(function(k,_){typeof exports=="object"&&typeof module<"u"?_(exports):typeof define=="function"&&define.amd?define(["exports"],_):(k=typeof globalThis<"u"?globalThis:k||self,_(k.VS={}))})(this,function(k){"use strict";var St=Object.defineProperty;var Tt=(k,_,b)=>_ in k?St(k,_,{enumerable:!0,configurable:!0,writable:!0,value:b}):k[_]=b;var M=(k,_,b)=>(Tt(k,typeof _!="symbol"?_+"":_,b),b);function _(e,t){for(var r=0;rn[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}const b=function(){this._handlers={}};b.prototype.register=function(e){this._handlers[e.getName()]=e},b.prototype.getHandler=function(e){return this._handlers[e]};let ue=function(e){this._request=30,this._response=31,this._error=32,this._handlerManager=e};ue.prototype.onMessage=function(e,t){if(console.log("Incoming DataMessage",JSON.stringify(t)),t.t===this._request){var r=t.data,n=this._handlerManager.getHandler(r.handler);n&&n[r.method].apply(n,r.args)}else if(t.t===this._response&&t.parentMessage){var i=t.parentMessage.responseCallback;i&&i.onSuccess&&i.onSuccess.apply(i,[t.data])}else if(t.t===this._error&&t.parentMessage){var i=t.parentMessage.responseCallback;i&&i.onError&&i.onError.apply(i,[t.data])}};let J=function(e){this._client=e};J.NAME="call",J.prototype.getName=function(){return J.NAME};const U={ResponseCallback:function(e,t){return{onSuccess:e,onError:t}},getResponseCallback:function(e){if(e&&e.length>0&&typeof e[e.length-1].onSuccess=="function")return e[e.length-1]}};let S=function(e){this._client=e};S.NAME="conversation",S.prototype.getName=function(){return S.NAME},S.prototype.getConversations=function(){this._client.call(S.NAME,"getConversations",[],U.getResponseCallback(arguments))},S.prototype.create=function(e){this._client.call(S.NAME,"create",[e],U.getResponseCallback(arguments))},S.prototype.addMessage=function(e,t){this._client.call(S.NAME,"addMessage",[e,t],U.getResponseCallback(arguments))};const z=function(e,t,r){this._relation=e,this._conversationProvider=t,this._callProvider=r,this._commanders={};var n=new J(this);this._commanders[n.getName()]=n;var i=new S(this);this._commanders[i.getName()]=i};z.prototype.getConversationProvider=function(){return this._conversationProvider},z.prototype.getCallProvider=function(){return this._callProvider},z.prototype.getCommander=function(e){return this._commanders[e]},z.prototype.call=function(e,t,r,n){var i=this;if(n)this._relation.call(e,t,r,n);else return new Promise(function(o,s){i._relation.call(e,t,r,{onSuccess:o,onError:s})})};function fe(e,t){this._uri=e,this._relationListeners=[],this._opened=!1,this._onMessageFn=t,this._wsConnection=null,this._maxTimeReconnect=4e3,this._maxTimeForConnect=2e3,this._incrementIntervalOnReconnect=200,this._currentReconnectInterval=0,this._waitReconnect=!1}fe.prototype={addRelationListener:function(e){this._relationListeners.push(e)},connect:function(){var e=this;e._manuallyClosed=!1,e._open()},write:function(e){var t=JSON.stringify(e,function(r,n){return typeof n=="number"&&!isFinite(n)?String(n):n});if(this._wsConnection&&this._wsConnection.readyState===1)this._wsConnection.send(t);else throw console.log("Can not send data, because no connection with uri ="+this._uri),new Error("Can not send data, because no connection with uri ="+this._uri)},close:function(){this._manuallyClosed=!0,this._wsConnection&&this._wsConnection.close()},_open:function(){var e=this;if(e._waitReconnect=!1,e._connecting||e._opened||e._manuallyClosed)return;e._connecting=!0,e._wsConnection=new WebSocket(this._uri);const t=this._wsConnection,r=setTimeout(function(){t.close()},e._maxTimeForConnect);this._wsConnection.onopen=function(n){clearTimeout(r),e._wsConnection===t&&(e._connecting=!1,e._opened=!0,e._currentReconnectInterval=0,e._relationListeners.forEach(function(i){i.onConnect&&i.onConnect(n)}))},this._wsConnection.onmessage=function(n){e._onMessageFn&&e._wsConnection===t&&e._onMessageFn(n.data)},this._wsConnection.onclose=function(n){clearTimeout(r),e._wsConnection===t&&(e._connecting=!1,e._opened=!1,e._relationListeners.forEach(function(i){i.onDisconnect&&i.onDisconnect(n)}),e._tryReconnect())}},_tryReconnect(){const e=this;!e._manuallyClosed&&!e._waitReconnect&&(e._waitReconnect=!0,setTimeout(()=>{e._open()},e._getReconnectInterval()))},_getReconnectInterval(){return this._currentReconnectInterval{console.log("Send local ConnectionInfo ",n),n&&this._vs.getClient().call("call",d.ServerMethod.setConnectionInfo,[e,n])}).catch(n=>{console.error("PIZDA",n)})},y.prototype.setTrackInfo=function(e,t){},y.prototype.updateTrackInfo=function(e,t,r){var n=this._vs.getClient().getCallProvider().get(e);this._vs.getBus().post(d.APIEvent.trackInfo,[n._callInfo,t,r])},y.prototype.addExtraConnectionInfo=function(e,t){var r=this._vs.getClient().getCallProvider().get(e);r.addExtraSessionDescription(t)},y.prototype.left=function(e,t){var r=this._vs.getClient().getCallProvider().get(e);r&&this._vs.getBus().post(d.APIEvent.left,[r._callInfo,t])},y.prototype.addedParticipant=function(e,t){var r=this._vs.getClient().getCallProvider().get(e);r.addParticipant(t),this._vs.getBus().post(d.APIEvent.addedParticipant,[r._callInfo,t])},y.prototype.removedParticipant=function(e,t){var r=this._vs.getClient().getCallProvider().get(e);r&&(r.removeParticipant(t),this._vs.getBus().post(d.APIEvent.removedParticipant,[r._callInfo,t]))},y.prototype.joined=function(e,t){var r=this._vs.getClient().getCallProvider().get(e);r.joinedParticipant(t),this._vs.getBus().post(d.APIEvent.joined,[r._callInfo,t]),r.startConnectivity().then(n=>{console.log("Send local ConnectionInfo after joined event ",n),n&&this._vs.getClient().call("call",d.ServerMethod.setConnectionInfo,[e,n])}).catch(n=>{console.error("PIZDA after joined event",n)})},y.prototype.finished=function(e){this._vs.getClient().getCallProvider().destroy(e)};let N=function(e){this._vs=e};N.NAME="conversation",N.prototype.created=function(e){var t=this._vs.getClient().getConversationProvider().create(e);t&&(t.getConversationEventListener().created(e),this._vs.getBus().post(d.IConversationEvent.created,[t]))},N.prototype.addedMessage=function(e,t){var r=this._vs.getClient().getConversationProvider().get(e);r&&(r.getConversationEventListener().addedMessage(t),this._vs.getBus().post(d.IConversationEvent.addedMessage,[e,t]))},N.prototype.getName=function(){return N.NAME};const te=function(){this._elements={}};te.prototype={add:function(e){this._elements[e.id]=e},remove:function(e){var t=this._elements[e];return t&&delete this._elements[e],t},get:function(e){return this._elements[e]},forEach:function(e){for(var t in this._elements)e(this._elements[t])}};const E=function(){this._listeners={}};E.prototype={register:function(e,t,r){this._listeners[e]={func:t,context:r}},post:function(e,t){var r=this._listeners[e];if(r)return r.func.apply(r.context?r.context:window,t)},clear:function(){this._listeners={}}};let he=!0,me=!0;function H(e,t,r){const n=e.match(t);return n&&n.length>=r&&parseInt(n[r],10)}function O(e,t,r){if(!e.RTCPeerConnection)return;const n=e.RTCPeerConnection.prototype,i=n.addEventListener;n.addEventListener=function(s,a){if(s!==t)return i.apply(this,arguments);const l=c=>{const p=r(c);p&&(a.handleEvent?a.handleEvent(p):a(p))};return this._eventMap=this._eventMap||{},this._eventMap[t]||(this._eventMap[t]=new Map),this._eventMap[t].set(a,l),i.apply(this,[s,l])};const o=n.removeEventListener;n.removeEventListener=function(s,a){if(s!==t||!this._eventMap||!this._eventMap[t])return o.apply(this,arguments);if(!this._eventMap[t].has(a))return o.apply(this,arguments);const l=this._eventMap[t].get(a);return this._eventMap[t].delete(a),this._eventMap[t].size===0&&delete this._eventMap[t],Object.keys(this._eventMap).length===0&&delete this._eventMap,o.apply(this,[s,l])},Object.defineProperty(n,"on"+t,{get(){return this["_on"+t]},set(s){this["_on"+t]&&(this.removeEventListener(t,this["_on"+t]),delete this["_on"+t]),s&&this.addEventListener(t,this["_on"+t]=s)},enumerable:!0,configurable:!0})}function rt(e){return typeof e!="boolean"?new Error("Argument type: "+typeof e+". Please use a boolean."):(he=e,e?"adapter.js logging disabled":"adapter.js logging enabled")}function it(e){return typeof e!="boolean"?new Error("Argument type: "+typeof e+". Please use a boolean."):(me=!e,"adapter.js deprecation warnings "+(e?"disabled":"enabled"))}function ge(){if(typeof window=="object"){if(he)return;typeof console<"u"&&typeof console.log=="function"&&console.log.apply(console,arguments)}}function ne(e,t){me&&console.warn(e+" is deprecated, please use "+t+" instead.")}function ot(e){const t={browser:null,version:null};if(typeof e>"u"||!e.navigator||!e.navigator.userAgent)return t.browser="Not a browser.",t;const{navigator:r}=e;if(r.mozGetUserMedia)t.browser="firefox",t.version=H(r.userAgent,/Firefox\/(\d+)\./,1);else if(r.webkitGetUserMedia||e.isSecureContext===!1&&e.webkitRTCPeerConnection)t.browser="chrome",t.version=H(r.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(e.RTCPeerConnection&&r.userAgent.match(/AppleWebKit\/(\d+)\./))t.browser="safari",t.version=H(r.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 ve(e){return Object.prototype.toString.call(e)==="[object Object]"}function Ce(e){return ve(e)?Object.keys(e).reduce(function(t,r){const n=ve(e[r]),i=n?Ce(e[r]):e[r],o=n&&!Object.keys(i).length;return i===void 0||o?t:Object.assign(t,{[r]:i})},{}):e}function re(e,t,r){!t||r.has(t.id)||(r.set(t.id,t),Object.keys(t).forEach(n=>{n.endsWith("Id")?re(e,e.get(t[n]),r):n.endsWith("Ids")&&t[n].forEach(i=>{re(e,e.get(i),r)})}))}function ye(e,t,r){const n=r?"outbound-rtp":"inbound-rtp",i=new Map;if(t===null)return i;const o=[];return e.forEach(s=>{s.type==="track"&&s.trackIdentifier===t.id&&o.push(s)}),o.forEach(s=>{e.forEach(a=>{a.type===n&&a.trackId===s.id&&re(e,a,i)})}),i}const _e=ge;function Se(e,t){const r=e&&e.navigator;if(!r.mediaDevices)return;const n=function(a){if(typeof a!="object"||a.mandatory||a.optional)return a;const l={};return Object.keys(a).forEach(c=>{if(c==="require"||c==="advanced"||c==="mediaSource")return;const p=typeof a[c]=="object"?a[c]:{ideal:a[c]};p.exact!==void 0&&typeof p.exact=="number"&&(p.min=p.max=p.exact);const u=function(f,h){return f?f+h.charAt(0).toUpperCase()+h.slice(1):h==="deviceId"?"sourceId":h};if(p.ideal!==void 0){l.optional=l.optional||[];let f={};typeof p.ideal=="number"?(f[u("min",c)]=p.ideal,l.optional.push(f),f={},f[u("max",c)]=p.ideal,l.optional.push(f)):(f[u("",c)]=p.ideal,l.optional.push(f))}p.exact!==void 0&&typeof p.exact!="number"?(l.mandatory=l.mandatory||{},l.mandatory[u("",c)]=p.exact):["min","max"].forEach(f=>{p[f]!==void 0&&(l.mandatory=l.mandatory||{},l.mandatory[u(f,c)]=p[f])})}),a.advanced&&(l.optional=(l.optional||[]).concat(a.advanced)),l},i=function(a,l){if(t.version>=61)return l(a);if(a=JSON.parse(JSON.stringify(a)),a&&typeof a.audio=="object"){const c=function(p,u,f){u in p&&!(f in p)&&(p[f]=p[u],delete p[u])};a=JSON.parse(JSON.stringify(a)),c(a.audio,"autoGainControl","googAutoGainControl"),c(a.audio,"noiseSuppression","googNoiseSuppression"),a.audio=n(a.audio)}if(a&&typeof a.video=="object"){let c=a.video.facingMode;c=c&&(typeof c=="object"?c:{ideal:c});const p=t.version<66;if(c&&(c.exact==="user"||c.exact==="environment"||c.ideal==="user"||c.ideal==="environment")&&!(r.mediaDevices.getSupportedConstraints&&r.mediaDevices.getSupportedConstraints().facingMode&&!p)){delete a.video.facingMode;let u;if(c.exact==="environment"||c.ideal==="environment"?u=["back","rear"]:(c.exact==="user"||c.ideal==="user")&&(u=["front"]),u)return r.mediaDevices.enumerateDevices().then(f=>{f=f.filter(m=>m.kind==="videoinput");let h=f.find(m=>u.some(C=>m.label.toLowerCase().includes(C)));return!h&&f.length&&u.includes("back")&&(h=f[f.length-1]),h&&(a.video.deviceId=c.exact?{exact:h.deviceId}:{ideal:h.deviceId}),a.video=n(a.video),_e("chrome: "+JSON.stringify(a)),l(a)})}a.video=n(a.video)}return _e("chrome: "+JSON.stringify(a)),l(a)},o=function(a){return t.version>=64?a:{name:{PermissionDeniedError:"NotAllowedError",PermissionDismissedError:"NotAllowedError",InvalidStateError:"NotAllowedError",DevicesNotFoundError:"NotFoundError",ConstraintNotSatisfiedError:"OverconstrainedError",TrackStartError:"NotReadableError",MediaDeviceFailedDueToShutdown:"NotAllowedError",MediaDeviceKillSwitchOn:"NotAllowedError",TabCaptureError:"AbortError",ScreenCaptureError:"AbortError",DeviceCaptureError:"AbortError"}[a.name]||a.name,message:a.message,constraint:a.constraint||a.constraintName,toString(){return this.name+(this.message&&": ")+this.message}}},s=function(a,l,c){i(a,p=>{r.webkitGetUserMedia(p,l,u=>{c&&c(o(u))})})};if(r.getUserMedia=s.bind(r),r.mediaDevices.getUserMedia){const a=r.mediaDevices.getUserMedia.bind(r.mediaDevices);r.mediaDevices.getUserMedia=function(l){return i(l,c=>a(c).then(p=>{if(c.audio&&!p.getAudioTracks().length||c.video&&!p.getVideoTracks().length)throw p.getTracks().forEach(u=>{u.stop()}),new DOMException("","NotFoundError");return p},p=>Promise.reject(o(p))))}}}function st(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(i=>{const o=n.video&&n.video.width,s=n.video&&n.video.height,a=n.video&&n.video.frameRate;return n.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:i,maxFrameRate:a||3}},o&&(n.video.mandatory.maxWidth=o),s&&(n.video.mandatory.maxHeight=s),e.navigator.mediaDevices.getUserMedia(n)})}}}function Te(e){e.MediaStream=e.MediaStream||e.webkitMediaStream}function Pe(e){if(typeof e=="object"&&e.RTCPeerConnection&&!("ontrack"in e.RTCPeerConnection.prototype)){Object.defineProperty(e.RTCPeerConnection.prototype,"ontrack",{get(){return this._ontrack},set(r){this._ontrack&&this.removeEventListener("track",this._ontrack),this.addEventListener("track",this._ontrack=r)},enumerable:!0,configurable:!0});const t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=n=>{n.stream.addEventListener("addtrack",i=>{let o;e.RTCPeerConnection.prototype.getReceivers?o=this.getReceivers().find(a=>a.track&&a.track.id===i.track.id):o={track:i.track};const s=new Event("track");s.track=i.track,s.receiver=o,s.transceiver={receiver:o},s.streams=[n.stream],this.dispatchEvent(s)}),n.stream.getTracks().forEach(i=>{let o;e.RTCPeerConnection.prototype.getReceivers?o=this.getReceivers().find(a=>a.track&&a.track.id===i.id):o={track:i};const s=new Event("track");s.track=i,s.receiver=o,s.transceiver={receiver:o},s.streams=[n.stream],this.dispatchEvent(s)})},this.addEventListener("addstream",this._ontrackpoly)),t.apply(this,arguments)}}else O(e,"track",t=>(t.transceiver||Object.defineProperty(t,"transceiver",{value:{receiver:t.receiver}}),t))}function Re(e){if(typeof e=="object"&&e.RTCPeerConnection&&!("getSenders"in e.RTCPeerConnection.prototype)&&"createDTMFSender"in e.RTCPeerConnection.prototype){const t=function(i,o){return{track:o,get dtmf(){return this._dtmf===void 0&&(o.kind==="audio"?this._dtmf=i.createDTMFSender(o):this._dtmf=null),this._dtmf},_pc:i}};if(!e.RTCPeerConnection.prototype.getSenders){e.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};const i=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(a,l){let c=i.apply(this,arguments);return c||(c=t(this,a),this._senders.push(c)),c};const o=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(a){o.apply(this,arguments);const l=this._senders.indexOf(a);l!==-1&&this._senders.splice(l,1)}}const r=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(o){this._senders=this._senders||[],r.apply(this,[o]),o.getTracks().forEach(s=>{this._senders.push(t(this,s))})};const n=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(o){this._senders=this._senders||[],n.apply(this,[o]),o.getTracks().forEach(s=>{const a=this._senders.find(l=>l.track===s);a&&this._senders.splice(this._senders.indexOf(a),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)){const t=e.RTCPeerConnection.prototype.getSenders;e.RTCPeerConnection.prototype.getSenders=function(){const n=t.apply(this,[]);return n.forEach(i=>i._pc=this),n},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 ke(e){if(!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){const[n,i,o]=arguments;if(arguments.length>0&&typeof n=="function")return t.apply(this,arguments);if(t.length===0&&(arguments.length===0||typeof n!="function"))return t.apply(this,[]);const s=function(l){const c={};return l.result().forEach(u=>{const f={id:u.id,timestamp:u.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[u.type]||u.type};u.names().forEach(h=>{f[h]=u.stat(h)}),c[f.id]=f}),c},a=function(l){return new Map(Object.keys(l).map(c=>[c,l[c]]))};if(arguments.length>=2){const l=function(c){i(a(s(c)))};return t.apply(this,[l,n])}return new Promise((l,c)=>{t.apply(this,[function(p){l(a(s(p)))},c])}).then(i,o)}}function Ee(e){if(!(typeof e=="object"&&e.RTCPeerConnection&&e.RTCRtpSender&&e.RTCRtpReceiver))return;if(!("getStats"in e.RTCRtpSender.prototype)){const r=e.RTCPeerConnection.prototype.getSenders;r&&(e.RTCPeerConnection.prototype.getSenders=function(){const o=r.apply(this,[]);return o.forEach(s=>s._pc=this),o});const n=e.RTCPeerConnection.prototype.addTrack;n&&(e.RTCPeerConnection.prototype.addTrack=function(){const o=n.apply(this,arguments);return o._pc=this,o}),e.RTCRtpSender.prototype.getStats=function(){const o=this;return this._pc.getStats().then(s=>ye(s,o.track,!0))}}if(!("getStats"in e.RTCRtpReceiver.prototype)){const r=e.RTCPeerConnection.prototype.getReceivers;r&&(e.RTCPeerConnection.prototype.getReceivers=function(){const i=r.apply(this,[]);return i.forEach(o=>o._pc=this),i}),O(e,"track",n=>(n.receiver._pc=n.srcElement,n)),e.RTCRtpReceiver.prototype.getStats=function(){const i=this;return this._pc.getStats().then(o=>ye(o,i.track,!1))}}if(!("getStats"in e.RTCRtpSender.prototype&&"getStats"in e.RTCRtpReceiver.prototype))return;const t=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof e.MediaStreamTrack){const n=arguments[0];let i,o,s;return this.getSenders().forEach(a=>{a.track===n&&(i?s=!0:i=a)}),this.getReceivers().forEach(a=>(a.track===n&&(o?s=!0:o=a),a.track===n)),s||i&&o?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):i?i.getStats():o?o.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return t.apply(this,arguments)}}function Me(e){e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(s=>this._shimmedLocalStreams[s][0])};const t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addTrack=function(s,a){if(!a)return t.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};const l=t.apply(this,arguments);return this._shimmedLocalStreams[a.id]?this._shimmedLocalStreams[a.id].indexOf(l)===-1&&this._shimmedLocalStreams[a.id].push(l):this._shimmedLocalStreams[a.id]=[a,l],l};const r=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(s){this._shimmedLocalStreams=this._shimmedLocalStreams||{},s.getTracks().forEach(c=>{if(this.getSenders().find(u=>u.track===c))throw new DOMException("Track already exists.","InvalidAccessError")});const a=this.getSenders();r.apply(this,arguments);const l=this.getSenders().filter(c=>a.indexOf(c)===-1);this._shimmedLocalStreams[s.id]=[s].concat(l)};const n=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(s){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[s.id],n.apply(this,arguments)};const i=e.RTCPeerConnection.prototype.removeTrack;e.RTCPeerConnection.prototype.removeTrack=function(s){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},s&&Object.keys(this._shimmedLocalStreams).forEach(a=>{const l=this._shimmedLocalStreams[a].indexOf(s);l!==-1&&this._shimmedLocalStreams[a].splice(l,1),this._shimmedLocalStreams[a].length===1&&delete this._shimmedLocalStreams[a]}),i.apply(this,arguments)}}function be(e,t){if(!e.RTCPeerConnection)return;if(e.RTCPeerConnection.prototype.addTrack&&t.version>=65)return Me(e);const r=e.RTCPeerConnection.prototype.getLocalStreams;e.RTCPeerConnection.prototype.getLocalStreams=function(){const p=r.apply(this);return this._reverseStreams=this._reverseStreams||{},p.map(u=>this._reverseStreams[u.id])};const n=e.RTCPeerConnection.prototype.addStream;e.RTCPeerConnection.prototype.addStream=function(p){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},p.getTracks().forEach(u=>{if(this.getSenders().find(h=>h.track===u))throw new DOMException("Track already exists.","InvalidAccessError")}),!this._reverseStreams[p.id]){const u=new e.MediaStream(p.getTracks());this._streams[p.id]=u,this._reverseStreams[u.id]=p,p=u}n.apply(this,[p])};const i=e.RTCPeerConnection.prototype.removeStream;e.RTCPeerConnection.prototype.removeStream=function(p){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},i.apply(this,[this._streams[p.id]||p]),delete this._reverseStreams[this._streams[p.id]?this._streams[p.id].id:p.id],delete this._streams[p.id]},e.RTCPeerConnection.prototype.addTrack=function(p,u){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");const f=[].slice.call(arguments,1);if(f.length!==1||!f[0].getTracks().find(C=>C===p))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(C=>C.track===p))throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};const m=this._streams[u.id];if(m)m.addTrack(p),Promise.resolve().then(()=>{this.dispatchEvent(new Event("negotiationneeded"))});else{const C=new e.MediaStream([p]);this._streams[u.id]=C,this._reverseStreams[C.id]=u,this.addStream(C)}return this.getSenders().find(C=>C.track===p)};function o(c,p){let u=p.sdp;return Object.keys(c._reverseStreams||[]).forEach(f=>{const h=c._reverseStreams[f],m=c._streams[h.id];u=u.replace(new RegExp(m.id,"g"),h.id)}),new RTCSessionDescription({type:p.type,sdp:u})}function s(c,p){let u=p.sdp;return Object.keys(c._reverseStreams||[]).forEach(f=>{const h=c._reverseStreams[f],m=c._streams[h.id];u=u.replace(new RegExp(h.id,"g"),m.id)}),new RTCSessionDescription({type:p.type,sdp:u})}["createOffer","createAnswer"].forEach(function(c){const p=e.RTCPeerConnection.prototype[c],u={[c](){const f=arguments;return arguments.length&&typeof arguments[0]=="function"?p.apply(this,[m=>{const C=o(this,m);f[0].apply(null,[C])},m=>{f[1]&&f[1].apply(null,m)},arguments[2]]):p.apply(this,arguments).then(m=>o(this,m))}};e.RTCPeerConnection.prototype[c]=u[c]});const a=e.RTCPeerConnection.prototype.setLocalDescription;e.RTCPeerConnection.prototype.setLocalDescription=function(){return!arguments.length||!arguments[0].type?a.apply(this,arguments):(arguments[0]=s(this,arguments[0]),a.apply(this,arguments))};const l=Object.getOwnPropertyDescriptor(e.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(e.RTCPeerConnection.prototype,"localDescription",{get(){const c=l.get.apply(this);return c.type===""?c:o(this,c)}}),e.RTCPeerConnection.prototype.removeTrack=function(p){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");if(!p._pc)throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.","TypeError");if(!(p._pc===this))throw new DOMException("Sender was not created by this connection.","InvalidAccessError");this._streams=this._streams||{};let f;Object.keys(this._streams).forEach(h=>{this._streams[h].getTracks().find(C=>p.track===C)&&(f=this._streams[h])}),f&&(f.getTracks().length===1?this.removeStream(this._reverseStreams[f.id]):f.removeTrack(p.track),this.dispatchEvent(new Event("negotiationneeded")))}}function ie(e,t){!e.RTCPeerConnection&&e.webkitRTCPeerConnection&&(e.RTCPeerConnection=e.webkitRTCPeerConnection),e.RTCPeerConnection&&t.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(r){const n=e.RTCPeerConnection.prototype[r],i={[r](){return arguments[0]=new(r==="addIceCandidate"?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),n.apply(this,arguments)}};e.RTCPeerConnection.prototype[r]=i[r]})}function Ie(e,t){O(e,"negotiationneeded",r=>{const n=r.target;if(!((t.version<72||n.getConfiguration&&n.getConfiguration().sdpSemantics==="plan-b")&&n.signalingState!=="stable"))return r})}const xe=Object.freeze(Object.defineProperty({__proto__:null,fixNegotiationNeeded:Ie,shimAddTrackRemoveTrack:be,shimAddTrackRemoveTrackWithNative:Me,shimGetDisplayMedia:st,shimGetSendersWithDtmf:Re,shimGetStats:ke,shimGetUserMedia:Se,shimMediaStream:Te,shimOnTrack:Pe,shimPeerConnection:ie,shimSenderReceiverGetStats:Ee},Symbol.toStringTag,{value:"Module"}));function De(e,t){const r=e&&e.navigator,n=e&&e.MediaStreamTrack;if(r.getUserMedia=function(i,o,s){ne("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),r.mediaDevices.getUserMedia(i).then(o,s)},!(t.version>55&&"autoGainControl"in r.mediaDevices.getSupportedConstraints())){const i=function(s,a,l){a in s&&!(l in s)&&(s[l]=s[a],delete s[a])},o=r.mediaDevices.getUserMedia.bind(r.mediaDevices);if(r.mediaDevices.getUserMedia=function(s){return typeof s=="object"&&typeof s.audio=="object"&&(s=JSON.parse(JSON.stringify(s)),i(s.audio,"autoGainControl","mozAutoGainControl"),i(s.audio,"noiseSuppression","mozNoiseSuppression")),o(s)},n&&n.prototype.getSettings){const s=n.prototype.getSettings;n.prototype.getSettings=function(){const a=s.apply(this,arguments);return i(a,"mozAutoGainControl","autoGainControl"),i(a,"mozNoiseSuppression","noiseSuppression"),a}}if(n&&n.prototype.applyConstraints){const s=n.prototype.applyConstraints;n.prototype.applyConstraints=function(a){return this.kind==="audio"&&typeof a=="object"&&(a=JSON.parse(JSON.stringify(a)),i(a,"autoGainControl","mozAutoGainControl"),i(a,"noiseSuppression","mozNoiseSuppression")),s.apply(this,[a])}}}}function at(e,t){e.navigator.mediaDevices&&"getDisplayMedia"in e.navigator.mediaDevices||e.navigator.mediaDevices&&(e.navigator.mediaDevices.getDisplayMedia=function(n){if(!(n&&n.video)){const i=new DOMException("getDisplayMedia without video constraints is undefined");return i.name="NotFoundError",i.code=8,Promise.reject(i)}return n.video===!0?n.video={mediaSource:t}:n.video.mediaSource=t,e.navigator.mediaDevices.getUserMedia(n)})}function Oe(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 oe(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(i){const o=e.RTCPeerConnection.prototype[i],s={[i](){return arguments[0]=new(i==="addIceCandidate"?e.RTCIceCandidate:e.RTCSessionDescription)(arguments[0]),o.apply(this,arguments)}};e.RTCPeerConnection.prototype[i]=s[i]});const r={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},n=e.RTCPeerConnection.prototype.getStats;e.RTCPeerConnection.prototype.getStats=function(){const[o,s,a]=arguments;return n.apply(this,[o||null]).then(l=>{if(t.version<53&&!s)try{l.forEach(c=>{c.type=r[c.type]||c.type})}catch(c){if(c.name!=="TypeError")throw c;l.forEach((p,u)=>{l.set(u,Object.assign({},p,{type:r[p.type]||p.type}))})}return l}).then(s,a)}}function Le(e){if(!(typeof e=="object"&&e.RTCPeerConnection&&e.RTCRtpSender)||e.RTCRtpSender&&"getStats"in e.RTCRtpSender.prototype)return;const t=e.RTCPeerConnection.prototype.getSenders;t&&(e.RTCPeerConnection.prototype.getSenders=function(){const i=t.apply(this,[]);return i.forEach(o=>o._pc=this),i});const r=e.RTCPeerConnection.prototype.addTrack;r&&(e.RTCPeerConnection.prototype.addTrack=function(){const i=r.apply(this,arguments);return i._pc=this,i}),e.RTCRtpSender.prototype.getStats=function(){return this.track?this._pc.getStats(this.track):Promise.resolve(new Map)}}function Ae(e){if(!(typeof e=="object"&&e.RTCPeerConnection&&e.RTCRtpSender)||e.RTCRtpSender&&"getStats"in e.RTCRtpReceiver.prototype)return;const t=e.RTCPeerConnection.prototype.getReceivers;t&&(e.RTCPeerConnection.prototype.getReceivers=function(){const n=t.apply(this,[]);return n.forEach(i=>i._pc=this),n}),O(e,"track",r=>(r.receiver._pc=r.srcElement,r)),e.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function je(e){!e.RTCPeerConnection||"removeStream"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.removeStream=function(r){ne("removeStream","removeTrack"),this.getSenders().forEach(n=>{n.track&&r.getTracks().includes(n.track)&&this.removeTrack(n)})})}function Ue(e){e.DataChannel&&!e.RTCDataChannel&&(e.RTCDataChannel=e.DataChannel)}function Ne(e){if(!(typeof e=="object"&&e.RTCPeerConnection))return;const t=e.RTCPeerConnection.prototype.addTransceiver;t&&(e.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];let n=arguments[1]&&arguments[1].sendEncodings;n===void 0&&(n=[]),n=[...n];const i=n.length>0;i&&n.forEach(s=>{if("rid"in s&&!/^[a-z0-9]{0,16}$/i.test(s.rid))throw new TypeError("Invalid RID value provided.");if("scaleResolutionDownBy"in s&&!(parseFloat(s.scaleResolutionDownBy)>=1))throw new RangeError("scale_resolution_down_by must be >= 1.0");if("maxFramerate"in s&&!(parseFloat(s.maxFramerate)>=0))throw new RangeError("max_framerate must be >= 0.0")});const o=t.apply(this,arguments);if(i){const{sender:s}=o,a=s.getParameters();(!("encodings"in a)||a.encodings.length===1&&Object.keys(a.encodings[0]).length===0)&&(a.encodings=n,s.sendEncodings=n,this.setParametersPromises.push(s.setParameters(a).then(()=>{delete s.sendEncodings}).catch(()=>{delete s.sendEncodings})))}return o})}function Fe(e){if(!(typeof e=="object"&&e.RTCRtpSender))return;const t=e.RTCRtpSender.prototype.getParameters;t&&(e.RTCRtpSender.prototype.getParameters=function(){const n=t.apply(this,arguments);return"encodings"in n||(n.encodings=[].concat(this.sendEncodings||[{}])),n})}function Ge(e){if(!(typeof e=="object"&&e.RTCPeerConnection))return;const 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 ze(e){if(!(typeof e=="object"&&e.RTCPeerConnection))return;const 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)}}const Ve=Object.freeze(Object.defineProperty({__proto__:null,shimAddTransceiver:Ne,shimCreateAnswer:ze,shimCreateOffer:Ge,shimGetDisplayMedia:at,shimGetParameters:Fe,shimGetUserMedia:De,shimOnTrack:Oe,shimPeerConnection:oe,shimRTCDataChannel:Ue,shimReceiverGetStats:Ae,shimRemoveStream:je,shimSenderGetStats:Le},Symbol.toStringTag,{value:"Module"}));function We(e){if(!(typeof e!="object"||!e.RTCPeerConnection)){if("getLocalStreams"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),!("addStream"in e.RTCPeerConnection.prototype)){const t=e.RTCPeerConnection.prototype.addTrack;e.RTCPeerConnection.prototype.addStream=function(n){this._localStreams||(this._localStreams=[]),this._localStreams.includes(n)||this._localStreams.push(n),n.getAudioTracks().forEach(i=>t.call(this,i,n)),n.getVideoTracks().forEach(i=>t.call(this,i,n))},e.RTCPeerConnection.prototype.addTrack=function(n,...i){return i&&i.forEach(o=>{this._localStreams?this._localStreams.includes(o)||this._localStreams.push(o):this._localStreams=[o]}),t.apply(this,arguments)}}"removeStream"in e.RTCPeerConnection.prototype||(e.RTCPeerConnection.prototype.removeStream=function(r){this._localStreams||(this._localStreams=[]);const n=this._localStreams.indexOf(r);if(n===-1)return;this._localStreams.splice(n,1);const i=r.getTracks();this.getSenders().forEach(o=>{i.includes(o.track)&&this.removeTrack(o)})})}}function Je(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(r){this._onaddstream&&(this.removeEventListener("addstream",this._onaddstream),this.removeEventListener("track",this._onaddstreampoly)),this.addEventListener("addstream",this._onaddstream=r),this.addEventListener("track",this._onaddstreampoly=n=>{n.streams.forEach(i=>{if(this._remoteStreams||(this._remoteStreams=[]),this._remoteStreams.includes(i))return;this._remoteStreams.push(i);const o=new Event("addstream");o.stream=i,this.dispatchEvent(o)})})}});const t=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){const n=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(i){i.streams.forEach(o=>{if(n._remoteStreams||(n._remoteStreams=[]),n._remoteStreams.indexOf(o)>=0)return;n._remoteStreams.push(o);const s=new Event("addstream");s.stream=o,n.dispatchEvent(s)})}),t.apply(n,arguments)}}}function Be(e){if(typeof e!="object"||!e.RTCPeerConnection)return;const t=e.RTCPeerConnection.prototype,r=t.createOffer,n=t.createAnswer,i=t.setLocalDescription,o=t.setRemoteDescription,s=t.addIceCandidate;t.createOffer=function(c,p){const u=arguments.length>=2?arguments[2]:arguments[0],f=r.apply(this,[u]);return p?(f.then(c,p),Promise.resolve()):f},t.createAnswer=function(c,p){const u=arguments.length>=2?arguments[2]:arguments[0],f=n.apply(this,[u]);return p?(f.then(c,p),Promise.resolve()):f};let a=function(l,c,p){const u=i.apply(this,[l]);return p?(u.then(c,p),Promise.resolve()):u};t.setLocalDescription=a,a=function(l,c,p){const u=o.apply(this,[l]);return p?(u.then(c,p),Promise.resolve()):u},t.setRemoteDescription=a,a=function(l,c,p){const u=s.apply(this,[l]);return p?(u.then(c,p),Promise.resolve()):u},t.addIceCandidate=a}function He(e){const t=e&&e.navigator;if(t.mediaDevices&&t.mediaDevices.getUserMedia){const r=t.mediaDevices,n=r.getUserMedia.bind(r);t.mediaDevices.getUserMedia=i=>n($e(i))}!t.getUserMedia&&t.mediaDevices&&t.mediaDevices.getUserMedia&&(t.getUserMedia=(function(n,i,o){t.mediaDevices.getUserMedia(n).then(i,o)}).bind(t))}function $e(e){return e&&e.video!==void 0?Object.assign({},e,{video:Ce(e.video)}):e}function Ke(e){if(!e.RTCPeerConnection)return;const t=e.RTCPeerConnection;e.RTCPeerConnection=function(n,i){if(n&&n.iceServers){const o=[];for(let s=0;ss.receiver.track.kind==="audio");n.offerToReceiveAudio===!1&&i?i.direction==="sendrecv"?i.setDirection?i.setDirection("sendonly"):i.direction="sendonly":i.direction==="recvonly"&&(i.setDirection?i.setDirection("inactive"):i.direction="inactive"):n.offerToReceiveAudio===!0&&!i&&this.addTransceiver("audio",{direction:"recvonly"}),typeof n.offerToReceiveVideo<"u"&&(n.offerToReceiveVideo=!!n.offerToReceiveVideo);const o=this.getTransceivers().find(s=>s.receiver.track.kind==="video");n.offerToReceiveVideo===!1&&o?o.direction==="sendrecv"?o.setDirection?o.setDirection("sendonly"):o.direction="sendonly":o.direction==="recvonly"&&(o.setDirection?o.setDirection("inactive"):o.direction="inactive"):n.offerToReceiveVideo===!0&&!o&&this.addTransceiver("video",{direction:"recvonly"})}return t.apply(this,arguments)}}function Xe(e){typeof e!="object"||e.AudioContext||(e.AudioContext=e.webkitAudioContext)}const Ye=Object.freeze(Object.defineProperty({__proto__:null,shimAudioContext:Xe,shimCallbacksAPI:Be,shimConstraints:$e,shimCreateOfferLegacy:Ze,shimGetUserMedia:He,shimLocalStreamsAPI:We,shimRTCIceServerUrls:Ke,shimRemoteStreamsAPI:Je,shimTrackEventTransceiver:qe},Symbol.toStringTag,{value:"Module"}));function ct(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Qe={exports:{}};(function(e){const t={};t.generateIdentifier=function(){return Math.random().toString(36).substring(2,12)},t.localCName=t.generateIdentifier(),t.splitLines=function(r){return r.trim().split(` `).map(n=>n.trim())},t.splitSections=function(r){return r.split(` m=`).map((i,o)=>(o>0?"m="+i:i).trim()+`\r `)},t.getDescription=function(r){const n=t.splitSections(r);return n&&n[0]},t.getMediaSections=function(r){const n=t.splitSections(r);return n.shift(),n},t.matchPrefix=function(r,n){return t.splitLines(r).filter(i=>i.indexOf(n)===0)},t.parseCandidate=function(r){let n;r.indexOf("a=candidate:")===0?n=r.substring(12).split(" "):n=r.substring(10).split(" ");const i={foundation:n[0],component:{1:"rtp",2:"rtcp"}[n[1]]||n[1],protocol:n[2].toLowerCase(),priority:parseInt(n[3],10),ip:n[4],address:n[4],port:parseInt(n[5],10),type:n[7]};for(let o=8;o0?n[0].split("/")[1]:"sendrecv",uri:n[1],attributes:n.slice(2).join(" ")}},t.writeExtmap=function(r){return"a=extmap:"+(r.id||r.preferredId)+(r.direction&&r.direction!=="sendrecv"?"/"+r.direction:"")+" "+r.uri+(r.attributes?" "+r.attributes:"")+`\r `},t.parseFmtp=function(r){const n={};let i;const o=r.substring(r.indexOf(" ")+1).split(";");for(let s=0;s{r.parameters[s]!==void 0?o.push(s+"="+r.parameters[s]):o.push(s)}),n+="a=fmtp:"+i+" "+o.join(";")+`\r `}return n},t.parseRtcpFb=function(r){const n=r.substring(r.indexOf(" ")+1).split(" ");return{type:n.shift(),parameter:n.join(" ")}},t.writeRtcpFb=function(r){let n="",i=r.payloadType;return r.preferredPayloadType!==void 0&&(i=r.preferredPayloadType),r.rtcpFeedback&&r.rtcpFeedback.length&&r.rtcpFeedback.forEach(o=>{n+="a=rtcp-fb:"+i+" "+o.type+(o.parameter&&o.parameter.length?" "+o.parameter:"")+`\r `}),n},t.parseSsrcMedia=function(r){const n=r.indexOf(" "),i={ssrc:parseInt(r.substring(7,n),10)},o=r.indexOf(":",n);return o>-1?(i.attribute=r.substring(n+1,o),i.value=r.substring(o+1)):i.attribute=r.substring(n+1),i},t.parseSsrcGroup=function(r){const n=r.substring(13).split(" ");return{semantics:n.shift(),ssrcs:n.map(i=>parseInt(i,10))}},t.getMid=function(r){const n=t.matchPrefix(r,"a=mid:")[0];if(n)return n.substring(6)},t.parseFingerprint=function(r){const n=r.substring(14).split(" ");return{algorithm:n[0].toLowerCase(),value:n[1].toUpperCase()}},t.getDtlsParameters=function(r,n){return{role:"auto",fingerprints:t.matchPrefix(r+n,"a=fingerprint:").map(t.parseFingerprint)}},t.writeDtlsParameters=function(r,n){let i="a=setup:"+n+`\r `;return r.fingerprints.forEach(o=>{i+="a=fingerprint:"+o.algorithm+" "+o.value+`\r `}),i},t.parseCryptoLine=function(r){const n=r.substring(9).split(" ");return{tag:parseInt(n[0],10),cryptoSuite:n[1],keyParams:n[2],sessionParams:n.slice(3)}},t.writeCryptoLine=function(r){return"a=crypto:"+r.tag+" "+r.cryptoSuite+" "+(typeof r.keyParams=="object"?t.writeCryptoKeyParams(r.keyParams):r.keyParams)+(r.sessionParams?" "+r.sessionParams.join(" "):"")+`\r `},t.parseCryptoKeyParams=function(r){if(r.indexOf("inline:")!==0)return null;const n=r.substring(7).split("|");return{keyMethod:"inline",keySalt:n[0],lifeTime:n[1],mkiValue:n[2]?n[2].split(":")[0]:void 0,mkiLength:n[2]?n[2].split(":")[1]:void 0}},t.writeCryptoKeyParams=function(r){return r.keyMethod+":"+r.keySalt+(r.lifeTime?"|"+r.lifeTime:"")+(r.mkiValue&&r.mkiLength?"|"+r.mkiValue+":"+r.mkiLength:"")},t.getCryptoParameters=function(r,n){return t.matchPrefix(r+n,"a=crypto:").map(t.parseCryptoLine)},t.getIceParameters=function(r,n){const i=t.matchPrefix(r+n,"a=ice-ufrag:")[0],o=t.matchPrefix(r+n,"a=ice-pwd:")[0];return i&&o?{usernameFragment:i.substring(12),password:o.substring(10)}:null},t.writeIceParameters=function(r){let n="a=ice-ufrag:"+r.usernameFragment+`\r a=ice-pwd:`+r.password+`\r `;return r.iceLite&&(n+=`a=ice-lite\r `),n},t.parseRtpParameters=function(r){const n={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},o=t.splitLines(r)[0].split(" ");n.profile=o[2];for(let a=3;a{n.headerExtensions.push(t.parseExtmap(a))});const s=t.matchPrefix(r,"a=rtcp-fb:* ").map(t.parseRtcpFb);return n.codecs.forEach(a=>{s.forEach(l=>{a.rtcpFeedback.find(p=>p.type===l.type&&p.parameter===l.parameter)||a.rtcpFeedback.push(l)})}),n},t.writeRtpDescription=function(r,n){let i="";i+="m="+r+" ",i+=n.codecs.length>0?"9":"0",i+=" "+(n.profile||"UDP/TLS/RTP/SAVPF")+" ",i+=n.codecs.map(s=>s.preferredPayloadType!==void 0?s.preferredPayloadType:s.payloadType).join(" ")+`\r `,i+=`c=IN IP4 0.0.0.0\r `,i+=`a=rtcp:9 IN IP4 0.0.0.0\r `,n.codecs.forEach(s=>{i+=t.writeRtpMap(s),i+=t.writeFmtp(s),i+=t.writeRtcpFb(s)});let o=0;return n.codecs.forEach(s=>{s.maxptime>o&&(o=s.maxptime)}),o>0&&(i+="a=maxptime:"+o+`\r `),n.headerExtensions&&n.headerExtensions.forEach(s=>{i+=t.writeExtmap(s)}),i},t.parseRtpEncodingParameters=function(r){const n=[],i=t.parseRtpParameters(r),o=i.fecMechanisms.indexOf("RED")!==-1,s=i.fecMechanisms.indexOf("ULPFEC")!==-1,a=t.matchPrefix(r,"a=ssrc:").map(f=>t.parseSsrcMedia(f)).filter(f=>f.attribute==="cname"),l=a.length>0&&a[0].ssrc;let c;const p=t.matchPrefix(r,"a=ssrc-group:FID").map(f=>f.substring(17).split(" ").map(m=>parseInt(m,10)));p.length>0&&p[0].length>1&&p[0][0]===l&&(c=p[0][1]),i.codecs.forEach(f=>{if(f.name.toUpperCase()==="RTX"&&f.parameters.apt){let h={ssrc:l,codecPayloadType:parseInt(f.parameters.apt,10)};l&&c&&(h.rtx={ssrc:c}),n.push(h),o&&(h=JSON.parse(JSON.stringify(h)),h.fec={ssrc:l,mechanism:s?"red+ulpfec":"red"},n.push(h))}}),n.length===0&&l&&n.push({ssrc:l});let u=t.matchPrefix(r,"b=");return u.length&&(u[0].indexOf("b=TIAS:")===0?u=parseInt(u[0].substring(7),10):u[0].indexOf("b=AS:")===0?u=parseInt(u[0].substring(5),10)*1e3*.95-50*40*8:u=void 0,n.forEach(f=>{f.maxBitrate=u})),n},t.parseRtcpParameters=function(r){const n={},i=t.matchPrefix(r,"a=ssrc:").map(a=>t.parseSsrcMedia(a)).filter(a=>a.attribute==="cname")[0];i&&(n.cname=i.value,n.ssrc=i.ssrc);const o=t.matchPrefix(r,"a=rtcp-rsize");n.reducedSize=o.length>0,n.compound=o.length===0;const s=t.matchPrefix(r,"a=rtcp-mux");return n.mux=s.length>0,n},t.writeRtcpParameters=function(r){let n="";return r.reducedSize&&(n+=`a=rtcp-rsize\r `),r.mux&&(n+=`a=rtcp-mux\r `),r.ssrc!==void 0&&r.cname&&(n+="a=ssrc:"+r.ssrc+" cname:"+r.cname+`\r `),n},t.parseMsid=function(r){let n;const i=t.matchPrefix(r,"a=msid:");if(i.length===1)return n=i[0].substring(7).split(" "),{stream:n[0],track:n[1]};const o=t.matchPrefix(r,"a=ssrc:").map(s=>t.parseSsrcMedia(s)).filter(s=>s.attribute==="msid");if(o.length>0)return n=o[0].value.split(" "),{stream:n[0],track:n[1]}},t.parseSctpDescription=function(r){const n=t.parseMLine(r),i=t.matchPrefix(r,"a=max-message-size:");let o;i.length>0&&(o=parseInt(i[0].substring(19),10)),isNaN(o)&&(o=65536);const s=t.matchPrefix(r,"a=sctp-port:");if(s.length>0)return{port:parseInt(s[0].substring(12),10),protocol:n.fmt,maxMessageSize:o};const a=t.matchPrefix(r,"a=sctpmap:");if(a.length>0){const l=a[0].substring(10).split(" ");return{port:parseInt(l[0],10),protocol:l[1],maxMessageSize:o}}},t.writeSctpDescription=function(r,n){let i=[];return r.protocol!=="DTLS/SCTP"?i=["m="+r.kind+" 9 "+r.protocol+" "+n.protocol+`\r `,`c=IN IP4 0.0.0.0\r `,"a=sctp-port:"+n.port+`\r `]:i=["m="+r.kind+" 9 "+r.protocol+" "+n.port+`\r `,`c=IN IP4 0.0.0.0\r `,"a=sctpmap:"+n.port+" "+n.protocol+` 65535\r `],n.maxMessageSize!==void 0&&i.push("a=max-message-size:"+n.maxMessageSize+`\r `),i.join("")},t.generateSessionId=function(){return Math.random().toString().substr(2,22)},t.writeSessionBoilerplate=function(r,n,i){let o;const s=n!==void 0?n:2;return r?o=r:o=t.generateSessionId(),`v=0\r o=`+(i||"thisisadapterortc")+" "+o+" "+s+` IN IP4 127.0.0.1\r s=-\r t=0 0\r `},t.getDirection=function(r,n){const i=t.splitLines(r);for(let o=0;o(r.candidate&&Object.defineProperty(r,"candidate",{value:new e.RTCIceCandidate(r.candidate),writable:"false"}),r))}function se(e){!e.RTCIceCandidate||e.RTCIceCandidate&&"relayProtocol"in e.RTCIceCandidate.prototype||O(e,"icecandidate",t=>{if(t.candidate){const r=F.parseCandidate(t.candidate.candidate);r.type==="relay"&&(t.candidate.relayProtocol={0:"tls",1:"tcp",2:"udp"}[r.priority>>24])}return t})}function K(e,t){if(!e.RTCPeerConnection)return;"sctp"in e.RTCPeerConnection.prototype||Object.defineProperty(e.RTCPeerConnection.prototype,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp}});const r=function(a){if(!a||!a.sdp)return!1;const l=F.splitSections(a.sdp);return l.shift(),l.some(c=>{const p=F.parseMLine(c);return p&&p.kind==="application"&&p.protocol.indexOf("SCTP")!==-1})},n=function(a){const l=a.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(l===null||l.length<2)return-1;const c=parseInt(l[1],10);return c!==c?-1:c},i=function(a){let l=65536;return t.browser==="firefox"&&(t.version<57?a===-1?l=16384:l=2147483637:t.version<60?l=t.version===57?65535:65536:l=2147483637),l},o=function(a,l){let c=65536;t.browser==="firefox"&&t.version===57&&(c=65535);const p=F.matchPrefix(a.sdp,"a=max-message-size:");return p.length>0?c=parseInt(p[0].substring(19),10):t.browser==="firefox"&&l!==-1&&(c=2147483637),c},s=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,t.browser==="chrome"&&t.version>=76){const{sdpSemantics:l}=this.getConfiguration();l==="plan-b"&&Object.defineProperty(this,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp},enumerable:!0,configurable:!0})}if(r(arguments[0])){const l=n(arguments[0]),c=i(l),p=o(arguments[0],l);let u;c===0&&p===0?u=Number.POSITIVE_INFINITY:c===0||p===0?u=Math.max(c,p):u=Math.min(c,p);const f={};Object.defineProperty(f,"maxMessageSize",{get(){return u}}),this._sctp=f}return s.apply(this,arguments)}}function q(e){if(!(e.RTCPeerConnection&&"createDataChannel"in e.RTCPeerConnection.prototype))return;function t(n,i){const o=n.send;n.send=function(){const a=arguments[0],l=a.length||a.size||a.byteLength;if(n.readyState==="open"&&i.sctp&&l>i.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+i.sctp.maxMessageSize+" bytes)");return o.apply(n,arguments)}}const r=e.RTCPeerConnection.prototype.createDataChannel;e.RTCPeerConnection.prototype.createDataChannel=function(){const i=r.apply(this,arguments);return t(i,this),i},O(e,"datachannel",n=>(t(n.channel,n.target),n))}function ae(e){if(!e.RTCPeerConnection||"connectionState"in e.RTCPeerConnection.prototype)return;const 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(r){this._onconnectionstatechange&&(this.removeEventListener("connectionstatechange",this._onconnectionstatechange),delete this._onconnectionstatechange),r&&this.addEventListener("connectionstatechange",this._onconnectionstatechange=r)},enumerable:!0,configurable:!0}),["setLocalDescription","setRemoteDescription"].forEach(r=>{const n=t[r];t[r]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=i=>{const o=i.target;if(o._lastConnectionState!==o.connectionState){o._lastConnectionState=o.connectionState;const s=new Event("connectionstatechange",i);o.dispatchEvent(s)}return i},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),n.apply(this,arguments)}})}function ce(e,t){if(!e.RTCPeerConnection||t.browser==="chrome"&&t.version>=71||t.browser==="safari"&&t.version>=605)return;const r=e.RTCPeerConnection.prototype.setRemoteDescription;e.RTCPeerConnection.prototype.setRemoteDescription=function(i){if(i&&i.sdp&&i.sdp.indexOf(` a=extmap-allow-mixed`)!==-1){const o=i.sdp.split(` `).filter(s=>s.trim()!=="a=extmap-allow-mixed").join(` `);e.RTCSessionDescription&&i instanceof e.RTCSessionDescription?arguments[0]=new e.RTCSessionDescription({type:i.type,sdp:o}):i.sdp=o}return r.apply(this,arguments)}}function Z(e,t){if(!(e.RTCPeerConnection&&e.RTCPeerConnection.prototype))return;const r=e.RTCPeerConnection.prototype.addIceCandidate;!r||r.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():r.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}function X(e,t){if(!(e.RTCPeerConnection&&e.RTCPeerConnection.prototype))return;const r=e.RTCPeerConnection.prototype.setLocalDescription;!r||r.length===0||(e.RTCPeerConnection.prototype.setLocalDescription=function(){let i=arguments[0]||{};if(typeof i!="object"||i.type&&i.sdp)return r.apply(this,arguments);if(i={type:i.type,sdp:i.sdp},!i.type)switch(this.signalingState){case"stable":case"have-local-offer":case"have-remote-pranswer":i.type="offer";break;default:i.type="answer";break}return i.sdp||i.type!=="offer"&&i.type!=="answer"?r.apply(this,[i]):(i.type==="offer"?this.createOffer:this.createAnswer).apply(this).then(s=>r.apply(this,[s]))})}const lt=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:ce,shimAddIceCandidateNullOrEmpty:Z,shimConnectionState:ae,shimMaxMessageSize:K,shimParameterlessSetLocalDescription:X,shimRTCIceCandidate:$,shimRTCIceCandidateRelayProtocol:se,shimSendThrowTypeError:q},Symbol.toStringTag,{value:"Module"}));function ut({window:e}={},t={shimChrome:!0,shimFirefox:!0,shimSafari:!0}){const r=ge,n=ot(e),i={browserDetails:n,commonShim:lt,extractVersion:H,disableLog:rt,disableWarnings:it,sdp:pt};switch(n.browser){case"chrome":if(!xe||!ie||!t.shimChrome)return r("Chrome shim is not included in this adapter release."),i;if(n.version===null)return r("Chrome shim can not determine version, not shimming."),i;r("adapter.js shimming chrome."),i.browserShim=xe,Z(e,n),X(e),Se(e,n),Te(e),ie(e,n),Pe(e),be(e,n),Re(e),ke(e),Ee(e),Ie(e,n),$(e),se(e),ae(e),K(e,n),q(e),ce(e,n);break;case"firefox":if(!Ve||!oe||!t.shimFirefox)return r("Firefox shim is not included in this adapter release."),i;r("adapter.js shimming firefox."),i.browserShim=Ve,Z(e,n),X(e),De(e,n),oe(e,n),Oe(e),je(e),Le(e),Ae(e),Ue(e),Ne(e),Fe(e),Ge(e),ze(e),$(e),ae(e),K(e,n),q(e);break;case"safari":if(!Ye||!t.shimSafari)return r("Safari shim is not included in this adapter release."),i;r("adapter.js shimming safari."),i.browserShim=Ye,Z(e,n),X(e),Ke(e),Ze(e),Be(e),We(e),Je(e),qe(e),He(e),Xe(e),$(e),se(e),K(e,n),q(e),ce(e,n);break;default:r("Unsupported browser!");break}return i}const ft=ut({window:typeof window>"u"?void 0:window});console.log("Browser Details"+JSON.stringify(ft.browserDetails));const dt=navigator.mediaDevices,ht=window.RTCPeerConnection,mt=window.RTCSessionDescription,gt=window.RTCIceCandidate,vt=window.MediaStream,P=function(e,t,r){E.apply(this,arguments);var n=this;n._options=e,n._connectionState=d.ConnectionState.new,n._waitAnswer=!1,n._remoteNewSDPInfo=!1,n.pcConfig={iceServers:Ct([...e.STUN_SERVERS,...e.TURN_SERVERS])},n._iceCandidates=[],n._destroyed=!1,console.log("PC CONFIG",n.pcConfig),n._pc=new ht(n.pcConfig),n._pc.addEventListener("icecandidate",i=>{n._destroyed||i.candidate&&n.post(d.WorkerEvent.iceCandidate,[i.candidate])}),n._pc.addEventListener("track",i=>{n._destroyed||n.post(d.WorkerEvent.onTrack,[i])}),n._pc.addEventListener("iceconnectionstatechange",i=>{if(!n._destroyed){switch(n._pc.iceConnectionState){case"checking":n._connectionState=d.ConnectionState.connecting;break;case"connected":n._connectionState=d.ConnectionState.connected;break;case"completed":n._connectionState=d.ConnectionState.completed;break;case"failed":n._connectionState=d.ConnectionState.failed;break;case"disconnected":n._connectionState=d.ConnectionState.disconnected;break}n.post(d.WorkerEvent.connectionState,[n._connectionState])}}),n._pc.addEventListener("signalingstatechange",i=>{n._destroyed||n._pc.signalingState==="stable"&&n._iceCandidates.length>0&&(n._iceCandidates.forEach(o=>{n.addIceCandidate(o)}),n._iceCandidates=[])}),n._localSessionInfo=null,n._remoteSessionInfo=null};P.prototype=Object.create(E.prototype),P.prototype.constructor=P,P.prototype.startConnectivity=function(e){var t=this;if(e&&(t._stream=e),t._remoteNewSDPInfo)return t._remoteNewSDPInfo=!1,t._connectionState=d.ConnectionState.connecting,d.SessionInfoType.offer===t._remoteSessionInfo.sdpInfo.type?t.createAnswer(t._stream):Promise.resolve();if(!t._waitAnswer)return t.createOffer(t._stream)},P.prototype.waitConnectivity=function(){var e=this;return console.log("AAAA",e._remoteNewSDPInfo,e._connectionState===d.ConnectionState.new,!e._waitAnswer),e._remoteNewSDPInfo||e._connectionState===d.ConnectionState.new&&!e._waitAnswer},P.prototype.setRemoteSessionInfo=function(e){var t=this;return t._remoteSessionInfo=e,t._remoteNewSDPInfo=!0,t._waitAnswer=!1,t._remoteSessionInfo.tracksInfo&&t.post(d.WorkerEvent.trackInfo,[t._remoteSessionInfo.tracksInfo]),t._pc.setRemoteDescription(new mt(t._remoteSessionInfo.sdpInfo)).then(()=>{e.extraSDPInfo&&t.addExtraSdpInfo(e.extraSDPInfo)})},P.prototype.addExtraSdpInfo=function(e){var t=this;e.iceCandidates.forEach(r=>{t._pc.signalingState==="stable"?t.addIceCandidate(r):t._iceCandidates.push(r)})},P.prototype.destroy=function(e){var t=this;t._pc&&t._pc.close(),t._destroyed=!0},P.prototype.createOffer=function(e){var t=this;if(t._pc!==null)return e.getTracks().forEach(r=>{t._pc.addTrack(r)}),t._pc.createOffer({offerToReceiveAudio:!0,offerToReceiveVideo:!0}).then(r=>{let n=t.gotLocalDescription(r);return t._waitAnswer=!0,n})},P.prototype.createAnswer=function(e){var t=this;if(t._pc!==null)return e.getTracks().forEach(r=>{t._pc.addTrack(r,e)}),t._pc.createAnswer().then(r=>t.gotLocalDescription(r))},P.prototype.gotLocalDescription=function(e){var t=this;if(t._pc.setLocalDescription(e),t._localSessionInfo={sdpInfo:e},t._stream){t._localSessionInfo.tracksInfo=[];let r=!1;t._stream.getTracks().forEach(n=>{n.kind==="video"&&(r=!0);const i={id:n.id,type:n.kind,enabled:n.enabled};t._localSessionInfo.tracksInfo.push(i)}),r||t._localSessionInfo.tracksInfo.push({id:"video",type:"video",enabled:!1})}return t._localSessionInfo},P.prototype.addIceCandidate=function(e){var t=this;t._pc.addIceCandidate(new gt(e),()=>{},r=>{console.log("Error on 'addIceCandidate': "+r)})};function Ct(e){const t=yt(e);return Object.keys(t).forEach((r,n,i)=>{t[n].hasOwnProperty("url")?t[n].urls=t[n].url:t[n].url=t[n].urls}),t}function yt(e={},t=!1){try{const r=JSON.stringify(e),n=t?r.replace(/null/g,'""'):r;return JSON.parse(n)}catch{return e}}const v=function(e,t,r,n){E.apply(this,arguments);var i=this;i._callInfo=e,i._options=t,i._worker=null,i._userWorkers={},i.id=e.id,i.loggedUser=r,i.participants={},i.participants[r.username]={username:r.username,role:40,joinOrdinal:1},e.participants.forEach(o=>{i.participants[o.username]=o,(o.joinOrdinal||!n)&&o.username!==r.username&&i.createOrGetWorker(o.username)})};v.prototype=Object.create(E.prototype),v.prototype.constructor=v,v.prototype.addParticipant=function(e){const t=this;t.participants[e.username]=e},v.prototype.removeParticipant=function(e){const t=this;let r=e.username;delete t.participants[r],t._userWorkers&&t._userWorkers[r]&&(t._userWorkers[r].destroy(),delete t._userWorkers[r])},v.prototype.joinedParticipant=function(e){const t=this;t.participants[e.username]=e;let r=t.loggedUser.username,n=t.participants[r];console.log("My Participant ",n);for(const[i,o]of Object.entries(t.participants))console.log("Participant ",o),o.joinOrdinal>0&&n.joinOrdinal>0&&n.joinOrdinal>o.joinOrdinal&&o.username!==r&&t.createOrGetWorker(o.username)},v.prototype.startConnectivity=function(e){var t=this,r=[];e&&(t._stream=e);const n={};let i=!1;for(const[o,s]of Object.entries(t._userWorkers))try{console.log("Check need connectivity for worker",o),s.waitConnectivity()&&t._stream&&(console.log("Start connectivity for worker with username",o,t._stream),r.push(s.startConnectivity(t._stream).then(a=>{a&&(i=!0,console.log("For "+o+" received sessionInfo: ",a),n[o]=a)})))}catch(a){console.log("Error on start connectivity",a)}return Promise.all(r).then(()=>(console.log("All workers ready needSend:"+i+"; usersSessionInfo:",n),i?{usersSessionInfo:n}:null))},v.prototype.updateConnectionInfo=function(e){var t=this,r=e.sessionInfo;if(r){var n=t.createOrGetWorker();r.sdpInfo&&n.setRemoteSessionInfo(r)}for(var i in e.usersSessionInfo){var o=t.createOrGetWorker(i),s=e.usersSessionInfo[i];s.sdpInfo&&o.setRemoteSessionInfo(s)}},v.prototype.muteAudio=function(e){var n;var t=this;const r=[];return(n=t._stream)==null||n.getAudioTracks().forEach(i=>{i.enabled=!e;const o={id:i.id,type:i.kind,enabled:i.enabled};r.push(o)}),r},v.prototype.muteVideo=function(e){var n;var t=this;const r=[];return(n=t._stream)==null||n.getVideoTracks().forEach(i=>{i.enabled=!e;const o={id:i.id,type:i.kind,enabled:i.enabled};r.push(o)}),r},v.prototype.addExtraSessionDescription=function(e){var t=this;e.extraSDPInfo&&t._worker&&t._worker.addExtraSdpInfo(e.extraSDPInfo);let r=e.usersExtraSDPInfo;if(r)for(const n in r)r.hasOwnProperty(n)&&t._userWorkers&&t._userWorkers[n]&&t._userWorkers[n].addExtraSdpInfo(r[n])},v.prototype.createOrGetWorker=function(e){var t=this;if(e){var r=t._userWorkers[e];return r||(console.log("Create worker for ",e),r=t.createWorker(e),t._userWorkers[e]=r),r}else return t._worker||(t._worker=t.createWorker()),t._worker},v.prototype.createWorker=function(e){var t=this,r=new P(t._options);return r.register(d.WorkerEvent.iceCandidate,function(n){t.post(d.CallEvent.onIceCandidate,[t.id,e,n])}),r.register(d.WorkerEvent.onTrack,function(n){t.post(d.CallEvent.onTrack,[e,n])}),r.register(d.WorkerEvent.trackInfo,function(n){t.post(d.CallEvent.trackInfo,[t.participants[e],n])}),r.register(d.WorkerEvent.connectionState,function(n){const i=t.participants[e];(n==="connectionState.failed"||n==="connectionState.disconnected")&&setTimeout(()=>{i&&(i.connectionState==="connectionState.failed"||i.connectionState==="connectionState.disconnected")&&t.post(d.CallEvent.dead,[e,n])},5e3),i&&(i.connectionState=n),t.post(d.CallEvent.connectionState,[e,n])}),r},v.prototype.destroy=function(){var e=this;e._worker&&(e._worker.destroy(),e._worker=null);for(const t in e._userWorkers)e._userWorkers.hasOwnProperty(t)&&e._userWorkers[t].destroy();e._userWorkers={},e._stream&&e._stream.getTracks().forEach(t=>{t.stop()})};const L=function(t){this._vs=t,this._storage=new te};L.prototype.get=function(e){return this._storage.get(e)},L.prototype.create=function(e,t,r){var n=this;if(n._storage.get(e.id))throw new Error("Call with "+e.id+" already exist");let i=n._vs.getAuthManager().getLoggedUser();const o=new v(e,t,i,r);return n._storage.add(o),o.register(d.CallEvent.onIceCandidate,function(s,a,l){const c=n._vs.getCallManager();if(a){const p={};p[a]={iceCandidates:[l]},c.addExtraConnectionInfo(s,{usersExtraSDPInfo:p})}else c.addExtraConnectionInfo(s,{extraSDPInfo:{iceCandidates:[l]}})}),o.register(d.CallEvent.onTrack,(s,a)=>{n._vs.getBus().post(d.APIEvent.onTrack,[o._callInfo,s,a])}),o.register(d.CallEvent.trackInfo,(s,a)=>{n._vs.getBus().post(d.APIEvent.trackInfo,[o._callInfo,s,a])}),o.register(d.CallEvent.connectionState,(s,a)=>{n._vs.getBus().post(d.APIEvent.connectionState,[o._callInfo,s,a])}),o.register(d.CallEvent.dead,(s,a)=>{console.log("CallEvent dead username="+s+", event="+a)}),o},L.prototype.processCurrentCalls=function(e,t){const r=this;if(e&&(r._storage.forEach(n=>{let i=!1;e.forEach(o=>{o.id===n.id&&(i=!0)}),i||r.destroy(n.id)}),e.length>0)){let n=e[0];r.invite(n,t)}},L.prototype.invite=function(e,t){var r=this;let n=r.get(e.id);n?console.log("Call with id "+n.id+" already exist, ignore info"):(n=r.create(e,t,!0),r._vs.getBus().post(d.APIEvent.invite,[e]),n.updateConnectionInfo(e.connectionInfo))},L.prototype.destroy=function(e){var t=this;let r=t.remove(e);return r&&(console.log("Destroy call with id="+e),r.destroy(),r.post(d.CallEvent.finished),t._vs.getBus().post(d.APIEvent.finished,[r._callInfo])),r},L.prototype.remove=function(e){return this._storage.remove(e)};const pe=function(e){this._conversation=e};pe.prototype.created=function(e){},pe.prototype.addedMessage=function(e){this._conversation.history.push(e)};const et=function(e,t){this._conversation=e,this._client=t};et.prototype.addMessage=function(e){this._conversation.history.push(e),this._client.getCommander(S.NAME).addMessage(this._conversation.id,e)};const le=function(e){this.id=null,this.participants=null,this.attributes=null,this.name=null,this.status=null,this.history=[],this._conversationEventListener=new pe(this),this._conversationController=new et(this,e)};le.prototype.getConversationEventListener=function(){return this._conversationEventListener},le.prototype.getConversationController=function(){return this._conversationController};const Y=function(t){this._virusonic=t,this._storage=new te};Y.prototype.get=function(e){return this._storage.get(e)},Y.prototype.getByUsername=function(e){var t=null;return this._storage.forEach(function(r){r.participants.length==1&&r.participants[0].username==e&&(t=r)}),t},Y.prototype.create=function(e){var t=new le(this._virusonic.getClient());return t.id=e.id,t.participants=e.participants,t.attributes=e.attributes,t.name=e.name,this._storage.add(t),t};const A=function(t,r){E.apply(this,arguments),this._client=t,this._options=r,this._loggedUser={}};A.prototype=Object.create(E.prototype),A.prototype.constructor=A,A.prototype.getLoggedUser=function(){return this._loggedUser},A.prototype.auth=function(e,t){var r=this;return new Promise(function(n,i){r._client.call("auth",d.ServerMethod.auth,[e,t,{attributes:{},version:"1.0.1"}]).then(function(o){o.status==="10"?i():(r._loggedUser=o.user,n(o.user),r._client.getCallProvider().processCurrentCalls(o.calls,r._options))}).catch(o=>{i(o)})})},A.prototype.changeSettings=function(e,t,r,n){var i=this;i._client.call("main",d.ServerMethod.changeSettings,[e.username,t,r,n])};const G=function(t,r){E.apply(this,arguments),this._client=t,this._options=r,this._users={}};G.prototype=Object.create(E.prototype),G.prototype.constructor=G,G.prototype.getUsers=function(e){var t=this,r=new U.ResponseCallback(function(n){n.forEach(function(s){t._users[s.username]=s});for(var i in t._users){var o=t._users[i];o.chatlog=[]}return e(t._users)});t._client.call("main",d.ServerMethod.getUsers,[],r)},G.prototype.callback_updateUsers=function(e){this.notify(d.VSEvent.onUsersChange,[e])};const tt={getUUID:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=Math.random()*16|0,r=e=="x"?t:t&3|8;return r.toString(16)})}},j=function(t,r){this._client=t,this._options=r};j.prototype.getConversations=function(e){var t=this;this._client.getCommander(S.NAME).getConversations(new U.ResponseCallback(function(r){r.forEach(function(n){var i=[],o=t._client.getConversationProvider().create(n);o&&(o.getConversationEventListener().created(n),i.push(o)),e&&e(i)})}))},j.prototype.create=function(e){e.id=tt.getUUID(),e.name||(e.name="",e.participants.forEach(function(r){e.name+=r.username+","}),e.name&&(e.name=e.name.substr(0,e.name.length-1)));var t=this._client.getConversationProvider().create(e);return this._client.getCommander(S.NAME).create(e),t},j.prototype.get=function(e){return this._client.getConversationProvider().get(e)},j.prototype.getByUsername=function(e){return this._client.getConversationProvider().getByUsername(e)},j.prototype.addMessage=function(e,t){var r=this._client.getConversationProvider().get(e);r&&r.getConversationController().addMessage(t)},j.prototype.getHistory=function(e){var t=this._client.getConversationProvider().get(e);if(t)return t.history};const R=function(t,r){E.apply(this,arguments),this._vs=t,this._client=t._client,this._options=r,this._outgoingCallId=void 0};R.prototype=Object.create(E.prototype),R.prototype.constructor=R,R.prototype.invite=function(e,t,r){var n=this;if(this._outgoingCallId)throw new Error("Sdk can not have more one ougoing call, current outgoing call id = "+this._outgoingCallId);this.outgoingCallId=tt.getUUID();var i={id:this.outgoingCallId,p2p:!0,attributes:r,participants:[{username:e,role:20}]},o=n._client.getCallProvider().create(i,n._options,!1);return o.register(d.CallEvent.finished,function(){n._outgoingCallId=void 0}),o.startConnectivity(t).then(s=>(i.connectionInfo=s,n._client.call("call",d.ServerMethod.invite,[i]).then(()=>i)))},R.prototype.addParticipant=function(e,t){const r=this;r._client.getCallProvider().get(e);const n={username:t,role:20};r._client.call("call",d.ServerMethod.addParticipant,[e,n])},R.prototype.removeParticipant=function(e,t){const r=this;r._client.getCallProvider().get(e);const n={username:t,role:20};r._client.call("call",d.ServerMethod.removeParticipant,[e,n])},R.prototype.join=function(e,t){const r=this;r._stream=t;const n=r._client.getCallProvider().get(e);return n.startConnectivity(t).then(i=>{r._client.call("call",d.ServerMethod.join,[n.id,i])})},R.prototype.addExtraConnectionInfo=function(e,t){var r=this;r._client.call("call",d.ServerMethod.addExtraConnectionInfo,[e,t])},R.prototype.muteAudio=function(e,t){var r=this,n=r._client.getCallProvider().get(e);if(n){const i=n.muteAudio(t);r._client.call("call",d.ServerMethod.setTrackInfo,[e,i])}},R.prototype.muteVideo=function(e,t){var r=this,n=r._client.getCallProvider().get(e);if(n){const i=n.muteVideo(t);r._client.call("call",d.ServerMethod.setTrackInfo,[e,i])}},R.prototype.leave=function(e){var t=this,r=t._client.getCallProvider().get(e);if(r){var n={status:30};t._client.call("call",d.ServerMethod.leave,[r.id,n]),t._client.getCallProvider().destroy(r.id)}},R.prototype.getCalls=function(){var e=this,t=new U.ResponseCallback(function(r){if(r&&r.length>0){let n=r[0];e._client.getCallProvider().invite(n,this._vs._options)}});e._client.call("call",d.ServerMethod.getCalls,[],t)};const W=function(){this.audioTrack=null,this.videoTrack=null};W.prototype.clear=function(){this.audioTrack=null,this.videoTrack=null},W.prototype.available=function(){return getUserMedia!==void 0&&RTCPeerConnection!==void 0},W.prototype.getStream=function(e){const t=this,r={},n=new vt;return e.audio&&(t._checkAliveTrack(t.audioTrack)?(n.addTrack(t.audioTrack),t.audioTrack.enabled=!0):(t.audioTrack=null,r.audio=!0)),e.video&&(t._checkAliveTrack(t.videoTrack)?(n.addTrack(t.videoTrack),t.videoTrack.enabled=!0):(t.videoTrack=null,r.video=!0)),r.video||r.audio?dt.getUserMedia(r).then(i=>(r.audio&&(t.audioTrack=i.getAudioTracks()[0],n.addTrack(t.audioTrack)),r.video&&(t.videoTrack=i.getVideoTracks()[0],n.addTrack(t.videoTrack)),Promise.resolve(n))):Promise.resolve(n)},W.prototype._checkAliveTrack=function(e){return e&&e.readyState==="live"};class _t{constructor(t,r){M(this,"_uri");M(this,"_options");M(this,"_bus");M(this,"_callManager");M(this,"_conversationManager");M(this,"_userManager");M(this,"_authManager");M(this,"_handlerManager");M(this,"_relation");M(this,"_client");M(this,"_localMediaManager");var n=this;n._uri=t,n._options=r,n._bus=new E}connect(){var t=this;t._handlerManager=new b,this._relation=new de(this._uri),this._relation.addMessageListener(new ue(this._handlerManager));let r=()=>{t._bus.post(d.RelationEvent.connected)},n=o=>{t._bus.post(d.RelationEvent.disconnected,[o])},i=new nt(r,n);this._relation.addRelationListener(i),this._relation.connect(),this._client=new z(this._relation,new Y(this),new L(this)),this._handlerManager.register(new y(this)),this._handlerManager.register(new N(this)),this._authManager=new A(this._client,this._options),this._userManager=new G(this._client,this._options),this._conversationManager=new j(this._client,this._options),this._callManager=new R(this,this._options),this._localMediaManager=new W}getBus(){return this._bus}getClient(){return this._client}getHandlerManager(){return this._handlerManager}getAuthManager(){return this._authManager}getUserManager(){return this._userManager}getConversationManager(){return this._conversationManager}getCallManager(){return this._callManager}getMediaManager(){return this._localMediaManager}close(){var t;delete this._callManager,delete this._conversationManager,delete this._userManager,delete this._authManager,delete this._handlerManager,(t=this._relation)==null||t.close(),delete this._client}}k.VS=_t,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});