37 lines
1.6 KiB
JavaScript
37 lines
1.6 KiB
JavaScript
import {LocalRecording} from './local-recording.js';
|
|
|
|
// Blob URLs live only as long as this page's review. No storage persistence,
|
|
// automatic download, media upload, or access to the numeric reporting channel.
|
|
export function reviewControls(document) {
|
|
const el=id=>document.getElementById(id);
|
|
let url=null;
|
|
function clear() {
|
|
el('replay').pause();el('replay').removeAttribute('src');el('replay').load();
|
|
el('download-recording').removeAttribute('href');el('review').hidden=true;
|
|
if(url)URL.revokeObjectURL(url);
|
|
url=null;
|
|
}
|
|
const recorder=new LocalRecording({
|
|
onStatus:message=>{el('record-status').textContent=message;},
|
|
onReady:blob=>{
|
|
clear();url=URL.createObjectURL(blob);
|
|
el('replay').src=url;el('download-recording').href=url;
|
|
el('download-recording').download=`av-review.${blob.type.includes('mp4')?'mp4':'webm'}`;
|
|
el('review').hidden=false;
|
|
},
|
|
});
|
|
el('record-review').disabled=!recorder.supported;
|
|
if(!recorder.supported)el('record-status').textContent='Local recording is unavailable in this browser.';
|
|
el('discard-recording').onclick=()=>{recorder.discard();clear();el('record-status').textContent='Clip cleared.';};
|
|
return {
|
|
begin(stream) {
|
|
recorder.discard();clear();
|
|
if(el('record-review').checked)return recorder.start(stream);
|
|
el('record-status').textContent='Not recording';return false;
|
|
},
|
|
lock(locked){el('record-review').disabled=locked||!recorder.supported;},
|
|
finish(){recorder.finish();},
|
|
discard(){recorder.discard();clear();},
|
|
};
|
|
}
|