From fa01188d954e2267cedfa4151badd2fe1edb2dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Mih=C3=A1ly?= Date: Wed, 27 Jan 2021 22:18:25 +0100 Subject: [PATCH] Add recovery for crashed or abored recordings --- app/src/RoomClient.js | 123 +++++++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 50 deletions(-) diff --git a/app/src/RoomClient.js b/app/src/RoomClient.js index fed810df..15fb6b5f 100644 --- a/app/src/RoomClient.js +++ b/app/src/RoomClient.js @@ -3622,54 +3622,6 @@ export default class RoomClient throw new Error('Unsupported media recording format %O', recordingMimeType); } - function invokeSaveAsDialog(blob, fileName) - { - const link = document.createElement('a'); - - link.style = 'display:none;opacity:0;color:transparent;'; - link.href = URL.createObjectURL(blob); - link.download = fileName; - - (document.body || document.documentElement).appendChild(link); - if (typeof link.click === 'function') - { - link.click(); - } - else - { - link.target = '_blank'; - link.dispatchEvent(new MouseEvent('click', - { - view : window, - bubbles : true, - cancelable : true - })); - } - URL.revokeObjectURL(link.href); - } - - // save recording and destroy - function saveRecordingAndCleanup(blobs) - { - // merge blob - const blob = new Blob(blobs, { type: recordingMimeType }); - - // Stop all used video/audio tracks - recorderStream.getTracks().forEach((track) => track.stop()); - - gdmStream.getTracks().forEach((track) => track.stop()); - - // save as - invokeSaveAsDialog(blob, `${idbName}.webm`); - - // destroy - idbDB.close(); - deleteDB(idbName); - recordingMimeType=null; - recordingData=[]; - recorder = null; - } - function mixer(stream1, stream2) { const ctx = new AudioContext(); @@ -3774,7 +3726,7 @@ export default class RoomClient idbDB.getAll(idbStoreName).then((blobs) => { - saveRecordingAndCleanup(blobs); + this.saveRecordingAndCleanup(blobs, idbDB, idbName); }); @@ -3787,7 +3739,7 @@ export default class RoomClient } else { - saveRecordingAndCleanup(recordingData); + this.saveRecordingAndCleanup(recordingData, idbDB, idbName); } }; @@ -3872,6 +3824,77 @@ export default class RoomClient } } + invokeSaveAsDialog(blob, fileName) + { + const link = document.createElement('a'); + + link.style = 'display:none;opacity:0;color:transparent;'; + link.href = URL.createObjectURL(blob); + link.download = fileName; + + (document.body || document.documentElement).appendChild(link); + if (typeof link.click === 'function') + { + link.click(); + } + else + { + link.target = '_blank'; + link.dispatchEvent(new MouseEvent('click', + { + view : window, + bubbles : true, + cancelable : true + })); + } + URL.revokeObjectURL(link.href); + } + + // save recording and destroy + saveRecordingAndCleanup(blobs, db, dbName) + { + // merge blob + const blob = new Blob(blobs, { type: recordingMimeType }); + + // Stop all used video/audio tracks + if (recorderStream && recorderStream.getTracks().length > 0) + recorderStream.getTracks().forEach((track) => track.stop()); + + if (gdmStream && gdmStream.getTracks().length > 0) + gdmStream.getTracks().forEach((track) => track.stop()); + + // save as + this.invokeSaveAsDialog(blob, `${dbName}.webm`); + + // destroy + db.close(); + deleteDB(dbName); + recordingMimeType=null; + recordingData=[]; + recorder = null; + } + + // Emergency recovery you need the date from indexDB as parameter. + recoverRecording(dbName) + { + try + { + openDB(dbName, 1).then((db) => + { + db.getAll(idbStoreName).then((blobs) => + { + this.saveRecordingAndCleanup(blobs, db, dbName); + }); + } + + ); + } + catch (error) + { + logger.error('Error during save recovered recording error: %O', error); + } + } + async lockRoom() { logger.debug('lockRoom()');