@networked-aframe/naf-janus-adapter
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -1,3 +0,2 @@ | ||
/*! For license information please see naf-janus-adapter.min.js.LICENSE.txt */ | ||
(()=>{var e={806:e=>{function t(e){this.session=e,this.id=void 0}function n(e,t){this.output=e,this.id=void 0,this.nextTxId=0,this.txns={},this.eventHandlers={},this.options=Object.assign({verbose:!1,timeoutMs:1e4,keepaliveMs:3e4},t)}t.prototype.attach=function(e,t){var n={plugin:e,loop_index:t,"force-bundle":!0,"force-rtcp-mux":!0};return this.session.send("attach",n).then((e=>(this.id=e.data.id,e)))},t.prototype.detach=function(){return this.send("detach")},t.prototype.on=function(e,t){return this.session.on(e,(e=>{e.sender==this.id&&t(e)}))},t.prototype.send=function(e,t){return this.session.send(e,Object.assign({handle_id:this.id},t))},t.prototype.sendMessage=function(e){return this.send("message",{body:e})},t.prototype.sendJsep=function(e){return this.send("message",{body:{},jsep:e})},t.prototype.sendTrickle=function(e){return this.send("trickle",{candidate:e})},n.prototype.create=function(){return this.send("create").then((e=>(this.id=e.data.id,e)))},n.prototype.destroy=function(){return this.send("destroy").then((e=>(this.dispose(),e)))},n.prototype.dispose=function(){for(var e in this._killKeepalive(),this.eventHandlers={},this.txns)if(this.txns.hasOwnProperty(e)){var t=this.txns[e];clearTimeout(t.timeout),t.reject(new Error("Janus session was disposed.")),delete this.txns[e]}},n.prototype.isError=function(e){return"error"===e.janus},n.prototype.on=function(e,t){var n=this.eventHandlers[e];null==n&&(n=this.eventHandlers[e]=[]),n.push(t)},n.prototype.receive=function(e){this.options.verbose&&this._logIncoming(e),e.session_id!=this.id&&console.warn("Incorrect session ID received in Janus signalling message: was "+e.session_id+", expected "+this.id+".");var t=e.janus,n=this.eventHandlers[t];if(null!=n)for(var r=0;r<n.length;r++)n[r](e);if(null!=e.transaction){var s=this.txns[e.transaction];if(null==s)return;if("ack"===t&&"message"==s.type)return;clearTimeout(s.timeout),delete this.txns[e.transaction],(this.isError(e)?s.reject:s.resolve)(e)}},n.prototype.send=function(e,t){return t=Object.assign({transaction:(this.nextTxId++).toString()},t),new Promise(((n,r)=>{var s=null;this.options.timeoutMs&&(s=setTimeout((()=>{delete this.txns[t.transaction],r(new Error("Signalling transaction with txid "+t.transaction+" timed out."))}),this.options.timeoutMs)),this.txns[t.transaction]={resolve:n,reject:r,timeout:s,type:e},this._transmit(e,t)}))},n.prototype._transmit=function(e,t){t=Object.assign({janus:e},t),null!=this.id&&(t=Object.assign({session_id:this.id},t)),this.options.verbose&&this._logOutgoing(t),this.output(JSON.stringify(t)),this._resetKeepalive()},n.prototype._logOutgoing=function(e){var t=e.janus;"message"===t&&e.jsep&&(t=e.jsep.type);var n="> Outgoing Janus "+(t||"signal")+" (#"+e.transaction+"): ";console.debug("%c"+n,"color: #040",e)},n.prototype._logIncoming=function(e){var t=e.janus,n=e.transaction?"< Incoming Janus "+(t||"signal")+" (#"+e.transaction+"): ":"< Incoming Janus "+(t||"signal")+": ";console.debug("%c"+n,"color: #004",e)},n.prototype._sendKeepalive=function(){return this.send("keepalive")},n.prototype._killKeepalive=function(){clearTimeout(this.keepaliveTimeout)},n.prototype._resetKeepalive=function(){this._killKeepalive(),this.options.keepaliveMs&&(this.keepaliveTimeout=setTimeout((()=>{this._sendKeepalive().catch((e=>console.error("Error received from keepalive: ",e)))}),this.options.keepaliveMs))},e.exports={JanusPluginHandle:t,JanusSession:n}},579:(e,t,n)=>{function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function s(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function a(){"use strict";a=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,s=Object.defineProperty||function(e,t,n){e[t]=n.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function l(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,n){return e[t]=n}}function p(e,t,n,r){var i=t&&t.prototype instanceof f?t:f,a=Object.create(i.prototype),o=new E(r||[]);return s(a,"_invoke",{value:x(e,n,o)}),a}function d(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=p;var h={};function f(){}function m(){}function g(){}var v={};l(v,o,(function(){return this}));var y=Object.getPrototypeOf,b=y&&y(y(F([])));b&&b!==t&&n.call(b,o)&&(v=b);var w=g.prototype=f.prototype=Object.create(v);function k(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function C(e,t){function i(s,a,o,c){var u=d(e[s],e,a);if("throw"!==u.type){var l=u.arg,p=l.value;return p&&"object"==r(p)&&n.call(p,"__await")?t.resolve(p.__await).then((function(e){i("next",e,o,c)}),(function(e){i("throw",e,o,c)})):t.resolve(p).then((function(e){l.value=e,o(l)}),(function(e){return i("throw",e,o,c)}))}c(u.arg)}var a;s(this,"_invoke",{value:function(e,n){function r(){return new t((function(t,r){i(e,n,t,r)}))}return a=a?a.then(r,r):r()}})}function x(e,t,n){var r="suspendedStart";return function(s,i){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===s)throw i;return{value:void 0,done:!0}}for(n.method=s,n.arg=i;;){var a=n.delegate;if(a){var o=O(a,n);if(o){if(o===h)continue;return o}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=d(e,t,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}function O(e,t){var n=t.method,r=e.iterator[n];if(void 0===r)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,O(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),h;var s=d(r,e.iterator,t.arg);if("throw"===s.type)return t.method="throw",t.arg=s.arg,t.delegate=null,h;var i=s.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,h):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,h)}function S(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(S,this),this.reset(!0)}function F(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,s=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return s.next=s}}return{next:P}}function P(){return{value:void 0,done:!0}}return m.prototype=g,s(w,"constructor",{value:g,configurable:!0}),s(g,"constructor",{value:m,configurable:!0}),m.displayName=l(g,u,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,g):(e.__proto__=g,l(e,u,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},k(C.prototype),l(C.prototype,c,(function(){return this})),e.AsyncIterator=C,e.async=function(t,n,r,s,i){void 0===i&&(i=Promise);var a=new C(p(t,n,r,s),i);return e.isGeneratorFunction(n)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},k(w),l(w,u,"Generator"),l(w,o,(function(){return this})),l(w,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),n=[];for(var r in t)n.push(r);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},e.values=F,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(T),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return a.type="throw",a.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var s=this.tryEntries.length-1;s>=0;--s){var i=this.tryEntries[s],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var o=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(o&&c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(o){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var s=this.tryEntries[r];if(s.tryLoc<=this.prev&&n.call(s,"finallyLoc")&&this.prev<s.finallyLoc){var i=s;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),h},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),T(n),h}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var s=r.arg;T(n)}return s}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:F(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),h}},e}function o(e,t,n,r,s,i,a){try{var o=e[i](a),c=o.value}catch(e){return void n(e)}o.done?t(c):Promise.resolve(c).then(r,s)}function c(e){return function(){var t=this,n=arguments;return new Promise((function(r,s){var i=e.apply(t,n);function a(e){o(i,r,s,a,c,"next",e)}function c(e){o(i,r,s,a,c,"throw",e)}a(void 0)}))}}function u(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,(void 0,i=function(e,t){if("object"!==r(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var s=n.call(e,"string");if("object"!==r(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(s.key),"symbol"===r(i)?i:String(i)),s)}var i}var l=n(806);l.JanusSession.prototype.sendOriginal=l.JanusSession.prototype.send,l.JanusSession.prototype.send=function(e,t){return this.sendOriginal(e,t).catch((function(e){if(!(e.message&&e.message.indexOf("timed out")>-1))throw e;console.error("web socket timed out"),NAF.connection.adapter.reconnect()}))};var p=n(539),d=n(227)("naf-janus-adapter:debug"),h=(n(227)("naf-janus-adapter:warn"),n(227)("naf-janus-adapter:error")),f=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function m(e,t){return new Promise((function(n){var r=Math.random()*(t-e)+e;setTimeout(n,r)}))}function g(e){var t=Promise.resolve();return function(){var n=this,r=Array.prototype.slice.call(arguments);t=t.then((function(t){return e.apply(n,r)}))}}function v(e){return new Promise((function(t,n){if("open"===e.readyState)t();else{var r,s,i=function(){e.removeEventListener("open",r),e.removeEventListener("error",s)};r=function(){i(),t()},s=function(){i(),n()},e.addEventListener("open",r),e.addEventListener("error",s)}}))}var y=""!==document.createElement("video").canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"'),b={usedtx:1,stereo:0,"sprop-stereo":0},w={iceServers:[{urls:"stun:stun1.l.google.com:19302"},{urls:"stun:stun2.l.google.com:19302"}]},k=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.room=null,this.clientId=null,this.joinToken=null,this.serverUrl=null,this.webRtcOptions={},this.peerConnectionConfig=null,this.ws=null,this.session=null,this.reliableTransport="datachannel",this.unreliableTransport="datachannel",this.initialReconnectionDelay=1e3*Math.random(),this.reconnectionDelay=this.initialReconnectionDelay,this.reconnectionTimeout=null,this.maxReconnectionAttempts=10,this.reconnectionAttempts=0,this.publisher=null,this.occupantIds=[],this.occupants={},this.mediaStreams={},this.localMediaStream=null,this.pendingMediaRequests=new Map,this.pendingOccupants=new Set,this.availableOccupants=[],this.requestedOccupants=null,this.blockedClients=new Map,this.frozenUpdates=new Map,this.timeOffsets=[],this.serverTimeRequests=0,this.avgTimeOffset=0,this.onWebsocketOpen=this.onWebsocketOpen.bind(this),this.onWebsocketClose=this.onWebsocketClose.bind(this),this.onWebsocketMessage=this.onWebsocketMessage.bind(this),this.onDataChannelMessage=this.onDataChannelMessage.bind(this),this.onData=this.onData.bind(this)}var t,n,r,i,o,k,C,x,O;return t=e,n=[{key:"setServerUrl",value:function(e){this.serverUrl=e}},{key:"setApp",value:function(e){}},{key:"setRoom",value:function(e){this.room=e}},{key:"setJoinToken",value:function(e){this.joinToken=e}},{key:"setClientId",value:function(e){this.clientId=e}},{key:"setWebRtcOptions",value:function(e){this.webRtcOptions=e}},{key:"setPeerConnectionConfig",value:function(e){this.peerConnectionConfig=e}},{key:"setServerConnectListeners",value:function(e,t){this.connectSuccess=e,this.connectFailure=t}},{key:"setRoomOccupantListener",value:function(e){this.onOccupantsChanged=e}},{key:"setDataChannelListeners",value:function(e,t,n){this.onOccupantConnected=e,this.onOccupantDisconnected=t,this.onOccupantMessage=n}},{key:"setReconnectionListeners",value:function(e,t,n){this.onReconnecting=e,this.onReconnected=t,this.onReconnectionError=n}},{key:"setEventLoops",value:function(e){this.loops=e}},{key:"connect",value:function(){var e=this;d("connecting to ".concat(this.serverUrl));var t=new Promise((function(t,n){e.ws=new WebSocket(e.serverUrl,"janus-protocol"),e.session=new l.JanusSession(e.ws.send.bind(e.ws),{timeoutMs:4e4}),e.ws.addEventListener("close",e.onWebsocketClose),e.ws.addEventListener("message",e.onWebsocketMessage),e.wsOnOpen=function(){e.ws.removeEventListener("open",e.wsOnOpen),e.onWebsocketOpen().then(t).catch(n)},e.ws.addEventListener("open",e.wsOnOpen)}));return Promise.all([t,this.updateTimeOffset()])}},{key:"disconnect",value:function(){d("disconnecting"),clearTimeout(this.reconnectionTimeout),this.removeAllOccupants(),this.publisher&&(this.publisher.conn.close(),this.publisher=null),this.session&&(this.session.dispose(),this.session=null),this.ws&&(this.ws.removeEventListener("open",this.wsOnOpen),this.ws.removeEventListener("close",this.onWebsocketClose),this.ws.removeEventListener("message",this.onWebsocketMessage),this.ws.close(),this.ws=null),this.delayedReconnectTimeout&&(clearTimeout(this.delayedReconnectTimeout),this.delayedReconnectTimeout=null)}},{key:"isDisconnected",value:function(){return null===this.ws}},{key:"onWebsocketOpen",value:(O=c(a().mark((function e(){var t,n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.session.create();case 2:return e.next=4,this.createPublisher();case 4:this.publisher=e.sent,this.connectSuccess(this.clientId),t=0;case 7:if(!(t<this.publisher.initialOccupants.length)){e.next=15;break}if((n=this.publisher.initialOccupants[t])!==this.clientId){e.next=11;break}return e.abrupt("continue",12);case 11:this.addAvailableOccupant(n);case 12:t++,e.next=7;break;case 15:this.syncOccupants();case 16:case"end":return e.stop()}}),e,this)}))),function(){return O.apply(this,arguments)})},{key:"onWebsocketClose",value:function(e){var t=this;1e3!==e.code&&(console.warn("Janus websocket closed unexpectedly."),this.onReconnecting&&this.onReconnecting(this.reconnectionDelay),this.reconnectionTimeout=setTimeout((function(){return t.reconnect()}),this.reconnectionDelay))}},{key:"reconnect",value:function(){var e=this;this.disconnect(),this.connect().then((function(){e.reconnectionDelay=e.initialReconnectionDelay,e.reconnectionAttempts=0,e.onReconnected&&e.onReconnected()})).catch((function(t){if(e.reconnectionDelay+=1e3,e.reconnectionAttempts++,e.reconnectionAttempts>e.maxReconnectionAttempts&&e.onReconnectionError)return e.onReconnectionError(new Error("Connection could not be reestablished, exceeded maximum number of reconnection attempts."));console.warn("Error during reconnect, retrying."),console.warn(t),e.onReconnecting&&e.onReconnecting(e.reconnectionDelay),e.reconnectionTimeout=setTimeout((function(){return e.reconnect()}),e.reconnectionDelay)}))}},{key:"performDelayedReconnect",value:function(){var e=this;this.delayedReconnectTimeout&&clearTimeout(this.delayedReconnectTimeout),this.delayedReconnectTimeout=setTimeout((function(){e.delayedReconnectTimeout=null,e.reconnect()}),1e4)}},{key:"onWebsocketMessage",value:function(e){this.session.receive(JSON.parse(e.data))}},{key:"addAvailableOccupant",value:function(e){-1===this.availableOccupants.indexOf(e)&&this.availableOccupants.push(e)}},{key:"removeAvailableOccupant",value:function(e){var t=this.availableOccupants.indexOf(e);-1!==t&&this.availableOccupants.splice(t,1)}},{key:"syncOccupants",value:function(e){if(e&&(this.requestedOccupants=e),this.requestedOccupants){for(var t=0;t<this.requestedOccupants.length;t++){var n=this.requestedOccupants[t];this.occupants[n]||-1===this.availableOccupants.indexOf(n)||this.pendingOccupants.has(n)||this.addOccupant(n)}for(var r=0;r<this.availableOccupants.length;r++){var s=this.availableOccupants[r];this.occupants[s]&&-1===this.requestedOccupants.indexOf(s)&&this.removeOccupant(s)}this.onOccupantsChanged(this.occupants)}}},{key:"addOccupant",value:(x=c(a().mark((function e(t){var n;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.pendingOccupants.add(t),!(this.availableOccupants.length>5)){e.next=5;break}return e.next=5,m(0,5e3);case 5:return e.next=7,this.createSubscriber(t);case 7:(n=e.sent)&&(this.pendingOccupants.has(t)?(this.pendingOccupants.delete(t),this.occupantIds.push(t),this.occupants[t]=n,this.setMediaStream(t,n.mediaStream),this.onOccupantConnected(t)):n.conn.close());case 9:case"end":return e.stop()}}),e,this)}))),function(e){return x.apply(this,arguments)})},{key:"removeAllOccupants",value:function(){this.pendingOccupants.clear();for(var e=this.occupantIds.length-1;e>=0;e--)this.removeOccupant(this.occupantIds[e])}},{key:"removeOccupant",value:function(e){if(this.pendingOccupants.delete(e),this.occupants[e]&&(this.occupants[e].conn.close(),delete this.occupants[e],this.occupantIds.splice(this.occupantIds.indexOf(e),1)),this.mediaStreams[e]&&delete this.mediaStreams[e],this.pendingMediaRequests.has(e)){var t="The user disconnected before the media stream was resolved.";this.pendingMediaRequests.get(e).audio.reject(t),this.pendingMediaRequests.get(e).video.reject(t),this.pendingMediaRequests.delete(e)}this.onOccupantDisconnected(e)}},{key:"associate",value:function(e,t){var n=this;e.addEventListener("icecandidate",(function(e){t.sendTrickle(e.candidate||null).catch((function(e){return h("Error trickling ICE: %o",e)}))})),e.addEventListener("iceconnectionstatechange",(function(t){"connected"===e.iceConnectionState&&console.log("ICE state changed to connected"),"disconnected"===e.iceConnectionState&&console.warn("ICE state changed to disconnected"),"failed"===e.iceConnectionState&&(console.warn("ICE failure detected. Reconnecting in 10s."),n.performDelayedReconnect())})),e.addEventListener("negotiationneeded",g((function(r){d("Sending new offer for handle: %o",t);var s=e.createOffer().then(n.configurePublisherSdp).then(n.fixSafariIceUFrag),i=s.then((function(t){return e.setLocalDescription(t)})),a=s;return a=a.then(n.fixSafariIceUFrag).then((function(e){return t.sendJsep(e)})).then((function(t){return e.setRemoteDescription(t.jsep)})),Promise.all([i,a]).catch((function(e){return h("Error negotiating offer: %o",e)}))}))),t.on("event",g((function(r){var s=r.jsep;if(s&&"offer"==s.type){d("Accepting new offer for handle: %o",t);var i=e.setRemoteDescription(n.configureSubscriberSdp(s)).then((function(t){return e.createAnswer()})).then(n.fixSafariIceUFrag),a=i.then((function(t){return e.setLocalDescription(t)})),o=i.then((function(e){return t.sendJsep(e)}));return Promise.all([a,o]).catch((function(e){return h("Error negotiating answer: %o",e)}))}return null})))}},{key:"createPublisher",value:(C=c(a().mark((function e(){var t,n,r,s,i,o,c,u,p=this;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=new l.JanusPluginHandle(this.session),n=new RTCPeerConnection(this.peerConnectionConfig||w),d("pub waiting for sfu"),e.next=5,t.attach("janus.plugin.sfu",this.loops&&this.clientId?parseInt(this.clientId)%this.loops:void 0);case 5:return this.associate(n,t),d("pub waiting for data channels & webrtcup"),r=new Promise((function(e){return t.on("webrtcup",e)})),s=n.createDataChannel("reliable",{ordered:!0}),i=n.createDataChannel("unreliable",{ordered:!1,maxRetransmits:0}),s.addEventListener("message",(function(e){return p.onDataChannelMessage(e,"janus-reliable")})),i.addEventListener("message",(function(e){return p.onDataChannelMessage(e,"janus-unreliable")})),e.next=14,r;case 14:return e.next=16,v(s);case 16:return e.next=18,v(i);case 18:return this.localMediaStream&&this.localMediaStream.getTracks().forEach((function(e){n.addTrack(e,p.localMediaStream)})),t.on("event",(function(e){var t=e.plugindata.data;if("join"==t.event&&t.room_id==p.room){if(p.delayedReconnectTimeout)return;p.addAvailableOccupant(t.user_id),p.syncOccupants()}else"leave"==t.event&&t.room_id==p.room?(p.removeAvailableOccupant(t.user_id),p.removeOccupant(t.user_id)):"blocked"==t.event?document.body.dispatchEvent(new CustomEvent("blocked",{detail:{clientId:t.by}})):"unblocked"==t.event?document.body.dispatchEvent(new CustomEvent("unblocked",{detail:{clientId:t.by}})):"data"===t.event&&p.onData(JSON.parse(t.body),"janus-event")})),d("pub waiting for join"),e.next=23,this.sendJoin(t,{notifications:!0,data:!0});case 23:if((o=e.sent).plugindata.data.success){e.next=29;break}throw c=o.plugindata.data.error,console.error(c),n.close(),c;case 29:return(u=o.plugindata.data.response.users[this.room]||[]).includes(this.clientId)&&(console.warn("Janus still has previous session for this client. Reconnecting in 10s."),this.performDelayedReconnect()),d("publisher ready"),e.abrupt("return",{handle:t,initialOccupants:u,reliableChannel:s,unreliableChannel:i,conn:n});case 33:case"end":return e.stop()}}),e,this)}))),function(){return C.apply(this,arguments)})},{key:"configurePublisherSdp",value:function(e){return e.sdp=e.sdp.replace(/a=fmtp:(109|111).*\r\n/g,(function(e,t){var n=Object.assign(p.parseFmtp(e),b);return p.writeFmtp({payloadType:t,parameters:n})})),e}},{key:"configureSubscriberSdp",value:function(e){return y||-1!==navigator.userAgent.indexOf("HeadlessChrome")&&(e.sdp=e.sdp.replace(/m=video[^]*m=/,"m=")),-1===navigator.userAgent.indexOf("Android")?e.sdp=e.sdp.replace("a=rtcp-fb:107 goog-remb\r\n","a=rtcp-fb:107 goog-remb\r\na=rtcp-fb:107 transport-cc\r\na=fmtp:107 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\n"):e.sdp=e.sdp.replace("a=rtcp-fb:107 goog-remb\r\n","a=rtcp-fb:107 goog-remb\r\na=rtcp-fb:107 transport-cc\r\na=fmtp:107 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f\r\n"),e}},{key:"fixSafariIceUFrag",value:(k=c(a().mark((function e(t){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t.sdp=t.sdp.replace(/[^\r]\na=ice-ufrag/g,"\r\na=ice-ufrag"),e.abrupt("return",t);case 2:case"end":return e.stop()}}),e)}))),function(e){return k.apply(this,arguments)})},{key:"createSubscriber",value:(o=c(a().mark((function e(t){var n,r,s,i,o,c,u=this,p=arguments;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=p.length>1&&void 0!==p[1]?p[1]:5,-1!==this.availableOccupants.indexOf(t)){e.next=4;break}return console.warn(t+": cancelled occupant connection, occupant left before subscription negotation."),e.abrupt("return",null);case 4:return r=new l.JanusPluginHandle(this.session),s=new RTCPeerConnection(this.peerConnectionConfig||w),d(t+": sub waiting for sfu"),e.next=9,r.attach("janus.plugin.sfu",this.loops?parseInt(t)%this.loops:void 0);case 9:if(this.associate(s,r),d(t+": sub waiting for join"),-1!==this.availableOccupants.indexOf(t)){e.next=15;break}return s.close(),console.warn(t+": cancelled occupant connection, occupant left after attach"),e.abrupt("return",null);case 15:return i=!1,o=new Promise((function(e){var n=setInterval((function(){-1===u.availableOccupants.indexOf(t)&&(clearInterval(n),e())}),1e3),s=setTimeout((function(){clearInterval(n),i=!0,e()}),15e3);r.on("webrtcup",(function(){clearTimeout(s),clearInterval(n),e()}))})),e.next=19,this.sendJoin(r,{media:t});case 19:if(-1!==this.availableOccupants.indexOf(t)){e.next=23;break}return s.close(),console.warn(t+": cancelled occupant connection, occupant left after join"),e.abrupt("return",null);case 23:return d(t+": sub waiting for webrtcup"),e.next=26,o;case 26:if(-1!==this.availableOccupants.indexOf(t)){e.next=30;break}return s.close(),console.warn(t+": cancel occupant connection, occupant left during or after webrtcup"),e.abrupt("return",null);case 30:if(!i){e.next=39;break}if(s.close(),!(n>0)){e.next=37;break}return console.warn(t+": webrtc up timed out, retrying"),e.abrupt("return",this.createSubscriber(t,n-1));case 37:return console.warn(t+": webrtc up timed out"),e.abrupt("return",null);case 39:if(!f||this._iOSHackDelayedInitialPeer){e.next=43;break}return e.next=42,new Promise((function(e){return setTimeout(e,3e3)}));case 42:this._iOSHackDelayedInitialPeer=!0;case 43:return c=new MediaStream,s.getReceivers().forEach((function(e){e.track&&c.addTrack(e.track)})),0===c.getTracks().length&&(c=null),d(t+": subscriber ready"),e.abrupt("return",{handle:r,mediaStream:c,conn:s});case 49:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"sendJoin",value:function(e,t){return e.sendMessage({kind:"join",room_id:this.room,user_id:this.clientId,subscribe:t,token:this.joinToken})}},{key:"toggleFreeze",value:function(){this.frozen?this.unfreeze():this.freeze()}},{key:"freeze",value:function(){this.frozen=!0}},{key:"unfreeze",value:function(){this.frozen=!1,this.flushPendingUpdates()}},{key:"dataForUpdateMultiMessage",value:function(e,t){for(var n=0,r=t.data.d.length;n<r;n++){var s=t.data.d[n];if(s.networkId===e)return s}return null}},{key:"getPendingData",value:function(e,t){if(!t)return null;var n="um"===t.dataType?this.dataForUpdateMultiMessage(e,t):t.data;return n.owner&&!this.occupants[n.owner]||n.owner&&this.blockedClients.has(n.owner)?null:n}},{key:"getPendingDataForNetworkId",value:function(e){return this.getPendingData(e,this.frozenUpdates.get(e))}},{key:"flushPendingUpdates",value:function(){var e,t,n,r=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=s(e))){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,c=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){c=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(c)throw a}}}}(this.frozenUpdates);try{for(r.s();!(e=r.n()).done;){var i=(t=e.value,n=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,s,i,a,o=[],c=!0,u=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=i.call(n)).done)&&(o.push(r.value),o.length!==t);c=!0);}catch(e){u=!0,s=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(u)throw s}}return o}}(t,n)||s(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),a=i[0],o=i[1],c=this.getPendingData(a,o);if(c){var u="um"===o.dataType?"u":o.dataType;this.onOccupantMessage(null,u,c,o.source)}}}catch(e){r.e(e)}finally{r.f()}this.frozenUpdates.clear()}},{key:"storeMessage",value:function(e){if("um"===e.dataType)for(var t=0,n=e.data.d.length;t<n;t++)this.storeSingleMessage(e,t);else this.storeSingleMessage(e)}},{key:"storeSingleMessage",value:function(e,t){var n=void 0!==t?e.data.d[t]:e.data,r=e.dataType,s=(e.source,n.networkId);if(this.frozenUpdates.has(s)){var i=this.frozenUpdates.get(s),a="um"===i.dataType?this.dataForUpdateMultiMessage(s,i):i.data,o=n.lastOwnerTime<a.lastOwnerTime,c=n.lastOwnerTime===a.lastOwnerTime;if(o||c&&a.owner>n.owner)return;"r"===r?a&&a.isFirstSync?this.frozenUpdates.delete(s):this.frozenUpdates.set(s,e):a.components&&n.components&&Object.assign(a.components,n.components)}else this.frozenUpdates.set(s,e)}},{key:"onDataChannelMessage",value:function(e,t){this.onData(JSON.parse(e.data),t)}},{key:"onData",value:function(e,t){d.enabled&&d("DC in: ".concat(e)),e.dataType&&(e.source=t,this.frozen?this.storeMessage(e):this.onOccupantMessage(null,e.dataType,e.data,e.source))}},{key:"shouldStartConnectionTo",value:function(e){return!0}},{key:"startStreamConnection",value:function(e){}},{key:"closeStreamConnection",value:function(e){}},{key:"getConnectStatus",value:function(e){return this.occupants[e]?NAF.adapters.IS_CONNECTED:NAF.adapters.NOT_CONNECTED}},{key:"updateTimeOffset",value:(i=c(a().mark((function e(){var t,n,r,s,i,o=this;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isDisconnected()){e.next=2;break}return e.abrupt("return");case 2:return t=Date.now(),e.next=5,fetch(document.location.href,{method:"HEAD",cache:"no-cache"});case 5:n=e.sent,r=new Date(n.headers.get("Date")).getTime()+500,s=Date.now(),i=r+(s-t)/2-s,this.serverTimeRequests++,this.serverTimeRequests<=10?this.timeOffsets.push(i):this.timeOffsets[this.serverTimeRequests%10]=i,this.avgTimeOffset=this.timeOffsets.reduce((function(e,t){return e+t}),0)/this.timeOffsets.length,this.serverTimeRequests>10?(d("new server time offset: ".concat(this.avgTimeOffset,"ms")),setTimeout((function(){return o.updateTimeOffset()}),3e5)):this.updateTimeOffset();case 15:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"getServerTime",value:function(){return Date.now()+this.avgTimeOffset}},{key:"getMediaStream",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"audio";if(this.mediaStreams[e])return d("Already had ".concat(n," for ").concat(e)),Promise.resolve(this.mediaStreams[e][n]);if(d("Waiting on ".concat(n," for ").concat(e)),!this.pendingMediaRequests.has(e)){this.pendingMediaRequests.set(e,{});var r=new Promise((function(n,r){t.pendingMediaRequests.get(e).audio={resolve:n,reject:r}})),s=new Promise((function(n,r){t.pendingMediaRequests.get(e).video={resolve:n,reject:r}}));this.pendingMediaRequests.get(e).audio.promise=r,this.pendingMediaRequests.get(e).video.promise=s,r.catch((function(t){return console.warn("".concat(e," getMediaStream Audio Error"),t)})),s.catch((function(t){return console.warn("".concat(e," getMediaStream Video Error"),t)}))}return this.pendingMediaRequests.get(e)[n].promise}},{key:"setMediaStream",value:function(e,t){var n=new MediaStream;try{t.getAudioTracks().forEach((function(e){return n.addTrack(e)}))}catch(t){console.warn("".concat(e," setMediaStream Audio Error"),t)}var r=new MediaStream;try{t.getVideoTracks().forEach((function(e){return r.addTrack(e)}))}catch(t){console.warn("".concat(e," setMediaStream Video Error"),t)}this.mediaStreams[e]={audio:n,video:r},this.pendingMediaRequests.has(e)&&(this.pendingMediaRequests.get(e).audio.resolve(n),this.pendingMediaRequests.get(e).video.resolve(r))}},{key:"setLocalMediaStream",value:(r=c(a().mark((function e(t){var n,r,s,i,o,c=this;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.publisher||!this.publisher.conn){e.next=12;break}n=this.publisher.conn.getSenders(),r=[],s=t.getTracks(),i=a().mark((function e(){var i,u;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(i=s[o],null==(u=n.find((function(e){return null!=e.track&&e.track.kind==i.kind})))){e.next=14;break}if(!u.replaceTrack){e.next=9;break}return e.next=6,u.replaceTrack(i);case 6:"video"===i.kind&&i.enabled&&navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&(i.enabled=!1,setTimeout((function(){return i.enabled=!0}),1e3)),e.next=11;break;case 9:t.removeTrack(u.track),t.addTrack(i);case 11:r.push(u),e.next=15;break;case 14:r.push(c.publisher.conn.addTrack(i,t));case 15:case"end":return e.stop()}}),e)})),o=0;case 6:if(!(o<s.length)){e.next=11;break}return e.delegateYield(i(),"t0",8);case 8:o++,e.next=6;break;case 11:n.forEach((function(e){r.includes(e)||(e.track.enabled=!1)}));case 12:this.localMediaStream=t,this.setMediaStream(this.clientId,t);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"enableMicrophone",value:function(e){this.publisher&&this.publisher.conn&&this.publisher.conn.getSenders().forEach((function(t){"audio"==t.track.kind&&(t.track.enabled=e)}))}},{key:"sendData",value:function(e,t,n){if(this.publisher)switch(this.unreliableTransport){case"websocket":this.publisher.handle.sendMessage({kind:"data",body:JSON.stringify({dataType:t,data:n}),whom:e});break;case"datachannel":this.publisher.unreliableChannel.send(JSON.stringify({clientId:e,dataType:t,data:n}));break;default:this.unreliableTransport(e,t,n)}else console.warn("sendData called without a publisher")}},{key:"sendDataGuaranteed",value:function(e,t,n){if(this.publisher)switch(this.reliableTransport){case"websocket":this.publisher.handle.sendMessage({kind:"data",body:JSON.stringify({dataType:t,data:n}),whom:e});break;case"datachannel":this.publisher.reliableChannel.send(JSON.stringify({clientId:e,dataType:t,data:n}));break;default:this.reliableTransport(e,t,n)}else console.warn("sendDataGuaranteed called without a publisher")}},{key:"broadcastData",value:function(e,t){if(this.publisher)switch(this.unreliableTransport){case"websocket":this.publisher.handle.sendMessage({kind:"data",body:JSON.stringify({dataType:e,data:t})});break;case"datachannel":this.publisher.unreliableChannel.send(JSON.stringify({dataType:e,data:t}));break;default:this.unreliableTransport(void 0,e,t)}else console.warn("broadcastData called without a publisher")}},{key:"broadcastDataGuaranteed",value:function(e,t){if(this.publisher)switch(this.reliableTransport){case"websocket":this.publisher.handle.sendMessage({kind:"data",body:JSON.stringify({dataType:e,data:t})});break;case"datachannel":this.publisher.reliableChannel.send(JSON.stringify({dataType:e,data:t}));break;default:this.reliableTransport(void 0,e,t)}else console.warn("broadcastDataGuaranteed called without a publisher")}},{key:"kick",value:function(e,t){return this.publisher.handle.sendMessage({kind:"kick",room_id:this.room,user_id:e,token:t}).then((function(){document.body.dispatchEvent(new CustomEvent("kicked",{detail:{clientId:e}}))}))}},{key:"block",value:function(e){var t=this;return this.publisher.handle.sendMessage({kind:"block",whom:e}).then((function(){t.blockedClients.set(e,!0),document.body.dispatchEvent(new CustomEvent("blocked",{detail:{clientId:e}}))}))}},{key:"unblock",value:function(e){var t=this;return this.publisher.handle.sendMessage({kind:"unblock",whom:e}).then((function(){t.blockedClients.delete(e),document.body.dispatchEvent(new CustomEvent("unblocked",{detail:{clientId:e}}))}))}}],n&&u(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();NAF.adapters.register("janus",k),e.exports=k},227:(e,t,n)=>{t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,s=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(r++,"%c"===e&&(s=r))})),t.splice(s,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=n(447)(t);const{formatters:r}=e.exports;r.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}},447:(e,t,n)=>{e.exports=function(e){function t(e){let n,s,i,a=null;function o(...e){if(!o.enabled)return;const r=o,s=Number(new Date),i=s-(n||s);r.diff=i,r.prev=n,r.curr=s,n=s,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let a=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((n,s)=>{if("%%"===n)return"%";a++;const i=t.formatters[s];if("function"==typeof i){const t=e[a];n=i.call(r,t),e.splice(a,1),a--}return n})),t.formatArgs.call(r,e),(r.log||t.log).apply(r,e)}return o.namespace=e,o.useColors=t.useColors(),o.color=t.selectColor(e),o.extend=r,o.destroy=t.destroy,Object.defineProperty(o,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==a?a:(s!==t.namespaces&&(s=t.namespaces,i=t.enabled(e)),i),set:e=>{a=e}}),"function"==typeof t.init&&t.init(o),o}function r(e,n){const r=t(this.namespace+(void 0===n?":":n)+e);return r.log=this.log,r}function s(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names.map(s),...t.skips.map(s).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const r=("string"==typeof e?e:"").split(/[\s,]+/),s=r.length;for(n=0;n<s;n++)r[n]&&("-"===(e=r[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.slice(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,r;for(n=0,r=t.skips.length;n<r;n++)if(t.skips[n].test(e))return!1;for(n=0,r=t.names.length;n<r;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=n(824),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((n=>{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}},824:e=>{var t=1e3,n=60*t,r=60*n,s=24*r;function i(e,t,n,r){var s=t>=1.5*n;return Math.round(e/n)+" "+r+(s?"s":"")}e.exports=function(e,a){a=a||{};var o,c,u=typeof e;if("string"===u&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var i=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(i){var a=parseFloat(i[1]);switch((i[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*a;case"weeks":case"week":case"w":return 6048e5*a;case"days":case"day":case"d":return a*s;case"hours":case"hour":case"hrs":case"hr":case"h":return a*r;case"minutes":case"minute":case"mins":case"min":case"m":return a*n;case"seconds":case"second":case"secs":case"sec":case"s":return a*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}}}(e);if("number"===u&&isFinite(e))return a.long?(o=e,(c=Math.abs(o))>=s?i(o,c,s,"day"):c>=r?i(o,c,r,"hour"):c>=n?i(o,c,n,"minute"):c>=t?i(o,c,t,"second"):o+" ms"):function(e){var i=Math.abs(e);return i>=s?Math.round(e/s)+"d":i>=r?Math.round(e/r)+"h":i>=n?Math.round(e/n)+"m":i>=t?Math.round(e/t)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},539:e=>{"use strict";const t={generateIdentifier:function(){return Math.random().toString(36).substring(2,12)}};t.localCName=t.generateIdentifier(),t.splitLines=function(e){return e.trim().split("\n").map((e=>e.trim()))},t.splitSections=function(e){return e.split("\nm=").map(((e,t)=>(t>0?"m="+e:e).trim()+"\r\n"))},t.getDescription=function(e){const n=t.splitSections(e);return n&&n[0]},t.getMediaSections=function(e){const n=t.splitSections(e);return n.shift(),n},t.matchPrefix=function(e,n){return t.splitLines(e).filter((e=>0===e.indexOf(n)))},t.parseCandidate=function(e){let t;t=0===e.indexOf("a=candidate:")?e.substring(12).split(" "):e.substring(10).split(" ");const n={foundation:t[0],component:{1:"rtp",2:"rtcp"}[t[1]]||t[1],protocol:t[2].toLowerCase(),priority:parseInt(t[3],10),ip:t[4],address:t[4],port:parseInt(t[5],10),type:t[7]};for(let e=8;e<t.length;e+=2)switch(t[e]){case"raddr":n.relatedAddress=t[e+1];break;case"rport":n.relatedPort=parseInt(t[e+1],10);break;case"tcptype":n.tcpType=t[e+1];break;case"ufrag":n.ufrag=t[e+1],n.usernameFragment=t[e+1];break;default:void 0===n[t[e]]&&(n[t[e]]=t[e+1])}return n},t.writeCandidate=function(e){const t=[];t.push(e.foundation);const n=e.component;"rtp"===n?t.push(1):"rtcp"===n?t.push(2):t.push(n),t.push(e.protocol.toUpperCase()),t.push(e.priority),t.push(e.address||e.ip),t.push(e.port);const r=e.type;return t.push("typ"),t.push(r),"host"!==r&&e.relatedAddress&&e.relatedPort&&(t.push("raddr"),t.push(e.relatedAddress),t.push("rport"),t.push(e.relatedPort)),e.tcpType&&"tcp"===e.protocol.toLowerCase()&&(t.push("tcptype"),t.push(e.tcpType)),(e.usernameFragment||e.ufrag)&&(t.push("ufrag"),t.push(e.usernameFragment||e.ufrag)),"candidate:"+t.join(" ")},t.parseIceOptions=function(e){return e.substring(14).split(" ")},t.parseRtpMap=function(e){let t=e.substring(9).split(" ");const n={payloadType:parseInt(t.shift(),10)};return t=t[0].split("/"),n.name=t[0],n.clockRate=parseInt(t[1],10),n.channels=3===t.length?parseInt(t[2],10):1,n.numChannels=n.channels,n},t.writeRtpMap=function(e){let t=e.payloadType;void 0!==e.preferredPayloadType&&(t=e.preferredPayloadType);const n=e.channels||e.numChannels||1;return"a=rtpmap:"+t+" "+e.name+"/"+e.clockRate+(1!==n?"/"+n:"")+"\r\n"},t.parseExtmap=function(e){const t=e.substring(9).split(" ");return{id:parseInt(t[0],10),direction:t[0].indexOf("/")>0?t[0].split("/")[1]:"sendrecv",uri:t[1],attributes:t.slice(2).join(" ")}},t.writeExtmap=function(e){return"a=extmap:"+(e.id||e.preferredId)+(e.direction&&"sendrecv"!==e.direction?"/"+e.direction:"")+" "+e.uri+(e.attributes?" "+e.attributes:"")+"\r\n"},t.parseFmtp=function(e){const t={};let n;const r=e.substring(e.indexOf(" ")+1).split(";");for(let e=0;e<r.length;e++)n=r[e].trim().split("="),t[n[0].trim()]=n[1];return t},t.writeFmtp=function(e){let t="",n=e.payloadType;if(void 0!==e.preferredPayloadType&&(n=e.preferredPayloadType),e.parameters&&Object.keys(e.parameters).length){const r=[];Object.keys(e.parameters).forEach((t=>{void 0!==e.parameters[t]?r.push(t+"="+e.parameters[t]):r.push(t)})),t+="a=fmtp:"+n+" "+r.join(";")+"\r\n"}return t},t.parseRtcpFb=function(e){const t=e.substring(e.indexOf(" ")+1).split(" ");return{type:t.shift(),parameter:t.join(" ")}},t.writeRtcpFb=function(e){let t="",n=e.payloadType;return void 0!==e.preferredPayloadType&&(n=e.preferredPayloadType),e.rtcpFeedback&&e.rtcpFeedback.length&&e.rtcpFeedback.forEach((e=>{t+="a=rtcp-fb:"+n+" "+e.type+(e.parameter&&e.parameter.length?" "+e.parameter:"")+"\r\n"})),t},t.parseSsrcMedia=function(e){const t=e.indexOf(" "),n={ssrc:parseInt(e.substring(7,t),10)},r=e.indexOf(":",t);return r>-1?(n.attribute=e.substring(t+1,r),n.value=e.substring(r+1)):n.attribute=e.substring(t+1),n},t.parseSsrcGroup=function(e){const t=e.substring(13).split(" ");return{semantics:t.shift(),ssrcs:t.map((e=>parseInt(e,10)))}},t.getMid=function(e){const n=t.matchPrefix(e,"a=mid:")[0];if(n)return n.substring(6)},t.parseFingerprint=function(e){const t=e.substring(14).split(" ");return{algorithm:t[0].toLowerCase(),value:t[1].toUpperCase()}},t.getDtlsParameters=function(e,n){return{role:"auto",fingerprints:t.matchPrefix(e+n,"a=fingerprint:").map(t.parseFingerprint)}},t.writeDtlsParameters=function(e,t){let n="a=setup:"+t+"\r\n";return e.fingerprints.forEach((e=>{n+="a=fingerprint:"+e.algorithm+" "+e.value+"\r\n"})),n},t.parseCryptoLine=function(e){const t=e.substring(9).split(" ");return{tag:parseInt(t[0],10),cryptoSuite:t[1],keyParams:t[2],sessionParams:t.slice(3)}},t.writeCryptoLine=function(e){return"a=crypto:"+e.tag+" "+e.cryptoSuite+" "+("object"==typeof e.keyParams?t.writeCryptoKeyParams(e.keyParams):e.keyParams)+(e.sessionParams?" "+e.sessionParams.join(" "):"")+"\r\n"},t.parseCryptoKeyParams=function(e){if(0!==e.indexOf("inline:"))return null;const t=e.substring(7).split("|");return{keyMethod:"inline",keySalt:t[0],lifeTime:t[1],mkiValue:t[2]?t[2].split(":")[0]:void 0,mkiLength:t[2]?t[2].split(":")[1]:void 0}},t.writeCryptoKeyParams=function(e){return e.keyMethod+":"+e.keySalt+(e.lifeTime?"|"+e.lifeTime:"")+(e.mkiValue&&e.mkiLength?"|"+e.mkiValue+":"+e.mkiLength:"")},t.getCryptoParameters=function(e,n){return t.matchPrefix(e+n,"a=crypto:").map(t.parseCryptoLine)},t.getIceParameters=function(e,n){const r=t.matchPrefix(e+n,"a=ice-ufrag:")[0],s=t.matchPrefix(e+n,"a=ice-pwd:")[0];return r&&s?{usernameFragment:r.substring(12),password:s.substring(10)}:null},t.writeIceParameters=function(e){let t="a=ice-ufrag:"+e.usernameFragment+"\r\na=ice-pwd:"+e.password+"\r\n";return e.iceLite&&(t+="a=ice-lite\r\n"),t},t.parseRtpParameters=function(e){const n={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},r=t.splitLines(e)[0].split(" ");n.profile=r[2];for(let s=3;s<r.length;s++){const i=r[s],a=t.matchPrefix(e,"a=rtpmap:"+i+" ")[0];if(a){const r=t.parseRtpMap(a),s=t.matchPrefix(e,"a=fmtp:"+i+" ");switch(r.parameters=s.length?t.parseFmtp(s[0]):{},r.rtcpFeedback=t.matchPrefix(e,"a=rtcp-fb:"+i+" ").map(t.parseRtcpFb),n.codecs.push(r),r.name.toUpperCase()){case"RED":case"ULPFEC":n.fecMechanisms.push(r.name.toUpperCase())}}}t.matchPrefix(e,"a=extmap:").forEach((e=>{n.headerExtensions.push(t.parseExtmap(e))}));const s=t.matchPrefix(e,"a=rtcp-fb:* ").map(t.parseRtcpFb);return n.codecs.forEach((e=>{s.forEach((t=>{e.rtcpFeedback.find((e=>e.type===t.type&&e.parameter===t.parameter))||e.rtcpFeedback.push(t)}))})),n},t.writeRtpDescription=function(e,n){let r="";r+="m="+e+" ",r+=n.codecs.length>0?"9":"0",r+=" "+(n.profile||"UDP/TLS/RTP/SAVPF")+" ",r+=n.codecs.map((e=>void 0!==e.preferredPayloadType?e.preferredPayloadType:e.payloadType)).join(" ")+"\r\n",r+="c=IN IP4 0.0.0.0\r\n",r+="a=rtcp:9 IN IP4 0.0.0.0\r\n",n.codecs.forEach((e=>{r+=t.writeRtpMap(e),r+=t.writeFmtp(e),r+=t.writeRtcpFb(e)}));let s=0;return n.codecs.forEach((e=>{e.maxptime>s&&(s=e.maxptime)})),s>0&&(r+="a=maxptime:"+s+"\r\n"),n.headerExtensions&&n.headerExtensions.forEach((e=>{r+=t.writeExtmap(e)})),r},t.parseRtpEncodingParameters=function(e){const n=[],r=t.parseRtpParameters(e),s=-1!==r.fecMechanisms.indexOf("RED"),i=-1!==r.fecMechanisms.indexOf("ULPFEC"),a=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"cname"===e.attribute)),o=a.length>0&&a[0].ssrc;let c;const u=t.matchPrefix(e,"a=ssrc-group:FID").map((e=>e.substring(17).split(" ").map((e=>parseInt(e,10)))));u.length>0&&u[0].length>1&&u[0][0]===o&&(c=u[0][1]),r.codecs.forEach((e=>{if("RTX"===e.name.toUpperCase()&&e.parameters.apt){let t={ssrc:o,codecPayloadType:parseInt(e.parameters.apt,10)};o&&c&&(t.rtx={ssrc:c}),n.push(t),s&&(t=JSON.parse(JSON.stringify(t)),t.fec={ssrc:o,mechanism:i?"red+ulpfec":"red"},n.push(t))}})),0===n.length&&o&&n.push({ssrc:o});let l=t.matchPrefix(e,"b=");return l.length&&(l=0===l[0].indexOf("b=TIAS:")?parseInt(l[0].substring(7),10):0===l[0].indexOf("b=AS:")?1e3*parseInt(l[0].substring(5),10)*.95-16e3:void 0,n.forEach((e=>{e.maxBitrate=l}))),n},t.parseRtcpParameters=function(e){const n={},r=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"cname"===e.attribute))[0];r&&(n.cname=r.value,n.ssrc=r.ssrc);const s=t.matchPrefix(e,"a=rtcp-rsize");n.reducedSize=s.length>0,n.compound=0===s.length;const i=t.matchPrefix(e,"a=rtcp-mux");return n.mux=i.length>0,n},t.writeRtcpParameters=function(e){let t="";return e.reducedSize&&(t+="a=rtcp-rsize\r\n"),e.mux&&(t+="a=rtcp-mux\r\n"),void 0!==e.ssrc&&e.cname&&(t+="a=ssrc:"+e.ssrc+" cname:"+e.cname+"\r\n"),t},t.parseMsid=function(e){let n;const r=t.matchPrefix(e,"a=msid:");if(1===r.length)return n=r[0].substring(7).split(" "),{stream:n[0],track:n[1]};const s=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"msid"===e.attribute));return s.length>0?(n=s[0].value.split(" "),{stream:n[0],track:n[1]}):void 0},t.parseSctpDescription=function(e){const n=t.parseMLine(e),r=t.matchPrefix(e,"a=max-message-size:");let s;r.length>0&&(s=parseInt(r[0].substring(19),10)),isNaN(s)&&(s=65536);const i=t.matchPrefix(e,"a=sctp-port:");if(i.length>0)return{port:parseInt(i[0].substring(12),10),protocol:n.fmt,maxMessageSize:s};const a=t.matchPrefix(e,"a=sctpmap:");if(a.length>0){const e=a[0].substring(10).split(" ");return{port:parseInt(e[0],10),protocol:e[1],maxMessageSize:s}}},t.writeSctpDescription=function(e,t){let n=[];return n="DTLS/SCTP"!==e.protocol?["m="+e.kind+" 9 "+e.protocol+" "+t.protocol+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctp-port:"+t.port+"\r\n"]:["m="+e.kind+" 9 "+e.protocol+" "+t.port+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctpmap:"+t.port+" "+t.protocol+" 65535\r\n"],void 0!==t.maxMessageSize&&n.push("a=max-message-size:"+t.maxMessageSize+"\r\n"),n.join("")},t.generateSessionId=function(){return Math.random().toString().substr(2,22)},t.writeSessionBoilerplate=function(e,n,r){let s;const i=void 0!==n?n:2;return s=e||t.generateSessionId(),"v=0\r\no="+(r||"thisisadapterortc")+" "+s+" "+i+" IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"},t.getDirection=function(e,n){const r=t.splitLines(e);for(let e=0;e<r.length;e++)switch(r[e]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return r[e].substring(2)}return n?t.getDirection(n):"sendrecv"},t.getKind=function(e){return t.splitLines(e)[0].split(" ")[0].substring(2)},t.isRejected=function(e){return"0"===e.split(" ",2)[1]},t.parseMLine=function(e){const n=t.splitLines(e)[0].substring(2).split(" ");return{kind:n[0],port:parseInt(n[1],10),protocol:n[2],fmt:n.slice(3).join(" ")}},t.parseOLine=function(e){const n=t.matchPrefix(e,"o=")[0].substring(2).split(" ");return{username:n[0],sessionId:n[1],sessionVersion:parseInt(n[2],10),netType:n[3],addressType:n[4],address:n[5]}},t.isValidSDP=function(e){if("string"!=typeof e||0===e.length)return!1;const n=t.splitLines(e);for(let e=0;e<n.length;e++)if(n[e].length<2||"="!==n[e].charAt(1))return!1;return!0},e.exports=t}},t={};!function n(r){var s=t[r];if(void 0!==s)return s.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}(579)})(); | ||
(()=>{var e={734:e=>{function t(e){this.session=e,this.id=void 0}function n(e,t){this.output=e,this.id=void 0,this.nextTxId=0,this.txns={},this.eventHandlers={},this.options=Object.assign({verbose:!1,timeoutMs:1e4,keepaliveMs:3e4},t)}t.prototype.attach=function(e,t){var n={plugin:e,loop_index:t,"force-bundle":!0,"force-rtcp-mux":!0};return this.session.send("attach",n).then((e=>(this.id=e.data.id,e)))},t.prototype.detach=function(){return this.send("detach")},t.prototype.on=function(e,t){return this.session.on(e,(e=>{e.sender==this.id&&t(e)}))},t.prototype.send=function(e,t){return this.session.send(e,Object.assign({handle_id:this.id},t))},t.prototype.sendMessage=function(e){return this.send("message",{body:e})},t.prototype.sendJsep=function(e){return this.send("message",{body:{},jsep:e})},t.prototype.sendTrickle=function(e){return this.send("trickle",{candidate:e})},n.prototype.create=function(){return this.send("create").then((e=>(this.id=e.data.id,e)))},n.prototype.destroy=function(){return this.send("destroy").then((e=>(this.dispose(),e)))},n.prototype.dispose=function(){for(var e in this._killKeepalive(),this.eventHandlers={},this.txns)if(this.txns.hasOwnProperty(e)){var t=this.txns[e];clearTimeout(t.timeout),t.reject(new Error("Janus session was disposed.")),delete this.txns[e]}},n.prototype.isError=function(e){return"error"===e.janus},n.prototype.on=function(e,t){var n=this.eventHandlers[e];null==n&&(n=this.eventHandlers[e]=[]),n.push(t)},n.prototype.receive=function(e){this.options.verbose&&this._logIncoming(e),e.session_id!=this.id&&console.warn("Incorrect session ID received in Janus signalling message: was "+e.session_id+", expected "+this.id+".");var t=e.janus,n=this.eventHandlers[t];if(null!=n)for(var s=0;s<n.length;s++)n[s](e);if(null!=e.transaction){var i=this.txns[e.transaction];if(null==i)return;if("ack"===t&&"message"==i.type)return;clearTimeout(i.timeout),delete this.txns[e.transaction],(this.isError(e)?i.reject:i.resolve)(e)}},n.prototype.send=function(e,t){return t=Object.assign({transaction:(this.nextTxId++).toString()},t),new Promise(((n,s)=>{var i=null;this.options.timeoutMs&&(i=setTimeout((()=>{delete this.txns[t.transaction],s(new Error("Signalling transaction with txid "+t.transaction+" timed out."))}),this.options.timeoutMs)),this.txns[t.transaction]={resolve:n,reject:s,timeout:i,type:e},this._transmit(e,t)}))},n.prototype._transmit=function(e,t){t=Object.assign({janus:e},t),null!=this.id&&(t=Object.assign({session_id:this.id},t)),this.options.verbose&&this._logOutgoing(t),this.output(JSON.stringify(t)),this._resetKeepalive()},n.prototype._logOutgoing=function(e){var t=e.janus;"message"===t&&e.jsep&&(t=e.jsep.type);var n="> Outgoing Janus "+(t||"signal")+" (#"+e.transaction+"): ";console.debug("%c"+n,"color: #040",e)},n.prototype._logIncoming=function(e){var t=e.janus,n=e.transaction?"< Incoming Janus "+(t||"signal")+" (#"+e.transaction+"): ":"< Incoming Janus "+(t||"signal")+": ";console.debug("%c"+n,"color: #004",e)},n.prototype._sendKeepalive=function(){return this.send("keepalive")},n.prototype._killKeepalive=function(){clearTimeout(this.keepaliveTimeout)},n.prototype._resetKeepalive=function(){this._killKeepalive(),this.options.keepaliveMs&&(this.keepaliveTimeout=setTimeout((()=>{this._sendKeepalive().catch((e=>console.error("Error received from keepalive: ",e)))}),this.options.keepaliveMs))},e.exports={JanusPluginHandle:t,JanusSession:n}},497:(e,t,n)=>{var s=n(734);s.JanusSession.prototype.sendOriginal=s.JanusSession.prototype.send,s.JanusSession.prototype.send=function(e,t){return this.sendOriginal(e,t).catch((e=>{if(!(e.message&&e.message.indexOf("timed out")>-1))throw e;console.error("web socket timed out"),NAF.connection.adapter.reconnect()}))};var i=n(963),r=n(833)("naf-janus-adapter:debug"),a=(n(833)("naf-janus-adapter:warn"),n(833)("naf-janus-adapter:error")),o=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function c(e){var t=Promise.resolve();return function(){var n=Array.prototype.slice.call(arguments);t=t.then((t=>e.apply(this,n)))}}function l(e){return new Promise(((t,n)=>{if("open"===e.readyState)t();else{let s,i;const r=()=>{e.removeEventListener("open",s),e.removeEventListener("error",i)};s=()=>{r(),t()},i=()=>{r(),n()},e.addEventListener("open",s),e.addEventListener("error",i)}}))}const d=""!==document.createElement("video").canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"'),u={usedtx:1,stereo:0,"sprop-stereo":0},p={iceServers:[{urls:"stun:stun1.l.google.com:19302"},{urls:"stun:stun2.l.google.com:19302"}]};class h{constructor(){this.room=null,this.clientId=null,this.joinToken=null,this.serverUrl=null,this.webRtcOptions={},this.peerConnectionConfig=null,this.ws=null,this.session=null,this.reliableTransport="datachannel",this.unreliableTransport="datachannel",this.initialReconnectionDelay=1e3*Math.random(),this.reconnectionDelay=this.initialReconnectionDelay,this.reconnectionTimeout=null,this.maxReconnectionAttempts=10,this.reconnectionAttempts=0,this.publisher=null,this.occupantIds=[],this.occupants={},this.mediaStreams={},this.localMediaStream=null,this.pendingMediaRequests=new Map,this.pendingOccupants=new Set,this.availableOccupants=[],this.requestedOccupants=null,this.blockedClients=new Map,this.frozenUpdates=new Map,this.timeOffsets=[],this.serverTimeRequests=0,this.avgTimeOffset=0,this.onWebsocketOpen=this.onWebsocketOpen.bind(this),this.onWebsocketClose=this.onWebsocketClose.bind(this),this.onWebsocketMessage=this.onWebsocketMessage.bind(this),this.onDataChannelMessage=this.onDataChannelMessage.bind(this),this.onData=this.onData.bind(this)}setServerUrl(e){this.serverUrl=e}setApp(e){}setRoom(e){this.room=e}setJoinToken(e){this.joinToken=e}setClientId(e){this.clientId=e}setWebRtcOptions(e){this.webRtcOptions=e}setPeerConnectionConfig(e){this.peerConnectionConfig=e}setServerConnectListeners(e,t){this.connectSuccess=e,this.connectFailure=t}setRoomOccupantListener(e){this.onOccupantsChanged=e}setDataChannelListeners(e,t,n){this.onOccupantConnected=e,this.onOccupantDisconnected=t,this.onOccupantMessage=n}setReconnectionListeners(e,t,n){this.onReconnecting=e,this.onReconnected=t,this.onReconnectionError=n}setEventLoops(e){this.loops=e}connect(){r(`connecting to ${this.serverUrl}`);const e=new Promise(((e,t)=>{this.ws=new WebSocket(this.serverUrl,"janus-protocol"),this.session=new s.JanusSession(this.ws.send.bind(this.ws),{timeoutMs:4e4}),this.ws.addEventListener("close",this.onWebsocketClose),this.ws.addEventListener("message",this.onWebsocketMessage),this.wsOnOpen=()=>{this.ws.removeEventListener("open",this.wsOnOpen),this.onWebsocketOpen().then(e).catch(t)},this.ws.addEventListener("open",this.wsOnOpen)}));return Promise.all([e,this.updateTimeOffset()])}disconnect(){r("disconnecting"),clearTimeout(this.reconnectionTimeout),this.removeAllOccupants(),this.publisher&&(this.publisher.conn.close(),this.publisher=null),this.session&&(this.session.dispose(),this.session=null),this.ws&&(this.ws.removeEventListener("open",this.wsOnOpen),this.ws.removeEventListener("close",this.onWebsocketClose),this.ws.removeEventListener("message",this.onWebsocketMessage),this.ws.close(),this.ws=null),this.delayedReconnectTimeout&&(clearTimeout(this.delayedReconnectTimeout),this.delayedReconnectTimeout=null)}isDisconnected(){return null===this.ws}async onWebsocketOpen(){await this.session.create(),this.publisher=await this.createPublisher(),this.connectSuccess(this.clientId);for(let e=0;e<this.publisher.initialOccupants.length;e++){const t=this.publisher.initialOccupants[e];t!==this.clientId&&this.addAvailableOccupant(t)}this.syncOccupants()}onWebsocketClose(e){1e3!==e.code&&(console.warn("Janus websocket closed unexpectedly."),this.onReconnecting&&this.onReconnecting(this.reconnectionDelay),this.reconnectionTimeout=setTimeout((()=>this.reconnect()),this.reconnectionDelay))}reconnect(){this.disconnect(),this.connect().then((()=>{this.reconnectionDelay=this.initialReconnectionDelay,this.reconnectionAttempts=0,this.onReconnected&&this.onReconnected()})).catch((e=>{if(this.reconnectionDelay+=1e3,this.reconnectionAttempts++,this.reconnectionAttempts>this.maxReconnectionAttempts&&this.onReconnectionError)return this.onReconnectionError(new Error("Connection could not be reestablished, exceeded maximum number of reconnection attempts."));console.warn("Error during reconnect, retrying."),console.warn(e),this.onReconnecting&&this.onReconnecting(this.reconnectionDelay),this.reconnectionTimeout=setTimeout((()=>this.reconnect()),this.reconnectionDelay)}))}performDelayedReconnect(){this.delayedReconnectTimeout&&clearTimeout(this.delayedReconnectTimeout),this.delayedReconnectTimeout=setTimeout((()=>{this.delayedReconnectTimeout=null,this.reconnect()}),1e4)}onWebsocketMessage(e){this.session.receive(JSON.parse(e.data))}addAvailableOccupant(e){-1===this.availableOccupants.indexOf(e)&&this.availableOccupants.push(e)}removeAvailableOccupant(e){const t=this.availableOccupants.indexOf(e);-1!==t&&this.availableOccupants.splice(t,1)}syncOccupants(e){if(e&&(this.requestedOccupants=e),this.requestedOccupants){for(let e=0;e<this.requestedOccupants.length;e++){const t=this.requestedOccupants[e];this.occupants[t]||-1===this.availableOccupants.indexOf(t)||this.pendingOccupants.has(t)||this.addOccupant(t)}for(let e=0;e<this.availableOccupants.length;e++){const t=this.availableOccupants[e];this.occupants[t]&&-1===this.requestedOccupants.indexOf(t)&&this.removeOccupant(t)}this.onOccupantsChanged(this.occupants)}}async addOccupant(e){this.pendingOccupants.add(e),this.availableOccupants.length>5&&await(0,5e3,new Promise((e=>{const t=5e3*Math.random()+0;setTimeout(e,t)})));const t=await this.createSubscriber(e);t&&(this.pendingOccupants.has(e)?(this.pendingOccupants.delete(e),this.occupantIds.push(e),this.occupants[e]=t,this.setMediaStream(e,t.mediaStream),this.onOccupantConnected(e)):t.conn.close())}removeAllOccupants(){this.pendingOccupants.clear();for(let e=this.occupantIds.length-1;e>=0;e--)this.removeOccupant(this.occupantIds[e])}removeOccupant(e){if(this.pendingOccupants.delete(e),this.occupants[e]&&(this.occupants[e].conn.close(),delete this.occupants[e],this.occupantIds.splice(this.occupantIds.indexOf(e),1)),this.mediaStreams[e]&&delete this.mediaStreams[e],this.pendingMediaRequests.has(e)){const t="The user disconnected before the media stream was resolved.";this.pendingMediaRequests.get(e).audio.reject(t),this.pendingMediaRequests.get(e).video.reject(t),this.pendingMediaRequests.delete(e)}this.onOccupantDisconnected(e)}associate(e,t){e.addEventListener("icecandidate",(e=>{t.sendTrickle(e.candidate||null).catch((e=>a("Error trickling ICE: %o",e)))})),e.addEventListener("iceconnectionstatechange",(t=>{"connected"===e.iceConnectionState&&console.log("ICE state changed to connected"),"disconnected"===e.iceConnectionState&&console.warn("ICE state changed to disconnected"),"failed"===e.iceConnectionState&&(console.warn("ICE failure detected. Reconnecting in 10s."),this.performDelayedReconnect())})),e.addEventListener("negotiationneeded",c((n=>{r("Sending new offer for handle: %o",t);var s=e.createOffer().then(this.configurePublisherSdp).then(this.fixSafariIceUFrag),i=s.then((t=>e.setLocalDescription(t))),o=s;return o=o.then(this.fixSafariIceUFrag).then((e=>t.sendJsep(e))).then((t=>e.setRemoteDescription(t.jsep))),Promise.all([i,o]).catch((e=>a("Error negotiating offer: %o",e)))}))),t.on("event",c((n=>{var s=n.jsep;if(s&&"offer"==s.type){r("Accepting new offer for handle: %o",t);var i=e.setRemoteDescription(this.configureSubscriberSdp(s)).then((t=>e.createAnswer())).then(this.fixSafariIceUFrag),o=i.then((t=>e.setLocalDescription(t))),c=i.then((e=>t.sendJsep(e)));return Promise.all([o,c]).catch((e=>a("Error negotiating answer: %o",e)))}return null})))}async createPublisher(){var e=new s.JanusPluginHandle(this.session),t=new RTCPeerConnection(this.peerConnectionConfig||p);r("pub waiting for sfu"),await e.attach("janus.plugin.sfu",this.loops&&this.clientId?parseInt(this.clientId)%this.loops:void 0),this.associate(t,e),r("pub waiting for data channels & webrtcup");var n=new Promise((t=>e.on("webrtcup",t))),i=t.createDataChannel("reliable",{ordered:!0}),a=t.createDataChannel("unreliable",{ordered:!1,maxRetransmits:0});i.addEventListener("message",(e=>this.onDataChannelMessage(e,"janus-reliable"))),a.addEventListener("message",(e=>this.onDataChannelMessage(e,"janus-unreliable"))),await n,await l(i),await l(a),this.localMediaStream&&this.localMediaStream.getTracks().forEach((e=>{t.addTrack(e,this.localMediaStream)})),e.on("event",(e=>{var t=e.plugindata.data;if("join"==t.event&&t.room_id==this.room){if(this.delayedReconnectTimeout)return;this.addAvailableOccupant(t.user_id),this.syncOccupants()}else"leave"==t.event&&t.room_id==this.room?(this.removeAvailableOccupant(t.user_id),this.removeOccupant(t.user_id)):"blocked"==t.event?document.body.dispatchEvent(new CustomEvent("blocked",{detail:{clientId:t.by}})):"unblocked"==t.event?document.body.dispatchEvent(new CustomEvent("unblocked",{detail:{clientId:t.by}})):"data"===t.event&&this.onData(JSON.parse(t.body),"janus-event")})),r("pub waiting for join");var o=await this.sendJoin(e,{notifications:!0,data:!0});if(!o.plugindata.data.success){const e=o.plugindata.data.error;throw console.error(e),t.close(),e}var c=o.plugindata.data.response.users[this.room]||[];return c.includes(this.clientId)&&(console.warn("Janus still has previous session for this client. Reconnecting in 10s."),this.performDelayedReconnect()),r("publisher ready"),{handle:e,initialOccupants:c,reliableChannel:i,unreliableChannel:a,conn:t}}configurePublisherSdp(e){return e.sdp=e.sdp.replace(/a=fmtp:(109|111).*\r\n/g,((e,t)=>{const n=Object.assign(i.parseFmtp(e),u);return i.writeFmtp({payloadType:t,parameters:n})})),e}configureSubscriberSdp(e){return d||-1!==navigator.userAgent.indexOf("HeadlessChrome")&&(e.sdp=e.sdp.replace(/m=video[^]*m=/,"m=")),-1===navigator.userAgent.indexOf("Android")?e.sdp=e.sdp.replace("a=rtcp-fb:107 goog-remb\r\n","a=rtcp-fb:107 goog-remb\r\na=rtcp-fb:107 transport-cc\r\na=fmtp:107 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\n"):e.sdp=e.sdp.replace("a=rtcp-fb:107 goog-remb\r\n","a=rtcp-fb:107 goog-remb\r\na=rtcp-fb:107 transport-cc\r\na=fmtp:107 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f\r\n"),e}async fixSafariIceUFrag(e){return e.sdp=e.sdp.replace(/[^\r]\na=ice-ufrag/g,"\r\na=ice-ufrag"),e}async createSubscriber(e,t=5){if(-1===this.availableOccupants.indexOf(e))return console.warn(e+": cancelled occupant connection, occupant left before subscription negotation."),null;var n=new s.JanusPluginHandle(this.session),i=new RTCPeerConnection(this.peerConnectionConfig||p);if(r(e+": sub waiting for sfu"),await n.attach("janus.plugin.sfu",this.loops?parseInt(e)%this.loops:void 0),this.associate(i,n),r(e+": sub waiting for join"),-1===this.availableOccupants.indexOf(e))return i.close(),console.warn(e+": cancelled occupant connection, occupant left after attach"),null;let a=!1;const c=new Promise((t=>{const s=setInterval((()=>{-1===this.availableOccupants.indexOf(e)&&(clearInterval(s),t())}),1e3),i=setTimeout((()=>{clearInterval(s),a=!0,t()}),15e3);n.on("webrtcup",(()=>{clearTimeout(i),clearInterval(s),t()}))}));if(await this.sendJoin(n,{media:e}),-1===this.availableOccupants.indexOf(e))return i.close(),console.warn(e+": cancelled occupant connection, occupant left after join"),null;if(r(e+": sub waiting for webrtcup"),await c,-1===this.availableOccupants.indexOf(e))return i.close(),console.warn(e+": cancel occupant connection, occupant left during or after webrtcup"),null;if(a)return i.close(),t>0?(console.warn(e+": webrtc up timed out, retrying"),this.createSubscriber(e,t-1)):(console.warn(e+": webrtc up timed out"),null);o&&!this._iOSHackDelayedInitialPeer&&(await new Promise((e=>setTimeout(e,3e3))),this._iOSHackDelayedInitialPeer=!0);var l=new MediaStream;return i.getReceivers().forEach((e=>{e.track&&l.addTrack(e.track)})),0===l.getTracks().length&&(l=null),r(e+": subscriber ready"),{handle:n,mediaStream:l,conn:i}}sendJoin(e,t){return e.sendMessage({kind:"join",room_id:this.room,user_id:this.clientId,subscribe:t,token:this.joinToken})}toggleFreeze(){this.frozen?this.unfreeze():this.freeze()}freeze(){this.frozen=!0}unfreeze(){this.frozen=!1,this.flushPendingUpdates()}dataForUpdateMultiMessage(e,t){for(let n=0,s=t.data.d.length;n<s;n++){const s=t.data.d[n];if(s.networkId===e)return s}return null}getPendingData(e,t){if(!t)return null;let n="um"===t.dataType?this.dataForUpdateMultiMessage(e,t):t.data;return n.owner&&!this.occupants[n.owner]||n.owner&&this.blockedClients.has(n.owner)?null:n}getPendingDataForNetworkId(e){return this.getPendingData(e,this.frozenUpdates.get(e))}flushPendingUpdates(){for(const[e,t]of this.frozenUpdates){let n=this.getPendingData(e,t);if(!n)continue;const s="um"===t.dataType?"u":t.dataType;this.onOccupantMessage(null,s,n,t.source)}this.frozenUpdates.clear()}storeMessage(e){if("um"===e.dataType)for(let t=0,n=e.data.d.length;t<n;t++)this.storeSingleMessage(e,t);else this.storeSingleMessage(e)}storeSingleMessage(e,t){const n=void 0!==t?e.data.d[t]:e.data,s=e.dataType,i=(e.source,n.networkId);if(this.frozenUpdates.has(i)){const t=this.frozenUpdates.get(i),r="um"===t.dataType?this.dataForUpdateMultiMessage(i,t):t.data,a=n.lastOwnerTime<r.lastOwnerTime,o=n.lastOwnerTime===r.lastOwnerTime;if(a||o&&r.owner>n.owner)return;"r"===s?r&&r.isFirstSync?this.frozenUpdates.delete(i):this.frozenUpdates.set(i,e):r.components&&n.components&&Object.assign(r.components,n.components)}else this.frozenUpdates.set(i,e)}onDataChannelMessage(e,t){this.onData(JSON.parse(e.data),t)}onData(e,t){r.enabled&&r(`DC in: ${e}`),e.dataType&&(e.source=t,this.frozen?this.storeMessage(e):this.onOccupantMessage(null,e.dataType,e.data,e.source))}shouldStartConnectionTo(e){return!0}startStreamConnection(e){}closeStreamConnection(e){}getConnectStatus(e){return this.occupants[e]?NAF.adapters.IS_CONNECTED:NAF.adapters.NOT_CONNECTED}async updateTimeOffset(){if(this.isDisconnected())return;const e=Date.now(),t=await fetch(document.location.href,{method:"HEAD",cache:"no-cache"}),n=new Date(t.headers.get("Date")).getTime()+500,s=Date.now(),i=n+(s-e)/2-s;this.serverTimeRequests++,this.serverTimeRequests<=10?this.timeOffsets.push(i):this.timeOffsets[this.serverTimeRequests%10]=i,this.avgTimeOffset=this.timeOffsets.reduce(((e,t)=>e+t),0)/this.timeOffsets.length,this.serverTimeRequests>10?(r(`new server time offset: ${this.avgTimeOffset}ms`),setTimeout((()=>this.updateTimeOffset()),3e5)):this.updateTimeOffset()}getServerTime(){return Date.now()+this.avgTimeOffset}getMediaStream(e,t="audio"){if(this.mediaStreams[e])return r(`Already had ${t} for ${e}`),Promise.resolve(this.mediaStreams[e][t]);if(r(`Waiting on ${t} for ${e}`),!this.pendingMediaRequests.has(e)){this.pendingMediaRequests.set(e,{});const t=new Promise(((t,n)=>{this.pendingMediaRequests.get(e).audio={resolve:t,reject:n}})),n=new Promise(((t,n)=>{this.pendingMediaRequests.get(e).video={resolve:t,reject:n}}));this.pendingMediaRequests.get(e).audio.promise=t,this.pendingMediaRequests.get(e).video.promise=n,t.catch((t=>console.warn(`${e} getMediaStream Audio Error`,t))),n.catch((t=>console.warn(`${e} getMediaStream Video Error`,t)))}return this.pendingMediaRequests.get(e)[t].promise}setMediaStream(e,t){const n=new MediaStream;try{t.getAudioTracks().forEach((e=>n.addTrack(e)))}catch(t){console.warn(`${e} setMediaStream Audio Error`,t)}const s=new MediaStream;try{t.getVideoTracks().forEach((e=>s.addTrack(e)))}catch(t){console.warn(`${e} setMediaStream Video Error`,t)}this.mediaStreams[e]={audio:n,video:s},this.pendingMediaRequests.has(e)&&(this.pendingMediaRequests.get(e).audio.resolve(n),this.pendingMediaRequests.get(e).video.resolve(s))}async setLocalMediaStream(e){if(this.publisher&&this.publisher.conn){const t=this.publisher.conn.getSenders(),n=[],s=e.getTracks();for(let i=0;i<s.length;i++){const r=s[i],a=t.find((e=>null!=e.track&&e.track.kind==r.kind));null!=a?(a.replaceTrack?(await a.replaceTrack(r),"video"===r.kind&&r.enabled&&navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&(r.enabled=!1,setTimeout((()=>r.enabled=!0),1e3))):(e.removeTrack(a.track),e.addTrack(r)),n.push(a)):n.push(this.publisher.conn.addTrack(r,e))}t.forEach((e=>{n.includes(e)||(e.track.enabled=!1)}))}this.localMediaStream=e,this.setMediaStream(this.clientId,e)}enableMicrophone(e){this.publisher&&this.publisher.conn&&this.publisher.conn.getSenders().forEach((t=>{"audio"==t.track.kind&&(t.track.enabled=e)}))}sendData(e,t,n){if(this.publisher)switch(this.unreliableTransport){case"websocket":1===this.ws.readyState&&this.publisher.handle.sendMessage({kind:"data",body:JSON.stringify({dataType:t,data:n}),whom:e});break;case"datachannel":"open"===this.publisher.unreliableChannel.readyState&&this.publisher.unreliableChannel.send(JSON.stringify({clientId:e,dataType:t,data:n}));break;default:this.unreliableTransport(e,t,n)}else console.warn("sendData called without a publisher")}sendDataGuaranteed(e,t,n){if(this.publisher)switch(this.reliableTransport){case"websocket":1===this.ws.readyState&&this.publisher.handle.sendMessage({kind:"data",body:JSON.stringify({dataType:t,data:n}),whom:e});break;case"datachannel":"open"===this.publisher.reliableChannel.readyState&&this.publisher.reliableChannel.send(JSON.stringify({clientId:e,dataType:t,data:n}));break;default:this.reliableTransport(e,t,n)}else console.warn("sendDataGuaranteed called without a publisher")}broadcastData(e,t){if(this.publisher)switch(this.unreliableTransport){case"websocket":1===this.ws.readyState&&this.publisher.handle.sendMessage({kind:"data",body:JSON.stringify({dataType:e,data:t})});break;case"datachannel":"open"===this.publisher.unreliableChannel.readyState&&this.publisher.unreliableChannel.send(JSON.stringify({dataType:e,data:t}));break;default:this.unreliableTransport(void 0,e,t)}else console.warn("broadcastData called without a publisher")}broadcastDataGuaranteed(e,t){if(this.publisher)switch(this.reliableTransport){case"websocket":1===this.ws.readyState&&this.publisher.handle.sendMessage({kind:"data",body:JSON.stringify({dataType:e,data:t})});break;case"datachannel":"open"===this.publisher.reliableChannel.readyState&&this.publisher.reliableChannel.send(JSON.stringify({dataType:e,data:t}));break;default:this.reliableTransport(void 0,e,t)}else console.warn("broadcastDataGuaranteed called without a publisher")}kick(e,t){return this.publisher.handle.sendMessage({kind:"kick",room_id:this.room,user_id:e,token:t}).then((()=>{document.body.dispatchEvent(new CustomEvent("kicked",{detail:{clientId:e}}))}))}block(e){return this.publisher.handle.sendMessage({kind:"block",whom:e}).then((()=>{this.blockedClients.set(e,!0),document.body.dispatchEvent(new CustomEvent("blocked",{detail:{clientId:e}}))}))}unblock(e){return this.publisher.handle.sendMessage({kind:"unblock",whom:e}).then((()=>{this.blockedClients.delete(e),document.body.dispatchEvent(new CustomEvent("unblocked",{detail:{clientId:e}}))}))}}NAF.adapters.register("janus",h),e.exports=h},833:(e,t,n)=>{t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let s=0,i=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(s++,"%c"===e&&(i=s))})),t.splice(i,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch(e){}},t.load=function(){let e;try{e=t.storage.getItem("debug")}catch(e){}return!e&&"undefined"!=typeof process&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},t.storage=function(){try{return localStorage}catch(e){}}(),t.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=n(736)(t);const{formatters:s}=e.exports;s.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}},736:(e,t,n)=>{e.exports=function(e){function t(e){let n,i,r,a=null;function o(...e){if(!o.enabled)return;const s=o,i=Number(new Date),r=i-(n||i);s.diff=r,s.prev=n,s.curr=i,n=i,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let a=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((n,i)=>{if("%%"===n)return"%";a++;const r=t.formatters[i];if("function"==typeof r){const t=e[a];n=r.call(s,t),e.splice(a,1),a--}return n})),t.formatArgs.call(s,e),(s.log||t.log).apply(s,e)}return o.namespace=e,o.useColors=t.useColors(),o.color=t.selectColor(e),o.extend=s,o.destroy=t.destroy,Object.defineProperty(o,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==a?a:(i!==t.namespaces&&(i=t.namespaces,r=t.enabled(e)),r),set:e=>{a=e}}),"function"==typeof t.init&&t.init(o),o}function s(e,n){const s=t(this.namespace+(void 0===n?":":n)+e);return s.log=this.log,s}function i(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names.map(i),...t.skips.map(i).map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){let n;t.save(e),t.namespaces=e,t.names=[],t.skips=[];const s=("string"==typeof e?e:"").split(/[\s,]+/),i=s.length;for(n=0;n<i;n++)s[n]&&("-"===(e=s[n].replace(/\*/g,".*?"))[0]?t.skips.push(new RegExp("^"+e.slice(1)+"$")):t.names.push(new RegExp("^"+e+"$")))},t.enabled=function(e){if("*"===e[e.length-1])return!0;let n,s;for(n=0,s=t.skips.length;n<s;n++)if(t.skips[n].test(e))return!1;for(n=0,s=t.names.length;n<s;n++)if(t.names[n].test(e))return!0;return!1},t.humanize=n(585),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((n=>{t[n]=e[n]})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t}},585:e=>{var t=1e3,n=60*t,s=60*n,i=24*s;function r(e,t,n,s){var i=t>=1.5*n;return Math.round(e/n)+" "+s+(i?"s":"")}e.exports=function(e,a){a=a||{};var o,c,l=typeof e;if("string"===l&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var r=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(r){var a=parseFloat(r[1]);switch((r[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*a;case"weeks":case"week":case"w":return 6048e5*a;case"days":case"day":case"d":return a*i;case"hours":case"hour":case"hrs":case"hr":case"h":return a*s;case"minutes":case"minute":case"mins":case"min":case"m":return a*n;case"seconds":case"second":case"secs":case"sec":case"s":return a*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}}}(e);if("number"===l&&isFinite(e))return a.long?(o=e,(c=Math.abs(o))>=i?r(o,c,i,"day"):c>=s?r(o,c,s,"hour"):c>=n?r(o,c,n,"minute"):c>=t?r(o,c,t,"second"):o+" ms"):function(e){var r=Math.abs(e);return r>=i?Math.round(e/i)+"d":r>=s?Math.round(e/s)+"h":r>=n?Math.round(e/n)+"m":r>=t?Math.round(e/t)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},963:e=>{"use strict";const t={generateIdentifier:function(){return Math.random().toString(36).substring(2,12)}};t.localCName=t.generateIdentifier(),t.splitLines=function(e){return e.trim().split("\n").map((e=>e.trim()))},t.splitSections=function(e){return e.split("\nm=").map(((e,t)=>(t>0?"m="+e:e).trim()+"\r\n"))},t.getDescription=function(e){const n=t.splitSections(e);return n&&n[0]},t.getMediaSections=function(e){const n=t.splitSections(e);return n.shift(),n},t.matchPrefix=function(e,n){return t.splitLines(e).filter((e=>0===e.indexOf(n)))},t.parseCandidate=function(e){let t;t=0===e.indexOf("a=candidate:")?e.substring(12).split(" "):e.substring(10).split(" ");const n={foundation:t[0],component:{1:"rtp",2:"rtcp"}[t[1]]||t[1],protocol:t[2].toLowerCase(),priority:parseInt(t[3],10),ip:t[4],address:t[4],port:parseInt(t[5],10),type:t[7]};for(let e=8;e<t.length;e+=2)switch(t[e]){case"raddr":n.relatedAddress=t[e+1];break;case"rport":n.relatedPort=parseInt(t[e+1],10);break;case"tcptype":n.tcpType=t[e+1];break;case"ufrag":n.ufrag=t[e+1],n.usernameFragment=t[e+1];break;default:void 0===n[t[e]]&&(n[t[e]]=t[e+1])}return n},t.writeCandidate=function(e){const t=[];t.push(e.foundation);const n=e.component;"rtp"===n?t.push(1):"rtcp"===n?t.push(2):t.push(n),t.push(e.protocol.toUpperCase()),t.push(e.priority),t.push(e.address||e.ip),t.push(e.port);const s=e.type;return t.push("typ"),t.push(s),"host"!==s&&e.relatedAddress&&e.relatedPort&&(t.push("raddr"),t.push(e.relatedAddress),t.push("rport"),t.push(e.relatedPort)),e.tcpType&&"tcp"===e.protocol.toLowerCase()&&(t.push("tcptype"),t.push(e.tcpType)),(e.usernameFragment||e.ufrag)&&(t.push("ufrag"),t.push(e.usernameFragment||e.ufrag)),"candidate:"+t.join(" ")},t.parseIceOptions=function(e){return e.substring(14).split(" ")},t.parseRtpMap=function(e){let t=e.substring(9).split(" ");const n={payloadType:parseInt(t.shift(),10)};return t=t[0].split("/"),n.name=t[0],n.clockRate=parseInt(t[1],10),n.channels=3===t.length?parseInt(t[2],10):1,n.numChannels=n.channels,n},t.writeRtpMap=function(e){let t=e.payloadType;void 0!==e.preferredPayloadType&&(t=e.preferredPayloadType);const n=e.channels||e.numChannels||1;return"a=rtpmap:"+t+" "+e.name+"/"+e.clockRate+(1!==n?"/"+n:"")+"\r\n"},t.parseExtmap=function(e){const t=e.substring(9).split(" ");return{id:parseInt(t[0],10),direction:t[0].indexOf("/")>0?t[0].split("/")[1]:"sendrecv",uri:t[1],attributes:t.slice(2).join(" ")}},t.writeExtmap=function(e){return"a=extmap:"+(e.id||e.preferredId)+(e.direction&&"sendrecv"!==e.direction?"/"+e.direction:"")+" "+e.uri+(e.attributes?" "+e.attributes:"")+"\r\n"},t.parseFmtp=function(e){const t={};let n;const s=e.substring(e.indexOf(" ")+1).split(";");for(let e=0;e<s.length;e++)n=s[e].trim().split("="),t[n[0].trim()]=n[1];return t},t.writeFmtp=function(e){let t="",n=e.payloadType;if(void 0!==e.preferredPayloadType&&(n=e.preferredPayloadType),e.parameters&&Object.keys(e.parameters).length){const s=[];Object.keys(e.parameters).forEach((t=>{void 0!==e.parameters[t]?s.push(t+"="+e.parameters[t]):s.push(t)})),t+="a=fmtp:"+n+" "+s.join(";")+"\r\n"}return t},t.parseRtcpFb=function(e){const t=e.substring(e.indexOf(" ")+1).split(" ");return{type:t.shift(),parameter:t.join(" ")}},t.writeRtcpFb=function(e){let t="",n=e.payloadType;return void 0!==e.preferredPayloadType&&(n=e.preferredPayloadType),e.rtcpFeedback&&e.rtcpFeedback.length&&e.rtcpFeedback.forEach((e=>{t+="a=rtcp-fb:"+n+" "+e.type+(e.parameter&&e.parameter.length?" "+e.parameter:"")+"\r\n"})),t},t.parseSsrcMedia=function(e){const t=e.indexOf(" "),n={ssrc:parseInt(e.substring(7,t),10)},s=e.indexOf(":",t);return s>-1?(n.attribute=e.substring(t+1,s),n.value=e.substring(s+1)):n.attribute=e.substring(t+1),n},t.parseSsrcGroup=function(e){const t=e.substring(13).split(" ");return{semantics:t.shift(),ssrcs:t.map((e=>parseInt(e,10)))}},t.getMid=function(e){const n=t.matchPrefix(e,"a=mid:")[0];if(n)return n.substring(6)},t.parseFingerprint=function(e){const t=e.substring(14).split(" ");return{algorithm:t[0].toLowerCase(),value:t[1].toUpperCase()}},t.getDtlsParameters=function(e,n){return{role:"auto",fingerprints:t.matchPrefix(e+n,"a=fingerprint:").map(t.parseFingerprint)}},t.writeDtlsParameters=function(e,t){let n="a=setup:"+t+"\r\n";return e.fingerprints.forEach((e=>{n+="a=fingerprint:"+e.algorithm+" "+e.value+"\r\n"})),n},t.parseCryptoLine=function(e){const t=e.substring(9).split(" ");return{tag:parseInt(t[0],10),cryptoSuite:t[1],keyParams:t[2],sessionParams:t.slice(3)}},t.writeCryptoLine=function(e){return"a=crypto:"+e.tag+" "+e.cryptoSuite+" "+("object"==typeof e.keyParams?t.writeCryptoKeyParams(e.keyParams):e.keyParams)+(e.sessionParams?" "+e.sessionParams.join(" "):"")+"\r\n"},t.parseCryptoKeyParams=function(e){if(0!==e.indexOf("inline:"))return null;const t=e.substring(7).split("|");return{keyMethod:"inline",keySalt:t[0],lifeTime:t[1],mkiValue:t[2]?t[2].split(":")[0]:void 0,mkiLength:t[2]?t[2].split(":")[1]:void 0}},t.writeCryptoKeyParams=function(e){return e.keyMethod+":"+e.keySalt+(e.lifeTime?"|"+e.lifeTime:"")+(e.mkiValue&&e.mkiLength?"|"+e.mkiValue+":"+e.mkiLength:"")},t.getCryptoParameters=function(e,n){return t.matchPrefix(e+n,"a=crypto:").map(t.parseCryptoLine)},t.getIceParameters=function(e,n){const s=t.matchPrefix(e+n,"a=ice-ufrag:")[0],i=t.matchPrefix(e+n,"a=ice-pwd:")[0];return s&&i?{usernameFragment:s.substring(12),password:i.substring(10)}:null},t.writeIceParameters=function(e){let t="a=ice-ufrag:"+e.usernameFragment+"\r\na=ice-pwd:"+e.password+"\r\n";return e.iceLite&&(t+="a=ice-lite\r\n"),t},t.parseRtpParameters=function(e){const n={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},s=t.splitLines(e)[0].split(" ");n.profile=s[2];for(let i=3;i<s.length;i++){const r=s[i],a=t.matchPrefix(e,"a=rtpmap:"+r+" ")[0];if(a){const s=t.parseRtpMap(a),i=t.matchPrefix(e,"a=fmtp:"+r+" ");switch(s.parameters=i.length?t.parseFmtp(i[0]):{},s.rtcpFeedback=t.matchPrefix(e,"a=rtcp-fb:"+r+" ").map(t.parseRtcpFb),n.codecs.push(s),s.name.toUpperCase()){case"RED":case"ULPFEC":n.fecMechanisms.push(s.name.toUpperCase())}}}t.matchPrefix(e,"a=extmap:").forEach((e=>{n.headerExtensions.push(t.parseExtmap(e))}));const i=t.matchPrefix(e,"a=rtcp-fb:* ").map(t.parseRtcpFb);return n.codecs.forEach((e=>{i.forEach((t=>{e.rtcpFeedback.find((e=>e.type===t.type&&e.parameter===t.parameter))||e.rtcpFeedback.push(t)}))})),n},t.writeRtpDescription=function(e,n){let s="";s+="m="+e+" ",s+=n.codecs.length>0?"9":"0",s+=" "+(n.profile||"UDP/TLS/RTP/SAVPF")+" ",s+=n.codecs.map((e=>void 0!==e.preferredPayloadType?e.preferredPayloadType:e.payloadType)).join(" ")+"\r\n",s+="c=IN IP4 0.0.0.0\r\n",s+="a=rtcp:9 IN IP4 0.0.0.0\r\n",n.codecs.forEach((e=>{s+=t.writeRtpMap(e),s+=t.writeFmtp(e),s+=t.writeRtcpFb(e)}));let i=0;return n.codecs.forEach((e=>{e.maxptime>i&&(i=e.maxptime)})),i>0&&(s+="a=maxptime:"+i+"\r\n"),n.headerExtensions&&n.headerExtensions.forEach((e=>{s+=t.writeExtmap(e)})),s},t.parseRtpEncodingParameters=function(e){const n=[],s=t.parseRtpParameters(e),i=-1!==s.fecMechanisms.indexOf("RED"),r=-1!==s.fecMechanisms.indexOf("ULPFEC"),a=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"cname"===e.attribute)),o=a.length>0&&a[0].ssrc;let c;const l=t.matchPrefix(e,"a=ssrc-group:FID").map((e=>e.substring(17).split(" ").map((e=>parseInt(e,10)))));l.length>0&&l[0].length>1&&l[0][0]===o&&(c=l[0][1]),s.codecs.forEach((e=>{if("RTX"===e.name.toUpperCase()&&e.parameters.apt){let t={ssrc:o,codecPayloadType:parseInt(e.parameters.apt,10)};o&&c&&(t.rtx={ssrc:c}),n.push(t),i&&(t=JSON.parse(JSON.stringify(t)),t.fec={ssrc:o,mechanism:r?"red+ulpfec":"red"},n.push(t))}})),0===n.length&&o&&n.push({ssrc:o});let d=t.matchPrefix(e,"b=");return d.length&&(d=0===d[0].indexOf("b=TIAS:")?parseInt(d[0].substring(7),10):0===d[0].indexOf("b=AS:")?1e3*parseInt(d[0].substring(5),10)*.95-16e3:void 0,n.forEach((e=>{e.maxBitrate=d}))),n},t.parseRtcpParameters=function(e){const n={},s=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"cname"===e.attribute))[0];s&&(n.cname=s.value,n.ssrc=s.ssrc);const i=t.matchPrefix(e,"a=rtcp-rsize");n.reducedSize=i.length>0,n.compound=0===i.length;const r=t.matchPrefix(e,"a=rtcp-mux");return n.mux=r.length>0,n},t.writeRtcpParameters=function(e){let t="";return e.reducedSize&&(t+="a=rtcp-rsize\r\n"),e.mux&&(t+="a=rtcp-mux\r\n"),void 0!==e.ssrc&&e.cname&&(t+="a=ssrc:"+e.ssrc+" cname:"+e.cname+"\r\n"),t},t.parseMsid=function(e){let n;const s=t.matchPrefix(e,"a=msid:");if(1===s.length)return n=s[0].substring(7).split(" "),{stream:n[0],track:n[1]};const i=t.matchPrefix(e,"a=ssrc:").map((e=>t.parseSsrcMedia(e))).filter((e=>"msid"===e.attribute));return i.length>0?(n=i[0].value.split(" "),{stream:n[0],track:n[1]}):void 0},t.parseSctpDescription=function(e){const n=t.parseMLine(e),s=t.matchPrefix(e,"a=max-message-size:");let i;s.length>0&&(i=parseInt(s[0].substring(19),10)),isNaN(i)&&(i=65536);const r=t.matchPrefix(e,"a=sctp-port:");if(r.length>0)return{port:parseInt(r[0].substring(12),10),protocol:n.fmt,maxMessageSize:i};const a=t.matchPrefix(e,"a=sctpmap:");if(a.length>0){const e=a[0].substring(10).split(" ");return{port:parseInt(e[0],10),protocol:e[1],maxMessageSize:i}}},t.writeSctpDescription=function(e,t){let n=[];return n="DTLS/SCTP"!==e.protocol?["m="+e.kind+" 9 "+e.protocol+" "+t.protocol+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctp-port:"+t.port+"\r\n"]:["m="+e.kind+" 9 "+e.protocol+" "+t.port+"\r\n","c=IN IP4 0.0.0.0\r\n","a=sctpmap:"+t.port+" "+t.protocol+" 65535\r\n"],void 0!==t.maxMessageSize&&n.push("a=max-message-size:"+t.maxMessageSize+"\r\n"),n.join("")},t.generateSessionId=function(){return Math.random().toString().substr(2,22)},t.writeSessionBoilerplate=function(e,n,s){let i;const r=void 0!==n?n:2;return i=e||t.generateSessionId(),"v=0\r\no="+(s||"thisisadapterortc")+" "+i+" "+r+" IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n"},t.getDirection=function(e,n){const s=t.splitLines(e);for(let e=0;e<s.length;e++)switch(s[e]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return s[e].substring(2)}return n?t.getDirection(n):"sendrecv"},t.getKind=function(e){return t.splitLines(e)[0].split(" ")[0].substring(2)},t.isRejected=function(e){return"0"===e.split(" ",2)[1]},t.parseMLine=function(e){const n=t.splitLines(e)[0].substring(2).split(" ");return{kind:n[0],port:parseInt(n[1],10),protocol:n[2],fmt:n.slice(3).join(" ")}},t.parseOLine=function(e){const n=t.matchPrefix(e,"o=")[0].substring(2).split(" ");return{username:n[0],sessionId:n[1],sessionVersion:parseInt(n[2],10),netType:n[3],addressType:n[4],address:n[5]}},t.isValidSDP=function(e){if("string"!=typeof e||0===e.length)return!1;const n=t.splitLines(e);for(let e=0;e<n.length;e++)if(n[e].length<2||"="!==n[e].charAt(1))return!1;return!0},e.exports=t}},t={};!function n(s){var i=t[s];if(void 0!==i)return i.exports;var r=t[s]={exports:{}};return e[s](r,r.exports,n),r.exports}(497)})(); | ||
//# sourceMappingURL=naf-janus-adapter.min.js.map |
{ | ||
"name": "@networked-aframe/naf-janus-adapter", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "networked-aframe Janus network adapter", | ||
@@ -9,11 +9,9 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.22.5", | ||
"@babel/preset-env": "^7.22.5", | ||
"babel-loader": "^9.1.2", | ||
"eslint": "^8.43.0", | ||
"@babel/core": "^7.23.9", | ||
"babel-loader": "^9.1.3", | ||
"eslint": "^8.56.0", | ||
"np": "^8.0.4", | ||
"webpack": "^5.87.0", | ||
"webpack": "^5.90.2", | ||
"webpack-cli": "^5.1.4", | ||
"webpack-dev-server": "^4.15.1", | ||
"webpack-merge": "^5.9.0" | ||
"webpack-dev-server": "^5.0.2" | ||
}, | ||
@@ -20,0 +18,0 @@ "dependencies": { |
@@ -23,3 +23,3 @@ # Networked-AFrame Janus Adapter | ||
<script src="https://unpkg.com/networked-aframe@^0.11.0/dist/networked-aframe.min.js" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/gh/networked-aframe/naf-janus-adapter@4.1.0/dist/naf-janus-adapter.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/gh/networked-aframe/naf-janus-adapter@4.2.0/dist/naf-janus-adapter.min.js"></script> | ||
</head> | ||
@@ -88,6 +88,9 @@ <body> | ||
- Dev: `npm run start` | ||
- Dev: `npm start` | ||
- Build: `npm run build` | ||
- Release: `npm run release` | ||
For development on the same LAN with `npm start` and if you run the janus docker image locally, you can use the config | ||
`serverURL: wss://192.168.1.15:8080/janus;` (change the ip by yours of course). | ||
## Janus SFU deployment | ||
@@ -94,0 +97,0 @@ |
@@ -1048,6 +1048,10 @@ /* global NAF */ | ||
case "websocket": | ||
this.publisher.handle.sendMessage({ kind: "data", body: JSON.stringify({ dataType, data }), whom: clientId }); | ||
if (this.ws.readyState === 1) { // OPEN | ||
this.publisher.handle.sendMessage({ kind: "data", body: JSON.stringify({ dataType, data }), whom: clientId }); | ||
} | ||
break; | ||
case "datachannel": | ||
this.publisher.unreliableChannel.send(JSON.stringify({ clientId, dataType, data })); | ||
if (this.publisher.unreliableChannel.readyState === "open") { | ||
this.publisher.unreliableChannel.send(JSON.stringify({ clientId, dataType, data })); | ||
} | ||
break; | ||
@@ -1067,6 +1071,10 @@ default: | ||
case "websocket": | ||
this.publisher.handle.sendMessage({ kind: "data", body: JSON.stringify({ dataType, data }), whom: clientId }); | ||
if (this.ws.readyState === 1) { // OPEN | ||
this.publisher.handle.sendMessage({ kind: "data", body: JSON.stringify({ dataType, data }), whom: clientId }); | ||
} | ||
break; | ||
case "datachannel": | ||
this.publisher.reliableChannel.send(JSON.stringify({ clientId, dataType, data })); | ||
if (this.publisher.reliableChannel.readyState === "open") { | ||
this.publisher.reliableChannel.send(JSON.stringify({ clientId, dataType, data })); | ||
} | ||
break; | ||
@@ -1086,6 +1094,10 @@ default: | ||
case "websocket": | ||
this.publisher.handle.sendMessage({ kind: "data", body: JSON.stringify({ dataType, data }) }); | ||
if (this.ws.readyState === 1) { // OPEN | ||
this.publisher.handle.sendMessage({ kind: "data", body: JSON.stringify({ dataType, data }) }); | ||
} | ||
break; | ||
case "datachannel": | ||
this.publisher.unreliableChannel.send(JSON.stringify({ dataType, data })); | ||
if (this.publisher.unreliableChannel.readyState === "open") { | ||
this.publisher.unreliableChannel.send(JSON.stringify({ dataType, data })); | ||
} | ||
break; | ||
@@ -1105,6 +1117,10 @@ default: | ||
case "websocket": | ||
this.publisher.handle.sendMessage({ kind: "data", body: JSON.stringify({ dataType, data }) }); | ||
if (this.ws.readyState === 1) { // OPEN | ||
this.publisher.handle.sendMessage({ kind: "data", body: JSON.stringify({ dataType, data }) }); | ||
} | ||
break; | ||
case "datachannel": | ||
this.publisher.reliableChannel.send(JSON.stringify({ dataType, data })); | ||
if (this.publisher.reliableChannel.readyState === "open") { | ||
this.publisher.reliableChannel.send(JSON.stringify({ dataType, data })); | ||
} | ||
break; | ||
@@ -1111,0 +1127,0 @@ default: |
const path = require("path"); | ||
const { merge } = require("webpack-merge"); | ||
const common = require("./webpack.common"); | ||
module.exports = merge(common, { | ||
module.exports = { | ||
extends: ['webpack.common.js'], | ||
mode: "development", | ||
@@ -10,8 +9,15 @@ devtool: "inline-source-map", | ||
server: { | ||
type: 'https' | ||
type: "https", | ||
}, | ||
proxy: [ | ||
{ | ||
context: ["/janus"], | ||
target: "http://127.0.0.1:8188/janus", | ||
ws: true, | ||
}, | ||
], | ||
static: { | ||
directory: path.resolve(__dirname, "examples") | ||
} | ||
} | ||
}); | ||
directory: path.resolve(__dirname, "examples"), | ||
}, | ||
}, | ||
}; |
const path = require("path"); | ||
const { merge } = require("webpack-merge"); | ||
const common = require("./webpack.common"); | ||
module.exports = merge(common, { | ||
module.exports = { | ||
extends: ['webpack.common.js'], | ||
mode: "production", | ||
@@ -11,2 +10,2 @@ output: { | ||
devtool: "source-map" | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
7
98
947257
4075