src/RemonRecorder.js
import Context from './Context';
import 'platform'
import Config from './Configure';
import l from './Logger';
class RemonRecorder{
constructor(ctx, stream, postfix){
this.context = ctx;
this.stream = stream;
this.type = (platform.name === "Firefox")?"audio/ogg": "audio/webm";
//this.recorder = new MediaRecorder(this.stream, {audioBitsPerSecond: 128000, mimeType : this.type});
this.recorder = new MediaRecorder(this.stream, {audioBitsPerSecond: 8192, videoBitsPerSecond: 16000, mimeType : this.type});
this.array = [];
//this.recordingCb = null;
//this.stopCb = null;
this.recorder.ondataavailable = (e) =>{this.array.push(e.data);};
this.recorder.onstop = (e) =>{
var audioFile = new Blob(this.array, {type: this.type});
// var link = document.createElement('a');
// link.href = window.URL.createObjectURL(audioFile);
// link.download = this.context.token+ '.ogg';
// link.click();
var req = new XMLHttpRequest();
req.open("POST", "https://remotemonster.com/rest/record", true);
req.setRequestHeader("X-FILENAME",this.context.serviceId+"."+this.context.token.substring(0,6) + postfix+".ogg");
req.onload = function (oEvent) {
l.d("upload is completed");
};
req.send(audioFile);
};
}
start(){
this.recorder.start(3000);
}
stop(){
this.recorder.stop();
}
}
export default RemonRecorder;