vart=require("./bufferbuilder").BufferBuilder,e=require("./bufferbuilder").binaryFeatures,i={unpack:function(t){returnnewr(t).unpack()},pack:function(t){vare=newn;returne.pack(t),e.getBuffer()}};functionr(t){this.index=0,this.dataBuffer=t,this.dataView=newUint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}functionn(){this.bufferBuilder=newt}functionu(t){vare=t.charCodeAt(0);returne<=2047?"00":e<=65535?"000":e<=2097151?"0000":e<=67108863?"00000":"000000"}functiona(t){returnt.length>600?newBlob([t]).size:t.replace(/[^\u0000-\u007F]/g,u).length}module.exports=i,r.prototype.unpack=function(){vart,e=this.unpack_uint8();if(e<128)returne;if((224^e)<32)return(224^e)-32;if((t=160^e)<=15)returnthis.unpack_raw(t);if((t=176^e)<=15)returnthis.unpack_string(t);if((t=144^e)<=15)returnthis.unpack_array(t);if((t=128^e)<=15)returnthis.unpack_map(t);switch(e){case192:returnnull;case193:return;case194:return!1;case195:return!0;case202:returnthis.unpack_float();case203:returnthis.unpack_double();case204:returnthis.unpack_uint8();case205:returnthis.unpack_uint16();case206:returnthis.unpack_uint32();case207:returnthis.unpack_uint64();case208:returnthis.unpack_int8();case209:returnthis.unpack_int16();case210:returnthis.unpack_int32();case211:returnthis.unpack_int64();case212:case213:case214:case215:return;case216:returnt=this.unpack_uint16(),this.unpack_string(t);case217:returnt=this.unpack_uint32(),this.unpack_string(t);case218:returnt=this.unpack_uint16(),this.unpack_raw(t);case219:returnt=this.unpack_uint32(),this.unpack_raw(t);case220:returnt=this.unpack_uint16(),this.unpack_array(t);case221:returnt=this.unpack_uint32(),this.unpack_array(t);case222:returnt=this.unpack_uint16(),this.unpack_map(t);case223:returnt=this.unpack_uint32(),this.unpack_map(t)}},r.prototype.unpack_uint8=function(){vart=255&this.dataView[this.index];returnthis.index++,t},r.prototype.unpack_uint16=function(){vart=this.read(2),e=256*(255&t[0])+(255&t[1]);returnthis.index+=2,e},r.prototype.unpack_uint32=function(){vart=this.read(4),e=256*(256*(256*t[0]+t[1])+t[2])+t[3];returnthis.index+=4,e},r.prototype.unpack_uint64=function(){vart=this.read(8),e=256*(256*(256*(256*(256*(256*(256*t[0]+t[1])+t[2])+t[3])+t[4])+t[5])+t[6])+t[7];returnthis.index+=8,e},r.prototype.unpack_int8=function(){vart=this.unpack_uint8();returnt<128?t:t-256},r.prototype.unpack_int16=function(){vart=this.unpack_uint16();returnt<32768?t:t-65536},r.prototype.unpack_int32=function(){vart=this.unpack_uint32();returnt<Math.pow(2,31)?t:t-Math.pow(2,32)},r.prototype.unpack_int64=function(){vart=this.unpack_uint64();returnt<Math.pow(2,63)?t:t-Math.pow(2,64)},r.prototype.unpack_raw=function(t){if(this.length<this.index+t)thrownewError("BinaryPackFailure: index is out of range "+this.index+" "+t+" "+this.length);vare=this.dataBuffer.slice(this.index,this.index+t);returnthis.index+=t,e},r.prototype.unpack_string=function(t){for(vare,i,r=this.read(t),n=0,u="";n<t;)(e=r[n])<128?(u+=String.fromCharCode(e),n++):(192^e)<32?(i=(192^e)<<6|63&r[n+1],u+=String.fromCharCode(i),n+=2):(i=(15&e)<<12|(63&r[n+1])<<6|63&r[n+2],u+=String.fromCharCode(i),n+=3);returnthis.index+=t,u},r.prototype.unpack_array=function(t){for(vare=newArray(t),i=0;i<t;i++)e[i]=this.unpack();returne},r.prototype.unpack_map=function(t){for(vare={},i=0;i<t;i++){varr=this.unpack(),n=this.unpack();e[r]=n}returne},r.prototype.unpack_float=function(){vart=this.unpack_uint32(),e=(t>>23&255)-127;return(0===t>>31?1:-1)*(8388607&t|8388608)*Math.pow(2,e-23)},r.prototype.unpack_double=function(){vart=this.unpack_uint32(),e=this.unpack_uint32(),i=(t>>20&2047)-1023;return(0===t>>31?1:-1)*((1048575&t|1048576)*Math.pow(2,i-20)+e*Math.pow(2,i-52))},r.prototype.read=function(t){vare=this.index;if(e+t<=this.length)returnthis.dataView.subarray(e,e+t);thrownewError("BinaryPackFailure: read index out of range")},n.prototype.getBuffer=function(){returnthis.bufferBuilder.getBuffer()},n.prototype.pack=function(t){vari=typeoft;if("string"===i)this.pack_st
"use strict";functione(e,t,n){returntine?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}functiont(e){return(t="function"==typeofSymbol&&"symbol"==typeofSymbol.iterator?function(e){returntypeofe}:function(e){returne&&"function"==typeofSymbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeofe})(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.extractVersion=o,exports.wrapPeerConnectionEvent=i,exports.disableLog=s,exports.disableWarnings=a,exports.log=p,exports.deprecated=u,exports.detectBrowser=c,exports.compactObject=f,exports.walkStats=l,exports.filterStats=v;varn=!0,r=!0;functiono(e,t,n){varr=e.match(t);returnr&&r.length>=n&&parseInt(r[n],10)}functioni(e,t,n){if(e.RTCPeerConnection){varr=e.RTCPeerConnection.prototype,o=r.addEventListener;r.addEventListener=function(e,r){if(e!==t)returno.apply(this,arguments);vari=function(e){vart=n(e);t&&(r.handleEvent?r.handleEvent(t):r(t))};returnthis._eventMap=this._eventMap||{},this._eventMap[t]||(this._eventMap[t]=newMap),this._eventMap[t].set(r,i),o.apply(this,[e,i])};vari=r.removeEventListener;r.removeEventListener=function(e,n){if(e!==t||!this._eventMap||!this._eventMap[t])returni.apply(this,arguments);if(!this._eventMap[t].has(n))returni.apply(this,arguments);varr=this._eventMap[t].get(n);returnthis._eventMap[t].delete(n),0===this._eventMap[t].size&&deletethis._eventMap[t],0===Object.keys(this._eventMap).length&&deletethis._eventMap,i.apply(this,[e,r])},Object.defineProperty(r,"on"+t,{get:function(){returnthis["_on"+t]},set:function(e){this["_on"+t]&&(this.removeEventListener(t,this["_on"+t]),deletethis["_on"+t]),e&&this.addEventListener(t,this["_on"+t]=e)},enumerable:!0,configurable:!0})}}functions(e){return"boolean"!=typeofe?newError("Argument type: "+t(e)+". Please use a boolean."):(n=e,e?"adapter.js logging disabled":"adapter.js logging enabled")}functiona(e){return"boolean"!=typeofe?newError("Argument type: "+t(e)+". Please use a boolean."):(r=!e,"adapter.js deprecation warnings "+(e?"disabled":"enabled"))}functionp(){if("object"===("undefined"==typeofwindow?"undefined":t(window))){if(n)return;"undefined"!=typeofconsole&&"function"==typeofconsole.log&&console.log.apply(console,arguments)}}functionu(e,t){r&&console.warn(e+" is deprecated, please use "+t+" instead.")}functionc(e){vart={browser:null,version:null};if(void0===e||!e.navigator)returnt.browser="Not a browser.",t;var{navigator:n}=e;if(n.mozGetUserMedia)t.browser="firefox",t.version=o(n.userAgent,/Firefox\/(\d+)\./,1);elseif(n.webkitGetUserMedia||!1===e.isSecureContext&&e.webkitRTCPeerConnection&&!e.RTCIceGatherer)t.browser="chrome",t.version=o(n.userAgent,/Chrom(e|ium)\/(\d+)\./,2);elseif(n.mediaDevices&&n.userAgent.match(/Edge\/(\d+).(\d+)$/))t.browser="edge",t.version=o(n.userAgent,/Edge\/(\d+).(\d+)$/,2);else{if(!e.RTCPeerConnection||!n.userAgent.match(/AppleWebKit\/(\d+)\./))returnt.browser="Not a supported browser.",t;t.browser="safari",t.version=o(n.userAgent,/AppleWebKit\/(\d+)\./,1),t.supportsUnifiedPlan=e.RTCRtpTransceiver&&"currentDirection"ine.RTCRtpTransceiver.prototype}returnt}functiond(e){return"[object Object]"===Object.prototype.toString.call(e)}functionf(t){returnd(t)?Object.keys(t).reduce(function(n,r){varo=d(t[r]),i=o?f(t[r]):t[r],s=o&&!Object.keys(i).length;returnvoid0===i||s?n:Object.assign(n,e({},r,i))},{}):t}functionl(e,t,n){t&&!n.has(t.id)&&(n.set(t.id,t),Object.keys(t).forEach(function(r){r.endsWith("Id")?l(e,e.get(t[r]),n):r.endsWith("Ids")&&t[r].forEach(function(t){l(e,e.get(t),n)})}))}functionv(e,t,n){varr=n?"outbound-rtp":"inbound-rtp",o=newMap;if(null===t)returno;vari=[];returne.forEach(function(e){"track"===e.type&&e.trackIdentifier===t.id&&i.push(e)}),i.forEach(function(t){e.forEach(function(n){n.type===r&&n.trackId===t.id&&l(e,n,o)})}),o}
"use strict";functione(e,i){e.navigator.mediaDevices&&"getDisplayMedia"ine.navigator.mediaDevices||e.navigator.mediaDevices&&("function"==typeofi?e.navigator.mediaDevices.getDisplayMedia=function(a){returni(a).then(function(i){vart=a.video&&a.video.width,o=a.video&&a.video.height,d=a.video&&a.video.frameRate;returna.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:i,maxFrameRate:d||3}},t&&(a.video.mandatory.maxWidth=t),o&&(a.video.mandatory.maxHeight=o),e.navigator.mediaDevices.getUserMedia(a)})}:console.error("shimGetDisplayMedia: getSourceId argument is not a function"))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.shimGetDisplayMedia=e;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shimPeerConnection=p,exports.shimReplaceTrack=a,Object.defineProperty(exports,"shimGetUserMedia",{enumerable:!0,get:function(){returnn.shimGetUserMedia}}),Object.defineProperty(exports,"shimGetDisplayMedia",{enumerable:!0,get:function(){returni.shimGetDisplayMedia}});vare=s(require("../utils")),t=require("./filtericeservers"),r=o(require("rtcpeerconnection-shim")),n=require("./getusermedia"),i=require("./getdisplaymedia");functiono(e){returne&&e.__esModule?e:{default:e}}functionc(){if("function"!=typeofWeakMap)returnnull;vare=newWeakMap;returnc=function(){returne},e}functions(e){if(e&&e.__esModule)returne;if(null===e||"object"!=typeofe&&"function"!=typeofe)return{default:e};vart=c();if(t&&t.has(e))returnt.get(e);varr={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(variine)if(Object.prototype.hasOwnProperty.call(e,i)){varo=n?Object.getOwnPropertyDescriptor(e,i):null;o&&(o.get||o.set)?Object.defineProperty(r,i,o):r[i]=e[i]}returnr.default=e,t&&t.set(e,r),r}functionp(n,i){if(n.RTCIceGatherer&&(n.RTCIceCandidate||(n.RTCIceCandidate=function(e){returne}),n.RTCSessionDescription||(n.RTCSessionDescription=function(e){returne}),i.version<15025)){varo=Object.getOwnPropertyDescriptor(n.MediaStreamTrack.prototype,"enabled");Object.defineProperty(n.MediaStreamTrack.prototype,"enabled",{set:function(e){o.set.call(this,e);vart=newEvent("enabled");t.enabled=e,this.dispatchEvent(t)}})}!n.RTCRtpSender||"dtmf"inn.RTCRtpSender.prototype||Object.defineProperty(n.RTCRtpSender.prototype,"dtmf",{get:function(){returnvoid0===this._dtmf&&("audio"===this.track.kind?this._dtmf=newn.RTCDtmfSender(this):"video"===this.track.kind&&(this._dtmf=null)),this._dtmf}}),n.RTCDtmfSender&&!n.RTCDTMFSender&&(n.RTCDTMFSender=n.RTCDtmfSender);varc=(0,r.default)(n,i.version);n.RTCPeerConnection=function(r){returnr&&r.iceServers&&(r.iceServers=(0,t.filterIceServers)(r.iceServers,i.version),e.log("ICE servers after filtering:",r.iceServers)),newc(r)},n.RTCPeerConnection.prototype=c.prototype}functiona(e){!e.RTCRtpSender||"replaceTrack"ine.RTCRtpSender.prototype||(e.RTCRtpSender.prototype.replaceTrack=e.RTCRtpSender.prototype.setTrack)}
"use strict";functione(e,i){e.navigator.mediaDevices&&"getDisplayMedia"ine.navigator.mediaDevices||e.navigator.mediaDevices&&(e.navigator.mediaDevices.getDisplayMedia=function(a){if(!a||!a.video){vart=newDOMException("getDisplayMedia without video constraints is undefined");returnt.name="NotFoundError",t.code=8,Promise.reject(t)}return!0===a.video?a.video={mediaSource:i}:a.video.mediaSource=i,e.navigator.mediaDevices.getUserMedia(a)})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.shimGetDisplayMedia=e;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shimRTCIceCandidate=a,exports.shimMaxMessageSize=c,exports.shimSendThrowTypeError=s,exports.shimConnectionState=p,exports.removeExtmapAllowMixed=d,exports.shimAddIceCandidateNullOrEmpty=u;vare=r(require("sdp")),t=o(require("./utils"));functionn(){if("function"!=typeofWeakMap)returnnull;vare=newWeakMap;returnn=function(){returne},e}functiono(e){if(e&&e.__esModule)returne;if(null===e||"object"!=typeofe&&"function"!=typeofe)return{default:e};vart=n();if(t&&t.has(e))returnt.get(e);varo={},r=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(variine)if(Object.prototype.hasOwnProperty.call(e,i)){vara=r?Object.getOwnPropertyDescriptor(e,i):null;a&&(a.get||a.set)?Object.defineProperty(o,i,a):o[i]=e[i]}returno.default=e,t&&t.set(e,o),o}functionr(e){returne&&e.__esModule?e:{default:e}}functioni(e){return(i="function"==typeofSymbol&&"symbol"==typeofSymbol.iterator?function(e){returntypeofe}:function(e){returne&&"function"==typeofSymbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeofe})(e)}functiona(n){if(n.RTCIceCandidate&&!(n.RTCIceCandidate&&"foundation"inn.RTCIceCandidate.prototype)){varo=n.RTCIceCandidate;n.RTCIceCandidate=function(t){if("object"===i(t)&&t.candidate&&0===t.candidate.indexOf("a=")&&((t=JSON.parse(JSON.stringify(t))).candidate=t.candidate.substr(2)),t.candidate&&t.candidate.length){varn=newo(t),r=e.default.parseCandidate(t.candidate),a=Object.assign(n,r);returna.toJSON=function(){return{candidate:a.candidate,sdpMid:a.sdpMid,sdpMLineIndex:a.sdpMLineIndex,usernameFragment:a.usernameFragment}},a}returnnewo(t)},n.RTCIceCandidate.prototype=o.prototype,t.wrapPeerConnectionEvent(n,"icecandidate",function(e){returne.candidate&&Object.defineProperty(e,"candidate",{value:newn.RTCIceCandidate(e.candidate),writable:"false"}),e})}}functionc(t,n){if(t.RTCPeerConnection){"sctp"int.RTCPeerConnection.prototype||Object.defineProperty(t.RTCPeerConnection.prototype,"sctp",{get:function(){returnvoid0===this._sctp?null:this._sctp}});varo=t.RTCPeerConnection.prototype.setRemoteDescription;t.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,"chrome"===n.browser&&n.version>=76){var{sdpSemantics:t}=this.getConfiguration();"plan-b"===t&&Object.defineProperty(this,"sctp",{get:function(){returnvoid0===this._sctp?null:this._sctp},enumerable:!0,configurable:!0})}if(function(t){if(!t||!t.sdp)return!1;varn=e.default.splitSections(t.sdp);returnn.shift(),n.some(function(t){varn=e.default.parseMLine(t);returnn&&"application"===n.kind&&-1!==n.protocol.indexOf("SCTP")})}(arguments[0])){varr,i=function(e){vart=e.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(null===t||t.length<2)return-1;varn=parseInt(t[1],10);returnn!=n?-1:n}(arguments[0]),a=(p=i,d=65536,"firefox"===n.browser&&(d=n.version<57?-1===p?16384:2147483637:n.version<60?57===n.version?65535:65536:2147483637),d),c=function(t,o){varr=65536;"firefox"===n.browser&&57===n.version&&(r=65535);vari=e.default.matchPrefix(t.sdp,"a=max-message-size:");returni.length>0?r=parseInt(i[0].substr(19),10):"firefox"===n.browser&&-1!==o&&(r=2147483637),r}(arguments[0],i);r=0===a&&0===c?Number.POSITIVE_INFINITY:0===a||0===c?Math.max(a,c):Math.min(a,c);vars={};Object.defineProperty(s,"maxMessageSize",{get:function(){returnr}}),this._sctp=s}varp,d;returno.apply(this,arguments)}}}functions(e){if(e.RTCPeerConnection&&"createDataChannel"ine.RTCPeerConnection.prototype){varn=e.RTCPeerConnection.prototype.createDataChannel;e.RTCPeerConnection.prototype.createDataChannel=function(){vare=n.apply(this,arguments);returno(e,this),e},t.wrapPeerConnectionEvent(e,"datachannel",function(e){returno(e.channel,e.target),e})}functiono(e,t){varn=e.send;e.send=function(){varo=arguments[0],r=o.length||o.size||o.byteLength;if("open"===e.readyState&&t.sctp&&r>t.sctp.maxMessageSize)thrownewTypeError("Message too large (can send a maximum of "+t.sctp.maxMessageSize+" bytes)");returnn.apply(e,arguments)}}}functionp(e){if(e.RTCPeerConne
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.adapterFactory=o;vare=m(require("./utils")),i=m(require("./chrome/chrome_shim")),r=m(require("./edge/edge_shim")),s=m(require("./firefox/firefox_shim")),t=m(require("./safari/safari_shim")),a=m(require("./common_shim"));functionn(){if("function"!=typeofWeakMap)returnnull;vare=newWeakMap;returnn=function(){returne},e}functionm(e){if(e&&e.__esModule)returne;if(null===e||"object"!=typeofe&&"function"!=typeofe)return{default:e};vari=n();if(i&&i.has(e))returni.get(e);varr={},s=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(vartine)if(Object.prototype.hasOwnProperty.call(e,t)){vara=s?Object.getOwnPropertyDescriptor(e,t):null;a&&(a.get||a.set)?Object.defineProperty(r,t,a):r[t]=e[t]}returnr.default=e,i&&i.set(e,r),r}functiono(){var{window:n}=arguments.length>0&&void0!==arguments[0]?arguments[0]:{},m=arguments.length>1&&void0!==arguments[1]?arguments[1]:{shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0},o=e.log,h=e.detectBrowser(n),d={browserDetails:h,commonShim:a,extractVersion:e.extractVersion,disableLog:e.disableLog,disableWarnings:e.disableWarnings};switch(h.browser){case"chrome":if(!i||!i.shimPeerConnection||!m.shimChrome)returno("Chrome shim is not included in this adapter release."),d;if(null===h.version)returno("Chrome shim can not determine version, not shimming."),d;o("adapter.js shimming chrome."),d.browserShim=i,a.shimAddIceCandidateNullOrEmpty(n,h),i.shimGetUserMedia(n,h),i.shimMediaStream(n,h),i.shimPeerConnection(n,h),i.shimOnTrack(n,h),i.shimAddTrackRemoveTrack(n,h),i.shimGetSendersWithDtmf(n,h),i.shimGetStats(n,h),i.shimSenderReceiverGetStats(n,h),i.fixNegotiationNeeded(n,h),a.shimRTCIceCandidate(n,h),a.shimConnectionState(n,h),a.shimMaxMessageSize(n,h),a.shimSendThrowTypeError(n,h),a.removeExtmapAllowMixed(n,h);break;case"firefox":if(!s||!s.shimPeerConnection||!m.shimFirefox)returno("Firefox shim is not included in this adapter release."),d;o("adapter.js shimming firefox."),d.browserShim=s,a.shimAddIceCandidateNullOrEmpty(n,h),s.shimGetUserMedia(n,h),s.shimPeerConnection(n,h),s.shimOnTrack(n,h),s.shimRemoveStream(n,h),s.shimSenderGetStats(n,h),s.shimReceiverGetStats(n,h),s.shimRTCDataChannel(n,h),s.shimAddTransceiver(n,h),s.shimGetParameters(n,h),s.shimCreateOffer(n,h),s.shimCreateAnswer(n,h),a.shimRTCIceCandidate(n,h),a.shimConnectionState(n,h),a.shimMaxMessageSize(n,h),a.shimSendThrowTypeError(n,h);break;case"edge":if(!r||!r.shimPeerConnection||!m.shimEdge)returno("MS edge shim is not included in this adapter release."),d;o("adapter.js shimming edge."),d.browserShim=r,r.shimGetUserMedia(n,h),r.shimGetDisplayMedia(n,h),r.shimPeerConnection(n,h),r.shimReplaceTrack(n,h),a.shimMaxMessageSize(n,h),a.shimSendThrowTypeError(n,h);break;case"safari":if(!t||!m.shimSafari)returno("Safari shim is not included in this adapter release."),d;o("adapter.js shimming safari."),d.browserShim=t,a.shimAddIceCandidateNullOrEmpty(n,h),t.shimRTCIceServerUrls(n,h),t.shimCreateOfferLegacy(n,h),t.shimCallbacksAPI(n,h),t.shimLocalStreamsAPI(n,h),t.shimRemoteStreamsAPI(n,h),t.shimTrackEventTransceiver(n,h),t.shimGetUserMedia(n,h),t.shimAudioContext(n,h),a.shimRTCIceCandidate(n,h),a.shimMaxMessageSize(n,h),a.shimSendThrowTypeError(n,h),a.removeExtmapAllowMixed(n,h);break;default:o("Unsupported browser!")}returnd}
"use strict";vare=Object.prototype.hasOwnProperty,t="~";functionn(){}functionr(e,t,n){this.fn=e,this.context=t,this.once=n||!1}functiono(e,n,o,s,i){if("function"!=typeofo)thrownewTypeError("The listener must be a function");varc=newr(o,s||e,i),f=t?t+n:n;returne._events[f]?e._events[f].fn?e._events[f]=[e._events[f],c]:e._events[f].push(c):(e._events[f]=c,e._eventsCount++),e}functions(e,t){0==--e._eventsCount?e._events=newn:deletee._events[t]}functioni(){this._events=newn,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(newn).__proto__||(t=!1)),i.prototype.eventNames=function(){varn,r,o=[];if(0===this._eventsCount)returno;for(rinn=this._events)e.call(n,r)&&o.push(t?r.slice(1):r);returnObject.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(n)):o},i.prototype.listeners=function(e){varn=t?t+e:e,r=this._events[n];if(!r)return[];if(r.fn)return[r.fn];for(varo=0,s=r.length,i=newArray(s);o<s;o++)i[o]=r[o].fn;returni},i.prototype.listenerCount=function(e){varn=t?t+e:e,r=this._events[n];returnr?r.fn?1:r.length:0},i.prototype.emit=function(e,n,r,o,s,i){varc=t?t+e:e;if(!this._events[c])return!1;varf,u,a=this._events[c],l=arguments.length;if(a.fn){switch(a.once&&this.removeListener(e,a.fn,void0,!0),l){case1:returna.fn.call(a.context),!0;case2:returna.fn.call(a.context,n),!0;case3:returna.fn.call(a.context,n,r),!0;case4:returna.fn.call(a.context,n,r,o),!0;case5:returna.fn.call(a.context,n,r,o,s),!0;case6:returna.fn.call(a.context,n,r,o,s,i),!0}for(u=1,f=newArray(l-1);u<l;u++)f[u-1]=arguments[u];a.fn.apply(a.context,f)}else{varv,h=a.length;for(u=0;u<h;u++)switch(a[u].once&&this.removeListener(e,a[u].fn,void0,!0),l){case1:a[u].fn.call(a[u].context);break;case2:a[u].fn.call(a[u].context,n);break;case3:a[u].fn.call(a[u].context,n,r);break;case4:a[u].fn.call(a[u].context,n,r,o);break;default:if(!f)for(v=1,f=newArray(l-1);v<l;v++)f[v-1]=arguments[v];a[u].fn.apply(a[u].context,f)}}return!0},i.prototype.on=function(e,t,n){returno(this,e,t,n,!1)},i.prototype.once=function(e,t,n){returno(this,e,t,n,!0)},i.prototype.removeListener=function(e,n,r,o){vari=t?t+e:e;if(!this._events[i])returnthis;if(!n)returns(this,i),this;varc=this._events[i];if(c.fn)c.fn!==n||o&&!c.once||r&&c.context!==r||s(this,i);else{for(varf=0,u=[],a=c.length;f<a;f++)(c[f].fn!==n||o&&!c[f].once||r&&c[f].context!==r)&&u.push(c[f]);u.length?this._events[i]=1===u.length?u[0]:u:s(this,i)}returnthis},i.prototype.removeAllListeners=function(e){varr;returne?(r=t?t+e:e,this._events[r]&&s(this,r)):(this._events=newn,this._eventsCount=0),this},i.prototype.off=i.prototype.removeListener,i.prototype.addListener=i.prototype.on,i.prefixed=t,i.EventEmitter=i,"undefined"!=typeofmodule&&(module.exports=i);
"use strict";vare=this&&this.__extends||function(){vare=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceofArray&&function(e,t){e.__proto__=t}||function(e,t){for(varnint)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(t,n)};returnfunction(t,n){if("function"!=typeofn&&null!==n)thrownewTypeError("Class extends value "+String(n)+" is not a constructor or null");functiono(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(o.prototype=n.prototype,newo)}}(),t=this&&this.__read||function(e,t){varn="function"==typeofSymbol&&e[Symbol.iterator];if(!n)returne;varo,s,r=n.call(e),i=[];try{for(;(void0===t||t-->0)&&!(o=r.next()).done;)i.push(o.value)}catch(c){s={error:c}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(s)throws.error}}returni},n=this&&this.__spreadArray||function(e,t){for(varn=0,o=t.length,s=e.length;n<o;n++,s++)e[s]=t[n];returne},o=this&&this.__values||function(e){vart="function"==typeofSymbol&&Symbol.iterator,n=t&&e[t],o=0;if(n)returnn.call(e);if(e&&"number"==typeofe.length)return{next:function(){returne&&o>=e.length&&(e=void0),{value:e&&e[o++],done:!e}}};thrownewTypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},s=this&&this.__importDefault||function(e){returne&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Socket=void0;varr=require("eventemitter3"),i=s(require("./logger")),c=require("./enums"),a=function(s){functionr(e,t,n,o,r,i){void0===i&&(i=5e3);varc=s.call(this)||this;c.pingInterval=i,c._disconnected=!0,c._messagesQueue=[];vara=e?"wss://":"ws://";returnc._baseUrl=a+t+":"+n+o+"peerjs?key="+r,c}returne(r,s),r.prototype.start=function(e,t){varn=this;this._id=e;varo=this._baseUrl+"&id="+e+"&token="+t;!this._socket&&this._disconnected&&(this._socket=newWebSocket(o),this._disconnected=!1,this._socket.onmessage=function(e){vart;try{t=JSON.parse(e.data),i.default.log("Server message received:",t)}catch(o){returnvoidi.default.log("Invalid server message",e.data)}n.emit(c.SocketEventType.Message,t)},this._socket.onclose=function(e){n._disconnected||(i.default.log("Socket closed.",e),n._cleanup(),n._disconnected=!0,n.emit(c.SocketEventType.Disconnected))},this._socket.onopen=function(){n._disconnected||(n._sendQueuedMessages(),i.default.log("Socket open"),n._scheduleHeartbeat())})},r.prototype._scheduleHeartbeat=function(){vare=this;this._wsPingTimer=setTimeout(function(){e._sendHeartbeat()},this.pingInterval)},r.prototype._sendHeartbeat=function(){if(this._wsOpen()){vare=JSON.stringify({type:c.ServerMessageType.Heartbeat});this._socket.send(e),this._scheduleHeartbeat()}elsei.default.log("Cannot send heartbeat, because socket closed")},r.prototype._wsOpen=function(){return!!this._socket&&1===this._socket.readyState},r.prototype._sendQueuedMessages=function(){vare,s,r=n([],t(this._messagesQueue));this._messagesQueue=[];try{for(vari=o(r),c=i.next();!c.done;c=i.next()){vara=c.value;this.send(a)}}catch(u){e={error:u}}finally{try{c&&!c.done&&(s=i.return)&&s.call(i)}finally{if(e)throwe.error}}},r.prototype.send=function(e){if(!this._disconnected)if(this._id)if(e.type){if(this._wsOpen()){vart=JSON.stringify(e);this._socket.send(t)}}elsethis.emit(c.SocketEventType.Error,"Invalid message");elsethis._messagesQueue.push(e)},r.prototype.close=function(){this._disconnected||(this._cleanup(),this._disconnected=!0)},r.prototype._cleanup=function(){this._socket&&(this._socket.onopen=this._socket.onmessage=this._socket.onclose=null,this._socket.close(),this._socket=void0),clearTimeout(this._wsPingTimer)},r}(r.EventEmitter);exports.Socket=a;
"use strict";vare=this&&this.__assign||function(){return(e=Object.assign||function(e){for(varn,t=1,o=arguments.length;t<o;t++)for(variinn=arguments[t])Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i]);returne}).apply(this,arguments)},n=this&&this.__awaiter||function(e,n,t,o){returnnew(t||(t=Promise))(function(i,r){functionc(e){try{s(o.next(e))}catch(n){r(n)}}functiona(e){try{s(o.throw(e))}catch(n){r(n)}}functions(e){varn;e.done?i(e.value):(n=e.value,ninstanceoft?n:newt(function(e){e(n)})).then(c,a)}s((o=o.apply(e,n||[])).next())})},t=this&&this.__generator||function(e,n){vart,o,i,r,c={label:0,sent:function(){if(1&i[0])throwi[1];returni[1]},trys:[],ops:[]};returnr={next:a(0),throw:a(1),return:a(2)},"function"==typeofSymbol&&(r[Symbol.iterator]=function(){returnthis}),r;functiona(r){returnfunction(a){returnfunction(r){if(t)thrownewTypeError("Generator is already executing.");for(;c;)try{if(t=1,o&&(i=2&r[0]?o.return:r[0]?o.throw||((i=o.return)&&i.call(o),0):o.next)&&!(i=i.call(o,r[1])).done)returni;switch(o=0,i&&(r=[2&r[0],i.value]),r[0]){case0:case1:i=r;break;case4:returnc.label++,{value:r[1],done:!1};case5:c.label++,o=r[1],r=[0];continue;case7:r=c.ops.pop(),c.trys.pop();continue;default:if(!(i=(i=c.trys).length>0&&i[i.length-1])&&(6===r[0]||2===r[0])){c=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){c.label=r[1];break}if(6===r[0]&&c.label<i[1]){c.label=i[1],i=r;break}if(i&&c.label<i[2]){c.label=i[2],c.ops.push(r);break}i[2]&&c.ops.pop(),c.trys.pop();continue}r=n.call(e,c)}catch(a){r=[6,a],o=0}finally{t=i=0}if(5&r[0])throwr[1];return{value:r[0]?r[1]:void0,done:!0}}([r,a])}}},o=this&&this.__importDefault||function(e){returne&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Negotiator=void0;vari=require("./util"),r=o(require("./logger")),c=require("./enums"),a=function(){functiono(e){this.connection=e}returno.prototype.startConnection=function(e){varn=this._startPeerConnection();if(this.connection.peerConnection=n,this.connection.type===c.ConnectionType.Media&&e._stream&&this._addTracksToConnection(e._stream,n),e.originator){if(this.connection.type===c.ConnectionType.Data){vart=this.connection,o={ordered:!!e.reliable},i=n.createDataChannel(t.label,o);t.initialize(i)}this._makeOffer()}elsethis.handleSDP("OFFER",e.sdp)},o.prototype._startPeerConnection=function(){r.default.log("Creating RTCPeerConnection.");vare=newRTCPeerConnection(this.connection.provider.options.config);returnthis._setupListeners(e),e},o.prototype._setupListeners=function(e){varn=this,t=this.connection.peer,o=this.connection.connectionId,a=this.connection.type,s=this.connection.provider;r.default.log("Listening for ICE candidates."),e.onicecandidate=function(e){e.candidate&&e.candidate.candidate&&(r.default.log("Received ICE candidates for "+t+":",e.candidate),s.socket.send({type:c.ServerMessageType.Candidate,payload:{candidate:e.candidate,type:a,connectionId:o},dst:t}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":r.default.log("iceConnectionState is failed, closing connections to "+t),n.connection.emit(c.ConnectionEventType.Error,newError("Negotiation of connection to "+t+" failed.")),n.connection.close();break;case"closed":r.default.log("iceConnectionState is closed, closing connections to "+t),n.connection.emit(c.ConnectionEventType.Error,newError("Connection to "+t+" closed.")),n.connection.close();break;case"disconnected":r.default.log("iceConnectionState changed to disconnected on the connection with "+t);break;case"completed":e.onicecandidate=i.util.noop}n.connection.emit(c.ConnectionEventType.IceStateChanged,e.iceConnectionState)},r.default.log("Listening for data channel"),e.ondatachannel=function(e){r.default.log("Received data channel");varn=e.channel;s.getConnection(t,o).initialize(n)},r.default.log("Listening for remote stream"),e.ontrack=function(e){r.default.log("Received remote stream");vari=e.streams[0],a=s.getConnection(t,o);if(a.type===c.ConnectionType.Media){vard=a;n._addStreamToMediaConnecti
"use strict";vart=this&&this.__extends||function(){vart=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceofArray&&function(t,e){t.__proto__=e}||function(t,e){for(varnine)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(e,n)};returnfunction(e,n){if("function"!=typeofn&&null!==n)thrownewTypeError("Class extends value "+String(n)+" is not a constructor or null");functiono(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(o.prototype=n.prototype,newo)}}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.BaseConnection=void0;vare=require("eventemitter3"),n=function(e){functionn(t,n,o){varr=e.call(this)||this;returnr.peer=t,r.provider=n,r.options=o,r._open=!1,r.metadata=o.metadata,r}returnt(n,e),Object.defineProperty(n.prototype,"open",{get:function(){returnthis._open},enumerable:!1,configurable:!0}),n}(e.EventEmitter);exports.BaseConnection=n;
"use strict";vare=this&&this.__extends||function(){vare=function(t,o){return(e=Object.setPrototypeOf||{__proto__:[]}instanceofArray&&function(e,t){e.__proto__=t}||function(e,t){for(varoint)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])})(t,o)};returnfunction(t,o){if("function"!=typeofo&&null!==o)thrownewTypeError("Class extends value "+String(o)+" is not a constructor or null");functionr(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(r.prototype=o.prototype,newr)}}(),t=this&&this.__assign||function(){return(t=Object.assign||function(e){for(vart,o=1,r=arguments.length;o<r;o++)for(varnint=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);returne}).apply(this,arguments)},o=this&&this.__values||function(e){vart="function"==typeofSymbol&&Symbol.iterator,o=t&&e[t],r=0;if(o)returno.call(e);if(e&&"number"==typeofe.length)return{next:function(){returne&&r>=e.length&&(e=void0),{value:e&&e[r++],done:!e}}};thrownewTypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},r=this&&this.__importDefault||function(e){returne&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.MediaConnection=void0;varn=require("./util"),i=r(require("./logger")),a=require("./negotiator"),s=require("./enums"),l=require("./baseconnection"),c=function(r){functionl(e,t,o){vari=r.call(this,e,t,o)||this;returni._localStream=i.options._stream,i.connectionId=i.options.connectionId||l.ID_PREFIX+n.util.randomToken(),i._negotiator=newa.Negotiator(i),i._localStream&&i._negotiator.startConnection({_stream:i._localStream,originator:!0}),i}returne(l,r),Object.defineProperty(l.prototype,"type",{get:function(){returns.ConnectionType.Media},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"localStream",{get:function(){returnthis._localStream},enumerable:!1,configurable:!0}),Object.defineProperty(l.prototype,"remoteStream",{get:function(){returnthis._remoteStream},enumerable:!1,configurable:!0}),l.prototype.addStream=function(e){i.default.log("Receiving stream",e),this._remoteStream=e,r.prototype.emit.call(this,s.ConnectionEventType.Stream,e)},l.prototype.handleMessage=function(e){vart=e.type,o=e.payload;switch(e.type){cases.ServerMessageType.Answer:this._negotiator.handleSDP(t,o.sdp),this._open=!0;break;cases.ServerMessageType.Candidate:this._negotiator.handleCandidate(o.candidate);break;default:i.default.warn("Unrecognized message type:"+t+" from peer:"+this.peer)}},l.prototype.answer=function(e,r){varn,a;if(void0===r&&(r={}),this._localStream)i.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");else{this._localStream=e,r&&r.sdpTransform&&(this.options.sdpTransform=r.sdpTransform),this._negotiator.startConnection(t(t({},this.options._payload),{_stream:e}));vars=this.provider._getMessages(this.connectionId);try{for(varl=o(s),c=l.next();!c.done;c=l.next()){varp=c.value;this.handleMessage(p)}}catch(u){n={error:u}}finally{try{c&&!c.done&&(a=l.return)&&a.call(l)}finally{if(n)thrown.error}}this._open=!0}},l.prototype.close=function(){this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this._localStream=null,this._remoteStream=null,this.provider&&(this.provider._removeConnection(this),this.provider=null),this.options&&this.options._stream&&(this.options._stream=null),this.open&&(this._open=!1,r.prototype.emit.call(this,s.ConnectionEventType.Close))},l.ID_PREFIX="mc_",l}(l.BaseConnection);exports.MediaConnection=c;
"use strict";vare=this&&this.__extends||function(){vare=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceofArray&&function(e,t){e.__proto__=t}||function(e,t){for(varrint)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(t,r)};returnfunction(t,r){if("function"!=typeofr&&null!==r)thrownewTypeError("Class extends value "+String(r)+" is not a constructor or null");functiono(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(o.prototype=r.prototype,newo)}}(),t=this&&this.__importDefault||function(e){returne&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.EncodingQueue=void0;varr=require("eventemitter3"),o=t(require("./logger")),n=function(t){functionr(){vare=t.call(this)||this;returne.fileReader=newFileReader,e._queue=[],e._processing=!1,e.fileReader.onload=function(t){e._processing=!1,t.target&&e.emit("done",t.target.result),e.doNextTask()},e.fileReader.onerror=function(t){o.default.error("EncodingQueue error:",t),e._processing=!1,e.destroy(),e.emit("error",t)},e}returne(r,t),Object.defineProperty(r.prototype,"queue",{get:function(){returnthis._queue},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"size",{get:function(){returnthis.queue.length},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"processing",{get:function(){returnthis._processing},enumerable:!1,configurable:!0}),r.prototype.enque=function(e){this.queue.push(e),this.processing||this.doNextTask()},r.prototype.destroy=function(){this.fileReader.abort(),this._queue=[]},r.prototype.doNextTask=function(){0!==this.size&&(this.processing||(this._processing=!0,this.fileReader.readAsArrayBuffer(this.queue.shift())))},r}(r.EventEmitter);exports.EncodingQueue=n;
"use strict";vare=this&&this.__extends||function(){vare=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceofArray&&function(e,t){e.__proto__=t}||function(e,t){for(varnint)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(t,n)};returnfunction(t,n){if("function"!=typeofn&&null!==n)thrownewTypeError("Class extends value "+String(n)+" is not a constructor or null");functioni(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(i.prototype=n.prototype,newi)}}(),t=this&&this.__values||function(e){vart="function"==typeofSymbol&&Symbol.iterator,n=t&&e[t],i=0;if(n)returnn.call(e);if(e&&"number"==typeofe.length)return{next:function(){returne&&i>=e.length&&(e=void0),{value:e&&e[i++],done:!e}}};thrownewTypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},n=this&&this.__importDefault||function(e){returne&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataConnection=void0;vari=require("./util"),o=n(require("./logger")),r=require("./negotiator"),a=require("./enums"),s=require("./baseconnection"),u=require("./encodingQueue"),l=function(n){functions(e,t,l){varf=n.call(this,e,t,l)||this;returnf.stringify=JSON.stringify,f.parse=JSON.parse,f._buffer=[],f._bufferSize=0,f._buffering=!1,f._chunkedData={},f._encodingQueue=newu.EncodingQueue,f.connectionId=f.options.connectionId||s.ID_PREFIX+i.util.randomToken(),f.label=f.options.label||f.connectionId,f.serialization=f.options.serialization||a.SerializationType.Binary,f.reliable=!!f.options.reliable,f._encodingQueue.on("done",function(e){f._bufferedSend(e)}),f._encodingQueue.on("error",function(){o.default.error("DC#"+f.connectionId+": Error occured in encoding from blob to arraybuffer, close DC"),f.close()}),f._negotiator=newr.Negotiator(f),f._negotiator.startConnection(f.options._payload||{originator:!0}),f}returne(s,n),Object.defineProperty(s.prototype,"type",{get:function(){returna.ConnectionType.Data},enumerable:!1,configurable:!0}),Object.defineProperty(s.prototype,"dataChannel",{get:function(){returnthis._dc},enumerable:!1,configurable:!0}),Object.defineProperty(s.prototype,"bufferSize",{get:function(){returnthis._bufferSize},enumerable:!1,configurable:!0}),s.prototype.initialize=function(e){this._dc=e,this._configureDataChannel()},s.prototype._configureDataChannel=function(){vare=this;i.util.supports.binaryBlob&&!i.util.supports.reliable||(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){o.default.log("DC#"+e.connectionId+" dc connection success"),e._open=!0,e.emit(a.ConnectionEventType.Open)},this.dataChannel.onmessage=function(t){o.default.log("DC#"+e.connectionId+" dc onmessage:",t.data),e._handleDataMessage(t)},this.dataChannel.onclose=function(){o.default.log("DC#"+e.connectionId+" dc closed for:",e.peer),e.close()}},s.prototype._handleDataMessage=function(e){vart=this,o=e.data,r=o.constructor,s=o;if(this.serialization===a.SerializationType.Binary||this.serialization===a.SerializationType.BinaryUTF8){if(r===Blob)returnvoidi.util.blobToArrayBuffer(o,function(e){varn=i.util.unpack(e);t.emit(a.ConnectionEventType.Data,n)});if(r===ArrayBuffer)s=i.util.unpack(o);elseif(r===String){varu=i.util.binaryStringToArrayBuffer(o);s=i.util.unpack(u)}}elsethis.serialization===a.SerializationType.JSON&&(s=this.parse(o));s.__peerData?this._handleChunk(s):n.prototype.emit.call(this,a.ConnectionEventType.Data,s)},s.prototype._handleChunk=function(e){vart=e.__peerData,n=this._chunkedData[t]||{data:[],count:0,total:e.total};if(n.data[e.n]=e.data,n.count++,this._chunkedData[t]=n,n.total===n.count){deletethis._chunkedData[t];vari=newBlob(n.data);this._handleDataMessage({data:i})}},s.prototype.close=function(){this._buffer=[],this._bufferSize=0,this._chunkedData={},this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this.provider&&(this.provider._removeConnection(this),this.provider=null),this.dataChannel&&(this.dataChannel.onopen=null,this.dataChannel.onmessage=null,this.dataChannel.onclose=null,this._dc=null)
"use strict";vart=this&&this.__awaiter||function(t,e,r,o){returnnew(r||(r=Promise))(function(n,s){functioni(t){try{a(o.next(t))}catch(e){s(e)}}functionu(t){try{a(o.throw(t))}catch(e){s(e)}}functiona(t){vare;t.done?n(t.value):(e=t.value,einstanceofr?e:newr(function(t){t(e)})).then(i,u)}a((o=o.apply(t,e||[])).next())})},e=this&&this.__generator||function(t,e){varr,o,n,s,i={label:0,sent:function(){if(1&n[0])thrown[1];returnn[1]},trys:[],ops:[]};returns={next:u(0),throw:u(1),return:u(2)},"function"==typeofSymbol&&(s[Symbol.iterator]=function(){returnthis}),s;functionu(s){returnfunction(u){returnfunction(s){if(r)thrownewTypeError("Generator is already executing.");for(;i;)try{if(r=1,o&&(n=2&s[0]?o.return:s[0]?o.throw||((n=o.return)&&n.call(o),0):o.next)&&!(n=n.call(o,s[1])).done)returnn;switch(o=0,n&&(s=[2&s[0],n.value]),s[0]){case0:case1:n=s;break;case4:returni.label++,{value:s[1],done:!1};case5:i.label++,o=s[1],s=[0];continue;case7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(n=(n=i.trys).length>0&&n[n.length-1])&&(6===s[0]||2===s[0])){i=0;continue}if(3===s[0]&&(!n||s[1]>n[0]&&s[1]<n[3])){i.label=s[1];break}if(6===s[0]&&i.label<n[1]){i.label=n[1],n=s;break}if(n&&i.label<n[2]){i.label=n[2],i.ops.push(s);break}n[2]&&i.ops.pop(),i.trys.pop();continue}s=e.call(t,i)}catch(u){s=[6,u],o=0}finally{r=n=0}if(5&s[0])throws[1];return{value:s[0]?s[1]:void0,done:!0}}([s,u])}}},r=this&&this.__importDefault||function(t){returnt&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.API=void0;varo=require("./util"),n=r(require("./logger")),s=function(){functionr(t){this._options=t}returnr.prototype._buildUrl=function(t){vare=(this._options.secure?"https://":"http://")+this._options.host+":"+this._options.port+this._options.path+this._options.key+"/"+t;returne+="?ts="+(newDate).getTime()+Math.random()},r.prototype.retrieveId=function(){returnt(this,void0,Promise,function(){vart,r,s,i;returne(this,function(e){switch(e.label){case0:t=this._buildUrl("id"),e.label=1;case1:returne.trys.push([1,3,,4]),[4,fetch(t)];case2:if(200!==(r=e.sent()).status)thrownewError("Error. Status:"+r.status);return[2,r.text()];case3:throws=e.sent(),n.default.error("Error retrieving ID",s),i="","/"===this._options.path&&this._options.host!==o.util.CLOUD_HOST&&(i=" If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."),newError("Could not get an ID from the server."+i);case4:return[2]}})})},r.prototype.listAllPeers=function(){returnt(this,void0,Promise,function(){vart,r,s,i;returne(this,function(e){switch(e.label){case0:t=this._buildUrl("peers"),e.label=1;case1:returne.trys.push([1,3,,4]),[4,fetch(t)];case2:if(200!==(r=e.sent()).status){if(401===r.status)throws="",s=this._options.host===o.util.CLOUD_HOST?"It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key.":"You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.",newError("It doesn't look like you have permission to list peers IDs. "+s);thrownewError("Error. Status:"+r.status)}return[2,r.json()];case3:throwi=e.sent(),n.default.error("Error retrieving list peers",i),newError("Could not get list peers from the server."+i);case4:return[2]}})})},r}();exports.API=s;
"use strict";vare=this&&this.__extends||function(){vare=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceofArray&&function(e,t){e.__proto__=t}||function(e,t){for(varnint)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(t,n)};returnfunction(t,n){if("function"!=typeofn&&null!==n)thrownewTypeError("Class extends value "+String(n)+" is not a constructor or null");functionr(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,newr)}}(),t=this&&this.__assign||function(){return(t=Object.assign||function(e){for(vart,n=1,r=arguments.length;n<r;n++)for(varoint=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);returne}).apply(this,arguments)},n=this&&this.__values||function(e){vart="function"==typeofSymbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)returnn.call(e);if(e&&"number"==typeofe.length)return{next:function(){returne&&r>=e.length&&(e=void0),{value:e&&e[r++],done:!e}}};thrownewTypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},r=this&&this.__read||function(e,t){varn="function"==typeofSymbol&&e[Symbol.iterator];if(!n)returne;varr,o,i=n.call(e),s=[];try{for(;(void0===t||t-->0)&&!(r=i.next()).done;)s.push(r.value)}catch(a){o={error:a}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throwo.error}}returns},o=this&&this.__importDefault||function(e){returne&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Peer=void0;vari=require("eventemitter3"),s=require("./util"),a=o(require("./logger")),c=require("./socket"),l=require("./mediaconnection"),u=require("./dataconnection"),d=require("./enums"),p=require("./api"),h=function(){returnfunction(){}}(),f=function(o){functioni(e,n){varr,c=o.call(this)||this;returnc._id=null,c._lastServerId=null,c._destroyed=!1,c._disconnected=!1,c._open=!1,c._connections=newMap,c._lostMessages=newMap,e&&e.constructor==Object?n=e:e&&(r=e.toString()),n=t({debug:0,host:s.util.CLOUD_HOST,port:s.util.CLOUD_PORT,path:"/",key:i.DEFAULT_KEY,token:s.util.randomToken(),config:s.util.defaultConfig},n),c._options=n,"/"===c._options.host&&(c._options.host=window.location.hostname),c._options.path&&("/"!==c._options.path[0]&&(c._options.path="/"+c._options.path),"/"!==c._options.path[c._options.path.length-1]&&(c._options.path+="/")),void0===c._options.secure&&c._options.host!==s.util.CLOUD_HOST?c._options.secure=s.util.isSecure():c._options.host==s.util.CLOUD_HOST&&(c._options.secure=!0),c._options.logFunction&&a.default.setLogFunction(c._options.logFunction),a.default.logLevel=c._options.debug||0,c._api=newp.API(n),c._socket=c._createServerConnection(),s.util.supports.audioVideo||s.util.supports.data?r&&!s.util.validateId(r)?(c._delayedAbort(d.PeerErrorType.InvalidID,'ID "'+r+'" is invalid'),c):(r?c._initialize(r):c._api.retrieveId().then(function(e){returnc._initialize(e)}).catch(function(e){returnc._abort(d.PeerErrorType.ServerError,e)}),c):(c._delayedAbort(d.PeerErrorType.BrowserIncompatible,"The current browser does not support WebRTC"),c)}returne(i,o),Object.defineProperty(i.prototype,"id",{get:function(){returnthis._id},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"options",{get:function(){returnthis._options},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"open",{get:function(){returnthis._open},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"socket",{get:function(){returnthis._socket},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"connections",{get:function(){vare,t,o=Object.create(null);try{for(vari=n(this._connections),s=i.next();!s.done;s=i.next()){vara=r(s.value,2),c=a[0],l=a[1];o[c]=l}}catch(u){e={error:u}}finally{try{s&&!s.done&&(t=i.return)&&t.call(i)}finally{if(e)throwe.error}}returno},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"destroyed",{get:function(){returnthis._destroyed},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"disconnected",{get:function(){returnthis._disc