"use strict"; /* global ZoomMtg, emf, meq */ // c:\work\maven\scripts\imacs-live\instructors\6.0\htm\imacs-zoom.htm $( document ).ready( function() { let zoomlib = "https://source.zoom.us/" + $("input[name=zoomlibversion]").val() + "/lib"; if ( window.location.pathname.includes( "livezoom" ) ) { const queryString = window.location.search; const urlParams = new URLSearchParams( queryString ); const mtgnum = urlParams.get( 'num' ); const mtgpw = urlParams.get( 'pw' ); let trybuttons = true; if ( emf.debug ) console.log( urlParams ); if ( urlParams.has( "leftmeeting" ) ) { console.log( "left meeting" ); parent.postMessage( "closezoom" , "*" ); //20230913IF should we return here? Rather than rejoin? } ZoomMtg.setZoomJSLib( zoomlib, "/av" ); ZoomMtg.preLoadWasm(); ZoomMtg.prepareWebSDK(); ZoomMtg.i18n.load( "en-US" ); // loads language files, also passes any error messages to the ui ZoomMtg.i18n.reload( "en-US" ); ZoomMtg.init( { leaveUrl: "livezoom?num=" + mtgnum + "&pw=" + mtgpw + "&leftmeeting=1", success: success => { if ( emf.debug ) console.log( success ); // call server to provide ZoomMtg parameters meq.ajax( "data", "zoom-sig", { num: mtgnum, pw: mtgpw, browser: Navigator.userAgent }, function( xml ) { let config = $(xml).find( "zoominfo" ); if ( emf.debug ) console.log( config ); ZoomMtg.join( { sdkKey: config.attr( "sdkKey" ), signature: config.attr( "signature" ), meetingNumber: config.attr( "meetingNumber" ), passWord: config.attr( "passWord" ), userName: config.attr( "userName" ), success: result => { if ( emf.debug ) console.log( result ); try { hideJoinAudio(); startVideo(); $.wait( pickRightView, 3 ); parent.postMessage( "joinedzoom" , "*" ); $("button.footer__leave-btn" ).click( () => { if ( emf.debug ) console.log( "stopping button presses" ); trybuttons = false; } ); } catch ( e ) { emf.ajax( "data", "zoom-error", { name:"Error 1", browser: Navigator.userAgent, json: JSON.stringify( { error: e, result: result, signature: config.attr( "signature" ), meetingnumber: config.attr( "meetingNumber" ), username: config.attr( "userName" ), password: config.attr( "passWord" ) } ) } ); console.warn( "zoom error 1: " + e ); } }, error: error => { emf.ajax( "data", "zoom-error", { name:"Error 2", browser: Navigator.userAgent, json: JSON.stringify( { error: error, signature: config.attr( "signature" ), meetingnumber: config.attr( "meetingNumber" ), username: config.attr( "userName" ), password: config.attr( "passWord" ) } ) } ); console.warn( error ); } } ); } ); }, error: error => { emf.ajax( "data", "zoom-error", { name:"Error 3", error: error, browser: Navigator.userAgent, json: JSON.stringify( { meetingnumber: mtgnum, password: mtgpw } ) } ); console.warn( error ); } } ); addEventListener( "beforeunload", () => // (event) => { console.log("LEAVINGWINDOW"); parent.postMessage( "closezoom" , "*" ); } ); ZoomMtg.inMeetingServiceListener( "onMeetingStatus", function( data ) { // {status: 1(connecting), 2(connected), 3(disconnected), 4(reconnecting)} if ( emf.debug ) console.log( data ); if ( data && data.meetingStatus == 3 ) { console.log( "MEETINGENDED" ); parent.postMessage( "closezoom" , "*" ); } } ); addEventListener( "resize", pickRightView ); function pickRightView() { if ( emf.debug ) console.log( "setting correct view for screen size" ); if ( window.innerHeight < 350 ) { $( "div[feature-type=settings]" ).hide(); if ( $("a[aria-label='Side-by-side: Gallery']")[0] ) $("a[aria-label='Side-by-side: Gallery']")[0].click(); else if ( $("a[aria-label='Gallery View']")[0] ) $("a[aria-label='Gallery View']")[0].click(); } else { $( "div[feature-type=settings]" ).show(); if ( window.innerWidth < window.innerHeight * 1.33 ) // narrow width screen (want gallery on top) { if ( $("a[aria-label='Standard']")[0] ) $("a[aria-label='Standard']")[0].click(); else if ( $("a[aria-label='Speaker View']")[0] ) $("a[aria-label='Speaker View']")[0].click(); } else // wider screens (want side by side gallery) { if ( $("a[aria-label='Side-by-side: Gallery']")[0] ) $("a[aria-label='Side-by-side: Gallery']")[0].click(); else if ( $("a[aria-label='Speaker View']")[0] ) $("a[aria-label='Speaker View']")[0].click(); } } } function hideJoinAudio() { let mutebtn = $( "button[arialabel='mute my microphone']" )[0], unmutebtn = $( "button[arialabel='unmute my microphone']" )[0]; if ( mutebtn == null && unmutebtn == null && trybuttons ) { if ( emf.debug ) console.log( "Trying to auto join audio" ); let joinByPC = $( "button.join-audio-by-voip__join-btn" )[0], joinAudio = $( "button[arialabel='join audio']" )[0]; if ( joinByPC ) { $.wait( JoinAudioAuto, 0.2 ); } else if ( joinAudio ) { joinAudio.click(); $.wait( hideJoinAudio, 1 ); } else { $.wait( hideJoinAudio, 1 ); } } else if ( unmutebtn && trybuttons ) { unmutebtn.click(); } } function startVideo() { let vidbtn = $( "button[arialabel='start sending my video']" )[0]; if ( emf.debug ) console.log( "Trying to start video button" ); if ( vidbtn && trybuttons ) { vidbtn.click(); $.wait( startVideo, 1 ); } else { //turn on blurred background let settings = $( "button[aria-label='Settings']" )[0]; if ( settings && trybuttons ) { if ( emf.debug ) console.log( "Turn on blurred background" ); settings.click(); $.wait( function(){ $( "div#background" ).click(); }, 0.2 ); $.wait( function() { if ( $( "div.settings-background" ).find( "div.zm-checkbox2" ).attr("aria-checked") == "false" ) $( "div.settings-background" ).find( "div.zm-checkbox2" ).click(); }, 0.4 ); $.wait( function() { if ( $( "div.settings-background" ).find( "div.zm-checkbox2" ).attr("aria-checked") == "true" ) $( "div.settings-background" ).find( "img#blur" ).click(); }, 0.6 ); $.wait( function() { $( "button.settings-dialog__close" ).click(); }, 0.8 ); } } } function JoinAudioAuto() { let btn = $( "button.join-audio-by-voip__join-btn" )[0]; if ( emf.debug ) console.log( "Trying to auto click button" ); if ( btn && trybuttons ) { btn.click(); $.wait( JoinAudioAuto, 1 ); } } $.wait = function( callback, seconds) { return window.setTimeout( callback, seconds * 1000 ); }; } else if ( window.location.pathname.indexOf( "joinzoom" ) > 0 ) { $("button#joinbtn").on( "click", function() { let mtgnum = $("input#mtgnum").val().replace( /\D/g, "" ), mtgpw = $("input#mtgpw").val().replace( /\s/g, "" ); window.location.href = "livezoom?v=" + Date.now() + "&num=" + mtgnum + "&pw=" + mtgpw; } ); } } );