text: !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var t,n,o=(function(t){var n,o;n=e,o=function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"];function i(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(o){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function r(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function s(o){return"debug"===o&&(o="log"),typeof console!==t&&("trace"===o&&n?r:void 0!==console[o]?i(console,o):void 0!==console.log?i(console,"log"):e)}function a(t,n){for(var i=0;i<o.length;i++){var r=o[i];this[r]=i<t?e:this.methodFactory(r,t,n)}this.log=this.debug}function c(e,n,o){return function(){typeof console!==t&&(a.call(this,n,o),this[e].apply(this,arguments))}}function d(e,t,n){return s(e)||c.apply(this,arguments)}function l(e,n,i){var r,s=this,c="loglevel";function l(){var e;if(typeof window!==t){try{e=window.localStorage[c]}catch(i){}if(typeof e===t)try{var n=window.document.cookie,o=n.indexOf(encodeURIComponent(c)+"=");-1!==o&&(e=/^([^;]+)/.exec(n.slice(o))[1])}catch(i){}return void 0===s.levels[e]&&(e=void 0),e}}e&&(c+=":"+e),s.name=e,s.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},s.methodFactory=i||d,s.getLevel=function(){return r},s.setLevel=function(n,i){if("string"==typeof n&&void 0!==s.levels[n.toUpperCase()]&&(n=s.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=s.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(r=n,!1!==i&&function(e){var n=(o[e]||"silent").toUpperCase();if(typeof window!==t){try{return void(window.localStorage[c]=n)}catch(i){}try{window.document.cookie=encodeURIComponent(c)+"="+n+";"}catch(i){}}}(n),a.call(s,n,e),typeof console===t&&n<s.levels.SILENT)return"No console available for logging"},s.setDefaultLevel=function(e){l()||s.setLevel(e,!1)},s.enableAll=function(e){s.setLevel(s.levels.TRACE,e)},s.disableAll=function(e){s.setLevel(s.levels.SILENT,e)};var u=l();null==u&&(u=null==n?"WARN":n),s.setLevel(u,!1)}var u=new l,p={};u.getLogger=function(e){if("string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=p[e];return t||(t=p[e]=new l(e,u.getLevel(),u.methodFactory)),t};var h=typeof window!==t?window.log:void 0;return u.noConflict=function(){return typeof window!==t&&window.log===u&&(window.log=h),u},u.getLoggers=function(){return p},u},t.exports?t.exports=o():n.log=o()}(n={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&n.path)}},n.exports),n.exports);const i=((e,t=!0)=>{const n=o.getLogger(e);return n.methodFactory=(t,n,i)=>{const r=(0,o.methodFactory)(t,n,i);return function(){r(`${e} ${(new Date).toUTCString()}`,...arguments)}},t?n.enableAll():n.setLevel(4),n})("ObserverRTC",!1);class r{constructor(){this.runInternal=this.runInternal.bind(this)}start(e,t){this._runnable=e,this._intervalDurationInMs=t,this.runInternal()}stop(){this._runId&&(clearTimeout(this._runId),this._runId=void 0)}runInternal(){var e;null===(e=this._runnable)||void 0===e||e.execute(),this._runId=setTimeout(this.runInternal.bind(this),this._intervalDurationInMs)}}class s{constructor(e){this._workerCallback=e,this.setWorkerScope=this.setWorkerScope.bind(this),this.onMessage=this.onMessage.bind(this),this.requestInitialConfig=this.requestInitialConfig.bind(this),this.requestRawStats=this.requestRawStats.bind(this),this.sendTransportData=this.sendTransportData.bind(this)}setWorkerScope(e){this._workerScope=e}onMessage(e){var t,n,o;const r=e.data;switch(r.what){case"onRequestRawStats":return void(null===(t=this._workerCallback)||void 0===t||t.onResponseRawStats(r.data));case"onRequestInitialConfig":return void(null===(n=this._workerCallback)||void 0===n||n.onResponseInitialConfig(r.data));case"onUserMediaError":return void(null===(o=this._workerCallback)||void 0===o||o.onUserMediaError(r.data));default:i.warn("unknown types",r)}}requestInitialConfig(){this._workerScope.postMessage({what:"requestInitialConfig"})}requestRawStats(){this._workerScope.postMessage({what:"requestRawStats"})}sendTransportData(e){this._workerScope.postMessage({data:e,what:"onLocalTransport"})}}class a{isMediaSoupIntegration(e){return e&&e.length>0&&"Mediasoup"===e[0].details.integration}filterShortCalls(e){return e.filter(this.hasStats.bind(this))}hasStats(e){return e.stats.receiverStats.length>0||e.stats.senderStats.length>0}}class c{isTokBoxIntegration(e){return e&&e.length>0&&"TokBox"===e[0].details.integration}filterShortCalls(e){return e.filter(this.hasStats.bind(this))}hasStats(e){return e.stats.receiverStats.length>0||e.stats.senderStats.length>0}}class d{constructor(){this._tokBoxOptimizer=new c,this._mediaSoupOptimizer=new a}optimize(e){return this._tokBoxOptimizer.isTokBoxIntegration(e)?this._tokBoxOptimizer.filterShortCalls(e):this._mediaSoupOptimizer.isMediaSoupIntegration(e)?this._mediaSoupOptimizer.filterShortCalls(e):e}}class l{static localCandidate(e){const{candidateType:t,deleted:n,id:o,ip:i,isRemote:r,networkType:s,port:a,priority:c,protocol:d,transportId:l}=e;return{candidateType:t,deleted:n,id:o,ip:i,isRemote:r,networkType:s,port:a,priority:c,protocol:d,transportId:l}}static remoteCandidate(e){const{candidateType:t,deleted:n,id:o,ip:i,isRemote:r,port:s,priority:a,protocol:c,transportId:d}=e;return{candidateType:t,deleted:n,id:o,ip:i,isRemote:r,port:s,priority:a,protocol:c,transportId:d}}static candidatePair(e){const{availableOutgoingBitrate:t,bytesReceived:n,bytesSent:o,consentRequestsSent:i,currentRoundTripTime:r,id:s,localCandidateId:a,nominated:c,priority:d,remoteCandidateId:l,requestsReceived:u,requestsSent:p,responsesReceived:h,responsesSent:m,state:f,totalRoundTripTime:y,transportId:_,writable:g}=e;return{availableOutgoingBitrate:t,bytesReceived:n,bytesSent:o,consentRequestsSent:i,currentRoundTripTime:r,id:s,localCandidateId:a,nominated:c,priority:d,remoteCandidateId:l,requestsReceived:u,requestsSent:p,responsesReceived:h,responsesSent:m,state:f,totalRoundTripTime:y,transportId:_,writable:g}}static mediaSource(e){const{audioLevel:t,framesPerSecond:n,height:o,id:i,mediaType:r,totalAudioEnergy:s,totalSamplesDuration:a,trackId:c,width:d}=e;return{audioLevel:t,framesPerSecond:n,height:o,id:i,mediaType:r||e.kind,totalAudioEnergy:s,totalSamplesDuration:a,trackId:c||e.trackIdentifier,width:d}}static inboundRTPStatElement(e){const{bytesReceived:t,codecId:n,decoderImplementation:o,estimatedPlayoutTimestamp:i,fecPacketsDiscarded:r,fecPacketsReceived:s,firCount:a,framesDecoded:c,headerBytesReceived:d,id:l,isRemote:u,jitter:p,keyFramesDecoded:h,lastPacketReceivedTimestamp:m,mediaType:f,nackCount:y,packetsLost:_,packetsReceived:g,pliCount:v,qpSum:b,ssrc:S,totalDecodeTime:w,totalInterFrameDelay:T,totalSquaredInterFrameDelay:C,trackId:k,transportId:I}=e;return{bytesReceived:t,codecId:n,decoderImplementation:o,estimatedPlayoutTimestamp:i,fecPacketsDiscarded:r,fecPacketsReceived:s,firCount:a,framesDecoded:c,headerBytesReceived:d,id:l,isRemote:u,jitter:p,keyFramesDecoded:h,lastPacketReceivedTimestamp:m,mediaType:f||e.kind,nackCount:y,packetsLost:_,packetsReceived:g,pliCount:v,qpSum:b,ssrc:S,totalDecodeTime:w,totalInterFrameDelay:T,totalSquaredInterFrameDelay:C,trackId:k,transportId:I}}static outboundRTPStatElement(e){const{bytesSent:t,codecId:n,encoderImplementation:o,firCount:i,framesEncoded:r,headerBytesSent:s,id:a,isRemote:c,keyFramesEncoded:d,mediaSourceId:l,mediaType:u,nackCount:p,packetsSent:h,pliCount:m,qpSum:f,qualityLimitationReason:y,qualityLimitationResolutionChanges:_,remoteId:g,retransmittedBytesSent:v,retransmittedPacketsSent:b,ssrc:S,totalEncodedBytesTarget:w,totalEncodeTime:T,totalPacketSendDelay:C,trackId:k,transportId:I}=e;return{bytesSent:t,codecId:n,encoderImplementation:o,firCount:i,framesEncoded:r,headerBytesSent:s,id:a,isRemote:c,keyFramesEncoded:d,mediaSourceId:l,mediaType:u||e.kind,nackCount:p,packetsSent:h,pliCount:m,qpSum:f,qualityLimitationReason:y,qualityLimitationResolutionChanges:_,remoteId:g,retransmittedBytesSent:v,retransmittedPacketsSent:b,ssrc:S,totalEncodeTime:T,totalEncodedBytesTarget:w,totalPacketSendDelay:C,trackId:k,transportId:I}}static remoteInboundRTPStatElement(e){const{codecId:t,id:n,jitter:o,localId:i,mediaType:r,packetsLost:s,roundTripTime:a,ssrc:c,transportId:d}=e;return{codecId:t,id:n,jitter:o,localId:i,mediaType:r||e.kind,packetsLost:s,roundTripTime:a,ssrc:c,transportId:d}}static track(e){const{concealedSamples:t,concealmentEvents:n,detached:o,ended:i,framesDecoded:r,framesDropped:s,framesReceived:a,hugeFramesSent:c,id:d,insertedSamplesForDeceleration:l,jitterBufferDelay:u,jitterBufferEmittedCount:p,mediaSourceId:h,mediaType:m,remoteSource:f,removedSamplesForAcceleration:y,samplesDuration:_,silentConcealedSamples:g,totalSamplesReceived:v}=e;return{concealedSamples:t,concealmentEvents:n,detached:o,ended:i,framesDecoded:r,framesDropped:s,framesReceived:a,hugeFramesSent:c,id:d,insertedSamplesForDeceleration:l,jitterBufferDelay:u,jitterBufferEmittedCount:p,mediaSourceId:h,mediaType:m||e.kind,remoteSource:f,removedSamplesForAcceleration:y,samplesDuration:_,silentConcealedSamples:g,totalSamplesReceived:v}}}class u{static getSendRecvStats(e){return{inboundRTPStats:e.filter((e=>"inbound-rtp"===e.type)).map((e=>l.inboundRTPStatElement(e))),mediaSources:e.filter((e=>"media-source"===e.type)).map((e=>l.mediaSource(e))),outboundRTPStats:e.filter((e=>"outbound-rtp"===e.type)).map((e=>l.outboundRTPStatElement(e))),remoteInboundRTPStats:e.filter((e=>"remote-inbound-rtp"===e.type)).map((e=>l.remoteInboundRTPStatElement(e))),tracks:e.filter((e=>"track"===e.type)).map((e=>l.track(e)))}}static getIceStats(e){const{receiverStats:t,senderStats:n}=e,o=[...t.map((e=>e)).filter((e=>"local-candidate"===e.type)),...n.map((e=>e)).filter((e=>"local-candidate"===e.type))].map((e=>l.localCandidate(e))),i=[...t.map((e=>e)).filter((e=>"remote-candidate"===e.type)),...n.map((e=>e)).filter((e=>"remote-candidate"===e.type))].map((e=>l.remoteCandidate(e)));return{candidatePairs:[...t.map((e=>e)).filter((e=>"candidate-pair"===e.type)),...n.map((e=>e)).filter((e=>"candidate-pair"===e.type))].map((e=>l.candidatePair(e))),localCandidates:o,remoteCandidates:i}}}class p{constructor(){this._lastStatList=[],this.addStatBulk=this.addStatBulk.bind(this),this.getLast=this.getLast.bind(this),this.removeOldBulk=this.removeOldBulk.bind(this),this.isEqual=this.isEqual.bind(this),this.excludeSameCandidates=this.excludeSameCandidates.bind(this)}excludeSameCandidates(e){var t,n,o,i,r,s;const a=this.getLast(e);if(!a)return e;const c=JSON.parse(JSON.stringify(e));return this.isEqual(null===(t=a.iceStats)||void 0===t?void 0:t.localCandidates,null===(n=e.iceStats)||void 0===n?void 0:n.localCandidates)&&(null===(o=c.iceStats)||void 0===o||delete o.localCandidates),this.isEqual(null===(i=a.iceStats)||void 0===i?void 0:i.remoteCandidates,null===(r=e.iceStats)||void 0===r?void 0:r.remoteCandidates)&&(null===(s=c.iceStats)||void 0===s||delete s.remoteCandidates),c}addStatBulk(e){this._lastStatList.push(...e),this.removeOldBulk()}isEqual(e=[],t=[]){return t.every((t=>e.some((e=>e.id===t.id))))}removeOldBulk(){const e=class{static getCurrent(){return Date.now()}static getTimeZoneOffsetInMinute(){return(new Date).getTimezoneOffset()}}.getCurrent();this._lastStatList=this._lastStatList.filter((t=>e-t.timestamp<15e3))}getLast(e){for(let t=this._lastStatList.length-1;t>=0;t-=1)if(this._lastStatList[t].peerConnectionId===e.peerConnectionId)return this._lastStatList[t]}}var h=function(e,t){return(h=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function m(e,t){function n(){this.constructor=e}h(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function f(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,i,r=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(o=r.next()).done;)s.push(o.value)}catch(a){i={error:a}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return s}function y(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(f(arguments[t]));return e}var _=function(e,t){this.target=t,this.type=e},g=function(e){function t(t,n){var o=e.call(this,"error",n)||this;return o.message=t.message,o.error=t,o}return m(t,e),t}(_),v=function(e){function t(t,n,o){void 0===t&&(t=1e3),void 0===n&&(n="");var i=e.call(this,"close",o)||this;return i.wasClean=!0,i.code=t,i.reason=n,i}return m(t,e),t}(_),b=function(){if("undefined"!=typeof WebSocket)return WebSocket},S={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+4e3*Math.random(),minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1},w=function(){function e(e,t,n){var o=this;void 0===n&&(n={}),this._listeners={error:[],message:[],open:[],close:[]},this._retryCount=-1,this._shouldReconnect=!0,this._connectLock=!1,this._binaryType="blob",this._closeCalled=!1,this._messageQueue=[],this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this._handleOpen=function(e){o._debug("open event");var t=o._options.minUptime,n=void 0===t?S.minUptime:t;clearTimeout(o._connectTimeout),o._uptimeTimeout=setTimeout((function(){return o._acceptOpen()}),n),o._ws.binaryType=o._binaryType,o._messageQueue.forEach((function(e){return o._ws.send(e)})),o._messageQueue=[],o.onopen&&o.onopen(e),o._listeners.open.forEach((function(t){return o._callEventListener(e,t)}))},this._handleMessage=function(e){o._debug("message event"),o.onmessage&&o.onmessage(e),o._listeners.message.forEach((function(t){return o._callEventListener(e,t)}))},this._handleError=function(e){o._debug("error event",e.message),o._disconnect(void 0,"TIMEOUT"===e.message?"timeout":void 0),o.onerror&&o.onerror(e),o._debug("exec error listeners"),o._listeners.error.forEach((function(t){return o._callEventListener(e,t)})),o._connect()},this._handleClose=function(e){o._debug("close event"),o._clearTimeouts(),o._shouldReconnect&&o._connect(),o.onclose&&o.onclose(e),o._listeners.close.forEach((function(t){return o._callEventListener(e,t)}))},this._url=e,this._protocols=t,this._options=n,this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}return Object.defineProperty(e,"CONNECTING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OPEN",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSED",{get:function(){return 3},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CONNECTING",{get:function(){return e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"OPEN",{get:function(){return e.OPEN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSING",{get:function(){return e.CLOSING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSED",{get:function(){return e.CLOSED},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"binaryType",{get:function(){return this._ws?this._ws.binaryType:this._binaryType},set:function(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"retryCount",{get:function(){return Math.max(this._retryCount,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bufferedAmount",{get:function(){return this._messageQueue.reduce((function(e,t){return"string"==typeof t?e+=t.length:t instanceof Blob?e+=t.size:e+=t.byteLength,e}),0)+(this._ws?this._ws.bufferedAmount:0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"extensions",{get:function(){return this._ws?this._ws.extensions:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"protocol",{get:function(){return this._ws?this._ws.protocol:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"readyState",{get:function(){return this._ws?this._ws.readyState:this._options.startClosed?e.CLOSED:e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"url",{get:function(){return this._ws?this._ws.url:""},enumerable:!0,configurable:!0}),e.prototype.close=function(e,t){void 0===e&&(e=1e3),this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),this._ws?this._ws.readyState!==this.CLOSED?this._ws.close(e,t):this._debug("close: already closed"):this._debug("close enqueued: no ws instance")},e.prototype.reconnect=function(e,t){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,this._ws&&this._ws.readyState!==this.CLOSED?(this._disconnect(e,t),this._connect()):this._connect()},e.prototype.send=function(e){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",e),this._ws.send(e);else{var t=this._options.maxEnqueuedMessages,n=void 0===t?S.maxEnqueuedMessages:t;this._messageQueue.length<n&&(this._debug("enqueue",e),this._messageQueue.push(e))}},e.prototype.addEventListener=function(e,t){this._listeners[e]&&this._listeners[e].push(t)},e.prototype.dispatchEvent=function(e){var t,n,o=this._listeners[e.type];if(o)try{for(var i=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}(o),r=i.next();!r.done;r=i.next()){var s=r.value;this._callEventListener(e,s)}}catch(a){t={error:a}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return!0},e.prototype.removeEventListener=function(e,t){this._listeners[e]&&(this._listeners[e]=this._listeners[e].filter((function(e){return e!==t})))},e.prototype._debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._options.debug&&console.log.apply(console,y(["RWS>"],e))},e.prototype._getNextDelay=function(){var e=this._options,t=e.reconnectionDelayGrowFactor,n=void 0===t?S.reconnectionDelayGrowFactor:t,o=e.minReconnectionDelay,i=void 0===o?S.minReconnectionDelay:o,r=e.maxReconnectionDelay,s=void 0===r?S.maxReconnectionDelay:r,a=0;return this._retryCount>0&&(a=i*Math.pow(n,this._retryCount-1))>s&&(a=s),this._debug("next delay",a),a},e.prototype._wait=function(){var e=this;return new Promise((function(t){setTimeout(t,e._getNextDelay())}))},e.prototype._getNextUrl=function(e){if("string"==typeof e)return Promise.resolve(e);if("function"==typeof e){var t=e();if("string"==typeof t)return Promise.resolve(t);if(t.then)return t}throw Error("Invalid URL")},e.prototype._connect=function(){var e=this;if(!this._connectLock&&this._shouldReconnect){this._connectLock=!0;var t=this._options,n=t.maxRetries,o=void 0===n?S.maxRetries:n,i=t.connectionTimeout,r=void 0===i?S.connectionTimeout:i,s=t.WebSocket,a=void 0===s?b():s;if(this._retryCount>=o)this._debug("max retries reached",this._retryCount,">=",o);else{if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),void 0===(c=a)||!c||2!==c.CLOSING)throw Error("No valid WebSocket class provided");var c;this._wait().then((function(){return e._getNextUrl(e._url)})).then((function(t){e._closeCalled||(e._debug("connect",{url:t,protocols:e._protocols}),e._ws=e._protocols?new a(t,e._protocols):new a(t),e._ws.binaryType=e._binaryType,e._connectLock=!1,e._addListeners(),e._connectTimeout=setTimeout((function(){return e._handleTimeout()}),r))}))}}},e.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new g(Error("TIMEOUT"),this))},e.prototype._disconnect=function(e,t){if(void 0===e&&(e=1e3),this._clearTimeouts(),this._ws){this._removeListeners();try{this._ws.close(e,t),this._handleClose(new v(e,t,this))}catch(n){}}},e.prototype._acceptOpen=function(){this._debug("accept open"),this._retryCount=0},e.prototype._callEventListener=function(e,t){"handleEvent"in t?t.handleEvent(e):t(e)},e.prototype._removeListeners=function(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))},e.prototype._addListeners=function(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))},e.prototype._clearTimeouts=function(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)},e}();class T{constructor(e){if(this.send=this.send.bind(this),this.sendBulk=this.sendBulk.bind(this),!e)throw new Error("websocker server address is required");this._webSocket=new w(e,[],{connectionTimeout:3e4,debug:!1,maxEnqueuedMessages:120,maxRetries:100}),this._webSocket.onclose=e=>{i.warn("websocket closed",e)},this._webSocket.onerror=e=>{i.warn("websocket error",e)},this._webSocket.onopen=e=>{i.warn("websocket on open",e)}}dispose(){var e;null===(e=this._webSocket)||void 0===e||e.close(),this._webSocket=void 0}send(e){var t;i.warn("sending payload ->",e),null===(t=this._webSocket)||void 0===t||t.send(JSON.stringify(e))}sendBulk(e){e.forEach((e=>{this.send(e)}))}}const C=new class{constructor(){this._cron=new r,this._statsOptimizer=new p,this._integrationOptimizer=new d,this._processorWorker=new s(this),this.startWsServer=this.startWsServer.bind(this),this.startCronTask=this.startCronTask.bind(this),this.onResponseRawStats=this.onResponseRawStats.bind(this),this.onResponseInitialConfig=this.onResponseInitialConfig.bind(this),this.sendDataToTransport=this.sendDataToTransport.bind(this),console.warn("$ObserverRTC version[processor]","0.6.0","from build date","Thu, 14 Jan 2021 02:34:39 GMT")}get messageHandler(){return this._processorWorker.onMessage}onResponseRawStats(e){const t=this._integrationOptimizer.optimize(e).map((e=>({browserId:e.details.browserId,callId:e.details.callId,iceStats:u.getIceStats(e.stats),peerConnectionId:e.details.peerConnectionId,receiverStats:u.getSendRecvStats(e.stats.receiverStats),senderStats:u.getSendRecvStats(e.stats.senderStats),timeZoneOffsetInMinute:e.details.timeZoneOffsetInMinute,timestamp:e.details.timestamp,userId:e.details.userId}))),n=t.map((e=>this._statsOptimizer.excludeSameCandidates(e)));this._statsOptimizer.addStatBulk(t),this.sendDataToTransport(n)}onUserMediaError(e){const t={browserId:e.details.browserId,timeZoneOffsetInMinute:e.details.timeZoneOffsetInMinute,timestamp:e.details.timestamp,userMediaErrors:[{message:e.errName}]};this.sendDataToTransport([t])}updateWorkerInstance(e){this._processorWorker.setWorkerScope(e)}initialize(){this._processorWorker.requestInitialConfig()}onResponseInitialConfig(e){this._initialConfig=e,this.startCronTask(e.poolingIntervalInMs),"local"!==this._initialConfig.transportType&&this.startWsServer(e.wsAddress)}startWsServer(e){i.warn("start websocket server",e),this._webSocketTransport&&this._webSocketTransport.dispose(),this._webSocketTransport=new T(e)}startCronTask(e=1e3){this._cron.start({execute:this._processorWorker.requestRawStats.bind(this)},e)}sendDataToTransport(e){var t,n;"local"===(null===(t=this._initialConfig)||void 0===t?void 0:t.transportType)?e.length>0&&this._processorWorker.sendTransportData(e):null===(n=this._webSocketTransport)||void 0===n||n.sendBulk(e)}};C.updateWorkerInstance(self),C.initialize(),onmessage=C.messageHandler}));
  