diff --git a/src/EventTypes.js b/src/EventTypes.js index 95bd01f8a1db82e98e302c7486b81f650f6784f7..ae94f1db551be7386838dbdd9c6ea23e90bbb77c 100644 --- a/src/EventTypes.js +++ b/src/EventTypes.js @@ -67,6 +67,7 @@ const EventTypes = { // { roomId, ownerId, subject, startTime } EVENT_CALL_ROOM_INFO: 'call-room-info', EVENT_CALL_RECORDING_SAVED: 'call-recording-saved-event', + EVENT_CALL_RECORDING_UNSUPPORTED: 'call-recording-unsupported-event', // Calling events END // Message Events START diff --git a/src/call/CallRecorder.js b/src/call/CallRecorder.js index 57de460d9ed5539c0d16ebe0f00d2a44c911fb9d..e161c31c2dead314384a3e85ec7896df2c06c1a3 100644 --- a/src/call/CallRecorder.js +++ b/src/call/CallRecorder.js @@ -85,7 +85,7 @@ class CallRecorder { * @returns {void} */ initAudioContext = () => { - this._audioContext = new AudioContext(); + this._audioContext = new (window.AudioContext || window.webkitAudioContext)(); this._destination = this.audioContext.createMediaStreamDestination(); } @@ -144,9 +144,14 @@ class CallRecorder { getRecordingOptions = () => { // TODO: Change this when video recording is being implemented let options = { mimeType: RECORDING_MIME_TYPES.audioClean }; - if (!MediaRecorder.isTypeSupported(options.mimeType)) { - console.error('[CALL-RECORDING-UNSUPPORTED-MIME]', `${options.mimeType} is not supported`); - return; + + try { + if (!MediaRecorder.isTypeSupported(options.mimeType)) { + console.error('[CALL-RECORDING-UNSUPPORTED-MIME]', `${options.mimeType} is not supported`); + return; + } + } catch (e) { + retrun; } return options; @@ -175,6 +180,7 @@ class CallRecorder { * @returns {void} */ handleRecordingChunksEvent = (event) => { + const recState = this.getRecordingState(); if (event.data.size > 0) { this._indexDBManager .getItem(this._callId) @@ -186,7 +192,11 @@ class CallRecorder { chunks.push(event.data); this._indexDBManager .storeItem(this._callId, chunks) - .then(() => { }) + .then(() => { + if (recState === RECORDING_STATES.inactive || recState === RECORDING_STATES.paused) { + this.handleRecordingStopEvent(); + } + }) .catch(err => { console.log('[CALL-RECORDING-SAVE-FILE-INDEXDB-ERROR]', err); }); @@ -196,6 +206,9 @@ class CallRecorder { }); } else { console.log('[CALL-RECORDING-CHUNKS-EMPTY]', event); + if (recState === RECORDING_STATES.inactive || recState === RECORDING_STATES.paused) { + this.handleRecordingStopEvent(); + } } } @@ -227,7 +240,7 @@ class CallRecorder { initEventHandlers = () => { if (this.mediaRecorder) { this.mediaRecorder.ondataavailable = this.handleRecordingChunksEvent; - this.mediaRecorder.onstop = this.handleRecordingStopEvent; + //this.mediaRecorder.onstop = this.handleRecordingStopEvent; this.mediaRecorder.onerror = this.handleRecordingErrorEvent; } } @@ -252,6 +265,8 @@ class CallRecorder { } else { console.log('[CALL-RECORDING-ERROR]', 'No streams with tracks are added to record!'); } + } else { + this._facade.notify(EventTypes.EVENT_CALL_RECORDING_UNSUPPORTED); } }