/** moe-video enabler component **/ (function() { // state let moeOTSession = false; let moePublisher = false; let moeVideoElement = false; let moeArchiveID = false; let uploadOrRecord = 'record'; // initialize elements, events function init(_container = false) { $('[moe-video-progress]').remove(); $('
') .attr('moe-video-progress', 1) .append('') .appendTo('body'); _container = $(_container || 'body'); _container .find('[moe-video]:not([moe-initialized])') .each(function() { // assign a unique id let moeID = Math.ceil(Math.random() * 1000000); $(this).attr('moe-id', moeID); var buttonsDiv = $('
').appendTo(this); // record button $('' + '' + '
' + '
' + '
' + '

Setting up camera and microphone access...

' + '

Click "Allow" to allow hardware access and begin the recording

' + '
' + '

It appears we do not have access to your input hardware.

' + '

Please allow access to your hardware by clicking the ' + ' icon ' + 'towards the far right of the browser address bar. Once done, please click here to refresh the page and retry.

' + '
' + '
' + '
' + '' + '' + '' + '' + '').appendTo('body'); } function startWait() { $('[moe-start-recording]').hide(); $('[moe-stop-recording]').hide(); $('[moe-play-recording]').hide(); $('[moe-restart-recording]').hide(); $('[moe-submit-recording]').hide(); $('[moe-close-popup]').hide(); $('[moe-wait]').show(); $('[moe-video-progress]').removeClass('d-none').addClass('d-flex'); } function stopWait() { $('[moe-wait]').hide(); $('[moe-video-progress]').removeClass('d-flex').addClass('d-none'); } // init ot, publisher and show cam feed function initCamera(_moeVideoElement) { startWait(); $('.upload-or-record').removeClass('d-block').addClass('d-none'); $('.access-information').removeClass('d-none').addClass('d-block'); // cleanup if(!!moeOTSession) { moeOTSession.disconnect(); moeOTSession = false; moePublisher = false; } // create session (using sessionID given by the server) moeOTSession = OT.initSession( _moeVideoElement.attr('moe-ot-api-key'), _moeVideoElement.attr('moe-ot-session-id') ); // init publisher moePublisher = OT.initPublisher( $('[moe-video-canvas]').first()[0], { //videoSource: 'screen', // comment out in prod width: 540 } ); // publisher events moePublisher.on({ accessAllowed: function (event) { // The user has granted access to the camera and mic. console.log('ALIX: accessAllowed'); $('.access-information').removeClass('d-block').addClass('d-none'); $('[moe-video-canvas]').removeClass('d-none').addClass('d-block'); stopWait() }, accessDenied: function accessDeniedHandler(event) { // The user has denied access to the camera and mic. console.log('ALIX: accessDenied'); $('.click-allow').addClass('d-none'); $('.denied').removeClass('d-none'); stopWait() }, accessDialogOpened: function (event) { // The Allow/Deny dialog box is opened. console.log('ALIX: accessDialogOpened'); $('.click-allow').removeClass('d-none'); stopWait() }, accessDialogClosed: function (event) { // The Allow/Deny dialog box is closed. console.log('ALIX: accessDialogClosed'); stopWait() } }); // OT events moeOTSession.connect(_moeVideoElement.attr('moe-ot-client-token'), function(error) { if (error) { console.error('Failed to connect', error); } else { moeOTSession.publish(moePublisher, function(error) { if (error) { console.error('Failed to publish', error); } else { stopWait(); $('[moe-start-recording]').show(); $('[moe-stop-recording]').hide(); $('[moe-play-recording]').hide(); $('[moe-restart-recording]').hide(); $('[moe-submit-recording]').hide(); $('[moe-close-popup]').show(); } }); } }); moeOTSession.on('archiveStarted', function(event) { stopWait(); moeArchiveID = event.id; $('[moe-start-recording]').hide(); $('[moe-stop-recording]').show(); $('[moe-play-recording]').hide(); $('[moe-restart-recording]').hide(); $('[moe-submit-recording]').hide(); $('[moe-close-popup]').hide(); }); moeOTSession.on('archiveStopped', function() { // moeArchiveID = false; // stopWait(); // $('[moe-start-recording]').show(); // $('[moe-stop-recording]').hide(); // $('[moe-play-recording]').hide(); // $('[moe-restart-recording]').hide(); // $('[moe-submit-recording]').hide(); // $('[moe-close-popup]').show(); }); } $(document).ready(function() { init(); }); })();