Your IP : 3.144.45.22


Current Path : /home/bitrix/ext_www/dev.home-comfort.in.ua/bitrix/js/im/webrtc/
Upload File :
Current File : /home/bitrix/ext_www/dev.home-comfort.in.ua/bitrix/js/im/webrtc/janus.min.js

Janus.sessions={};Janus.extensionId="hapfgfdkleiggjjpfpenajgdnfckjpaj";Janus.isExtensionEnabled=function(){if(window.navigator.userAgent.match("Chrome")){var e=parseInt(window.navigator.userAgent.match(/Chrome\/(.*) /)[1],10);var n=33;if(window.navigator.userAgent.match("Linux"))n=35;if(e>=26&&e<=n){return true}return document.getElementById("janus-extension-installed")!==null}else{return true}};Janus.noop=function(){};Janus.init=function(e){e=e||{};e.callback=typeof e.callback=="function"?e.callback:Janus.noop;if(Janus.initDone===true){e.callback()}else{if(typeof console=="undefined"||typeof console.log=="undefined")console={log:function(){}};Janus.trace=Janus.noop;Janus.debug=Janus.noop;Janus.log=Janus.noop;Janus.warn=Janus.noop;Janus.error=Janus.noop;if(e.debug===true||e.debug==="all"){Janus.trace=console.trace.bind(console);Janus.debug=console.debug.bind(console);Janus.log=console.log.bind(console);Janus.warn=console.warn.bind(console);Janus.error=console.error.bind(console)}else if(Array.isArray(e.debug)){for(var n in e.debug){var r=e.debug[n];switch(r){case"trace":Janus.trace=console.trace.bind(console);break;case"debug":Janus.debug=console.debug.bind(console);break;case"log":Janus.log=console.log.bind(console);break;case"warn":Janus.warn=console.warn.bind(console);break;case"error":Janus.error=console.error.bind(console);break;default:console.error("Unknown debugging option '"+r+"' (supported: 'trace', 'debug', 'log', warn', 'error')");break}}}Janus.log("Initializing library");Janus.listDevices=function(e){e=typeof e=="function"?e:Janus.noop;if(navigator.mediaDevices){navigator.mediaDevices.getUserMedia({audio:true,video:true}).then(function(n){navigator.mediaDevices.enumerateDevices().then(function(r){Janus.debug(r);e(r);try{n.stop()}catch(t){}try{var a=n.getTracks();for(var s in a){var o=a[s];if(o!==null&&o!==undefined)o.stop()}}catch(t){}})}).catch(function(n){Janus.error(n);e([])})}else{Janus.warn("navigator.mediaDevices unavailable");e([])}};Janus.attachMediaStream=function(e,n){if(adapter.browserDetails.browser==="chrome"){var r=adapter.browserDetails.version;if(r>=43){e.srcObject=n}else if(typeof e.src!=="undefined"){e.src=URL.createObjectURL(n)}else{Janus.error("Error attaching stream to element")}}else{e.srcObject=n}};Janus.reattachMediaStream=function(e,n){if(adapter.browserDetails.browser==="chrome"){var r=adapter.browserDetails.version;if(r>=43){e.srcObject=n.srcObject}else if(typeof element.src!=="undefined"){e.src=n.src}}else{e.srcObject=n.srcObject}};Janus.ajax=function(e){if(e===null||e===undefined)return;e.success=typeof e.success=="function"?e.success:Janus.noop;e.error=typeof e.error=="function"?e.error:Janus.noop;if(e.url===null||e.url===undefined){Janus.error("Missing url",e.url);e.error(null,-1,"Missing url");return}e.async=e.async===null||e.async===undefined?true:e.async===true;Janus.log(e);var n=new XMLHttpRequest;n.open(e.type,e.url,e.async);if(e.contentType!==null&&e.contentType!==undefined)n.setRequestHeader("Content-type",e.contentType);if(e.async){n.onreadystatechange=function(){if(n.readyState!=4)return;if(n.status!==200){if(n.status===0)n.status="error";e.error(n,n.status,"");return}e.success(JSON.parse(n.responseText))}}try{n.send(e.data);if(!e.async){if(n.status!==200){if(n.status===0)n.status="error";e.error(n,n.status,"");return}e.success(JSON.parse(n.responseText))}}catch(r){e.error(n,"error","")}};var t=window.onbeforeunload;window.onbeforeunload=function(){Janus.log("Closing window");for(var e in Janus.sessions){if(Janus.sessions[e]!==null&&Janus.sessions[e]!==undefined&&Janus.sessions[e].destroyOnUnload){Janus.log("Destroying session "+e);Janus.sessions[e].destroy()}}if(t&&typeof t=="function")t()};function a(n){if(!n||!Array.isArray(n)||n.length==0){e.callback()}var r=0;s(n[r],t);function t(){r++;if(r<n.length){s(n[r],t)}else{e.callback()}}}function s(e,n){if(e==="adapter.js"){if(navigator.getUserMedia&&navigator.mediaDevices.getUserMedia&&window.RTCPeerConnection){Janus.debug(e+" already loaded, skipping");n();return}}var r=document.getElementsByTagName("head").item(0);var t=document.createElement("script");t.type="text/javascript";t.src=e;t.onload=function(){Janus.log("Library "+e+" loaded");n()};r.appendChild(t)}Janus.initDone=true;a(["adapter.js"])}};Janus.isWebrtcSupported=function(){return window.RTCPeerConnection!==undefined&&window.RTCPeerConnection!==null&&navigator.getUserMedia!==undefined&&navigator.getUserMedia!==null};function Janus(e){if(Janus.initDone===undefined){e.error("Library not initialized");return{}}if(!Janus.isWebrtcSupported()){e.error("WebRTC not supported by this browser");return{}}Janus.log("Library initialized: "+Janus.initDone);e=e||{};e.success=typeof e.success=="function"?e.success:Janus.noop;e.error=typeof e.error=="function"?e.error:Janus.noop;e.destroyed=typeof e.destroyed=="function"?e.destroyed:Janus.noop;if(e.server===null||e.server===undefined){e.error("Invalid gateway url");return{}}var n=false;var r=null;var t={};var a=null;var s=null,o=0;var i=e.server;if(Array.isArray(i)){Janus.log("Multiple servers provided ("+i.length+"), will use the first that works");i=null;s=e.server;Janus.debug(s)}else{if(i.indexOf("ws")===0){n=true;Janus.log("Using WebSockets to contact Janus: "+i)}else{n=false;Janus.log("Using REST API to contact Janus: "+i)}}var u=e.iceServers;if(u===undefined||u===null)u=[{urls:"stun:stun.l.google.com:19302"}];var d=e.ipv6;if(d===undefined||d===null)d=false;var l=null;if(e.max_poll_events!==undefined&&e.max_poll_events!==null)l=e.max_poll_events;if(l<1)l=1;var c=null;if(e.token!==undefined&&e.token!==null)c=e.token;var f=null;if(e.apisecret!==undefined&&e.apisecret!==null)f=e.apisecret;this.destroyOnUnload=true;if(e.destroyOnUnload!==undefined&&e.destroyOnUnload!==null)this.destroyOnUnload=e.destroyOnUnload===true;var g=false;var p=null;var v={};var m=this;var b=0;var J={};k(e);this.getServer=function(){return i};this.isConnected=function(){return g};this.getSessionId=function(){return p};this.destroy=function(e){T(e)};this.attach=function(e){D(e)};function w(e){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";var r="";for(var t=0;t<e;t++){var a=Math.floor(Math.random()*n.length);r+=n.substring(a,a+1)}return r}function y(){if(p==null)return;Janus.debug("Long poll...");if(!g){Janus.warn("Is the gateway down? (connected=false)");return}var n=i+"/"+p+"?rid="+(new Date).getTime();if(l!==undefined&&l!==null)n=n+"&maxev="+l;if(c!==null&&c!==undefined)n=n+"&token="+c;if(f!==null&&f!==undefined)n=n+"&apisecret="+f;Janus.ajax({type:"GET",url:n,cache:false,timeout:6e4,success:h,error:function(n,r,t){Janus.error(r+": "+t);b++;if(b>3){g=false;e.error("Lost connection to the gateway (is it down?)");return}y()},dataType:"json"})}function h(e){b=0;if(!n&&p!==undefined&&p!==null)setTimeout(y,200);Janus.debug("Got event on session "+p);Janus.debug(e);if(!n&&Array.isArray(e)){for(var r=0;r<e.length;r++){h(e[r])}return}if(e["janus"]==="keepalive"){return}else if(e["janus"]==="ack"){var t=e["transaction"];if(t!==null&&t!==undefined){var a=J[t];if(a!==null&&a!==undefined){a(e)}delete J[t]}return}else if(e["janus"]==="success"){var t=e["transaction"];if(t!==null&&t!==undefined){var a=J[t];if(a!==null&&a!==undefined){a(e)}delete J[t]}return}else if(e["janus"]==="webrtcup"){var s=e["sender"];if(s===undefined||s===null){Janus.warn("Missing sender...");return}var o=v[s];if(o===undefined||o===null){Janus.warn("This handle is not attached to this session");return}o.webrtcState(true);return}else if(e["janus"]==="hangup"){var s=e["sender"];if(s===undefined||s===null){Janus.warn("Missing sender...");return}var o=v[s];if(o===undefined||o===null){Janus.warn("This handle is not attached to this session");return}o.webrtcState(false);o.hangup()}else if(e["janus"]==="detached"){var s=e["sender"];if(s===undefined||s===null){Janus.warn("Missing sender...");return}var o=v[s];if(o===undefined||o===null){return}o.ondetached();o.detach()}else if(e["janus"]==="media"){var s=e["sender"];if(s===undefined||s===null){Janus.warn("Missing sender...");return}var o=v[s];if(o===undefined||o===null){Janus.warn("This handle is not attached to this session");return}o.mediaState(e["type"],e["receiving"])}else if(e["janus"]==="error"){Janus.error("Ooops: "+e["error"].code+" "+e["error"].reason);var t=e["transaction"];if(t!==null&&t!==undefined){var a=J[t];if(a!==null&&a!==undefined){a(e)}delete J[t]}return}else if(e["janus"]==="event"){var s=e["sender"];if(s===undefined||s===null){Janus.warn("Missing sender...");return}var i=e["plugindata"];if(i===undefined||i===null){Janus.warn("Missing plugindata...");return}Janus.debug("  -- Event is coming from "+s+" ("+i["plugin"]+")");var u=i["data"];Janus.debug(u);var o=v[s];if(o===undefined||o===null){Janus.warn("This handle is not attached to this session");return}var d=e["jsep"];if(d!==undefined&&d!==null){Janus.debug("Handling SDP as well...");Janus.debug(d)}var l=o.onmessage;if(l!==null&&l!==undefined){Janus.debug("Notifying application...");l(u,d)}else{Janus.debug("No provided notification callback")}}else{Janus.warn("Unknown message '"+e["janus"]+"'")}}function S(){if(i===null||!n||!g)return;a=setTimeout(S,3e4);var e={janus:"keepalive",session_id:p,transaction:w(12)};if(c!==null&&c!==undefined)e["token"]=c;if(f!==null&&f!==undefined)e["apisecret"]=f;r.send(JSON.stringify(e))}function k(u){var d=w(12);var l={janus:"create",transaction:d};if(c!==null&&c!==undefined)l["token"]=c;if(f!==null&&f!==undefined)l["apisecret"]=f;if(i===null&&Array.isArray(s)){i=s[o];if(i.indexOf("ws")===0){n=true;Janus.log("Server #"+(o+1)+": trying WebSockets to contact Janus ("+i+")")}else{n=false;Janus.log("Server #"+(o+1)+": trying REST API to contact Janus ("+i+")")}}if(n){r=new WebSocket(i,"janus-protocol");t={error:function(){Janus.error("Error connecting to the Janus WebSockets server... "+i);if(Array.isArray(s)){o++;if(o==s.length){u.error("Error connecting to any of the provided Janus servers: Is the gateway down?");return}i=null;setTimeout(function(){k(u)},200);return}u.error("Error connecting to the Janus WebSockets server: Is the gateway down?")},open:function(){J[d]=function(e){Janus.debug(e);if(e["janus"]!=="success"){Janus.error("Ooops: "+e["error"].code+" "+e["error"].reason);u.error(e["error"].reason);return}a=setTimeout(S,3e4);g=true;p=e.data["id"];Janus.log("Created session: "+p);Janus.sessions[p]=m;u.success()};r.send(JSON.stringify(l))},message:function(e){h(JSON.parse(e.data))},close:function(){if(i===null||!g){return}g=false;e.error("Lost connection to the gateway (is it down?)")}};for(var v in t){r.addEventListener(v,t[v])}return}Janus.ajax({type:"POST",url:i,cache:false,contentType:"application/json",data:JSON.stringify(l),success:function(e){Janus.debug(e);if(e["janus"]!=="success"){Janus.error("Ooops: "+e["error"].code+" "+e["error"].reason);u.error(e["error"].reason);return}g=true;p=e.data["id"];Janus.log("Created session: "+p);Janus.sessions[p]=m;y();u.success()},error:function(e,n,r){Janus.error(n+": "+r);if(Array.isArray(s)){o++;if(o==s.length){u.error("Error connecting to any of the provided Janus servers: Is the gateway down?");return}i=null;setTimeout(function(){k(u)},200);return}if(r==="")u.error(n+": Is the gateway down?");else u.error(n+": "+r)},dataType:"json"})}function T(s,o){o=o===true;Janus.log("Destroying session "+p+" (sync="+o+")");s=s||{};s.success=typeof s.success=="function"?s.success:Janus.noop;if(!g){Janus.warn("Is the gateway down? (connected=false)");s.success();return}if(p===undefined||p===null){Janus.warn("No session to destroy");s.success();e.destroyed();return}delete Janus.sessions[p];for(var u in v){var d=v[u];Janus.log("Destroying handle "+d.id+" ("+d.plugin+")");M(d.id,null,o)}var l={janus:"destroy",transaction:w(12)};if(c!==null&&c!==undefined)l["token"]=c;if(f!==null&&f!==undefined)l["apisecret"]=f;if(n){l["session_id"]=p;var m=function(){for(var e in t){r.removeEventListener(e,t[e])}r.removeEventListener("message",b);r.removeEventListener("error",J);if(a){clearTimeout(a)}};var b=function(n){var r=JSON.parse(n.data);if(r.session_id==l.session_id&&r.transaction==l.transaction){m();s.success();e.destroyed()}};var J=function(n){m();s.error("Failed to destroy the gateway: Is the gateway down?");e.destroyed()};r.addEventListener("message",b);r.addEventListener("error",J);r.send(JSON.stringify(l));return}Janus.ajax({type:"POST",url:i+"/"+p,async:o,cache:false,contentType:"application/json",data:JSON.stringify(l),success:function(n){Janus.log("Destroyed session:");Janus.debug(n);p=null;g=false;if(n["janus"]!=="success"){Janus.error("Ooops: "+n["error"].code+" "+n["error"].reason)}s.success();e.destroyed()},error:function(n,r,t){Janus.error(r+": "+t);p=null;g=false;s.success();e.destroyed()},dataType:"json"})}function D(e){e=e||{};e.success=typeof e.success=="function"?e.success:Janus.noop;e.error=typeof e.error=="function"?e.error:Janus.noop;e.consentDialog=typeof e.consentDialog=="function"?e.consentDialog:Janus.noop;e.mediaState=typeof e.mediaState=="function"?e.mediaState:Janus.noop;e.webrtcState=typeof e.webrtcState=="function"?e.webrtcState:Janus.noop;e.onmessage=typeof e.onmessage=="function"?e.onmessage:Janus.noop;e.onlocalstream=typeof e.onlocalstream=="function"?e.onlocalstream:Janus.noop;e.onremotestream=typeof e.onremotestream=="function"?e.onremotestream:Janus.noop;e.ondata=typeof e.ondata=="function"?e.ondata:Janus.noop;e.ondataopen=typeof e.ondataopen=="function"?e.ondataopen:Janus.noop;e.oncleanup=typeof e.oncleanup=="function"?e.oncleanup:Janus.noop;e.ondetached=typeof e.ondetached=="function"?e.ondetached:Janus.noop;if(!g){Janus.warn("Is the gateway down? (connected=false)");e.error("Is the gateway down? (connected=false)");return}var t=e.plugin;if(t===undefined||t===null){Janus.error("Invalid plugin");e.error("Invalid plugin");return}var a=w(12);var s={janus:"attach",plugin:t,transaction:a};if(c!==null&&c!==undefined)s["token"]=c;if(f!==null&&f!==undefined)s["apisecret"]=f;if(n){J[a]=function(n){Janus.debug(n);if(n["janus"]!=="success"){Janus.error("Ooops: "+n["error"].code+" "+n["error"].reason);e.error("Ooops: "+n["error"].code+" "+n["error"].reason);return}var r=n.data["id"];Janus.log("Created handle: "+r);var a={session:m,plugin:t,id:r,webrtcStuff:{started:false,myStream:null,streamExternal:false,remoteStream:null,mySdp:null,pc:null,dataChannel:null,dtmfSender:null,trickle:true,iceDone:false,sdpSent:false,volume:{value:null,timer:null},bitrate:{value:null,bsnow:null,bsbefore:null,tsnow:null,tsbefore:null,timer:null}},getId:function(){return r},getPlugin:function(){return t},getVolume:function(){return P(r)},isAudioMuted:function(){return U(r,false)},muteAudio:function(){return L(r,false,true)},unmuteAudio:function(){return L(r,false,false)},isVideoMuted:function(){return U(r,true)},muteVideo:function(){return L(r,true,true)},unmuteVideo:function(){return L(r,true,false)},getBitrate:function(){return F(r)},send:function(e){j(r,e)},data:function(e){O(r,e)},dtmf:function(e){x(r,e)},consentDialog:e.consentDialog,mediaState:e.mediaState,webrtcState:e.webrtcState,onmessage:e.onmessage,createOffer:function(e){R(r,e)},createAnswer:function(e){R(r,e)},handleRemoteJsep:function(e){C(r,e)},onlocalstream:e.onlocalstream,onremotestream:e.onremotestream,ondata:e.ondata,ondataopen:e.ondataopen,oncleanup:e.oncleanup,ondetached:e.ondetached,hangup:function(e){W(r,e===true)},detach:function(e){M(r,e)}};v[r]=a;e.success(a)};s["session_id"]=p;r.send(JSON.stringify(s));return}Janus.ajax({type:"POST",url:i+"/"+p,cache:false,contentType:"application/json",data:JSON.stringify(s),success:function(n){Janus.debug(n);if(n["janus"]!=="success"){Janus.error("Ooops: "+n["error"].code+" "+n["error"].reason);e.error("Ooops: "+n["error"].code+" "+n["error"].reason);return}var r=n.data["id"];Janus.log("Created handle: "+r);var a={session:m,plugin:t,id:r,webrtcStuff:{started:false,myStream:null,streamExternal:false,remoteStream:null,mySdp:null,pc:null,dataChannel:null,dtmfSender:null,trickle:true,iceDone:false,sdpSent:false,volume:{value:null,timer:null},bitrate:{value:null,bsnow:null,bsbefore:null,tsnow:null,tsbefore:null,timer:null}},getId:function(){return r},getPlugin:function(){return t},getVolume:function(){return P(r)},isAudioMuted:function(){return U(r,false)},muteAudio:function(){return L(r,false,true)},unmuteAudio:function(){return L(r,false,false)},isVideoMuted:function(){return U(r,true)},muteVideo:function(){return L(r,true,true)},unmuteVideo:function(){return L(r,true,false)},getBitrate:function(){return F(r)},send:function(e){j(r,e)},data:function(e){O(r,e)},dtmf:function(e){x(r,e)},consentDialog:e.consentDialog,mediaState:e.mediaState,webrtcState:e.webrtcState,onmessage:e.onmessage,createOffer:function(e){R(r,e)},createAnswer:function(e){R(r,e)},handleRemoteJsep:function(e){C(r,e)},onlocalstream:e.onlocalstream,onremotestream:e.onremotestream,ondata:e.ondata,ondataopen:e.ondataopen,oncleanup:e.oncleanup,ondetached:e.ondetached,hangup:function(e){W(r,e===true)},detach:function(e){M(r,e)}};v[r]=a;e.success(a)},error:function(e,n,r){Janus.error(n+": "+r)},dataType:"json"})}function j(e,t){t=t||{};t.success=typeof t.success=="function"?t.success:Janus.noop;t.error=typeof t.error=="function"?t.error:Janus.noop;if(!g){Janus.warn("Is the gateway down? (connected=false)");t.error("Is the gateway down? (connected=false)");return}var a=t.message;var s=t.jsep;var o=w(12);var u={janus:"message",body:a,transaction:o};if(c!==null&&c!==undefined)u["token"]=c;if(f!==null&&f!==undefined)u["apisecret"]=f;if(s!==null&&s!==undefined)u.jsep=s;Janus.debug("Sending message to plugin (handle="+e+"):");Janus.debug(u);if(n){u["session_id"]=p;u["handle_id"]=e;J[o]=function(e){Janus.debug("Message sent!");Janus.debug(e);if(e["janus"]==="success"){var n=e["plugindata"];if(n===undefined||n===null){Janus.warn("Request succeeded, but missing plugindata...");t.success();return}Janus.log("Synchronous transaction successful ("+n["plugin"]+")");var r=n["data"];Janus.debug(r);t.success(r);return}else if(e["janus"]!=="ack"){if(e["error"]!==undefined&&e["error"]!==null){Janus.error("Ooops: "+e["error"].code+" "+e["error"].reason);t.error(e["error"].code+" "+e["error"].reason)}else{Janus.error("Unknown error");t.error("Unknown error")}return}t.success()};r.send(JSON.stringify(u));return}Janus.ajax({type:"POST",url:i+"/"+p+"/"+e,cache:false,contentType:"application/json",data:JSON.stringify(u),success:function(e){Janus.debug("Message sent!");Janus.debug(e);if(e["janus"]==="success"){var n=e["plugindata"];if(n===undefined||n===null){Janus.warn("Request succeeded, but missing plugindata...");t.success();return}Janus.log("Synchronous transaction successful ("+n["plugin"]+")");var r=n["data"];Janus.debug(r);t.success(r);return}else if(e["janus"]!=="ack"){if(e["error"]!==undefined&&e["error"]!==null){Janus.error("Ooops: "+e["error"].code+" "+e["error"].reason);t.error(e["error"].code+" "+e["error"].reason)}else{Janus.error("Unknown error");t.error("Unknown error")}return}t.success()},error:function(e,n,r){Janus.error(n+": "+r);t.error(n+": "+r)},dataType:"json"})}function I(e,t){if(!g){Janus.warn("Is the gateway down? (connected=false)");return}var a={janus:"trickle",candidate:t,transaction:w(12)};if(c!==null&&c!==undefined)a["token"]=c;if(f!==null&&f!==undefined)a["apisecret"]=f;Janus.debug("Sending trickle candidate (handle="+e+"):");Janus.debug(a);if(n){a["session_id"]=p;a["handle_id"]=e;r.send(JSON.stringify(a));return}Janus.ajax({type:"POST",url:i+"/"+p+"/"+e,cache:false,contentType:"application/json",data:JSON.stringify(a),success:function(e){Janus.debug("Candidate sent!");Janus.debug(e);if(e["janus"]!=="ack"){Janus.error("Ooops: "+e["error"].code+" "+e["error"].reason);return}},error:function(e,n,r){Janus.error(n+": "+r)},dataType:"json"})}function O(e,n){n=n||{};n.success=typeof n.success=="function"?n.success:Janus.noop;n.error=typeof n.error=="function"?n.error:Janus.noop;var r=v[e];if(r===null||r===undefined||r.webrtcStuff===null||r.webrtcStuff===undefined){Janus.warn("Invalid handle");n.error("Invalid handle");return}var t=r.webrtcStuff;var a=n.text;if(a===null||a===undefined){Janus.warn("Invalid text");n.error("Invalid text");return}Janus.log("Sending string on data channel: "+a);t.dataChannel.send(a);n.success()}function x(e,n){n=n||{};n.success=typeof n.success=="function"?n.success:Janus.noop;n.error=typeof n.error=="function"?n.error:Janus.noop;var r=v[e];if(r===null||r===undefined||r.webrtcStuff===null||r.webrtcStuff===undefined){Janus.warn("Invalid handle");n.error("Invalid handle");return}var t=r.webrtcStuff;if(t.dtmfSender===null||t.dtmfSender===undefined){if(t.myStream!==undefined&&t.myStream!==null){var a=t.myStream.getAudioTracks();if(a!==null&&a!==undefined&&a.length>0){var s=a[0];t.dtmfSender=t.pc.createDTMFSender(s);Janus.log("Created DTMF Sender");t.dtmfSender.ontonechange=function(e){Janus.debug("Sent DTMF tone: "+e.tone)}}}if(t.dtmfSender===null||t.dtmfSender===undefined){Janus.warn("Invalid DTMF configuration");n.error("Invalid DTMF configuration");return}}var o=n.dtmf;if(o===null||o===undefined){Janus.warn("Invalid DTMF parameters");n.error("Invalid DTMF parameters");return}var i=o.tones;if(i===null||i===undefined){Janus.warn("Invalid DTMF string");n.error("Invalid DTMF string");return}var u=o.duration;if(u===null||u===undefined)u=500;var d=o.gap;if(d===null||d===undefined)d=50;Janus.debug("Sending DTMF string "+i+" (duration "+u+"ms, gap "+d+"ms");t.dtmfSender.insertDTMF(i,u,d)}function M(e,t,a){a=a===true;Janus.log("Destroying handle "+e+" (sync="+a+")");t=t||{};t.success=typeof t.success=="function"?t.success:Janus.noop;t.error=typeof t.error=="function"?t.error:Janus.noop;W(e);if(!g){Janus.warn("Is the gateway down? (connected=false)");t.error("Is the gateway down? (connected=false)");return}var s={janus:"detach",transaction:w(12)};if(c!==null&&c!==undefined)s["token"]=c;if(f!==null&&f!==undefined)s["apisecret"]=f;if(n){s["session_id"]=p;s["handle_id"]=e;r.send(JSON.stringify(s));delete v[e];t.success();return}Janus.ajax({type:"POST",url:i+"/"+p+"/"+e,async:a,cache:false,contentType:"application/json",data:JSON.stringify(s),success:function(n){Janus.log("Destroyed handle:");Janus.debug(n);if(n["janus"]!=="success"){Janus.error("Ooops: "+n["error"].code+" "+n["error"].reason)}delete v[e];t.success()},error:function(n,r,a){Janus.error(r+": "+a);delete v[e];t.success()},dataType:"json"})}function A(e,n,r,t,a){var s=v[e];if(s===null||s===undefined||s.webrtcStuff===null||s.webrtcStuff===undefined){Janus.warn("Invalid handle");t.error("Invalid handle");return}var o=s.webrtcStuff;Janus.debug("streamsDone:",a);o.myStream=a;var i={iceServers:u};var l={optional:[{DtlsSrtpKeyAgreement:true}]};if(d===true){l.optional.push({googIPv6:true})}Janus.log("Creating PeerConnection");Janus.debug(l);o.pc=new RTCPeerConnection(i,l);Janus.debug(o.pc);if(o.pc.getStats){o.volume.value=0;o.bitrate.value="0 kbits/sec"}Janus.log("Preparing local SDP and gathering candidates (trickle="+o.trickle+")");o.pc.onicecandidate=function(n){if(n.candidate==null||adapter.browserDetails.browser==="edge"&&n.candidate.candidate.indexOf("endOfCandidates")>0){Janus.log("End of candidates.");o.iceDone=true;if(o.trickle===true){I(e,{completed:true})}else{_(e,t)}}else{var r={candidate:n.candidate.candidate,sdpMid:n.candidate.sdpMid,sdpMLineIndex:n.candidate.sdpMLineIndex};if(o.trickle===true){I(e,r)}}};if(a!==null&&a!==undefined){Janus.log("Adding local stream");o.pc.addStream(a);s.onlocalstream(a)}o.pc.onaddstream=function(e){Janus.log("Handling Remote Stream");Janus.debug(e);o.remoteStream=e;s.onremotestream(e.stream)};if(B(r)){Janus.log("Creating data channel");var c=function(e){Janus.log("Received message on data channel: "+e.data);s.ondata(e.data)};var f=function(){var e=o.dataChannel!==null?o.dataChannel.readyState:"null";Janus.log("State change on data channel: "+e);if(e==="open"){s.ondataopen()}};var g=function(e){Janus.error("Got error on data channel:",e)};o.dataChannel=o.pc.createDataChannel("JanusDataChannel",{ordered:false});o.dataChannel.onmessage=c;o.dataChannel.onopen=f;o.dataChannel.onclose=f;o.dataChannel.onerror=g}if(n===null||n===undefined){E(e,r,t)}else{o.pc.setRemoteDescription(new RTCSessionDescription(n),function(){Janus.log("Remote description accepted!");N(e,r,t)},t.error)}}function R(e,n){n=n||{};n.success=typeof n.success=="function"?n.success:Janus.noop;n.error=typeof n.error=="function"?n.error:V;var r=n.jsep;var t=n.media;var a=v[e];if(a===null||a===undefined||a.webrtcStuff===null||a.webrtcStuff===undefined){Janus.warn("Invalid handle");n.error("Invalid handle");return}var s=a.webrtcStuff;if(s.pc!==undefined&&s.pc!==null){Janus.log("Updating existing media session");if(r===null||r===undefined){E(e,t,n)}else{s.pc.setRemoteDescription(new RTCSessionDescription(r),function(){Janus.log("Remote description accepted!");N(e,t,n)},n.error)}return}if(n.stream!==null&&n.stream!==undefined){var o=n.stream;Janus.log("MediaStream provided by the application");Janus.debug(o);s.streamExternal=true;A(e,r,t,n,o);return}s.trickle=Y(n.trickle);if(H(t)||q(t)){var i={mandatory:{},optional:[]};a.consentDialog(true);var u=H(t);if(u===true&&t!=undefined&&t!=null){if(typeof t.audio==="object"){u=t.audio}}var d=q(t);if(d===true&&t!=undefined&&t!=null){if(t.video&&t.video!="screen"&&t.video!="window"){var l=0;var c=0,f=0;if(t.video==="lowres"){c=240;f=240;l=320}else if(t.video==="lowres-16:9"){c=180;f=180;l=320}else if(t.video==="hires"||t.video==="hires-16:9"){c=720;f=720;l=1280;if(navigator.mozGetUserMedia){var g=parseInt(window.navigator.userAgent.match(/Firefox\/(.*)/)[1],10);if(g<38){Janus.warn(t.video+" unsupported, falling back to stdres (old Firefox)");c=480;f=480;l=640}}}else if(t.video==="stdres"){c=480;f=480;l=640}else if(t.video==="stdres-16:9"){c=360;f=360;l=640}else{Janus.log("Default video setting ("+t.video+") is stdres 4:3");c=480;f=480;l=640}Janus.log("Adding media constraint "+t.video);if(navigator.mozGetUserMedia){var g=parseInt(window.navigator.userAgent.match(/Firefox\/(.*)/)[1],10);if(g<38){d={require:["height","width"],height:{max:f,min:c},width:{max:l,min:l}}}else{d={height:{ideal:c},width:{ideal:l}}}}else{d={mandatory:{maxHeight:f,minHeight:c,maxWidth:l,minWidth:l},optional:[]}}if(typeof t.video==="object"){d=t.video}Janus.debug(d)}else if(t.video==="screen"||t.video==="window"){if(window.location.protocol!=="https:"){Janus.warn("Screen sharing only works on HTTPS, try the https:// version of this page");a.consentDialog(false);n.error("Screen sharing only works on HTTPS, try the https:// version of this page");return}var p={};function m(s,o){a.consentDialog(false);if(s){n.error({code:s.code,name:s.name,message:s.message})}else{A(e,r,t,n,o)}}function b(e,n){Janus.log("Adding media constraint (screen capture)");Janus.debug(e);navigator.mediaDevices.getUserMedia(e).then(function(e){n(null,e)}).catch(function(e){a.consentDialog(false);n(e)})}if(adapter.browserDetails.browser==="chrome"){var J=adapter.browserDetails.version;var w=33;if(window.navigator.userAgent.match("Linux"))w=35;if(J>=26&&J<=w){i={video:{mandatory:{googLeakyBucket:true,maxWidth:window.screen.width,maxHeight:window.screen.height,maxFrameRate:3,chromeMediaSource:"screen"}},audio:H(t)};b(i,m)}else{var y=window.setTimeout(function(){S=new Error("NavigatorUserMediaError");S.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.consentDialog(false);return n.error(S)},1e3);p[y]=[m,null];window.postMessage({type:"janusGetScreen",id:y},"*")}}else if(window.navigator.userAgent.match("Firefox")){var h=parseInt(window.navigator.userAgent.match(/Firefox\/(.*)/)[1],10);if(h>=33){i={video:{mozMediaSource:t.video,mediaSource:t.video},audio:H(t)};b(i,function(e,n){m(e,n);if(!e){var r=n.currentTime;var t=window.setInterval(function(){if(!n)window.clearInterval(t);if(n.currentTime==r){window.clearInterval(t);if(n.onended){n.onended()}}r=n.currentTime},500)}})}else{var S=new Error("NavigatorUserMediaError");S.name="Your version of Firefox does not support screen sharing, please install Firefox 33 (or more recent versions)";a.consentDialog(false);n.error(S);return}}window.addEventListener("message",function(e){if(e.origin!=window.location.origin)return;if(e.data.type=="janusGotScreen"&&p[e.data.id]){var r=p[e.data.id];var s=r[0];delete p[e.data.id];if(e.data.sourceId===""){var o=new Error("NavigatorUserMediaError");o.name="You cancelled the request for permission, giving up...";a.consentDialog(false);n.error(o)}else{i={audio:H(t),video:{mandatory:{chromeMediaSource:"desktop",maxWidth:window.screen.width,maxHeight:window.screen.height,maxFrameRate:3},optional:[{googLeakyBucket:true},{googTemporalLayeredScreencast:true}]}};i.video.mandatory.chromeMediaSourceId=e.data.sourceId;b(i,s)}}else if(e.data.type=="janusGetScreenPending"){window.clearTimeout(e.data.id)}});return}}if(t===null||t===undefined||t.video!=="screen"){navigator.mediaDevices.enumerateDevices().then(function(s){var o=s.some(function(e){return e.kind==="audioinput"}),i=s.some(function(e){return e.kind==="videoinput"});var l=H(t);var c=q(t);if(l||c){var f=l?o:false;var g=c?i:false;if(!f&&!g){a.consentDialog(false);n.error("No capture device found");return false}}navigator.mediaDevices.getUserMedia({audio:o?u:false,video:i?d:false}).then(function(s){a.consentDialog(false);A(e,r,t,n,s)}).catch(function(e){a.consentDialog(false);n.error({code:e.code,name:e.name,message:e.message})})}).catch(function(e){a.consentDialog(false);n.error("enumerateDevices error",e)})}}else{A(e,r,t,n)}}function C(e,n){n=n||{};n.success=typeof n.success=="function"?n.success:Janus.noop;n.error=typeof n.error=="function"?n.error:V;var r=n.jsep;var t=v[e];if(t===null||t===undefined||t.webrtcStuff===null||t.webrtcStuff===undefined){Janus.warn("Invalid handle");n.error("Invalid handle");return}var a=t.webrtcStuff;if(r!==undefined&&r!==null){if(a.pc===null){Janus.warn("Wait, no PeerConnection?? if this is an answer, use createAnswer and not handleRemoteJsep");n.error("No PeerConnection: if this is an answer, use createAnswer and not handleRemoteJsep");return}a.pc.setRemoteDescription(new RTCSessionDescription(r),function(){Janus.log("Remote description accepted!");n.success()},n.error)}else{n.error("Invalid JSEP")}}function E(e,n,r){r=r||{};r.success=typeof r.success=="function"?r.success:Janus.noop;r.error=typeof r.error=="function"?r.error:Janus.noop;var t=v[e];if(t===null||t===undefined||t.webrtcStuff===null||t.webrtcStuff===undefined){Janus.warn("Invalid handle");r.error("Invalid handle");return}var a=t.webrtcStuff;Janus.log("Creating offer (iceDone="+a.iceDone+")");var s=null;if(adapter.browserDetails.browser=="firefox"||adapter.browserDetails.browser=="edge"){s={offerToReceiveAudio:G(n),offerToReceiveVideo:z(n)}}else{s={mandatory:{OfferToReceiveAudio:G(n),OfferToReceiveVideo:z(n)}}}Janus.debug(s);a.pc.createOffer(function(e){Janus.debug(e);if(a.mySdp===null||a.mySdp===undefined){Janus.log("Setting local description");a.mySdp=e.sdp;a.pc.setLocalDescription(e)}if(!a.iceDone&&!a.trickle){Janus.log("Waiting for all candidates...");return}if(a.sdpSent){Janus.log("Offer already sent, not sending it again");return}Janus.log("Offer ready");Janus.debug(r);a.sdpSent=true;var n={type:e.type,sdp:e.sdp};r.success(n)},r.error,s)}function N(e,n,r){r=r||{};r.success=typeof r.success=="function"?r.success:Janus.noop;r.error=typeof r.error=="function"?r.error:Janus.noop;var t=v[e];if(t===null||t===undefined||t.webrtcStuff===null||t.webrtcStuff===undefined){Janus.warn("Invalid handle");r.error("Invalid handle");return}var a=t.webrtcStuff;Janus.log("Creating answer (iceDone="+a.iceDone+")");var s=null;if(adapter.browserDetails.browser=="firefox"||adapter.browserDetails.browser=="edge"){s={offerToReceiveAudio:G(n),offerToReceiveVideo:z(n)}}else{s={mandatory:{OfferToReceiveAudio:G(n),OfferToReceiveVideo:z(n)}}}Janus.debug(s);

a.pc.createAnswer(function(e){Janus.debug(e);if(a.mySdp===null||a.mySdp===undefined){Janus.log("Setting local description");a.mySdp=e.sdp;a.pc.setLocalDescription(e)}if(!a.iceDone&&!a.trickle){Janus.log("Waiting for all candidates...");return}if(a.sdpSent){Janus.log("Answer already sent, not sending it again");return}a.sdpSent=true;var n={type:e.type,sdp:e.sdp};r.success(n)},r.error,s)}function _(e,n){n=n||{};n.success=typeof n.success=="function"?n.success:Janus.noop;n.error=typeof n.error=="function"?n.error:Janus.noop;var r=v[e];if(r===null||r===undefined||r.webrtcStuff===null||r.webrtcStuff===undefined){Janus.warn("Invalid handle, not sending anything");return}var t=r.webrtcStuff;Janus.log("Sending offer/answer SDP...");if(t.mySdp===null||t.mySdp===undefined){Janus.warn("Local SDP instance is invalid, not sending anything...");return}t.mySdp={type:t.pc.localDescription.type,sdp:t.pc.localDescription.sdp};if(t.sdpSent){Janus.log("Offer/Answer SDP already sent, not sending it again");return}if(t.trickle===false)t.mySdp["trickle"]=false;Janus.debug(n);t.sdpSent=true;n.success(t.mySdp)}function P(e){var n=v[e];if(n===null||n===undefined||n.webrtcStuff===null||n.webrtcStuff===undefined){Janus.warn("Invalid handle");return 0}var r=n.webrtcStuff;if(r.pc.getStats&&adapter.browserDetails.browser=="chrome"){if(r.remoteStream===null||r.remoteStream===undefined){Janus.warn("Remote stream unavailable");return 0}if(r.volume.timer===null||r.volume.timer===undefined){Janus.log("Starting volume monitor");r.volume.timer=setInterval(function(){r.pc.getStats(function(e){var n=e.result();for(var t=0;t<n.length;t++){var a=n[t];if(a.type=="ssrc"&&a.stat("audioOutputLevel")){r.volume.value=a.stat("audioOutputLevel")}}})},200);return 0}return r.volume.value}else{Janus.log("Getting the remote volume unsupported by browser");return 0}}function U(e,n){var r=v[e];if(r===null||r===undefined||r.webrtcStuff===null||r.webrtcStuff===undefined){Janus.warn("Invalid handle");return true}var t=r.webrtcStuff;if(t.pc===null||t.pc===undefined){Janus.warn("Invalid PeerConnection");return true}if(t.myStream===undefined||t.myStream===null){Janus.warn("Invalid local MediaStream");return true}if(n){if(t.myStream.getVideoTracks()===null||t.myStream.getVideoTracks()===undefined||t.myStream.getVideoTracks().length===0){Janus.warn("No video track");return true}return!t.myStream.getVideoTracks()[0].enabled}else{if(t.myStream.getAudioTracks()===null||t.myStream.getAudioTracks()===undefined||t.myStream.getAudioTracks().length===0){Janus.warn("No audio track");return true}return!t.myStream.getAudioTracks()[0].enabled}}function L(e,n,r){var t=v[e];if(t===null||t===undefined||t.webrtcStuff===null||t.webrtcStuff===undefined){Janus.warn("Invalid handle");return false}var a=t.webrtcStuff;if(a.pc===null||a.pc===undefined){Janus.warn("Invalid PeerConnection");return false}if(a.myStream===undefined||a.myStream===null){Janus.warn("Invalid local MediaStream");return false}if(n){if(a.myStream.getVideoTracks()===null||a.myStream.getVideoTracks()===undefined||a.myStream.getVideoTracks().length===0){Janus.warn("No video track");return false}a.myStream.getVideoTracks()[0].enabled=r?false:true;return true}else{if(a.myStream.getAudioTracks()===null||a.myStream.getAudioTracks()===undefined||a.myStream.getAudioTracks().length===0){Janus.warn("No audio track");return false}a.myStream.getAudioTracks()[0].enabled=r?false:true;return true}}function F(e){var n=v[e];if(n===null||n===undefined||n.webrtcStuff===null||n.webrtcStuff===undefined){Janus.warn("Invalid handle");return"Invalid handle"}var r=n.webrtcStuff;if(r.pc===null||r.pc===undefined)return"Invalid PeerConnection";if(r.pc.getStats&&adapter.browserDetails.browser=="chrome"){if(r.remoteStream===null||r.remoteStream===undefined){Janus.warn("Remote stream unavailable");return"Remote stream unavailable"}if(r.bitrate.timer===null||r.bitrate.timer===undefined){Janus.log("Starting bitrate timer (Chrome)");r.bitrate.timer=setInterval(function(){r.pc.getStats(function(e){var n=e.result();for(var t=0;t<n.length;t++){var a=n[t];if(a.type=="ssrc"&&a.stat("googFrameHeightReceived")){r.bitrate.bsnow=a.stat("bytesReceived");r.bitrate.tsnow=a.timestamp;if(r.bitrate.bsbefore===null||r.bitrate.tsbefore===null){r.bitrate.bsbefore=r.bitrate.bsnow;r.bitrate.tsbefore=r.bitrate.tsnow}else{var s=Math.round((r.bitrate.bsnow-r.bitrate.bsbefore)*8/(r.bitrate.tsnow-r.bitrate.tsbefore));r.bitrate.value=s+" kbits/sec";r.bitrate.bsbefore=r.bitrate.bsnow;r.bitrate.tsbefore=r.bitrate.tsnow}}}})},1e3);return"0 kbits/sec"}return r.bitrate.value}else if(r.pc.getStats&&adapter.browserDetails.browser=="firefox"){if(r.remoteStream===null||r.remoteStream===undefined||r.remoteStream.stream===null||r.remoteStream.stream===undefined){Janus.warn("Remote stream unavailable");return"Remote stream unavailable"}var t=r.remoteStream.stream.getVideoTracks();if(t===null||t===undefined||t.length<1){Janus.warn("No video track");return"No video track"}if(r.bitrate.timer===null||r.bitrate.timer===undefined){Janus.log("Starting bitrate timer (Firefox)");r.bitrate.timer=setInterval(function(){var e=function(e){if(e===null||e===undefined||e.inbound_rtp_video_1==null||e.inbound_rtp_video_1==null){r.bitrate.value="Missing inbound_rtp_video_1";return}r.bitrate.bsnow=e.inbound_rtp_video_1.bytesReceived;r.bitrate.tsnow=e.inbound_rtp_video_1.timestamp;if(r.bitrate.bsbefore===null||r.bitrate.tsbefore===null){r.bitrate.bsbefore=r.bitrate.bsnow;r.bitrate.tsbefore=r.bitrate.tsnow}else{var n=Math.round((r.bitrate.bsnow-r.bitrate.bsbefore)*8/(r.bitrate.tsnow-r.bitrate.tsbefore));r.bitrate.value=n+" kbits/sec";r.bitrate.bsbefore=r.bitrate.bsnow;r.bitrate.tsbefore=r.bitrate.tsnow}};r.pc.getStats(t[0],function(n){e(n)},e)},1e3);return"0 kbits/sec"}return r.bitrate.value}else{Janus.warn("Getting the video bitrate unsupported by browser");return"Feature unsupported by browser"}}function V(e){Janus.error("WebRTC error:",e)}function W(e,t){Janus.log("Cleaning WebRTC stuff");var a=v[e];if(a===null||a===undefined){return}var s=a.webrtcStuff;if(s!==null&&s!==undefined){if(t===true){var o={janus:"hangup",transaction:w(12)};if(c!==null&&c!==undefined)o["token"]=c;if(f!==null&&f!==undefined)o["apisecret"]=f;Janus.debug("Sending hangup request (handle="+e+"):");Janus.debug(o);if(n){o["session_id"]=p;o["handle_id"]=e;r.send(JSON.stringify(o))}else{$.ajax({type:"POST",url:i+"/"+p+"/"+e,cache:false,contentType:"application/json",data:JSON.stringify(o),dataType:"json"})}}s.remoteStream=null;if(s.volume.timer)clearInterval(s.volume.timer);s.volume.value=null;if(s.bitrate.timer)clearInterval(s.bitrate.timer);s.bitrate.timer=null;s.bitrate.bsnow=null;s.bitrate.bsbefore=null;s.bitrate.tsnow=null;s.bitrate.tsbefore=null;s.bitrate.value=null;try{if(!s.streamExternal&&s.myStream!==null&&s.myStream!==undefined){Janus.log("Stopping local stream");s.myStream.stop()}}catch(u){}try{if(!s.streamExternal&&s.myStream!==null&&s.myStream!==undefined){Janus.log("Stopping local stream tracks");var d=s.myStream.getTracks();for(var l in d){var g=d[l];Janus.log(g);if(g!==null&&g!==undefined)g.stop()}}}catch(u){}s.streamExternal=false;s.myStream=null;try{s.pc.close()}catch(u){}s.pc=null;s.mySdp=null;s.iceDone=false;s.sdpSent=false;s.dataChannel=null;s.dtmfSender=null}a.oncleanup()}function H(e){Janus.debug("isAudioSendEnabled:",e);if(e===undefined||e===null)return true;if(e.audio===false)return false;if(e.audioSend===undefined||e.audioSend===null)return true;return e.audioSend===true}function G(e){Janus.debug("isAudioRecvEnabled:",e);if(e===undefined||e===null)return true;if(e.audio===false)return false;if(e.audioRecv===undefined||e.audioRecv===null)return true;return e.audioRecv===true}function q(e){Janus.debug("isVideoSendEnabled:",e);if(adapter.browserDetails.browser=="edge"){Janus.warn("Edge doesn't support compatible video yet");return false}if(e===undefined||e===null)return true;if(e.video===false)return false;if(e.videoSend===undefined||e.videoSend===null)return true;return e.videoSend===true}function z(e){Janus.debug("isVideoRecvEnabled:",e);if(adapter.browserDetails.browser=="edge"){Janus.warn("Edge doesn't support compatible video yet");return false}if(e===undefined||e===null)return true;if(e.video===false)return false;if(e.videoRecv===undefined||e.videoRecv===null)return true;return e.videoRecv===true}function B(e){Janus.debug("isDataEnabled:",e);if(adapter.browserDetails.browser=="edge"){Janus.warn("Edge doesn't support data channels yet");return false}if(e===undefined||e===null)return false;return e.data===true}function Y(e){Janus.debug("isTrickleEnabled:",e);if(e===undefined||e===null)return true;return e===true}}
//# sourceMappingURL=janus.map.js