- Track Needle/MenuScene/dist and Needle/SampleScene/dist for container deploys - Dockerfile copies pre-built dist (no npm in image); rebuild with npm run build before commit - Fix Needle .gitignore: /assets/ so dist/assets is not ignored - Git LFS: track *.wasm; relax .dockerignore so dist is sent as build context Made-with: Cursor
78 lines
137 KiB
JavaScript
78 lines
137 KiB
JavaScript
import{n as e,r as t,t as n}from"./rolldown-runtime.CYVBeYYp.js";var r=n(((e,t)=>{var n={};n.useBlobBuilder=(function(){try{return new Blob([]),!1}catch{return!0}})(),n.useArrayBufferView=!n.useBlobBuilder&&(function(){try{return new Blob([new Uint8Array([])]).size===0}catch{return!0}})(),t.exports.binaryFeatures=n;var r=t.exports.BlobBuilder;typeof window<`u`&&(r=t.exports.BlobBuilder=window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder||window.BlobBuilder);function i(){this._pieces=[],this._parts=[]}i.prototype.append=function(e){typeof e==`number`?this._pieces.push(e):(this.flush(),this._parts.push(e))},i.prototype.flush=function(){if(this._pieces.length>0){var e=new Uint8Array(this._pieces);n.useArrayBufferView||(e=e.buffer),this._parts.push(e),this._pieces=[]}},i.prototype.getBuffer=function(){if(this.flush(),n.useBlobBuilder){for(var e=new r,t=0,i=this._parts.length;t<i;t++)e.append(this._parts[t]);return e.getBlob()}else return new Blob(this._parts)},t.exports.BufferBuilder=i})),i=t(n(((e,t)=>{var n=r().BufferBuilder,i=r().binaryFeatures;t.exports={unpack:function(e){return new a(e).unpack()},pack:function(e){var t=new o;return t.pack(e),t.getBuffer()}};function a(e){this.index=0,this.dataBuffer=e,this.dataView=new Uint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}a.prototype.unpack=function(){var e=this.unpack_uint8();if(e<128)return e;if((e^224)<32)return(e^224)-32;var t;if((t=e^160)<=15)return this.unpack_raw(t);if((t=e^176)<=15)return this.unpack_string(t);if((t=e^144)<=15)return this.unpack_array(t);if((t=e^128)<=15)return this.unpack_map(t);switch(e){case 192:return null;case 193:return;case 194:return!1;case 195:return!0;case 202:return this.unpack_float();case 203:return this.unpack_double();case 204:return this.unpack_uint8();case 205:return this.unpack_uint16();case 206:return this.unpack_uint32();case 207:return this.unpack_uint64();case 208:return this.unpack_int8();case 209:return this.unpack_int16();case 210:return this.unpack_int32();case 211:return this.unpack_int64();case 212:return;case 213:return;case 214:return;case 215:return;case 216:return t=this.unpack_uint16(),this.unpack_string(t);case 217:return t=this.unpack_uint32(),this.unpack_string(t);case 218:return t=this.unpack_uint16(),this.unpack_raw(t);case 219:return t=this.unpack_uint32(),this.unpack_raw(t);case 220:return t=this.unpack_uint16(),this.unpack_array(t);case 221:return t=this.unpack_uint32(),this.unpack_array(t);case 222:return t=this.unpack_uint16(),this.unpack_map(t);case 223:return t=this.unpack_uint32(),this.unpack_map(t)}},a.prototype.unpack_uint8=function(){var e=this.dataView[this.index]&255;return this.index++,e},a.prototype.unpack_uint16=function(){var e=this.read(2),t=(e[0]&255)*256+(e[1]&255);return this.index+=2,t},a.prototype.unpack_uint32=function(){var e=this.read(4),t=((e[0]*256+e[1])*256+e[2])*256+e[3];return this.index+=4,t},a.prototype.unpack_uint64=function(){var e=this.read(8),t=((((((e[0]*256+e[1])*256+e[2])*256+e[3])*256+e[4])*256+e[5])*256+e[6])*256+e[7];return this.index+=8,t},a.prototype.unpack_int8=function(){var e=this.unpack_uint8();return e<128?e:e-256},a.prototype.unpack_int16=function(){var e=this.unpack_uint16();return e<32768?e:e-65536},a.prototype.unpack_int32=function(){var e=this.unpack_uint32();return e<2**31?e:e-2**32},a.prototype.unpack_int64=function(){var e=this.unpack_uint64();return e<2**63?e:e-2**64},a.prototype.unpack_raw=function(e){if(this.length<this.index+e)throw Error(`BinaryPackFailure: index is out of range `+this.index+` `+e+` `+this.length);var t=this.dataBuffer.slice(this.index,this.index+e);return this.index+=e,t},a.prototype.unpack_string=function(e){for(var t=this.read(e),n=0,r=``,i,a;n<e;)i=t[n],i<128?(r+=String.fromCharCode(i),n++):(i^192)<32?(a=(i^192)<<6|t[n+1]&63,r+=String.fromCharCode(a),n+=2):(a=(i&15)<<12|(t[n+1]&63)<<6|t[n+2]&63,r+=String.fromCharCode(a),n+=3);return this.index+=e,r},a.prototype.unpack_array=function(e){for(var t=Array(e),n=0;n<e;n++)t[n]=this.unpack();return t},a.prototype.unpack_map=function(e){for(var t={},n=0;n<e;n++){var r=this.unpack();t[r]=this.unpack()}return t},a.prototype.unpack_float=function(){var e=this.unpack_uint32(),t=e>>31,n=(e>>23&255)-127,r=e&8388607|8388608;return(t===0?1:-1)*r*2**(n-23)},a.prototype.unpack_double=function(){var e=this.unpack_uint32(),t=this.unpack_uint32(),n=e>>31,r=(e>>20&2047)-1023,i=(e&1048575|1048576)*2**(r-20)+t*2**(r-52);return(n===0?1:-1)*i},a.prototype.read=function(e){var t=this.index;if(t+e<=this.length)return this.dataView.subarray(t,t+e);throw Error(`BinaryPackFailure: read index out of range`)};function o(){this.bufferBuilder=new n}o.prototype.getBuffer=function(){return this.bufferBuilder.getBuffer()},o.prototype.pack=function(e){var t=typeof e;if(t===`string`)this.pack_string(e);else if(t===`number`)Math.floor(e)===e?this.pack_integer(e):this.pack_double(e);else if(t===`boolean`)e===!0?this.bufferBuilder.append(195):e===!1&&this.bufferBuilder.append(194);else if(t===`undefined`)this.bufferBuilder.append(192);else if(t===`object`)if(e===null)this.bufferBuilder.append(192);else{var n=e.constructor;if(n==Array)this.pack_array(e);else if(n==Blob||n==File||e instanceof Blob||e instanceof File)this.pack_bin(e);else if(n==ArrayBuffer)i.useArrayBufferView?this.pack_bin(new Uint8Array(e)):this.pack_bin(e);else if(`BYTES_PER_ELEMENT`in e)i.useArrayBufferView?this.pack_bin(new Uint8Array(e.buffer)):this.pack_bin(e.buffer);else if(n==Object||n.toString().startsWith(`class`))this.pack_object(e);else if(n==Date)this.pack_string(e.toString());else if(typeof e.toBinaryPack==`function`)this.bufferBuilder.append(e.toBinaryPack());else throw Error(`Type "`+n.toString()+`" not yet supported`)}else throw Error(`Type "`+t+`" not yet supported`);this.bufferBuilder.flush()},o.prototype.pack_bin=function(e){var t=e.length||e.byteLength||e.size;if(t<=15)this.pack_uint8(160+t);else if(t<=65535)this.bufferBuilder.append(218),this.pack_uint16(t);else if(t<=4294967295)this.bufferBuilder.append(219),this.pack_uint32(t);else throw Error(`Invalid length`);this.bufferBuilder.append(e)},o.prototype.pack_string=function(e){var t=c(e);if(t<=15)this.pack_uint8(176+t);else if(t<=65535)this.bufferBuilder.append(216),this.pack_uint16(t);else if(t<=4294967295)this.bufferBuilder.append(217),this.pack_uint32(t);else throw Error(`Invalid length`);this.bufferBuilder.append(e)},o.prototype.pack_array=function(e){var t=e.length;if(t<=15)this.pack_uint8(144+t);else if(t<=65535)this.bufferBuilder.append(220),this.pack_uint16(t);else if(t<=4294967295)this.bufferBuilder.append(221),this.pack_uint32(t);else throw Error(`Invalid length`);for(var n=0;n<t;n++)this.pack(e[n])},o.prototype.pack_integer=function(e){if(e>=-32&&e<=127)this.bufferBuilder.append(e&255);else if(e>=0&&e<=255)this.bufferBuilder.append(204),this.pack_uint8(e);else if(e>=-128&&e<=127)this.bufferBuilder.append(208),this.pack_int8(e);else if(e>=0&&e<=65535)this.bufferBuilder.append(205),this.pack_uint16(e);else if(e>=-32768&&e<=32767)this.bufferBuilder.append(209),this.pack_int16(e);else if(e>=0&&e<=4294967295)this.bufferBuilder.append(206),this.pack_uint32(e);else if(e>=-2147483648&&e<=2147483647)this.bufferBuilder.append(210),this.pack_int32(e);else if(e>=-0x8000000000000000&&e<=0x8000000000000000)this.bufferBuilder.append(211),this.pack_int64(e);else if(e>=0&&e<=0x10000000000000000)this.bufferBuilder.append(207),this.pack_uint64(e);else throw Error(`Invalid integer`)},o.prototype.pack_double=function(e){var t=0;e<0&&(t=1,e=-e);var n=Math.floor(Math.log(e)/Math.LN2),r=e/2**n-1,i=Math.floor(r*2**52),a=2**32,o=t<<31|n+1023<<20|i/a&1048575,s=i%a;this.bufferBuilder.append(203),this.pack_int32(o),this.pack_int32(s)},o.prototype.pack_object=function(e){var t=Object.keys(e).length;if(t<=15)this.pack_uint8(128+t);else if(t<=65535)this.bufferBuilder.append(222),this.pack_uint16(t);else if(t<=4294967295)this.bufferBuilder.append(223),this.pack_uint32(t);else throw Error(`Invalid length`);for(var n in e)e.hasOwnProperty(n)&&(this.pack(n),this.pack(e[n]))},o.prototype.pack_uint8=function(e){this.bufferBuilder.append(e)},o.prototype.pack_uint16=function(e){this.bufferBuilder.append(e>>8),this.bufferBuilder.append(e&255)},o.prototype.pack_uint32=function(e){var t=e&4294967295;this.bufferBuilder.append((t&4278190080)>>>24),this.bufferBuilder.append((t&16711680)>>>16),this.bufferBuilder.append((t&65280)>>>8),this.bufferBuilder.append(t&255)},o.prototype.pack_uint64=function(e){var t=e/2**32,n=e%2**32;this.bufferBuilder.append((t&4278190080)>>>24),this.bufferBuilder.append((t&16711680)>>>16),this.bufferBuilder.append((t&65280)>>>8),this.bufferBuilder.append(t&255),this.bufferBuilder.append((n&4278190080)>>>24),this.bufferBuilder.append((n&16711680)>>>16),this.bufferBuilder.append((n&65280)>>>8),this.bufferBuilder.append(n&255)},o.prototype.pack_int8=function(e){this.bufferBuilder.append(e&255)},o.prototype.pack_int16=function(e){this.bufferBuilder.append((e&65280)>>8),this.bufferBuilder.append(e&255)},o.prototype.pack_int32=function(e){this.bufferBuilder.append(e>>>24&255),this.bufferBuilder.append((e&16711680)>>>16),this.bufferBuilder.append((e&65280)>>>8),this.bufferBuilder.append(e&255)},o.prototype.pack_int64=function(e){var t=Math.floor(e/2**32),n=e%2**32;this.bufferBuilder.append((t&4278190080)>>>24),this.bufferBuilder.append((t&16711680)>>>16),this.bufferBuilder.append((t&65280)>>>8),this.bufferBuilder.append(t&255),this.bufferBuilder.append((n&4278190080)>>>24),this.bufferBuilder.append((n&16711680)>>>16),this.bufferBuilder.append((n&65280)>>>8),this.bufferBuilder.append(n&255)};function s(e){var t=e.charCodeAt(0);return t<=2047?`00`:t<=65535?`000`:t<=2097151?`0000`:t<=67108863?`00000`:`000000`}function c(e){return e.length>600?new Blob([e]).size:e.replace(/[^\u0000-\u007F]/g,s).length}}))(),1),a=!0,o=!0;function s(e,t,n){let r=e.match(t);return r&&r.length>=n&&parseInt(r[n],10)}function c(e,t,n){if(!e.RTCPeerConnection)return;let r=e.RTCPeerConnection.prototype,i=r.addEventListener;r.addEventListener=function(e,r){if(e!==t)return i.apply(this,arguments);let a=e=>{let t=n(e);t&&(r.handleEvent?r.handleEvent(t):r(t))};return this._eventMap=this._eventMap||{},this._eventMap[t]||(this._eventMap[t]=new Map),this._eventMap[t].set(r,a),i.apply(this,[e,a])};let a=r.removeEventListener;r.removeEventListener=function(e,n){if(e!==t||!this._eventMap||!this._eventMap[t]||!this._eventMap[t].has(n))return a.apply(this,arguments);let r=this._eventMap[t].get(n);return this._eventMap[t].delete(n),this._eventMap[t].size===0&&delete this._eventMap[t],Object.keys(this._eventMap).length===0&&delete this._eventMap,a.apply(this,[e,r])},Object.defineProperty(r,`on`+t,{get(){return this[`_on`+t]},set(e){this[`_on`+t]&&(this.removeEventListener(t,this[`_on`+t]),delete this[`_on`+t]),e&&this.addEventListener(t,this[`_on`+t]=e)},enumerable:!0,configurable:!0})}function l(e){return typeof e==`boolean`?(a=e,e?`adapter.js logging disabled`:`adapter.js logging enabled`):Error(`Argument type: `+typeof e+`. Please use a boolean.`)}function u(e){return typeof e==`boolean`?(o=!e,`adapter.js deprecation warnings `+(e?`disabled`:`enabled`)):Error(`Argument type: `+typeof e+`. Please use a boolean.`)}function d(){if(typeof window==`object`){if(a)return;typeof console<`u`&&typeof console.log==`function`&&console.log.apply(console,arguments)}}function f(e,t){o&&console.warn(e+` is deprecated, please use `+t+` instead.`)}function p(e){let t={browser:null,version:null};if(e===void 0||!e.navigator)return t.browser=`Not a browser.`,t;let{navigator:n}=e;if(n.mozGetUserMedia)t.browser=`firefox`,t.version=s(n.userAgent,/Firefox\/(\d+)\./,1);else if(n.webkitGetUserMedia||e.isSecureContext===!1&&e.webkitRTCPeerConnection&&!e.RTCIceGatherer)t.browser=`chrome`,t.version=s(n.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(n.mediaDevices&&n.userAgent.match(/Edge\/(\d+).(\d+)$/))t.browser=`edge`,t.version=s(n.userAgent,/Edge\/(\d+).(\d+)$/,2);else if(e.RTCPeerConnection&&n.userAgent.match(/AppleWebKit\/(\d+)\./))t.browser=`safari`,t.version=s(n.userAgent,/AppleWebKit\/(\d+)\./,1),t.supportsUnifiedPlan=e.RTCRtpTransceiver&&`currentDirection`in e.RTCRtpTransceiver.prototype;else return t.browser=`Not a supported browser.`,t;return t}function m(e){return Object.prototype.toString.call(e)===`[object Object]`}function h(e){return m(e)?Object.keys(e).reduce(function(t,n){let r=m(e[n]),i=r?h(e[n]):e[n],a=r&&!Object.keys(i).length;return i===void 0||a?t:Object.assign(t,{[n]:i})},{}):e}function ee(e,t,n){!t||n.has(t.id)||(n.set(t.id,t),Object.keys(t).forEach(r=>{r.endsWith(`Id`)?ee(e,e.get(t[r]),n):r.endsWith(`Ids`)&&t[r].forEach(t=>{ee(e,e.get(t),n)})}))}function g(e,t,n){let r=n?`outbound-rtp`:`inbound-rtp`,i=new Map;if(t===null)return i;let a=[];return e.forEach(e=>{e.type===`track`&&e.trackIdentifier===t.id&&a.push(e)}),a.forEach(t=>{e.forEach(n=>{n.type===r&&n.trackId===t.id&&ee(e,n,i)})}),i}var _=d;function v(e,t){let n=e&&e.navigator;if(!n.mediaDevices)return;let r=function(e){if(typeof e!=`object`||e.mandatory||e.optional)return e;let t={};return Object.keys(e).forEach(n=>{if(n===`require`||n===`advanced`||n===`mediaSource`)return;let r=typeof e[n]==`object`?e[n]:{ideal:e[n]};r.exact!==void 0&&typeof r.exact==`number`&&(r.min=r.max=r.exact);let i=function(e,t){return e?e+t.charAt(0).toUpperCase()+t.slice(1):t===`deviceId`?`sourceId`:t};if(r.ideal!==void 0){t.optional=t.optional||[];let e={};typeof r.ideal==`number`?(e[i(`min`,n)]=r.ideal,t.optional.push(e),e={},e[i(`max`,n)]=r.ideal,t.optional.push(e)):(e[i(``,n)]=r.ideal,t.optional.push(e))}r.exact!==void 0&&typeof r.exact!=`number`?(t.mandatory=t.mandatory||{},t.mandatory[i(``,n)]=r.exact):[`min`,`max`].forEach(e=>{r[e]!==void 0&&(t.mandatory=t.mandatory||{},t.mandatory[i(e,n)]=r[e])})}),e.advanced&&(t.optional=(t.optional||[]).concat(e.advanced)),t},i=function(e,i){if(t.version>=61)return i(e);if(e=JSON.parse(JSON.stringify(e)),e&&typeof e.audio==`object`){let t=function(e,t,n){t in e&&!(n in e)&&(e[n]=e[t],delete e[t])};e=JSON.parse(JSON.stringify(e)),t(e.audio,`autoGainControl`,`googAutoGainControl`),t(e.audio,`noiseSuppression`,`googNoiseSuppression`),e.audio=r(e.audio)}if(e&&typeof e.video==`object`){let a=e.video.facingMode;a&&=typeof a==`object`?a:{ideal:a};let o=t.version<66;if(a&&(a.exact===`user`||a.exact===`environment`||a.ideal===`user`||a.ideal===`environment`)&&!(n.mediaDevices.getSupportedConstraints&&n.mediaDevices.getSupportedConstraints().facingMode&&!o)){delete e.video.facingMode;let t;if(a.exact===`environment`||a.ideal===`environment`?t=[`back`,`rear`]:(a.exact===`user`||a.ideal===`user`)&&(t=[`front`]),t)return n.mediaDevices.enumerateDevices().then(n=>{n=n.filter(e=>e.kind===`videoinput`);let o=n.find(e=>t.some(t=>e.label.toLowerCase().includes(t)));return!o&&n.length&&t.includes(`back`)&&(o=n[n.length-1]),o&&(e.video.deviceId=a.exact?{exact:o.deviceId}:{ideal:o.deviceId}),e.video=r(e.video),_(`chrome: `+JSON.stringify(e)),i(e)})}e.video=r(e.video)}return _(`chrome: `+JSON.stringify(e)),i(e)},a=function(e){return t.version>=64?e:{name:{PermissionDeniedError:`NotAllowedError`,PermissionDismissedError:`NotAllowedError`,InvalidStateError:`NotAllowedError`,DevicesNotFoundError:`NotFoundError`,ConstraintNotSatisfiedError:`OverconstrainedError`,TrackStartError:`NotReadableError`,MediaDeviceFailedDueToShutdown:`NotAllowedError`,MediaDeviceKillSwitchOn:`NotAllowedError`,TabCaptureError:`AbortError`,ScreenCaptureError:`AbortError`,DeviceCaptureError:`AbortError`}[e.name]||e.name,message:e.message,constraint:e.constraint||e.constraintName,toString(){return this.name+(this.message&&`: `)+this.message}}};if(n.getUserMedia=function(e,t,r){i(e,e=>{n.webkitGetUserMedia(e,t,e=>{r&&r(a(e))})})}.bind(n),n.mediaDevices.getUserMedia){let e=n.mediaDevices.getUserMedia.bind(n.mediaDevices);Object.getOwnPropertyDescriptor(n.mediaDevices,`getUserMedia`)?.writable&&(n.mediaDevices.getUserMedia=function(t){return i(t,t=>e(t).then(e=>{if(t.audio&&!e.getAudioTracks().length||t.video&&!e.getVideoTracks().length)throw e.getTracks().forEach(e=>{e.stop()}),new DOMException(``,`NotFoundError`);return e},e=>Promise.reject(a(e))))})}}function y(e,t){if(!(e.navigator.mediaDevices&&`getDisplayMedia`in e.navigator.mediaDevices)&&e.navigator.mediaDevices){if(typeof t!=`function`){console.error(`shimGetDisplayMedia: getSourceId argument is not a function`);return}e.navigator.mediaDevices.getDisplayMedia=function(n){return t(n).then(t=>{let r=n.video&&n.video.width,i=n.video&&n.video.height;return n.video={mandatory:{chromeMediaSource:`desktop`,chromeMediaSourceId:t,maxFrameRate:n.video&&n.video.frameRate||3}},r&&(n.video.mandatory.maxWidth=r),i&&(n.video.mandatory.maxHeight=i),e.navigator.mediaDevices.getUserMedia(n)})}}}var b=e({fixNegotiationNeeded:()=>D,shimAddTrackRemoveTrack:()=>T,shimAddTrackRemoveTrackWithNative:()=>w,shimGetDisplayMedia:()=>y,shimGetSendersWithDtmf:()=>ne,shimGetStats:()=>S,shimGetUserMedia:()=>v,shimMediaStream:()=>te,shimOnTrack:()=>x,shimPeerConnection:()=>E,shimSenderReceiverGetStats:()=>C});function te(e){e.MediaStream=e.MediaStream||e.webkitMediaStream}function x(e){if(typeof e==`object`&&e.RTCPeerConnection&&!(`ontrack`in e.RTCPeerConnection.prototype)){Object.defineProperty(e.RTCPeerConnection.prototype,`ontrack`,{get(){return this._ontrack},set(e){this._ontrack&&this.removeEventListener(`track`,this._ontrack),this.addEventListener(`track`,this._ontrack=e)},enumerable:!0,configurable:!0});let t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=t=>{t.stream.addEventListener(`addtrack`,n=>{let r;r=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find(e=>e.track&&e.track.id===n.track.id):{track:n.track};let i=new Event(`track`);i.track=n.track,i.receiver=r,i.transceiver={receiver:r},i.streams=[t.stream],this.dispatchEvent(i)}),t.stream.getTracks().forEach(n=>{let r;r=e.RTCPeerConnection.prototype.getReceivers?this.getReceivers().find(e=>e.track&&e.track.id===n.id):{track:n};let i=new Event(`track`);i.track=n,i.receiver=r,i.transceiver={receiver:r},i.streams=[t.stream],this.dispatchEvent(i)})},this.addEventListener(`addstream`,this._ontrackpoly)),t.apply(this,arguments)}}else c(e,`track`,e=>(e.transceiver||Object.defineProperty(e,`transceiver`,{value:{receiver:e.receiver}}),e))}function ne(e){if(typeof e==`object`&&e.RTCPeerConnection&&!(`getSenders`in e.RTCPeerConnection.prototype)&&`createDTMFSender`in e.RTCPeerConnection.prototype){let t=function(e,t){return{track:t,get dtmf(){return this._dtmf===void 0&&(t.kind===`audio`?this._dtmf=e.createDTMFSender(t):this._dtmf=null),this._dtmf},_pc:e}};if(!e.RTCPeerConnection.prototype.getSenders){e.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};let n=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,r){let i=n.apply(this,arguments);return i||(i=t(this,e),this._senders.push(i)),i};let r=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){r.apply(this,arguments);let t=this._senders.indexOf(e);t!==-1&&this._senders.splice(t,1)}}let n=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){this._senders=this._senders||[],n.apply(this,[e]),e.getTracks().forEach(e=>{this._senders.push(t(this,e))})};let r=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){this._senders=this._senders||[],r.apply(this,[e]),e.getTracks().forEach(e=>{let t=this._senders.find(t=>t.track===e);t&&this._senders.splice(this._senders.indexOf(t),1)})}}else if(typeof e==`object`&&e.RTCPeerConnection&&`getSenders`in e.RTCPeerConnection.prototype&&`createDTMFSender`in e.RTCPeerConnection.prototype&&e.RTCRtpSender&&!(`dtmf`in e.RTCRtpSender.prototype)){let t=e.RTCPeerConnection.prototype.getSenders;e.RTCPeerConnection.prototype.getSenders=function(){let e=t.apply(this,[]);return e.forEach(e=>e._pc=this),e},Object.defineProperty(e.RTCRtpSender.prototype,`dtmf`,{get(){return this._dtmf===void 0&&(this.track.kind===`audio`?this._dtmf=this._pc.createDTMFSender(this.track):this._dtmf=null),this._dtmf}})}}function S(e){if(!e.RTCPeerConnection)return;let t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){let[e,n,r]=arguments;if(arguments.length>0&&typeof e==`function`)return t.apply(this,arguments);if(t.length===0&&(arguments.length===0||typeof e!=`function`))return t.apply(this,[]);let i=function(e){let t={};return e.result().forEach(e=>{let n={id:e.id,timestamp:e.timestamp,type:{localcandidate:`local-candidate`,remotecandidate:`remote-candidate`}[e.type]||e.type};e.names().forEach(t=>{n[t]=e.stat(t)}),t[n.id]=n}),t},a=function(e){return new Map(Object.keys(e).map(t=>[t,e[t]]))};return arguments.length>=2?t.apply(this,[function(e){n(a(i(e)))},e]):new Promise((e,n)=>{t.apply(this,[function(t){e(a(i(t)))},n])}).then(n,r)}}function C(e){if(!(typeof e==`object`&&e.RTCPeerConnection&&e.RTCRtpSender&&e.RTCRtpReceiver))return;if(!(`getStats`in e.RTCRtpSender.prototype)){let t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){let e=t.apply(this,[]);return e.forEach(e=>e._pc=this),e});let n=e.RTCPeerConnection.prototype.addTrack;n&&(e.RTCPeerConnection.prototype.addTrack=function(){let e=n.apply(this,arguments);return e._pc=this,e}),e.RTCRtpSender.prototype.getStats=function(){let e=this;return this._pc.getStats().then(t=>g(t,e.track,!0))}}if(!(`getStats`in e.RTCRtpReceiver.prototype)){let t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){let e=t.apply(this,[]);return e.forEach(e=>e._pc=this),e}),c(e,`track`,e=>(e.receiver._pc=e.srcElement,e)),e.RTCRtpReceiver.prototype.getStats=function(){let e=this;return this._pc.getStats().then(t=>g(t,e.track,!1))}}if(!(`getStats`in e.RTCRtpSender.prototype&&`getStats`in e.RTCRtpReceiver.prototype))return;let t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof e.MediaStreamTrack){let e=arguments[0],t,n,r;return this.getSenders().forEach(n=>{n.track===e&&(t?r=!0:t=n)}),this.getReceivers().forEach(t=>(t.track===e&&(n?r=!0:n=t),t.track===e)),r||t&&n?Promise.reject(new DOMException(`There are more than one sender or receiver for the track.`,`InvalidAccessError`)):t?t.getStats():n?n.getStats():Promise.reject(new DOMException(`There is no sender or receiver for the track.`,`InvalidAccessError`))}return t.apply(this,arguments)}}function w(e){e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(e=>this._shimmedLocalStreams[e][0])};let t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(e,n){if(!n)return t.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};let r=t.apply(this,arguments);return this._shimmedLocalStreams[n.id]?this._shimmedLocalStreams[n.id].indexOf(r)===-1&&this._shimmedLocalStreams[n.id].push(r):this._shimmedLocalStreams[n.id]=[n,r],r};let n=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(e){this._shimmedLocalStreams=this._shimmedLocalStreams||{},e.getTracks().forEach(e=>{if(this.getSenders().find(t=>t.track===e))throw new DOMException(`Track already exists.`,`InvalidAccessError`)});let t=this.getSenders();n.apply(this,arguments);let r=this.getSenders().filter(e=>t.indexOf(e)===-1);this._shimmedLocalStreams[e.id]=[e].concat(r)};let r=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[e.id],r.apply(this,arguments)};let i=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(e){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},e&&Object.keys(this._shimmedLocalStreams).forEach(t=>{let n=this._shimmedLocalStreams[t].indexOf(e);n!==-1&&this._shimmedLocalStreams[t].splice(n,1),this._shimmedLocalStreams[t].length===1&&delete this._shimmedLocalStreams[t]}),i.apply(this,arguments)}}function T(e,t){if(!e.RTCPeerConnection)return;if(e.RTCPeerConnection.prototype.addTrack&&t.version>=65)return w(e);let n=e.RTCPeerConnection.prototype.getLocalStreams;e.RTCPeerConnection.prototype.getLocalStreams=function(){let e=n.apply(this);return this._reverseStreams=this._reverseStreams||{},e.map(e=>this._reverseStreams[e.id])};let r=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(t){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},t.getTracks().forEach(e=>{if(this.getSenders().find(t=>t.track===e))throw new DOMException(`Track already exists.`,`InvalidAccessError`)}),!this._reverseStreams[t.id]){let n=new e.MediaStream(t.getTracks());this._streams[t.id]=n,this._reverseStreams[n.id]=t,t=n}r.apply(this,[t])};let i=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(e){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},i.apply(this,[this._streams[e.id]||e]),delete this._reverseStreams[this._streams[e.id]?this._streams[e.id].id:e.id],delete this._streams[e.id]},e.RTCPeerConnection.prototype.addTrack=function(t,n){if(this.signalingState===`closed`)throw new DOMException(`The RTCPeerConnection's signalingState is 'closed'.`,`InvalidStateError`);let r=[].slice.call(arguments,1);if(r.length!==1||!r[0].getTracks().find(e=>e===t))throw new DOMException(`The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.`,`NotSupportedError`);if(this.getSenders().find(e=>e.track===t))throw new DOMException(`Track already exists.`,`InvalidAccessError`);this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};let i=this._streams[n.id];if(i)i.addTrack(t),Promise.resolve().then(()=>{this.dispatchEvent(new Event(`negotiationneeded`))});else{let r=new e.MediaStream([t]);this._streams[n.id]=r,this._reverseStreams[r.id]=n,this.addStream(r)}return this.getSenders().find(e=>e.track===t)};function a(e,t){let n=t.sdp;return Object.keys(e._reverseStreams||[]).forEach(t=>{let r=e._reverseStreams[t],i=e._streams[r.id];n=n.replace(new RegExp(i.id,`g`),r.id)}),new RTCSessionDescription({type:t.type,sdp:n})}function o(e,t){let n=t.sdp;return Object.keys(e._reverseStreams||[]).forEach(t=>{let r=e._reverseStreams[t],i=e._streams[r.id];n=n.replace(new RegExp(r.id,`g`),i.id)}),new RTCSessionDescription({type:t.type,sdp:n})}[`createOffer`,`createAnswer`].forEach(function(t){let n=e.RTCPeerConnection.prototype[t],r={[t](){let e=arguments;return arguments.length&&typeof arguments[0]==`function`?n.apply(this,[t=>{let n=a(this,t);e[0].apply(null,[n])},t=>{e[1]&&e[1].apply(null,t)},arguments[2]]):n.apply(this,arguments).then(e=>a(this,e))}};e.RTCPeerConnection.prototype[t]=r[t]});let s=e.RTCPeerConnection.prototype.setLocalDescription;e.RTCPeerConnection.prototype.setLocalDescription=function(){return!arguments.length||!arguments[0].type||(arguments[0]=o(this,arguments[0])),s.apply(this,arguments)};let c=Object.getOwnPropertyDescriptor(e.RTCPeerConnection.prototype,`localDescription`);Object.defineProperty(e.RTCPeerConnection.prototype,`localDescription`,{get(){let e=c.get.apply(this);return e.type===``?e:a(this,e)}}),e.RTCPeerConnection.prototype.removeTrack=function(e){if(this.signalingState===`closed`)throw new DOMException(`The RTCPeerConnection's signalingState is 'closed'.`,`InvalidStateError`);if(!e._pc)throw new DOMException(`Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.`,`TypeError`);if(e._pc!==this)throw new DOMException(`Sender was not created by this connection.`,`InvalidAccessError`);this._streams=this._streams||{};let t;Object.keys(this._streams).forEach(n=>{this._streams[n].getTracks().find(t=>e.track===t)&&(t=this._streams[n])}),t&&(t.getTracks().length===1?this.removeStream(this._reverseStreams[t.id]):t.removeTrack(e.track),this.dispatchEvent(new Event(`negotiationneeded`)))}}function E(e,t){!e.RTCPeerConnection&&e.webkitRTCPeerConnection&&(e.RTCPeerConnection=e.webkitRTCPeerConnection),e.RTCPeerConnection&&t.version<53&&[`setLocalDescription`,`setRemoteDescription`,`addIceCandidate`].forEach(function(t){let n=e.RTCPeerConnection.prototype[t],r={[t](){return arguments[0]=new(t===`addIceCandidate`?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),n.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=r[t]})}function D(e,t){c(e,`negotiationneeded`,e=>{let n=e.target;if(!((t.version<72||n.getConfiguration&&n.getConfiguration().sdpSemantics===`plan-b`)&&n.signalingState!==`stable`))return e})}function O(e,t){let n=!1;return e=JSON.parse(JSON.stringify(e)),e.filter(e=>{if(e&&(e.urls||e.url)){let t=e.urls||e.url;e.url&&!e.urls&&f(`RTCIceServer.url`,`RTCIceServer.urls`);let r=typeof t==`string`;return r&&(t=[t]),t=t.filter(e=>{if(e.indexOf(`stun:`)===0)return!1;let t=e.startsWith(`turn`)&&!e.startsWith(`turn:[`)&&e.includes(`transport=udp`);return t&&!n?(n=!0,!0):t&&!n}),delete e.url,e.urls=r?t[0]:t,!!t.length}})}var re=n(((e,t)=>{var n={};n.generateIdentifier=function(){return Math.random().toString(36).substr(2,10)},n.localCName=n.generateIdentifier(),n.splitLines=function(e){return e.trim().split(`
|
|
`).map(function(e){return e.trim()})},n.splitSections=function(e){return e.split(`
|
|
m=`).map(function(e,t){return(t>0?`m=`+e:e).trim()+`\r
|
|
`})},n.getDescription=function(e){var t=n.splitSections(e);return t&&t[0]},n.getMediaSections=function(e){var t=n.splitSections(e);return t.shift(),t},n.matchPrefix=function(e,t){return n.splitLines(e).filter(function(e){return e.indexOf(t)===0})},n.parseCandidate=function(e){for(var t=e.indexOf(`a=candidate:`)===0?e.substring(12).split(` `):e.substring(10).split(` `),n={foundation:t[0],component:parseInt(t[1],10),protocol:t[2].toLowerCase(),priority:parseInt(t[3],10),ip:t[4],address:t[4],port:parseInt(t[5],10),type:t[7]},r=8;r<t.length;r+=2)switch(t[r]){case`raddr`:n.relatedAddress=t[r+1];break;case`rport`:n.relatedPort=parseInt(t[r+1],10);break;case`tcptype`:n.tcpType=t[r+1];break;case`ufrag`:n.ufrag=t[r+1],n.usernameFragment=t[r+1];break;default:n[t[r]]=t[r+1];break}return n},n.writeCandidate=function(e){var t=[];t.push(e.foundation),t.push(e.component),t.push(e.protocol.toUpperCase()),t.push(e.priority),t.push(e.address||e.ip),t.push(e.port);var n=e.type;return t.push(`typ`),t.push(n),n!==`host`&&e.relatedAddress&&e.relatedPort&&(t.push(`raddr`),t.push(e.relatedAddress),t.push(`rport`),t.push(e.relatedPort)),e.tcpType&&e.protocol.toLowerCase()===`tcp`&&(t.push(`tcptype`),t.push(e.tcpType)),(e.usernameFragment||e.ufrag)&&(t.push(`ufrag`),t.push(e.usernameFragment||e.ufrag)),`candidate:`+t.join(` `)},n.parseIceOptions=function(e){return e.substr(14).split(` `)},n.parseRtpMap=function(e){var t=e.substr(9).split(` `),n={payloadType:parseInt(t.shift(),10)};return t=t[0].split(`/`),n.name=t[0],n.clockRate=parseInt(t[1],10),n.channels=t.length===3?parseInt(t[2],10):1,n.numChannels=n.channels,n},n.writeRtpMap=function(e){var t=e.payloadType;e.preferredPayloadType!==void 0&&(t=e.preferredPayloadType);var n=e.channels||e.numChannels||1;return`a=rtpmap:`+t+` `+e.name+`/`+e.clockRate+(n===1?``:`/`+n)+`\r
|
|
`},n.parseExtmap=function(e){var t=e.substr(9).split(` `);return{id:parseInt(t[0],10),direction:t[0].indexOf(`/`)>0?t[0].split(`/`)[1]:`sendrecv`,uri:t[1]}},n.writeExtmap=function(e){return`a=extmap:`+(e.id||e.preferredId)+(e.direction&&e.direction!==`sendrecv`?`/`+e.direction:``)+` `+e.uri+`\r
|
|
`},n.parseFmtp=function(e){for(var t={},n,r=e.substr(e.indexOf(` `)+1).split(`;`),i=0;i<r.length;i++)n=r[i].trim().split(`=`),t[n[0].trim()]=n[1];return t},n.writeFmtp=function(e){var t=``,n=e.payloadType;if(e.preferredPayloadType!==void 0&&(n=e.preferredPayloadType),e.parameters&&Object.keys(e.parameters).length){var r=[];Object.keys(e.parameters).forEach(function(t){e.parameters[t]?r.push(t+`=`+e.parameters[t]):r.push(t)}),t+=`a=fmtp:`+n+` `+r.join(`;`)+`\r
|
|
`}return t},n.parseRtcpFb=function(e){var t=e.substr(e.indexOf(` `)+1).split(` `);return{type:t.shift(),parameter:t.join(` `)}},n.writeRtcpFb=function(e){var t=``,n=e.payloadType;return e.preferredPayloadType!==void 0&&(n=e.preferredPayloadType),e.rtcpFeedback&&e.rtcpFeedback.length&&e.rtcpFeedback.forEach(function(e){t+=`a=rtcp-fb:`+n+` `+e.type+(e.parameter&&e.parameter.length?` `+e.parameter:``)+`\r
|
|
`}),t},n.parseSsrcMedia=function(e){var t=e.indexOf(` `),n={ssrc:parseInt(e.substr(7,t-7),10)},r=e.indexOf(`:`,t);return r>-1?(n.attribute=e.substr(t+1,r-t-1),n.value=e.substr(r+1)):n.attribute=e.substr(t+1),n},n.parseSsrcGroup=function(e){var t=e.substr(13).split(` `);return{semantics:t.shift(),ssrcs:t.map(function(e){return parseInt(e,10)})}},n.getMid=function(e){var t=n.matchPrefix(e,`a=mid:`)[0];if(t)return t.substr(6)},n.parseFingerprint=function(e){var t=e.substr(14).split(` `);return{algorithm:t[0].toLowerCase(),value:t[1]}},n.getDtlsParameters=function(e,t){return{role:`auto`,fingerprints:n.matchPrefix(e+t,`a=fingerprint:`).map(n.parseFingerprint)}},n.writeDtlsParameters=function(e,t){var n=`a=setup:`+t+`\r
|
|
`;return e.fingerprints.forEach(function(e){n+=`a=fingerprint:`+e.algorithm+` `+e.value+`\r
|
|
`}),n},n.parseCryptoLine=function(e){var t=e.substr(9).split(` `);return{tag:parseInt(t[0],10),cryptoSuite:t[1],keyParams:t[2],sessionParams:t.slice(3)}},n.writeCryptoLine=function(e){return`a=crypto:`+e.tag+` `+e.cryptoSuite+` `+(typeof e.keyParams==`object`?n.writeCryptoKeyParams(e.keyParams):e.keyParams)+(e.sessionParams?` `+e.sessionParams.join(` `):``)+`\r
|
|
`},n.parseCryptoKeyParams=function(e){if(e.indexOf(`inline:`)!==0)return null;var t=e.substr(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}},n.writeCryptoKeyParams=function(e){return e.keyMethod+`:`+e.keySalt+(e.lifeTime?`|`+e.lifeTime:``)+(e.mkiValue&&e.mkiLength?`|`+e.mkiValue+`:`+e.mkiLength:``)},n.getCryptoParameters=function(e,t){return n.matchPrefix(e+t,`a=crypto:`).map(n.parseCryptoLine)},n.getIceParameters=function(e,t){var r=n.matchPrefix(e+t,`a=ice-ufrag:`)[0],i=n.matchPrefix(e+t,`a=ice-pwd:`)[0];return r&&i?{usernameFragment:r.substr(12),password:i.substr(10)}:null},n.writeIceParameters=function(e){return`a=ice-ufrag:`+e.usernameFragment+`\r
|
|
a=ice-pwd:`+e.password+`\r
|
|
`},n.parseRtpParameters=function(e){for(var t={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},r=n.splitLines(e)[0].split(` `),i=3;i<r.length;i++){var a=r[i],o=n.matchPrefix(e,`a=rtpmap:`+a+` `)[0];if(o){var s=n.parseRtpMap(o),c=n.matchPrefix(e,`a=fmtp:`+a+` `);switch(s.parameters=c.length?n.parseFmtp(c[0]):{},s.rtcpFeedback=n.matchPrefix(e,`a=rtcp-fb:`+a+` `).map(n.parseRtcpFb),t.codecs.push(s),s.name.toUpperCase()){case`RED`:case`ULPFEC`:t.fecMechanisms.push(s.name.toUpperCase());break;default:break}}}return n.matchPrefix(e,`a=extmap:`).forEach(function(e){t.headerExtensions.push(n.parseExtmap(e))}),t},n.writeRtpDescription=function(e,t){var r=``;r+=`m=`+e+` `,r+=t.codecs.length>0?`9`:`0`,r+=` UDP/TLS/RTP/SAVPF `,r+=t.codecs.map(function(e){return e.preferredPayloadType===void 0?e.payloadType:e.preferredPayloadType}).join(` `)+`\r
|
|
`,r+=`c=IN IP4 0.0.0.0\r
|
|
`,r+=`a=rtcp:9 IN IP4 0.0.0.0\r
|
|
`,t.codecs.forEach(function(e){r+=n.writeRtpMap(e),r+=n.writeFmtp(e),r+=n.writeRtcpFb(e)});var i=0;return t.codecs.forEach(function(e){e.maxptime>i&&(i=e.maxptime)}),i>0&&(r+=`a=maxptime:`+i+`\r
|
|
`),r+=`a=rtcp-mux\r
|
|
`,t.headerExtensions&&t.headerExtensions.forEach(function(e){r+=n.writeExtmap(e)}),r},n.parseRtpEncodingParameters=function(e){var t=[],r=n.parseRtpParameters(e),i=r.fecMechanisms.indexOf(`RED`)!==-1,a=r.fecMechanisms.indexOf(`ULPFEC`)!==-1,o=n.matchPrefix(e,`a=ssrc:`).map(function(e){return n.parseSsrcMedia(e)}).filter(function(e){return e.attribute===`cname`}),s=o.length>0&&o[0].ssrc,c,l=n.matchPrefix(e,`a=ssrc-group:FID`).map(function(e){return e.substr(17).split(` `).map(function(e){return parseInt(e,10)})});l.length>0&&l[0].length>1&&l[0][0]===s&&(c=l[0][1]),r.codecs.forEach(function(e){if(e.name.toUpperCase()===`RTX`&&e.parameters.apt){var n={ssrc:s,codecPayloadType:parseInt(e.parameters.apt,10)};s&&c&&(n.rtx={ssrc:c}),t.push(n),i&&(n=JSON.parse(JSON.stringify(n)),n.fec={ssrc:s,mechanism:a?`red+ulpfec`:`red`},t.push(n))}}),t.length===0&&s&&t.push({ssrc:s});var u=n.matchPrefix(e,`b=`);return u.length&&(u=u[0].indexOf(`b=TIAS:`)===0?parseInt(u[0].substr(7),10):u[0].indexOf(`b=AS:`)===0?parseInt(u[0].substr(5),10)*1e3*.95-2e3*8:void 0,t.forEach(function(e){e.maxBitrate=u})),t},n.parseRtcpParameters=function(e){var t={},r=n.matchPrefix(e,`a=ssrc:`).map(function(e){return n.parseSsrcMedia(e)}).filter(function(e){return e.attribute===`cname`})[0];r&&(t.cname=r.value,t.ssrc=r.ssrc);var i=n.matchPrefix(e,`a=rtcp-rsize`);return t.reducedSize=i.length>0,t.compound=i.length===0,t.mux=n.matchPrefix(e,`a=rtcp-mux`).length>0,t},n.parseMsid=function(e){var t,r=n.matchPrefix(e,`a=msid:`);if(r.length===1)return t=r[0].substr(7).split(` `),{stream:t[0],track:t[1]};var i=n.matchPrefix(e,`a=ssrc:`).map(function(e){return n.parseSsrcMedia(e)}).filter(function(e){return e.attribute===`msid`});if(i.length>0)return t=i[0].value.split(` `),{stream:t[0],track:t[1]}},n.parseSctpDescription=function(e){var t=n.parseMLine(e),r=n.matchPrefix(e,`a=max-message-size:`),i;r.length>0&&(i=parseInt(r[0].substr(19),10)),isNaN(i)&&(i=65536);var a=n.matchPrefix(e,`a=sctp-port:`);if(a.length>0)return{port:parseInt(a[0].substr(12),10),protocol:t.fmt,maxMessageSize:i};if(n.matchPrefix(e,`a=sctpmap:`).length>0){var o=n.matchPrefix(e,`a=sctpmap:`)[0].substr(10).split(` `);return{port:parseInt(o[0],10),protocol:o[1],maxMessageSize:i}}},n.writeSctpDescription=function(e,t){var n=[];return n=e.protocol===`DTLS/SCTP`?[`m=`+e.kind+` 9 `+e.protocol+` `+t.port+`\r
|
|
`,`c=IN IP4 0.0.0.0\r
|
|
`,`a=sctpmap:`+t.port+` `+t.protocol+` 65535\r
|
|
`]:[`m=`+e.kind+` 9 `+e.protocol+` `+t.protocol+`\r
|
|
`,`c=IN IP4 0.0.0.0\r
|
|
`,`a=sctp-port:`+t.port+`\r
|
|
`],t.maxMessageSize!==void 0&&n.push(`a=max-message-size:`+t.maxMessageSize+`\r
|
|
`),n.join(``)},n.generateSessionId=function(){return Math.random().toString().substr(2,21)},n.writeSessionBoilerplate=function(e,t,r){var i,a=t===void 0?2:t;return i=e||n.generateSessionId(),`v=0\r
|
|
o=`+(r||`thisisadapterortc`)+` `+i+` `+a+` IN IP4 127.0.0.1\r
|
|
s=-\r
|
|
t=0 0\r
|
|
`},n.writeMediaSection=function(e,t,r,i){var a=n.writeRtpDescription(e.kind,t);if(a+=n.writeIceParameters(e.iceGatherer.getLocalParameters()),a+=n.writeDtlsParameters(e.dtlsTransport.getLocalParameters(),r===`offer`?`actpass`:`active`),a+=`a=mid:`+e.mid+`\r
|
|
`,e.direction?a+=`a=`+e.direction+`\r
|
|
`:e.rtpSender&&e.rtpReceiver?a+=`a=sendrecv\r
|
|
`:e.rtpSender?a+=`a=sendonly\r
|
|
`:e.rtpReceiver?a+=`a=recvonly\r
|
|
`:a+=`a=inactive\r
|
|
`,e.rtpSender){var o=`msid:`+i.id+` `+e.rtpSender.track.id+`\r
|
|
`;a+=`a=`+o,a+=`a=ssrc:`+e.sendEncodingParameters[0].ssrc+` `+o,e.sendEncodingParameters[0].rtx&&(a+=`a=ssrc:`+e.sendEncodingParameters[0].rtx.ssrc+` `+o,a+=`a=ssrc-group:FID `+e.sendEncodingParameters[0].ssrc+` `+e.sendEncodingParameters[0].rtx.ssrc+`\r
|
|
`)}return a+=`a=ssrc:`+e.sendEncodingParameters[0].ssrc+` cname:`+n.localCName+`\r
|
|
`,e.rtpSender&&e.sendEncodingParameters[0].rtx&&(a+=`a=ssrc:`+e.sendEncodingParameters[0].rtx.ssrc+` cname:`+n.localCName+`\r
|
|
`),a},n.getDirection=function(e,t){for(var r=n.splitLines(e),i=0;i<r.length;i++)switch(r[i]){case`a=sendrecv`:case`a=sendonly`:case`a=recvonly`:case`a=inactive`:return r[i].substr(2);default:}return t?n.getDirection(t):`sendrecv`},n.getKind=function(e){return n.splitLines(e)[0].split(` `)[0].substr(2)},n.isRejected=function(e){return e.split(` `,2)[1]===`0`},n.parseMLine=function(e){var t=n.splitLines(e)[0].substr(2).split(` `);return{kind:t[0],port:parseInt(t[1],10),protocol:t[2],fmt:t.slice(3).join(` `)}},n.parseOLine=function(e){var t=n.matchPrefix(e,`o=`)[0].substr(2).split(` `);return{username:t[0],sessionId:t[1],sessionVersion:parseInt(t[2],10),netType:t[3],addressType:t[4],address:t[5]}},n.isValidSDP=function(e){if(typeof e!=`string`||e.length===0)return!1;for(var t=n.splitLines(e),r=0;r<t.length;r++)if(t[r].length<2||t[r].charAt(1)!==`=`)return!1;return!0},typeof t==`object`&&(t.exports=n)})),ie=t(n(((e,t)=>{var n=re();function r(e){return{inboundrtp:`inbound-rtp`,outboundrtp:`outbound-rtp`,candidatepair:`candidate-pair`,localcandidate:`local-candidate`,remotecandidate:`remote-candidate`}[e.type]||e.type}function i(e,t,r,i,a){var o=n.writeRtpDescription(e.kind,t);if(o+=n.writeIceParameters(e.iceGatherer.getLocalParameters()),o+=n.writeDtlsParameters(e.dtlsTransport.getLocalParameters(),r===`offer`?`actpass`:a||`active`),o+=`a=mid:`+e.mid+`\r
|
|
`,e.rtpSender&&e.rtpReceiver?o+=`a=sendrecv\r
|
|
`:e.rtpSender?o+=`a=sendonly\r
|
|
`:e.rtpReceiver?o+=`a=recvonly\r
|
|
`:o+=`a=inactive\r
|
|
`,e.rtpSender){var s=e.rtpSender._initialTrackId||e.rtpSender.track.id;e.rtpSender._initialTrackId=s;var c=`msid:`+(i?i.id:`-`)+` `+s+`\r
|
|
`;o+=`a=`+c,o+=`a=ssrc:`+e.sendEncodingParameters[0].ssrc+` `+c,e.sendEncodingParameters[0].rtx&&(o+=`a=ssrc:`+e.sendEncodingParameters[0].rtx.ssrc+` `+c,o+=`a=ssrc-group:FID `+e.sendEncodingParameters[0].ssrc+` `+e.sendEncodingParameters[0].rtx.ssrc+`\r
|
|
`)}return o+=`a=ssrc:`+e.sendEncodingParameters[0].ssrc+` cname:`+n.localCName+`\r
|
|
`,e.rtpSender&&e.sendEncodingParameters[0].rtx&&(o+=`a=ssrc:`+e.sendEncodingParameters[0].rtx.ssrc+` cname:`+n.localCName+`\r
|
|
`),o}function a(e,t){var n=!1;return e=JSON.parse(JSON.stringify(e)),e.filter(function(e){if(e&&(e.urls||e.url)){var r=e.urls||e.url;e.url&&!e.urls&&console.warn(`RTCIceServer.url is deprecated! Use urls instead.`);var i=typeof r==`string`;return i&&(r=[r]),r=r.filter(function(e){return e.indexOf(`turn:`)===0&&e.indexOf(`transport=udp`)!==-1&&e.indexOf(`turn:[`)===-1&&!n?(n=!0,!0):e.indexOf(`stun:`)===0&&t>=14393&&e.indexOf(`?transport=udp`)===-1}),delete e.url,e.urls=i?r[0]:r,!!r.length}})}function o(e,t){var n={codecs:[],headerExtensions:[],fecMechanisms:[]},r=function(e,t){e=parseInt(e,10);for(var n=0;n<t.length;n++)if(t[n].payloadType===e||t[n].preferredPayloadType===e)return t[n]},i=function(e,t,n,i){var a=r(e.parameters.apt,n),o=r(t.parameters.apt,i);return a&&o&&a.name.toLowerCase()===o.name.toLowerCase()};return e.codecs.forEach(function(r){for(var a=0;a<t.codecs.length;a++){var o=t.codecs[a];if(r.name.toLowerCase()===o.name.toLowerCase()&&r.clockRate===o.clockRate){if(r.name.toLowerCase()===`rtx`&&r.parameters&&o.parameters.apt&&!i(r,o,e.codecs,t.codecs))continue;o=JSON.parse(JSON.stringify(o)),o.numChannels=Math.min(r.numChannels,o.numChannels),n.codecs.push(o),o.rtcpFeedback=o.rtcpFeedback.filter(function(e){for(var t=0;t<r.rtcpFeedback.length;t++)if(r.rtcpFeedback[t].type===e.type&&r.rtcpFeedback[t].parameter===e.parameter)return!0;return!1});break}}}),e.headerExtensions.forEach(function(e){for(var r=0;r<t.headerExtensions.length;r++){var i=t.headerExtensions[r];if(e.uri===i.uri){n.headerExtensions.push(i);break}}}),n}function s(e,t,n){return{offer:{setLocalDescription:[`stable`,`have-local-offer`],setRemoteDescription:[`stable`,`have-remote-offer`]},answer:{setLocalDescription:[`have-remote-offer`,`have-local-pranswer`],setRemoteDescription:[`have-local-offer`,`have-remote-pranswer`]}}[t][e].indexOf(n)!==-1}function c(e,t){var n=e.getRemoteCandidates().find(function(e){return t.foundation===e.foundation&&t.ip===e.ip&&t.port===e.port&&t.priority===e.priority&&t.protocol===e.protocol&&t.type===e.type});return n||e.addRemoteCandidate(t),!n}function l(e,t){var n=Error(t);return n.name=e,n.code={NotSupportedError:9,InvalidStateError:11,InvalidAccessError:15,TypeError:void 0,OperationError:void 0}[e],n}t.exports=function(e,t){function u(t,n){n.addTrack(t),n.dispatchEvent(new e.MediaStreamTrackEvent(`addtrack`,{track:t}))}function d(t,n){n.removeTrack(t),n.dispatchEvent(new e.MediaStreamTrackEvent(`removetrack`,{track:t}))}function f(t,n,r,i){var a=new Event(`track`);a.track=n,a.receiver=r,a.transceiver={receiver:r},a.streams=i,e.setTimeout(function(){t._dispatchEvent(`track`,a)})}var p=function(r){var i=this,o=document.createDocumentFragment();if([`addEventListener`,`removeEventListener`,`dispatchEvent`].forEach(function(e){i[e]=o[e].bind(o)}),this.canTrickleIceCandidates=null,this.needNegotiation=!1,this.localStreams=[],this.remoteStreams=[],this._localDescription=null,this._remoteDescription=null,this.signalingState=`stable`,this.iceConnectionState=`new`,this.connectionState=`new`,this.iceGatheringState=`new`,r=JSON.parse(JSON.stringify(r||{})),this.usingBundle=r.bundlePolicy===`max-bundle`,r.rtcpMuxPolicy===`negotiate`)throw l(`NotSupportedError`,`rtcpMuxPolicy 'negotiate' is not supported`);switch(r.rtcpMuxPolicy||=`require`,r.iceTransportPolicy){case`all`:case`relay`:break;default:r.iceTransportPolicy=`all`;break}switch(r.bundlePolicy){case`balanced`:case`max-compat`:case`max-bundle`:break;default:r.bundlePolicy=`balanced`;break}if(r.iceServers=a(r.iceServers||[],t),this._iceGatherers=[],r.iceCandidatePoolSize)for(var s=r.iceCandidatePoolSize;s>0;s--)this._iceGatherers.push(new e.RTCIceGatherer({iceServers:r.iceServers,gatherPolicy:r.iceTransportPolicy}));else r.iceCandidatePoolSize=0;this._config=r,this.transceivers=[],this._sdpSessionId=n.generateSessionId(),this._sdpSessionVersion=0,this._dtlsRole=void 0,this._isClosed=!1};Object.defineProperty(p.prototype,`localDescription`,{configurable:!0,get:function(){return this._localDescription}}),Object.defineProperty(p.prototype,`remoteDescription`,{configurable:!0,get:function(){return this._remoteDescription}}),p.prototype.onicecandidate=null,p.prototype.onaddstream=null,p.prototype.ontrack=null,p.prototype.onremovestream=null,p.prototype.onsignalingstatechange=null,p.prototype.oniceconnectionstatechange=null,p.prototype.onconnectionstatechange=null,p.prototype.onicegatheringstatechange=null,p.prototype.onnegotiationneeded=null,p.prototype.ondatachannel=null,p.prototype._dispatchEvent=function(e,t){this._isClosed||(this.dispatchEvent(t),typeof this[`on`+e]==`function`&&this[`on`+e](t))},p.prototype._emitGatheringStateChange=function(){var e=new Event(`icegatheringstatechange`);this._dispatchEvent(`icegatheringstatechange`,e)},p.prototype.getConfiguration=function(){return this._config},p.prototype.getLocalStreams=function(){return this.localStreams},p.prototype.getRemoteStreams=function(){return this.remoteStreams},p.prototype._createTransceiver=function(e,t){var n=this.transceivers.length>0,r={track:null,iceGatherer:null,iceTransport:null,dtlsTransport:null,localCapabilities:null,remoteCapabilities:null,rtpSender:null,rtpReceiver:null,kind:e,mid:null,sendEncodingParameters:null,recvEncodingParameters:null,stream:null,associatedRemoteMediaStreams:[],wantReceive:!0};if(this.usingBundle&&n)r.iceTransport=this.transceivers[0].iceTransport,r.dtlsTransport=this.transceivers[0].dtlsTransport;else{var i=this._createIceAndDtlsTransports();r.iceTransport=i.iceTransport,r.dtlsTransport=i.dtlsTransport}return t||this.transceivers.push(r),r},p.prototype.addTrack=function(t,n){if(this._isClosed)throw l(`InvalidStateError`,`Attempted to call addTrack on a closed peerconnection.`);if(this.transceivers.find(function(e){return e.track===t}))throw l(`InvalidAccessError`,`Track already exists.`);for(var r,i=0;i<this.transceivers.length;i++)!this.transceivers[i].track&&this.transceivers[i].kind===t.kind&&(r=this.transceivers[i]);return r||=this._createTransceiver(t.kind),this._maybeFireNegotiationNeeded(),this.localStreams.indexOf(n)===-1&&this.localStreams.push(n),r.track=t,r.stream=n,r.rtpSender=new e.RTCRtpSender(t,r.dtlsTransport),r.rtpSender},p.prototype.addStream=function(e){var n=this;if(t>=15025)e.getTracks().forEach(function(t){n.addTrack(t,e)});else{var r=e.clone();e.getTracks().forEach(function(e,t){var n=r.getTracks()[t];e.addEventListener(`enabled`,function(e){n.enabled=e.enabled})}),r.getTracks().forEach(function(e){n.addTrack(e,r)})}},p.prototype.removeTrack=function(t){if(this._isClosed)throw l(`InvalidStateError`,`Attempted to call removeTrack on a closed peerconnection.`);if(!(t instanceof e.RTCRtpSender))throw TypeError(`Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.`);var n=this.transceivers.find(function(e){return e.rtpSender===t});if(!n)throw l(`InvalidAccessError`,`Sender was not created by this connection.`);var r=n.stream;n.rtpSender.stop(),n.rtpSender=null,n.track=null,n.stream=null,this.transceivers.map(function(e){return e.stream}).indexOf(r)===-1&&this.localStreams.indexOf(r)>-1&&this.localStreams.splice(this.localStreams.indexOf(r),1),this._maybeFireNegotiationNeeded()},p.prototype.removeStream=function(e){var t=this;e.getTracks().forEach(function(e){var n=t.getSenders().find(function(t){return t.track===e});n&&t.removeTrack(n)})},p.prototype.getSenders=function(){return this.transceivers.filter(function(e){return!!e.rtpSender}).map(function(e){return e.rtpSender})},p.prototype.getReceivers=function(){return this.transceivers.filter(function(e){return!!e.rtpReceiver}).map(function(e){return e.rtpReceiver})},p.prototype._createIceGatherer=function(t,n){var r=this;if(n&&t>0)return this.transceivers[0].iceGatherer;if(this._iceGatherers.length)return this._iceGatherers.shift();var i=new e.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(i,`state`,{value:`new`,writable:!0}),this.transceivers[t].bufferedCandidateEvents=[],this.transceivers[t].bufferCandidates=function(e){i.state=!e.candidate||Object.keys(e.candidate).length===0?`completed`:`gathering`,r.transceivers[t].bufferedCandidateEvents!==null&&r.transceivers[t].bufferedCandidateEvents.push(e)},i.addEventListener(`localcandidate`,this.transceivers[t].bufferCandidates),i},p.prototype._gather=function(t,r){var i=this,a=this.transceivers[r].iceGatherer;if(!a.onlocalcandidate){var o=this.transceivers[r].bufferedCandidateEvents;this.transceivers[r].bufferedCandidateEvents=null,a.removeEventListener(`localcandidate`,this.transceivers[r].bufferCandidates),a.onlocalcandidate=function(e){if(!(i.usingBundle&&r>0)){var o=new Event(`icecandidate`);o.candidate={sdpMid:t,sdpMLineIndex:r};var s=e.candidate,c=!s||Object.keys(s).length===0;if(c)(a.state===`new`||a.state===`gathering`)&&(a.state=`completed`);else{a.state===`new`&&(a.state=`gathering`),s.component=1,s.ufrag=a.getLocalParameters().usernameFragment;var l=n.writeCandidate(s);o.candidate=Object.assign(o.candidate,n.parseCandidate(l)),o.candidate.candidate=l,o.candidate.toJSON=function(){return{candidate:o.candidate.candidate,sdpMid:o.candidate.sdpMid,sdpMLineIndex:o.candidate.sdpMLineIndex,usernameFragment:o.candidate.usernameFragment}}}var u=n.getMediaSections(i._localDescription.sdp);c?u[o.candidate.sdpMLineIndex]+=`a=end-of-candidates\r
|
|
`:u[o.candidate.sdpMLineIndex]+=`a=`+o.candidate.candidate+`\r
|
|
`,i._localDescription.sdp=n.getDescription(i._localDescription.sdp)+u.join(``);var d=i.transceivers.every(function(e){return e.iceGatherer&&e.iceGatherer.state===`completed`});i.iceGatheringState!==`gathering`&&(i.iceGatheringState=`gathering`,i._emitGatheringStateChange()),c||i._dispatchEvent(`icecandidate`,o),d&&(i._dispatchEvent(`icecandidate`,new Event(`icecandidate`)),i.iceGatheringState=`complete`,i._emitGatheringStateChange())}},e.setTimeout(function(){o.forEach(function(e){a.onlocalcandidate(e)})},0)}},p.prototype._createIceAndDtlsTransports=function(){var t=this,n=new e.RTCIceTransport(null);n.onicestatechange=function(){t._updateIceConnectionState(),t._updateConnectionState()};var r=new e.RTCDtlsTransport(n);return r.ondtlsstatechange=function(){t._updateConnectionState()},r.onerror=function(){Object.defineProperty(r,`state`,{value:`failed`,writable:!0}),t._updateConnectionState()},{iceTransport:n,dtlsTransport:r}},p.prototype._disposeIceAndDtlsTransports=function(e){var t=this.transceivers[e].iceGatherer;t&&(delete t.onlocalcandidate,delete this.transceivers[e].iceGatherer);var n=this.transceivers[e].iceTransport;n&&(delete n.onicestatechange,delete this.transceivers[e].iceTransport);var r=this.transceivers[e].dtlsTransport;r&&(delete r.ondtlsstatechange,delete r.onerror,delete this.transceivers[e].dtlsTransport)},p.prototype._transceive=function(e,r,i){var a=o(e.localCapabilities,e.remoteCapabilities);r&&e.rtpSender&&(a.encodings=e.sendEncodingParameters,a.rtcp={cname:n.localCName,compound:e.rtcpParameters.compound},e.recvEncodingParameters.length&&(a.rtcp.ssrc=e.recvEncodingParameters[0].ssrc),e.rtpSender.send(a)),i&&e.rtpReceiver&&a.codecs.length>0&&(e.kind===`video`&&e.recvEncodingParameters&&t<15019&&e.recvEncodingParameters.forEach(function(e){delete e.rtx}),e.recvEncodingParameters.length?a.encodings=e.recvEncodingParameters:a.encodings=[{}],a.rtcp={compound:e.rtcpParameters.compound},e.rtcpParameters.cname&&(a.rtcp.cname=e.rtcpParameters.cname),e.sendEncodingParameters.length&&(a.rtcp.ssrc=e.sendEncodingParameters[0].ssrc),e.rtpReceiver.receive(a))},p.prototype.setLocalDescription=function(e){var t=this;if([`offer`,`answer`].indexOf(e.type)===-1)return Promise.reject(l(`TypeError`,`Unsupported type "`+e.type+`"`));if(!s(`setLocalDescription`,e.type,t.signalingState)||t._isClosed)return Promise.reject(l(`InvalidStateError`,`Can not set local `+e.type+` in state `+t.signalingState));var r,i;if(e.type===`offer`)r=n.splitSections(e.sdp),i=r.shift(),r.forEach(function(e,r){var i=n.parseRtpParameters(e);t.transceivers[r].localCapabilities=i}),t.transceivers.forEach(function(e,n){t._gather(e.mid,n)});else if(e.type===`answer`){r=n.splitSections(t._remoteDescription.sdp),i=r.shift();var a=n.matchPrefix(i,`a=ice-lite`).length>0;r.forEach(function(e,r){var s=t.transceivers[r],c=s.iceGatherer,l=s.iceTransport,u=s.dtlsTransport,d=s.localCapabilities,f=s.remoteCapabilities;if(!(n.isRejected(e)&&n.matchPrefix(e,`a=bundle-only`).length===0)&&!s.rejected){var p=n.getIceParameters(e,i),m=n.getDtlsParameters(e,i);a&&(m.role=`server`),(!t.usingBundle||r===0)&&(t._gather(s.mid,r),l.state===`new`&&l.start(c,p,a?`controlling`:`controlled`),u.state===`new`&&u.start(m));var h=o(d,f);t._transceive(s,h.codecs.length>0,!1)}})}return t._localDescription={type:e.type,sdp:e.sdp},e.type===`offer`?t._updateSignalingState(`have-local-offer`):t._updateSignalingState(`stable`),Promise.resolve()},p.prototype.setRemoteDescription=function(r){var i=this;if([`offer`,`answer`].indexOf(r.type)===-1)return Promise.reject(l(`TypeError`,`Unsupported type "`+r.type+`"`));if(!s(`setRemoteDescription`,r.type,i.signalingState)||i._isClosed)return Promise.reject(l(`InvalidStateError`,`Can not set remote `+r.type+` in state `+i.signalingState));var a={};i.remoteStreams.forEach(function(e){a[e.id]=e});var p=[],m=n.splitSections(r.sdp),h=m.shift(),ee=n.matchPrefix(h,`a=ice-lite`).length>0,g=n.matchPrefix(h,`a=group:BUNDLE `).length>0;i.usingBundle=g;var _=n.matchPrefix(h,`a=ice-options:`)[0];return _?i.canTrickleIceCandidates=_.substr(14).split(` `).indexOf(`trickle`)>=0:i.canTrickleIceCandidates=!1,m.forEach(function(s,l){var f=n.splitLines(s),m=n.getKind(s),_=n.isRejected(s)&&n.matchPrefix(s,`a=bundle-only`).length===0,v=f[0].substr(2).split(` `)[2],y=n.getDirection(s,h),b=n.parseMsid(s),te=n.getMid(s)||n.generateIdentifier();if(_||m===`application`&&(v===`DTLS/SCTP`||v===`UDP/DTLS/SCTP`)){i.transceivers[l]={mid:te,kind:m,protocol:v,rejected:!0};return}!_&&i.transceivers[l]&&i.transceivers[l].rejected&&(i.transceivers[l]=i._createTransceiver(m,!0));var x,ne,S,C,w,T,E,D,O,re=n.parseRtpParameters(s),ie,k;_||(ie=n.getIceParameters(s,h),k=n.getDtlsParameters(s,h),k.role=`client`),E=n.parseRtpEncodingParameters(s);var ae=n.parseRtcpParameters(s),oe=n.matchPrefix(s,`a=end-of-candidates`,h).length>0,A=n.matchPrefix(s,`a=candidate:`).map(function(e){return n.parseCandidate(e)}).filter(function(e){return e.component===1});if((r.type===`offer`||r.type===`answer`)&&!_&&g&&l>0&&i.transceivers[l]&&(i._disposeIceAndDtlsTransports(l),i.transceivers[l].iceGatherer=i.transceivers[0].iceGatherer,i.transceivers[l].iceTransport=i.transceivers[0].iceTransport,i.transceivers[l].dtlsTransport=i.transceivers[0].dtlsTransport,i.transceivers[l].rtpSender&&i.transceivers[l].rtpSender.setTransport(i.transceivers[0].dtlsTransport),i.transceivers[l].rtpReceiver&&i.transceivers[l].rtpReceiver.setTransport(i.transceivers[0].dtlsTransport)),r.type===`offer`&&!_){x=i.transceivers[l]||i._createTransceiver(m),x.mid=te,x.iceGatherer||=i._createIceGatherer(l,g),A.length&&x.iceTransport.state===`new`&&(oe&&(!g||l===0)?x.iceTransport.setRemoteCandidates(A):A.forEach(function(e){c(x.iceTransport,e)})),D=e.RTCRtpReceiver.getCapabilities(m),t<15019&&(D.codecs=D.codecs.filter(function(e){return e.name!==`rtx`})),T=x.sendEncodingParameters||[{ssrc:(2*l+2)*1001}];var j=!1;if(y===`sendrecv`||y===`sendonly`){if(j=!x.rtpReceiver,w=x.rtpReceiver||new e.RTCRtpReceiver(x.dtlsTransport,m),j){var M;O=w.track,b&&b.stream===`-`||(b?(a[b.stream]||(a[b.stream]=new e.MediaStream,Object.defineProperty(a[b.stream],`id`,{get:function(){return b.stream}})),Object.defineProperty(O,`id`,{get:function(){return b.track}}),M=a[b.stream]):(a.default||=new e.MediaStream,M=a.default)),M&&(u(O,M),x.associatedRemoteMediaStreams.push(M)),p.push([O,w,M])}}else x.rtpReceiver&&x.rtpReceiver.track&&(x.associatedRemoteMediaStreams.forEach(function(e){var t=e.getTracks().find(function(e){return e.id===x.rtpReceiver.track.id});t&&d(t,e)}),x.associatedRemoteMediaStreams=[]);x.localCapabilities=D,x.remoteCapabilities=re,x.rtpReceiver=w,x.rtcpParameters=ae,x.sendEncodingParameters=T,x.recvEncodingParameters=E,i._transceive(i.transceivers[l],!1,j)}else r.type===`answer`&&!_&&(x=i.transceivers[l],ne=x.iceGatherer,S=x.iceTransport,C=x.dtlsTransport,w=x.rtpReceiver,T=x.sendEncodingParameters,D=x.localCapabilities,i.transceivers[l].recvEncodingParameters=E,i.transceivers[l].remoteCapabilities=re,i.transceivers[l].rtcpParameters=ae,A.length&&S.state===`new`&&((ee||oe)&&(!g||l===0)?S.setRemoteCandidates(A):A.forEach(function(e){c(x.iceTransport,e)})),(!g||l===0)&&(S.state===`new`&&S.start(ne,ie,`controlling`),C.state===`new`&&C.start(k)),!o(x.localCapabilities,x.remoteCapabilities).codecs.filter(function(e){return e.name.toLowerCase()===`rtx`}).length&&x.sendEncodingParameters[0].rtx&&delete x.sendEncodingParameters[0].rtx,i._transceive(x,y===`sendrecv`||y===`recvonly`,y===`sendrecv`||y===`sendonly`),w&&(y===`sendrecv`||y===`sendonly`)?(O=w.track,b?(a[b.stream]||(a[b.stream]=new e.MediaStream),u(O,a[b.stream]),p.push([O,w,a[b.stream]])):(a.default||=new e.MediaStream,u(O,a.default),p.push([O,w,a.default]))):delete x.rtpReceiver)}),i._dtlsRole===void 0&&(i._dtlsRole=r.type===`offer`?`active`:`passive`),i._remoteDescription={type:r.type,sdp:r.sdp},r.type===`offer`?i._updateSignalingState(`have-remote-offer`):i._updateSignalingState(`stable`),Object.keys(a).forEach(function(t){var n=a[t];if(n.getTracks().length){if(i.remoteStreams.indexOf(n)===-1){i.remoteStreams.push(n);var r=new Event(`addstream`);r.stream=n,e.setTimeout(function(){i._dispatchEvent(`addstream`,r)})}p.forEach(function(e){var t=e[0],r=e[1];n.id===e[2].id&&f(i,t,r,[n])})}}),p.forEach(function(e){e[2]||f(i,e[0],e[1],[])}),e.setTimeout(function(){i&&i.transceivers&&i.transceivers.forEach(function(e){e.iceTransport&&e.iceTransport.state===`new`&&e.iceTransport.getRemoteCandidates().length>0&&(console.warn(`Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification`),e.iceTransport.addRemoteCandidate({}))})},4e3),Promise.resolve()},p.prototype.close=function(){this.transceivers.forEach(function(e){e.iceTransport&&e.iceTransport.stop(),e.dtlsTransport&&e.dtlsTransport.stop(),e.rtpSender&&e.rtpSender.stop(),e.rtpReceiver&&e.rtpReceiver.stop()}),this._isClosed=!0,this._updateSignalingState(`closed`)},p.prototype._updateSignalingState=function(e){this.signalingState=e;var t=new Event(`signalingstatechange`);this._dispatchEvent(`signalingstatechange`,t)},p.prototype._maybeFireNegotiationNeeded=function(){var t=this;this.signalingState!==`stable`||this.needNegotiation===!0||(this.needNegotiation=!0,e.setTimeout(function(){if(t.needNegotiation){t.needNegotiation=!1;var e=new Event(`negotiationneeded`);t._dispatchEvent(`negotiationneeded`,e)}},0))},p.prototype._updateIceConnectionState=function(){var e,t={new:0,closed:0,checking:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(e){e.iceTransport&&!e.rejected&&t[e.iceTransport.state]++}),e=`new`,t.failed>0?e=`failed`:t.checking>0?e=`checking`:t.disconnected>0?e=`disconnected`:t.new>0?e=`new`:t.connected>0?e=`connected`:t.completed>0&&(e=`completed`),e!==this.iceConnectionState){this.iceConnectionState=e;var n=new Event(`iceconnectionstatechange`);this._dispatchEvent(`iceconnectionstatechange`,n)}},p.prototype._updateConnectionState=function(){var e,t={new:0,closed:0,connecting:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(e){e.iceTransport&&e.dtlsTransport&&!e.rejected&&(t[e.iceTransport.state]++,t[e.dtlsTransport.state]++)}),t.connected+=t.completed,e=`new`,t.failed>0?e=`failed`:t.connecting>0?e=`connecting`:t.disconnected>0?e=`disconnected`:t.new>0?e=`new`:t.connected>0&&(e=`connected`),e!==this.connectionState){this.connectionState=e;var n=new Event(`connectionstatechange`);this._dispatchEvent(`connectionstatechange`,n)}},p.prototype.createOffer=function(){var r=this;if(r._isClosed)return Promise.reject(l(`InvalidStateError`,`Can not call createOffer after close`));var a=r.transceivers.filter(function(e){return e.kind===`audio`}).length,o=r.transceivers.filter(function(e){return e.kind===`video`}).length,s=arguments[0];if(s){if(s.mandatory||s.optional)throw TypeError(`Legacy mandatory/optional constraints not supported.`);s.offerToReceiveAudio!==void 0&&(a=s.offerToReceiveAudio===!0?1:s.offerToReceiveAudio===!1?0:s.offerToReceiveAudio),s.offerToReceiveVideo!==void 0&&(o=s.offerToReceiveVideo===!0?1:s.offerToReceiveVideo===!1?0:s.offerToReceiveVideo)}for(r.transceivers.forEach(function(e){e.kind===`audio`?(a--,a<0&&(e.wantReceive=!1)):e.kind===`video`&&(o--,o<0&&(e.wantReceive=!1))});a>0||o>0;)a>0&&(r._createTransceiver(`audio`),a--),o>0&&(r._createTransceiver(`video`),o--);var c=n.writeSessionBoilerplate(r._sdpSessionId,r._sdpSessionVersion++);r.transceivers.forEach(function(i,a){var o=i.track,s=i.kind;i.mid=i.mid||n.generateIdentifier(),i.iceGatherer||=r._createIceGatherer(a,r.usingBundle);var c=e.RTCRtpSender.getCapabilities(s);t<15019&&(c.codecs=c.codecs.filter(function(e){return e.name!==`rtx`})),c.codecs.forEach(function(e){e.name===`H264`&&e.parameters[`level-asymmetry-allowed`]===void 0&&(e.parameters[`level-asymmetry-allowed`]=`1`),i.remoteCapabilities&&i.remoteCapabilities.codecs&&i.remoteCapabilities.codecs.forEach(function(t){e.name.toLowerCase()===t.name.toLowerCase()&&e.clockRate===t.clockRate&&(e.preferredPayloadType=t.payloadType)})}),c.headerExtensions.forEach(function(e){(i.remoteCapabilities&&i.remoteCapabilities.headerExtensions||[]).forEach(function(t){e.uri===t.uri&&(e.id=t.id)})});var l=i.sendEncodingParameters||[{ssrc:(2*a+1)*1001}];o&&t>=15019&&s===`video`&&!l[0].rtx&&(l[0].rtx={ssrc:l[0].ssrc+1}),i.wantReceive&&(i.rtpReceiver=new e.RTCRtpReceiver(i.dtlsTransport,s)),i.localCapabilities=c,i.sendEncodingParameters=l}),r._config.bundlePolicy!==`max-compat`&&(c+=`a=group:BUNDLE `+r.transceivers.map(function(e){return e.mid}).join(` `)+`\r
|
|
`),c+=`a=ice-options:trickle\r
|
|
`,r.transceivers.forEach(function(e,t){c+=i(e,e.localCapabilities,`offer`,e.stream,r._dtlsRole),c+=`a=rtcp-rsize\r
|
|
`,e.iceGatherer&&r.iceGatheringState!==`new`&&(t===0||!r.usingBundle)&&(e.iceGatherer.getLocalCandidates().forEach(function(e){e.component=1,c+=`a=`+n.writeCandidate(e)+`\r
|
|
`}),e.iceGatherer.state===`completed`&&(c+=`a=end-of-candidates\r
|
|
`))});var u=new e.RTCSessionDescription({type:`offer`,sdp:c});return Promise.resolve(u)},p.prototype.createAnswer=function(){var r=this;if(r._isClosed)return Promise.reject(l(`InvalidStateError`,`Can not call createAnswer after close`));if(!(r.signalingState===`have-remote-offer`||r.signalingState===`have-local-pranswer`))return Promise.reject(l(`InvalidStateError`,`Can not call createAnswer in signalingState `+r.signalingState));var a=n.writeSessionBoilerplate(r._sdpSessionId,r._sdpSessionVersion++);r.usingBundle&&(a+=`a=group:BUNDLE `+r.transceivers.map(function(e){return e.mid}).join(` `)+`\r
|
|
`),a+=`a=ice-options:trickle\r
|
|
`;var s=n.getMediaSections(r._remoteDescription.sdp).length;r.transceivers.forEach(function(e,n){if(!(n+1>s)){if(e.rejected){e.kind===`application`?e.protocol===`DTLS/SCTP`?a+=`m=application 0 DTLS/SCTP 5000\r
|
|
`:a+=`m=application 0 `+e.protocol+` webrtc-datachannel\r
|
|
`:e.kind===`audio`?a+=`m=audio 0 UDP/TLS/RTP/SAVPF 0\r
|
|
a=rtpmap:0 PCMU/8000\r
|
|
`:e.kind===`video`&&(a+=`m=video 0 UDP/TLS/RTP/SAVPF 120\r
|
|
a=rtpmap:120 VP8/90000\r
|
|
`),a+=`c=IN IP4 0.0.0.0\r
|
|
a=inactive\r
|
|
a=mid:`+e.mid+`\r
|
|
`;return}if(e.stream){var c;e.kind===`audio`?c=e.stream.getAudioTracks()[0]:e.kind===`video`&&(c=e.stream.getVideoTracks()[0]),c&&t>=15019&&e.kind===`video`&&!e.sendEncodingParameters[0].rtx&&(e.sendEncodingParameters[0].rtx={ssrc:e.sendEncodingParameters[0].ssrc+1})}var l=o(e.localCapabilities,e.remoteCapabilities);!l.codecs.filter(function(e){return e.name.toLowerCase()===`rtx`}).length&&e.sendEncodingParameters[0].rtx&&delete e.sendEncodingParameters[0].rtx,a+=i(e,l,`answer`,e.stream,r._dtlsRole),e.rtcpParameters&&e.rtcpParameters.reducedSize&&(a+=`a=rtcp-rsize\r
|
|
`)}});var c=new e.RTCSessionDescription({type:`answer`,sdp:a});return Promise.resolve(c)},p.prototype.addIceCandidate=function(e){var t=this,r;return e&&!(e.sdpMLineIndex!==void 0||e.sdpMid)?Promise.reject(TypeError(`sdpMLineIndex or sdpMid required`)):new Promise(function(i,a){if(!t._remoteDescription)return a(l(`InvalidStateError`,`Can not add ICE candidate without a remote description`));if(!e||e.candidate===``)for(var o=0;o<t.transceivers.length&&!(!t.transceivers[o].rejected&&(t.transceivers[o].iceTransport.addRemoteCandidate({}),r=n.getMediaSections(t._remoteDescription.sdp),r[o]+=`a=end-of-candidates\r
|
|
`,t._remoteDescription.sdp=n.getDescription(t._remoteDescription.sdp)+r.join(``),t.usingBundle));o++);else{var s=e.sdpMLineIndex;if(e.sdpMid){for(var u=0;u<t.transceivers.length;u++)if(t.transceivers[u].mid===e.sdpMid){s=u;break}}var d=t.transceivers[s];if(d){if(d.rejected)return i();var f=Object.keys(e.candidate).length>0?n.parseCandidate(e.candidate):{};if(f.protocol===`tcp`&&(f.port===0||f.port===9)||f.component&&f.component!==1)return i();if((s===0||s>0&&d.iceTransport!==t.transceivers[0].iceTransport)&&!c(d.iceTransport,f))return a(l(`OperationError`,`Can not add ICE candidate`));var p=e.candidate.trim();p.indexOf(`a=`)===0&&(p=p.substr(2)),r=n.getMediaSections(t._remoteDescription.sdp),r[s]+=`a=`+(f.type?p:`end-of-candidates`)+`\r
|
|
`,t._remoteDescription.sdp=n.getDescription(t._remoteDescription.sdp)+r.join(``)}else return a(l(`OperationError`,`Can not add ICE candidate`))}i()})},p.prototype.getStats=function(t){if(t&&t instanceof e.MediaStreamTrack){var n=null;if(this.transceivers.forEach(function(e){e.rtpSender&&e.rtpSender.track===t?n=e.rtpSender:e.rtpReceiver&&e.rtpReceiver.track===t&&(n=e.rtpReceiver)}),!n)throw l(`InvalidAccessError`,`Invalid selector.`);return n.getStats()}var r=[];return this.transceivers.forEach(function(e){[`rtpSender`,`rtpReceiver`,`iceGatherer`,`iceTransport`,`dtlsTransport`].forEach(function(t){e[t]&&r.push(e[t].getStats())})}),Promise.all(r).then(function(e){var t=new Map;return e.forEach(function(e){e.forEach(function(e){t.set(e.id,e)})}),t})},[`RTCRtpSender`,`RTCRtpReceiver`,`RTCIceGatherer`,`RTCIceTransport`,`RTCDtlsTransport`].forEach(function(t){var n=e[t];if(n&&n.prototype&&n.prototype.getStats){var i=n.prototype.getStats;n.prototype.getStats=function(){return i.apply(this).then(function(e){var t=new Map;return Object.keys(e).forEach(function(n){e[n].type=r(e[n]),t.set(n,e[n])}),t})}}});var m=[`createOffer`,`createAnswer`];return m.forEach(function(e){var t=p.prototype[e];p.prototype[e]=function(){var e=arguments;return typeof e[0]==`function`||typeof e[1]==`function`?t.apply(this,[arguments[2]]).then(function(t){typeof e[0]==`function`&&e[0].apply(null,[t])},function(t){typeof e[1]==`function`&&e[1].apply(null,[t])}):t.apply(this,arguments)}}),m=[`setLocalDescription`,`setRemoteDescription`,`addIceCandidate`],m.forEach(function(e){var t=p.prototype[e];p.prototype[e]=function(){var e=arguments;return typeof e[1]==`function`||typeof e[2]==`function`?t.apply(this,arguments).then(function(){typeof e[1]==`function`&&e[1].apply(null)},function(t){typeof e[2]==`function`&&e[2].apply(null,[t])}):t.apply(this,arguments)}}),[`getStats`].forEach(function(e){var t=p.prototype[e];p.prototype[e]=function(){var e=arguments;return typeof e[1]==`function`?t.apply(this,arguments).then(function(){typeof e[1]==`function`&&e[1].apply(null)}):t.apply(this,arguments)}}),p}}))());function k(e){let t=e&&e.navigator,n=function(e){return{name:{PermissionDeniedError:`NotAllowedError`}[e.name]||e.name,message:e.message,constraint:e.constraint,toString(){return this.name}}},r=t.mediaDevices.getUserMedia.bind(t.mediaDevices);Object.getOwnPropertyDescriptor(t.mediaDevices,`getUserMedia`)?.writable&&(t.mediaDevices.getUserMedia=function(e){return r(e).catch(e=>Promise.reject(n(e)))})}function ae(e){`getDisplayMedia`in e.navigator&&e.navigator.mediaDevices&&(e.navigator.mediaDevices&&`getDisplayMedia`in e.navigator.mediaDevices||(e.navigator.mediaDevices.getDisplayMedia=e.navigator.getDisplayMedia.bind(e.navigator)))}var oe=e({shimGetDisplayMedia:()=>ae,shimGetUserMedia:()=>k,shimPeerConnection:()=>A,shimReplaceTrack:()=>j});function A(e,t){if(e.RTCIceGatherer&&(e.RTCIceCandidate||=function(e){return e},e.RTCSessionDescription||=function(e){return e},t.version<15025)){let t=Object.getOwnPropertyDescriptor(e.MediaStreamTrack.prototype,`enabled`);Object.defineProperty(e.MediaStreamTrack.prototype,`enabled`,{set(e){t.set.call(this,e);let n=new Event(`enabled`);n.enabled=e,this.dispatchEvent(n)}})}e.RTCRtpSender&&!(`dtmf`in e.RTCRtpSender.prototype)&&Object.defineProperty(e.RTCRtpSender.prototype,`dtmf`,{get(){return this._dtmf===void 0&&(this.track.kind===`audio`?this._dtmf=new e.RTCDtmfSender(this):this.track.kind===`video`&&(this._dtmf=null)),this._dtmf}}),e.RTCDtmfSender&&!e.RTCDTMFSender&&(e.RTCDTMFSender=e.RTCDtmfSender);let n=(0,ie.default)(e,t.version);e.RTCPeerConnection=function(e){return e&&e.iceServers&&(e.iceServers=O(e.iceServers,t.version),d(`ICE servers after filtering:`,e.iceServers)),new n(e)},e.RTCPeerConnection.prototype=n.prototype}function j(e){e.RTCRtpSender&&!(`replaceTrack`in e.RTCRtpSender.prototype)&&(e.RTCRtpSender.prototype.replaceTrack=e.RTCRtpSender.prototype.setTrack)}function M(e,t){let n=e&&e.navigator,r=e&&e.MediaStreamTrack;if(n.getUserMedia=function(e,t,r){f(`navigator.getUserMedia`,`navigator.mediaDevices.getUserMedia`),n.mediaDevices.getUserMedia(e).then(t,r)},!(t.version>55&&`autoGainControl`in n.mediaDevices.getSupportedConstraints())){let e=function(e,t,n){t in e&&!(n in e)&&(e[n]=e[t],delete e[t])},t=n.mediaDevices.getUserMedia.bind(n.mediaDevices);if(Object.getOwnPropertyDescriptor(n.mediaDevices,`getUserMedia`)?.writable&&(n.mediaDevices.getUserMedia=function(n){return typeof n==`object`&&typeof n.audio==`object`&&(n=JSON.parse(JSON.stringify(n)),e(n.audio,`autoGainControl`,`mozAutoGainControl`),e(n.audio,`noiseSuppression`,`mozNoiseSuppression`)),t(n)}),r&&r.prototype.getSettings){let t=r.prototype.getSettings;r.prototype.getSettings=function(){let n=t.apply(this,arguments);return e(n,`mozAutoGainControl`,`autoGainControl`),e(n,`mozNoiseSuppression`,`noiseSuppression`),n}}if(r&&r.prototype.applyConstraints){let t=r.prototype.applyConstraints;r.prototype.applyConstraints=function(n){return this.kind===`audio`&&typeof n==`object`&&(n=JSON.parse(JSON.stringify(n)),e(n,`autoGainControl`,`mozAutoGainControl`),e(n,`noiseSuppression`,`mozNoiseSuppression`)),t.apply(this,[n])}}}}function se(e,t){e.navigator.mediaDevices&&`getDisplayMedia`in e.navigator.mediaDevices||e.navigator.mediaDevices&&(e.navigator.mediaDevices.getDisplayMedia=function(n){if(!(n&&n.video)){let e=new DOMException(`getDisplayMedia without video constraints is undefined`);return e.name=`NotFoundError`,e.code=8,Promise.reject(e)}return n.video===!0?n.video={mediaSource:t}:n.video.mediaSource=t,e.navigator.mediaDevices.getUserMedia(n)})}var ce=e({shimAddTransceiver:()=>he,shimCreateAnswer:()=>ve,shimCreateOffer:()=>_e,shimGetDisplayMedia:()=>se,shimGetParameters:()=>ge,shimGetUserMedia:()=>M,shimOnTrack:()=>le,shimPeerConnection:()=>ue,shimRTCDataChannel:()=>me,shimReceiverGetStats:()=>fe,shimRemoveStream:()=>pe,shimSenderGetStats:()=>de});function le(e){typeof e==`object`&&e.RTCTrackEvent&&`receiver`in e.RTCTrackEvent.prototype&&!(`transceiver`in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,`transceiver`,{get(){return{receiver:this.receiver}}})}function ue(e,t){if(typeof e!=`object`||!(e.RTCPeerConnection||e.mozRTCPeerConnection))return;!e.RTCPeerConnection&&e.mozRTCPeerConnection&&(e.RTCPeerConnection=e.mozRTCPeerConnection),t.version<53&&[`setLocalDescription`,`setRemoteDescription`,`addIceCandidate`].forEach(function(t){let n=e.RTCPeerConnection.prototype[t],r={[t](){return arguments[0]=new(t===`addIceCandidate`?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),n.apply(this,arguments)}};e.RTCPeerConnection.prototype[t]=r[t]});let n={inboundrtp:`inbound-rtp`,outboundrtp:`outbound-rtp`,candidatepair:`candidate-pair`,localcandidate:`local-candidate`,remotecandidate:`remote-candidate`},r=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){let[e,i,a]=arguments;return r.apply(this,[e||null]).then(e=>{if(t.version<53&&!i)try{e.forEach(e=>{e.type=n[e.type]||e.type})}catch(t){if(t.name!==`TypeError`)throw t;e.forEach((t,r)=>{e.set(r,Object.assign({},t,{type:n[t.type]||t.type}))})}return e}).then(i,a)}}function de(e){if(!(typeof e==`object`&&e.RTCPeerConnection&&e.RTCRtpSender)||e.RTCRtpSender&&`getStats`in e.RTCRtpSender.prototype)return;let t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){let e=t.apply(this,[]);return e.forEach(e=>e._pc=this),e});let n=e.RTCPeerConnection.prototype.addTrack;n&&(e.RTCPeerConnection.prototype.addTrack=function(){let e=n.apply(this,arguments);return e._pc=this,e}),e.RTCRtpSender.prototype.getStats=function(){return this.track?this._pc.getStats(this.track):Promise.resolve(new Map)}}function fe(e){if(!(typeof e==`object`&&e.RTCPeerConnection&&e.RTCRtpSender)||e.RTCRtpSender&&`getStats`in e.RTCRtpReceiver.prototype)return;let t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){let e=t.apply(this,[]);return e.forEach(e=>e._pc=this),e}),c(e,`track`,e=>(e.receiver._pc=e.srcElement,e)),e.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function pe(e){!e.RTCPeerConnection||`removeStream`in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.removeStream=function(e){f(`removeStream`,`removeTrack`),this.getSenders().forEach(t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)})})}function me(e){e.DataChannel&&!e.RTCDataChannel&&(e.RTCDataChannel=e.DataChannel)}function he(e){if(!(typeof e==`object`&&e.RTCPeerConnection))return;let t=e.RTCPeerConnection.prototype.addTransceiver;t&&(e.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];let e=arguments[1],n=e&&`sendEncodings`in e;n&&e.sendEncodings.forEach(e=>{if(`rid`in e&&!/^[a-z0-9]{0,16}$/i.test(e.rid))throw TypeError(`Invalid RID value provided.`);if(`scaleResolutionDownBy`in e&&!(parseFloat(e.scaleResolutionDownBy)>=1))throw RangeError(`scale_resolution_down_by must be >= 1.0`);if(`maxFramerate`in e&&!(parseFloat(e.maxFramerate)>=0))throw RangeError(`max_framerate must be >= 0.0`)});let r=t.apply(this,arguments);if(n){let{sender:t}=r,n=t.getParameters();(!(`encodings`in n)||n.encodings.length===1&&Object.keys(n.encodings[0]).length===0)&&(n.encodings=e.sendEncodings,t.sendEncodings=e.sendEncodings,this.setParametersPromises.push(t.setParameters(n).then(()=>{delete t.sendEncodings}).catch(()=>{delete t.sendEncodings})))}return r})}function ge(e){if(!(typeof e==`object`&&e.RTCRtpSender))return;let t=e.RTCRtpSender.prototype.getParameters;t&&(e.RTCRtpSender.prototype.getParameters=function(){let e=t.apply(this,arguments);return`encodings`in e||(e.encodings=[].concat(this.sendEncodings||[{}])),e})}function _e(e){if(!(typeof e==`object`&&e.RTCPeerConnection))return;let t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>t.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):t.apply(this,arguments)}}function ve(e){if(!(typeof e==`object`&&e.RTCPeerConnection))return;let t=e.RTCPeerConnection.prototype.createAnswer;e.RTCPeerConnection.prototype.createAnswer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>t.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):t.apply(this,arguments)}}var ye=e({shimAudioContext:()=>Oe,shimCallbacksAPI:()=>Se,shimConstraints:()=>we,shimCreateOfferLegacy:()=>De,shimGetUserMedia:()=>Ce,shimLocalStreamsAPI:()=>be,shimRTCIceServerUrls:()=>Te,shimRemoteStreamsAPI:()=>xe,shimTrackEventTransceiver:()=>Ee});function be(e){if(!(typeof e!=`object`||!e.RTCPeerConnection)){if(`getLocalStreams`in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||=[],this._localStreams}),!(`addStream`in e.RTCPeerConnection.prototype)){let t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addStream=function(e){this._localStreams||=[],this._localStreams.includes(e)||this._localStreams.push(e),e.getAudioTracks().forEach(n=>t.call(this,n,e)),e.getVideoTracks().forEach(n=>t.call(this,n,e))},e.RTCPeerConnection.prototype.addTrack=function(e,...n){return n&&n.forEach(e=>{this._localStreams?this._localStreams.includes(e)||this._localStreams.push(e):this._localStreams=[e]}),t.apply(this,arguments)}}`removeStream`in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.removeStream=function(e){this._localStreams||=[];let t=this._localStreams.indexOf(e);if(t===-1)return;this._localStreams.splice(t,1);let n=e.getTracks();this.getSenders().forEach(e=>{n.includes(e.track)&&this.removeTrack(e)})})}}function xe(e){if(!(typeof e!=`object`||!e.RTCPeerConnection)&&(`getRemoteStreams`in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),!(`onaddstream`in e.RTCPeerConnection.prototype))){Object.defineProperty(e.RTCPeerConnection.prototype,`onaddstream`,{get(){return this._onaddstream},set(e){this._onaddstream&&(this.removeEventListener(`addstream`,this._onaddstream),this.removeEventListener(`track`,this._onaddstreampoly)),this.addEventListener(`addstream`,this._onaddstream=e),this.addEventListener(`track`,this._onaddstreampoly=e=>{e.streams.forEach(e=>{if(this._remoteStreams||=[],this._remoteStreams.includes(e))return;this._remoteStreams.push(e);let t=new Event(`addstream`);t.stream=e,this.dispatchEvent(t)})})}});let t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){let e=this;return this._onaddstreampoly||this.addEventListener(`track`,this._onaddstreampoly=function(t){t.streams.forEach(t=>{if(e._remoteStreams||=[],e._remoteStreams.indexOf(t)>=0)return;e._remoteStreams.push(t);let n=new Event(`addstream`);n.stream=t,e.dispatchEvent(n)})}),t.apply(e,arguments)}}}function Se(e){if(typeof e!=`object`||!e.RTCPeerConnection)return;let t=e.RTCPeerConnection.prototype,n=t.createOffer,r=t.createAnswer,i=t.setLocalDescription,a=t.setRemoteDescription,o=t.addIceCandidate;t.createOffer=function(e,t){let r=arguments.length>=2?arguments[2]:arguments[0],i=n.apply(this,[r]);return t?(i.then(e,t),Promise.resolve()):i},t.createAnswer=function(e,t){let n=arguments.length>=2?arguments[2]:arguments[0],i=r.apply(this,[n]);return t?(i.then(e,t),Promise.resolve()):i};let s=function(e,t,n){let r=i.apply(this,[e]);return n?(r.then(t,n),Promise.resolve()):r};t.setLocalDescription=s,s=function(e,t,n){let r=a.apply(this,[e]);return n?(r.then(t,n),Promise.resolve()):r},t.setRemoteDescription=s,s=function(e,t,n){let r=o.apply(this,[e]);return n?(r.then(t,n),Promise.resolve()):r},t.addIceCandidate=s}function Ce(e){let t=e&&e.navigator;if(t.mediaDevices&&t.mediaDevices.getUserMedia){let e=t.mediaDevices,n=e.getUserMedia.bind(e);t.mediaDevices.getUserMedia=e=>n(we(e))}!t.getUserMedia&&t.mediaDevices&&t.mediaDevices.getUserMedia&&(t.getUserMedia=function(e,n,r){t.mediaDevices.getUserMedia(e).then(n,r)}.bind(t))}function we(e){return e&&e.video!==void 0?Object.assign({},e,{video:h(e.video)}):e}function Te(e){if(!e.RTCPeerConnection)return;let t=e.RTCPeerConnection;e.RTCPeerConnection=function(e,n){if(e&&e.iceServers){let t=[];for(let n=0;n<e.iceServers.length;n++){let r=e.iceServers[n];!r.hasOwnProperty(`urls`)&&r.hasOwnProperty(`url`)?(f(`RTCIceServer.url`,`RTCIceServer.urls`),r=JSON.parse(JSON.stringify(r)),r.urls=r.url,delete r.url,t.push(r)):t.push(e.iceServers[n])}e.iceServers=t}return new t(e,n)},e.RTCPeerConnection.prototype=t.prototype,`generateCertificate`in t&&Object.defineProperty(e.RTCPeerConnection,`generateCertificate`,{get(){return t.generateCertificate}})}function Ee(e){typeof e==`object`&&e.RTCTrackEvent&&`receiver`in e.RTCTrackEvent.prototype&&!(`transceiver`in e.RTCTrackEvent.prototype)&&Object.defineProperty(e.RTCTrackEvent.prototype,`transceiver`,{get(){return{receiver:this.receiver}}})}function De(e){let t=e.RTCPeerConnection.prototype.createOffer;e.RTCPeerConnection.prototype.createOffer=function(e){if(e){e.offerToReceiveAudio!==void 0&&(e.offerToReceiveAudio=!!e.offerToReceiveAudio);let t=this.getTransceivers().find(e=>e.receiver.track.kind===`audio`);e.offerToReceiveAudio===!1&&t?t.direction===`sendrecv`?t.setDirection?t.setDirection(`sendonly`):t.direction=`sendonly`:t.direction===`recvonly`&&(t.setDirection?t.setDirection(`inactive`):t.direction=`inactive`):e.offerToReceiveAudio===!0&&!t&&this.addTransceiver(`audio`),e.offerToReceiveVideo!==void 0&&(e.offerToReceiveVideo=!!e.offerToReceiveVideo);let n=this.getTransceivers().find(e=>e.receiver.track.kind===`video`);e.offerToReceiveVideo===!1&&n?n.direction===`sendrecv`?n.setDirection?n.setDirection(`sendonly`):n.direction=`sendonly`:n.direction===`recvonly`&&(n.setDirection?n.setDirection(`inactive`):n.direction=`inactive`):e.offerToReceiveVideo===!0&&!n&&this.addTransceiver(`video`)}return t.apply(this,arguments)}}function Oe(e){typeof e!=`object`||e.AudioContext||(e.AudioContext=e.webkitAudioContext)}var ke=e({removeExtmapAllowMixed:()=>Ne,shimAddIceCandidateNullOrEmpty:()=>Pe,shimConnectionState:()=>Me,shimMaxMessageSize:()=>N,shimRTCIceCandidate:()=>je,shimSendThrowTypeError:()=>P}),Ae=t(re());function je(e){if(!e.RTCIceCandidate||e.RTCIceCandidate&&`foundation`in e.RTCIceCandidate.prototype)return;let t=e.RTCIceCandidate;e.RTCIceCandidate=function(e){if(typeof e==`object`&&e.candidate&&e.candidate.indexOf(`a=`)===0&&(e=JSON.parse(JSON.stringify(e)),e.candidate=e.candidate.substr(2)),e.candidate&&e.candidate.length){let n=new t(e),r=Ae.default.parseCandidate(e.candidate),i=Object.assign(n,r);return i.toJSON=function(){return{candidate:i.candidate,sdpMid:i.sdpMid,sdpMLineIndex:i.sdpMLineIndex,usernameFragment:i.usernameFragment}},i}return new t(e)},e.RTCIceCandidate.prototype=t.prototype,c(e,`icecandidate`,t=>(t.candidate&&Object.defineProperty(t,`candidate`,{value:new e.RTCIceCandidate(t.candidate),writable:`false`}),t))}function N(e,t){if(!e.RTCPeerConnection)return;`sctp`in e.RTCPeerConnection.prototype||Object.defineProperty(e.RTCPeerConnection.prototype,`sctp`,{get(){return this._sctp===void 0?null:this._sctp}});let n=function(e){if(!e||!e.sdp)return!1;let t=Ae.default.splitSections(e.sdp);return t.shift(),t.some(e=>{let t=Ae.default.parseMLine(e);return t&&t.kind===`application`&&t.protocol.indexOf(`SCTP`)!==-1})},r=function(e){let t=e.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(t===null||t.length<2)return-1;let n=parseInt(t[1],10);return n===n?n:-1},i=function(e){let n=65536;return t.browser===`firefox`&&(n=t.version<57?e===-1?16384:2147483637:t.version<60?t.version===57?65535:65536:2147483637),n},a=function(e,n){let r=65536;t.browser===`firefox`&&t.version===57&&(r=65535);let i=Ae.default.matchPrefix(e.sdp,`a=max-message-size:`);return i.length>0?r=parseInt(i[0].substr(19),10):t.browser===`firefox`&&n!==-1&&(r=2147483637),r},o=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,t.browser===`chrome`&&t.version>=76){let{sdpSemantics:e}=this.getConfiguration();e===`plan-b`&&Object.defineProperty(this,`sctp`,{get(){return this._sctp===void 0?null:this._sctp},enumerable:!0,configurable:!0})}if(n(arguments[0])){let e=r(arguments[0]),t=i(e),n=a(arguments[0],e),o;o=t===0&&n===0?1/0:t===0||n===0?Math.max(t,n):Math.min(t,n);let s={};Object.defineProperty(s,`maxMessageSize`,{get(){return o}}),this._sctp=s}return o.apply(this,arguments)}}function P(e){if(!(e.RTCPeerConnection&&`createDataChannel`in e.RTCPeerConnection.prototype))return;function t(e,t){let n=e.send;e.send=function(){let r=arguments[0],i=r.length||r.size||r.byteLength;if(e.readyState===`open`&&t.sctp&&i>t.sctp.maxMessageSize)throw TypeError(`Message too large (can send a maximum of `+t.sctp.maxMessageSize+` bytes)`);return n.apply(e,arguments)}}let n=e.RTCPeerConnection.prototype.createDataChannel;e.RTCPeerConnection.prototype.createDataChannel=function(){let e=n.apply(this,arguments);return t(e,this),e},c(e,`datachannel`,e=>(t(e.channel,e.target),e))}function Me(e){if(!e.RTCPeerConnection||`connectionState`in e.RTCPeerConnection.prototype)return;let t=e.RTCPeerConnection.prototype;Object.defineProperty(t,`connectionState`,{get(){return{completed:`connected`,checking:`connecting`}[this.iceConnectionState]||this.iceConnectionState},enumerable:!0,configurable:!0}),Object.defineProperty(t,`onconnectionstatechange`,{get(){return this._onconnectionstatechange||null},set(e){this._onconnectionstatechange&&(this.removeEventListener(`connectionstatechange`,this._onconnectionstatechange),delete this._onconnectionstatechange),e&&this.addEventListener(`connectionstatechange`,this._onconnectionstatechange=e)},enumerable:!0,configurable:!0}),[`setLocalDescription`,`setRemoteDescription`].forEach(e=>{let n=t[e];t[e]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=e=>{let t=e.target;if(t._lastConnectionState!==t.connectionState){t._lastConnectionState=t.connectionState;let n=new Event(`connectionstatechange`,e);t.dispatchEvent(n)}return e},this.addEventListener(`iceconnectionstatechange`,this._connectionstatechangepoly)),n.apply(this,arguments)}})}function Ne(e,t){if(!e.RTCPeerConnection||t.browser===`chrome`&&t.version>=71||t.browser===`safari`&&t.version>=605)return;let n=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(t){if(t&&t.sdp&&t.sdp.indexOf(`
|
|
a=extmap-allow-mixed`)!==-1){let n=t.sdp.split(`
|
|
`).filter(e=>e.trim()!==`a=extmap-allow-mixed`).join(`
|
|
`);e.RTCSessionDescription&&t instanceof e.RTCSessionDescription?arguments[0]=new e.RTCSessionDescription({type:t.type,sdp:n}):t.sdp=n}return n.apply(this,arguments)}}function Pe(e,t){if(!(e.RTCPeerConnection&&e.RTCPeerConnection.prototype))return;let n=e.RTCPeerConnection.prototype.addIceCandidate;!n||n.length===0||(e.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?(t.browser===`chrome`&&t.version<78||t.browser===`firefox`&&t.version<68||t.browser===`safari`)&&arguments[0]&&arguments[0].candidate===``?Promise.resolve():n.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}function Fe({window:e}={},t={shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0}){let n=d,r=p(e),i={browserDetails:r,commonShim:ke,extractVersion:s,disableLog:l,disableWarnings:u};switch(r.browser){case`chrome`:if(!b||!E||!t.shimChrome)return n(`Chrome shim is not included in this adapter release.`),i;if(r.version===null)return n(`Chrome shim can not determine version, not shimming.`),i;n(`adapter.js shimming chrome.`),i.browserShim=b,Pe(e,r),v(e,r),te(e,r),E(e,r),x(e,r),T(e,r),ne(e,r),S(e,r),C(e,r),D(e,r),je(e,r),Me(e,r),N(e,r),P(e,r),Ne(e,r);break;case`firefox`:if(!ce||!ue||!t.shimFirefox)return n(`Firefox shim is not included in this adapter release.`),i;n(`adapter.js shimming firefox.`),i.browserShim=ce,Pe(e,r),M(e,r),ue(e,r),le(e,r),pe(e,r),de(e,r),fe(e,r),me(e,r),he(e,r),ge(e,r),_e(e,r),ve(e,r),je(e,r),Me(e,r),N(e,r),P(e,r);break;case`edge`:if(!oe||!A||!t.shimEdge)return n(`MS edge shim is not included in this adapter release.`),i;n(`adapter.js shimming edge.`),i.browserShim=oe,k(e,r),ae(e,r),A(e,r),j(e,r),N(e,r),P(e,r);break;case`safari`:if(!ye||!t.shimSafari)return n(`Safari shim is not included in this adapter release.`),i;n(`adapter.js shimming safari.`),i.browserShim=ye,Pe(e,r),Te(e,r),De(e,r),Se(e,r),be(e,r),xe(e,r),Ee(e,r),Ce(e,r),Oe(e,r),je(e,r),N(e,r),P(e,r),Ne(e,r);break;default:n(`Unsupported browser!`);break}return i}var Ie=Fe({window:typeof window>`u`?void 0:window}),Le=e({Peer:()=>Tt,default:()=>Et,util:()=>L});function F(e,t,n,r){Object.defineProperty(e,t,{get:n,set:r,enumerable:!0,configurable:!0})}var Re=Ie.default||Ie,I=new(function(){function e(){this.isIOS=[`iPad`,`iPhone`,`iPod`].includes(navigator.platform),this.supportedBrowsers=[`firefox`,`chrome`,`safari`],this.minFirefoxVersion=59,this.minChromeVersion=72,this.minSafariVersion=605}return e.prototype.isWebRTCSupported=function(){return typeof RTCPeerConnection<`u`},e.prototype.isBrowserSupported=function(){var e=this.getBrowser(),t=this.getVersion();return this.supportedBrowsers.includes(e)?e===`chrome`?t>=this.minChromeVersion:e===`firefox`?t>=this.minFirefoxVersion:e===`safari`?!this.isIOS&&t>=this.minSafariVersion:!1:!1},e.prototype.getBrowser=function(){return Re.browserDetails.browser},e.prototype.getVersion=function(){return Re.browserDetails.version||0},e.prototype.isUnifiedPlanSupported=function(){var e=this.getBrowser(),t=Re.browserDetails.version||0;if(e===`chrome`&&t<this.minChromeVersion)return!1;if(e===`firefox`&&t>=this.minFirefoxVersion)return!0;if(!window.RTCRtpTransceiver||!(`currentDirection`in RTCRtpTransceiver.prototype))return!1;var n,r=!1;try{n=new RTCPeerConnection,n.addTransceiver(`audio`),r=!0}catch{}finally{n&&n.close()}return r},e.prototype.toString=function(){return`Supports:
|
|
browser:${this.getBrowser()}
|
|
version:${this.getVersion()}
|
|
isIOS:${this.isIOS}
|
|
isWebRTCSupported:${this.isWebRTCSupported()}
|
|
isBrowserSupported:${this.isBrowserSupported()}
|
|
isUnifiedPlanSupported:${this.isUnifiedPlanSupported()}`},e}()),ze={iceServers:[{urls:`stun:stun.l.google.com:19302`},{urls:[`turn:eu-0.turn.peerjs.com:3478`,`turn:us-0.turn.peerjs.com:3478`],username:`peerjs`,credential:`peerjsp`}],sdpSemantics:`unified-plan`},L=new(function(){function e(){this.CLOUD_HOST=`0.peerjs.com`,this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=ze,this.browser=I.getBrowser(),this.browserVersion=I.getVersion(),this.supports=function(){var e={browser:I.isBrowserSupported(),webRTC:I.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(ze),e.audioVideo=!0;var n=void 0;try{n=t.createDataChannel(`_PEERJSTEST`,{ordered:!0}),e.data=!0,e.reliable=!!n.ordered;try{n.binaryType=`blob`,e.binaryBlob=!I.isIOS}catch{}}catch{}finally{n&&n.close()}}catch{}finally{t&&t.close()}return e}(),this.pack=i.default.pack,this.unpack=i.default.unpack,this._dataCount=1}return e.prototype.noop=function(){},e.prototype.validateId=function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(e)},e.prototype.chunk=function(e){for(var t=[],n=e.size,r=Math.ceil(n/L.chunkedMTU),i=0,a=0;a<n;){var o=Math.min(n,a+L.chunkedMTU),s=e.slice(a,o),c={__peerData:this._dataCount,n:i,data:s,total:r};t.push(c),a=o,i++}return this._dataCount++,t},e.prototype.blobToArrayBuffer=function(e,t){var n=new FileReader;return n.onload=function(e){e.target&&t(e.target.result)},n.readAsArrayBuffer(e),n},e.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t.buffer},e.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},e.prototype.isSecure=function(){return location.protocol===`https:`},e}()),Be={};F(Be,`Peer`,()=>Tt,e=>Tt=e);var R={},Ve=Object.prototype.hasOwnProperty,z=`~`;function B(){}Object.create&&(B.prototype=Object.create(null),new B().__proto__||(z=!1));function He(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function Ue(e,t,n,r,i){if(typeof n!=`function`)throw TypeError(`The listener must be a function`);var a=new He(n,r||e,i),o=z?z+t:t;return e._events[o]?e._events[o].fn?e._events[o]=[e._events[o],a]:e._events[o].push(a):(e._events[o]=a,e._eventsCount++),e}function We(e,t){--e._eventsCount===0?e._events=new B:delete e._events[t]}function V(){this._events=new B,this._eventsCount=0}V.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Ve.call(t,n)&&e.push(z?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e},V.prototype.listeners=function(e){var t=z?z+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var r=0,i=n.length,a=Array(i);r<i;r++)a[r]=n[r].fn;return a},V.prototype.listenerCount=function(e){var t=z?z+e:e,n=this._events[t];return n?n.fn?1:n.length:0},V.prototype.emit=function(e,t,n,r,i,a){var o=z?z+e:e;if(!this._events[o])return!1;var s=this._events[o],c=arguments.length,l,u;if(s.fn){switch(s.once&&this.removeListener(e,s.fn,void 0,!0),c){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,t),!0;case 3:return s.fn.call(s.context,t,n),!0;case 4:return s.fn.call(s.context,t,n,r),!0;case 5:return s.fn.call(s.context,t,n,r,i),!0;case 6:return s.fn.call(s.context,t,n,r,i,a),!0}for(u=1,l=Array(c-1);u<c;u++)l[u-1]=arguments[u];s.fn.apply(s.context,l)}else{var d=s.length,f;for(u=0;u<d;u++)switch(s[u].once&&this.removeListener(e,s[u].fn,void 0,!0),c){case 1:s[u].fn.call(s[u].context);break;case 2:s[u].fn.call(s[u].context,t);break;case 3:s[u].fn.call(s[u].context,t,n);break;case 4:s[u].fn.call(s[u].context,t,n,r);break;default:if(!l)for(f=1,l=Array(c-1);f<c;f++)l[f-1]=arguments[f];s[u].fn.apply(s[u].context,l)}}return!0},V.prototype.on=function(e,t,n){return Ue(this,e,t,n,!1)},V.prototype.once=function(e,t,n){return Ue(this,e,t,n,!0)},V.prototype.removeListener=function(e,t,n,r){var i=z?z+e:e;if(!this._events[i])return this;if(!t)return We(this,i),this;var a=this._events[i];if(a.fn)a.fn===t&&(!r||a.once)&&(!n||a.context===n)&&We(this,i);else{for(var o=0,s=[],c=a.length;o<c;o++)(a[o].fn!==t||r&&!a[o].once||n&&a[o].context!==n)&&s.push(a[o]);s.length?this._events[i]=s.length===1?s[0]:s:We(this,i)}return this},V.prototype.removeAllListeners=function(e){var t;return e?(t=z?z+e:e,this._events[t]&&We(this,t)):(this._events=new B,this._eventsCount=0),this},V.prototype.off=V.prototype.removeListener,V.prototype.addListener=V.prototype.on,V.prefixed=z,V.EventEmitter=V,R=V;var H={};F(H,`LogLevel`,()=>G,e=>G=e),F(H,`default`,()=>Ke,e=>Ke=e);var U=function(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,a=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},W=function(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))},Ge=`PeerJS: `,G;(function(e){e[e.Disabled=0]=`Disabled`,e[e.Errors=1]=`Errors`,e[e.Warnings=2]=`Warnings`,e[e.All=3]=`All`})(G||={});var Ke=new(function(){function e(){this._logLevel=G.Disabled}return Object.defineProperty(e.prototype,`logLevel`,{get:function(){return this._logLevel},set:function(e){this._logLevel=e},enumerable:!1,configurable:!0}),e.prototype.log=function(){var e=[...arguments];this._logLevel>=G.All&&this._print.apply(this,W([G.All],U(e),!1))},e.prototype.warn=function(){var e=[...arguments];this._logLevel>=G.Warnings&&this._print.apply(this,W([G.Warnings],U(e),!1))},e.prototype.error=function(){var e=[...arguments];this._logLevel>=G.Errors&&this._print.apply(this,W([G.Errors],U(e),!1))},e.prototype.setLogFunction=function(e){this._print=e},e.prototype._print=function(e){var t=[...arguments].slice(1),n=W([Ge],U(t),!1);for(var r in n)n[r]instanceof Error&&(n[r]=`(`+n[r].name+`) `+n[r].message);e>=G.All?console.log.apply(console,W([],U(n),!1)):e>=G.Warnings?console.warn.apply(console,W([`WARNING`],U(n),!1)):e>=G.Errors&&console.error.apply(console,W([`ERROR`],U(n),!1))},e}()),qe={};F(qe,`Socket`,()=>$e,e=>$e=e);var K;(function(e){e.Data=`data`,e.Media=`media`})(K||={});var q;(function(e){e.BrowserIncompatible=`browser-incompatible`,e.Disconnected=`disconnected`,e.InvalidID=`invalid-id`,e.InvalidKey=`invalid-key`,e.Network=`network`,e.PeerUnavailable=`peer-unavailable`,e.SslUnavailable=`ssl-unavailable`,e.ServerError=`server-error`,e.SocketError=`socket-error`,e.SocketClosed=`socket-closed`,e.UnavailableID=`unavailable-id`,e.WebRTC=`webrtc`})(q||={});var J;(function(e){e.Binary=`binary`,e.BinaryUTF8=`binary-utf8`,e.JSON=`json`})(J||={});var Y;(function(e){e.Message=`message`,e.Disconnected=`disconnected`,e.Error=`error`,e.Close=`close`})(Y||={});var X;(function(e){e.Heartbeat=`HEARTBEAT`,e.Candidate=`CANDIDATE`,e.Offer=`OFFER`,e.Answer=`ANSWER`,e.Open=`OPEN`,e.Error=`ERROR`,e.IdTaken=`ID-TAKEN`,e.InvalidKey=`INVALID-KEY`,e.Leave=`LEAVE`,e.Expire=`EXPIRE`})(X||={});var Je={};Je=JSON.parse(`{"name":"peerjs","version":"1.4.7","keywords":["peerjs","webrtc","p2p","rtc"],"description":"PeerJS client","homepage":"https://peerjs.com","bugs":{"url":"https://github.com/peers/peerjs/issues"},"repository":{"type":"git","url":"https://github.com/peers/peerjs"},"license":"MIT","contributors":["Michelle Bu <michelle@michellebu.com>","afrokick <devbyru@gmail.com>","ericz <really.ez@gmail.com>","Jairo <kidandcat@gmail.com>","Jonas Gloning <34194370+jonasgloning@users.noreply.github.com>","Jairo Caro-Accino Viciana <jairo@galax.be>","Carlos Caballero <carlos.caballero.gonzalez@gmail.com>","hc <hheennrryy@gmail.com>","Muhammad Asif <capripio@gmail.com>","PrashoonB <prashoonbhattacharjee@gmail.com>","Harsh Bardhan Mishra <47351025+HarshCasper@users.noreply.github.com>","akotynski <aleksanderkotbury@gmail.com>","lmb <i@lmb.io>","Jairooo <jairocaro@msn.com>","Moritz Stückler <moritz.stueckler@gmail.com>","Simon <crydotsnakegithub@gmail.com>","Denis Lukov <denismassters@gmail.com>","Philipp Hancke <fippo@andyet.net>","Hans Oksendahl <hansoksendahl@gmail.com>","Jess <jessachandler@gmail.com>","khankuan <khankuan@gmail.com>","DUODVK <kurmanov.work@gmail.com>","XiZhao <kwang1imsa@gmail.com>","Matthias Lohr <matthias@lohr.me>","=frank tree <=frnktrb@googlemail.com>","Andre Eckardt <aeckardt@outlook.com>","Chris Cowan <agentme49@gmail.com>","Alex Chuev <alex@chuev.com>","alxnull <alxnull@e.mail.de>","Yemel Jardi <angel.jardi@gmail.com>","Ben Parnell <benjaminparnell.94@gmail.com>","Benny Lichtner <bennlich@gmail.com>","fresheneesz <bitetrudpublic@gmail.com>","bob.barstead@exaptive.com <bob.barstead@exaptive.com>","chandika <chandika@gmail.com>","emersion <contact@emersion.fr>","Christopher Van <cvan@users.noreply.github.com>","eddieherm <edhermoso@gmail.com>","Eduardo Pinho <enet4mikeenet@gmail.com>","Evandro Zanatta <ezanatta@tray.net.br>","Gardner Bickford <gardner@users.noreply.github.com>","Gian Luca <gianluca.cecchi@cynny.com>","PatrickJS <github@gdi2290.com>","jonnyf <github@jonathanfoss.co.uk>","Hizkia Felix <hizkifw@gmail.com>","Hristo Oskov <hristo.oskov@gmail.com>","Isaac Madwed <i.madwed@gmail.com>","Ilya Konanykhin <ilya.konanykhin@gmail.com>","jasonbarry <jasbarry@me.com>","Jonathan Burke <jonathan.burke.1311@googlemail.com>","Josh Hamit <josh.hamit@gmail.com>","Jordan Austin <jrax86@gmail.com>","Joel Wetzell <jwetzell@yahoo.com>","xizhao <kevin.wang@cloudera.com>","Alberto Torres <kungfoobar@gmail.com>","Jonathan Mayol <mayoljonathan@gmail.com>","Jefferson Felix <me@jsfelix.dev>","Rolf Erik Lekang <me@rolflekang.com>","Kevin Mai-Husan Chia <mhchia@users.noreply.github.com>","Pepijn de Vos <pepijndevos@gmail.com>","JooYoung <qkdlql@naver.com>","Tobias Speicher <rootcommander@gmail.com>","Steve Blaurock <sblaurock@gmail.com>","Kyrylo Shegeda <shegeda@ualberta.ca>","Diwank Singh Tomer <singh@diwank.name>","Sören Balko <Soeren.Balko@gmail.com>","Arpit Solanki <solankiarpit1997@gmail.com>","Yuki Ito <yuki@gnnk.net>","Artur Zayats <zag2art@gmail.com>"],"funding":{"type":"opencollective","url":"https://opencollective.com/peer"},"collective":{"type":"opencollective","url":"https://opencollective.com/peer"},"files":["dist/*"],"sideEffects":["lib/global.ts","lib/supports.ts"],"main":"dist/bundler.cjs","module":"dist/bundler.mjs","browser-minified":"dist/peerjs.min.js","browser-unminified":"dist/peerjs.js","types":"dist/types.d.ts","engines":{"node":">= 10"},"targets":{"types":{"source":"lib/exports.ts"},"main":{"source":"lib/exports.ts","sourceMap":{"inlineSources":true}},"module":{"source":"lib/exports.ts","includeNodeModules":["eventemitter3"],"sourceMap":{"inlineSources":true}},"browser-minified":{"context":"browser","outputFormat":"global","optimize":true,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"},"browser-unminified":{"context":"browser","outputFormat":"global","optimize":false,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"}},"scripts":{"contributors":"git-authors-cli --print=false && prettier --write package.json && git add package.json package-lock.json && git commit -m \\"chore(contributors): update and sort contributors list\\"","check":"tsc --noEmit","watch":"parcel watch","build":"rm -rf dist && parcel build","prepublishOnly":"npm run build","test":"mocha -r ts-node/register -r jsdom-global/register test/**/*.ts","format":"prettier --write .","semantic-release":"semantic-release"},"devDependencies":{"@parcel/config-default":"^2.5.0","@parcel/packager-ts":"^2.5.0","@parcel/transformer-typescript-tsc":"^2.5.0","@parcel/transformer-typescript-types":"^2.5.0","@semantic-release/changelog":"^6.0.1","@semantic-release/git":"^10.0.1","@types/chai":"^4.3.0","@types/mocha":"^9.1.0","@types/node":"^17.0.18","chai":"^4.3.6","git-authors-cli":"^1.0.40","jsdom":"^19.0.0","jsdom-global":"^3.0.2","mocha":"^9.2.0","mock-socket":"8.0.5","parcel":"^2.5.0","parcel-transformer-tsc-sourcemaps":"^1.0.2","prettier":"^2.6.2","semantic-release":"^19.0.2","standard":"^16.0.4","ts-node":"^10.5.0","typescript":"^4.5.5"},"dependencies":{"@swc/helpers":"^0.3.13","eventemitter3":"^4.0.7","peerjs-js-binarypack":"1.0.1","webrtc-adapter":"^7.7.1"}}`);var Ye=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if(typeof n!=`function`&&n!==null)throw TypeError(`Class extends value `+String(n)+` is not a constructor or null`);e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),Xe=function(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,a=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},Ze=function(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))},Qe=function(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)},$e=function(e){Ye(t,e);function t(t,n,r,i,a,o){o===void 0&&(o=5e3);var s=e.call(this)||this;return s.pingInterval=o,s._disconnected=!0,s._messagesQueue=[],s._baseUrl=(t?`wss://`:`ws://`)+n+`:`+r+i+`peerjs?key=`+a,s}return t.prototype.start=function(e,t){var n=this;this._id=e;var r=`${this._baseUrl}&id=${e}&token=${t}`;this._socket||!this._disconnected||(this._socket=new WebSocket(r+`&version=`+Je.version),this._disconnected=!1,this._socket.onmessage=function(e){var t;try{t=JSON.parse(e.data),H.default.log(`Server message received:`,t)}catch{H.default.log(`Invalid server message`,e.data);return}n.emit(Y.Message,t)},this._socket.onclose=function(e){n._disconnected||(H.default.log(`Socket closed.`,e),n._cleanup(),n._disconnected=!0,n.emit(Y.Disconnected))},this._socket.onopen=function(){n._disconnected||(n._sendQueuedMessages(),H.default.log(`Socket open`),n._scheduleHeartbeat())})},t.prototype._scheduleHeartbeat=function(){var e=this;this._wsPingTimer=setTimeout(function(){e._sendHeartbeat()},this.pingInterval)},t.prototype._sendHeartbeat=function(){if(!this._wsOpen()){H.default.log(`Cannot send heartbeat, because socket closed`);return}var e=JSON.stringify({type:X.Heartbeat});this._socket.send(e),this._scheduleHeartbeat()},t.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},t.prototype._sendQueuedMessages=function(){var e,t,n=Ze([],Xe(this._messagesQueue),!1);this._messagesQueue=[];try{for(var r=Qe(n),i=r.next();!i.done;i=r.next()){var a=i.value;this.send(a)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}},t.prototype.send=function(e){if(!this._disconnected){if(!this._id){this._messagesQueue.push(e);return}if(!e.type){this.emit(Y.Error,`Invalid message`);return}if(this._wsOpen()){var t=JSON.stringify(e);this._socket.send(t)}}},t.prototype.close=function(){this._disconnected||=(this._cleanup(),!0)},t.prototype._cleanup=function(){this._socket&&=(this._socket.onopen=this._socket.onmessage=this._socket.onclose=null,this._socket.close(),void 0),clearTimeout(this._wsPingTimer)},t}(R.EventEmitter),et={};F(et,`MediaConnection`,()=>dt,e=>dt=e);var tt={};F(tt,`Negotiator`,()=>it,e=>it=e);var nt=function(){return nt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},nt.apply(this,arguments)},Z=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},rt=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(o){if(r)throw TypeError(`Generator is already executing.`);for(;n;)try{if(r=1,i&&(a=o[0]&2?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[o[0]&2,a.value]),o[0]){case 0:case 1:a=o;break;case 4:return n.label++,{value:o[1],done:!1};case 5:n.label++,i=o[1],o=[0];continue;case 7:o=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(o[0]===6||o[0]===2)){n=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){n.label=o[1];break}if(o[0]===6&&n.label<a[1]){n.label=a[1],a=o;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(o);break}a[2]&&n.ops.pop(),n.trys.pop();continue}o=t.call(e,n)}catch(e){o=[6,e],i=0}finally{r=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}},it=function(){function e(e){this.connection=e}return e.prototype.startConnection=function(e){var t=this._startPeerConnection();if(this.connection.peerConnection=t,this.connection.type===K.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===K.Data){var n=this.connection,r={ordered:!!e.reliable},i=t.createDataChannel(n.label,r);n.initialize(i)}this._makeOffer()}else this.handleSDP(`OFFER`,e.sdp)},e.prototype._startPeerConnection=function(){H.default.log(`Creating RTCPeerConnection.`);var e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e},e.prototype._setupListeners=function(e){var t=this,n=this.connection.peer,r=this.connection.connectionId,i=this.connection.type,a=this.connection.provider;H.default.log(`Listening for ICE candidates.`),e.onicecandidate=function(e){!e.candidate||!e.candidate.candidate||(H.default.log(`Received ICE candidates for ${n}:`,e.candidate),a.socket.send({type:X.Candidate,payload:{candidate:e.candidate,type:i,connectionId:r},dst:n}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case`failed`:H.default.log(`iceConnectionState is failed, closing connections to `+n),t.connection.emit(`error`,Error(`Negotiation of connection to `+n+` failed.`)),t.connection.close();break;case`closed`:H.default.log(`iceConnectionState is closed, closing connections to `+n),t.connection.emit(`error`,Error(`Connection to `+n+` closed.`)),t.connection.close();break;case`disconnected`:H.default.log(`iceConnectionState changed to disconnected on the connection with `+n);break;case`completed`:e.onicecandidate=L.noop;break}t.connection.emit(`iceStateChanged`,e.iceConnectionState)},H.default.log(`Listening for data channel`),e.ondatachannel=function(e){H.default.log(`Received data channel`);var t=e.channel;a.getConnection(n,r).initialize(t)},H.default.log(`Listening for remote stream`),e.ontrack=function(e){H.default.log(`Received remote stream`);var i=e.streams[0],o=a.getConnection(n,r);if(o.type===K.Media){var s=o;t._addStreamToMediaConnection(i,s)}}},e.prototype.cleanup=function(){H.default.log(`Cleaning up PeerConnection to `+this.connection.peer);var e=this.connection.peerConnection;if(e){this.connection.peerConnection=null,e.onicecandidate=e.oniceconnectionstatechange=e.ondatachannel=e.ontrack=function(){};var t=e.signalingState!==`closed`,n=!1;if(this.connection.type===K.Data){var r=this.connection.dataChannel;r&&(n=!!r.readyState&&r.readyState!==`closed`)}(t||n)&&e.close()}},e.prototype._makeOffer=function(){return Z(this,void 0,Promise,function(){var e,t,n,r,i,a,o;return rt(this,function(s){switch(s.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,s.label=1;case 1:return s.trys.push([1,7,,8]),[4,e.createOffer(this.connection.options.constraints)];case 2:n=s.sent(),H.default.log(`Created offer.`),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform==`function`&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),s.label=3;case 3:return s.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return s.sent(),H.default.log(`Set localDescription:`,n,`for:${this.connection.peer}`),r={sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:L.browser},this.connection.type===K.Data&&(i=this.connection,r=nt(nt({},r),{label:i.label,reliable:i.reliable,serialization:i.serialization})),t.socket.send({type:X.Offer,payload:r,dst:this.connection.peer}),[3,6];case 5:return a=s.sent(),a!=`OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer`&&(t.emitError(q.WebRTC,a),H.default.log(`Failed to setLocalDescription, `,a)),[3,6];case 6:return[3,8];case 7:return o=s.sent(),t.emitError(q.WebRTC,o),H.default.log(`Failed to createOffer, `,o),[3,8];case 8:return[2]}})})},e.prototype._makeAnswer=function(){return Z(this,void 0,Promise,function(){var e,t,n,r,i;return rt(this,function(a){switch(a.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,a.label=1;case 1:return a.trys.push([1,7,,8]),[4,e.createAnswer()];case 2:n=a.sent(),H.default.log(`Created answer.`),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform==`function`&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),a.label=3;case 3:return a.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return a.sent(),H.default.log(`Set localDescription:`,n,`for:${this.connection.peer}`),t.socket.send({type:X.Answer,payload:{sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,browser:L.browser},dst:this.connection.peer}),[3,6];case 5:return r=a.sent(),t.emitError(q.WebRTC,r),H.default.log(`Failed to setLocalDescription, `,r),[3,6];case 6:return[3,8];case 7:return i=a.sent(),t.emitError(q.WebRTC,i),H.default.log(`Failed to create answer, `,i),[3,8];case 8:return[2]}})})},e.prototype.handleSDP=function(e,t){return Z(this,void 0,Promise,function(){var n,r,i,a;return rt(this,function(o){switch(o.label){case 0:t=new RTCSessionDescription(t),n=this.connection.peerConnection,r=this.connection.provider,H.default.log(`Setting remote description`,t),i=this,o.label=1;case 1:return o.trys.push([1,5,,6]),[4,n.setRemoteDescription(t)];case 2:return o.sent(),H.default.log(`Set remoteDescription:${e} for:${this.connection.peer}`),e===`OFFER`?[4,i._makeAnswer()]:[3,4];case 3:o.sent(),o.label=4;case 4:return[3,6];case 5:return a=o.sent(),r.emitError(q.WebRTC,a),H.default.log(`Failed to setRemoteDescription, `,a),[3,6];case 6:return[2]}})})},e.prototype.handleCandidate=function(e){return Z(this,void 0,Promise,function(){var t,n,r,i,a,o;return rt(this,function(s){switch(s.label){case 0:H.default.log(`handleCandidate:`,e),t=e.candidate,n=e.sdpMLineIndex,r=e.sdpMid,i=this.connection.peerConnection,a=this.connection.provider,s.label=1;case 1:return s.trys.push([1,3,,4]),[4,i.addIceCandidate(new RTCIceCandidate({sdpMid:r,sdpMLineIndex:n,candidate:t}))];case 2:return s.sent(),H.default.log(`Added ICE candidate for:${this.connection.peer}`),[3,4];case 3:return o=s.sent(),a.emitError(q.WebRTC,o),H.default.log(`Failed to handleCandidate, `,o),[3,4];case 4:return[2]}})})},e.prototype._addTracksToConnection=function(e,t){if(H.default.log(`add tracks from stream ${e.id} to peer connection`),!t.addTrack)return H.default.error(`Your browser does't support RTCPeerConnection#addTrack. Ignored.`);e.getTracks().forEach(function(n){t.addTrack(n,e)})},e.prototype._addStreamToMediaConnection=function(e,t){H.default.log(`add stream ${e.id} to media connection ${t.connectionId}`),t.addStream(e)},e}(),at={};F(at,`BaseConnection`,()=>st,e=>st=e);var ot=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if(typeof n!=`function`&&n!==null)throw TypeError(`Class extends value `+String(n)+` is not a constructor or null`);e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),st=function(e){ot(t,e);function t(t,n,r){var i=e.call(this)||this;return i.peer=t,i.provider=n,i.options=r,i._open=!1,i.metadata=r.metadata,i}return Object.defineProperty(t.prototype,`open`,{get:function(){return this._open},enumerable:!1,configurable:!0}),t}(R.EventEmitter),ct=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if(typeof n!=`function`&&n!==null)throw TypeError(`Class extends value `+String(n)+` is not a constructor or null`);e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),lt=function(){return lt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},lt.apply(this,arguments)},ut=function(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)},dt=function(e){ct(t,e);function t(n,r,i){var a=e.call(this,n,r,i)||this;return a._localStream=a.options._stream,a.connectionId=a.options.connectionId||t.ID_PREFIX+L.randomToken(),a._negotiator=new tt.Negotiator(a),a._localStream&&a._negotiator.startConnection({_stream:a._localStream,originator:!0}),a}return Object.defineProperty(t.prototype,`type`,{get:function(){return K.Media},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`localStream`,{get:function(){return this._localStream},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`remoteStream`,{get:function(){return this._remoteStream},enumerable:!1,configurable:!0}),t.prototype.addStream=function(t){H.default.log(`Receiving stream`,t),this._remoteStream=t,e.prototype.emit.call(this,`stream`,t)},t.prototype.handleMessage=function(e){var t=e.type,n=e.payload;switch(e.type){case X.Answer:this._negotiator.handleSDP(t,n.sdp),this._open=!0;break;case X.Candidate:this._negotiator.handleCandidate(n.candidate);break;default:H.default.warn(`Unrecognized message type:${t} from peer:${this.peer}`);break}},t.prototype.answer=function(e,t){var n,r;if(t===void 0&&(t={}),this._localStream){H.default.warn(`Local stream already exists on this MediaConnection. Are you answering a call twice?`);return}this._localStream=e,t&&t.sdpTransform&&(this.options.sdpTransform=t.sdpTransform),this._negotiator.startConnection(lt(lt({},this.options._payload),{_stream:e}));var i=this.provider._getMessages(this.connectionId);try{for(var a=ut(i),o=a.next();!o.done;o=a.next()){var s=o.value;this.handleMessage(s)}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}this._open=!0},t.prototype.close=function(){this._negotiator&&=(this._negotiator.cleanup(),null),this._localStream=null,this._remoteStream=null,this.provider&&=(this.provider._removeConnection(this),null),this.options&&this.options._stream&&(this.options._stream=null),this.open&&(this._open=!1,e.prototype.emit.call(this,`close`))},t.ID_PREFIX=`mc_`,t}(at.BaseConnection),ft={};F(ft,`DataConnection`,()=>vt,e=>vt=e);var pt={};F(pt,`EncodingQueue`,()=>ht,e=>ht=e);var mt=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if(typeof n!=`function`&&n!==null)throw TypeError(`Class extends value `+String(n)+` is not a constructor or null`);e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),ht=function(e){mt(t,e);function t(){var t=e.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(e){t._processing=!1,e.target&&t.emit(`done`,e.target.result),t.doNextTask()},t.fileReader.onerror=function(e){H.default.error(`EncodingQueue error:`,e),t._processing=!1,t.destroy(),t.emit(`error`,e)},t}return Object.defineProperty(t.prototype,`queue`,{get:function(){return this._queue},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`size`,{get:function(){return this.queue.length},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`processing`,{get:function(){return this._processing},enumerable:!1,configurable:!0}),t.prototype.enque=function(e){this.queue.push(e),!this.processing&&this.doNextTask()},t.prototype.destroy=function(){this.fileReader.abort(),this._queue=[]},t.prototype.doNextTask=function(){this.size!==0&&(this.processing||(this._processing=!0,this.fileReader.readAsArrayBuffer(this.queue.shift())))},t}(R.EventEmitter),gt=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if(typeof n!=`function`&&n!==null)throw TypeError(`Class extends value `+String(n)+` is not a constructor or null`);e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),_t=function(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)},vt=function(e){gt(t,e);function t(n,r,i){var a=e.call(this,n,r,i)||this;return a.stringify=JSON.stringify,a.parse=JSON.parse,a._buffer=[],a._bufferSize=0,a._buffering=!1,a._chunkedData={},a._encodingQueue=new pt.EncodingQueue,a.connectionId=a.options.connectionId||t.ID_PREFIX+L.randomToken(),a.label=a.options.label||a.connectionId,a.serialization=a.options.serialization||J.Binary,a.reliable=!!a.options.reliable,a._encodingQueue.on(`done`,function(e){a._bufferedSend(e)}),a._encodingQueue.on(`error`,function(){H.default.error(`DC#${a.connectionId}: Error occured in encoding from blob to arraybuffer, close DC`),a.close()}),a._negotiator=new tt.Negotiator(a),a._negotiator.startConnection(a.options._payload||{originator:!0}),a}return Object.defineProperty(t.prototype,`type`,{get:function(){return K.Data},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`dataChannel`,{get:function(){return this._dc},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`bufferSize`,{get:function(){return this._bufferSize},enumerable:!1,configurable:!0}),t.prototype.initialize=function(e){this._dc=e,this._configureDataChannel()},t.prototype._configureDataChannel=function(){var e=this;(!L.supports.binaryBlob||L.supports.reliable)&&(this.dataChannel.binaryType=`arraybuffer`),this.dataChannel.onopen=function(){H.default.log(`DC#${e.connectionId} dc connection success`),e._open=!0,e.emit(`open`)},this.dataChannel.onmessage=function(t){H.default.log(`DC#${e.connectionId} dc onmessage:`,t.data),e._handleDataMessage(t)},this.dataChannel.onclose=function(){H.default.log(`DC#${e.connectionId} dc closed for:`,e.peer),e.close()}},t.prototype._handleDataMessage=function(t){var n=this,r=t.data,i=r.constructor,a=this.serialization===J.Binary||this.serialization===J.BinaryUTF8,o=r;if(a){if(i===Blob){L.blobToArrayBuffer(r,function(e){var t=L.unpack(e);n.emit(`data`,t)});return}else if(i===ArrayBuffer)o=L.unpack(r);else if(i===String){var s=L.binaryStringToArrayBuffer(r);o=L.unpack(s)}}else this.serialization===J.JSON&&(o=this.parse(r));if(o.__peerData){this._handleChunk(o);return}e.prototype.emit.call(this,`data`,o)},t.prototype._handleChunk=function(e){var t=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){delete this._chunkedData[t];var r=new Blob(n.data);this._handleDataMessage({data:r})}},t.prototype.close=function(){this._buffer=[],this._bufferSize=0,this._chunkedData={},this._negotiator&&=(this._negotiator.cleanup(),null),this.provider&&=(this.provider._removeConnection(this),null),this.dataChannel&&(this.dataChannel.onopen=null,this.dataChannel.onmessage=null,this.dataChannel.onclose=null,this._dc=null),this._encodingQueue&&=(this._encodingQueue.destroy(),this._encodingQueue.removeAllListeners(),null),this.open&&(this._open=!1,e.prototype.emit.call(this,`close`))},t.prototype.send=function(t,n){if(!this.open){e.prototype.emit.call(this,`error`,Error("Connection is not open. You should listen for the `open` event before sending messages."));return}if(this.serialization===J.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===J.Binary||this.serialization===J.BinaryUTF8){var r=L.pack(t);if(!n&&r.size>L.chunkedMTU){this._sendChunks(r);return}L.supports.binaryBlob?this._bufferedSend(r):this._encodingQueue.enque(r)}else this._bufferedSend(t)},t.prototype._bufferedSend=function(e){(this._buffering||!this._trySend(e))&&(this._buffer.push(e),this._bufferSize=this._buffer.length)},t.prototype._trySend=function(e){var n=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>t.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){n._buffering=!1,n._tryBuffer()},50),!1;try{this.dataChannel.send(e)}catch(e){return H.default.error(`DC#:${this.connectionId} Error when sending:`,e),this._buffering=!0,this.close(),!1}return!0},t.prototype._tryBuffer=function(){if(this.open&&this._buffer.length!==0){var e=this._buffer[0];this._trySend(e)&&(this._buffer.shift(),this._bufferSize=this._buffer.length,this._tryBuffer())}},t.prototype._sendChunks=function(e){var t,n,r=L.chunk(e);H.default.log(`DC#${this.connectionId} Try to send ${r.length} chunks...`);try{for(var i=_t(r),a=i.next();!a.done;a=i.next()){var o=a.value;this.send(o,!0)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}},t.prototype.handleMessage=function(e){var t=e.payload;switch(e.type){case X.Answer:this._negotiator.handleSDP(e.type,t.sdp);break;case X.Candidate:this._negotiator.handleCandidate(t.candidate);break;default:H.default.warn(`Unrecognized message type:`,e.type,`from peer:`,this.peer);break}},t.ID_PREFIX=`dc_`,t.MAX_BUFFERED_AMOUNT=8388608,t}(at.BaseConnection),yt={};F(yt,`API`,()=>St,e=>St=e);var bt=function(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})},xt=function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(o){if(r)throw TypeError(`Generator is already executing.`);for(;n;)try{if(r=1,i&&(a=o[0]&2?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[o[0]&2,a.value]),o[0]){case 0:case 1:a=o;break;case 4:return n.label++,{value:o[1],done:!1};case 5:n.label++,i=o[1],o=[0];continue;case 7:o=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(o[0]===6||o[0]===2)){n=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){n.label=o[1];break}if(o[0]===6&&n.label<a[1]){n.label=a[1],a=o;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(o);break}a[2]&&n.ops.pop(),n.trys.pop();continue}o=t.call(e,n)}catch(e){o=[6,e],i=0}finally{r=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}},St=function(){function e(e){this._options=e}return e.prototype._buildRequest=function(e){var t=this._options.secure?`https`:`http`,n=this._options,r=n.host,i=n.port,a=n.path,o=n.key,s=new URL(`${t}://${r}:${i}${a}${o}/${e}`);return s.searchParams.set(`ts`,`${Date.now()}${Math.random()}`),s.searchParams.set(`version`,Je.version),fetch(s.href,{referrerPolicy:this._options.referrerPolicy})},e.prototype.retrieveId=function(){return bt(this,void 0,Promise,function(){var e,t,n;return xt(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this._buildRequest(`id`)];case 1:if(e=r.sent(),e.status!==200)throw Error(`Error. Status:${e.status}`);return[2,e.text()];case 2:throw t=r.sent(),H.default.error(`Error retrieving ID`,t),n=``,this._options.path===`/`&&this._options.host!==L.CLOUD_HOST&&(n=" 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."),Error(`Could not get an ID from the server.`+n);case 3:return[2]}})})},e.prototype.listAllPeers=function(){return bt(this,void 0,Promise,function(){var e,t,n;return xt(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this._buildRequest(`peers`)];case 1:if(e=r.sent(),e.status!==200)throw e.status===401?(t=``,t=this._options.host===L.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.",Error(`It doesn't look like you have permission to list peers IDs. `+t)):Error(`Error. Status:${e.status}`);return[2,e.json()];case 2:throw n=r.sent(),H.default.error(`Error retrieving list peers`,n),Error(`Could not get list peers from the server.`+n);case 3:return[2]}})})},e}(),Ct=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if(typeof n!=`function`&&n!==null)throw TypeError(`Class extends value `+String(n)+` is not a constructor or null`);e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),Q=function(){return Q=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},Q.apply(this,arguments)},$=function(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)},wt=function(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,a=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a};(function(){function e(){}return e})();var Tt=function(e){Ct(t,e);function t(n,r){var i=e.call(this)||this;i._id=null,i._lastServerId=null,i._destroyed=!1,i._disconnected=!1,i._open=!1,i._connections=new Map,i._lostMessages=new Map;var a;return n&&n.constructor==Object?r=n:n&&(a=n.toString()),r=Q({debug:0,host:L.CLOUD_HOST,port:L.CLOUD_PORT,path:`/`,key:t.DEFAULT_KEY,token:L.randomToken(),config:L.defaultConfig,referrerPolicy:`strict-origin-when-cross-origin`},r),i._options=r,i._options.host===`/`&&(i._options.host=window.location.hostname),i._options.path&&(i._options.path[0]!==`/`&&(i._options.path=`/`+i._options.path),i._options.path[i._options.path.length-1]!==`/`&&(i._options.path+=`/`)),i._options.secure===void 0&&i._options.host!==L.CLOUD_HOST?i._options.secure=L.isSecure():i._options.host==L.CLOUD_HOST&&(i._options.secure=!0),i._options.logFunction&&H.default.setLogFunction(i._options.logFunction),H.default.logLevel=i._options.debug||0,i._api=new yt.API(r),i._socket=i._createServerConnection(),!L.supports.audioVideo&&!L.supports.data?(i._delayedAbort(q.BrowserIncompatible,`The current browser does not support WebRTC`),i):a&&!L.validateId(a)?(i._delayedAbort(q.InvalidID,`ID "${a}" is invalid`),i):(a?i._initialize(a):i._api.retrieveId().then(function(e){return i._initialize(e)}).catch(function(e){return i._abort(q.ServerError,e)}),i)}return Object.defineProperty(t.prototype,`id`,{get:function(){return this._id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`options`,{get:function(){return this._options},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`open`,{get:function(){return this._open},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`socket`,{get:function(){return this._socket},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`connections`,{get:function(){var e,t,n=Object.create(null);try{for(var r=$(this._connections),i=r.next();!i.done;i=r.next()){var a=wt(i.value,2),o=a[0];n[o]=a[1]}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}return n},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`destroyed`,{get:function(){return this._destroyed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,`disconnected`,{get:function(){return this._disconnected},enumerable:!1,configurable:!0}),t.prototype._createServerConnection=function(){var e=this,t=new qe.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return t.on(Y.Message,function(t){e._handleMessage(t)}),t.on(Y.Error,function(t){e._abort(q.SocketError,t)}),t.on(Y.Disconnected,function(){e.disconnected||(e.emitError(q.Network,`Lost connection to server.`),e.disconnect())}),t.on(Y.Close,function(){e.disconnected||e._abort(q.SocketClosed,`Underlying socket is already closed.`)}),t},t.prototype._initialize=function(e){this._id=e,this.socket.start(e,this._options.token)},t.prototype._handleMessage=function(e){var t,n,r=e.type,i=e.payload,a=e.src;switch(r){case X.Open:this._lastServerId=this.id,this._open=!0,this.emit(`open`,this.id);break;case X.Error:this._abort(q.ServerError,i.msg);break;case X.IdTaken:this._abort(q.UnavailableID,`ID "${this.id}" is taken`);break;case X.InvalidKey:this._abort(q.InvalidKey,`API KEY "${this._options.key}" is invalid`);break;case X.Leave:H.default.log(`Received leave message from ${a}`),this._cleanupPeer(a),this._connections.delete(a);break;case X.Expire:this.emitError(q.PeerUnavailable,`Could not connect to peer ${a}`);break;case X.Offer:var o=i.connectionId,s=this.getConnection(a,o);if(s&&(s.close(),H.default.warn(`Offer received for existing Connection ID:${o}`)),i.type===K.Media){var c=new et.MediaConnection(a,this,{connectionId:o,_payload:i,metadata:i.metadata});s=c,this._addConnection(a,s),this.emit(`call`,c)}else if(i.type===K.Data){var l=new ft.DataConnection(a,this,{connectionId:o,_payload:i,metadata:i.metadata,label:i.label,serialization:i.serialization,reliable:i.reliable});s=l,this._addConnection(a,s),this.emit(`connection`,l)}else{H.default.warn(`Received malformed connection type:${i.type}`);return}var u=this._getMessages(o);try{for(var d=$(u),f=d.next();!f.done;f=d.next()){var p=f.value;s.handleMessage(p)}}catch(e){t={error:e}}finally{try{f&&!f.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}break;default:if(!i){H.default.warn(`You received a malformed message from ${a} of type ${r}`);return}var o=i.connectionId,s=this.getConnection(a,o);s&&s.peerConnection?s.handleMessage(e):o?this._storeMessage(o,e):H.default.warn(`You received an unrecognized message:`,e);break}},t.prototype._storeMessage=function(e,t){this._lostMessages.has(e)||this._lostMessages.set(e,[]),this._lostMessages.get(e).push(t)},t.prototype._getMessages=function(e){var t=this._lostMessages.get(e);return t?(this._lostMessages.delete(e),t):[]},t.prototype.connect=function(e,t){if(t===void 0&&(t={}),this.disconnected){H.default.warn(`You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect, or call reconnect on this peer if you believe its ID to still be available.`),this.emitError(q.Disconnected,`Cannot connect to new Peer after disconnecting from server.`);return}var n=new ft.DataConnection(e,this,t);return this._addConnection(e,n),n},t.prototype.call=function(e,t,n){if(n===void 0&&(n={}),this.disconnected){H.default.warn(`You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect.`),this.emitError(q.Disconnected,`Cannot connect to new Peer after disconnecting from server.`);return}if(!t){H.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var r=new et.MediaConnection(e,this,Q(Q({},n),{_stream:t}));return this._addConnection(e,r),r},t.prototype._addConnection=function(e,t){H.default.log(`add connection ${t.type}:${t.connectionId} to peerId:${e}`),this._connections.has(e)||this._connections.set(e,[]),this._connections.get(e).push(t)},t.prototype._removeConnection=function(e){var t=this._connections.get(e.peer);if(t){var n=t.indexOf(e);n!==-1&&t.splice(n,1)}this._lostMessages.delete(e.connectionId)},t.prototype.getConnection=function(e,t){var n,r,i=this._connections.get(e);if(!i)return null;try{for(var a=$(i),o=a.next();!o.done;o=a.next()){var s=o.value;if(s.connectionId===t)return s}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return null},t.prototype._delayedAbort=function(e,t){var n=this;setTimeout(function(){n._abort(e,t)},0)},t.prototype._abort=function(e,t){H.default.error(`Aborting!`),this.emitError(e,t),this._lastServerId?this.disconnect():this.destroy()},t.prototype.emitError=function(e,t){H.default.error(`Error:`,t);var n=typeof t==`string`?Error(t):t;n.type=e,this.emit(`error`,n)},t.prototype.destroy=function(){this.destroyed||(H.default.log(`Destroy peer with ID:${this.id}`),this.disconnect(),this._cleanup(),this._destroyed=!0,this.emit(`close`))},t.prototype._cleanup=function(){var e,t;try{for(var n=$(this._connections.keys()),r=n.next();!r.done;r=n.next()){var i=r.value;this._cleanupPeer(i),this._connections.delete(i)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}this.socket.removeAllListeners()},t.prototype._cleanupPeer=function(e){var t,n,r=this._connections.get(e);if(r)try{for(var i=$(r),a=i.next();!a.done;a=i.next())a.value.close()}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}},t.prototype.disconnect=function(){if(!this.disconnected){var e=this.id;H.default.log(`Disconnect peer with ID:${e}`),this._disconnected=!0,this._open=!1,this.socket.close(),this._lastServerId=e,this._id=null,this.emit(`disconnected`,e)}},t.prototype.reconnect=function(){if(this.disconnected&&!this.destroyed)H.default.log(`Attempting reconnection to server with ID ${this._lastServerId}`),this._disconnected=!1,this._initialize(this._lastServerId);else if(this.destroyed)throw Error(`This peer cannot reconnect to the server. It has already been destroyed.`);else if(!this.disconnected&&!this.open)H.default.error(`In a hurry? We're still trying to make the initial connection!`);else throw Error(`Peer ${this.id} cannot reconnect because it is not disconnected from the server!`)},t.prototype.listAllPeers=function(e){var t=this;e===void 0&&(e=function(e){}),this._api.listAllPeers().then(function(t){return e(t)}).catch(function(e){return t._abort(q.ServerError,e)})},t.DEFAULT_KEY=`peerjs`,t}(R.EventEmitter),Et=Be.Peer;export{Le as t}; |