ezuikit-js 8.0.10-alpha.2 → 8.0.10-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ezuikit.js +2 -2
- package/package.json +1 -1
package/ezuikit.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
*
|
|
3
|
-
* ezuikit.js v8.0.10-alpha.
|
|
3
|
+
* ezuikit.js v8.0.10-alpha.3
|
|
4
4
|
* Copyright (c) 2024-8-21 Ezviz-OpenBiz
|
|
5
5
|
* Released under ISC the License.
|
|
6
6
|
*
|
|
@@ -127,4 +127,4 @@ var sn="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValue
|
|
|
127
127
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
128
128
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
129
129
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
130
|
-
*/Bl.sessions={},Bl.isExtensionEnabled=function(){if(navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia)return!0;if(window.navigator.userAgent.match("Chrome")){var A=parseInt(window.navigator.userAgent.match(/Chrome\/(.*) /)[1],10),e=33;return window.navigator.userAgent.match("Linux")&&(e=35),A>=26&&A<=e||Bl.extension.isInstalled()}return!0};var hl={extensionId:"hapfgfdkleiggjjpfpenajgdnfckjpaj",isInstalled:function(){return null!==document.querySelector("#janus-extension-installed")},getScreen:function(A){var e=window.setTimeout((function(){var e=new Error("NavigatorUserMediaError");return e.name='The required Chrome extension is not installed: click <a href="#">here</a> to install it. (NOTE: this will need you to refresh the page)',A(e)}),1e3);this.cache[e]=A,window.postMessage({type:"janusGetScreen",id:e},"*")},init:function(){var A={};this.cache=A,window.addEventListener("message",(function(e){if(e.origin==window.location.origin)if("janusGotScreen"==e.data.type&&A[e.data.id]){var t=A[e.data.id];if(delete A[e.data.id],""===e.data.sourceId){var i=new Error("NavigatorUserMediaError");i.name="You cancelled the request for permission, giving up...",t(i)}else t(null,e.data.sourceId)}else"janusGetScreenPending"==e.data.type&&(console.log("clearing ",e.data.id),window.clearTimeout(e.data.id))}))}};function Bl(A,e){if(void 0===Bl.initDone)return A.error("Library not initialized"),{};if(!Bl.isWebrtcSupported())return A.error("WebRTC not supported by this browser"),{};if(Bl.log("Library initialized: "+Bl.initDone),(A=A||{}).success="function"==typeof A.success?A.success:Bl.noop,A.error="function"==typeof A.error?A.error:Bl.noop,A.destroyed="function"==typeof A.destroyed?A.destroyed:Bl.noop,null===A.server||void 0===A.server)return A.error("Invalid server url"),{};var t=!1,i=null,n={},a=null,r=null,o=0,s=A.server;Bl.isArray(s)?(Bl.log("Multiple servers provided ("+s.length+"), will use the first that works"),s=null,r=A.server,Bl.debug(r)):0===s.indexOf("ws")?(t=!0,Bl.log("Using WebSockets to contact Janus: "+s)):(t=!1,Bl.log("Using REST API to contact Janus: "+s));var g=A.iceServers;null==g&&(g=[{urls:"stun:stun.l.google.com:19302"}]);var c=A.iceTransportPolicy,l=A.bundlePolicy,I=A.ipv6;null==I&&(I=!1);var d=!1;void 0!==A.withCredentials&&null!==A.withCredentials&&(d=!0===A.withCredentials);var h=10;void 0!==A.max_poll_events&&null!==A.max_poll_events&&(h=A.max_poll_events),h<1&&(h=1);var B=null;void 0!==A.token&&null!==A.token&&(B=A.token);var u=null;void 0!==A.apisecret&&null!==A.apisecret&&(u=A.apisecret),this.destroyOnUnload=!0,void 0!==A.destroyOnUnload&&null!==A.destroyOnUnload&&(this.destroyOnUnload=!0===A.destroyOnUnload);var E=25e3;void 0!==A.keepAlivePeriod&&null!==A.keepAlivePeriod&&(E=A.keepAlivePeriod),isNaN(E)&&(E=25e3);var f=6e4;function Q(A){var e={high:9e5,medium:3e5,low:1e5};return null!=A&&(A.high&&(e.high=A.high),A.medium&&(e.medium=A.medium),A.low&&(e.low=A.low)),e}void 0!==A.longPollTimeout&&null!==A.longPollTimeout&&(f=A.longPollTimeout),isNaN(f)&&(f=6e4);var x=!1,p=null,m={},y=this,_=0,S={};function D(){if(null!=p)if(Bl.debug("Long poll..."),x){var e=s+"/"+p+"?rid="+(new Date).getTime();null!=h&&(e=e+"&maxev="+h),null!=B&&(e=e+"&token="+encodeURIComponent(B)),null!=u&&(e=e+"&apisecret="+encodeURIComponent(u)),Bl.httpAPICall(e,{verb:"GET",withCredentials:d,success:w,timeout:f,error:function(e,t){if(Bl.error(e+":",t),++_>3)return x=!1,void A.error("Lost connection to the server (is it down?)");D()}})}else Bl.warn("Is the server down? (connected=false)")}function w(A,e){if(_=0,t||null==p||!0===e||D(),t||!Bl.isArray(A))if("keepalive"!==A.rtcgw)if("ack"!==A.rtcgw)if("success"!==A.rtcgw)if("trickle"===A.rtcgw){if(null==(s=A.sender))return void Bl.warn("Missing sender...");if(null==(c=m[s]))return void Bl.debug("This handle is not attached to this session");var n=A.candidate;Bl.debug("Got a trickled candidate on session "+p),Bl.debug(n);var a=c.webrtcStuff;a.pc&&a.remoteSdp?(Bl.debug("Adding remote candidate:",n),n&&!0!==n.completed?a.pc.addIceCandidate(n):a.pc.addIceCandidate(Bl.endOfCandidates)):(Bl.debug("We didn't do setRemoteDescription (trickle got here before the offer?), caching candidate"),a.candidates||(a.candidates=[]),a.candidates.push(n),Bl.debug(a.candidates))}else{if("webrtcup"===A.rtcgw)return Bl.debug("Got a webrtcup event on session "+p),Bl.debug(A),null==(s=A.sender)?void Bl.warn("Missing sender..."):null==(c=m[s])?void Bl.debug("This handle is not attached to this session"):void c.webrtcState(!0);if("hangup"===A.rtcgw){if(Bl.debug("Got a hangup event on session "+p),Bl.debug(A),null==(s=A.sender))return void Bl.warn("Missing sender...");if(null==(c=m[s]))return void Bl.debug("This handle is not attached to this session");c.webrtcState(!1,A.reason),c.hangup()}else if("detached"===A.rtcgw){if(Bl.debug("Got a detached event on session "+p),Bl.debug(A),null==(s=A.sender))return void Bl.warn("Missing sender...");if(null==(c=m[s]))return;c.detached=!0,c.ondetached(),c.detach()}else if("media"===A.rtcgw){if(Bl.debug("Got a media event on session "+p),Bl.debug(A),null==(s=A.sender))return void Bl.warn("Missing sender...");if(null==(c=m[s]))return void Bl.debug("This handle is not attached to this session");c.mediaState(A.type,A.receiving)}else if("slowlink"===A.rtcgw){if(Bl.debug("Got a slowlink event on session "+p),Bl.debug(A),console.log("json的所有信息打印-----------------------------------------------",A),null==(s=A.sender))return void Bl.warn("Missing sender...");if(null==(c=m[s]))return void Bl.debug("This handle is not attached to this session");c.slowLink(A.uplink,A.lost)}else{if("error"===A.rtcgw){var r,o;if(Bl.error("Ooops: "+A.error.code+" "+A.error.reason),Bl.debug(A),null!=(r=A.transaction))null!=(o=S[r])&&o(A),delete S[r];return}if("event"===A.rtcgw){var s;if(Bl.debug("Got a plugin event on session "+p),Bl.debug(A),null==(s=A.sender))return void Bl.warn("Missing sender...");var g=A.plugindata;if(null==g)return void Bl.warn("Missing plugindata...");Bl.debug(" -- Event is coming from "+s+" ("+g.plugin+")");var c,l=g.data;if(Bl.debug(l),null==(c=m[s]))return void Bl.warn("This handle is not attached to this session");var I=A.jsep;null!=I&&(Bl.debug("Handling SDP as well..."),Bl.debug(I));var C=c.onmessage;null!=C?(Bl.debug("Notifying application..."),C(l,I)):Bl.debug("No provided notification callback")}else{if("timeout"===A.rtcgw)return Bl.error("Timeout on session "+p),Bl.debug(A),void(t&&i.close(3504,"Gateway timeout"));Bl.warn("Unknown message/event '"+A.rtcgw+"' on session "+p),Bl.debug(A)}}}else Bl.debug("Got a success on session "+p),Bl.debug(A),null!=(r=A.transaction)&&(null!=(o=S[r])&&o(A),delete S[r]);else Bl.debug("Got an ack on session "+p),Bl.debug(A),null!=(r=A.transaction)&&(null!=(o=S[r])&&o(A),delete S[r]);else Bl.vdebug("Got a keepalive on session "+p);else for(var d=0;d<A.length;d++)w(A[d],!0)}function v(){if(null!==s&&t&&x){a=setTimeout(v,E);var A={rtcgw:"keepalive",session_id:p,transaction:Bl.randomString(12)};null!=B&&(A.token=B),null!=u&&(A.apisecret=u),i.send(JSON.stringify(A))}}function F(A){var g=Bl.randomString(12),c={rtcgw:"create",transaction:g,token:"testtoken"};if(c=Object.assign({},c,e),A.reconnect&&(x=!1,c.rtcgw="claim",c.session_id=p,i&&(i.onopen=null,i.onerror=null,i.onclose=null,a&&(clearTimeout(a),a=null))),null!=B&&(c.token=B),null!=u&&(c.apisecret=u),null===s&&Bl.isArray(r)&&(0===(s=r[o]).indexOf("ws")?(t=!0,Bl.log("Server #"+(o+1)+": trying WebSockets to contact Janus ("+s+")")):(t=!1,Bl.log("Server #"+(o+1)+": trying REST API to contact Janus ("+s+")"))),t)for(var l in i=Bl.newWebSocket(s,"rtcgw-protocol"),n={error:function(){if(Bl.error("Error connecting to the Janus WebSockets server... "+s),Bl.isArray(r)&&!A.reconnect)return++o==r.length?void A.error("Error connecting to any of the provided Janus servers: Is the server down?"):(s=null,void setTimeout((function(){F(A)}),200));A.error("Error connecting to the Janus WebSockets server: Is the server down?")},open:function(){S[g]=function(e){if(Bl.debug(e),"success"!==e.rtcgw)return Bl.error("Ooops: "+e.error.code+" "+e.error.reason),void A.error(e.error.reason);a=setTimeout(v,E),x=!0,p=e.session_id?e.session_id:e.data.id,A.reconnect?Bl.log("Claimed session: "+p):Bl.log("Created session: "+p),Bl.sessions[p]=y,A.success(p)},i.send(JSON.stringify(c))},message:function(A){w(JSON.parse(A.data))}})i.addEventListener(l,n[l]);else Bl.httpAPICall(s,{verb:"POST",withCredentials:d,body:c,success:function(e){if(Bl.debug(e),"success"!==e.rtcgw)return Bl.error("Ooops: "+e.error.code+" "+e.error.reason),void A.error(e.error.reason);x=!0,p=e.session_id?e.session_id:e.data.id,A.reconnect?Bl.log("Claimed session: "+p):Bl.log("Created session: "+p),Bl.sessions[p]=y,D(),A.success()},error:function(e,t){if(Bl.error(e+":",t),Bl.isArray(r)&&!A.reconnect)return++o==r.length?void A.error("Error connecting to any of the provided Janus servers: Is the server down?"):(s=null,void setTimeout((function(){F(A)}),200));""===t?A.error(e+": Is the server down?"):A.error(e+": "+t)}})}function b(A,e){if((e=e||{}).success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:Bl.noop,!x)return Bl.warn("Is the server down? (connected=false)"),void e.error("Is the server down? (connected=false)");var n=m[A];if(null==n||null===n.webrtcStuff||void 0===n.webrtcStuff)return Bl.warn("Invalid handle"),void e.error("Invalid handle");var a=e.message,r=e.jsep,o=Bl.randomString(12),g={rtcgw:"message",body:a,transaction:o};if(null!==n.token&&void 0!==n.token&&(g.token=n.token),null!=u&&(g.apisecret=u),null!=r&&(g.jsep=r),Bl.debug("Sending message to plugin (handle="+A+"):"),Bl.debug(g),t)return g.session_id=p,g.handle_id=A,S[o]=function(A){if(Bl.debug("Message sent!"),Bl.debug(A),"success"===A.rtcgw){var t=A.plugindata;if(null==t)return Bl.warn("Request succeeded, but missing plugindata..."),void e.success();Bl.log("Synchronous transaction successful ("+t.plugin+")");var i=t.data;return Bl.debug(i),void e.success(i)}"ack"===A.rtcgw?e.success():void 0!==A.error&&null!==A.error?(Bl.error("Ooops: "+A.error.code+" "+A.error.reason),e.error(A.error.code+" "+A.error.reason)):(Bl.error("Unknown error"),e.error("Unknown error"))},void i.send(JSON.stringify(g));Bl.httpAPICall(s+"/"+p+"/"+A,{verb:"POST",withCredentials:d,body:g,success:function(A){if(Bl.debug("Message sent!"),Bl.debug(A),"success"===A.rtcgw){var t=A.plugindata;if(null==t)return Bl.warn("Request succeeded, but missing plugindata..."),void e.success();Bl.log("Synchronous transaction successful ("+t.plugin+")");var i=t.data;return Bl.debug(i),void e.success(i)}"ack"===A.rtcgw?e.success():void 0!==A.error&&null!==A.error?(Bl.error("Ooops: "+A.error.code+" "+A.error.reason),e.error(A.error.code+" "+A.error.reason)):(Bl.error("Unknown error"),e.error("Unknown error"))},error:function(A,t){Bl.error(A+":",t),e.error(A+": "+t)}})}function R(A,e){if(x){var n=m[A];if(null!=n&&null!==n.webrtcStuff&&void 0!==n.webrtcStuff){var a={rtcgw:"trickle",candidate:e,transaction:Bl.randomString(12)};if(null!==n.token&&void 0!==n.token&&(a.token=n.token),null!=u&&(a.apisecret=u),Bl.vdebug("Sending trickle candidate (handle="+A+"):"),Bl.vdebug(a),t)return a.session_id=p,a.handle_id=A,void i.send(JSON.stringify(a));Bl.httpAPICall(s+"/"+p+"/"+A,{verb:"POST",withCredentials:d,body:a,success:function(A){Bl.vdebug("Candidate sent!"),Bl.vdebug(A),"ack"===A.rtcgw||Bl.error("Ooops: "+A.error.code+" "+A.error.reason)},error:function(A,e){Bl.error(A+":",e)}})}else Bl.warn("Invalid handle")}else Bl.warn("Is the server down? (connected=false)")}function k(A,e,t,i){var n=m[A];if(null!=n&&null!==n.webrtcStuff&&void 0!==n.webrtcStuff){var a=n.webrtcStuff,r=function(A){Bl.log("Received state change on data channel:",A);var e=A.target.label,t=a.dataChannel[e]?a.dataChannel[e].readyState:"null";if(Bl.log("State change on <"+e+"> data channel: "+t),"open"===t){if(a.dataChannel[e].pending&&a.dataChannel[e].pending.length>0){for(var i in Bl.log("Sending pending messages on <"+e+">:",a.dataChannel[e].pending.length),a.dataChannel[e].pending){var r=a.dataChannel[e].pending[i];Bl.log("Sending string on data channel <"+e+">: "+r),a.dataChannel[e].send(r)}a.dataChannel[e].pending=[]}n.ondataopen(e)}};a.dataChannel[e]=t||a.pc.createDataChannel(e,{ordered:!1}),a.dataChannel[e].onmessage=function(A){Bl.log("Received message on data channel:",A);var e=A.target.label;n.ondata(A.data,e)},a.dataChannel[e].onopen=r,a.dataChannel[e].onclose=r,a.dataChannel[e].onerror=function(A){Bl.error("Got error on data channel:",A)},a.dataChannel[e].pending=[],i&&a.dataChannel[e].pending.push(i)}else Bl.warn("Invalid handle")}function P(A,e){(e=e||{}).success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:Bl.noop;var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return Bl.warn("Invalid handle"),void e.error("Invalid handle");var i=t.webrtcStuff,n=e.text;if(null==n)return Bl.warn("Invalid text"),void e.error("Invalid text");var a=e.label?e.label:Bl.dataChanDefaultLabel;return i.dataChannel[a]?"open"!==i.dataChannel[a].readyState?(i.dataChannel[a].pending.push(n),void e.success()):(Bl.log("Sending string on data channel <"+a+">: "+n),i.dataChannel[a].send(n),void e.success()):(k(A,a,!1,n),void e.success())}function N(A,e){(e=e||{}).success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:Bl.noop;var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return Bl.warn("Invalid handle"),void e.error("Invalid handle");var i=t.webrtcStuff;if(null===i.dtmfSender||void 0===i.dtmfSender){if(void 0!==i.pc&&null!==i.pc){var n=i.pc.getSenders().find((function(A){return A.track&&"audio"===A.track.kind}));if(!n)return Bl.warn("Invalid DTMF configuration (no audio track)"),void e.error("Invalid DTMF configuration (no audio track)");i.dtmfSender=n.dtmf,i.dtmfSender&&(Bl.log("Created DTMF Sender"),i.dtmfSender.ontonechange=function(A){Bl.debug("Sent DTMF tone: "+A.tone)})}if(null===i.dtmfSender||void 0===i.dtmfSender)return Bl.warn("Invalid DTMF configuration"),void e.error("Invalid DTMF configuration")}var a=e.dtmf;if(null==a)return Bl.warn("Invalid DTMF parameters"),void e.error("Invalid DTMF parameters");var r=a.tones;if(null==r)return Bl.warn("Invalid DTMF string"),void e.error("Invalid DTMF string");var o=a.duration;null==o&&(o=500);var s=a.gap;null==s&&(s=50),Bl.debug("Sending DTMF string "+r+" (duration "+o+"ms, gap "+s+"ms)"),i.dtmfSender.insertDTMF(r,o,s),e.success()}function T(A,e){(e=e||{}).success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:Bl.noop;var n=!0;void 0!==e.asyncRequest&&null!==e.asyncRequest&&(n=!0===e.asyncRequest);var a=!0;void 0!==e.noRequest&&null!==e.noRequest&&(a=!0===e.noRequest),Bl.log("Destroying handle "+A+" (async="+n+")"),O(A);var r=m[A];if(null==r||r.detached)return delete m[A],void e.success();if(a)return delete m[A],void e.success();if(!x)return Bl.warn("Is the server down? (connected=false)"),void e.error("Is the server down? (connected=false)");var o={rtcgw:"detach",transaction:Bl.randomString(12)};if(null!==r.token&&void 0!==r.token&&(o.token=r.token),null!=u&&(o.apisecret=u),t)return o.session_id=p,o.handle_id=A,i.send(JSON.stringify(o)),delete m[A],void e.success();Bl.httpAPICall(s+"/"+p+"/"+A,{verb:"POST",async:n,withCredentials:d,body:o,success:function(t){Bl.log("Destroyed handle:"),Bl.debug(t),"success"!==t.rtcgw&&Bl.error("Ooops: "+t.error.code+" "+t.error.reason),delete m[A],e.success()},error:function(t,i){Bl.error(t+":",i),delete m[A],e.success()}})}function M(A,e,t,i,n){var a=m[A];if(null==a||null===a.webrtcStuff||void 0===a.webrtcStuff)return Bl.warn("Invalid handle"),void i.error("Invalid handle");var r=a.webrtcStuff;Bl.debug("streamsDone:",n),n&&(Bl.debug(" -- Audio tracks:",n.getAudioTracks()),Bl.debug(" -- Video tracks:",n.getVideoTracks()));var o=!1;if(r.myStream&&t.update&&!r.streamExternal){if((!t.update&&j(t)||t.update&&(t.addAudio||t.replaceAudio))&&n.getAudioTracks()&&n.getAudioTracks().length)if(r.myStream.addTrack(n.getAudioTracks()[0]),Bl.unifiedPlan){Bl.log((t.replaceAudio?"Replacing":"Adding")+" audio track:",n.getAudioTracks()[0]);var s=null;if((h=r.pc.getTransceivers())&&h.length>0)for(var d in h){if((u=h[d]).sender&&u.sender.track&&"audio"===u.sender.track.kind||u.receiver&&u.receiver.track&&"audio"===u.receiver.track.kind){s=u;break}}s&&s.sender?s.sender.replaceTrack(n.getAudioTracks()[0]):r.pc.addTrack(n.getAudioTracks()[0],n)}else Bl.log((t.replaceAudio?"Replacing":"Adding")+" audio track:",n.getAudioTracks()[0]),r.pc.addTrack(n.getAudioTracks()[0],n);if((!t.update&&Z(t)||t.update&&(t.addVideo||t.replaceVideo))&&n.getVideoTracks()&&n.getVideoTracks().length)if(r.myStream.addTrack(n.getVideoTracks()[0]),Bl.unifiedPlan){Bl.log((t.replaceVideo?"Replacing":"Adding")+" video track:",n.getVideoTracks()[0]);var h,B=null;if((h=r.pc.getTransceivers())&&h.length>0)for(var d in h){var u;if((u=h[d]).sender&&u.sender.track&&"video"===u.sender.track.kind||u.receiver&&u.receiver.track&&"video"===u.receiver.track.kind){B=u;break}}B&&B.sender?B.sender.replaceTrack(n.getVideoTracks()[0]):r.pc.addTrack(n.getVideoTracks()[0],n)}else Bl.log((t.replaceVideo?"Replacing":"Adding")+" video track:",n.getVideoTracks()[0]),r.pc.addTrack(n.getVideoTracks()[0],n)}else r.myStream=n,o=!0;if(!r.pc){var E={iceServers:g,iceTransportPolicy:c,bundlePolicy:l};"chrome"===Bl.webRTCAdapter.browserDetails.browser&&(E.sdpSemantics=Bl.webRTCAdapter.browserDetails.version<72?"plan-b":"unified-plan");var f={optional:[{DtlsSrtpKeyAgreement:!0}]};if(!0===I&&f.optional.push({googIPv6:!0}),i.rtcConstraints&&"object"===C(i.rtcConstraints))for(var d in Bl.debug("Adding custom PeerConnection constraints:",i.rtcConstraints),i.rtcConstraints)f.optional.push(i.rtcConstraints[d]);"edge"===Bl.webRTCAdapter.browserDetails.browser&&(E.bundlePolicy="max-bundle"),Bl.log("Creating PeerConnection"),Bl.debug(f),r.pc=new RTCPeerConnection(E,f),Bl.debug(r.pc),r.pc.getStats&&(r.volume={},r.bitrate.value="0 kbits/sec"),Bl.log("Preparing local SDP and gathering candidates (trickle="+r.trickle+")"),r.pc.oniceconnectionstatechange=function(A){r.pc&&a.iceState(r.pc.iceConnectionState)},r.pc.onicecandidate=function(e){if(null==e.candidate||"edge"===Bl.webRTCAdapter.browserDetails.browser&&e.candidate.candidate.indexOf("endOfCandidates")>0)Bl.log("End of candidates."),r.iceDone=!0,!0===r.trickle?R(A,{completed:!0}):function(A,e){e=e||{},e.success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:Bl.noop;var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return void Bl.warn("Invalid handle, not sending anything");var i=t.webrtcStuff;if(Bl.log("Sending offer/answer SDP..."),null===i.mySdp||void 0===i.mySdp)return void Bl.warn("Local SDP instance is invalid, not sending anything...");i.mySdp={type:i.pc.localDescription.type,sdp:i.pc.localDescription.sdp},!1===i.trickle&&(i.mySdp.trickle=!1);Bl.debug(e),i.sdpSent=!0,e.success(i.mySdp)}(A,i);else{var t={candidate:e.candidate.candidate,sdpMid:e.candidate.sdpMid,sdpMLineIndex:e.candidate.sdpMLineIndex};!0===r.trickle&&R(A,t)}},r.pc.ontrack=function(A){Bl.log("Handling Remote Track"),Bl.debug(A),A.streams&&(r.remoteStream=A.streams[0],a.onremotestream(r.remoteStream),A.track.onended||(Bl.log("Adding onended callback to track:",A.track),A.track.onended=function(A){Bl.log("Remote track muted/removed:",A),r.remoteStream&&(r.remoteStream.removeTrack(A.target),a.onremotestream(r.remoteStream))},A.track.onmute=A.track.onended,A.track.onunmute=function(A){Bl.log("Remote track flowing again:",A);try{r.remoteStream.addTrack(A.target),a.onremotestream(r.remoteStream)}catch(A){Bl.error(A)}}))}}if(o&&null!=n)if(Bl.log("Adding local stream"),console.log("callbacks",i),"screen"==i.media.video){var x=!0===i.simulcast2;n.getTracks().forEach((function(A){if(Bl.log("Adding local track:",A),A.applyConstraints({frameRate:5}),x)if("audio"===A.kind)r.pc.addTrack(A,n);else{Bl.log("Enabling rid-based simulcasting:",A);var e=Q(i.simulcastMaxBitrates);r.pc.addTransceiver(A,{direction:"sendrecv",streams:[n],sendEncodings:[{rid:"h",active:!0,maxBitrate:e.high},{rid:"m",active:!0,maxBitrate:e.medium,scaleResolutionDownBy:2},{rid:"l",active:!0,maxBitrate:e.low,scaleResolutionDownBy:4}]})}else r.pc.addTrack(A,n)}))}else{x=!0===i.simulcast2;var p=n.getTracks(),y=p[0];if(y){var _=y.getSettings();console.log("videoTrack",y),console.log("videosettings",_)}var S=n.getAudioTracks()[0];if(S){var D=S.getSettings();console.log("audiosettings",D)}p.forEach((function(A){if(A.applyConstraints({frameRate:{max:i.frameRate}}),Bl.log("Adding local track:",A),x){r.pc.addTrack(A,n);var e=null,t=r.pc.getSenders();for(var a in t){var o=t[a];o&&o.track&&"video"===o.track.kind&&(e=o)}var s=null;e&&(s=e.getParameters()),s&&s.encodings&&(s.encodings[0].maxBitrate=1e5,e.setParameters(s).then((function(A){console.log("Successed to set parameters!",s)})).catch((function(A){console.log("err",A),console.error(A)})))}else if("audio"===A.kind)r.pc.addTrack(A,n);else{Bl.log("Enabling rid-based simulcasting:",A);var g=i.bitrate||1e5;r.pc.addTransceiver(A,{direction:"sendrecv",streams:[n],sendEncodings:[{rid:"h",active:!0,maxBitrate:g}]})}}))}(function(A){if(Bl.debug("isDataEnabled:",A),"edge"==Bl.webRTCAdapter.browserDetails.browser)return Bl.warn("Edge doesn't support data channels yet"),!1;return null!=A&&!0===A.data})(t)&&!r.dataChannel[Bl.dataChanDefaultLabel]&&(Bl.log("Creating data channel"),k(A,Bl.dataChanDefaultLabel,!1),r.pc.ondatachannel=function(e){Bl.log("Data channel created by Janus:",e),k(A,e.channel.label,e.channel)}),r.myStream&&a.onlocalstream(r.myStream),null==e?function(A,e,t){t=t||{},t.success="function"==typeof t.success?t.success:Bl.noop,t.error="function"==typeof t.error?t.error:Bl.noop,t.customizeSdp="function"==typeof t.customizeSdp?t.customizeSdp:Bl.noop;var i=m[A];if(null==i||null===i.webrtcStuff||void 0===i.webrtcStuff)return Bl.warn("Invalid handle"),void t.error("Invalid handle");var n=i.webrtcStuff,a=!0===t.simulcast;a?Bl.log("Creating offer (iceDone="+n.iceDone+", simulcast="+a+")"):Bl.log("Creating offer (iceDone="+n.iceDone+")");var r={};if(Bl.unifiedPlan){var o=null,s=null,g=n.pc.getTransceivers();if(g&&g.length>0)for(var c in g){var l=g[c];l.sender&&l.sender.track&&"audio"===l.sender.track.kind||l.receiver&&l.receiver.track&&"audio"===l.receiver.track.kind?o||(o=l):(l.sender&&l.sender.track&&"video"===l.sender.track.kind||l.receiver&&l.receiver.track&&"video"===l.receiver.track.kind)&&(s||(s=l))}var I=j(e),C=W(e);I||C?I&&C?o&&(o.setDirection?o.setDirection("sendrecv"):o.direction="sendrecv",Bl.log("Setting audio transceiver to sendrecv:",o)):I&&!C?o&&(o.setDirection?o.setDirection("sendonly"):o.direction="sendonly",Bl.log("Setting audio transceiver to sendonly:",o)):!I&&C&&(o?(o.setDirection?o.setDirection("recvonly"):o.direction="recvonly",Bl.log("Setting audio transceiver to recvonly:",o)):(o=n.pc.addTransceiver("audio",{direction:"recvonly"}),Bl.log("Adding recvonly audio transceiver:",o))):e.removeAudio&&o&&(o.setDirection?o.setDirection("inactive"):o.direction="inactive",Bl.log("Setting audio transceiver to inactive:",o));var d=Z(e),h=X(e);d||h?d&&h?s&&(s.setDirection?s.setDirection("sendrecv"):s.direction="sendrecv",Bl.log("Setting video transceiver to sendrecv:",s)):d&&!h?s&&(s.setDirection?s.setDirection("sendonly"):s.direction="sendonly",Bl.log("Setting video transceiver to sendonly:",s)):!d&&h&&(s?(s.setDirection?s.setDirection("recvonly"):s.direction="recvonly",Bl.log("Setting video transceiver to recvonly:",s)):(s=n.pc.addTransceiver("video",{direction:"recvonly"}),Bl.log("Adding recvonly video transceiver:",s))):e.removeVideo&&s&&(s.setDirection?s.setDirection("inactive"):s.direction="inactive",Bl.log("Setting video transceiver to inactive:",s))}else r.offerToReceiveAudio=W(e),r.offerToReceiveVideo=X(e);var B=!0===t.iceRestart;B&&(r.iceRestart=!0);Bl.debug(r);var u=Z(e);if(u&&a&&"firefox"===Bl.webRTCAdapter.browserDetails.browser){Bl.log("Enabling Simulcasting for Firefox (RID)");var E=n.pc.getSenders().find((function(A){return"video"==A.track.kind}));if(E){var f=E.getParameters();f||(f={});var x=Q(t.simulcastMaxBitrates);f.encodings=[{rid:"h",active:!0,maxBitrate:x.high},{rid:"m",active:!0,maxBitrate:x.medium,scaleResolutionDownBy:2},{rid:"l",active:!0,maxBitrate:x.low,scaleResolutionDownBy:4}],E.setParameters(f)}}n.pc.createOffer(r).then((function(A){Bl.debug(A);var e={type:A.type,sdp:A.sdp};t.customizeSdp(e),A.sdp=e.sdp,Bl.log("Setting local description"),u&&a&&("chrome"===Bl.webRTCAdapter.browserDetails.browser||"safari"===Bl.webRTCAdapter.browserDetails.browser?(Bl.log("Enabling Simulcasting for Chrome (SDP munging)"),A.sdp=function(A){for(var e=A.split("\r\n"),t=!1,i=[-1],n=[-1],a=null,r=null,o=null,s=null,g=-1,c=0;c<e.length;c++){if(I=e[c].match(/m=(\w+) */)){if("video"===I[1]){if(!(i[0]<0)){g=c;break}t=!0}else if(i[0]>-1){g=c;break}}else if(t){var l=e[c].match(/a=ssrc-group:FID (\d+) (\d+)/);if(l)i[0]=l[1],n[0]=l[2],e.splice(c,1),c--;else{if(i[0]){if((d=e[c].match("a=ssrc:"+i[0]+" cname:(.+)"))&&(a=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" msid:(.+)"))&&(r=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" mslabel:(.+)"))&&(o=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" label:(.+)"))&&(s=d[1]),0===e[c].indexOf("a=ssrc:"+n[0])){e.splice(c,1),c--;continue}if(0===e[c].indexOf("a=ssrc:"+i[0])){e.splice(c,1),c--;continue}}0!=e[c].length||(e.splice(c,1),c--)}}}if(i[0]<0){g=-1,t=!1;for(c=0;c<e.length;c++){var I;if(I=e[c].match(/m=(\w+) */)){if("video"===I[1]){if(!(i[0]<0)){g=c;break}t=!0}else if(i[0]>-1){g=c;break}}else if(t){if(i[0]<0){var C=e[c].match(/a=ssrc:(\d+)/);if(C){i[0]=C[1],e.splice(c,1),c--;continue}}else{var d;if((d=e[c].match("a=ssrc:"+i[0]+" cname:(.+)"))&&(a=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" msid:(.+)"))&&(r=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" mslabel:(.+)"))&&(o=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" label:(.+)"))&&(s=d[1]),0===e[c].indexOf("a=ssrc:"+n[0])){e.splice(c,1),c--;continue}if(0===e[c].indexOf("a=ssrc:"+i[0])){e.splice(c,1),c--;continue}}0!=e[c].length||(e.splice(c,1),c--)}}}if(i[0]<0)return Bl.warn("Couldn't find the video SSRC, simulcasting NOT enabled"),A;g<0&&(g=e.length);i[1]=Math.floor(4294967295*Math.random()),i[2]=Math.floor(4294967295*Math.random()),n[1]=Math.floor(4294967295*Math.random()),n[2]=Math.floor(4294967295*Math.random());for(c=0;c<i.length;c++)a&&(e.splice(g,0,"a=ssrc:"+i[c]+" cname:"+a),g++),r&&(e.splice(g,0,"a=ssrc:"+i[c]+" msid:"+r),g++),o&&(e.splice(g,0,"a=ssrc:"+i[c]+" mslabel:"+o),g++),s&&(e.splice(g,0,"a=ssrc:"+i[c]+" label:"+s),g++),a&&(e.splice(g,0,"a=ssrc:"+n[c]+" cname:"+a),g++),r&&(e.splice(g,0,"a=ssrc:"+n[c]+" msid:"+r),g++),o&&(e.splice(g,0,"a=ssrc:"+n[c]+" mslabel:"+o),g++),s&&(e.splice(g,0,"a=ssrc:"+n[c]+" label:"+s),g++);e.splice(g,0,"a=ssrc-group:FID "+i[2]+" "+n[2]),e.splice(g,0,"a=ssrc-group:FID "+i[1]+" "+n[1]),e.splice(g,0,"a=ssrc-group:FID "+i[0]+" "+n[0]),e.splice(g,0,"a=ssrc-group:SIM "+i[0]+" "+i[1]+" "+i[2]),(A=e.join("\r\n")).endsWith("\r\n")||(A+="\r\n");return A}(A.sdp)):"firefox"!==Bl.webRTCAdapter.browserDetails.browser&&Bl.warn("simulcast=true, but this is not Chrome nor Firefox, ignoring")),n.mySdp=A.sdp,n.pc.setLocalDescription(A).catch(t.error),n.mediaConstraints=r,n.iceDone||n.trickle?(Bl.log("Offer ready"),Bl.debug(t),t.success(A)):Bl.log("Waiting for all candidates...")}),t.error)}(A,t,i):r.pc.setRemoteDescription(e).then((function(){if(Bl.log("Remote description accepted!"),r.remoteSdp=e.sdp,r.candidates&&r.candidates.length>0){for(var n=0;n<r.candidates.length;n++){var a=r.candidates[n];Bl.debug("Adding remote candidate:",a),a&&!0!==a.completed?r.pc.addIceCandidate(a):r.pc.addIceCandidate(Bl.endOfCandidates)}r.candidates=[]}!function(A,e,t){t=t||{},t.success="function"==typeof t.success?t.success:Bl.noop,t.error="function"==typeof t.error?t.error:Bl.noop,t.customizeSdp="function"==typeof t.customizeSdp?t.customizeSdp:Bl.noop;var i=m[A];if(null==i||null===i.webrtcStuff||void 0===i.webrtcStuff)return Bl.warn("Invalid handle"),void t.error("Invalid handle");var n=i.webrtcStuff,a=!0===t.simulcast;a?Bl.log("Creating answer (iceDone="+n.iceDone+", simulcast="+a+")"):Bl.log("Creating answer (iceDone="+n.iceDone+")");var r=null;if(Bl.unifiedPlan){r={};var o=null,s=null,g=n.pc.getTransceivers();if(g&&g.length>0)for(var c in g){var l=g[c];l.sender&&l.sender.track&&"audio"===l.sender.track.kind||l.receiver&&l.receiver.track&&"audio"===l.receiver.track.kind?o||(o=l):(l.sender&&l.sender.track&&"video"===l.sender.track.kind||l.receiver&&l.receiver.track&&"video"===l.receiver.track.kind)&&(s||(s=l))}var I=j(e),C=W(e);if(I||C){if(I&&C){if(o)try{o.setDirection?o.setDirection("sendrecv"):o.direction="sendrecv",Bl.log("Setting audio transceiver to sendrecv:",o)}catch(A){Bl.error(A)}}else if(I&&!C)try{o&&(o.setDirection?o.setDirection("sendonly"):o.direction="sendonly",Bl.log("Setting audio transceiver to sendonly:",o))}catch(A){Bl.error(A)}else if(!I&&C)if(o)try{o.setDirection?o.setDirection("recvonly"):o.direction="recvonly",Bl.log("Setting audio transceiver to recvonly:",o)}catch(A){Bl.error(A)}else o=n.pc.addTransceiver("audio",{direction:"recvonly"}),Bl.log("Adding recvonly audio transceiver:",o)}else if(e.removeAudio&&o)try{o.setDirection?o.setDirection("inactive"):o.direction="inactive",Bl.log("Setting audio transceiver to inactive:",o)}catch(A){Bl.error(A)}var d=Z(e),h=X(e);if(d||h){if(d&&h){if(s)try{s.setDirection?s.setDirection("sendrecv"):s.direction="sendrecv",Bl.log("Setting video transceiver to sendrecv:",s)}catch(A){Bl.error(A)}}else if(d&&!h){if(s)try{s.setDirection?s.setDirection("sendonly"):s.direction="sendonly",Bl.log("Setting video transceiver to sendonly:",s)}catch(A){Bl.error(A)}}else if(!d&&h)if(s)try{s.setDirection?s.setDirection("recvonly"):s.direction="recvonly",Bl.log("Setting video transceiver to recvonly:",s)}catch(A){Bl.error(A)}else s=n.pc.addTransceiver("video",{direction:"recvonly"}),Bl.log("Adding recvonly video transceiver:",s)}else if(e.removeVideo&&s)try{s.setDirection?s.setDirection("inactive"):s.direction="inactive",Bl.log("Setting video transceiver to inactive:",s)}catch(A){Bl.error(A)}}else r="firefox"==Bl.webRTCAdapter.browserDetails.browser||"edge"==Bl.webRTCAdapter.browserDetails.browser?{offerToReceiveAudio:W(e),offerToReceiveVideo:X(e)}:{mandatory:{OfferToReceiveAudio:W(e),OfferToReceiveVideo:X(e)}};Bl.debug(r);var B=Z(e);if(B&&a&&"firefox"===Bl.webRTCAdapter.browserDetails.browser){Bl.log("Enabling Simulcasting for Firefox (RID)");var u=n.pc.getSenders()[1];Bl.log(u);var E=u.getParameters();Bl.log(E);var f=Q(t.simulcastMaxBitrates);u.setParameters({encodings:[{rid:"high",active:!0,priority:"high",maxBitrate:f.high},{rid:"medium",active:!0,priority:"medium",maxBitrate:f.medium},{rid:"low",active:!0,priority:"low",maxBitrate:f.low}]})}n.pc.createAnswer(r).then((function(A){Bl.debug(A);var e={type:A.type,sdp:A.sdp};t.customizeSdp(e),A.sdp=e.sdp,Bl.log("Setting local description"),B&&a&&("chrome"===Bl.webRTCAdapter.browserDetails.browser?Bl.warn("simulcast=true, but this is an answer, and video breaks in Chrome if we enable it"):"firefox"!==Bl.webRTCAdapter.browserDetails.browser&&Bl.warn("simulcast=true, but this is not Chrome nor Firefox, ignoring")),n.mySdp=A.sdp,n.pc.setLocalDescription(A).catch(t.error),n.mediaConstraints=r,n.iceDone||n.trickle?t.success(A):Bl.log("Waiting for all candidates...")}),t.error)}(A,t,i)}),i.error)}function L(A,e,t){(t=t||{}).success="function"==typeof t.success?t.success:Bl.noop,t.error="function"==typeof t.error?t.error:V;var i=t.jsep;if(e&&i)return Bl.error("Provided a JSEP to a createOffer"),void t.error("Provided a JSEP to a createOffer");if(!(e||i&&i.type&&i.sdp))return Bl.error("A valid JSEP is required for createAnswer"),void t.error("A valid JSEP is required for createAnswer");t.media=t.media||{audio:!0,video:!0};var n=t.media,a=m[A];if(null==a||null===a.webrtcStuff||void 0===a.webrtcStuff)return Bl.warn("Invalid handle"),void t.error("Invalid handle");var r,o=a.webrtcStuff;if(o.trickle=(r=t.trickle,Bl.debug("isTrickleEnabled:",r),null==r||!0===r),void 0===o.pc||null===o.pc)n.update=!1,n.keepAudio=!1,n.keepVideo=!1;else if(void 0!==o.pc&&null!==o.pc){if(Bl.log("Updating existing media session"),n.update=!0,null!==t.stream&&void 0!==t.stream)t.stream!==o.myStream&&Bl.log("Renegotiation involves a new external stream");else{if(n.addAudio){if(n.keepAudio=!1,n.replaceAudio=!1,n.removeAudio=!1,n.audioSend=!0,o.myStream&&o.myStream.getAudioTracks()&&o.myStream.getAudioTracks().length)return Bl.error("Can't add audio stream, there already is one"),void t.error("Can't add audio stream, there already is one")}else n.removeAudio?(n.keepAudio=!1,n.replaceAudio=!1,n.addAudio=!1,n.audioSend=!1):n.replaceAudio&&(n.keepAudio=!1,n.addAudio=!1,n.removeAudio=!1,n.audioSend=!0);if(null===o.myStream||void 0===o.myStream?(n.replaceAudio&&(n.keepAudio=!1,n.replaceAudio=!1,n.addAudio=!0,n.audioSend=!0),j(n)&&(n.keepAudio=!1,n.addAudio=!0)):null===o.myStream.getAudioTracks()||void 0===o.myStream.getAudioTracks()||0===o.myStream.getAudioTracks().length?(n.replaceAudio&&(n.keepAudio=!1,n.replaceAudio=!1,n.addAudio=!0,n.audioSend=!0),j(n)&&(n.keepVideo=!1,n.addAudio=!0)):!j(n)||n.removeAudio||n.replaceAudio||(n.keepAudio=!0),n.addVideo){if(n.keepVideo=!1,n.replaceVideo=!1,n.removeVideo=!1,n.videoSend=!0,o.myStream&&o.myStream.getVideoTracks()&&o.myStream.getVideoTracks().length)return Bl.error("Can't add video stream, there already is one"),void t.error("Can't add video stream, there already is one")}else n.removeVideo?(n.keepVideo=!1,n.replaceVideo=!1,n.addVideo=!1,n.videoSend=!1):n.replaceVideo&&(n.keepVideo=!1,n.addVideo=!1,n.removeVideo=!1,n.videoSend=!0);null===o.myStream||void 0===o.myStream||null===o.myStream.getVideoTracks()||void 0===o.myStream.getVideoTracks()||0===o.myStream.getVideoTracks().length?(n.replaceVideo&&(n.keepVideo=!1,n.replaceVideo=!1,n.addVideo=!0,n.videoSend=!0),Z(n)&&(n.keepVideo=!1,n.addVideo=!0)):!Z(n)||n.removeVideo||n.replaceVideo||(n.keepVideo=!0),n.addData&&(n.data=!0)}if(j(n)&&n.keepAudio&&Z(n)&&n.keepVideo)return a.consentDialog(!1),void M(A,i,n,t,o.myStream)}if(n.update&&!o.streamExternal){if(n.removeAudio||n.replaceAudio){if(o.myStream&&o.myStream.getAudioTracks()&&o.myStream.getAudioTracks().length){var s=o.myStream.getAudioTracks()[0];Bl.log("Removing audio track:",s),o.myStream.removeTrack(s);try{s.stop()}catch(A){}}if(o.pc.getSenders()&&o.pc.getSenders().length){var g=!0;if(n.replaceAudio&&Bl.unifiedPlan&&(g=!1),g)for(var c in o.pc.getSenders()){(s=o.pc.getSenders()[c])&&s.track&&"audio"===s.track.kind&&(Bl.log("Removing audio sender:",s),o.pc.removeTrack(s))}}}if(n.removeVideo||n.replaceVideo){if(o.myStream&&o.myStream.getVideoTracks()&&o.myStream.getVideoTracks().length){s=o.myStream.getVideoTracks()[0];Bl.log("Removing video track:",s),o.myStream.removeTrack(s);try{s.stop()}catch(A){}}if(o.pc.getSenders()&&o.pc.getSenders().length){var l=!0;if(n.replaceVideo&&Bl.unifiedPlan&&(l=!1),l)for(var c in o.pc.getSenders()){(s=o.pc.getSenders()[c])&&s.track&&"video"===s.track.kind&&(Bl.log("Removing video sender:",s),o.pc.removeTrack(s))}}}}if(null!==t.stream&&void 0!==t.stream){var I=t.stream;if(Bl.log("MediaStream provided by the application"),Bl.debug(I),n.update&&o.myStream&&o.myStream!==t.stream&&!o.streamExternal){try{var d=o.myStream.getTracks();for(var h in d){var B=d[h];Bl.log(B),null!=B&&B.stop()}}catch(A){}o.myStream=null}return o.streamExternal=!0,a.consentDialog(!1),void M(A,i,n,t,I)}if(j(n)||Z(n)){if(!Bl.isGetUserMediaAvailable())return void t.error("getUserMedia not available");var u={mandatory:{},optional:[]};a.consentDialog(!0);var E=j(n);!0===E&&null!=n&&null!=n&&"object"===C(n.audio)&&(E=n.audio);var f=Z(n);if(!0===f&&null!=n&&null!=n){var Q=!0===t.simulcast,x=!0===t.simulcast2;if(!Q&&!x||i||void 0!==n.video&&!1!==n.video||(n.video="hires"),n.video&&"screen"!=n.video&&"window"!=n.video)if("object"===C(n.video))f=n.video;else{var p=0,y=0;"lowres"===n.video?(y=240,p=320):"lowres-16:9"===n.video?(y=180,p=320):"hires"===n.video||"hires-16:9"===n.video||"hdres"===n.video?(y=720,p=1280):"fhdres"===n.video?(y=1080,p=1920):"4kres"===n.video?(y=2160,p=3840):"stdres"===n.video?(y=480,p=640):"stdres-16:9"===n.video?(y=360,p=640):(Bl.log("Default video setting is stdres 4:3"),y=480,p=640),Bl.log("Adding media constraint:",n.video),f={height:{ideal:y},width:{ideal:p}},Bl.log("Adding video constraint:",f)}else if("screen"===n.video||"window"===n.video){var _=function(e,r){a.consentDialog(!1),e?t.error(e):M(A,i,n,t,r)},S=function(A,e,t){Bl.log("Adding media constraint (screen capture)"),Bl.debug(A),navigator.mediaDevices.getUserMedia(A).then((function(A){t?navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then((function(t){A.addTrack(t.getAudioTracks()[0]),e(null,A)})):e(null,A)})).catch((function(A){a.consentDialog(!1),e(A)}))};if(n.screenshareFrameRate||(n.screenshareFrameRate=3),navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia)return void navigator.mediaDevices.getDisplayMedia({video:!0}).then((function(e){a.consentDialog(!1),j(n)&&!n.keepAudio?navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then((function(a){e.addTrack(a.getAudioTracks()[0]),M(A,i,n,t,e)})):M(A,i,n,t,e)}),(function(A){a.consentDialog(!1),t.error(A)}));if("chrome"===Bl.webRTCAdapter.browserDetails.browser){var D=Bl.webRTCAdapter.browserDetails.version,w=33;window.navigator.userAgent.match("Linux")&&(w=35),D>=26&&D<=w?(u={video:{mandatory:{googLeakyBucket:!0,maxWidth:window.screen.width,maxHeight:window.screen.height,minFrameRate:n.screenshareFrameRate,maxFrameRate:n.screenshareFrameRate,chromeMediaSource:"screen"}},audio:j(n)&&!n.keepAudio},S(u,_)):Bl.extension.getScreen((function(A,e){if(A)return a.consentDialog(!1),t.error(A);(u={audio:!1,video:{mandatory:{chromeMediaSource:"desktop",maxWidth:window.screen.width,maxHeight:window.screen.height,minFrameRate:n.screenshareFrameRate,maxFrameRate:n.screenshareFrameRate},optional:[{googLeakyBucket:!0},{googTemporalLayeredScreencast:!0}]}}).video.mandatory.chromeMediaSourceId=e,S(u,_,j(n)&&!n.keepAudio)}))}else if("firefox"===Bl.webRTCAdapter.browserDetails.browser){if(!(Bl.webRTCAdapter.browserDetails.version>=33)){var v=new Error("NavigatorUserMediaError");return v.name="Your version of Firefox does not support screen sharing, please install Firefox 33 (or more recent versions)",a.consentDialog(!1),void t.error(v)}u={video:{mozMediaSource:n.video,mediaSource:n.video},audio:j(n)&&!n.keepAudio},S(u,(function(A,e){if(_(A,e),!A)var t=e.currentTime,i=window.setInterval((function(){e||window.clearInterval(i),e.currentTime==t&&(window.clearInterval(i),e.onended&&e.onended()),t=e.currentTime}),500)}))}return}}null!=n&&"screen"===n.video||navigator.mediaDevices.enumerateDevices().then((function(e){var r=e.some((function(A){return"audioinput"===A.kind})),o=function(A){if(Bl.debug("isScreenSendEnabled:",A),null==A)return!1;if("object"!==C(A.video)||"object"!==C(A.video.mandatory))return!1;var e=A.video.mandatory;if(e.chromeMediaSource)return"desktop"===e.chromeMediaSource||"screen"===e.chromeMediaSource;if(e.mozMediaSource)return"window"===e.mozMediaSource||"screen"===e.mozMediaSource;if(e.mediaSource)return"window"===e.mediaSource||"screen"===e.mediaSource;return!1}(n)||e.some((function(A){return"videoinput"===A.kind})),s=j(n),g=Z(n),c=function(A){return Bl.debug("isAudioSendRequired:",A),null!=A&&(!1!==A.audio&&!1!==A.audioSend&&(void 0!==A.failIfNoAudio&&null!==A.failIfNoAudio&&!0===A.failIfNoAudio))}(n),l=function(A){return Bl.debug("isVideoSendRequired:",A),null!=A&&(!1!==A.video&&!1!==A.videoSend&&(void 0!==A.failIfNoVideo&&null!==A.failIfNoVideo&&!0===A.failIfNoVideo))}(n);if(s||g||c||l){var d=!!s&&r,h=!!g&&o;if(!d&&!h)return a.consentDialog(!1),t.error("No capture device found"),!1;if(!d&&c)return a.consentDialog(!1),t.error("Audio capture is required, but no capture device found"),!1;if(!h&&l)return a.consentDialog(!1),t.error("Video capture is required, but no capture device found"),!1}var B={audio:!(!r||n.keepAudio)&&E,video:!(!o||n.keepVideo)&&f};n.encodings&&(B=n.encodings),Bl.debug("getUserMedia constraints",B),B.audio||B.video?(console.log("gumConstraints_________",B,n.encodings),navigator.mediaDevices.getUserMedia(n.encodings?n.encodings:B).then((function(e){a.consentDialog(!1),M(A,i,n,t,e)})).catch((function(A){a.consentDialog(!1),t.error({code:A.code,name:A.name,message:A.message})}))):(a.consentDialog(!1),M(A,i,n,t,I))})).catch((function(A){a.consentDialog(!1),t.error("enumerateDevices error",A)}))}else M(A,i,n,t)}function Y(A,e){(e=e||{}).success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:V;var t=e.jsep,i=m[A];if(null==i||null===i.webrtcStuff||void 0===i.webrtcStuff)return Bl.warn("Invalid handle"),void e.error("Invalid handle");var n=i.webrtcStuff;if(null!=t){if(null===n.pc)return Bl.warn("Wait, no PeerConnection?? if this is an answer, use createAnswer and not handleRemoteJsep"),void e.error("No PeerConnection: if this is an answer, use createAnswer and not handleRemoteJsep");n.pc.setRemoteDescription(t).then((function(){if(Bl.log("Remote description accepted!"),n.remoteSdp=t.sdp,n.candidates&&n.candidates.length>0){for(var A=0;A<n.candidates.length;A++){var i=n.candidates[A];Bl.debug("Adding remote candidate:",i),i&&!0!==i.completed?n.pc.addIceCandidate(i):n.pc.addIceCandidate(Bl.endOfCandidates)}n.candidates=[]}e.success()}),e.error)}else e.error("Invalid JSEP")}function G(A,e){var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return Bl.warn("Invalid handle"),0;var i=e?"remote":"local",n=t.webrtcStuff;return n.volume[i]||(n.volume[i]={value:0}),n.pc.getStats&&"chrome"===Bl.webRTCAdapter.browserDetails.browser?!e||null!==n.remoteStream&&void 0!==n.remoteStream?e||null!==n.myStream&&void 0!==n.myStream?null===n.volume[i].timer||void 0===n.volume[i].timer?(Bl.log("Starting "+i+" volume monitor"),n.volume[i].timer=setInterval((function(){n.pc.getStats((function(A){for(var t=A.result(),a=0;a<t.length;a++){var r=t[a];"ssrc"==r.type&&(e&&r.stat("audioOutputLevel")?n.volume[i].value=parseInt(r.stat("audioOutputLevel")):!e&&r.stat("audioInputLevel")&&(n.volume[i].value=parseInt(r.stat("audioInputLevel"))))}}))}),200),0):n.volume[i].value:(Bl.warn("Local stream unavailable"),0):(Bl.warn("Remote stream unavailable"),0):(Bl.warn("Getting the "+i+" volume unsupported by browser"),0)}function U(A,e){var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return Bl.warn("Invalid handle"),!0;var i=t.webrtcStuff;return null===i.pc||void 0===i.pc?(Bl.warn("Invalid PeerConnection"),!0):void 0===i.myStream||null===i.myStream?(Bl.warn("Invalid local MediaStream"),!0):e?null===i.myStream.getVideoTracks()||void 0===i.myStream.getVideoTracks()||0===i.myStream.getVideoTracks().length?(Bl.warn("No video track"),!0):!i.myStream.getVideoTracks()[0].enabled:null===i.myStream.getAudioTracks()||void 0===i.myStream.getAudioTracks()||0===i.myStream.getAudioTracks().length?(Bl.warn("No audio track"),!0):!i.myStream.getAudioTracks()[0].enabled}function J(A,e,t){var i=m[A];if(null==i||null===i.webrtcStuff||void 0===i.webrtcStuff)return Bl.warn("Invalid handle"),!1;var n=i.webrtcStuff;return null===n.pc||void 0===n.pc?(Bl.warn("Invalid PeerConnection"),!1):void 0===n.myStream||null===n.myStream?(Bl.warn("Invalid local MediaStream"),!1):e?null===n.myStream.getVideoTracks()||void 0===n.myStream.getVideoTracks()||0===n.myStream.getVideoTracks().length?(Bl.warn("No video track"),!1):(n.myStream.getVideoTracks()[0].enabled=!t,!0):null===n.myStream.getAudioTracks()||void 0===n.myStream.getAudioTracks()||0===n.myStream.getAudioTracks().length?(Bl.warn("No audio track"),!1):(n.myStream.getAudioTracks()[0].enabled=!t,!0)}function H(A,e){var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return Bl.warn("Invalid handle"),"Invalid handle";var i=t.webrtcStuff;return null===i.pc||void 0===i.pc?"Invalid PeerConnection":i.pc.getStats?void i.pc.getStats().then((function(A){A.forEach((function(A){if(A){var t=!1;if(("video"===A.mediaType||A.id.toLowerCase().indexOf("video")>-1)&&"inbound-rtp"===A.type&&A.id.indexOf("rtcp")<0?t=!0:"ssrc"!=A.type||!A.bytesReceived||"VP8"!==A.googCodecName&&""!==A.googCodecName||(t=!0),t)if(e&&e(A),i.bitrate.bsnow=A.bytesReceived,i.bitrate.tsnow=A.timestamp,null===i.bitrate.bsbefore||null===i.bitrate.tsbefore)i.bitrate.bsbefore=i.bitrate.bsnow,i.bitrate.tsbefore=i.bitrate.tsnow;else{var n=i.bitrate.tsnow-i.bitrate.tsbefore;"safari"==Bl.webRTCAdapter.browserDetails.browser&&(n/=1e3);var a=Math.round(8*(i.bitrate.bsnow-i.bitrate.bsbefore)/n);"safari"===Bl.webRTCAdapter.browserDetails.browser&&(a=parseInt(a/1e3)),i.bitrate.value=a+" kbits/sec",i.bitrate.bsbefore=i.bitrate.bsnow,i.bitrate.tsbefore=i.bitrate.tsnow}}}))})):(Bl.warn("Getting the video bitrate unsupported by browser"),"Feature unsupported by browser")}function K(A){var e=m[A];if(null==e||null===e.webrtcStuff||void 0===e.webrtcStuff)return Bl.warn("Invalid handle"),"Invalid handle";var t=e.webrtcStuff;return null===t.pc||void 0===t.pc?"Invalid PeerConnection":t.pc.getStats?null===t.bitrate.timer||void 0===t.bitrate.timer?(Bl.log("Starting bitrate timer (via getStats)"),t.bitrate.timer=setInterval((function(){t.pc.getStats().then((function(A){A.forEach((function(A){if(A){var e=!1;if(("video"===A.mediaType||A.id.toLowerCase().indexOf("video")>-1)&&"inbound-rtp"===A.type&&A.id.indexOf("rtcp")<0?e=!0:"ssrc"!=A.type||!A.bytesReceived||"VP8"!==A.googCodecName&&""!==A.googCodecName||(e=!0),e)if(t.bitrate.bsnow=A.bytesReceived,t.bitrate.tsnow=A.timestamp,null===t.bitrate.bsbefore||null===t.bitrate.tsbefore)t.bitrate.bsbefore=t.bitrate.bsnow,t.bitrate.tsbefore=t.bitrate.tsnow;else{var i=t.bitrate.tsnow-t.bitrate.tsbefore;"safari"==Bl.webRTCAdapter.browserDetails.browser&&(i/=1e3);var n=Math.round(8*(t.bitrate.bsnow-t.bitrate.bsbefore)/i);"safari"===Bl.webRTCAdapter.browserDetails.browser&&(n=parseInt(n/1e3)),t.bitrate.value=n+" kbits/sec",t.bitrate.bsbefore=t.bitrate.bsnow,t.bitrate.tsbefore=t.bitrate.tsnow}}}))}))}),1e3),"0 kbits/sec"):t.bitrate.value:(Bl.warn("Getting the video bitrate unsupported by browser"),"Feature unsupported by browser")}function V(A){Bl.error("WebRTC error:",A)}function O(A,e){Bl.log("Cleaning WebRTC stuff");var n=m[A];if(null!=n){var a=n.webrtcStuff;if(null!=a){if(!0===e){var r={rtcgw:"hangup",transaction:Bl.randomString(12)};null!==n.token&&void 0!==n.token&&(r.token=n.token),null!=u&&(r.apisecret=u),Bl.debug("Sending hangup request (handle="+A+"):"),Bl.debug(r),t?(r.session_id=p,r.handle_id=A,i.send(JSON.stringify(r))):Bl.httpAPICall(s+"/"+p+"/"+A,{verb:"POST",withCredentials:d,body:r})}a.remoteStream=null,a.volume&&(a.volume.local&&a.volume.local.timer&&clearInterval(a.volume.local.timer),a.volume.remote&&a.volume.remote.timer&&clearInterval(a.volume.remote.timer)),a.volume={},a.bitrate.timer&&clearInterval(a.bitrate.timer),a.bitrate.timer=null,a.bitrate.bsnow=null,a.bitrate.bsbefore=null,a.bitrate.tsnow=null,a.bitrate.tsbefore=null,a.bitrate.value=null;try{if(!a.streamExternal&&null!==a.myStream&&void 0!==a.myStream){Bl.log("Stopping local stream tracks");var o=a.myStream.getTracks();for(var g in o){var c=o[g];Bl.log(c),null!=c&&c.stop()}}}catch(A){}a.streamExternal=!1,a.myStream=null;try{a.pc.close()}catch(A){}a.pc=null,a.candidates=null,a.mySdp=null,a.remoteSdp=null,a.iceDone=!1,a.dataChannel={},a.dtmfSender=null}n.oncleanup()}}function j(A){return Bl.debug("isAudioSendEnabled:",A),null==A||!1!==A.audio&&(void 0===A.audioSend||null===A.audioSend||!0===A.audioSend)}function W(A){return Bl.debug("isAudioRecvEnabled:",A),null==A||!1!==A.audio&&(void 0===A.audioRecv||null===A.audioRecv||!0===A.audioRecv)}function Z(A){return Bl.debug("isVideoSendEnabled:",A),null==A||!1!==A.video&&(void 0===A.videoSend||null===A.videoSend||!0===A.videoSend)}function X(A){return Bl.debug("isVideoRecvEnabled:",A),null==A||!1!==A.video&&(void 0===A.videoRecv||null===A.videoRecv||!0===A.videoRecv)}F(A),this.getServer=function(){return s},this.isConnected=function(){return x},this.reconnect=function(A){(A=A||{}).success="function"==typeof A.success?A.success:Bl.noop,A.error="function"==typeof A.error?A.error:Bl.noop,A.reconnect=!0,F(A)},this.getSessionId=function(){return p},this.destroy=function(e){!function(e){e=e||{},e.success="function"==typeof e.success?e.success:Bl.noop;var r=!0;void 0!==e.asyncRequest&&null!==e.asyncRequest&&(r=!0===e.asyncRequest);var o=!0;void 0!==e.notifyDestroyed&&null!==e.notifyDestroyed&&(o=!0===e.notifyDestroyed);var g=!1;void 0!==e.cleanupHandles&&null!==e.cleanupHandles&&(g=!0===e.cleanupHandles);if(Bl.log("Destroying session "+p+" (async="+r+")"),!x)return Bl.warn("Is the server down? (connected=false)"),void e.success();if(null==p)return Bl.warn("No session to destroy"),e.success(),void(o&&A.destroyed());if(g)for(var c in m)T(c,{noRequest:!0});var l={rtcgw:"destroy",transaction:Bl.randomString(12)};null!=B&&(l.token=B);null!=u&&(l.apisecret=u);if(t){l.session_id=p;var I=function(){for(var A in n)i.removeEventListener(A,n[A]);i.removeEventListener("message",C),i.removeEventListener("error",h),a&&clearTimeout(a),i.close()},C=function(t){var i=JSON.parse(t.data);i.session_id==l.session_id&&i.transaction==l.transaction&&(I(),e.success(),o&&A.destroyed())},h=function(t){I(),e.error("Failed to destroy the server: Is the server down?"),o&&A.destroyed()};return i.addEventListener("message",C),i.addEventListener("error",h),void i.send(JSON.stringify(l))}Bl.httpAPICall(s+"/"+p,{verb:"POST",async:r,withCredentials:d,body:l,success:function(t){Bl.log("Destroyed session:"),Bl.debug(t),p=null,x=!1,"success"!==t.rtcgw&&Bl.error("Ooops: "+t.error.code+" "+t.error.reason),e.success(),o&&A.destroyed()},error:function(t,i){Bl.error(t+":",i),p=null,x=!1,e.success(),o&&A.destroyed(),pluginHandlesp}})}(e)},this.attach=function(A){!function(A){if(A=A||{},A.success="function"==typeof A.success?A.success:Bl.noop,A.error="function"==typeof A.error?A.error:Bl.noop,A.consentDialog="function"==typeof A.consentDialog?A.consentDialog:Bl.noop,A.iceState="function"==typeof A.iceState?A.iceState:Bl.noop,A.mediaState="function"==typeof A.mediaState?A.mediaState:Bl.noop,A.webrtcState="function"==typeof A.webrtcState?A.webrtcState:Bl.noop,A.slowLink="function"==typeof A.slowLink?A.slowLink:Bl.noop,A.onmessage="function"==typeof A.onmessage?A.onmessage:Bl.noop,A.onlocalstream="function"==typeof A.onlocalstream?A.onlocalstream:Bl.noop,A.onremotestream="function"==typeof A.onremotestream?A.onremotestream:Bl.noop,A.ondata="function"==typeof A.ondata?A.ondata:Bl.noop,A.ondataopen="function"==typeof A.ondataopen?A.ondataopen:Bl.noop,A.oncleanup="function"==typeof A.oncleanup?A.oncleanup:Bl.noop,A.ondetached="function"==typeof A.ondetached?A.ondetached:Bl.noop,!x)return Bl.warn("Is the server down? (connected=false)"),void A.error("Is the server down? (connected=false)");var e=A.plugin;if(null==e)return Bl.error("Invalid plugin"),void A.error("Invalid plugin");var n=A.opaqueId,a=A.token?A.token:B,r=Bl.randomString(12),o={rtcgw:"attach",plugin:e,opaque_id:n,transaction:r};null!=a&&(o.token=a);null!=u&&(o.apisecret=u);if(t)return S[r]=function(t){if(Bl.debug(t),"success"!==t.rtcgw)return Bl.error("Ooops: "+t.error.code+" "+t.error.reason),void A.error("Ooops: "+t.error.code+" "+t.error.reason);var i=t.data.id;Bl.log("Created handle: "+i);var n={session:y,plugin:e,id:i,token:a,detached:!1,webrtcStuff:{started:!1,myStream:null,streamExternal:!1,remoteStream:null,mySdp:null,mediaConstraints:null,pc:null,dataChannel:{},dtmfSender:null,trickle:!0,iceDone:!1,volume:{value:null,timer:null},bitrate:{value:null,bsnow:null,bsbefore:null,tsnow:null,tsbefore:null,timer:null}},getId:function(){return i},getPlugin:function(){return e},getVolume:function(){return G(i,!0)},getRemoteVolume:function(){return G(i,!0)},getLocalVolume:function(){return G(i,!1)},isAudioMuted:function(){return U(i,!1)},muteAudio:function(){return J(i,!1,!0)},unmuteAudio:function(){return J(i,!1,!1)},isVideoMuted:function(){return U(i,!0)},muteVideo:function(){return J(i,!0,!0)},unmuteVideo:function(){return J(i,!0,!1)},getBitrate:function(){return K(i)},getNetworkQuality:function(A){H(i,A)},send:function(A){b(i,A)},data:function(A){P(i,A)},dtmf:function(A){N(i,A)},consentDialog:A.consentDialog,iceState:A.iceState,mediaState:A.mediaState,webrtcState:A.webrtcState,slowLink:A.slowLink,onmessage:A.onmessage,createOffer:function(A){L(i,!0,A)},createAnswer:function(A){L(i,!1,A)},handleRemoteJsep:function(A){Y(i,A)},onlocalstream:A.onlocalstream,onremotestream:A.onremotestream,ondata:A.ondata,ondataopen:A.ondataopen,oncleanup:A.oncleanup,ondetached:A.ondetached,hangup:function(A){O(i,!0===A)},detach:function(A){T(i,A)}};m[i]=n,A.success(n)},o.session_id=p,void i.send(JSON.stringify(o));Bl.httpAPICall(s+"/"+p,{verb:"POST",withCredentials:d,body:o,success:function(t){if(Bl.debug(t),"success"!==t.rtcgw)return Bl.error("Ooops: "+t.error.code+" "+t.error.reason),void A.error("Ooops: "+t.error.code+" "+t.error.reason);var i=t.data.id;Bl.log("Created handle: "+i);var n={session:y,plugin:e,id:i,token:a,detached:!1,webrtcStuff:{started:!1,myStream:null,streamExternal:!1,remoteStream:null,mySdp:null,mediaConstraints:null,pc:null,dataChannel:{},dtmfSender:null,trickle:!0,iceDone:!1,volume:{value:null,timer:null},bitrate:{value:null,bsnow:null,bsbefore:null,tsnow:null,tsbefore:null,timer:null}},getId:function(){return i},getPlugin:function(){return e},getVolume:function(){return G(i,!0)},getRemoteVolume:function(){return G(i,!0)},getLocalVolume:function(){return G(i,!1)},isAudioMuted:function(){return U(i,!1)},muteAudio:function(){return J(i,!1,!0)},unmuteAudio:function(){return J(i,!1,!1)},isVideoMuted:function(){return U(i,!0)},muteVideo:function(){return J(i,!0,!0)},unmuteVideo:function(){return J(i,!0,!1)},getBitrate:function(){return K(i)},getNetworkQuality:function(A){H(i,A)},send:function(A){b(i,A)},data:function(A){P(i,A)},dtmf:function(A){N(i,A)},consentDialog:A.consentDialog,iceState:A.iceState,mediaState:A.mediaState,webrtcState:A.webrtcState,slowLink:A.slowLink,onmessage:A.onmessage,createOffer:function(A){L(i,!0,A)},createAnswer:function(A){L(i,!1,A)},handleRemoteJsep:function(A){Y(i,A)},onlocalstream:A.onlocalstream,onremotestream:A.onremotestream,ondata:A.ondata,ondataopen:A.ondataopen,oncleanup:A.oncleanup,ondetached:A.ondetached,hangup:function(A){O(i,!0===A)},detach:function(A){T(i,A)}};m[i]=n,A.success(n)},error:function(A,e){Bl.error(A+":",e)}})}(A)}}Bl.useDefaultDependencies=function(A){var e=A&&A.fetch||fetch,t=A&&A.Promise||Promise,i=A&&A.WebSocket||WebSocket;return{newWebSocket:function(A,e){return new i(A,e)},extension:A&&A.extension||hl,isArray:function(A){return Array.isArray(A)},webRTCAdapter:A&&A.adapter||adapter,httpAPICall:function(A,i){var n={method:i.verb,headers:{Accept:"application/json, text/plain, */*"},cache:"no-cache"};"POST"===i.verb&&(n.headers["Content-Type"]="application/json"),void 0!==i.withCredentials&&(n.credentials=!0===i.withCredentials?"include":i.withCredentials?i.withCredentials:"omit"),void 0!==i.body&&(n.body=JSON.stringify(i.body));var a=e(A,n).catch((function(A){return t.reject({message:"Probably a network error, is the server down?",error:A})}));if(void 0!==i.timeout){var r=new t((function(A,e){var t=setTimeout((function(){return clearTimeout(t),e({message:"Request timed out",timeout:i.timeout})}),i.timeout)}));a=t.race([a,r])}return a.then((function(A){return A.ok?C(i.success)===C(Bl.noop)?A.json().then((function(A){i.success(A)})).catch((function(e){return t.reject({message:"Failed to parse response body",error:e,response:A})})):void 0:t.reject({message:"API call failed",response:A})})).catch((function(A){C(i.error)===C(Bl.noop)&&i.error(A.message||"<< internal error >>",A)})),a}}},Bl.useOldDependencies=function(A){var e=A&&A.jQuery||jQuery,t=A&&A.WebSocket||WebSocket;return{newWebSocket:function(A,e){return new t(A,e)},isArray:function(A){return e.isArray(A)},extension:A&&A.extension||hl,webRTCAdapter:A&&A.adapter||adapter,httpAPICall:function(A,t){var i=void 0!==t.body?{contentType:"application/json",data:JSON.stringify(t.body)}:{},n=void 0!==t.withCredentials?{xhrFields:{withCredentials:t.withCredentials}}:{};return e.ajax(e.extend(i,n,{url:A,type:t.verb,cache:!1,dataType:"json",async:t.async,timeout:t.timeout,success:function(A){C(t.success)===C(Bl.noop)&&t.success(A)},error:function(A,e,i){C(t.error)===C(Bl.noop)&&t.error(e,i)}}))}}},Bl.noop=function(){},Bl.dataChanDefaultLabel="JanusDataChannel",Bl.endOfCandidates=null,Bl.init=function(A){if((A=A||{}).callback="function"==typeof A.callback?A.callback:Bl.noop,!0===Bl.initDone)A.callback();else{if("undefined"!=typeof console&&void 0!==console.log||(console={log:function(){}}),Bl.trace=Bl.noop,Bl.debug=Bl.noop,Bl.vdebug=Bl.noop,Bl.log=Bl.noop,Bl.warn=Bl.noop,Bl.error=Bl.noop,!0===A.debug||"all"===A.debug)Bl.trace=console.trace.bind(console),Bl.debug=console.debug.bind(console),Bl.vdebug=console.debug.bind(console),Bl.log=console.log.bind(console),Bl.warn=console.warn.bind(console),Bl.error=console.error.bind(console);else if(Array.isArray(A.debug))for(var e in A.debug){var t=A.debug[e];switch(t){case"trace":Bl.trace=console.trace.bind(console);break;case"debug":Bl.debug=console.debug.bind(console);break;case"vdebug":Bl.vdebug=console.debug.bind(console);break;case"log":Bl.log=console.log.bind(console);break;case"warn":Bl.warn=console.warn.bind(console);break;case"error":Bl.error=console.error.bind(console);break;default:console.error("Unknown debugging option '"+t+"' (supported: 'trace', 'debug', 'vdebug', 'log', warn', 'error')")}}var i=A.dependencies||Bl.useDefaultDependencies();Bl.isArray=i.isArray,Bl.webRTCAdapter=i.webRTCAdapter,Bl.httpAPICall=i.httpAPICall,Bl.newWebSocket=i.newWebSocket,Bl.extension=i.extension,Bl.extension.init(),Bl.listDevices=function(A,e){A="function"==typeof A?A:Bl.noop,null==e&&(e={audio:!0,video:!0}),Bl.isGetUserMediaAvailable()?navigator.mediaDevices.getUserMedia(e).then((function(e){navigator.mediaDevices.enumerateDevices().then((function(t){Bl.debug(t),A(t);try{var i=e.getTracks();for(var n in i){var a=i[n];null!=a&&a.stop()}}catch(A){}}))})).catch((function(e){Bl.error(e),A([])})):(Bl.warn("navigator.mediaDevices unavailable"),A([]))},Bl.attachMediaStream=function(A,e){"chrome"===Bl.webRTCAdapter.browserDetails.browser?Bl.webRTCAdapter.browserDetails.version>=52?A.srcObject=e:void 0!==A.src?A.src=URL.createObjectURL(e):Bl.error("Error attaching stream to element"):A.srcObject=e},Bl.reattachMediaStream=function(A,e){"chrome"===Bl.webRTCAdapter.browserDetails.browser?Bl.webRTCAdapter.browserDetails.version>=52?A.srcObject=e.srcObject:void 0!==A.src?A.src=e.src:Bl.error("Error reattaching stream to element"):A.srcObject=e.srcObject};var n=["iPad","iPhone","iPod"].indexOf(navigator.platform)>=0?"pagehide":"beforeunload",a=window["on"+n];if(window.addEventListener(n,(function(A){for(var e in Bl.log("Closing window"),Bl.sessions)null!==Bl.sessions[e]&&void 0!==Bl.sessions[e]&&Bl.sessions[e].destroyOnUnload&&(Bl.log("Destroying session "+e),Bl.sessions[e].destroy({asyncRequest:!1,notifyDestroyed:!1}));a&&"function"==typeof a&&a()})),Bl.safariVp8=!1,"safari"===Bl.webRTCAdapter.browserDetails.browser&&Bl.webRTCAdapter.browserDetails.version>=605)if(RTCRtpSender&&RTCRtpSender.getCapabilities&&RTCRtpSender.getCapabilities("video")&&RTCRtpSender.getCapabilities("video").codecs&&RTCRtpSender.getCapabilities("video").codecs.length){for(var e in RTCRtpSender.getCapabilities("video").codecs){var r=RTCRtpSender.getCapabilities("video").codecs[e];if(r&&r.mimeType&&"video/vp8"===r.mimeType.toLowerCase()){Bl.safariVp8=!0;break}}Bl.safariVp8?Bl.log("This version of Safari supports VP8"):Bl.warn("This version of Safari does NOT support VP8: if you're using a Technology Preview, try enabling the 'WebRTC VP8 codec' setting in the 'Experimental Features' Develop menu")}else{var o=new RTCPeerConnection({},{});o.createOffer({offerToReceiveVideo:!0}).then((function(A){Bl.safariVp8=-1!==A.sdp.indexOf("VP8"),Bl.safariVp8?Bl.log("This version of Safari supports VP8"):Bl.warn("This version of Safari does NOT support VP8: if you're using a Technology Preview, try enabling the 'WebRTC VP8 codec' setting in the 'Experimental Features' Develop menu"),o.close(),o=null}))}if(Bl.unifiedPlan=!1,"firefox"===Bl.webRTCAdapter.browserDetails.browser&&Bl.webRTCAdapter.browserDetails.version>=59)Bl.unifiedPlan=!0;else if("chrome"===Bl.webRTCAdapter.browserDetails.browser&&Bl.webRTCAdapter.browserDetails.version<72)Bl.unifiedPlan=!1;else if("currentDirection"in RTCRtpTransceiver.prototype){var s=new RTCPeerConnection;try{s.addTransceiver("audio"),Bl.unifiedPlan=!0}catch(A){}s.close()}else Bl.unifiedPlan=!1;Bl.initDone=!0,A.callback()}},Bl.isWebrtcSupported=function(){return void 0!==window.RTCPeerConnection&&null!==window.RTCPeerConnection},Bl.isGetUserMediaAvailable=function(){return void 0!==navigator.mediaDevices&&null!==navigator.mediaDevices&&void 0!==navigator.mediaDevices.getUserMedia&&null!==navigator.mediaDevices.getUserMedia},Bl.randomString=function(A){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="",i=0;i<A;i++){var n=Math.floor(62*Math.random());t+=e.substring(n,n+1)}return t},window.Janus=Bl;var ul="V1.0",El="https://open.ys7.com",fl={},Ql=function(A,e){fl[A]||(fl[A]=[]),fl[A].push(e)},xl=function(){var A=Array.prototype.shift.call(arguments),e=fl[A];if(!e||0===e.length)return!1;for(var t,i=0;t=e[i];i++)t.apply(this,arguments)};function pl(){var A={};return A.promise=new Promise((function(e,t){A.resolve=e,A.reject=t})),A}var ml,yl,_l,Sl,Dl=function(){return a((function A(e){t(this,A),o(this,"subscribe",(function(A){var e=pl(),t={cmdType:"subremote",streamtype:A.type,customId:A.clientId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId},i=null;return window["ezuikit-webrtc"].opt.janus.attach({plugin:"rtcgw.plugin.sts",opaqueId:window["ezuikit-webrtc"].opt.opaqueId,success:function(n){console.log("pluginHandle",n),8==A.type?window["ezuikit-webrtc"].opt.subscribeScreenHandle=n:(window["ezuikit-webrtc"].opt["".concat(A.clientId)]=n,1==A.type&&window["ezuikit-webrtc"].opt["".concat(A.clientId)].send({message:{cmdType:"unsubremote",streamtype:2,customId:A.clientId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId},success:function(){},error:function(A){}})),(i=n).createOffer({media:{videoSend:!1,audioSend:!1,audioRecv:!0,videoRecv:!0,audio:!0,video:!0,data:!1},simulcast:!1,simulcast2:!1,success:function(A){Janus.debug("remoteFeed createOffer Got SDP!"),Janus.debug(A),i.send({message:t,jsep:A})},error:function(A){Janus.error("remoteFeed WebRTC error:",A),e.reject(A)}})},error:function(A){console.error(" -- Error attaching plugin...",A),e.reject(A)},consentDialog:function(A){Janus.debug("Consent dialog should be "+(A?"on":"off")+" now")},iceState:function(A){switch(Janus.log("ICE state changed to "+A),A){case"connected":console.log("ice connect success");break;case"disconnected":console.log("ice connect loss")}},mediaState:function(A,e){Janus.log("Janus "+(e?"started":"stopped")+" receiving our "+A)},webrtcState:function(A){Janus.log("Janus says our WebRTC PeerConnection is "+(A?"up":"down")+" now")},slowLink:function(A,e){Janus.warn("Janus reports problems "+(A?"sending":"receiving")+" packets on this PeerConnection ("+e+" lost packets)")},onmessage:function(A,e){Janus.debug(" ::: Got a message :::"),Janus.debug(A),null!=e&&(Janus.debug("Handling SDP as well..."),Janus.debug(e),i.handleRemoteJsep({jsep:e})),"subremoteack"===A.rtcgw&&xl("subremoteack",A)},onlocalstream:function(A){},onremotestream:function(t){console.log("remoteStream==================================",t);var i={clientId:A.clientId,stream:t,streamType:A.type};e.resolve(i),xl("remoteStream",i)},ondataopen:function(A){Janus.log("The DataChannel is available!")},ondata:function(A){Janus.debug("We got data from the DataChannel! "+A)},oncleanup:function(){Janus.log(" ::: Got a cleanup notification :::")}}),e.promise})),o(this,"subscribeStream",(function(A){var e=pl(),t={cmdType:"resumesubremote",streamtype:A.type,customId:A.clientId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return window["ezuikit-webrtc"].opt["".concat(A.clientId)]&&window["ezuikit-webrtc"].opt["".concat(A.clientId)].send({message:t,success:function(){e.resolve("success")},error:function(A){e.reject(A)}}),e.promise})),o(this,"unsubscribe",(function(A){var e=pl(),t={cmdType:"unsubremote",streamtype:A.type,customId:A.clientId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return 8==A.type?window["ezuikit-webrtc"].opt.subscribeScreenHandle.send({message:t,success:function(){window["ezuikit-webrtc"].opt.subscribeScreenHandle.detach({noRequest:!1,success:function(){e.resolve("success")}})},error:function(A){e.reject(A)}}):window["ezuikit-webrtc"].opt["".concat(A.clientId)].send({message:t,success:function(){3==A.type?window["ezuikit-webrtc"].opt["".concat(A.clientId)].detach({noRequest:!1,success:function(){e.resolve("success")}}):e.resolve("success")},error:function(A){e.reject(A)}}),e.promise})),o(this,"unsubscribeStream",(function(A){var e=pl(),t={cmdType:"pausesubremote",streamtype:A.type,customId:A.clientId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return window["ezuikit-webrtc"].opt["".concat(A.clientId)].send({message:t,success:function(){e.resolve("success")},error:function(A){e.reject(A)}}),e.promise})),o(this,"listen",(function(){return Ql.apply(void 0,arguments)})),this.initEZWEBPlayer(e)}),[{key:"initEZWEBPlayer",value:function(A){console.log("params",A),window["ezuikit-webrtc"]={opt:{roomParams:{room:0,userId:A.userId,video:1,internalRoomId:null,roomId:A.roomId,clientId:null,rtctoken:A.rtctoken},janus:null,mainHandle:null,sts:null,screenHandle:null,subscribeScreenHandle:null,opaqueId:"sts-"+Janus.randomString(12),localStreamType:null,server:null,accessToken:A.accessToken,stream:"",screenStream:null,apiDomain:El,cln:{local:{username:"",client_id:""}}},videoParams:{},audioParams:{},cameraId:null,microphoneId:null,bitrate:1e5,frameRate:15,width:320,height:240},S("".concat(El,"/api/v3/rtc/wss"),"POST",{appId:A.appId,roomId:A.roomId,customId:A.userId,accessToken:A.accessToken},{"Content-Type":"application/x-www-form-urlencoded",accessToken:A.accessToken},(function(e){if(console.log("data",e),200!=e.meta.code)return void A.handleError(e.meta);var t=e.data;t.clientId;var i=t.domain;t.internalRoomId;var n=t.wssPath;window["ezuikit-webrtc"].opt.server="wss://".concat(i,"/").concat(n),window["ezuikit-webrtc"].opt.roomParams.internalRoomId=e.data.internalRoomId,window["ezuikit-webrtc"].opt.roomParams.clientId=e.data.clientId;var a={token:"token=".concat(A.rtctoken,"&userId=").concat(A.userId,"&roomId=").concat(A.roomId,"&appId=").concat(A.appId),authtype:23};Janus.init({debug:"all",callback:function(){window["ezuikit-webrtc"].opt.janus=new Janus({server:window["ezuikit-webrtc"].opt.server,success:function(e){e&&A.onMessage(e)},error:function(e){A.handleError(e)},destroyed:function(){}},a)}})}))}},{key:"getVersion",value:function(){var A=pl();return A.resolve(ul),A.promise}},{key:"getSupport",value:function(){var A=pl(),e={isWebrtcSupport:!0,isH264Support:!0},t=document.createElement("video");return t.canPlayType&&(t.canPlayType("video/mp4;codecs=“avc1.64001E”")?e.isH264Support=!0:e.isH264Support=!1),navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia?(e.isWebrtcSupport=!0,A.resolve(e)):(e.isWebrtcSupport=!1,A.reject(e)),A.promise}},{key:"getMediaList",value:function(){var A=pl();return navigator.mediaDevices?navigator.mediaDevices.enumerateDevices().then((function(e){A.resolve(e)})):A.reject("no devices"),A.promise}},{key:"getCamerasList",value:function(){var A=pl();return navigator.mediaDevices?navigator.mediaDevices.enumerateDevices().then((function(e){var t=[];e.map((function(A){"videoinput"==A.kind&&t.push(A)})),A.resolve(t)})):A.reject("no devices"),A.promise}},{key:"getMicrophonesList",value:function(){var A=pl();return navigator.mediaDevices?navigator.mediaDevices.enumerateDevices().then((function(e){var t=[];e.map((function(A){"audioinput"==A.kind&&t.push(A)})),A.resolve(t)})):A.reject("no devices"),A.promise}},{key:"getSpeakersList",value:function(){var A=pl();return navigator.mediaDevices?navigator.mediaDevices.enumerateDevices().then((function(e){var t=[];e.map((function(A){"audiooutput"==A.kind&&t.push(A)})),A.resolve(t)})):A.reject("no devices"),A.promise}},{key:"play",value:function(A){var e=pl(),t=document.getElementById(A.domId),i=window["ezuikit-webrtc"].opt.cln.local.stream;return Janus.attachMediaStream(t,i),t.play(),document.getElementById(A.domId)?e.resolve("success"):e.reject("no video dom"),e.promise}},{key:"leaveRoom",value:function(A){var e=pl(),t={cmdType:"exitRoom",customId:window["ezuikit-webrtc"].opt.roomParams.userId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return window["ezuikit-webrtc"].opt.mainHandle.send({message:t,success:function(){window["ezuikit-webrtc"].opt.janus.destroy({success:function(){}}),e.resolve("success")},error:function(A){console.error(" -- Error attaching plugin...",A),e.reject(A)}}),e.promise}},{key:"setCameraDevice",value:function(A){var e=pl();return window["ezuikit-webrtc"].cameraId=A.deviceId,window["ezuikit-webrtc"].opt.sts&&window["ezuikit-webrtc"].opt.sts.createOffer({media:{video:{deviceId:A.deviceId},replaceVideo:!0,audio:1!=window["ezuikit-webrtc"].opt.localStreamType},simulcast:!1,simulcast2:!1,bitrate:window["ezuikit-webrtc"].bitrate,frameRate:window["ezuikit-webrtc"].frameRate,success:function(A){console.log("createOffersuccess"),Janus.debug("Got SDP!"),Janus.debug(A),e.resolve("success")},error:function(A){console.log("createOffererror"),Janus.error("WebRTC error:",A),e.reject(A)}}),e.promise}},{key:"setMicrophoneDevice",value:function(A){var e=pl();return window["ezuikit-webrtc"].microphoneId=A.deviceId,window["ezuikit-webrtc"].opt.sts&&window["ezuikit-webrtc"].opt.sts.createOffer({media:{audio:{deviceId:A.deviceId},replaceAudio:!0,video:2!=window["ezuikit-webrtc"].opt.localStreamType},simulcast:!1,simulcast2:!1,bitrate:window["ezuikit-webrtc"].bitrate,frameRate:window["ezuikit-webrtc"].frameRate,success:function(A){console.log("createOffersuccess"),Janus.debug("Got SDP!"),Janus.debug(A),e.resolve("success")},error:function(A){console.log("createOffererror"),Janus.error("WebRTC error:",A),e.reject(A)}}),e.promise}},{key:"setVideoProfile",value:function(A){var e=pl(),t={video:{width:A.video.width||360,height:A.video.height||640,frameRate:A.video.frameRate},bitrate:A.video.bitrate||5e5,id:A.id};return window["ezuikit-webrtc"].videoParams=t.video,window["ezuikit-webrtc"].bitrate=1e3*t.bitrate,window["ezuikit-webrtc"].frameRate=A.video.frameRate,window["ezuikit-webrtc"].width=A.video.width,window["ezuikit-webrtc"].height=A.video.height,e.resolve("success"),e.promise}},{key:"setAudioProfile",value:function(A){var e={audio:{deviceId:window["ezuikit-webrtc"].cameraId,sampleRate:A.audio.sampleRate||"32000HZ",sampleSize:A.audio.sampleSize||16,channelCount:A.audio.channelCount||1},id:A.id};window["ezuikit-webrtc"].audioParams=e.audio,console.log("window['ezuikit-webrtc'].videoParams",window["ezuikit-webrtc"])}},{key:"joinRoom",value:function(A){var e=pl();return window["ezuikit-webrtc"].opt.janus.attach({plugin:"rtcgw.plugin.sts",opaqueId:window["ezuikit-webrtc"].opt.opaqueId,success:function(A){console.log("pluginHandle",A),window["ezuikit-webrtc"].opt.mainHandle=A,Janus.debug("Trying a createOffer too (audio/video sendrecv)");var t={cmdType:"enterRoom",customId:window["ezuikit-webrtc"].opt.roomParams.userId,clientId:window["ezuikit-webrtc"].opt.roomParams.clientId,strroomId:window["ezuikit-webrtc"].opt.roomParams.roomId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId,authtype:23,authentication:window["ezuikit-webrtc"].opt.roomParams.rtctoken};A.send({message:t}),e.resolve(A.id)},error:function(A){console.error(" -- Error attaching plugin...",A),e.reject(A)},consentDialog:function(A){Janus.debug("Consent dialog should be "+(A?"on":"off")+" now")},iceState:function(A){switch(Janus.log("ICE state changed to "+A),A){case"connected":console.log("ice connect success");break;case"disconnected":console.log("ice connect loss")}},mediaState:function(A,e){Janus.log("Janus "+(e?"started":"stopped")+" receiving our "+A)},webrtcState:function(A){Janus.log("Janus says our WebRTC PeerConnection is "+(A?"up":"down")+" now")},slowLink:function(A,e){Janus.warn("Janus reports problems "+(A?"sending":"receiving")+" packets on this PeerConnection ("+e+" lost packets)")},onmessage:function(A,e){Janus.debug(" ::: Got a message :::"),Janus.debug(A),null!=e&&(Janus.debug("Handling SDP as well..."),Janus.debug(e),window["ezuikit-webrtc"].opt.mainHandle.handleRemoteJsep({jsep:e}));var t=A.result;if(null!=t){if("done"===t)return;t.status}"enterRoomack"===A.rtcgw&&xl("enterRoomack",A),"clientJoin"===A.rtcgw&&xl("clientJoin",A),"clientLeave"===A.rtcgw&&xl("clientLeave",A),"stream-added"===A.rtcgw&&xl("steam-added",A),"stream-removed"===A.rtcgw&&xl("stream-removed",A),"audioleve"===A.rtcgw&&xl("audioleve",A),"networkquality"===A.rtcgw&&xl("networkquality",A),"error"===A.rtcgw&&xl("error",A),"audioleve"===A.rtcgw&&xl("audioleve",A),"publishlocalstreamack"===A.rtcgw&&xl("publishlocalstreamack",A),"subremoteack"===A.rtcgw&&xl("subremoteack",A)},onlocalstream:function(A){console.log("onlocalstream",A),Janus.debug(" ::: Got a local stream :::"),Janus.debug(A),window["ezuikit-webrtc"].opt.cln.local.stream=A},onremotestream:function(A){},ondataopen:function(A){Janus.log("The DataChannel is available!")},ondata:function(A){Janus.debug("We got data from the DataChannel! "+A)},oncleanup:function(){Janus.log(" ::: Got a cleanup notification :::")}}),e.promise}},{key:"getLocalStream",value:function(A){var e=pl();return window["ezuikit-webrtc"].opt.cln.local.stream?e.resolve(window["ezuikit-webrtc"].opt.cln.local.stream):e.reject("no stream"),e.promise}},{key:"getScreenStream",value:function(A){var e=pl();return window["ezuikit-webrtc"].opt.screenStream?e.resolve(window["ezuikit-webrtc"].opt.screenStream):e.reject("no stream"),e.promise}},{key:"suspendStream",value:function(A){this.controlStream(A,"suspend")}},{key:"controlStream",value:function(A,e){var t=pl(),i={cmdType:"resume"==e?"resumelocalstream":"pauselocalstream",streamtype:A.type,customId:window["ezuikit-webrtc"].opt.roomParams.userId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return 2==A.type&&window["ezuikit-webrtc"].opt.cln.local.stream.getTracks().forEach((function(A){"audio"==A.kind&&(A.enabled="resume"==e)})),1==A.type&&window["ezuikit-webrtc"].opt.cln.local.stream.getTracks().forEach((function(A){"video"==A.kind&&(A.enabled="resume"==e)})),8==A.type&&(console.log(" window['ezuikit-webrtc'].opt.screenStream.getTracks()",window["ezuikit-webrtc"].opt.screenStream.getTracks()),window["ezuikit-webrtc"].opt.screenStream.getTracks().forEach((function(A){A.enabled="resume"==e}))),3==A.type&&window["ezuikit-webrtc"].opt.cln.local.stream.getTracks().forEach((function(A){A.enabled="resume"==e})),8==A.type?window["ezuikit-webrtc"].opt.screenHandle.send({message:i,success:function(){t.resolve("success")},error:function(A){t.reject(A)}}):window["ezuikit-webrtc"].opt.sts.send({message:i,success:function(){t.resolve("success")},error:function(A){t.reject(A)}}),t.promise}},{key:"resumeStream",value:function(A){this.controlStream(A,"resume")}},{key:"publishStream",value:function(A){var e=pl(),t={cmdType:"publishlocalstream",streamtype:A.type,customId:window["ezuikit-webrtc"].opt.roomParams.userId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};8!=A.type&&(window["ezuikit-webrtc"].opt.localStreamType=A.type),window["ezuikit-webrtc"].videoParams;var i={videoSend:!0,audioSend:!0,audioRecv:!0,videoRecv:!0,data:!1,video:"stdres",audio:!0};switch(A.type){case 1:i={videoSend:!0,audioSend:!0,audioRecv:!0,videoRecv:!0,data:!1,video:{deviceId:window["ezuikit-webrtc"].cameraId,width:window["ezuikit-webrtc"].width,height:window["ezuikit-webrtc"].height},audio:!1};break;case 2:i={videoSend:!0,audioSend:!0,audioRecv:!0,videoRecv:!0,data:!1,video:!1,audio:{deviceId:window["ezuikit-webrtc"].microphoneId}};break;case 3:i={videoSend:!0,audioSend:!0,audioRecv:!0,videoRecv:!0,data:!1,video:{deviceId:window["ezuikit-webrtc"].cameraId,width:window["ezuikit-webrtc"].width,height:window["ezuikit-webrtc"].height},audio:{deviceId:window["ezuikit-webrtc"].microphoneId}};break;case 8:i={audioRecv:!1,videoRecv:!0,data:!1,audioSend:!1,videoSend:!0,video:"screen",screenshareFrameRate:3}}return console.log("media-----------",i),console.log("window['ezuikit-webrtc'].bitrate",window["ezuikit-webrtc"].bitrate),console.log("window['ezuikit-webrtc'].opt.sts",window["ezuikit-webrtc"].opt.sts),window["ezuikit-webrtc"].opt.sts&&8!=A.type?window["ezuikit-webrtc"].opt.sts.createOffer({media:i,simulcast:!1,simulcast2:!1,bitrate:window["ezuikit-webrtc"].bitrate,frameRate:window["ezuikit-webrtc"].frameRate,success:function(A){console.log("createOffersuccess"),Janus.debug("Got SDP!"),Janus.debug(A),window["ezuikit-webrtc"].opt.sts.send({message:t,jsep:A}),e.resolve("success")},error:function(A){console.log("createOffererror"),Janus.error("WebRTC error:",A),e.reject(A)}}):window["ezuikit-webrtc"].opt.janus.attach({plugin:"rtcgw.plugin.sts",opaqueId:window["ezuikit-webrtc"].opt.opaqueId,success:function(n){console.log("pluginHandle",n),8==A.type?window["ezuikit-webrtc"].opt.screenHandle=n:window["ezuikit-webrtc"].opt.sts=n,Janus.debug("Trying a createOffer too (audio/video sendrecv)"),n.createOffer({media:i,simulcast:!1,simulcast2:!1,bitrate:window["ezuikit-webrtc"].bitrate,frameRate:window["ezuikit-webrtc"].frameRate,success:function(A){console.log("createOffersuccess"),Janus.debug("Got SDP!"),Janus.debug(A),n.send({message:t,jsep:A}),e.resolve("success")},error:function(A){console.log("createOffererror"),Janus.error("WebRTC error:",A),e.reject(A)}})},error:function(A){console.error(" -- Error attaching plugin...",A),e.reject(A)},consentDialog:function(A){Janus.debug("Consent dialog should be "+(A?"on":"off")+" now")},iceState:function(A){switch(Janus.log("ICE state changed to "+A),A){case"connected":console.log("ice connect success");break;case"disconnected":console.log("ice connect loss")}},mediaState:function(A,e){Janus.log("Janus "+(e?"started":"stopped")+" receiving our "+A)},webrtcState:function(A){Janus.log("Janus says our WebRTC PeerConnection is "+(A?"up":"down")+" now")},slowLink:function(A,e){Janus.warn("Janus reports problems "+(A?"sending":"receiving")+" packets on this PeerConnection ("+e+" lost packets)")},onmessage:function(e,t){console.log("消息回调+++++++++++++++++++++++++++++++++++++++++",e,t),Janus.debug(" ::: Got a message :::"),Janus.debug(e),null!=t&&(Janus.debug("Handling SDP as well..."),Janus.debug(t),8==A.type?window["ezuikit-webrtc"].opt.screenHandle.handleRemoteJsep({jsep:t}):window["ezuikit-webrtc"].opt.sts.handleRemoteJsep({jsep:t}))},onlocalstream:function(e){console.log("onlocalstream",e),Janus.debug(" ::: Got a local stream :::"),Janus.debug(e),8==A.type?(window["ezuikit-webrtc"].opt.screenStream=e,e.getVideoTracks()[0].addEventListener("ended",(function(){console.log("停止了屏幕共享-----------------------");var A={cmdType:"unpublishlocalstream",streamtype:8,customId:window["ezuikit-webrtc"].opt.roomParams.userId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};window["ezuikit-webrtc"].opt.screenHandle&&window["ezuikit-webrtc"].opt.screenHandle.send({message:A,success:function(){window["ezuikit-webrtc"].opt.screenHandle.detach({noRequest:!1}),window["ezuikit-webrtc"].opt.screenHandle=null},error:function(A){}})}))):window["ezuikit-webrtc"].opt.cln.local.stream=e},onremotestream:function(A){},ondataopen:function(A){Janus.log("The DataChannel is available!")},ondata:function(A){Janus.debug("We got data from the DataChannel! "+A)},oncleanup:function(){Janus.log(" ::: Got a cleanup notification :::")}}),e.promise}},{key:"unpublishStream",value:function(A){var e=pl(),t={cmdType:"unpublishlocalstream",streamtype:3,customId:window["ezuikit-webrtc"].opt.roomParams.userId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return 8==A.type?window["ezuikit-webrtc"].opt.screenHandle.send({message:g(g({},t),{},{streamtype:8}),success:function(){window["ezuikit-webrtc"].opt.screenHandle.detach({noRequest:!1}),window["ezuikit-webrtc"].opt.screenHandle=null,e.resolve("success")},error:function(A){e.reject(A)}}):window["ezuikit-webrtc"].opt.sts.send({message:t,success:function(){window["ezuikit-webrtc"].opt.sts.detach({noRequest:!1}),window["ezuikit-webrtc"].opt.sts=null,e.resolve("success")},error:function(A){e.reject(A)}}),e.promise}},{key:"ezwebTrigger",value:function(A){var e={stream:window["ezuikit-webrtc"].opt.cln.local.stream,clientId:"cliendId-".concat(20*Math.random())};xl("steam-added",e)}},{key:"playRemoteSteam",value:function(A){var e=document.getElementById(A.domId);Janus.attachMediaStream(e,A.stream),e.load();var t=e.play();void 0!==t&&t.then((function(){e.play()})).catch((function(A){}))}},{key:"getQuality",value:function(A){window["ezuikit-webrtc"].opt.z3.getNetworkQuality(A.handleId,(function(A){console.log("NetworkQuality",A)}))}}])}(),wl="8.0.9",vl=(ml="undefined"!=typeof self?self:window,yl={navigator:void 0!==ml.navigator?ml.navigator:{userAgent:""},infoMap:{engine:["WebKit","Trident","Gecko","Presto"],browser:["Safari","Chrome","Edge","IE","Firefox","Firefox Focus","Chromium","Opera","Vivaldi","Yandex","Arora","Lunascape","QupZilla","Coc Coc","Kindle","Iceweasel","Konqueror","Iceape","SeaMonkey","Epiphany","360","360SE","360EE","UC","QQBrowser","QQ","Baidu","Maxthon","Sogou","LBBROWSER","2345Explorer","TheWorld","XiaoMi","Quark","Qiyu","Wechat","Taobao","Alipay","Weibo","Douban","Suning","iQiYi"],os:["Windows","Linux","Mac OS","Android","Ubuntu","FreeBSD","Debian","iOS","Windows Phone","BlackBerry","MeeGo","Symbian","Chrome OS","WebOS"],device:["Mobile","Tablet","iPad"]}},_l={getMatchMap:function(A){return{Trident:A.indexOf("Trident")>-1||A.indexOf("NET CLR")>-1,Presto:A.indexOf("Presto")>-1,WebKit:A.indexOf("AppleWebKit")>-1,Gecko:A.indexOf("Gecko/")>-1,Safari:A.indexOf("Safari")>-1,Chrome:A.indexOf("Chrome")>-1||A.indexOf("CriOS")>-1,IE:A.indexOf("MSIE")>-1||A.indexOf("Trident")>-1,Edge:A.indexOf("Edge")>-1,Firefox:A.indexOf("Firefox")>-1||A.indexOf("FxiOS")>-1,"Firefox Focus":A.indexOf("Focus")>-1,Chromium:A.indexOf("Chromium")>-1,Opera:A.indexOf("Opera")>-1||A.indexOf("OPR")>-1,Vivaldi:A.indexOf("Vivaldi")>-1,Yandex:A.indexOf("YaBrowser")>-1,Arora:A.indexOf("Arora")>-1,Lunascape:A.indexOf("Lunascape")>-1,QupZilla:A.indexOf("QupZilla")>-1,"Coc Coc":A.indexOf("coc_coc_browser")>-1,Kindle:A.indexOf("Kindle")>-1||A.indexOf("Silk/")>-1,Iceweasel:A.indexOf("Iceweasel")>-1,Konqueror:A.indexOf("Konqueror")>-1,Iceape:A.indexOf("Iceape")>-1,SeaMonkey:A.indexOf("SeaMonkey")>-1,Epiphany:A.indexOf("Epiphany")>-1,360:A.indexOf("QihooBrowser")>-1||A.indexOf("QHBrowser")>-1,"360EE":A.indexOf("360EE")>-1,"360SE":A.indexOf("360SE")>-1,UC:A.indexOf("UC")>-1||A.indexOf(" UBrowser")>-1,QQBrowser:A.indexOf("QQBrowser")>-1,QQ:A.indexOf("QQ/")>-1,Baidu:A.indexOf("Baidu")>-1||A.indexOf("BIDUBrowser")>-1,Maxthon:A.indexOf("Maxthon")>-1,Sogou:A.indexOf("MetaSr")>-1||A.indexOf("Sogou")>-1,LBBROWSER:A.indexOf("LBBROWSER")>-1,"2345Explorer":A.indexOf("2345Explorer")>-1,TheWorld:A.indexOf("TheWorld")>-1,XiaoMi:A.indexOf("MiuiBrowser")>-1,Quark:A.indexOf("Quark")>-1,Qiyu:A.indexOf("Qiyu")>-1,Wechat:A.indexOf("MicroMessenger")>-1,Taobao:A.indexOf("AliApp(TB")>-1,Alipay:A.indexOf("AliApp(AP")>-1,Weibo:A.indexOf("Weibo")>-1,Douban:A.indexOf("com.douban.frodo")>-1,Suning:A.indexOf("SNEBUY-APP")>-1,iQiYi:A.indexOf("IqiyiApp")>-1,Windows:A.indexOf("Windows")>-1,Linux:A.indexOf("Linux")>-1||A.indexOf("X11")>-1,"Mac OS":A.indexOf("Macintosh")>-1,Android:A.indexOf("Android")>-1||A.indexOf("Adr")>-1,Ubuntu:A.indexOf("Ubuntu")>-1,FreeBSD:A.indexOf("FreeBSD")>-1,Debian:A.indexOf("Debian")>-1,"Windows Phone":A.indexOf("IEMobile")>-1||A.indexOf("Windows Phone")>-1,BlackBerry:A.indexOf("BlackBerry")>-1||A.indexOf("RIM")>-1,MeeGo:A.indexOf("MeeGo")>-1,Symbian:A.indexOf("Symbian")>-1,iOS:A.indexOf("like Mac OS X")>-1,"Chrome OS":A.indexOf("CrOS")>-1,WebOS:A.indexOf("hpwOS")>-1,Mobile:A.indexOf("Mobi")>-1||A.indexOf("iPh")>-1||A.indexOf("480")>-1,Tablet:A.indexOf("Tablet")>-1||A.indexOf("Nexus 7")>-1,iPad:A.indexOf("iPad")>-1}},matchInfoMap:function(A){var e,t=(null==(e=yl.navigator)?void 0:e.userAgent)||"",i=_l.getMatchMap(t);for(var n in yl.infoMap)for(var a=0;a<yl.infoMap[n].length;a++){var r=yl.infoMap[n][a];i[r]&&(A[n]=r)}},getOS:function(){var A=this;return _l.matchInfoMap(A),null==A?void 0:A.os},getOSVersion:function(){var A=this,e=yl.navigator.userAgent||"";A.osVersion="";var t={Windows:function(){var A=e.replace(/^.*Windows NT ([\d.]+);.*$/,"$1");return{6.4:"10",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.2:"XP",5.1:"XP","5.0":"2000"}[A]||A},Android:function(){return e.replace(/^.*Android ([\d.]+);.*$/,"$1")},iOS:function(){return e.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,".")},Debian:function(){return e.replace(/^.*Debian\/([\d.]+).*$/,"$1")},"Windows Phone":function(){return e.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2")},"Mac OS":function(){return e.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,".")},WebOS:function(){return e.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")}};return"function"==typeof t[A.os]&&(A.osVersion=t[A.os](),A.osVersion==e&&(A.osVersion="")),A.osVersion},getOrientationStatu:function(){return window.matchMedia("(orientation: portrait)").matches?"vertical":"horizontal"},getDeviceType:function(){var A=this;return A.device="PC",_l.matchInfoMap(A),A.device},getNetwork:function(){var A,e,t,i;return null==(A=(null==(e=navigator)?void 0:e.connection)||(null==(t=navigator)?void 0:t.mozConnection)||(null==(i=navigator)?void 0:i.webkitConnection))?void 0:A.effectiveType},getLanguage:function(){var A,e,t;return this.language=((t=((null==(A=yl.navigator)?void 0:A.browserLanguage)||(null==(e=yl.navigator)?void 0:e.language)).split("-"))[1]&&(t[1]=t[1].toUpperCase()),t.join("_")),this.language},createFingerprint:function(A){var e=document.createElement("canvas"),t=e.getContext("2d"),i=A||window.location.host;t.textBaseline="top",t.font="14px 'Arial'",t.fillStyle="#f60",t.fillRect(125,1,62,20),t.fillStyle="#069",t.fillText(i,2,15),t.fillStyle="rgba(102, 204, 0, 0.7)",t.fillText(i,4,17);var n=e.toDataURL().replace("data:image/png;base64,","");return function(A){var e,t,i,n="";for(e=0,t=(A+="").length;e<t;e++)n+=(i=A.charCodeAt(e).toString(16)).length<2?"0"+i:i;return n}(atob(n).slice(-16,-12))},getBrowserInfo:function(){var A=this;_l.matchInfoMap(A);var e=yl.navigator.userAgent||"",t=function(A,e){var t=yl.navigator.mimeTypes;for(var i in t)if(t[i][A]==e)return!0;return!1},i=_l.getMatchMap(e),n=!1;if(ml.chrome){var a=e.replace(/^.*Chrome\/([\d]+).*$/,"$1");+a>36&&ml.showModalDialog?n=!0:+a>45&&(n=t("type","application/vnd.chromium.remoting-viewer"))}if(i.Baidu&&i.Opera&&(i.Baidu=!1),i.Mobile&&(i.Mobile=!e.includes("iPad")),n&&(t("type","application/gameplugin")||yl.navigator&&void 0===yl.navigator.connection.saveData?i["360SE"]=!0:i["360EE"]=!0),i.IE||i.Edge)switch(window.screenTop-window.screenY){case 71:case 74:case 99:case 75:case 105:break;case 102:i["360EE"]=!0;break;case 104:i["360SE"]=!0}var r={Safari:function(){return e.replace(/^.*Version\/([\d.]+).*$/,"$1")},Chrome:function(){return e.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1")},IE:function(){return e.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1")},Edge:function(){return e.replace(/^.*Edge\/([\d.]+).*$/,"$1")},Firefox:function(){return e.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1")},"Firefox Focus":function(){return e.replace(/^.*Focus\/([\d.]+).*$/,"$1")},Chromium:function(){return e.replace(/^.*Chromium\/([\d.]+).*$/,"$1")},Opera:function(){return e.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1")},Vivaldi:function(){return e.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1")},Yandex:function(){return e.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1")},Arora:function(){return e.replace(/^.*Arora\/([\d.]+).*$/,"$1")},Lunascape:function(){return e.replace(/^.*Lunascape[\/\s]([\d.]+).*$/,"$1")},QupZilla:function(){return e.replace(/^.*QupZilla[\/\s]([\d.]+).*$/,"$1")},"Coc Coc":function(){return e.replace(/^.*coc_coc_browser\/([\d.]+).*$/,"$1")},Kindle:function(){return e.replace(/^.*Version\/([\d.]+).*$/,"$1")},Iceweasel:function(){return e.replace(/^.*Iceweasel\/([\d.]+).*$/,"$1")},Konqueror:function(){return e.replace(/^.*Konqueror\/([\d.]+).*$/,"$1")},Iceape:function(){return e.replace(/^.*Iceape\/([\d.]+).*$/,"$1")},SeaMonkey:function(){return e.replace(/^.*SeaMonkey\/([\d.]+).*$/,"$1")},Epiphany:function(){return e.replace(/^.*Epiphany\/([\d.]+).*$/,"$1")},360:function(){return e.replace(/^.*QihooBrowser\/([\d.]+).*$/,"$1")},"360SE":function(){return{63:"10.0",55:"9.1",45:"8.1",42:"8.0",31:"7.0",21:"6.3"}[+e.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||""},"360EE":function(){return{69:"11.0",63:"9.5",55:"9.0",50:"8.7",30:"7.5"}[+e.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||""},Maxthon:function(){return e.replace(/^.*Maxthon\/([\d.]+).*$/,"$1")},QQBrowser:function(){return e.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1")},QQ:function(){return e.replace(/^.*QQ\/([\d.]+).*$/,"$1")},Baidu:function(){return e.replace(/^.*BIDUBrowser[\s\/]([\d.]+).*$/,"$1")},UC:function(){return e.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1")},Sogou:function(){return e.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1")},LBBROWSER:function(){return{57:"6.5",49:"6.0",46:"5.9",42:"5.3",39:"5.2",34:"5.0",29:"4.5",21:"4.0"}[+navigator.userAgent.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||""},"2345Explorer":function(){return e.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1")},TheWorld:function(){return e.replace(/^.*TheWorld ([\d.]+).*$/,"$1")},XiaoMi:function(){return e.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1")},Quark:function(){return e.replace(/^.*Quark\/([\d.]+).*$/,"$1")},Qiyu:function(){return e.replace(/^.*Qiyu\/([\d.]+).*$/,"$1")},Wechat:function(){return e.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1")},Taobao:function(){return e.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1")},Alipay:function(){return e.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1")},Weibo:function(){return e.replace(/^.*weibo__([\d.]+).*$/,"$1")},Douban:function(){return e.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1")},Suning:function(){return e.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1")},iQiYi:function(){return e.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")}};return A.browserVersion="",r[A.browser]&&(A.browserVersion=r[A.browser](),A.browserVersion==e&&(A.browserVersion="")),"Edge"==A.browser&&(A.engine="EdgeHTML"),"Chrome"==A.browser&&parseInt(A.browserVersion)>27&&(A.engine="Blink"),"Opera"==A.browser&&parseInt(A.browserVersion)>12&&(A.engine="Blink"),"Yandex"==A.browser&&(A.engine="Blink"),A.browser+" (version: "+A.browserVersion+"; kernel: "+A.engine+")"}},Sl={DeviceInfoObj:function(A){var e,t=function(e){var t;null==(t=A.info)||t.forEach((function(A){A.toLowerCase()===e.toLowerCase()&&(n[e]=i[e])}))};A=A||{domain:""};var i={deviceType:_l.getDeviceType(),OS:_l.getOS(),OSVersion:_l.getOSVersion(),sh:ml.screen.height,sw:ml.screen.width,lang:_l.getLanguage(),netWork:_l.getNetwork(),orientation:_l.getOrientationStatu(),browserInfo:_l.getBrowserInfo(),fingerprint:_l.createFingerprint(A.domain),userAgent:null==(e=yl.navigator)?void 0:e.userAgent};if(!A.info||0===A.info.length)return i;var n={};for(var a in i)t(a);return n}},{getDeviceInfo:function(A){return Sl.DeviceInfoObj(A)}}),Fl=function(){function A(){}return A.add=function(e,t){A.queues.push({url:e,data:t})},A.fire=function(){if(A.queues&&0!==A.queues.length){A.isStop=!1;var e=A.queues[0];e.url&&A.api.report(e.data),A.queues.splice(0,1),A.fire()}else A.isStop=!0},A}();Fl.isStop=!0,Fl.queues=[];var bl=function(){function A(A){this.url=A}var e=A.prototype;return e.report=function(A){this.checkUrl(this.url)&&this.sendInfo(A)},e.sendInfo=function(A){navigator.sendBeacon?this.sendBeacon(this.url,A):this.sendImage(this.url,A)},e.sendImage=function(A,e){var t=this.changeJSON2Query(e),i=new Image;i.onload=i.onerror=function(){i=null},i.src=A+"?"+t+"&random="+Math.random()},e.sendBeacon=function(A,e){try{navigator.sendBeacon(A,this.formatParamsByURLSearchParams(e))}catch(A){}},e.formatParamsByURLSearchParams=function(A){var e=new URLSearchParams;for(var t in A)"object"==typeof A[t]&&(A[t]=JSON.stringify(A[t])),e.append(t,A[t]);return e},e.changeJSON2Query=function(A){var e="";for(var t in A){""!=e&&(e+="&");var i=A[t];e+=t+"="+encodeURIComponent("object"==typeof i?JSON.stringify(i):i)}return e},e.checkUrl=function(A){return!!A&&/^[hH][tT][tT][pP]([sS]?):\/\//.test(A)},A}();function Rl(){return Rl=Object.assign||function(A){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(A[i]=t[i])}return A},Rl.apply(this,arguments)}var kl=function(){function A(A){this.options=A,this.extendsInfo=A.extendsInfo||{},this.clientInfo=this._getDeviceInfo(),Fl.api=new bl(A.url)}var e=A.prototype;return e.send=function(A){return this.options.forbidden||"object"!=typeof A||(this._handleRecordError(A),Fl.isStop&&Fl.fire()),this},e.setForbidden=function(A){this.options.forbidden=A},e.updateExtendsInfo=function(A){void 0===A&&(A={}),this.extendsInfo=Rl({},this.extendsInfo||{},A)},e._handleRecordError=function(A){try{var e=this._handleErrorInfo(A);Fl.add(this.options.url,e)}catch(A){}},e._handleErrorInfo=function(A){var e=this._getExtendsInfo(),t=Rl({st:(new Date).getTime()},e,A);return t.clientInfo=this.clientInfo,t},e._getExtendsInfo=function(){try{var A,e={},t=this.extendsInfo||{};for(var i in"function"==typeof t.getDynamic&&(A=t.getDynamic()),"[object Object]"===Object.prototype.toString.call(A)&&(t=Rl({},t,A)),t)"function"!=typeof t[i]&&(e[i]=t[i]);return e}catch(A){return{}}},e._getDeviceInfo=function(){try{var A=vl.getDeviceInfo();return JSON.stringify(A)}catch(A){return""}},A}(),Pl=function(){return a((function A(e){t(this,A),this.collect=new kl(e)}),[{key:"report",value:function(A){this.collect.send(g({},A))}},{key:"updateParams",value:function(A){this.collect.updateExtendsInfo(A)}},{key:"setForbidden",value:function(A){this.collect.setForbidden(A)}}])}();return window.monitorExtendsInfo={},window.ezuikitMonitor=new Pl({url:"https://log.ys7.com/statistics.do/opensdk_ezuikit",extendsInfo:{v:wl,getDynamic:function(){return window.monitorExtendsInfo}}}),{Core:h,HLS:w,FLV:P,EZUIKitPlayer:sl,EZUIKitHD:dl,EZWebRtc:Dl}}));
|
|
130
|
+
*/Bl.sessions={},Bl.isExtensionEnabled=function(){if(navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia)return!0;if(window.navigator.userAgent.match("Chrome")){var A=parseInt(window.navigator.userAgent.match(/Chrome\/(.*) /)[1],10),e=33;return window.navigator.userAgent.match("Linux")&&(e=35),A>=26&&A<=e||Bl.extension.isInstalled()}return!0};var hl={extensionId:"hapfgfdkleiggjjpfpenajgdnfckjpaj",isInstalled:function(){return null!==document.querySelector("#janus-extension-installed")},getScreen:function(A){var e=window.setTimeout((function(){var e=new Error("NavigatorUserMediaError");return e.name='The required Chrome extension is not installed: click <a href="#">here</a> to install it. (NOTE: this will need you to refresh the page)',A(e)}),1e3);this.cache[e]=A,window.postMessage({type:"janusGetScreen",id:e},"*")},init:function(){var A={};this.cache=A,window.addEventListener("message",(function(e){if(e.origin==window.location.origin)if("janusGotScreen"==e.data.type&&A[e.data.id]){var t=A[e.data.id];if(delete A[e.data.id],""===e.data.sourceId){var i=new Error("NavigatorUserMediaError");i.name="You cancelled the request for permission, giving up...",t(i)}else t(null,e.data.sourceId)}else"janusGetScreenPending"==e.data.type&&(console.log("clearing ",e.data.id),window.clearTimeout(e.data.id))}))}};function Bl(A,e){if(void 0===Bl.initDone)return A.error("Library not initialized"),{};if(!Bl.isWebrtcSupported())return A.error("WebRTC not supported by this browser"),{};if(Bl.log("Library initialized: "+Bl.initDone),(A=A||{}).success="function"==typeof A.success?A.success:Bl.noop,A.error="function"==typeof A.error?A.error:Bl.noop,A.destroyed="function"==typeof A.destroyed?A.destroyed:Bl.noop,null===A.server||void 0===A.server)return A.error("Invalid server url"),{};var t=!1,i=null,n={},a=null,r=null,o=0,s=A.server;Bl.isArray(s)?(Bl.log("Multiple servers provided ("+s.length+"), will use the first that works"),s=null,r=A.server,Bl.debug(r)):0===s.indexOf("ws")?(t=!0,Bl.log("Using WebSockets to contact Janus: "+s)):(t=!1,Bl.log("Using REST API to contact Janus: "+s));var g=A.iceServers;null==g&&(g=[{urls:"stun:stun.l.google.com:19302"}]);var c=A.iceTransportPolicy,l=A.bundlePolicy,I=A.ipv6;null==I&&(I=!1);var d=!1;void 0!==A.withCredentials&&null!==A.withCredentials&&(d=!0===A.withCredentials);var h=10;void 0!==A.max_poll_events&&null!==A.max_poll_events&&(h=A.max_poll_events),h<1&&(h=1);var B=null;void 0!==A.token&&null!==A.token&&(B=A.token);var u=null;void 0!==A.apisecret&&null!==A.apisecret&&(u=A.apisecret),this.destroyOnUnload=!0,void 0!==A.destroyOnUnload&&null!==A.destroyOnUnload&&(this.destroyOnUnload=!0===A.destroyOnUnload);var E=25e3;void 0!==A.keepAlivePeriod&&null!==A.keepAlivePeriod&&(E=A.keepAlivePeriod),isNaN(E)&&(E=25e3);var f=6e4;function Q(A){var e={high:9e5,medium:3e5,low:1e5};return null!=A&&(A.high&&(e.high=A.high),A.medium&&(e.medium=A.medium),A.low&&(e.low=A.low)),e}void 0!==A.longPollTimeout&&null!==A.longPollTimeout&&(f=A.longPollTimeout),isNaN(f)&&(f=6e4);var x=!1,p=null,m={},y=this,_=0,S={};function D(){if(null!=p)if(Bl.debug("Long poll..."),x){var e=s+"/"+p+"?rid="+(new Date).getTime();null!=h&&(e=e+"&maxev="+h),null!=B&&(e=e+"&token="+encodeURIComponent(B)),null!=u&&(e=e+"&apisecret="+encodeURIComponent(u)),Bl.httpAPICall(e,{verb:"GET",withCredentials:d,success:w,timeout:f,error:function(e,t){if(Bl.error(e+":",t),++_>3)return x=!1,void A.error("Lost connection to the server (is it down?)");D()}})}else Bl.warn("Is the server down? (connected=false)")}function w(A,e){if(_=0,t||null==p||!0===e||D(),t||!Bl.isArray(A))if("keepalive"!==A.rtcgw)if("ack"!==A.rtcgw)if("success"!==A.rtcgw)if("trickle"===A.rtcgw){if(null==(s=A.sender))return void Bl.warn("Missing sender...");if(null==(c=m[s]))return void Bl.debug("This handle is not attached to this session");var n=A.candidate;Bl.debug("Got a trickled candidate on session "+p),Bl.debug(n);var a=c.webrtcStuff;a.pc&&a.remoteSdp?(Bl.debug("Adding remote candidate:",n),n&&!0!==n.completed?a.pc.addIceCandidate(n):a.pc.addIceCandidate(Bl.endOfCandidates)):(Bl.debug("We didn't do setRemoteDescription (trickle got here before the offer?), caching candidate"),a.candidates||(a.candidates=[]),a.candidates.push(n),Bl.debug(a.candidates))}else{if("webrtcup"===A.rtcgw)return Bl.debug("Got a webrtcup event on session "+p),Bl.debug(A),null==(s=A.sender)?void Bl.warn("Missing sender..."):null==(c=m[s])?void Bl.debug("This handle is not attached to this session"):void c.webrtcState(!0);if("hangup"===A.rtcgw){if(Bl.debug("Got a hangup event on session "+p),Bl.debug(A),null==(s=A.sender))return void Bl.warn("Missing sender...");if(null==(c=m[s]))return void Bl.debug("This handle is not attached to this session");c.webrtcState(!1,A.reason),c.hangup()}else if("detached"===A.rtcgw){if(Bl.debug("Got a detached event on session "+p),Bl.debug(A),null==(s=A.sender))return void Bl.warn("Missing sender...");if(null==(c=m[s]))return;c.detached=!0,c.ondetached(),c.detach()}else if("media"===A.rtcgw){if(Bl.debug("Got a media event on session "+p),Bl.debug(A),null==(s=A.sender))return void Bl.warn("Missing sender...");if(null==(c=m[s]))return void Bl.debug("This handle is not attached to this session");c.mediaState(A.type,A.receiving)}else if("slowlink"===A.rtcgw){if(Bl.debug("Got a slowlink event on session "+p),Bl.debug(A),console.log("json的所有信息打印-----------------------------------------------",A),null==(s=A.sender))return void Bl.warn("Missing sender...");if(null==(c=m[s]))return void Bl.debug("This handle is not attached to this session");c.slowLink(A.uplink,A.lost)}else{if("error"===A.rtcgw){var r,o;if(Bl.error("Ooops: "+A.error.code+" "+A.error.reason),Bl.debug(A),null!=(r=A.transaction))null!=(o=S[r])&&o(A),delete S[r];return}if("event"===A.rtcgw){var s;if(Bl.debug("Got a plugin event on session "+p),Bl.debug(A),null==(s=A.sender))return void Bl.warn("Missing sender...");var g=A.plugindata;if(null==g)return void Bl.warn("Missing plugindata...");Bl.debug(" -- Event is coming from "+s+" ("+g.plugin+")");var c,l=g.data;if(Bl.debug(l),null==(c=m[s]))return void Bl.warn("This handle is not attached to this session");var I=A.jsep;null!=I&&(Bl.debug("Handling SDP as well..."),Bl.debug(I));var C=c.onmessage;null!=C?(Bl.debug("Notifying application..."),C(l,I)):Bl.debug("No provided notification callback")}else{if("timeout"===A.rtcgw)return Bl.error("Timeout on session "+p),Bl.debug(A),void(t&&i.close(3504,"Gateway timeout"));Bl.warn("Unknown message/event '"+A.rtcgw+"' on session "+p),Bl.debug(A)}}}else Bl.debug("Got a success on session "+p),Bl.debug(A),null!=(r=A.transaction)&&(null!=(o=S[r])&&o(A),delete S[r]);else Bl.debug("Got an ack on session "+p),Bl.debug(A),null!=(r=A.transaction)&&(null!=(o=S[r])&&o(A),delete S[r]);else Bl.vdebug("Got a keepalive on session "+p);else for(var d=0;d<A.length;d++)w(A[d],!0)}function v(){if(null!==s&&t&&x){a=setTimeout(v,E);var A={rtcgw:"keepalive",session_id:p,transaction:Bl.randomString(12)};null!=B&&(A.token=B),null!=u&&(A.apisecret=u),i.send(JSON.stringify(A))}}function F(A){var g=Bl.randomString(12),c={rtcgw:"create",transaction:g,token:"testtoken"};if(c=Object.assign({},c,e),A.reconnect&&(x=!1,c.rtcgw="claim",c.session_id=p,i&&(i.onopen=null,i.onerror=null,i.onclose=null,a&&(clearTimeout(a),a=null))),null!=B&&(c.token=B),null!=u&&(c.apisecret=u),null===s&&Bl.isArray(r)&&(0===(s=r[o]).indexOf("ws")?(t=!0,Bl.log("Server #"+(o+1)+": trying WebSockets to contact Janus ("+s+")")):(t=!1,Bl.log("Server #"+(o+1)+": trying REST API to contact Janus ("+s+")"))),t)for(var l in i=Bl.newWebSocket(s,"rtcgw-protocol"),n={error:function(){if(Bl.error("Error connecting to the Janus WebSockets server... "+s),Bl.isArray(r)&&!A.reconnect)return++o==r.length?void A.error("Error connecting to any of the provided Janus servers: Is the server down?"):(s=null,void setTimeout((function(){F(A)}),200));A.error("Error connecting to the Janus WebSockets server: Is the server down?")},open:function(){S[g]=function(e){if(Bl.debug(e),"success"!==e.rtcgw)return Bl.error("Ooops: "+e.error.code+" "+e.error.reason),void A.error(e.error.reason);a=setTimeout(v,E),x=!0,p=e.session_id?e.session_id:e.data.id,A.reconnect?Bl.log("Claimed session: "+p):Bl.log("Created session: "+p),Bl.sessions[p]=y,A.success(p)},i.send(JSON.stringify(c))},message:function(A){w(JSON.parse(A.data))}})i.addEventListener(l,n[l]);else Bl.httpAPICall(s,{verb:"POST",withCredentials:d,body:c,success:function(e){if(Bl.debug(e),"success"!==e.rtcgw)return Bl.error("Ooops: "+e.error.code+" "+e.error.reason),void A.error(e.error.reason);x=!0,p=e.session_id?e.session_id:e.data.id,A.reconnect?Bl.log("Claimed session: "+p):Bl.log("Created session: "+p),Bl.sessions[p]=y,D(),A.success()},error:function(e,t){if(Bl.error(e+":",t),Bl.isArray(r)&&!A.reconnect)return++o==r.length?void A.error("Error connecting to any of the provided Janus servers: Is the server down?"):(s=null,void setTimeout((function(){F(A)}),200));""===t?A.error(e+": Is the server down?"):A.error(e+": "+t)}})}function b(A,e){if((e=e||{}).success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:Bl.noop,!x)return Bl.warn("Is the server down? (connected=false)"),void e.error("Is the server down? (connected=false)");var n=m[A];if(null==n||null===n.webrtcStuff||void 0===n.webrtcStuff)return Bl.warn("Invalid handle"),void e.error("Invalid handle");var a=e.message,r=e.jsep,o=Bl.randomString(12),g={rtcgw:"message",body:a,transaction:o};if(null!==n.token&&void 0!==n.token&&(g.token=n.token),null!=u&&(g.apisecret=u),null!=r&&(g.jsep=r),Bl.debug("Sending message to plugin (handle="+A+"):"),Bl.debug(g),t)return g.session_id=p,g.handle_id=A,S[o]=function(A){if(Bl.debug("Message sent!"),Bl.debug(A),"success"===A.rtcgw){var t=A.plugindata;if(null==t)return Bl.warn("Request succeeded, but missing plugindata..."),void e.success();Bl.log("Synchronous transaction successful ("+t.plugin+")");var i=t.data;return Bl.debug(i),void e.success(i)}"ack"===A.rtcgw?e.success():void 0!==A.error&&null!==A.error?(Bl.error("Ooops: "+A.error.code+" "+A.error.reason),e.error(A.error.code+" "+A.error.reason)):(Bl.error("Unknown error"),e.error("Unknown error"))},void i.send(JSON.stringify(g));Bl.httpAPICall(s+"/"+p+"/"+A,{verb:"POST",withCredentials:d,body:g,success:function(A){if(Bl.debug("Message sent!"),Bl.debug(A),"success"===A.rtcgw){var t=A.plugindata;if(null==t)return Bl.warn("Request succeeded, but missing plugindata..."),void e.success();Bl.log("Synchronous transaction successful ("+t.plugin+")");var i=t.data;return Bl.debug(i),void e.success(i)}"ack"===A.rtcgw?e.success():void 0!==A.error&&null!==A.error?(Bl.error("Ooops: "+A.error.code+" "+A.error.reason),e.error(A.error.code+" "+A.error.reason)):(Bl.error("Unknown error"),e.error("Unknown error"))},error:function(A,t){Bl.error(A+":",t),e.error(A+": "+t)}})}function R(A,e){if(x){var n=m[A];if(null!=n&&null!==n.webrtcStuff&&void 0!==n.webrtcStuff){var a={rtcgw:"trickle",candidate:e,transaction:Bl.randomString(12)};if(null!==n.token&&void 0!==n.token&&(a.token=n.token),null!=u&&(a.apisecret=u),Bl.vdebug("Sending trickle candidate (handle="+A+"):"),Bl.vdebug(a),t)return a.session_id=p,a.handle_id=A,void i.send(JSON.stringify(a));Bl.httpAPICall(s+"/"+p+"/"+A,{verb:"POST",withCredentials:d,body:a,success:function(A){Bl.vdebug("Candidate sent!"),Bl.vdebug(A),"ack"===A.rtcgw||Bl.error("Ooops: "+A.error.code+" "+A.error.reason)},error:function(A,e){Bl.error(A+":",e)}})}else Bl.warn("Invalid handle")}else Bl.warn("Is the server down? (connected=false)")}function k(A,e,t,i){var n=m[A];if(null!=n&&null!==n.webrtcStuff&&void 0!==n.webrtcStuff){var a=n.webrtcStuff,r=function(A){Bl.log("Received state change on data channel:",A);var e=A.target.label,t=a.dataChannel[e]?a.dataChannel[e].readyState:"null";if(Bl.log("State change on <"+e+"> data channel: "+t),"open"===t){if(a.dataChannel[e].pending&&a.dataChannel[e].pending.length>0){for(var i in Bl.log("Sending pending messages on <"+e+">:",a.dataChannel[e].pending.length),a.dataChannel[e].pending){var r=a.dataChannel[e].pending[i];Bl.log("Sending string on data channel <"+e+">: "+r),a.dataChannel[e].send(r)}a.dataChannel[e].pending=[]}n.ondataopen(e)}};a.dataChannel[e]=t||a.pc.createDataChannel(e,{ordered:!1}),a.dataChannel[e].onmessage=function(A){Bl.log("Received message on data channel:",A);var e=A.target.label;n.ondata(A.data,e)},a.dataChannel[e].onopen=r,a.dataChannel[e].onclose=r,a.dataChannel[e].onerror=function(A){Bl.error("Got error on data channel:",A)},a.dataChannel[e].pending=[],i&&a.dataChannel[e].pending.push(i)}else Bl.warn("Invalid handle")}function P(A,e){(e=e||{}).success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:Bl.noop;var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return Bl.warn("Invalid handle"),void e.error("Invalid handle");var i=t.webrtcStuff,n=e.text;if(null==n)return Bl.warn("Invalid text"),void e.error("Invalid text");var a=e.label?e.label:Bl.dataChanDefaultLabel;return i.dataChannel[a]?"open"!==i.dataChannel[a].readyState?(i.dataChannel[a].pending.push(n),void e.success()):(Bl.log("Sending string on data channel <"+a+">: "+n),i.dataChannel[a].send(n),void e.success()):(k(A,a,!1,n),void e.success())}function N(A,e){(e=e||{}).success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:Bl.noop;var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return Bl.warn("Invalid handle"),void e.error("Invalid handle");var i=t.webrtcStuff;if(null===i.dtmfSender||void 0===i.dtmfSender){if(void 0!==i.pc&&null!==i.pc){var n=i.pc.getSenders().find((function(A){return A.track&&"audio"===A.track.kind}));if(!n)return Bl.warn("Invalid DTMF configuration (no audio track)"),void e.error("Invalid DTMF configuration (no audio track)");i.dtmfSender=n.dtmf,i.dtmfSender&&(Bl.log("Created DTMF Sender"),i.dtmfSender.ontonechange=function(A){Bl.debug("Sent DTMF tone: "+A.tone)})}if(null===i.dtmfSender||void 0===i.dtmfSender)return Bl.warn("Invalid DTMF configuration"),void e.error("Invalid DTMF configuration")}var a=e.dtmf;if(null==a)return Bl.warn("Invalid DTMF parameters"),void e.error("Invalid DTMF parameters");var r=a.tones;if(null==r)return Bl.warn("Invalid DTMF string"),void e.error("Invalid DTMF string");var o=a.duration;null==o&&(o=500);var s=a.gap;null==s&&(s=50),Bl.debug("Sending DTMF string "+r+" (duration "+o+"ms, gap "+s+"ms)"),i.dtmfSender.insertDTMF(r,o,s),e.success()}function T(A,e){(e=e||{}).success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:Bl.noop;var n=!0;void 0!==e.asyncRequest&&null!==e.asyncRequest&&(n=!0===e.asyncRequest);var a=!0;void 0!==e.noRequest&&null!==e.noRequest&&(a=!0===e.noRequest),Bl.log("Destroying handle "+A+" (async="+n+")"),O(A);var r=m[A];if(null==r||r.detached)return delete m[A],void e.success();if(a)return delete m[A],void e.success();if(!x)return Bl.warn("Is the server down? (connected=false)"),void e.error("Is the server down? (connected=false)");var o={rtcgw:"detach",transaction:Bl.randomString(12)};if(null!==r.token&&void 0!==r.token&&(o.token=r.token),null!=u&&(o.apisecret=u),t)return o.session_id=p,o.handle_id=A,i.send(JSON.stringify(o)),delete m[A],void e.success();Bl.httpAPICall(s+"/"+p+"/"+A,{verb:"POST",async:n,withCredentials:d,body:o,success:function(t){Bl.log("Destroyed handle:"),Bl.debug(t),"success"!==t.rtcgw&&Bl.error("Ooops: "+t.error.code+" "+t.error.reason),delete m[A],e.success()},error:function(t,i){Bl.error(t+":",i),delete m[A],e.success()}})}function M(A,e,t,i,n){var a=m[A];if(null==a||null===a.webrtcStuff||void 0===a.webrtcStuff)return Bl.warn("Invalid handle"),void i.error("Invalid handle");var r=a.webrtcStuff;Bl.debug("streamsDone:",n),n&&(Bl.debug(" -- Audio tracks:",n.getAudioTracks()),Bl.debug(" -- Video tracks:",n.getVideoTracks()));var o=!1;if(r.myStream&&t.update&&!r.streamExternal){if((!t.update&&j(t)||t.update&&(t.addAudio||t.replaceAudio))&&n.getAudioTracks()&&n.getAudioTracks().length)if(r.myStream.addTrack(n.getAudioTracks()[0]),Bl.unifiedPlan){Bl.log((t.replaceAudio?"Replacing":"Adding")+" audio track:",n.getAudioTracks()[0]);var s=null;if((h=r.pc.getTransceivers())&&h.length>0)for(var d in h){if((u=h[d]).sender&&u.sender.track&&"audio"===u.sender.track.kind||u.receiver&&u.receiver.track&&"audio"===u.receiver.track.kind){s=u;break}}s&&s.sender?s.sender.replaceTrack(n.getAudioTracks()[0]):r.pc.addTrack(n.getAudioTracks()[0],n)}else Bl.log((t.replaceAudio?"Replacing":"Adding")+" audio track:",n.getAudioTracks()[0]),r.pc.addTrack(n.getAudioTracks()[0],n);if((!t.update&&Z(t)||t.update&&(t.addVideo||t.replaceVideo))&&n.getVideoTracks()&&n.getVideoTracks().length)if(r.myStream.addTrack(n.getVideoTracks()[0]),Bl.unifiedPlan){Bl.log((t.replaceVideo?"Replacing":"Adding")+" video track:",n.getVideoTracks()[0]);var h,B=null;if((h=r.pc.getTransceivers())&&h.length>0)for(var d in h){var u;if((u=h[d]).sender&&u.sender.track&&"video"===u.sender.track.kind||u.receiver&&u.receiver.track&&"video"===u.receiver.track.kind){B=u;break}}B&&B.sender?B.sender.replaceTrack(n.getVideoTracks()[0]):r.pc.addTrack(n.getVideoTracks()[0],n)}else Bl.log((t.replaceVideo?"Replacing":"Adding")+" video track:",n.getVideoTracks()[0]),r.pc.addTrack(n.getVideoTracks()[0],n)}else r.myStream=n,o=!0;if(!r.pc){var E={iceServers:g,iceTransportPolicy:c,bundlePolicy:l};"chrome"===Bl.webRTCAdapter.browserDetails.browser&&(E.sdpSemantics=Bl.webRTCAdapter.browserDetails.version<72?"plan-b":"unified-plan");var f={optional:[{DtlsSrtpKeyAgreement:!0}]};if(!0===I&&f.optional.push({googIPv6:!0}),i.rtcConstraints&&"object"===C(i.rtcConstraints))for(var d in Bl.debug("Adding custom PeerConnection constraints:",i.rtcConstraints),i.rtcConstraints)f.optional.push(i.rtcConstraints[d]);"edge"===Bl.webRTCAdapter.browserDetails.browser&&(E.bundlePolicy="max-bundle"),Bl.log("Creating PeerConnection"),Bl.debug(f),r.pc=new RTCPeerConnection(E,f),Bl.debug(r.pc),r.pc.getStats&&(r.volume={},r.bitrate.value="0 kbits/sec"),Bl.log("Preparing local SDP and gathering candidates (trickle="+r.trickle+")"),r.pc.oniceconnectionstatechange=function(A){r.pc&&a.iceState(r.pc.iceConnectionState)},r.pc.onicecandidate=function(e){if(null==e.candidate||"edge"===Bl.webRTCAdapter.browserDetails.browser&&e.candidate.candidate.indexOf("endOfCandidates")>0)Bl.log("End of candidates."),r.iceDone=!0,!0===r.trickle?R(A,{completed:!0}):function(A,e){e=e||{},e.success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:Bl.noop;var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return void Bl.warn("Invalid handle, not sending anything");var i=t.webrtcStuff;if(Bl.log("Sending offer/answer SDP..."),null===i.mySdp||void 0===i.mySdp)return void Bl.warn("Local SDP instance is invalid, not sending anything...");i.mySdp={type:i.pc.localDescription.type,sdp:i.pc.localDescription.sdp},!1===i.trickle&&(i.mySdp.trickle=!1);Bl.debug(e),i.sdpSent=!0,e.success(i.mySdp)}(A,i);else{var t={candidate:e.candidate.candidate,sdpMid:e.candidate.sdpMid,sdpMLineIndex:e.candidate.sdpMLineIndex};!0===r.trickle&&R(A,t)}},r.pc.ontrack=function(A){Bl.log("Handling Remote Track"),Bl.debug(A),A.streams&&(r.remoteStream=A.streams[0],a.onremotestream(r.remoteStream),A.track.onended||(Bl.log("Adding onended callback to track:",A.track),A.track.onended=function(A){Bl.log("Remote track muted/removed:",A),r.remoteStream&&(r.remoteStream.removeTrack(A.target),a.onremotestream(r.remoteStream))},A.track.onmute=A.track.onended,A.track.onunmute=function(A){Bl.log("Remote track flowing again:",A);try{r.remoteStream.addTrack(A.target),a.onremotestream(r.remoteStream)}catch(A){Bl.error(A)}}))}}if(o&&null!=n)if(Bl.log("Adding local stream"),console.log("callbacks",i),"screen"==i.media.video){var x=!0===i.simulcast2;n.getTracks().forEach((function(A){if(Bl.log("Adding local track:",A),A.applyConstraints({frameRate:5}),x)if("audio"===A.kind)r.pc.addTrack(A,n);else{Bl.log("Enabling rid-based simulcasting:",A);var e=Q(i.simulcastMaxBitrates);r.pc.addTransceiver(A,{direction:"sendrecv",streams:[n],sendEncodings:[{rid:"h",active:!0,maxBitrate:e.high},{rid:"m",active:!0,maxBitrate:e.medium,scaleResolutionDownBy:2},{rid:"l",active:!0,maxBitrate:e.low,scaleResolutionDownBy:4}]})}else r.pc.addTrack(A,n)}))}else{x=!0===i.simulcast2;var p=n.getTracks(),y=p[0];if(y){var _=y.getSettings();console.log("videoTrack",y),console.log("videosettings",_)}var S=n.getAudioTracks()[0];if(S){var D=S.getSettings();console.log("audiosettings",D)}p.forEach((function(A){if(A.applyConstraints({frameRate:{max:i.frameRate}}),Bl.log("Adding local track:",A),x){r.pc.addTrack(A,n);var e=null,t=r.pc.getSenders();for(var a in t){var o=t[a];o&&o.track&&"video"===o.track.kind&&(e=o)}var s=null;e&&(s=e.getParameters()),s&&s.encodings&&(s.encodings[0].maxBitrate=1e5,e.setParameters(s).then((function(A){console.log("Successed to set parameters!",s)})).catch((function(A){console.log("err",A),console.error(A)})))}else if("audio"===A.kind)r.pc.addTrack(A,n);else{Bl.log("Enabling rid-based simulcasting:",A);var g=i.bitrate||1e5;r.pc.addTransceiver(A,{direction:"sendrecv",streams:[n],sendEncodings:[{rid:"h",active:!0,maxBitrate:g}]})}}))}(function(A){if(Bl.debug("isDataEnabled:",A),"edge"==Bl.webRTCAdapter.browserDetails.browser)return Bl.warn("Edge doesn't support data channels yet"),!1;return null!=A&&!0===A.data})(t)&&!r.dataChannel[Bl.dataChanDefaultLabel]&&(Bl.log("Creating data channel"),k(A,Bl.dataChanDefaultLabel,!1),r.pc.ondatachannel=function(e){Bl.log("Data channel created by Janus:",e),k(A,e.channel.label,e.channel)}),r.myStream&&a.onlocalstream(r.myStream),null==e?function(A,e,t){t=t||{},t.success="function"==typeof t.success?t.success:Bl.noop,t.error="function"==typeof t.error?t.error:Bl.noop,t.customizeSdp="function"==typeof t.customizeSdp?t.customizeSdp:Bl.noop;var i=m[A];if(null==i||null===i.webrtcStuff||void 0===i.webrtcStuff)return Bl.warn("Invalid handle"),void t.error("Invalid handle");var n=i.webrtcStuff,a=!0===t.simulcast;a?Bl.log("Creating offer (iceDone="+n.iceDone+", simulcast="+a+")"):Bl.log("Creating offer (iceDone="+n.iceDone+")");var r={};if(Bl.unifiedPlan){var o=null,s=null,g=n.pc.getTransceivers();if(g&&g.length>0)for(var c in g){var l=g[c];l.sender&&l.sender.track&&"audio"===l.sender.track.kind||l.receiver&&l.receiver.track&&"audio"===l.receiver.track.kind?o||(o=l):(l.sender&&l.sender.track&&"video"===l.sender.track.kind||l.receiver&&l.receiver.track&&"video"===l.receiver.track.kind)&&(s||(s=l))}var I=j(e),C=W(e);I||C?I&&C?o&&(o.setDirection?o.setDirection("sendrecv"):o.direction="sendrecv",Bl.log("Setting audio transceiver to sendrecv:",o)):I&&!C?o&&(o.setDirection?o.setDirection("sendonly"):o.direction="sendonly",Bl.log("Setting audio transceiver to sendonly:",o)):!I&&C&&(o?(o.setDirection?o.setDirection("recvonly"):o.direction="recvonly",Bl.log("Setting audio transceiver to recvonly:",o)):(o=n.pc.addTransceiver("audio",{direction:"recvonly"}),Bl.log("Adding recvonly audio transceiver:",o))):e.removeAudio&&o&&(o.setDirection?o.setDirection("inactive"):o.direction="inactive",Bl.log("Setting audio transceiver to inactive:",o));var d=Z(e),h=X(e);d||h?d&&h?s&&(s.setDirection?s.setDirection("sendrecv"):s.direction="sendrecv",Bl.log("Setting video transceiver to sendrecv:",s)):d&&!h?s&&(s.setDirection?s.setDirection("sendonly"):s.direction="sendonly",Bl.log("Setting video transceiver to sendonly:",s)):!d&&h&&(s?(s.setDirection?s.setDirection("recvonly"):s.direction="recvonly",Bl.log("Setting video transceiver to recvonly:",s)):(s=n.pc.addTransceiver("video",{direction:"recvonly"}),Bl.log("Adding recvonly video transceiver:",s))):e.removeVideo&&s&&(s.setDirection?s.setDirection("inactive"):s.direction="inactive",Bl.log("Setting video transceiver to inactive:",s))}else r.offerToReceiveAudio=W(e),r.offerToReceiveVideo=X(e);var B=!0===t.iceRestart;B&&(r.iceRestart=!0);Bl.debug(r);var u=Z(e);if(u&&a&&"firefox"===Bl.webRTCAdapter.browserDetails.browser){Bl.log("Enabling Simulcasting for Firefox (RID)");var E=n.pc.getSenders().find((function(A){return"video"==A.track.kind}));if(E){var f=E.getParameters();f||(f={});var x=Q(t.simulcastMaxBitrates);f.encodings=[{rid:"h",active:!0,maxBitrate:x.high},{rid:"m",active:!0,maxBitrate:x.medium,scaleResolutionDownBy:2},{rid:"l",active:!0,maxBitrate:x.low,scaleResolutionDownBy:4}],E.setParameters(f)}}n.pc.createOffer(r).then((function(A){Bl.debug(A);var e={type:A.type,sdp:A.sdp};t.customizeSdp(e),A.sdp=e.sdp,Bl.log("Setting local description"),u&&a&&("chrome"===Bl.webRTCAdapter.browserDetails.browser||"safari"===Bl.webRTCAdapter.browserDetails.browser?(Bl.log("Enabling Simulcasting for Chrome (SDP munging)"),A.sdp=function(A){for(var e=A.split("\r\n"),t=!1,i=[-1],n=[-1],a=null,r=null,o=null,s=null,g=-1,c=0;c<e.length;c++){if(I=e[c].match(/m=(\w+) */)){if("video"===I[1]){if(!(i[0]<0)){g=c;break}t=!0}else if(i[0]>-1){g=c;break}}else if(t){var l=e[c].match(/a=ssrc-group:FID (\d+) (\d+)/);if(l)i[0]=l[1],n[0]=l[2],e.splice(c,1),c--;else{if(i[0]){if((d=e[c].match("a=ssrc:"+i[0]+" cname:(.+)"))&&(a=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" msid:(.+)"))&&(r=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" mslabel:(.+)"))&&(o=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" label:(.+)"))&&(s=d[1]),0===e[c].indexOf("a=ssrc:"+n[0])){e.splice(c,1),c--;continue}if(0===e[c].indexOf("a=ssrc:"+i[0])){e.splice(c,1),c--;continue}}0!=e[c].length||(e.splice(c,1),c--)}}}if(i[0]<0){g=-1,t=!1;for(c=0;c<e.length;c++){var I;if(I=e[c].match(/m=(\w+) */)){if("video"===I[1]){if(!(i[0]<0)){g=c;break}t=!0}else if(i[0]>-1){g=c;break}}else if(t){if(i[0]<0){var C=e[c].match(/a=ssrc:(\d+)/);if(C){i[0]=C[1],e.splice(c,1),c--;continue}}else{var d;if((d=e[c].match("a=ssrc:"+i[0]+" cname:(.+)"))&&(a=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" msid:(.+)"))&&(r=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" mslabel:(.+)"))&&(o=d[1]),(d=e[c].match("a=ssrc:"+i[0]+" label:(.+)"))&&(s=d[1]),0===e[c].indexOf("a=ssrc:"+n[0])){e.splice(c,1),c--;continue}if(0===e[c].indexOf("a=ssrc:"+i[0])){e.splice(c,1),c--;continue}}0!=e[c].length||(e.splice(c,1),c--)}}}if(i[0]<0)return Bl.warn("Couldn't find the video SSRC, simulcasting NOT enabled"),A;g<0&&(g=e.length);i[1]=Math.floor(4294967295*Math.random()),i[2]=Math.floor(4294967295*Math.random()),n[1]=Math.floor(4294967295*Math.random()),n[2]=Math.floor(4294967295*Math.random());for(c=0;c<i.length;c++)a&&(e.splice(g,0,"a=ssrc:"+i[c]+" cname:"+a),g++),r&&(e.splice(g,0,"a=ssrc:"+i[c]+" msid:"+r),g++),o&&(e.splice(g,0,"a=ssrc:"+i[c]+" mslabel:"+o),g++),s&&(e.splice(g,0,"a=ssrc:"+i[c]+" label:"+s),g++),a&&(e.splice(g,0,"a=ssrc:"+n[c]+" cname:"+a),g++),r&&(e.splice(g,0,"a=ssrc:"+n[c]+" msid:"+r),g++),o&&(e.splice(g,0,"a=ssrc:"+n[c]+" mslabel:"+o),g++),s&&(e.splice(g,0,"a=ssrc:"+n[c]+" label:"+s),g++);e.splice(g,0,"a=ssrc-group:FID "+i[2]+" "+n[2]),e.splice(g,0,"a=ssrc-group:FID "+i[1]+" "+n[1]),e.splice(g,0,"a=ssrc-group:FID "+i[0]+" "+n[0]),e.splice(g,0,"a=ssrc-group:SIM "+i[0]+" "+i[1]+" "+i[2]),(A=e.join("\r\n")).endsWith("\r\n")||(A+="\r\n");return A}(A.sdp)):"firefox"!==Bl.webRTCAdapter.browserDetails.browser&&Bl.warn("simulcast=true, but this is not Chrome nor Firefox, ignoring")),n.mySdp=A.sdp,n.pc.setLocalDescription(A).catch(t.error),n.mediaConstraints=r,n.iceDone||n.trickle?(Bl.log("Offer ready"),Bl.debug(t),t.success(A)):Bl.log("Waiting for all candidates...")}),t.error)}(A,t,i):r.pc.setRemoteDescription(e).then((function(){if(Bl.log("Remote description accepted!"),r.remoteSdp=e.sdp,r.candidates&&r.candidates.length>0){for(var n=0;n<r.candidates.length;n++){var a=r.candidates[n];Bl.debug("Adding remote candidate:",a),a&&!0!==a.completed?r.pc.addIceCandidate(a):r.pc.addIceCandidate(Bl.endOfCandidates)}r.candidates=[]}!function(A,e,t){t=t||{},t.success="function"==typeof t.success?t.success:Bl.noop,t.error="function"==typeof t.error?t.error:Bl.noop,t.customizeSdp="function"==typeof t.customizeSdp?t.customizeSdp:Bl.noop;var i=m[A];if(null==i||null===i.webrtcStuff||void 0===i.webrtcStuff)return Bl.warn("Invalid handle"),void t.error("Invalid handle");var n=i.webrtcStuff,a=!0===t.simulcast;a?Bl.log("Creating answer (iceDone="+n.iceDone+", simulcast="+a+")"):Bl.log("Creating answer (iceDone="+n.iceDone+")");var r=null;if(Bl.unifiedPlan){r={};var o=null,s=null,g=n.pc.getTransceivers();if(g&&g.length>0)for(var c in g){var l=g[c];l.sender&&l.sender.track&&"audio"===l.sender.track.kind||l.receiver&&l.receiver.track&&"audio"===l.receiver.track.kind?o||(o=l):(l.sender&&l.sender.track&&"video"===l.sender.track.kind||l.receiver&&l.receiver.track&&"video"===l.receiver.track.kind)&&(s||(s=l))}var I=j(e),C=W(e);if(I||C){if(I&&C){if(o)try{o.setDirection?o.setDirection("sendrecv"):o.direction="sendrecv",Bl.log("Setting audio transceiver to sendrecv:",o)}catch(A){Bl.error(A)}}else if(I&&!C)try{o&&(o.setDirection?o.setDirection("sendonly"):o.direction="sendonly",Bl.log("Setting audio transceiver to sendonly:",o))}catch(A){Bl.error(A)}else if(!I&&C)if(o)try{o.setDirection?o.setDirection("recvonly"):o.direction="recvonly",Bl.log("Setting audio transceiver to recvonly:",o)}catch(A){Bl.error(A)}else o=n.pc.addTransceiver("audio",{direction:"recvonly"}),Bl.log("Adding recvonly audio transceiver:",o)}else if(e.removeAudio&&o)try{o.setDirection?o.setDirection("inactive"):o.direction="inactive",Bl.log("Setting audio transceiver to inactive:",o)}catch(A){Bl.error(A)}var d=Z(e),h=X(e);if(d||h){if(d&&h){if(s)try{s.setDirection?s.setDirection("sendrecv"):s.direction="sendrecv",Bl.log("Setting video transceiver to sendrecv:",s)}catch(A){Bl.error(A)}}else if(d&&!h){if(s)try{s.setDirection?s.setDirection("sendonly"):s.direction="sendonly",Bl.log("Setting video transceiver to sendonly:",s)}catch(A){Bl.error(A)}}else if(!d&&h)if(s)try{s.setDirection?s.setDirection("recvonly"):s.direction="recvonly",Bl.log("Setting video transceiver to recvonly:",s)}catch(A){Bl.error(A)}else s=n.pc.addTransceiver("video",{direction:"recvonly"}),Bl.log("Adding recvonly video transceiver:",s)}else if(e.removeVideo&&s)try{s.setDirection?s.setDirection("inactive"):s.direction="inactive",Bl.log("Setting video transceiver to inactive:",s)}catch(A){Bl.error(A)}}else r="firefox"==Bl.webRTCAdapter.browserDetails.browser||"edge"==Bl.webRTCAdapter.browserDetails.browser?{offerToReceiveAudio:W(e),offerToReceiveVideo:X(e)}:{mandatory:{OfferToReceiveAudio:W(e),OfferToReceiveVideo:X(e)}};Bl.debug(r);var B=Z(e);if(B&&a&&"firefox"===Bl.webRTCAdapter.browserDetails.browser){Bl.log("Enabling Simulcasting for Firefox (RID)");var u=n.pc.getSenders()[1];Bl.log(u);var E=u.getParameters();Bl.log(E);var f=Q(t.simulcastMaxBitrates);u.setParameters({encodings:[{rid:"high",active:!0,priority:"high",maxBitrate:f.high},{rid:"medium",active:!0,priority:"medium",maxBitrate:f.medium},{rid:"low",active:!0,priority:"low",maxBitrate:f.low}]})}n.pc.createAnswer(r).then((function(A){Bl.debug(A);var e={type:A.type,sdp:A.sdp};t.customizeSdp(e),A.sdp=e.sdp,Bl.log("Setting local description"),B&&a&&("chrome"===Bl.webRTCAdapter.browserDetails.browser?Bl.warn("simulcast=true, but this is an answer, and video breaks in Chrome if we enable it"):"firefox"!==Bl.webRTCAdapter.browserDetails.browser&&Bl.warn("simulcast=true, but this is not Chrome nor Firefox, ignoring")),n.mySdp=A.sdp,n.pc.setLocalDescription(A).catch(t.error),n.mediaConstraints=r,n.iceDone||n.trickle?t.success(A):Bl.log("Waiting for all candidates...")}),t.error)}(A,t,i)}),i.error)}function L(A,e,t){(t=t||{}).success="function"==typeof t.success?t.success:Bl.noop,t.error="function"==typeof t.error?t.error:V;var i=t.jsep;if(e&&i)return Bl.error("Provided a JSEP to a createOffer"),void t.error("Provided a JSEP to a createOffer");if(!(e||i&&i.type&&i.sdp))return Bl.error("A valid JSEP is required for createAnswer"),void t.error("A valid JSEP is required for createAnswer");t.media=t.media||{audio:!0,video:!0};var n=t.media,a=m[A];if(null==a||null===a.webrtcStuff||void 0===a.webrtcStuff)return Bl.warn("Invalid handle"),void t.error("Invalid handle");var r,o=a.webrtcStuff;if(o.trickle=(r=t.trickle,Bl.debug("isTrickleEnabled:",r),null==r||!0===r),void 0===o.pc||null===o.pc)n.update=!1,n.keepAudio=!1,n.keepVideo=!1;else if(void 0!==o.pc&&null!==o.pc){if(Bl.log("Updating existing media session"),n.update=!0,null!==t.stream&&void 0!==t.stream)t.stream!==o.myStream&&Bl.log("Renegotiation involves a new external stream");else{if(n.addAudio){if(n.keepAudio=!1,n.replaceAudio=!1,n.removeAudio=!1,n.audioSend=!0,o.myStream&&o.myStream.getAudioTracks()&&o.myStream.getAudioTracks().length)return Bl.error("Can't add audio stream, there already is one"),void t.error("Can't add audio stream, there already is one")}else n.removeAudio?(n.keepAudio=!1,n.replaceAudio=!1,n.addAudio=!1,n.audioSend=!1):n.replaceAudio&&(n.keepAudio=!1,n.addAudio=!1,n.removeAudio=!1,n.audioSend=!0);if(null===o.myStream||void 0===o.myStream?(n.replaceAudio&&(n.keepAudio=!1,n.replaceAudio=!1,n.addAudio=!0,n.audioSend=!0),j(n)&&(n.keepAudio=!1,n.addAudio=!0)):null===o.myStream.getAudioTracks()||void 0===o.myStream.getAudioTracks()||0===o.myStream.getAudioTracks().length?(n.replaceAudio&&(n.keepAudio=!1,n.replaceAudio=!1,n.addAudio=!0,n.audioSend=!0),j(n)&&(n.keepVideo=!1,n.addAudio=!0)):!j(n)||n.removeAudio||n.replaceAudio||(n.keepAudio=!0),n.addVideo){if(n.keepVideo=!1,n.replaceVideo=!1,n.removeVideo=!1,n.videoSend=!0,o.myStream&&o.myStream.getVideoTracks()&&o.myStream.getVideoTracks().length)return Bl.error("Can't add video stream, there already is one"),void t.error("Can't add video stream, there already is one")}else n.removeVideo?(n.keepVideo=!1,n.replaceVideo=!1,n.addVideo=!1,n.videoSend=!1):n.replaceVideo&&(n.keepVideo=!1,n.addVideo=!1,n.removeVideo=!1,n.videoSend=!0);null===o.myStream||void 0===o.myStream||null===o.myStream.getVideoTracks()||void 0===o.myStream.getVideoTracks()||0===o.myStream.getVideoTracks().length?(n.replaceVideo&&(n.keepVideo=!1,n.replaceVideo=!1,n.addVideo=!0,n.videoSend=!0),Z(n)&&(n.keepVideo=!1,n.addVideo=!0)):!Z(n)||n.removeVideo||n.replaceVideo||(n.keepVideo=!0),n.addData&&(n.data=!0)}if(j(n)&&n.keepAudio&&Z(n)&&n.keepVideo)return a.consentDialog(!1),void M(A,i,n,t,o.myStream)}if(n.update&&!o.streamExternal){if(n.removeAudio||n.replaceAudio){if(o.myStream&&o.myStream.getAudioTracks()&&o.myStream.getAudioTracks().length){var s=o.myStream.getAudioTracks()[0];Bl.log("Removing audio track:",s),o.myStream.removeTrack(s);try{s.stop()}catch(A){}}if(o.pc.getSenders()&&o.pc.getSenders().length){var g=!0;if(n.replaceAudio&&Bl.unifiedPlan&&(g=!1),g)for(var c in o.pc.getSenders()){(s=o.pc.getSenders()[c])&&s.track&&"audio"===s.track.kind&&(Bl.log("Removing audio sender:",s),o.pc.removeTrack(s))}}}if(n.removeVideo||n.replaceVideo){if(o.myStream&&o.myStream.getVideoTracks()&&o.myStream.getVideoTracks().length){s=o.myStream.getVideoTracks()[0];Bl.log("Removing video track:",s),o.myStream.removeTrack(s);try{s.stop()}catch(A){}}if(o.pc.getSenders()&&o.pc.getSenders().length){var l=!0;if(n.replaceVideo&&Bl.unifiedPlan&&(l=!1),l)for(var c in o.pc.getSenders()){(s=o.pc.getSenders()[c])&&s.track&&"video"===s.track.kind&&(Bl.log("Removing video sender:",s),o.pc.removeTrack(s))}}}}if(null!==t.stream&&void 0!==t.stream){var I=t.stream;if(Bl.log("MediaStream provided by the application"),Bl.debug(I),n.update&&o.myStream&&o.myStream!==t.stream&&!o.streamExternal){try{var d=o.myStream.getTracks();for(var h in d){var B=d[h];Bl.log(B),null!=B&&B.stop()}}catch(A){}o.myStream=null}return o.streamExternal=!0,a.consentDialog(!1),void M(A,i,n,t,I)}if(j(n)||Z(n)){if(!Bl.isGetUserMediaAvailable())return void t.error("getUserMedia not available");var u={mandatory:{},optional:[]};a.consentDialog(!0);var E=j(n);!0===E&&null!=n&&null!=n&&"object"===C(n.audio)&&(E=n.audio);var f=Z(n);if(!0===f&&null!=n&&null!=n){var Q=!0===t.simulcast,x=!0===t.simulcast2;if(!Q&&!x||i||void 0!==n.video&&!1!==n.video||(n.video="hires"),n.video&&"screen"!=n.video&&"window"!=n.video)if("object"===C(n.video))f=n.video;else{var p=0,y=0;"lowres"===n.video?(y=240,p=320):"lowres-16:9"===n.video?(y=180,p=320):"hires"===n.video||"hires-16:9"===n.video||"hdres"===n.video?(y=720,p=1280):"fhdres"===n.video?(y=1080,p=1920):"4kres"===n.video?(y=2160,p=3840):"stdres"===n.video?(y=480,p=640):"stdres-16:9"===n.video?(y=360,p=640):(Bl.log("Default video setting is stdres 4:3"),y=480,p=640),Bl.log("Adding media constraint:",n.video),f={height:{ideal:y},width:{ideal:p}},Bl.log("Adding video constraint:",f)}else if("screen"===n.video||"window"===n.video){var _=function(e,r){a.consentDialog(!1),e?t.error(e):M(A,i,n,t,r)},S=function(A,e,t){Bl.log("Adding media constraint (screen capture)"),Bl.debug(A),navigator.mediaDevices.getUserMedia(A).then((function(A){t?navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then((function(t){A.addTrack(t.getAudioTracks()[0]),e(null,A)})):e(null,A)})).catch((function(A){a.consentDialog(!1),e(A)}))};if(n.screenshareFrameRate||(n.screenshareFrameRate=3),navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia)return void navigator.mediaDevices.getDisplayMedia({video:!0}).then((function(e){a.consentDialog(!1),j(n)&&!n.keepAudio?navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then((function(a){e.addTrack(a.getAudioTracks()[0]),M(A,i,n,t,e)})):M(A,i,n,t,e)}),(function(A){a.consentDialog(!1),t.error(A)}));if("chrome"===Bl.webRTCAdapter.browserDetails.browser){var D=Bl.webRTCAdapter.browserDetails.version,w=33;window.navigator.userAgent.match("Linux")&&(w=35),D>=26&&D<=w?(u={video:{mandatory:{googLeakyBucket:!0,maxWidth:window.screen.width,maxHeight:window.screen.height,minFrameRate:n.screenshareFrameRate,maxFrameRate:n.screenshareFrameRate,chromeMediaSource:"screen"}},audio:j(n)&&!n.keepAudio},S(u,_)):Bl.extension.getScreen((function(A,e){if(A)return a.consentDialog(!1),t.error(A);(u={audio:!1,video:{mandatory:{chromeMediaSource:"desktop",maxWidth:window.screen.width,maxHeight:window.screen.height,minFrameRate:n.screenshareFrameRate,maxFrameRate:n.screenshareFrameRate},optional:[{googLeakyBucket:!0},{googTemporalLayeredScreencast:!0}]}}).video.mandatory.chromeMediaSourceId=e,S(u,_,j(n)&&!n.keepAudio)}))}else if("firefox"===Bl.webRTCAdapter.browserDetails.browser){if(!(Bl.webRTCAdapter.browserDetails.version>=33)){var v=new Error("NavigatorUserMediaError");return v.name="Your version of Firefox does not support screen sharing, please install Firefox 33 (or more recent versions)",a.consentDialog(!1),void t.error(v)}u={video:{mozMediaSource:n.video,mediaSource:n.video},audio:j(n)&&!n.keepAudio},S(u,(function(A,e){if(_(A,e),!A)var t=e.currentTime,i=window.setInterval((function(){e||window.clearInterval(i),e.currentTime==t&&(window.clearInterval(i),e.onended&&e.onended()),t=e.currentTime}),500)}))}return}}null!=n&&"screen"===n.video||navigator.mediaDevices.enumerateDevices().then((function(e){var r=e.some((function(A){return"audioinput"===A.kind})),o=function(A){if(Bl.debug("isScreenSendEnabled:",A),null==A)return!1;if("object"!==C(A.video)||"object"!==C(A.video.mandatory))return!1;var e=A.video.mandatory;if(e.chromeMediaSource)return"desktop"===e.chromeMediaSource||"screen"===e.chromeMediaSource;if(e.mozMediaSource)return"window"===e.mozMediaSource||"screen"===e.mozMediaSource;if(e.mediaSource)return"window"===e.mediaSource||"screen"===e.mediaSource;return!1}(n)||e.some((function(A){return"videoinput"===A.kind})),s=j(n),g=Z(n),c=function(A){return Bl.debug("isAudioSendRequired:",A),null!=A&&(!1!==A.audio&&!1!==A.audioSend&&(void 0!==A.failIfNoAudio&&null!==A.failIfNoAudio&&!0===A.failIfNoAudio))}(n),l=function(A){return Bl.debug("isVideoSendRequired:",A),null!=A&&(!1!==A.video&&!1!==A.videoSend&&(void 0!==A.failIfNoVideo&&null!==A.failIfNoVideo&&!0===A.failIfNoVideo))}(n);if(s||g||c||l){var d=!!s&&r,h=!!g&&o;if(!d&&!h)return a.consentDialog(!1),t.error("No capture device found"),!1;if(!d&&c)return a.consentDialog(!1),t.error("Audio capture is required, but no capture device found"),!1;if(!h&&l)return a.consentDialog(!1),t.error("Video capture is required, but no capture device found"),!1}var B={audio:!(!r||n.keepAudio)&&E,video:!(!o||n.keepVideo)&&f};n.encodings&&(B=n.encodings),Bl.debug("getUserMedia constraints",B),B.audio||B.video?(console.log("gumConstraints_________",B,n.encodings),navigator.mediaDevices.getUserMedia(n.encodings?n.encodings:B).then((function(e){a.consentDialog(!1),M(A,i,n,t,e)})).catch((function(A){a.consentDialog(!1),t.error({code:A.code,name:A.name,message:A.message})}))):(a.consentDialog(!1),M(A,i,n,t,I))})).catch((function(A){a.consentDialog(!1),t.error("enumerateDevices error",A)}))}else M(A,i,n,t)}function Y(A,e){(e=e||{}).success="function"==typeof e.success?e.success:Bl.noop,e.error="function"==typeof e.error?e.error:V;var t=e.jsep,i=m[A];if(null==i||null===i.webrtcStuff||void 0===i.webrtcStuff)return Bl.warn("Invalid handle"),void e.error("Invalid handle");var n=i.webrtcStuff;if(null!=t){if(null===n.pc)return Bl.warn("Wait, no PeerConnection?? if this is an answer, use createAnswer and not handleRemoteJsep"),void e.error("No PeerConnection: if this is an answer, use createAnswer and not handleRemoteJsep");n.pc.setRemoteDescription(t).then((function(){if(Bl.log("Remote description accepted!"),n.remoteSdp=t.sdp,n.candidates&&n.candidates.length>0){for(var A=0;A<n.candidates.length;A++){var i=n.candidates[A];Bl.debug("Adding remote candidate:",i),i&&!0!==i.completed?n.pc.addIceCandidate(i):n.pc.addIceCandidate(Bl.endOfCandidates)}n.candidates=[]}e.success()}),e.error)}else e.error("Invalid JSEP")}function G(A,e){var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return Bl.warn("Invalid handle"),0;var i=e?"remote":"local",n=t.webrtcStuff;return n.volume[i]||(n.volume[i]={value:0}),n.pc.getStats&&"chrome"===Bl.webRTCAdapter.browserDetails.browser?!e||null!==n.remoteStream&&void 0!==n.remoteStream?e||null!==n.myStream&&void 0!==n.myStream?null===n.volume[i].timer||void 0===n.volume[i].timer?(Bl.log("Starting "+i+" volume monitor"),n.volume[i].timer=setInterval((function(){n.pc.getStats((function(A){for(var t=A.result(),a=0;a<t.length;a++){var r=t[a];"ssrc"==r.type&&(e&&r.stat("audioOutputLevel")?n.volume[i].value=parseInt(r.stat("audioOutputLevel")):!e&&r.stat("audioInputLevel")&&(n.volume[i].value=parseInt(r.stat("audioInputLevel"))))}}))}),200),0):n.volume[i].value:(Bl.warn("Local stream unavailable"),0):(Bl.warn("Remote stream unavailable"),0):(Bl.warn("Getting the "+i+" volume unsupported by browser"),0)}function U(A,e){var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return Bl.warn("Invalid handle"),!0;var i=t.webrtcStuff;return null===i.pc||void 0===i.pc?(Bl.warn("Invalid PeerConnection"),!0):void 0===i.myStream||null===i.myStream?(Bl.warn("Invalid local MediaStream"),!0):e?null===i.myStream.getVideoTracks()||void 0===i.myStream.getVideoTracks()||0===i.myStream.getVideoTracks().length?(Bl.warn("No video track"),!0):!i.myStream.getVideoTracks()[0].enabled:null===i.myStream.getAudioTracks()||void 0===i.myStream.getAudioTracks()||0===i.myStream.getAudioTracks().length?(Bl.warn("No audio track"),!0):!i.myStream.getAudioTracks()[0].enabled}function J(A,e,t){var i=m[A];if(null==i||null===i.webrtcStuff||void 0===i.webrtcStuff)return Bl.warn("Invalid handle"),!1;var n=i.webrtcStuff;return null===n.pc||void 0===n.pc?(Bl.warn("Invalid PeerConnection"),!1):void 0===n.myStream||null===n.myStream?(Bl.warn("Invalid local MediaStream"),!1):e?null===n.myStream.getVideoTracks()||void 0===n.myStream.getVideoTracks()||0===n.myStream.getVideoTracks().length?(Bl.warn("No video track"),!1):(n.myStream.getVideoTracks()[0].enabled=!t,!0):null===n.myStream.getAudioTracks()||void 0===n.myStream.getAudioTracks()||0===n.myStream.getAudioTracks().length?(Bl.warn("No audio track"),!1):(n.myStream.getAudioTracks()[0].enabled=!t,!0)}function H(A,e){var t=m[A];if(null==t||null===t.webrtcStuff||void 0===t.webrtcStuff)return Bl.warn("Invalid handle"),"Invalid handle";var i=t.webrtcStuff;return null===i.pc||void 0===i.pc?"Invalid PeerConnection":i.pc.getStats?void i.pc.getStats().then((function(A){A.forEach((function(A){if(A){var t=!1;if(("video"===A.mediaType||A.id.toLowerCase().indexOf("video")>-1)&&"inbound-rtp"===A.type&&A.id.indexOf("rtcp")<0?t=!0:"ssrc"!=A.type||!A.bytesReceived||"VP8"!==A.googCodecName&&""!==A.googCodecName||(t=!0),t)if(e&&e(A),i.bitrate.bsnow=A.bytesReceived,i.bitrate.tsnow=A.timestamp,null===i.bitrate.bsbefore||null===i.bitrate.tsbefore)i.bitrate.bsbefore=i.bitrate.bsnow,i.bitrate.tsbefore=i.bitrate.tsnow;else{var n=i.bitrate.tsnow-i.bitrate.tsbefore;"safari"==Bl.webRTCAdapter.browserDetails.browser&&(n/=1e3);var a=Math.round(8*(i.bitrate.bsnow-i.bitrate.bsbefore)/n);"safari"===Bl.webRTCAdapter.browserDetails.browser&&(a=parseInt(a/1e3)),i.bitrate.value=a+" kbits/sec",i.bitrate.bsbefore=i.bitrate.bsnow,i.bitrate.tsbefore=i.bitrate.tsnow}}}))})):(Bl.warn("Getting the video bitrate unsupported by browser"),"Feature unsupported by browser")}function K(A){var e=m[A];if(null==e||null===e.webrtcStuff||void 0===e.webrtcStuff)return Bl.warn("Invalid handle"),"Invalid handle";var t=e.webrtcStuff;return null===t.pc||void 0===t.pc?"Invalid PeerConnection":t.pc.getStats?null===t.bitrate.timer||void 0===t.bitrate.timer?(Bl.log("Starting bitrate timer (via getStats)"),t.bitrate.timer=setInterval((function(){t.pc.getStats().then((function(A){A.forEach((function(A){if(A){var e=!1;if(("video"===A.mediaType||A.id.toLowerCase().indexOf("video")>-1)&&"inbound-rtp"===A.type&&A.id.indexOf("rtcp")<0?e=!0:"ssrc"!=A.type||!A.bytesReceived||"VP8"!==A.googCodecName&&""!==A.googCodecName||(e=!0),e)if(t.bitrate.bsnow=A.bytesReceived,t.bitrate.tsnow=A.timestamp,null===t.bitrate.bsbefore||null===t.bitrate.tsbefore)t.bitrate.bsbefore=t.bitrate.bsnow,t.bitrate.tsbefore=t.bitrate.tsnow;else{var i=t.bitrate.tsnow-t.bitrate.tsbefore;"safari"==Bl.webRTCAdapter.browserDetails.browser&&(i/=1e3);var n=Math.round(8*(t.bitrate.bsnow-t.bitrate.bsbefore)/i);"safari"===Bl.webRTCAdapter.browserDetails.browser&&(n=parseInt(n/1e3)),t.bitrate.value=n+" kbits/sec",t.bitrate.bsbefore=t.bitrate.bsnow,t.bitrate.tsbefore=t.bitrate.tsnow}}}))}))}),1e3),"0 kbits/sec"):t.bitrate.value:(Bl.warn("Getting the video bitrate unsupported by browser"),"Feature unsupported by browser")}function V(A){Bl.error("WebRTC error:",A)}function O(A,e){Bl.log("Cleaning WebRTC stuff");var n=m[A];if(null!=n){var a=n.webrtcStuff;if(null!=a){if(!0===e){var r={rtcgw:"hangup",transaction:Bl.randomString(12)};null!==n.token&&void 0!==n.token&&(r.token=n.token),null!=u&&(r.apisecret=u),Bl.debug("Sending hangup request (handle="+A+"):"),Bl.debug(r),t?(r.session_id=p,r.handle_id=A,i.send(JSON.stringify(r))):Bl.httpAPICall(s+"/"+p+"/"+A,{verb:"POST",withCredentials:d,body:r})}a.remoteStream=null,a.volume&&(a.volume.local&&a.volume.local.timer&&clearInterval(a.volume.local.timer),a.volume.remote&&a.volume.remote.timer&&clearInterval(a.volume.remote.timer)),a.volume={},a.bitrate.timer&&clearInterval(a.bitrate.timer),a.bitrate.timer=null,a.bitrate.bsnow=null,a.bitrate.bsbefore=null,a.bitrate.tsnow=null,a.bitrate.tsbefore=null,a.bitrate.value=null;try{if(!a.streamExternal&&null!==a.myStream&&void 0!==a.myStream){Bl.log("Stopping local stream tracks");var o=a.myStream.getTracks();for(var g in o){var c=o[g];Bl.log(c),null!=c&&c.stop()}}}catch(A){}a.streamExternal=!1,a.myStream=null;try{a.pc.close()}catch(A){}a.pc=null,a.candidates=null,a.mySdp=null,a.remoteSdp=null,a.iceDone=!1,a.dataChannel={},a.dtmfSender=null}n.oncleanup()}}function j(A){return Bl.debug("isAudioSendEnabled:",A),null==A||!1!==A.audio&&(void 0===A.audioSend||null===A.audioSend||!0===A.audioSend)}function W(A){return Bl.debug("isAudioRecvEnabled:",A),null==A||!1!==A.audio&&(void 0===A.audioRecv||null===A.audioRecv||!0===A.audioRecv)}function Z(A){return Bl.debug("isVideoSendEnabled:",A),null==A||!1!==A.video&&(void 0===A.videoSend||null===A.videoSend||!0===A.videoSend)}function X(A){return Bl.debug("isVideoRecvEnabled:",A),null==A||!1!==A.video&&(void 0===A.videoRecv||null===A.videoRecv||!0===A.videoRecv)}F(A),this.getServer=function(){return s},this.isConnected=function(){return x},this.reconnect=function(A){(A=A||{}).success="function"==typeof A.success?A.success:Bl.noop,A.error="function"==typeof A.error?A.error:Bl.noop,A.reconnect=!0,F(A)},this.getSessionId=function(){return p},this.destroy=function(e){!function(e){e=e||{},e.success="function"==typeof e.success?e.success:Bl.noop;var r=!0;void 0!==e.asyncRequest&&null!==e.asyncRequest&&(r=!0===e.asyncRequest);var o=!0;void 0!==e.notifyDestroyed&&null!==e.notifyDestroyed&&(o=!0===e.notifyDestroyed);var g=!1;void 0!==e.cleanupHandles&&null!==e.cleanupHandles&&(g=!0===e.cleanupHandles);if(Bl.log("Destroying session "+p+" (async="+r+")"),!x)return Bl.warn("Is the server down? (connected=false)"),void e.success();if(null==p)return Bl.warn("No session to destroy"),e.success(),void(o&&A.destroyed());if(g)for(var c in m)T(c,{noRequest:!0});var l={rtcgw:"destroy",transaction:Bl.randomString(12)};null!=B&&(l.token=B);null!=u&&(l.apisecret=u);if(t){l.session_id=p;var I=function(){for(var A in n)i.removeEventListener(A,n[A]);i.removeEventListener("message",C),i.removeEventListener("error",h),a&&clearTimeout(a),i.close()},C=function(t){var i=JSON.parse(t.data);i.session_id==l.session_id&&i.transaction==l.transaction&&(I(),e.success(),o&&A.destroyed())},h=function(t){I(),e.error("Failed to destroy the server: Is the server down?"),o&&A.destroyed()};return i.addEventListener("message",C),i.addEventListener("error",h),void i.send(JSON.stringify(l))}Bl.httpAPICall(s+"/"+p,{verb:"POST",async:r,withCredentials:d,body:l,success:function(t){Bl.log("Destroyed session:"),Bl.debug(t),p=null,x=!1,"success"!==t.rtcgw&&Bl.error("Ooops: "+t.error.code+" "+t.error.reason),e.success(),o&&A.destroyed()},error:function(t,i){Bl.error(t+":",i),p=null,x=!1,e.success(),o&&A.destroyed(),pluginHandlesp}})}(e)},this.attach=function(A){!function(A){if(A=A||{},A.success="function"==typeof A.success?A.success:Bl.noop,A.error="function"==typeof A.error?A.error:Bl.noop,A.consentDialog="function"==typeof A.consentDialog?A.consentDialog:Bl.noop,A.iceState="function"==typeof A.iceState?A.iceState:Bl.noop,A.mediaState="function"==typeof A.mediaState?A.mediaState:Bl.noop,A.webrtcState="function"==typeof A.webrtcState?A.webrtcState:Bl.noop,A.slowLink="function"==typeof A.slowLink?A.slowLink:Bl.noop,A.onmessage="function"==typeof A.onmessage?A.onmessage:Bl.noop,A.onlocalstream="function"==typeof A.onlocalstream?A.onlocalstream:Bl.noop,A.onremotestream="function"==typeof A.onremotestream?A.onremotestream:Bl.noop,A.ondata="function"==typeof A.ondata?A.ondata:Bl.noop,A.ondataopen="function"==typeof A.ondataopen?A.ondataopen:Bl.noop,A.oncleanup="function"==typeof A.oncleanup?A.oncleanup:Bl.noop,A.ondetached="function"==typeof A.ondetached?A.ondetached:Bl.noop,!x)return Bl.warn("Is the server down? (connected=false)"),void A.error("Is the server down? (connected=false)");var e=A.plugin;if(null==e)return Bl.error("Invalid plugin"),void A.error("Invalid plugin");var n=A.opaqueId,a=A.token?A.token:B,r=Bl.randomString(12),o={rtcgw:"attach",plugin:e,opaque_id:n,transaction:r};null!=a&&(o.token=a);null!=u&&(o.apisecret=u);if(t)return S[r]=function(t){if(Bl.debug(t),"success"!==t.rtcgw)return Bl.error("Ooops: "+t.error.code+" "+t.error.reason),void A.error("Ooops: "+t.error.code+" "+t.error.reason);var i=t.data.id;Bl.log("Created handle: "+i);var n={session:y,plugin:e,id:i,token:a,detached:!1,webrtcStuff:{started:!1,myStream:null,streamExternal:!1,remoteStream:null,mySdp:null,mediaConstraints:null,pc:null,dataChannel:{},dtmfSender:null,trickle:!0,iceDone:!1,volume:{value:null,timer:null},bitrate:{value:null,bsnow:null,bsbefore:null,tsnow:null,tsbefore:null,timer:null}},getId:function(){return i},getPlugin:function(){return e},getVolume:function(){return G(i,!0)},getRemoteVolume:function(){return G(i,!0)},getLocalVolume:function(){return G(i,!1)},isAudioMuted:function(){return U(i,!1)},muteAudio:function(){return J(i,!1,!0)},unmuteAudio:function(){return J(i,!1,!1)},isVideoMuted:function(){return U(i,!0)},muteVideo:function(){return J(i,!0,!0)},unmuteVideo:function(){return J(i,!0,!1)},getBitrate:function(){return K(i)},getNetworkQuality:function(A){H(i,A)},send:function(A){b(i,A)},data:function(A){P(i,A)},dtmf:function(A){N(i,A)},consentDialog:A.consentDialog,iceState:A.iceState,mediaState:A.mediaState,webrtcState:A.webrtcState,slowLink:A.slowLink,onmessage:A.onmessage,createOffer:function(A){L(i,!0,A)},createAnswer:function(A){L(i,!1,A)},handleRemoteJsep:function(A){Y(i,A)},onlocalstream:A.onlocalstream,onremotestream:A.onremotestream,ondata:A.ondata,ondataopen:A.ondataopen,oncleanup:A.oncleanup,ondetached:A.ondetached,hangup:function(A){O(i,!0===A)},detach:function(A){T(i,A)}};m[i]=n,A.success(n)},o.session_id=p,void i.send(JSON.stringify(o));Bl.httpAPICall(s+"/"+p,{verb:"POST",withCredentials:d,body:o,success:function(t){if(Bl.debug(t),"success"!==t.rtcgw)return Bl.error("Ooops: "+t.error.code+" "+t.error.reason),void A.error("Ooops: "+t.error.code+" "+t.error.reason);var i=t.data.id;Bl.log("Created handle: "+i);var n={session:y,plugin:e,id:i,token:a,detached:!1,webrtcStuff:{started:!1,myStream:null,streamExternal:!1,remoteStream:null,mySdp:null,mediaConstraints:null,pc:null,dataChannel:{},dtmfSender:null,trickle:!0,iceDone:!1,volume:{value:null,timer:null},bitrate:{value:null,bsnow:null,bsbefore:null,tsnow:null,tsbefore:null,timer:null}},getId:function(){return i},getPlugin:function(){return e},getVolume:function(){return G(i,!0)},getRemoteVolume:function(){return G(i,!0)},getLocalVolume:function(){return G(i,!1)},isAudioMuted:function(){return U(i,!1)},muteAudio:function(){return J(i,!1,!0)},unmuteAudio:function(){return J(i,!1,!1)},isVideoMuted:function(){return U(i,!0)},muteVideo:function(){return J(i,!0,!0)},unmuteVideo:function(){return J(i,!0,!1)},getBitrate:function(){return K(i)},getNetworkQuality:function(A){H(i,A)},send:function(A){b(i,A)},data:function(A){P(i,A)},dtmf:function(A){N(i,A)},consentDialog:A.consentDialog,iceState:A.iceState,mediaState:A.mediaState,webrtcState:A.webrtcState,slowLink:A.slowLink,onmessage:A.onmessage,createOffer:function(A){L(i,!0,A)},createAnswer:function(A){L(i,!1,A)},handleRemoteJsep:function(A){Y(i,A)},onlocalstream:A.onlocalstream,onremotestream:A.onremotestream,ondata:A.ondata,ondataopen:A.ondataopen,oncleanup:A.oncleanup,ondetached:A.ondetached,hangup:function(A){O(i,!0===A)},detach:function(A){T(i,A)}};m[i]=n,A.success(n)},error:function(A,e){Bl.error(A+":",e)}})}(A)}}Bl.useDefaultDependencies=function(A){var e=A&&A.fetch||fetch,t=A&&A.Promise||Promise,i=A&&A.WebSocket||WebSocket;return{newWebSocket:function(A,e){return new i(A,e)},extension:A&&A.extension||hl,isArray:function(A){return Array.isArray(A)},webRTCAdapter:A&&A.adapter||adapter,httpAPICall:function(A,i){var n={method:i.verb,headers:{Accept:"application/json, text/plain, */*"},cache:"no-cache"};"POST"===i.verb&&(n.headers["Content-Type"]="application/json"),void 0!==i.withCredentials&&(n.credentials=!0===i.withCredentials?"include":i.withCredentials?i.withCredentials:"omit"),void 0!==i.body&&(n.body=JSON.stringify(i.body));var a=e(A,n).catch((function(A){return t.reject({message:"Probably a network error, is the server down?",error:A})}));if(void 0!==i.timeout){var r=new t((function(A,e){var t=setTimeout((function(){return clearTimeout(t),e({message:"Request timed out",timeout:i.timeout})}),i.timeout)}));a=t.race([a,r])}return a.then((function(A){return A.ok?C(i.success)===C(Bl.noop)?A.json().then((function(A){i.success(A)})).catch((function(e){return t.reject({message:"Failed to parse response body",error:e,response:A})})):void 0:t.reject({message:"API call failed",response:A})})).catch((function(A){C(i.error)===C(Bl.noop)&&i.error(A.message||"<< internal error >>",A)})),a}}},Bl.useOldDependencies=function(A){var e=A&&A.jQuery||jQuery,t=A&&A.WebSocket||WebSocket;return{newWebSocket:function(A,e){return new t(A,e)},isArray:function(A){return e.isArray(A)},extension:A&&A.extension||hl,webRTCAdapter:A&&A.adapter||adapter,httpAPICall:function(A,t){var i=void 0!==t.body?{contentType:"application/json",data:JSON.stringify(t.body)}:{},n=void 0!==t.withCredentials?{xhrFields:{withCredentials:t.withCredentials}}:{};return e.ajax(e.extend(i,n,{url:A,type:t.verb,cache:!1,dataType:"json",async:t.async,timeout:t.timeout,success:function(A){C(t.success)===C(Bl.noop)&&t.success(A)},error:function(A,e,i){C(t.error)===C(Bl.noop)&&t.error(e,i)}}))}}},Bl.noop=function(){},Bl.dataChanDefaultLabel="JanusDataChannel",Bl.endOfCandidates=null,Bl.init=function(A){if((A=A||{}).callback="function"==typeof A.callback?A.callback:Bl.noop,!0===Bl.initDone)A.callback();else{if("undefined"!=typeof console&&void 0!==console.log||(console={log:function(){}}),Bl.trace=Bl.noop,Bl.debug=Bl.noop,Bl.vdebug=Bl.noop,Bl.log=Bl.noop,Bl.warn=Bl.noop,Bl.error=Bl.noop,!0===A.debug||"all"===A.debug)Bl.trace=console.trace.bind(console),Bl.debug=console.debug.bind(console),Bl.vdebug=console.debug.bind(console),Bl.log=console.log.bind(console),Bl.warn=console.warn.bind(console),Bl.error=console.error.bind(console);else if(Array.isArray(A.debug))for(var e in A.debug){var t=A.debug[e];switch(t){case"trace":Bl.trace=console.trace.bind(console);break;case"debug":Bl.debug=console.debug.bind(console);break;case"vdebug":Bl.vdebug=console.debug.bind(console);break;case"log":Bl.log=console.log.bind(console);break;case"warn":Bl.warn=console.warn.bind(console);break;case"error":Bl.error=console.error.bind(console);break;default:console.error("Unknown debugging option '"+t+"' (supported: 'trace', 'debug', 'vdebug', 'log', warn', 'error')")}}var i=A.dependencies||Bl.useDefaultDependencies();Bl.isArray=i.isArray,Bl.webRTCAdapter=i.webRTCAdapter,Bl.httpAPICall=i.httpAPICall,Bl.newWebSocket=i.newWebSocket,Bl.extension=i.extension,Bl.extension.init(),Bl.listDevices=function(A,e){A="function"==typeof A?A:Bl.noop,null==e&&(e={audio:!0,video:!0}),Bl.isGetUserMediaAvailable()?navigator.mediaDevices.getUserMedia(e).then((function(e){navigator.mediaDevices.enumerateDevices().then((function(t){Bl.debug(t),A(t);try{var i=e.getTracks();for(var n in i){var a=i[n];null!=a&&a.stop()}}catch(A){}}))})).catch((function(e){Bl.error(e),A([])})):(Bl.warn("navigator.mediaDevices unavailable"),A([]))},Bl.attachMediaStream=function(A,e){"chrome"===Bl.webRTCAdapter.browserDetails.browser?Bl.webRTCAdapter.browserDetails.version>=52?A.srcObject=e:void 0!==A.src?A.src=URL.createObjectURL(e):Bl.error("Error attaching stream to element"):A.srcObject=e},Bl.reattachMediaStream=function(A,e){"chrome"===Bl.webRTCAdapter.browserDetails.browser?Bl.webRTCAdapter.browserDetails.version>=52?A.srcObject=e.srcObject:void 0!==A.src?A.src=e.src:Bl.error("Error reattaching stream to element"):A.srcObject=e.srcObject};var n=["iPad","iPhone","iPod"].indexOf(navigator.platform)>=0?"pagehide":"beforeunload",a=window["on"+n];if(window.addEventListener(n,(function(A){for(var e in Bl.log("Closing window"),Bl.sessions)null!==Bl.sessions[e]&&void 0!==Bl.sessions[e]&&Bl.sessions[e].destroyOnUnload&&(Bl.log("Destroying session "+e),Bl.sessions[e].destroy({asyncRequest:!1,notifyDestroyed:!1}));a&&"function"==typeof a&&a()})),Bl.safariVp8=!1,"safari"===Bl.webRTCAdapter.browserDetails.browser&&Bl.webRTCAdapter.browserDetails.version>=605)if(RTCRtpSender&&RTCRtpSender.getCapabilities&&RTCRtpSender.getCapabilities("video")&&RTCRtpSender.getCapabilities("video").codecs&&RTCRtpSender.getCapabilities("video").codecs.length){for(var e in RTCRtpSender.getCapabilities("video").codecs){var r=RTCRtpSender.getCapabilities("video").codecs[e];if(r&&r.mimeType&&"video/vp8"===r.mimeType.toLowerCase()){Bl.safariVp8=!0;break}}Bl.safariVp8?Bl.log("This version of Safari supports VP8"):Bl.warn("This version of Safari does NOT support VP8: if you're using a Technology Preview, try enabling the 'WebRTC VP8 codec' setting in the 'Experimental Features' Develop menu")}else{var o=new RTCPeerConnection({},{});o.createOffer({offerToReceiveVideo:!0}).then((function(A){Bl.safariVp8=-1!==A.sdp.indexOf("VP8"),Bl.safariVp8?Bl.log("This version of Safari supports VP8"):Bl.warn("This version of Safari does NOT support VP8: if you're using a Technology Preview, try enabling the 'WebRTC VP8 codec' setting in the 'Experimental Features' Develop menu"),o.close(),o=null}))}if(Bl.unifiedPlan=!1,"firefox"===Bl.webRTCAdapter.browserDetails.browser&&Bl.webRTCAdapter.browserDetails.version>=59)Bl.unifiedPlan=!0;else if("chrome"===Bl.webRTCAdapter.browserDetails.browser&&Bl.webRTCAdapter.browserDetails.version<72)Bl.unifiedPlan=!1;else if("currentDirection"in RTCRtpTransceiver.prototype){var s=new RTCPeerConnection;try{s.addTransceiver("audio"),Bl.unifiedPlan=!0}catch(A){}s.close()}else Bl.unifiedPlan=!1;Bl.initDone=!0,A.callback()}},Bl.isWebrtcSupported=function(){return void 0!==window.RTCPeerConnection&&null!==window.RTCPeerConnection},Bl.isGetUserMediaAvailable=function(){return void 0!==navigator.mediaDevices&&null!==navigator.mediaDevices&&void 0!==navigator.mediaDevices.getUserMedia&&null!==navigator.mediaDevices.getUserMedia},Bl.randomString=function(A){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="",i=0;i<A;i++){var n=Math.floor(62*Math.random());t+=e.substring(n,n+1)}return t},window.Janus=Bl;var ul="V1.0",El="https://open.ys7.com",fl={},Ql=function(A,e){fl[A]||(fl[A]=[]),fl[A].push(e)},xl=function(){var A=Array.prototype.shift.call(arguments),e=fl[A];if(!e||0===e.length)return!1;for(var t,i=0;t=e[i];i++)t.apply(this,arguments)};function pl(){var A={};return A.promise=new Promise((function(e,t){A.resolve=e,A.reject=t})),A}var ml,yl,_l,Sl,Dl=function(){return a((function A(e){t(this,A),o(this,"subscribe",(function(A){var e=pl(),t={cmdType:"subremote",streamtype:A.type,customId:A.clientId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId},i=null;return window["ezuikit-webrtc"].opt.janus.attach({plugin:"rtcgw.plugin.sts",opaqueId:window["ezuikit-webrtc"].opt.opaqueId,success:function(n){console.log("pluginHandle",n),8==A.type?window["ezuikit-webrtc"].opt.subscribeScreenHandle=n:(window["ezuikit-webrtc"].opt["".concat(A.clientId)]=n,1==A.type&&window["ezuikit-webrtc"].opt["".concat(A.clientId)].send({message:{cmdType:"unsubremote",streamtype:2,customId:A.clientId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId},success:function(){},error:function(A){}})),(i=n).createOffer({media:{videoSend:!1,audioSend:!1,audioRecv:!0,videoRecv:!0,audio:!0,video:!0,data:!1},simulcast:!1,simulcast2:!1,success:function(A){Janus.debug("remoteFeed createOffer Got SDP!"),Janus.debug(A),i.send({message:t,jsep:A})},error:function(A){Janus.error("remoteFeed WebRTC error:",A),e.reject(A)}})},error:function(A){console.error(" -- Error attaching plugin...",A),e.reject(A)},consentDialog:function(A){Janus.debug("Consent dialog should be "+(A?"on":"off")+" now")},iceState:function(A){switch(Janus.log("ICE state changed to "+A),A){case"connected":console.log("ice connect success");break;case"disconnected":console.log("ice connect loss")}},mediaState:function(A,e){Janus.log("Janus "+(e?"started":"stopped")+" receiving our "+A)},webrtcState:function(A){Janus.log("Janus says our WebRTC PeerConnection is "+(A?"up":"down")+" now")},slowLink:function(A,e){Janus.warn("Janus reports problems "+(A?"sending":"receiving")+" packets on this PeerConnection ("+e+" lost packets)")},onmessage:function(A,e){Janus.debug(" ::: Got a message :::"),Janus.debug(A),null!=e&&(Janus.debug("Handling SDP as well..."),Janus.debug(e),i.handleRemoteJsep({jsep:e})),"subremoteack"===A.rtcgw&&xl("subremoteack",A)},onlocalstream:function(A){},onremotestream:function(t){console.log("remoteStream==================================",t);var i={clientId:A.clientId,stream:t,streamType:A.type};e.resolve(i),xl("remoteStream",i)},ondataopen:function(A){Janus.log("The DataChannel is available!")},ondata:function(A){Janus.debug("We got data from the DataChannel! "+A)},oncleanup:function(){Janus.log(" ::: Got a cleanup notification :::")}}),e.promise})),o(this,"subscribeStream",(function(A){var e=pl(),t={cmdType:"resumesubremote",streamtype:A.type,customId:A.clientId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return window["ezuikit-webrtc"].opt["".concat(A.clientId)]&&window["ezuikit-webrtc"].opt["".concat(A.clientId)].send({message:t,success:function(){e.resolve("success")},error:function(A){e.reject(A)}}),e.promise})),o(this,"unsubscribe",(function(A){var e=pl(),t={cmdType:"unsubremote",streamtype:A.type,customId:A.clientId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return 8==A.type?window["ezuikit-webrtc"].opt.subscribeScreenHandle.send({message:t,success:function(){window["ezuikit-webrtc"].opt.subscribeScreenHandle.detach({noRequest:!1,success:function(){e.resolve("success")}})},error:function(A){e.reject(A)}}):window["ezuikit-webrtc"].opt["".concat(A.clientId)].send({message:t,success:function(){3==A.type?window["ezuikit-webrtc"].opt["".concat(A.clientId)].detach({noRequest:!1,success:function(){e.resolve("success")}}):e.resolve("success")},error:function(A){e.reject(A)}}),e.promise})),o(this,"unsubscribeStream",(function(A){var e=pl(),t={cmdType:"pausesubremote",streamtype:A.type,customId:A.clientId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return window["ezuikit-webrtc"].opt["".concat(A.clientId)].send({message:t,success:function(){e.resolve("success")},error:function(A){e.reject(A)}}),e.promise})),o(this,"listen",(function(){return Ql.apply(void 0,arguments)})),this.initEZWEBPlayer(e)}),[{key:"initEZWEBPlayer",value:function(A){console.log("params",A),window["ezuikit-webrtc"]={opt:{roomParams:{room:0,userId:A.userId,video:1,internalRoomId:null,roomId:A.roomId,clientId:null,rtctoken:A.rtctoken},janus:null,mainHandle:null,sts:null,screenHandle:null,subscribeScreenHandle:null,opaqueId:"sts-"+Janus.randomString(12),localStreamType:null,server:null,accessToken:A.accessToken,stream:"",screenStream:null,apiDomain:El,cln:{local:{username:"",client_id:""}}},videoParams:{},audioParams:{},cameraId:null,microphoneId:null,bitrate:1e5,frameRate:15,width:320,height:240},S("".concat(El,"/api/v3/rtc/wss"),"POST",{appId:A.appId,roomId:A.roomId,customId:A.userId,accessToken:A.accessToken},{"Content-Type":"application/x-www-form-urlencoded",accessToken:A.accessToken},(function(e){if(console.log("data",e),200!=e.meta.code)return void A.handleError(e.meta);var t=e.data;t.clientId;var i=t.domain;t.internalRoomId;var n=t.wssPath;window["ezuikit-webrtc"].opt.server="wss://".concat(i,"/").concat(n),window["ezuikit-webrtc"].opt.roomParams.internalRoomId=e.data.internalRoomId,window["ezuikit-webrtc"].opt.roomParams.clientId=e.data.clientId;var a={token:"token=".concat(A.rtctoken,"&userId=").concat(A.userId,"&roomId=").concat(A.roomId,"&appId=").concat(A.appId),authtype:23};Janus.init({debug:"all",callback:function(){window["ezuikit-webrtc"].opt.janus=new Janus({server:window["ezuikit-webrtc"].opt.server,success:function(e){e&&A.onMessage(e)},error:function(e){A.handleError(e)},destroyed:function(){}},a)}})}))}},{key:"getVersion",value:function(){var A=pl();return A.resolve(ul),A.promise}},{key:"getSupport",value:function(){var A=pl(),e={isWebrtcSupport:!0,isH264Support:!0},t=document.createElement("video");return t.canPlayType&&(t.canPlayType("video/mp4;codecs=“avc1.64001E”")?e.isH264Support=!0:e.isH264Support=!1),navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia?(e.isWebrtcSupport=!0,A.resolve(e)):(e.isWebrtcSupport=!1,A.reject(e)),A.promise}},{key:"getMediaList",value:function(){var A=pl();return navigator.mediaDevices?navigator.mediaDevices.enumerateDevices().then((function(e){A.resolve(e)})):A.reject("no devices"),A.promise}},{key:"getCamerasList",value:function(){var A=pl();return navigator.mediaDevices?navigator.mediaDevices.enumerateDevices().then((function(e){var t=[];e.map((function(A){"videoinput"==A.kind&&t.push(A)})),A.resolve(t)})):A.reject("no devices"),A.promise}},{key:"getMicrophonesList",value:function(){var A=pl();return navigator.mediaDevices?navigator.mediaDevices.enumerateDevices().then((function(e){var t=[];e.map((function(A){"audioinput"==A.kind&&t.push(A)})),A.resolve(t)})):A.reject("no devices"),A.promise}},{key:"getSpeakersList",value:function(){var A=pl();return navigator.mediaDevices?navigator.mediaDevices.enumerateDevices().then((function(e){var t=[];e.map((function(A){"audiooutput"==A.kind&&t.push(A)})),A.resolve(t)})):A.reject("no devices"),A.promise}},{key:"play",value:function(A){var e=pl(),t=document.getElementById(A.domId),i=window["ezuikit-webrtc"].opt.cln.local.stream;return Janus.attachMediaStream(t,i),t.play(),document.getElementById(A.domId)?e.resolve("success"):e.reject("no video dom"),e.promise}},{key:"leaveRoom",value:function(A){var e=pl(),t={cmdType:"exitRoom",customId:window["ezuikit-webrtc"].opt.roomParams.userId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return window["ezuikit-webrtc"].opt.mainHandle.send({message:t,success:function(){window["ezuikit-webrtc"].opt.janus.destroy({success:function(){}}),e.resolve("success")},error:function(A){console.error(" -- Error attaching plugin...",A),e.reject(A)}}),e.promise}},{key:"setCameraDevice",value:function(A){var e=pl();return window["ezuikit-webrtc"].cameraId=A.deviceId,window["ezuikit-webrtc"].opt.sts&&window["ezuikit-webrtc"].opt.sts.createOffer({media:{video:{deviceId:A.deviceId},replaceVideo:!0,audio:1!=window["ezuikit-webrtc"].opt.localStreamType},simulcast:!1,simulcast2:!1,bitrate:window["ezuikit-webrtc"].bitrate,frameRate:window["ezuikit-webrtc"].frameRate,success:function(A){console.log("createOffersuccess"),Janus.debug("Got SDP!"),Janus.debug(A),e.resolve("success")},error:function(A){console.log("createOffererror"),Janus.error("WebRTC error:",A),e.reject(A)}}),e.promise}},{key:"setMicrophoneDevice",value:function(A){var e=pl();return window["ezuikit-webrtc"].microphoneId=A.deviceId,window["ezuikit-webrtc"].opt.sts&&window["ezuikit-webrtc"].opt.sts.createOffer({media:{audio:{deviceId:A.deviceId},replaceAudio:!0,video:2!=window["ezuikit-webrtc"].opt.localStreamType},simulcast:!1,simulcast2:!1,bitrate:window["ezuikit-webrtc"].bitrate,frameRate:window["ezuikit-webrtc"].frameRate,success:function(A){console.log("createOffersuccess"),Janus.debug("Got SDP!"),Janus.debug(A),e.resolve("success")},error:function(A){console.log("createOffererror"),Janus.error("WebRTC error:",A),e.reject(A)}}),e.promise}},{key:"setVideoProfile",value:function(A){var e=pl(),t={video:{width:A.video.width||360,height:A.video.height||640,frameRate:A.video.frameRate},bitrate:A.video.bitrate||5e5,id:A.id};return window["ezuikit-webrtc"].videoParams=t.video,window["ezuikit-webrtc"].bitrate=1e3*t.bitrate,window["ezuikit-webrtc"].frameRate=A.video.frameRate,window["ezuikit-webrtc"].width=A.video.width,window["ezuikit-webrtc"].height=A.video.height,e.resolve("success"),e.promise}},{key:"setAudioProfile",value:function(A){var e={audio:{deviceId:window["ezuikit-webrtc"].cameraId,sampleRate:A.audio.sampleRate||"32000HZ",sampleSize:A.audio.sampleSize||16,channelCount:A.audio.channelCount||1},id:A.id};window["ezuikit-webrtc"].audioParams=e.audio,console.log("window['ezuikit-webrtc'].videoParams",window["ezuikit-webrtc"])}},{key:"joinRoom",value:function(A){var e=pl();return window["ezuikit-webrtc"].opt.janus.attach({plugin:"rtcgw.plugin.sts",opaqueId:window["ezuikit-webrtc"].opt.opaqueId,success:function(A){console.log("pluginHandle",A),window["ezuikit-webrtc"].opt.mainHandle=A,Janus.debug("Trying a createOffer too (audio/video sendrecv)");var t={cmdType:"enterRoom",customId:window["ezuikit-webrtc"].opt.roomParams.userId,clientId:window["ezuikit-webrtc"].opt.roomParams.clientId,strroomId:window["ezuikit-webrtc"].opt.roomParams.roomId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId,authtype:23,authentication:window["ezuikit-webrtc"].opt.roomParams.rtctoken};A.send({message:t}),e.resolve(A.id)},error:function(A){console.error(" -- Error attaching plugin...",A),e.reject(A)},consentDialog:function(A){Janus.debug("Consent dialog should be "+(A?"on":"off")+" now")},iceState:function(A){switch(Janus.log("ICE state changed to "+A),A){case"connected":console.log("ice connect success");break;case"disconnected":console.log("ice connect loss")}},mediaState:function(A,e){Janus.log("Janus "+(e?"started":"stopped")+" receiving our "+A)},webrtcState:function(A){Janus.log("Janus says our WebRTC PeerConnection is "+(A?"up":"down")+" now")},slowLink:function(A,e){Janus.warn("Janus reports problems "+(A?"sending":"receiving")+" packets on this PeerConnection ("+e+" lost packets)")},onmessage:function(A,e){Janus.debug(" ::: Got a message :::"),Janus.debug(A),null!=e&&(Janus.debug("Handling SDP as well..."),Janus.debug(e),window["ezuikit-webrtc"].opt.mainHandle.handleRemoteJsep({jsep:e}));var t=A.result;if(null!=t){if("done"===t)return;t.status}"enterRoomack"===A.rtcgw&&xl("enterRoomack",A),"clientJoin"===A.rtcgw&&xl("clientJoin",A),"clientLeave"===A.rtcgw&&xl("clientLeave",A),"stream-added"===A.rtcgw&&xl("steam-added",A),"stream-removed"===A.rtcgw&&xl("stream-removed",A),"audioleve"===A.rtcgw&&xl("audioleve",A),"networkquality"===A.rtcgw&&xl("networkquality",A),"error"===A.rtcgw&&xl("error",A),"audioleve"===A.rtcgw&&xl("audioleve",A),"publishlocalstreamack"===A.rtcgw&&xl("publishlocalstreamack",A),"subremoteack"===A.rtcgw&&xl("subremoteack",A)},onlocalstream:function(A){console.log("onlocalstream",A),Janus.debug(" ::: Got a local stream :::"),Janus.debug(A),window["ezuikit-webrtc"].opt.cln.local.stream=A},onremotestream:function(A){},ondataopen:function(A){Janus.log("The DataChannel is available!")},ondata:function(A){Janus.debug("We got data from the DataChannel! "+A)},oncleanup:function(){Janus.log(" ::: Got a cleanup notification :::")}}),e.promise}},{key:"getLocalStream",value:function(A){var e=pl();return window["ezuikit-webrtc"].opt.cln.local.stream?e.resolve(window["ezuikit-webrtc"].opt.cln.local.stream):e.reject("no stream"),e.promise}},{key:"getScreenStream",value:function(A){var e=pl();return window["ezuikit-webrtc"].opt.screenStream?e.resolve(window["ezuikit-webrtc"].opt.screenStream):e.reject("no stream"),e.promise}},{key:"suspendStream",value:function(A){this.controlStream(A,"suspend")}},{key:"controlStream",value:function(A,e){var t=pl(),i={cmdType:"resume"==e?"resumelocalstream":"pauselocalstream",streamtype:A.type,customId:window["ezuikit-webrtc"].opt.roomParams.userId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return 2==A.type&&window["ezuikit-webrtc"].opt.cln.local.stream.getTracks().forEach((function(A){"audio"==A.kind&&(A.enabled="resume"==e)})),1==A.type&&window["ezuikit-webrtc"].opt.cln.local.stream.getTracks().forEach((function(A){"video"==A.kind&&(A.enabled="resume"==e)})),8==A.type&&(console.log(" window['ezuikit-webrtc'].opt.screenStream.getTracks()",window["ezuikit-webrtc"].opt.screenStream.getTracks()),window["ezuikit-webrtc"].opt.screenStream.getTracks().forEach((function(A){A.enabled="resume"==e}))),3==A.type&&window["ezuikit-webrtc"].opt.cln.local.stream.getTracks().forEach((function(A){A.enabled="resume"==e})),8==A.type?window["ezuikit-webrtc"].opt.screenHandle.send({message:i,success:function(){t.resolve("success")},error:function(A){t.reject(A)}}):window["ezuikit-webrtc"].opt.sts.send({message:i,success:function(){t.resolve("success")},error:function(A){t.reject(A)}}),t.promise}},{key:"resumeStream",value:function(A){this.controlStream(A,"resume")}},{key:"publishStream",value:function(A){var e=pl(),t={cmdType:"publishlocalstream",streamtype:A.type,customId:window["ezuikit-webrtc"].opt.roomParams.userId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};8!=A.type&&(window["ezuikit-webrtc"].opt.localStreamType=A.type),window["ezuikit-webrtc"].videoParams;var i={videoSend:!0,audioSend:!0,audioRecv:!0,videoRecv:!0,data:!1,video:"stdres",audio:!0};switch(A.type){case 1:i={videoSend:!0,audioSend:!0,audioRecv:!0,videoRecv:!0,data:!1,video:{deviceId:window["ezuikit-webrtc"].cameraId,width:window["ezuikit-webrtc"].width,height:window["ezuikit-webrtc"].height},audio:!1};break;case 2:i={videoSend:!0,audioSend:!0,audioRecv:!0,videoRecv:!0,data:!1,video:!1,audio:{deviceId:window["ezuikit-webrtc"].microphoneId}};break;case 3:i={videoSend:!0,audioSend:!0,audioRecv:!0,videoRecv:!0,data:!1,video:{deviceId:window["ezuikit-webrtc"].cameraId,width:window["ezuikit-webrtc"].width,height:window["ezuikit-webrtc"].height},audio:{deviceId:window["ezuikit-webrtc"].microphoneId}};break;case 8:i={audioRecv:!1,videoRecv:!0,data:!1,audioSend:!1,videoSend:!0,video:"screen",screenshareFrameRate:3}}return console.log("media-----------",i),console.log("window['ezuikit-webrtc'].bitrate",window["ezuikit-webrtc"].bitrate),console.log("window['ezuikit-webrtc'].opt.sts",window["ezuikit-webrtc"].opt.sts),window["ezuikit-webrtc"].opt.sts&&8!=A.type?window["ezuikit-webrtc"].opt.sts.createOffer({media:i,simulcast:!1,simulcast2:!1,bitrate:window["ezuikit-webrtc"].bitrate,frameRate:window["ezuikit-webrtc"].frameRate,success:function(A){console.log("createOffersuccess"),Janus.debug("Got SDP!"),Janus.debug(A),window["ezuikit-webrtc"].opt.sts.send({message:t,jsep:A}),e.resolve("success")},error:function(A){console.log("createOffererror"),Janus.error("WebRTC error:",A),e.reject(A)}}):window["ezuikit-webrtc"].opt.janus.attach({plugin:"rtcgw.plugin.sts",opaqueId:window["ezuikit-webrtc"].opt.opaqueId,success:function(n){console.log("pluginHandle",n),8==A.type?window["ezuikit-webrtc"].opt.screenHandle=n:window["ezuikit-webrtc"].opt.sts=n,Janus.debug("Trying a createOffer too (audio/video sendrecv)"),n.createOffer({media:i,simulcast:!1,simulcast2:!1,bitrate:window["ezuikit-webrtc"].bitrate,frameRate:window["ezuikit-webrtc"].frameRate,success:function(A){console.log("createOffersuccess"),Janus.debug("Got SDP!"),Janus.debug(A),n.send({message:t,jsep:A}),e.resolve("success")},error:function(A){console.log("createOffererror"),Janus.error("WebRTC error:",A),e.reject(A)}})},error:function(A){console.error(" -- Error attaching plugin...",A),e.reject(A)},consentDialog:function(A){Janus.debug("Consent dialog should be "+(A?"on":"off")+" now")},iceState:function(A){switch(Janus.log("ICE state changed to "+A),A){case"connected":console.log("ice connect success");break;case"disconnected":console.log("ice connect loss")}},mediaState:function(A,e){Janus.log("Janus "+(e?"started":"stopped")+" receiving our "+A)},webrtcState:function(A){Janus.log("Janus says our WebRTC PeerConnection is "+(A?"up":"down")+" now")},slowLink:function(A,e){Janus.warn("Janus reports problems "+(A?"sending":"receiving")+" packets on this PeerConnection ("+e+" lost packets)")},onmessage:function(e,t){console.log("消息回调+++++++++++++++++++++++++++++++++++++++++",e,t),Janus.debug(" ::: Got a message :::"),Janus.debug(e),null!=t&&(Janus.debug("Handling SDP as well..."),Janus.debug(t),8==A.type?window["ezuikit-webrtc"].opt.screenHandle.handleRemoteJsep({jsep:t}):window["ezuikit-webrtc"].opt.sts.handleRemoteJsep({jsep:t}))},onlocalstream:function(e){console.log("onlocalstream",e),Janus.debug(" ::: Got a local stream :::"),Janus.debug(e),8==A.type?(window["ezuikit-webrtc"].opt.screenStream=e,e.getVideoTracks()[0].addEventListener("ended",(function(){console.log("停止了屏幕共享-----------------------");var A={cmdType:"unpublishlocalstream",streamtype:8,customId:window["ezuikit-webrtc"].opt.roomParams.userId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};window["ezuikit-webrtc"].opt.screenHandle&&window["ezuikit-webrtc"].opt.screenHandle.send({message:A,success:function(){window["ezuikit-webrtc"].opt.screenHandle.detach({noRequest:!1}),window["ezuikit-webrtc"].opt.screenHandle=null},error:function(A){}})}))):window["ezuikit-webrtc"].opt.cln.local.stream=e},onremotestream:function(A){},ondataopen:function(A){Janus.log("The DataChannel is available!")},ondata:function(A){Janus.debug("We got data from the DataChannel! "+A)},oncleanup:function(){Janus.log(" ::: Got a cleanup notification :::")}}),e.promise}},{key:"unpublishStream",value:function(A){var e=pl(),t={cmdType:"unpublishlocalstream",streamtype:3,customId:window["ezuikit-webrtc"].opt.roomParams.userId,roomId:window["ezuikit-webrtc"].opt.roomParams.internalRoomId};return 8==A.type?window["ezuikit-webrtc"].opt.screenHandle.send({message:g(g({},t),{},{streamtype:8}),success:function(){window["ezuikit-webrtc"].opt.screenHandle.detach({noRequest:!1}),window["ezuikit-webrtc"].opt.screenHandle=null,e.resolve("success")},error:function(A){e.reject(A)}}):window["ezuikit-webrtc"].opt.sts.send({message:t,success:function(){window["ezuikit-webrtc"].opt.sts.detach({noRequest:!1}),window["ezuikit-webrtc"].opt.sts=null,e.resolve("success")},error:function(A){e.reject(A)}}),e.promise}},{key:"ezwebTrigger",value:function(A){var e={stream:window["ezuikit-webrtc"].opt.cln.local.stream,clientId:"cliendId-".concat(20*Math.random())};xl("steam-added",e)}},{key:"playRemoteSteam",value:function(A){var e=document.getElementById(A.domId);Janus.attachMediaStream(e,A.stream),e.load();var t=e.play();void 0!==t&&t.then((function(){e.play()})).catch((function(A){}))}},{key:"getQuality",value:function(A){window["ezuikit-webrtc"].opt.z3.getNetworkQuality(A.handleId,(function(A){console.log("NetworkQuality",A)}))}}])}(),wl="8.0.9",vl=(ml="undefined"!=typeof self?self:window,yl={navigator:void 0!==ml.navigator?ml.navigator:{userAgent:""},infoMap:{engine:["WebKit","Trident","Gecko","Presto"],browser:["Safari","Chrome","Edge","IE","Firefox","Firefox Focus","Chromium","Opera","Vivaldi","Yandex","Arora","Lunascape","QupZilla","Coc Coc","Kindle","Iceweasel","Konqueror","Iceape","SeaMonkey","Epiphany","360","360SE","360EE","UC","QQBrowser","QQ","Baidu","Maxthon","Sogou","LBBROWSER","2345Explorer","TheWorld","XiaoMi","Quark","Qiyu","Wechat","Taobao","Alipay","Weibo","Douban","Suning","iQiYi"],os:["Windows","Linux","Mac OS","Android","Ubuntu","FreeBSD","Debian","iOS","Windows Phone","BlackBerry","MeeGo","Symbian","Chrome OS","WebOS"],device:["Mobile","Tablet","iPad"]}},_l={getMatchMap:function(A){return{Trident:A.indexOf("Trident")>-1||A.indexOf("NET CLR")>-1,Presto:A.indexOf("Presto")>-1,WebKit:A.indexOf("AppleWebKit")>-1,Gecko:A.indexOf("Gecko/")>-1,Safari:A.indexOf("Safari")>-1,Chrome:A.indexOf("Chrome")>-1||A.indexOf("CriOS")>-1,IE:A.indexOf("MSIE")>-1||A.indexOf("Trident")>-1,Edge:A.indexOf("Edge")>-1,Firefox:A.indexOf("Firefox")>-1||A.indexOf("FxiOS")>-1,"Firefox Focus":A.indexOf("Focus")>-1,Chromium:A.indexOf("Chromium")>-1,Opera:A.indexOf("Opera")>-1||A.indexOf("OPR")>-1,Vivaldi:A.indexOf("Vivaldi")>-1,Yandex:A.indexOf("YaBrowser")>-1,Arora:A.indexOf("Arora")>-1,Lunascape:A.indexOf("Lunascape")>-1,QupZilla:A.indexOf("QupZilla")>-1,"Coc Coc":A.indexOf("coc_coc_browser")>-1,Kindle:A.indexOf("Kindle")>-1||A.indexOf("Silk/")>-1,Iceweasel:A.indexOf("Iceweasel")>-1,Konqueror:A.indexOf("Konqueror")>-1,Iceape:A.indexOf("Iceape")>-1,SeaMonkey:A.indexOf("SeaMonkey")>-1,Epiphany:A.indexOf("Epiphany")>-1,360:A.indexOf("QihooBrowser")>-1||A.indexOf("QHBrowser")>-1,"360EE":A.indexOf("360EE")>-1,"360SE":A.indexOf("360SE")>-1,UC:A.indexOf("UC")>-1||A.indexOf(" UBrowser")>-1,QQBrowser:A.indexOf("QQBrowser")>-1,QQ:A.indexOf("QQ/")>-1,Baidu:A.indexOf("Baidu")>-1||A.indexOf("BIDUBrowser")>-1,Maxthon:A.indexOf("Maxthon")>-1,Sogou:A.indexOf("MetaSr")>-1||A.indexOf("Sogou")>-1,LBBROWSER:A.indexOf("LBBROWSER")>-1,"2345Explorer":A.indexOf("2345Explorer")>-1,TheWorld:A.indexOf("TheWorld")>-1,XiaoMi:A.indexOf("MiuiBrowser")>-1,Quark:A.indexOf("Quark")>-1,Qiyu:A.indexOf("Qiyu")>-1,Wechat:A.indexOf("MicroMessenger")>-1,Taobao:A.indexOf("AliApp(TB")>-1,Alipay:A.indexOf("AliApp(AP")>-1,Weibo:A.indexOf("Weibo")>-1,Douban:A.indexOf("com.douban.frodo")>-1,Suning:A.indexOf("SNEBUY-APP")>-1,iQiYi:A.indexOf("IqiyiApp")>-1,Windows:A.indexOf("Windows")>-1,Linux:A.indexOf("Linux")>-1||A.indexOf("X11")>-1,"Mac OS":A.indexOf("Macintosh")>-1,Android:A.indexOf("Android")>-1||A.indexOf("Adr")>-1,Ubuntu:A.indexOf("Ubuntu")>-1,FreeBSD:A.indexOf("FreeBSD")>-1,Debian:A.indexOf("Debian")>-1,"Windows Phone":A.indexOf("IEMobile")>-1||A.indexOf("Windows Phone")>-1,BlackBerry:A.indexOf("BlackBerry")>-1||A.indexOf("RIM")>-1,MeeGo:A.indexOf("MeeGo")>-1,Symbian:A.indexOf("Symbian")>-1,iOS:A.indexOf("like Mac OS X")>-1,"Chrome OS":A.indexOf("CrOS")>-1,WebOS:A.indexOf("hpwOS")>-1,Mobile:A.indexOf("Mobi")>-1||A.indexOf("iPh")>-1||A.indexOf("480")>-1,Tablet:A.indexOf("Tablet")>-1||A.indexOf("Nexus 7")>-1,iPad:A.indexOf("iPad")>-1}},matchInfoMap:function(A){var e,t=(null==(e=yl.navigator)?void 0:e.userAgent)||"",i=_l.getMatchMap(t);for(var n in yl.infoMap)for(var a=0;a<yl.infoMap[n].length;a++){var r=yl.infoMap[n][a];i[r]&&(A[n]=r)}},getOS:function(){var A=this;return _l.matchInfoMap(A),null==A?void 0:A.os},getOSVersion:function(){var A=this,e=yl.navigator.userAgent||"";A.osVersion="";var t={Windows:function(){var A=e.replace(/^.*Windows NT ([\d.]+);.*$/,"$1");return{6.4:"10",6.3:"8.1",6.2:"8",6.1:"7","6.0":"Vista",5.2:"XP",5.1:"XP","5.0":"2000"}[A]||A},Android:function(){return e.replace(/^.*Android ([\d.]+);.*$/,"$1")},iOS:function(){return e.replace(/^.*OS ([\d_]+) like.*$/,"$1").replace(/_/g,".")},Debian:function(){return e.replace(/^.*Debian\/([\d.]+).*$/,"$1")},"Windows Phone":function(){return e.replace(/^.*Windows Phone( OS)? ([\d.]+);.*$/,"$2")},"Mac OS":function(){return e.replace(/^.*Mac OS X ([\d_]+).*$/,"$1").replace(/_/g,".")},WebOS:function(){return e.replace(/^.*hpwOS\/([\d.]+);.*$/,"$1")}};return"function"==typeof t[A.os]&&(A.osVersion=t[A.os](),A.osVersion==e&&(A.osVersion="")),A.osVersion},getOrientationStatu:function(){return window.matchMedia("(orientation: portrait)").matches?"vertical":"horizontal"},getDeviceType:function(){var A=this;return A.device="PC",_l.matchInfoMap(A),A.device},getNetwork:function(){var A,e,t,i;return null==(A=(null==(e=navigator)?void 0:e.connection)||(null==(t=navigator)?void 0:t.mozConnection)||(null==(i=navigator)?void 0:i.webkitConnection))?void 0:A.effectiveType},getLanguage:function(){var A,e,t;return this.language=((t=((null==(A=yl.navigator)?void 0:A.browserLanguage)||(null==(e=yl.navigator)?void 0:e.language)).split("-"))[1]&&(t[1]=t[1].toUpperCase()),t.join("_")),this.language},createFingerprint:function(A){var e=document.createElement("canvas"),t=e.getContext("2d"),i=A||window.location.host;t.textBaseline="top",t.font="14px 'Arial'",t.fillStyle="#f60",t.fillRect(125,1,62,20),t.fillStyle="#069",t.fillText(i,2,15),t.fillStyle="rgba(102, 204, 0, 0.7)",t.fillText(i,4,17);var n=e.toDataURL().replace("data:image/png;base64,","");return function(A){var e,t,i,n="";for(e=0,t=(A+="").length;e<t;e++)n+=(i=A.charCodeAt(e).toString(16)).length<2?"0"+i:i;return n}(atob(n).slice(-16,-12))},getBrowserInfo:function(){var A=this;_l.matchInfoMap(A);var e=yl.navigator.userAgent||"",t=function(A,e){var t=yl.navigator.mimeTypes;for(var i in t)if(t[i][A]==e)return!0;return!1},i=_l.getMatchMap(e),n=!1;if(ml.chrome){var a=e.replace(/^.*Chrome\/([\d]+).*$/,"$1");+a>36&&ml.showModalDialog?n=!0:+a>45&&(n=t("type","application/vnd.chromium.remoting-viewer"))}if(i.Baidu&&i.Opera&&(i.Baidu=!1),i.Mobile&&(i.Mobile=!e.includes("iPad")),n&&(t("type","application/gameplugin")||yl.navigator&&void 0===yl.navigator.connection.saveData?i["360SE"]=!0:i["360EE"]=!0),i.IE||i.Edge)switch(window.screenTop-window.screenY){case 71:case 74:case 99:case 75:case 105:break;case 102:i["360EE"]=!0;break;case 104:i["360SE"]=!0}var r={Safari:function(){return e.replace(/^.*Version\/([\d.]+).*$/,"$1")},Chrome:function(){return e.replace(/^.*Chrome\/([\d.]+).*$/,"$1").replace(/^.*CriOS\/([\d.]+).*$/,"$1")},IE:function(){return e.replace(/^.*MSIE ([\d.]+).*$/,"$1").replace(/^.*rv:([\d.]+).*$/,"$1")},Edge:function(){return e.replace(/^.*Edge\/([\d.]+).*$/,"$1")},Firefox:function(){return e.replace(/^.*Firefox\/([\d.]+).*$/,"$1").replace(/^.*FxiOS\/([\d.]+).*$/,"$1")},"Firefox Focus":function(){return e.replace(/^.*Focus\/([\d.]+).*$/,"$1")},Chromium:function(){return e.replace(/^.*Chromium\/([\d.]+).*$/,"$1")},Opera:function(){return e.replace(/^.*Opera\/([\d.]+).*$/,"$1").replace(/^.*OPR\/([\d.]+).*$/,"$1")},Vivaldi:function(){return e.replace(/^.*Vivaldi\/([\d.]+).*$/,"$1")},Yandex:function(){return e.replace(/^.*YaBrowser\/([\d.]+).*$/,"$1")},Arora:function(){return e.replace(/^.*Arora\/([\d.]+).*$/,"$1")},Lunascape:function(){return e.replace(/^.*Lunascape[\/\s]([\d.]+).*$/,"$1")},QupZilla:function(){return e.replace(/^.*QupZilla[\/\s]([\d.]+).*$/,"$1")},"Coc Coc":function(){return e.replace(/^.*coc_coc_browser\/([\d.]+).*$/,"$1")},Kindle:function(){return e.replace(/^.*Version\/([\d.]+).*$/,"$1")},Iceweasel:function(){return e.replace(/^.*Iceweasel\/([\d.]+).*$/,"$1")},Konqueror:function(){return e.replace(/^.*Konqueror\/([\d.]+).*$/,"$1")},Iceape:function(){return e.replace(/^.*Iceape\/([\d.]+).*$/,"$1")},SeaMonkey:function(){return e.replace(/^.*SeaMonkey\/([\d.]+).*$/,"$1")},Epiphany:function(){return e.replace(/^.*Epiphany\/([\d.]+).*$/,"$1")},360:function(){return e.replace(/^.*QihooBrowser\/([\d.]+).*$/,"$1")},"360SE":function(){return{63:"10.0",55:"9.1",45:"8.1",42:"8.0",31:"7.0",21:"6.3"}[+e.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||""},"360EE":function(){return{69:"11.0",63:"9.5",55:"9.0",50:"8.7",30:"7.5"}[+e.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||""},Maxthon:function(){return e.replace(/^.*Maxthon\/([\d.]+).*$/,"$1")},QQBrowser:function(){return e.replace(/^.*QQBrowser\/([\d.]+).*$/,"$1")},QQ:function(){return e.replace(/^.*QQ\/([\d.]+).*$/,"$1")},Baidu:function(){return e.replace(/^.*BIDUBrowser[\s\/]([\d.]+).*$/,"$1")},UC:function(){return e.replace(/^.*UC?Browser\/([\d.]+).*$/,"$1")},Sogou:function(){return e.replace(/^.*SE ([\d.X]+).*$/,"$1").replace(/^.*SogouMobileBrowser\/([\d.]+).*$/,"$1")},LBBROWSER:function(){return{57:"6.5",49:"6.0",46:"5.9",42:"5.3",39:"5.2",34:"5.0",29:"4.5",21:"4.0"}[+navigator.userAgent.replace(/^.*Chrome\/([\d]+).*$/,"$1")]||""},"2345Explorer":function(){return e.replace(/^.*2345Explorer\/([\d.]+).*$/,"$1")},TheWorld:function(){return e.replace(/^.*TheWorld ([\d.]+).*$/,"$1")},XiaoMi:function(){return e.replace(/^.*MiuiBrowser\/([\d.]+).*$/,"$1")},Quark:function(){return e.replace(/^.*Quark\/([\d.]+).*$/,"$1")},Qiyu:function(){return e.replace(/^.*Qiyu\/([\d.]+).*$/,"$1")},Wechat:function(){return e.replace(/^.*MicroMessenger\/([\d.]+).*$/,"$1")},Taobao:function(){return e.replace(/^.*AliApp\(TB\/([\d.]+).*$/,"$1")},Alipay:function(){return e.replace(/^.*AliApp\(AP\/([\d.]+).*$/,"$1")},Weibo:function(){return e.replace(/^.*weibo__([\d.]+).*$/,"$1")},Douban:function(){return e.replace(/^.*com.douban.frodo\/([\d.]+).*$/,"$1")},Suning:function(){return e.replace(/^.*SNEBUY-APP([\d.]+).*$/,"$1")},iQiYi:function(){return e.replace(/^.*IqiyiVersion\/([\d.]+).*$/,"$1")}};return A.browserVersion="",r[A.browser]&&(A.browserVersion=r[A.browser](),A.browserVersion==e&&(A.browserVersion="")),"Edge"==A.browser&&(A.engine="EdgeHTML"),"Chrome"==A.browser&&parseInt(A.browserVersion)>27&&(A.engine="Blink"),"Opera"==A.browser&&parseInt(A.browserVersion)>12&&(A.engine="Blink"),"Yandex"==A.browser&&(A.engine="Blink"),A.browser+" (version: "+A.browserVersion+"; kernel: "+A.engine+")"}},Sl={DeviceInfoObj:function(A){var e,t=function(e){var t;null==(t=A.info)||t.forEach((function(A){A.toLowerCase()===e.toLowerCase()&&(n[e]=i[e])}))};A=A||{domain:""};var i={deviceType:_l.getDeviceType(),OS:_l.getOS(),OSVersion:_l.getOSVersion(),sh:ml.screen.height,sw:ml.screen.width,lang:_l.getLanguage(),netWork:_l.getNetwork(),orientation:_l.getOrientationStatu(),browserInfo:_l.getBrowserInfo(),fingerprint:_l.createFingerprint(A.domain),userAgent:null==(e=yl.navigator)?void 0:e.userAgent};if(!A.info||0===A.info.length)return i;var n={};for(var a in i)t(a);return n}},{getDeviceInfo:function(A){return Sl.DeviceInfoObj(A)}}),Fl=function(){function A(){}return A.add=function(e,t){A.queues.push({url:e,data:t})},A.fire=function(){if(A.queues&&0!==A.queues.length){A.isStop=!1;var e=A.queues[0];e.url&&A.api.report(e.data),A.queues.splice(0,1),A.fire()}else A.isStop=!0},A}();Fl.isStop=!0,Fl.queues=[];var bl=function(){function A(A){this.url=A}var e=A.prototype;return e.report=function(A){this.checkUrl(this.url)&&this.sendInfo(A)},e.sendInfo=function(A){navigator.sendBeacon?this.sendBeacon(this.url,A):this.sendImage(this.url,A)},e.sendImage=function(A,e){var t=this.changeJSON2Query(e),i=new Image;i.onload=i.onerror=function(){i=null},i.src=A+"?"+t+"&random="+Math.random()},e.sendBeacon=function(A,e){try{navigator.sendBeacon(A,this.formatParamsByURLSearchParams(e))}catch(A){}},e.formatParamsByURLSearchParams=function(A){var e=new URLSearchParams;for(var t in A)"object"==typeof A[t]&&(A[t]=JSON.stringify(A[t])),e.append(t,A[t]);return e},e.changeJSON2Query=function(A){var e="";for(var t in A){""!=e&&(e+="&");var i=A[t];e+=t+"="+encodeURIComponent("object"==typeof i?JSON.stringify(i):i)}return e},e.checkUrl=function(A){return!!A&&/^[hH][tT][tT][pP]([sS]?):\/\//.test(A)},A}();function Rl(){return Rl=Object.assign||function(A){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(A[i]=t[i])}return A},Rl.apply(this,arguments)}var kl=function(){function A(A){this.options=A,this.extendsInfo=A.extendsInfo||{},this.clientInfo=this._getDeviceInfo(),Fl.api=new bl(A.url)}var e=A.prototype;return e.send=function(A){return this.options.forbidden||"object"!=typeof A||(this._handleRecordError(A),Fl.isStop&&Fl.fire()),this},e.setForbidden=function(A){this.options.forbidden=A},e.updateExtendsInfo=function(A){void 0===A&&(A={}),this.extendsInfo=Rl({},this.extendsInfo||{},A)},e._handleRecordError=function(A){try{var e=this._handleErrorInfo(A);Fl.add(this.options.url,e)}catch(A){}},e._handleErrorInfo=function(A){var e=this._getExtendsInfo(),t=Rl({st:(new Date).getTime()},e,A);return t.clientInfo=this.clientInfo,t},e._getExtendsInfo=function(){try{var A,e={},t=this.extendsInfo||{};for(var i in"function"==typeof t.getDynamic&&(A=t.getDynamic()),"[object Object]"===Object.prototype.toString.call(A)&&(t=Rl({},t,A)),t)"function"!=typeof t[i]&&(e[i]=t[i]);return e}catch(A){return{}}},e._getDeviceInfo=function(){try{var A=vl.getDeviceInfo();return JSON.stringify(A)}catch(A){return""}},A}(),Pl=function(){return a((function A(e){t(this,A),this.collect=new kl(e)}),[{key:"report",value:function(A){this.collect.send(g({},A))}},{key:"updateParams",value:function(A){this.collect.updateExtendsInfo(A)}},{key:"setForbidden",value:function(A){this.collect.setForbidden(A)}}])}();window.monitorExtendsInfo={},window.ezuikitMonitor=new Pl({url:"https://log.ys7.com/statistics.do/opensdk_ezuikit",extendsInfo:{v:wl,getDynamic:function(){return window.monitorExtendsInfo}}});var Nl={Core:h,HLS:w,FLV:P,EZUIKitPlayer:sl,EZUIKitHD:dl,EZWebRtc:Dl};return window.EZUIKit=Nl,Nl}));
|