sceyt-call 1.3.3 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +1 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
- !function(e,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?exports["sceyt-call"]=i():e["sceyt-call"]=i()}(this,(()=>{return e={547:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CallStateMachine=void 0;const n=t(578),a=(0,t(645).createLogger)("CallStateMachine");class l{constructor(e){this.callId=e}isValidStateTransition(e,i){var t,n;return null!==(n=null===(t=l.validStateTransitions.get(i))||void 0===t?void 0:t.has(e))&&void 0!==n&&n}setState(e,i,t){return this.isValidStateTransition(e,i)?(a.info(`[25] [CallId: ${this.callId}] Call state changed ${i} -> ${e}, reason: ${t}`,{color:"cyan"}),!0):(a.warn(`[28] [CallId: ${this.callId}] Invalid CallState changed ${i} -> ${e}, reason: ${t}`,{color:"red"}),!1)}updateState(e,i,t){return this.setState(e,i,t)}}i.CallStateMachine=l,l.validStateTransitions=new Map([[n.CallState.Idle,new Set([n.CallState.Connecting,n.CallState.Closed])],[n.CallState.Connecting,new Set([n.CallState.Connected,n.CallState.Closed,n.CallState.Idle])],[n.CallState.Connected,new Set([n.CallState.Closed,n.CallState.Idle])],[n.CallState.Closed,new Set([])]])},758:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ParticipantStateMachine=void 0;const n=t(578),a=(0,t(645).createLogger)("ParticipantStateMachine");class l{constructor(e,i){this.userId=e,this.callId=i}isValidParticipantStateTransition(e,i){var t,n;return null!==(n=null===(t=l.validParticipantStateTransitions.get(i))||void 0===t?void 0:t.has(e))&&void 0!==n&&n}isValidConnectionTransition(e,i){var t,n;return null!==(n=null===(t=l.validConnectionTransitions.get(i))||void 0===t?void 0:t.has(e))&&void 0!==n&&n}setState(e,i,t,l){let s=!1;void 0!==e&&void 0!==t&&this.isValidParticipantStateTransition(e,t)?(a.debug(`[43] [CallId: ${this.callId}] Participant state transition: ${t} -> ${e}`),s=!0):e&&a.warn(`[46] [CallId: ${this.callId}] Invalid ParticipantState transition from ${t?n.ParticipantState[t]:"undefined"} to ${e?n.ParticipantState[e]:"undefined"}`,{color:"yellow"}),void 0!==i&&void 0!==l&&this.isValidConnectionTransition(i,l)?(a.debug(`[50] [CallId: ${this.callId}] Connection state transition: ${l} -> ${i}`),s=!0):i&&a.warn(`[53] [CallId: ${this.callId}] Invalid ConnectionState transition from ${l?n.ParticipantConnectionState[l]:"undefined"} to ${i?n.ParticipantConnectionState[i]:"undefined"}`,{color:"yellow"})}updateState(e,i){return this.isValidParticipantStateTransition(e,i)?(this.setState(e,void 0,i,void 0),!0):(a.warn(`[63] [CallId: ${this.callId}] Invalid ParticipantState transition from ${n.ParticipantState[i]} to ${n.ParticipantState[e]}`,{color:"yellow"}),!1)}updateConnectionState(e,i){return this.isValidConnectionTransition(e,i)?(this.setState(void 0,e,void 0,i),!0):(a.warn(`[71] [CallId: ${this.callId}] Invalid ConnectionState transition from ${n.ParticipantConnectionState[i]} to ${n.ParticipantConnectionState[e]}`,{color:"yellow"}),!1)}}i.ParticipantStateMachine=l,l.validParticipantStateTransitions=new Map([[n.ParticipantState.Idle,new Set([n.ParticipantState.Ringing,n.ParticipantState.Declined,n.ParticipantState.Kicked,n.ParticipantState.NoAnswer,n.ParticipantState.Joined,n.ParticipantState.Left])],[n.ParticipantState.Ringing,new Set([n.ParticipantState.Joined,n.ParticipantState.Declined,n.ParticipantState.Kicked,n.ParticipantState.NoAnswer,n.ParticipantState.Idle])],[n.ParticipantState.Joined,new Set([n.ParticipantState.Left,n.ParticipantState.Kicked,n.ParticipantState.Idle])],[n.ParticipantState.Left,new Set([n.ParticipantState.Idle,n.ParticipantState.Joined])],[n.ParticipantState.Declined,new Set([n.ParticipantState.Idle,n.ParticipantState.Joined])],[n.ParticipantState.Kicked,new Set([n.ParticipantState.Idle])],[n.ParticipantState.NoAnswer,new Set([n.ParticipantState.Idle,n.ParticipantState.Joined])]]),l.validConnectionTransitions=new Map([[n.ParticipantConnectionState.Idle,new Set([n.ParticipantConnectionState.Connecting])],[n.ParticipantConnectionState.Connecting,new Set([n.ParticipantConnectionState.Connected,n.ParticipantConnectionState.Disconnected,n.ParticipantConnectionState.Idle])],[n.ParticipantConnectionState.Connected,new Set([n.ParticipantConnectionState.Reconnecting,n.ParticipantConnectionState.Disconnected,n.ParticipantConnectionState.Idle])],[n.ParticipantConnectionState.Reconnecting,new Set([n.ParticipantConnectionState.Connected,n.ParticipantConnectionState.Connecting,n.ParticipantConnectionState.Disconnected,n.ParticipantConnectionState.Idle])],[n.ParticipantConnectionState.Disconnected,new Set([n.ParticipantConnectionState.Idle,n.ParticipantConnectionState.Reconnecting,n.ParticipantConnectionState.Connected])]])},258:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.ActiveSpeakerManager=void 0;const a=t(645),l=t(578),s=(0,a.createLogger)("ActiveSpeakerManager");class o{constructor(e){this.speakingStates=new Map,this.activeSpeakers=[],this.dominantSpeaker=null,this.lastActiveSpeakers=[],this.lastDominantSpeaker=null,this.dominantSpeakerLastChangeTime=0,this.processingInterval=null,this.call=null,this.internalCallHandler=null,this.call=e}start(e){var i,t;this.processingInterval||(this.internalCallHandler=e,this.internalCallHandler&&this.call?(this.processingInterval=setInterval((()=>n(this,void 0,void 0,(function*(){var e,i,t,n,a,o,r;try{if(this.call&&this.internalCallHandler){if(this.call.localParticipant){let n=0;if(this.call.mediaFlow!==l.MediaFlow.SFU){const i=this.call.participants.find((e=>{var i,t,n,a;return e.id!==(null===(t=null===(i=this.call)||void 0===i?void 0:i.localParticipant)||void 0===t?void 0:t.id)||e.clientId!==(null===(a=null===(n=this.call)||void 0===n?void 0:n.localParticipant)||void 0===a?void 0:a.clientId)}));if(i){const t=null===(e=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===e?void 0:e[i.getFullId()];if(t){const e=yield t.getConnectionStats(),i=Array.from(e.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));n=i.length>0?Math.max(...i):0}}}else{const e=this.call.serverParticipant;if(e){const t=null===(i=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===i?void 0:i[e.getFullId()];if(t){const e=yield t.getConnectionStats(),i=Array.from(e.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));n=i.length>0?Math.max(...i):0}}}(null===(t=this.call.localParticipant.mediaState)||void 0===t?void 0:t.audio.enabled)||(n=0),this.processAudioLevels(this.call.localParticipant,n)}for(const e of this.call.participants){if(e.id===this.call.localParticipant.id&&e.clientId===this.call.localParticipant.clientId)continue;let i=0;if(this.call.mediaFlow!==l.MediaFlow.SFU){const t=null===(n=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===n?void 0:n[e.getFullId()];if(t){const e=yield t.getConnectionStats(),n=Array.from(e.values()).filter((e=>this.isInboundAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));i=n.length>0?Math.max(...n):0}}else{const t=null===(a=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===a?void 0:a[e.getFullId()];if(t){const e=yield t.getConnectionStats(),n=Array.from(e.values()).filter((e=>this.isInboundAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));i=n.length>0?Math.max(...n):0}}(null===(o=e.mediaState)||void 0===o?void 0:o.audio.enabled)||(i=0),this.processAudioLevels(e,i)}}this.processActiveSpeakers(),this.call&&(this.call.emitActiveSpeakersChanged(this.activeSpeakers),this.call.emitDominantSpeakerChanged(this.dominantSpeaker))}catch(e){s.error(`[137] [CallId: ${null===(r=this.call)||void 0===r?void 0:r.id}] Error processing audio levels: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}))),o.POLLING_INTERVAL_MS),s.info(`[141] [CallId: ${null===(t=this.call)||void 0===t?void 0:t.id}] Active speaker detection started`)):s.error(`[47] [CallId: ${null===(i=this.call)||void 0===i?void 0:i.id}] Call or InternalCallHandler is not set`,{color:"red"}))}getActiveSpeakers(){return this.activeSpeakers}stop(){var e;this.processingInterval&&(clearInterval(this.processingInterval),this.processingInterval=null),this.activeSpeakers=[],this.dominantSpeaker=null,this.speakingStates.clear(),this.lastActiveSpeakers=[],this.lastDominantSpeaker=null,s.info(`[154] [CallId: ${null===(e=this.call)||void 0===e?void 0:e.id}] Active speaker detection stopped`)}addParticipant(e){var i;const t=this.getParticipantKey(e);this.speakingStates.has(t)||(this.speakingStates.set(t,{participant:e,audioLevel:0,smoothedAudioLevel:0,isSpeaking:!1,speakingStartTime:0}),s.info(`[167] [CallId: ${null===(i=this.call)||void 0===i?void 0:i.id}] Added participant for active speaker detection: ${e.getFullId()}`))}updateParticipant(e){const i=this.getParticipantKey(e),t=this.speakingStates.get(i);t&&this.speakingStates.set(i,Object.assign(Object.assign({},t),{participant:e}))}removeParticipant(e){var i,t,n;const a=this.getParticipantKey(e);this.speakingStates.delete(a),this.lastActiveSpeakers.some((i=>i.participant.id===e.id&&i.participant.clientId===e.clientId))&&this.processActiveSpeakers(),(null===(i=this.lastDominantSpeaker)||void 0===i?void 0:i.participant.id)===e.id&&(null===(t=this.lastDominantSpeaker)||void 0===t?void 0:t.participant.clientId)===e.clientId&&(this.dominantSpeaker=null,this.lastDominantSpeaker=null),s.info(`[199] [CallId: ${null===(n=this.call)||void 0===n?void 0:n.id}] Removed participant from active speaker detection: ${e.getFullId()}`)}getAudioLevel(e){var i,t;const n=this.getParticipantKey(e);return null!==(t=null===(i=this.speakingStates.get(n))||void 0===i?void 0:i.smoothedAudioLevel)&&void 0!==t?t:null}isSpeaking(e){var i,t;const n=this.getParticipantKey(e);return null!==(t=null===(i=this.speakingStates.get(n))||void 0===i?void 0:i.isSpeaking)&&void 0!==t&&t}isDominantSpeaker(e){var i,t;return(null===(i=this.dominantSpeaker)||void 0===i?void 0:i.participant.id)===e.id&&(null===(t=this.dominantSpeaker)||void 0===t?void 0:t.participant.clientId)===e.clientId}processActiveSpeakers(){const e=Date.now(),i=new Map;this.speakingStates.forEach(((t,n)=>{i.set(n,this.updateSpeakingState(t,e))})),this.speakingStates=i;const t=Array.from(this.speakingStates.values()).filter((e=>e.isSpeaking)).sort(((e,i)=>i.smoothedAudioLevel-e.smoothedAudioLevel));JSON.stringify(t)!==JSON.stringify(this.lastActiveSpeakers)&&(this.activeSpeakers=t,this.lastActiveSpeakers=t),this.updateDominantSpeaker(t,e)}updateDominantSpeaker(e,i){if(0===e.length)return void(this.lastDominantSpeaker&&i-this.dominantSpeakerLastChangeTime>o.DOMINANT_SPEAKER_HYSTERESIS_MS&&(this.dominantSpeaker=null,this.lastDominantSpeaker=null));if(!this.lastDominantSpeaker)return this.dominantSpeaker=e[0],this.lastDominantSpeaker=e[0],void(this.dominantSpeakerLastChangeTime=i);const t=e[0];t.participant.id===this.lastDominantSpeaker.participant.id&&t.participant.clientId===this.lastDominantSpeaker.participant.clientId||t.smoothedAudioLevel>.5&&i-t.speakingStartTime>o.DOMINANT_SPEAKER_HYSTERESIS_MS&&(this.dominantSpeaker=t,this.lastDominantSpeaker=t,this.dominantSpeakerLastChangeTime=i)}updateSpeakingState(e,i){const t=e.audioLevel>e.smoothedAudioLevel?Math.max(e.smoothedAudioLevel,e.smoothedAudioLevel+(e.audioLevel-e.smoothedAudioLevel)*o.ACTIVE_LEVEL_BOOST):Math.max(0,e.smoothedAudioLevel-(e.smoothedAudioLevel-e.audioLevel)*o.ACTIVE_LEVEL_DECAY);let n=e.isSpeaking,a=e.speakingStartTime;return t>=o.AUDIO_LEVEL_THRESHOLD?e.isSpeaking||(n=!0,a=i):e.isSpeaking&&i-e.speakingStartTime>o.SPEAKING_TIME_THRESHOLD_MS&&(n=!1),Object.assign(Object.assign({},e),{smoothedAudioLevel:t,isSpeaking:n,speakingStartTime:a})}processAudioLevels(e,i){var t,n;try{let n=null;if(null===(t=e.mediaState)||void 0===t?void 0:t.audio.enabled)if("number"==typeof i)n=i;else{const e=Array.from(i.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));n=e.length>0?Math.max(...e):0}else n=0;if(null!==n){const i=this.getParticipantKey(e),t=this.speakingStates.get(i);t&&this.speakingStates.set(i,Object.assign(Object.assign({},t),{audioLevel:n}))}}catch(e){s.error(`[330] [CallId: ${null===(n=this.call)||void 0===n?void 0:n.id}] Error processing audio levels: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}getParticipantKey(e){return`${e.id}/${e.clientId}`}isOutboundAudio(e){return"outbound-rtp"===e.type&&"audio"===e.kind}isMediaSourceAudio(e){return"media-source"===e.type&&"audio"===e.kind}getStatsAudioLevel(e){var i;return null!==(i=e.audioLevel)&&void 0!==i?i:null}isInboundAudio(e){return"inbound-rtp"===e.type&&"audio"===e.kind}}i.ActiveSpeakerManager=o,o.AUDIO_LEVEL_THRESHOLD=.1,o.SPEAKING_TIME_THRESHOLD_MS=250,o.DOMINANT_SPEAKER_HYSTERESIS_MS=1e3,o.ACTIVE_LEVEL_DECAY=.2,o.ACTIVE_LEVEL_BOOST=1.5,o.POLLING_INTERVAL_MS=150},250:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.AudioTrack=void 0,i.AudioTrack=class{constructor(e){this._enabled=!0,this.id=e.id,this.audioTrack=e}set enabled(e){this._enabled=e,this.audioTrack.enabled=e}get enabled(){return this._enabled}}},271:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SceytCallClient=void 0;const n=t(650),a=t(645),l=t(185),s=t(297),o=t(228),r=(0,a.createLogger)("CallClient");class d extends s.TypedEventEmitter{constructor(e){super(),this.fetchCall=e=>{r.info(`[20] [CallId: ${e}] Get call from server`,{color:"cyan"});const i=this.internalCallHandler.activeCalls.find((i=>i.id===e));return i?Promise.resolve({success:!0,data:i}):this.internalCallHandler.prepareCallFromCallID(e)},this.getOngoingCalls=()=>(this.internalCallHandler.getCalls(),this.internalCallHandler.activeCalls),this.onLog=e=>((0,a.addLogListener)(e),()=>(0,a.removeLogListener)(e)),this.internalCallHandler=new n.InternalCallHandler(e),this.setupInternalEventBridge()}setupInternalEventBridge(){this.internalCallHandler.setCallEvent("onInvitedToCall",(e=>{this.emit("invitedToCall",{call:e})})),this.internalCallHandler.setCallEvent("onOngoingCallsUpdated",(e=>{this.emit("ongoingCallsUpdated",{calls:e})}))}get activeCalls(){return this.internalCallHandler.activeCalls}prepareCall(e,i){r.info(`[19] [CallId: ${e}] Prepare call`,{color:"cyan"});try{return this.internalCallHandler.prepareCall(e,i)}catch(i){return r.error(`[19] [CallId: ${e}] Prepare call failed: ${i.message||JSON.stringify(i)}`,{color:"red"}),{success:!1,error:(0,o.toCallException)(i)}}}get RecentCallQueryBuilder(){return l.RecentCallQueryBuilder}}i.SceytCallClient=d},998:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.Call=void 0;const a=t(302),l=t(65),s=t(650),o=t(578),r=t(547),d=t(645),c=t(258),u=t(297),p=t(228),h=(0,d.createLogger)("Call");class g extends u.TypedEventEmitter{get activeSpeakers(){return this._activeSpeakers}set activeSpeakers(e){this._activeSpeakers=e}constructor({id:e,sessionId:i="",mediaFlow:t,createdBy:a="",localParticipant:l,participants:r,metadata:d,chatClient:u,isCallSilenced:g}){super(),this.state=o.CallState.Idle,this._localAudioTracks=[],this._localVideoTracks=[],this._muted=!1,this._onHold=!1,this._screenSharing=!1,this._activeSpeakers=[],this.videoEnabled=!1,this.eventsQueue=new Map,this.isCallSilenced=!1,this.videoCall=!1,this.isCreatedRemotely=!1,this.videoDeviceId=null,this.audioDeviceId=null,this.getStats=()=>n(this,void 0,void 0,(function*(){try{const e=[];for(const i of this.participants){const t=yield this.getParticipantStats(i);t.success&&t.data&&e.push(t.data)}return{success:!0,data:e}}catch(e){return h.error(`[502] [CallId: ${this.id}] Error getting call stats ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}})),this.getParticipantStats=e=>n(this,void 0,void 0,(function*(){try{h.info(`[503] [CallId: ${this.id}] getParticipantStats for ${e.getFullId()}`,{color:"cyan"});const i=s.InternalCallHandler.getInstance().callParticipantsRTCMap[this.id],t=null==i?void 0:i[e.getFullId()];return t?{success:!0,data:yield t.getConnectionStats()}:{success:!1,error:(0,p.toCallException)(new Error("Participant RTC client not found"))}}catch(e){return h.error(`[504] [CallId: ${this.id}] Error getting participant stats ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}})),this.id=e,this.sessionId=i,this.createdBy=a,this.participants=r,this.localParticipant=l,this.mediaFlow=t,this.metadata=d,this.activeSpeakerManager=new c.ActiveSpeakerManager(this),this.chatClient=u,this.isCallSilenced=g}emitAudioTrackAdded(e,i){this.emit("audioTrackAdded",{call:this,participant:e,track:i})}emitAudioTrackRemoved(e){this.emit("audioTrackRemoved",{call:this,participant:e})}emitVideoTrackAdded(e,i){this.emit("videoTrackAdded",{call:this,participant:e,track:i})}emitVideoTrackRemoved(e){this.emit("videoTrackRemoved",{call:this,participant:e})}emitCallStateChanged(e){this.emit("callStateChanged",{call:this,state:e})}emitParticipantStateChanged(e,i,t){this.emit("participantStateChanged",{call:this,participant:e,state:i,reason:t})}emitParticipantConnectionStateChanged(e,i){this.emit("participantConnectionStateChanged",{call:this,participant:e,state:i})}emitParticipantEvent(e,i,t){this.emit("participantEvent",{call:this,participant:e,event:i,changedBy:t})}emitCallPermissionsUpdated(e){this.emit("callPermissionsUpdated",{call:this,permissions:e})}emitParticipantPermissionsUpdated(e,i){this.emit("participantPermissionsUpdated",{call:this,participant:e,permissions:i})}emitParticipantsAdded(e){this.emit("participantsAdded",{call:this,participants:e})}emitParticipantsRemoved(e){this.emit("participantsRemoved",{call:this,participants:e})}emitActiveSpeakersChanged(e){this._activeSpeakers=e,this.emit("activeSpeakersChanged",{call:this,activeSpeakers:e})}emitDominantSpeakerChanged(e){this.emit("dominantSpeakerChanged",{call:this,dominantSpeaker:e})}emitMediaFlowChanged(e){this.emit("mediaFlowChanged",{call:this,mediaFlow:e})}emitSessionRenewed(e){this.emit("sessionRenewed",{call:this,sessionId:e})}clearEventsQueue(){this.eventsQueue.clear()}setState(e,i){const t=new r.CallStateMachine(this.id).updateState(e,this.state,i);return t&&(this.state=e,e===o.CallState.Connected?this.activeSpeakerManager.start(s.InternalCallHandler.getInstance()):this.activeSpeakerManager.stop(),this.emitCallStateChanged(e)),t}addParticipants(e){const i=e=>s.InternalCallHandler.getInstance().addParticipantsToCall(e,this);return this.sessionId?i(e):this.eventsQueue.set("ADD_PARTICIPANTS",(()=>i(e))),{success:!0}}join(e,i){h.info(`[J1] [CallId: ${this.id}] Join call`,{color:"cyan"});try{if(!(new a.SendSignalValidator).canSendSignalEvent(o.SignalEvent.JOIN,this)){const e=`Cannot join call with ID ${this.id} due to invalid call state or participant state.`;return h.warn(`[J2] [CallId: ${this.id}] ${e}`,{color:"red"}),{success:!1,error:l.SceytCallException.BadRequest(4006,e)}}const t=s.InternalCallHandler.getInstance().joinCall(this,e,i);return(null==t?void 0:t.data)&&t.data.activeSpeakerManager.addParticipant(t.data.localParticipant),t}catch(e){return h.error(`[J3] [CallId: ${this.id}] Join failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}reject(e,i){try{return h.info(`[R1] [CallId: ${this.id}] Rejecting call`,{color:"cyan"}),s.InternalCallHandler.getInstance().rejectCall(this,e,i),this.activeSpeakerManager.removeParticipant(this.localParticipant),{success:!0}}catch(e){return h.error(`[R2] [CallId: ${this.id}] Rejection failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}leave(){try{return h.info(`[L1] [CallId: ${this.id}] Leaving call`,{color:"cyan"}),s.InternalCallHandler.getInstance().leaveCall(this,!0,"leave"),this.activeSpeakerManager.removeParticipant(this.localParticipant),{success:!0}}catch(e){return h.error(`[L2] [CallId: ${this.id}] Leave failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}create(){return n(this,void 0,void 0,(function*(){h.info(`[C1] [CallId: ${this.id}] Create call`,{color:"cyan"});try{const e=s.InternalCallHandler.getInstance();return yield e.createCall(this)}catch(e){return h.error(`[C3] [CallId: ${this.id}] create failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}addParticipantToList(e){this.participants.push(e)}kickParticipants(e){const i=e=>{const i=null==e?void 0:e.map((e=>({id:e})));return this.kickParticipantsFromList(i),!0};return this.sessionId?i(e):this.eventsQueue.set("KICK_PARTICIPANT",(()=>i(e))),{success:!0}}kickParticipantsFromList(e,i=!0){if(i)return s.InternalCallHandler.getInstance().kickParticipantsFromCall(e,this)}setSessionId(e){this.sessionId=e}setCreatedBy(e){this.createdBy=e}setVideoCall(e){this.videoCall=e}changeMediaFlow(e){this.mediaFlow!=e&&(this.mediaFlow=e,this.emitMediaFlowChanged(e))}switchToSFU(e){return n(this,void 0,void 0,(function*(){const i=i=>{h.info(`[159] [CallId: ${this.id}] handle switch call to ${o.MediaFlow.SFU}`,{color:"cyan"});const t=s.InternalCallHandler.getInstance(),n=t.activeCalls.find((e=>e.id===i));return t.switchCallToSfu(n,e)};return this.sessionId?i(this.id):this.eventsQueue.set(o.SignalEvent.SWITCH_MEDIA_FLOW,(()=>i(this.id))),{success:!0}}))}mute(e,i){var t,n;if(!e&&!1===(null===(t=this.localParticipant.permissions)||void 0===t?void 0:t.canPublishAudio))return{success:!1,error:new l.SceytCallException("Cannot unmute: you have been hard-muted by the host",403)};if(!e&&!1===(null===(n=this.permissions)||void 0===n?void 0:n.allowPublishAudio))return{success:!1,error:new l.SceytCallException("Cannot unmute: audio is locked for this call",403)};this.muted=e,this.localParticipant.setMediaAudioState({enabled:!e},this.localParticipant.permissions||{},this);const a=e=>{s.InternalCallHandler.getInstance().sendAudioEnable(this,e,i)};return this.sessionId?a(e):this.eventsQueue.set(o.SignalEvent.MUTE,(()=>a(e))),{success:!0}}muteAllRemoteParticipants(e){const i=()=>{s.InternalCallHandler.getInstance().muteAllRemoteParticipants(this,e)};return this.sessionId?i():this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_AUDIO,(()=>i())),{success:!0}}videoOffAllRemoteParticipants(e){const i=()=>{s.InternalCallHandler.getInstance().videoOffAllRemoteParticipants(this,e)};return this.sessionId?i():this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_VIDEO,(()=>i())),{success:!0}}disableAllRemoteParticipantsVideo(e){return this.videoOffAllRemoteParticipants(e)}updateParticipantPermissions(e,i,t){const n=e=>{s.InternalCallHandler.getInstance().updateParticipantPermissions(this,e,i,t)};return this.sessionId?n(e):this.eventsQueue.set(o.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE,(()=>n(e))),{success:!0}}muteRemoteParticipant(e,i){const t=e=>{s.InternalCallHandler.getInstance().muteRemoteParticipant(this,e,i)};return this.sessionId?t(e):this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_AUDIO,(()=>t(e))),{success:!0}}disableRemoteParticipantAudio(e,i){const t=e=>{s.InternalCallHandler.getInstance().disableRemoteParticipantAudio(this,e,i)};return this.sessionId?t(e):this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_AUDIO,(()=>t(e))),{success:!0}}enableRemoteParticipantAudio(e,i){const t=e=>{s.InternalCallHandler.getInstance().enableRemoteParticipantAudio(this,e,i)};return this.sessionId?t(e):this.eventsQueue.set(o.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE,(()=>t(e))),{success:!0}}enableCallAudio(e){var i,t;return this.updateCallPermissions({allowPublishAudio:!0,allowPublishVideo:null===(t=null===(i=this.permissions)||void 0===i?void 0:i.allowPublishVideo)||void 0===t||t},e)}disableCallAudio(e){var i,t;return this.updateCallPermissions({allowPublishAudio:!1,allowPublishVideo:null===(t=null===(i=this.permissions)||void 0===i?void 0:i.allowPublishVideo)||void 0===t||t},e)}disableRemoteParticipantVideo(e,i){const t=e=>{s.InternalCallHandler.getInstance().videoOffRemoteParticipant(this,e,i)};return this.sessionId?t(e):this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_VIDEO,(()=>t(e))),{success:!0}}videoOffRemoteParticipant(e,i){const t=e=>{s.InternalCallHandler.getInstance().videoOffRemoteParticipant(this,e,i)};return this.sessionId?t(e):this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_VIDEO,(()=>t(e))),{success:!0}}disableCallVideo(e){var i,t;return this.updateCallPermissions({allowPublishAudio:null===(t=null===(i=this.permissions)||void 0===i?void 0:i.allowPublishAudio)||void 0===t||t,allowPublishVideo:!1},e)}enableCallVideo(e){var i,t;return this.updateCallPermissions({allowPublishAudio:null===(t=null===(i=this.permissions)||void 0===i?void 0:i.allowPublishAudio)||void 0===t||t,allowPublishVideo:!0},e)}updateCallPermissions(e,i){const t=()=>{s.InternalCallHandler.getInstance().updateCallPermissions(this,e,i)};return this.sessionId?t():this.eventsQueue.set(o.SignalEvent.CALL_PERMISSIONS_UPDATE,(()=>t())),{success:!0}}hold(e){this.onHold=e,this.localAudioTracks.forEach((i=>{i.enabled=!e})),this.localVideoTracks.forEach((i=>{i.enabled=!e})),this.localParticipant.audioTracks.forEach((i=>{i.enabled=!e})),this.localParticipant.videoTracks.forEach((i=>{i.enabled=!e}));const i=e=>{s.InternalCallHandler.getInstance().sendHold(this,e)};return this.sessionId?i(e):this.eventsQueue.set(o.SignalEvent.HOLD,(()=>i(e))),{success:!0}}set localAudioTracks(e){this._localAudioTracks=e}get localAudioTracks(){return this._localAudioTracks}set localVideoTracks(e){this._localVideoTracks=e}get localVideoTracks(){return this._localVideoTracks}setServerParticipant(e){this.serverParticipant=e}set muted(e){this._muted=e}get muted(){return this._muted}set screenSharing(e){this._screenSharing=e}get screenSharing(){return this._screenSharing}set onHold(e){this._onHold=e}get onHold(){return this._onHold}setIsCallSilenced(e){this.isCallSilenced=e}getIsCallSilenced(){return this.isCallSilenced}setVideoDeviceId(e){this.videoDeviceId=e}getVideoDeviceId(){return this.videoDeviceId}setAudioDeviceId(e){this.audioDeviceId=e}getAudioDeviceId(){return this.audioDeviceId}setIsCreatedRemotely(e){this.isCreatedRemotely=e}getIsCreatedRemotely(){return this.isCreatedRemotely}enableVideo(e,i){return n(this,void 0,void 0,(function*(){return this.localParticipantVideoEnable(e,i)}))}localParticipantVideoEnable(e,i,t,a=!0){return n(this,void 0,void 0,(function*(){const t=s.InternalCallHandler.getInstance();let l=[];return e||(this.localVideoTracks.forEach((e=>{e.stop()})),this.localParticipant.videoTracks.forEach((e=>{e.enabled=!1}))),yield(()=>n(this,void 0,void 0,(function*(){var s,r,d,c,u,g;try{if(e){const e=(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind));this.videoDeviceId&&(e.some((e=>e.deviceId===this.videoDeviceId))||(h.warn(`Previously selected video device with ID ${this.videoDeviceId} not found. Falling back to default camera.`),this.setVideoDeviceId(null)));const i=null===(s=this.localVideoTracks[0])||void 0===s?void 0:s.getSettings().deviceId;if(this.videoDeviceId&&i===this.videoDeviceId&&"live"===(null===(r=this.localVideoTracks[0])||void 0===r?void 0:r.readyState))l=this.localVideoTracks;else{this.localVideoTracks.forEach((e=>{e.stop()})),this.localParticipant.videoTracks.forEach((e=>{e.enabled=!1}));const e=yield navigator.mediaDevices.getUserMedia({video:Object.assign(Object.assign({},this.videoDeviceId?{deviceId:{exact:this.videoDeviceId}}:{}),{width:{min:640,max:1280},height:{min:480,max:720}})});l=e.getVideoTracks(),l.sort((e=>(e.getSettings().deviceId||"")===this.videoDeviceId?-1:1)),this.setVideoDeviceId((null===(d=l[0])||void 0===d?void 0:d.getSettings().deviceId)||null)}}else l=this.localVideoTracks;!this.videoDeviceId&&l.length>0&&this.setVideoDeviceId((null===(c=l[0])||void 0===c?void 0:c.getSettings().deviceId)||null),this.localVideoTracks=l,this.localParticipant.setVideoTracks(l,this),this.localParticipant.setMediaVideoState({enabled:e,changedBy:null===(u=this.localParticipant.mediaState)||void 0===u?void 0:u.video.changedBy},this.localParticipant.permissions||{},this),this.localParticipant.videoTracks.forEach((i=>{i.enabled=e})),this.localVideoTracks&&(null===(g=this.localVideoTracks)||void 0===g?void 0:g.length)&&(yield t.changeVideoTracks(this,this.localVideoTracks[0],e));const v=e=>n(this,void 0,void 0,(function*(){try{t.sendVideoEnabled(this,e,i)}catch(e){return h.error(`[323] [CallId: ${this.id}] Failed to send video enabled signal: message: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),void(null==i||i({error:(0,p.toCallException)(e)}))}}));a&&(this.sessionId?v(e):this.eventsQueue.set(e?o.SignalEvent.VIDEO_ON:o.SignalEvent.VIDEO_OFF,(()=>v(e))))}catch(e){return h.error(`[325] [CallId: ${this.id}] Error enabling video ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}})))(),{success:!0}}))}shareScreen(e,i){var t,a,l,r,d;return n(this,void 0,void 0,(function*(){let c=[];this.screenSharing=e;try{if(e){const i=yield navigator.mediaDevices.getDisplayMedia({video:{width:{max:1280},height:{max:720},frameRate:{max:30}}});if(this.localVideoTracks.forEach((e=>{e.stop()})),c=i.getVideoTracks(),i.addEventListener("inactive",(()=>{var e;(null===(e=this.localParticipant.mediaState)||void 0===e?void 0:e.screenShare.enabled)&&this.stopScreenShare()})),this.localVideoTracks=c,this.localParticipant.setVideoTracks(c,this),this.localParticipant.videoTracks.forEach((i=>{i.enabled=e})),c&&c.length){const i=s.InternalCallHandler.getInstance();yield i.changeVideoTracks(this,c[0],e,!0)}this.localParticipant.setMediaScreenShareState({enabled:e,changedBy:null===(t=this.localParticipant.mediaState)||void 0===t?void 0:t.screenShare.changedBy},this)}else(null===(l=null===(a=this.localParticipant.mediaState)||void 0===a?void 0:a.video)||void 0===l?void 0:l.enabled)&&!e?(this.localParticipant.setMediaScreenShareState({enabled:e,changedBy:null===(r=this.localParticipant.mediaState)||void 0===r?void 0:r.screenShare.changedBy},this),yield this.localParticipantVideoEnable(!0,i,!0)):this.localParticipant.setMediaScreenShareState({enabled:e,changedBy:null===(d=this.localParticipant.mediaState)||void 0===d?void 0:d.screenShare.changedBy},this);const u=e=>n(this,void 0,void 0,(function*(){const t=s.InternalCallHandler.getInstance();this.videoEnabled&&e?yield t.sendVideoEnabled(this,!1,i):this.videoEnabled&&!e&&(yield t.sendVideoEnabled(this,!0,i)),yield t.sendScreenShare(this,e,i)}));return this.sessionId?u(e):this.eventsQueue.set(e?o.SignalEvent.SCREEN_SHARE_ON:o.SignalEvent.SCREEN_SHARE_OFF,(()=>u(e))),{success:!0}}catch(e){return h.error(`[324] [CallId: ${this.id}] Error sharing screen ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}startScreenShare(e){return n(this,void 0,void 0,(function*(){return this.shareScreen(!0,e)}))}stopScreenShare(e){return n(this,void 0,void 0,(function*(){return yield this.shareScreen(!1,e)}))}getAvailableVideoDevices(){return n(this,void 0,void 0,(function*(){try{return{success:!0,data:(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind))}}catch(e){return h.error(`[306] [CallId: ${this.id}] Error getting video devices ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}getAvailableAudioDevices(){return n(this,void 0,void 0,(function*(){try{return{success:!0,data:(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"audioinput"===e.kind))}}catch(e){return h.error(`[307] [CallId: ${this.id}] Error getting audio devices ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}selectVideoDevice(e){var i,t;return n(this,void 0,void 0,(function*(){if(this.setVideoDeviceId(e),!this.videoEnabled||(null===(i=this.localParticipant.mediaState)||void 0===i?void 0:i.screenShare.enabled))return{success:!0};try{this.localVideoTracks.forEach((e=>{e.stop()}));const i=(yield navigator.mediaDevices.getUserMedia({video:{deviceId:{exact:e},width:{min:640,max:1280},height:{min:480,max:720}}})).getVideoTracks();this.localVideoTracks=i,this.localParticipant.setVideoTracks(i,this);const n=s.InternalCallHandler.getInstance();return yield n.changeVideoTracks(this,i[0],!!(null===(t=this.localParticipant.mediaState)||void 0===t?void 0:t.video.enabled)),{success:!0}}catch(e){return h.error(`[308] [CallId: ${this.id}] Error selecting video device ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}selectAudioDevice(e){var i,t;return n(this,void 0,void 0,(function*(){try{const n=s.InternalCallHandler.getInstance(),a=(yield navigator.mediaDevices.getUserMedia({audio:{deviceId:{exact:e}}})).getAudioTracks();return this.localAudioTracks=a,this.localParticipant.setAudioTracks(a,this),this.setAudioDeviceId((null===(i=a[0])||void 0===i?void 0:i.getSettings().deviceId)||null),yield n.changeAudioTracks(this,a[0],!(null===(t=this.localParticipant.mediaState)||void 0===t?void 0:t.audio.enabled)),{success:!0}}catch(e){return h.error(`[309] [CallId: ${this.id}] Error selecting audio device ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}setVideoEnabled(e){this.videoEnabled=e}setMuted(e){this._muted=e}getParticipant(e,i){return this.participants.find((t=>t.id===e&&t.clientId===i))}sendRinging(e){return s.InternalCallHandler.getInstance().sendRinging(this,e)}setSettings(e){return void 0!==(null==e?void 0:e.callType)&&(this.callType=e.callType),this.settings=e,{success:!0}}toJson(){return{id:this.id,sessionId:this.sessionId,mediaFlow:this.mediaFlow,participants:this.participants,localParticipant:this.localParticipant,createdBy:this.createdBy,metadata:this.metadata,state:this.state,activeSpeakerManager:this.activeSpeakerManager,eventsQueue:this.eventsQueue,chatClient:this.chatClient,serverParticipant:this.serverParticipant,videoEnabled:this.videoEnabled,onHold:this.onHold,localAudioTracks:this.localAudioTracks,localVideoTracks:this.localVideoTracks,muted:this.muted,isCallSilenced:this.isCallSilenced}}}i.Call=g},228:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.checkCode=i.toCallException=i.handleAck=void 0;const n=t(65);function a(e,i){switch(e){case 4e3:return n.SceytCallException.BadSignal(e,i);case 4001:return n.SceytCallException.CallNotFound(e,i);case 4002:return n.SceytCallException.ParticipantNotFound(e,i);case 4005:case 4003:return n.SceytCallException.NotAllowed(e,i);case 4004:return n.SceytCallException.ParticipantAlreadyExists(e,i);case 5001:return n.SceytCallException.InternalError(e,i);case 9901:case 9903:case 9904:return n.SceytCallException.NetworkError(e,i);case 9902:return n.SceytCallException.Timeout(e,i);case 4006:return n.SceytCallException.BadRequest(e,i);default:return n.SceytCallException.Unknown(e,i)}}i.handleAck=function(e){return e.error&&a(e.error.code,e.error.message),e},i.toCallException=function(e){try{if(null==e?void 0:e.code)return a(e.code,e.message)}catch(e){if(e instanceof n.SceytCallException)return e}return n.SceytCallException.Unknown(void 0,(null==e?void 0:e.message)||String(e))},i.checkCode=a},65:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SceytCallException=void 0;class t extends Error{get isResendable(){return this._isResendable}constructor(e,i,t="SceytCallException"){super(e),this.code=i,this.name=t,this._isResendable=!1,this.name=t}static BadSignal(e,i){return new t(i,e,"BadSignal")}static CallNotFound(e,i){return new t(i,e,"CallNotFound")}static ParticipantNotFound(e,i){return new t(i,e,"ParticipantNotFound")}static NotAllowed(e,i){return new t(i,e,"NotAllowed")}static ParticipantAlreadyExists(e,i){return new t(i,e,"ParticipantAlreadyExists")}static InternalError(e,i){const n=new t(i,e,"InternalError");return n._isResendable=!0,n}static NetworkError(e,i){const n=new t(i,e,"NetworkError");return n._isResendable=!0,n}static Timeout(e,i){const n=new t(i,e,"Timeout");return n._isResendable=!0,n}static BadRequest(e,i){return new t(i,e,"BadRequest")}static Unknown(e,i){return new t(i,e)}}i.SceytCallException=t},650:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(i,"__esModule",{value:!0}),i.InternalCallHandler=void 0;const l=a(t(583)),s=t(787),o=t(546),r=t(786),d=t(578),c=t(998),u=t(489),p=t(645),h=t(429),g=t(65),v=t(680),S=t(228),f=(0,p.createLogger)("InternalCallHandler"),C="$all";class I{constructor(e){this.callParticipantsRTCMap={},this.activeCalls=[],this.prepareCalls=[],this.callEvents={},this.handleMediaConnectedSignal=e=>{const i=this.activeCalls.find((i=>i.id===e.callId));if(i){let t=null==i?void 0:i.participants.find((i=>i.getFullId()===e.from));if(t||(t=i.participants.find((i=>{var t;return i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&!i.clientId})),t?t.clientId=e.from.split("/")[1]:(t=new s.Participant(e.from),i.addParticipantToList(t),i.emitParticipantsAdded([t]))),t&&i.localParticipant.state===d.ParticipantState.Joined&&i.localParticipant.getFullId()!==t.getFullId()&&(!this.callParticipantsRTCMap[i.id]||!this.callParticipantsRTCMap[i.id][t.getFullId()]||(null==t?void 0:t.shouldResetPeerConnection)||(null==t?void 0:t.connectionState)!==d.ParticipantConnectionState.Connected)){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[968] [CallId: ${i.id}] SYNC CONNECT failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`):e.event!==d.SignalEvent.ERROR||f.error(`[971] [CallId: ${i.id}] SYNC CONNECT failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};f.info(`[975] [CallId: ${i.id}] SYNC CONNECT to participant ${t.getFullId()}`,{color:"blue"}),this.signalingClient.clearParticipantSignals(i.id,t.getFullId()),this.signalingClient.sendSignalMessage({to:t.getFullId(),event:d.SignalEvent.CONNECT,mediaFlow:i.mediaFlow,callId:i.id,sessionId:i.sessionId},e)}}},this.onIceCandidate=(e,i,t)=>{var n,a;if(t.mediaFlow!==d.MediaFlow.SFU)if(f.info(`[996] [CallId: ${t.id}] onIceCandidate, participantID: ${e.getFullId()}, candidate: ${null===(n=i.candidate)||void 0===n?void 0:n.candidate}, type: ${null===(a=i.candidate)||void 0===a?void 0:a.type}`,{color:"blue"}),i.candidate&&i.candidate.candidate){let n="";if(!/\bufrag\s+\S+/i.test(i.candidate.candidate)&&this.callParticipantsRTCMap[t.id]&&this.callParticipantsRTCMap[t.id][e.getFullId()]){const i=this.callParticipantsRTCMap[t.id][e.getFullId()];i&&(n=` ufrag ${i.getLocalSdpUfrag()}`)}const a={candidate:i.candidate.candidate+n,sdpMid:i.candidate.sdpMid||"",sdpMLineIndex:i.candidate.sdpMLineIndex||0};try{const i=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[1007] [CallId: ${t.id}] SYNC ICE failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`):e.event!==d.SignalEvent.ERROR||f.error(`[1011] [CallId: ${t.id}] SYNC ICE failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};this.signalingClient.sendSignalMessage({to:this.getParticipantId(e),event:d.SignalEvent.ICE,mediaFlow:t.mediaFlow,callId:t.id,sessionId:t.sessionId,ice:a},i)}catch(i){f.error(`[1023] [CallId: ${t.id}] Failed to send ICE candidate to ${e.getFullId()}: ${i instanceof Error?i.message:JSON.stringify(i)}`)}}else f.info(`[1025] [CallId: ${t.id}] ICE gathering complete for participant ${e.getFullId()} (null candidate)`,{color:"blue"});else f.info(`[1024] [CallId: ${t.id}] onIceCandidate, participantID: ${e.getFullId()}, skip for SFU`,{color:"blue"})},this.onTrack=(e,i,t)=>{const n=null==t?void 0:t.track;f.info(`[1032] [CallId: ${e.id}] onTrack, participantID: ${i.getFullId()}, kind: ${n.kind}`,{color:"blue"}),"audio"===(null==n?void 0:n.kind)?(i.setAudioTracks([n],e),n.onended=()=>{f.info(`[1038] [CallId: ${e.id}] Audio track ended for participant ${i.getFullId()}`,{color:"yellow"}),i.setAudioTracks([],e),e.emitAudioTrackRemoved(i)}):"video"===(null==n?void 0:n.kind)&&(i.setVideoTracks([n],e),n.onended=()=>{f.info(`[1052] [CallId: ${e.id}] Video track ended for participant ${i.getFullId()}`,{color:"yellow"}),i.setVideoTracks([],e),e.emitVideoTrackRemoved(i)})},this.kickParticipantsFromCall=(e,i)=>{this.signalingClient.sendSignalMessage({mediaFlow:i.mediaFlow,callId:i.id,event:d.SignalEvent.KICK,sessionId:i.sessionId,participants:e.map((e=>({id:e.id,clientId:""})))},(t=>{if(t instanceof g.SceytCallException||t instanceof Error)f.error(`[1642] [CallId: ${i.id}] Kick participant failed: ${t.message} code: ${t instanceof g.SceytCallException?t.code:""}`,{color:"red"});else if(t.event!==d.SignalEvent.ERROR)for(let t=0;t<e.length;t++){const n=e[t];i.participants.forEach((e=>{e.id===n.id&&(this.closePeerConnections(i.id,e.getFullId()),i.activeSpeakerManager.removeParticipant(e),e.updateState(d.ParticipantState.Kicked,i),e.updateConnectionState(d.ParticipantConnectionState.Idle,i))}))}else f.error(`[1646] [CallId: ${i.id}] Kick participant failed: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"})}))},this.addParticipantsToCall=(e,i)=>{try{if(e.forEach((e=>{const t=i.participants.filter((i=>i.id===e));if(t.length>0)for(const e of t)e.state!==d.ParticipantState.Joined&&e.state!==d.ParticipantState.Ringing&&(e.updateState(d.ParticipantState.Idle,i),e.updateConnectionState(d.ParticipantConnectionState.Idle,i));else{const t=new s.Participant(e);i.addParticipantToList(t),i.emitParticipantsAdded([t])}})),f.info(`[1547] [CallId: ${i.id}] added participants to call: ${e}, callId: ${i.id}`,{color:"light-green"}),e.length>0){const t=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[1551] [CallId: ${i.id}] SYNC INVITE failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[1555] [CallId: ${i.id}] SYNC INVITE failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};return this.signalingClient.sendSignalMessage({callId:i.id,sessionId:i.sessionId,event:d.SignalEvent.INVITE,participants:e.map((e=>new s.Participant(e).serialize()))},t),!0}return!1}catch(t){return f.error(`[1567] [CallId: ${i.id}] Failed to add participants to call: ${e}, callId: ${i.id} message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"}),!1}},this.sendSignalScreenShare=(e,i,t)=>{try{const n=i=>i instanceof g.SceytCallException||i instanceof Error?(f.error(`[1679] [CallId: ${e.id}] SYNC SCREEN_SHARE_ON failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`),void(null==t||t({error:(0,S.toCallException)(i)}))):i.event===d.SignalEvent.ERROR?(f.error(`[1683] [CallId: ${e.id}] SYNC SCREEN_SHARE_ON failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`),void(null==t||t({error:(0,S.toCallException)(i.error)}))):void 0;return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:i?d.SignalEvent.SCREEN_SHARE_ON:d.SignalEvent.SCREEN_SHARE_OFF,sessionId:e.sessionId},n),!0}catch(i){return f.error(`[1694] [CallId: ${e.id}] Failed to send screen share signal: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"}),null==t||t({error:(0,S.toCallException)(i)}),!1}},this.setupMediaStream=e=>n(this,void 0,void 0,(function*(){var i,t;try{const n=!e.getAudioDeviceId()||{deviceId:{exact:e.getAudioDeviceId()}},a=(yield navigator.mediaDevices.getUserMedia({video:!1,audio:n})).getAudioTracks();if(e.localAudioTracks=a,e.setAudioDeviceId((null===(i=a[0])||void 0===i?void 0:i.getSettings().deviceId)||null),!(null==e?void 0:e.localVideoTracks)||!(null===(t=e.localVideoTracks)||void 0===t?void 0:t.length)){const i=(0,u.getEmptyVideoTrack)();i.forEach((e=>e.enabled=!1)),e.localVideoTracks=i,e.localParticipant.setVideoTracks(i,e)}return e.localParticipant.audioTracks=a,{audioTracks:a}}catch(i){throw f.error(`[1945] [CallId: ${e.id}] Failed to get media: message: ${i instanceof Error?i.message:JSON.stringify(i)}`),(0,S.toCallException)(i)}})),this.chatClient=e,this.user=e.user,this.clientId=e.clientId,this.signalingClient=new r.Signaling(e,this.handleSignalMessage.bind(this));const i=new this.chatClient.ConnectionListener;i.onConnectionStateChanged=e=>{f.info(`[46] [CallId: GLOBAL_LOGS] Signaling connection state changed: ${e}`,{color:"cyan"}),"Connected"===e&&(this.activeCalls.forEach((e=>{const i=this.signalingClient.signalingQueues.get(e.id);i&&i.triggerSignalProcessing()})),setTimeout((()=>{this.signalingClient.sendSignalMessage({event:d.SignalEvent.GET_CALL,callId:""},(e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[57] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed ${e instanceof g.SceytCallException||e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}):e.event!==d.SignalEvent.ERROR?this.syncActiveCalls(e):f.error("[63] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: "+(e.error?`${e.error.message} code: ${e.error.code}`:""),{color:"red"})}),"get_call")}),1e3))},this.chatClient.addConnectionListener("listener_id",i),"Connected"===this.chatClient.connectionState&&setTimeout((()=>{this.signalingClient.sendSignalMessage({event:d.SignalEvent.GET_CALL,callId:""},(e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[74] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR?this.syncActiveCalls(e):f.error("[77] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: "+(e.error?`${e.error.message} code: ${e.error.code}`:""),{color:"red"})}),"get_call")}),1e3),I.instance=this}syncActiveCalls(e){var i,t;const n=this.activeCalls;try{if(!(null==e?void 0:e.calls))return;if(e.event!==d.SignalEvent.SUCCESS)return void f.error("[98] [CallId: GLOBAL_LOGS] Failed to get call information after reconnection message: "+(e.error?`${e.error.message} code: ${e.error.code}`:""),{color:"red"});for(const a of n){const n=e.calls.find((e=>(null==e?void 0:e.id)===a.id));if(!n&&!(null==a?void 0:a.sessionId))continue;if(!n){this.closeCall(a);continue}if(n.sessionId!==a.sessionId){f.info(`[syncActiveCalls] [CallId: ${a.id}] sessionId changed (${a.sessionId} → ${n.sessionId}), closing stale call`,{color:"yellow"}),this.closeCall(a),this.promoteFromPrepared(n.id,n)?f.info(`[syncActiveCalls] [CallId: ${n.id}] Promoted from prepareCalls to activeCalls`,{color:"cyan"}):this.findOrCreateCall({id:n.id,sessionId:n.sessionId,mediaFlow:n.mediaFlow,participants:[],metadata:n.metadata,createdBy:n.createdBy,callOptions:null==n?void 0:n.options},n.participants);continue}const l=a.mediaFlow!==d.MediaFlow.SFU&&n.mediaFlow===d.MediaFlow.SFU;if(this.updateCallMetadata(a,n),l&&this.handleMediaFlowSwitch(a),this.syncParticipants(a,n.participants),a.localParticipant.state<=d.ParticipantState.Joined&&(a.state===d.CallState.Connected||a.state===d.CallState.Connecting)){for(const e of a.participants)if(a.mediaFlow!==d.MediaFlow.SFU&&e.connectionState===d.ParticipantConnectionState.Connected&&e.id!==a.localParticipant.id&&e.clientId!==a.localParticipant.clientId){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[139] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[143] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({event:d.SignalEvent.MEDIA_CONNECTED,callId:a.id,sessionId:a.sessionId,mediaFlow:a.mediaFlow,to:a.id},e)}if(a.mediaFlow===d.MediaFlow.SFU&&(null===(i=a.serverParticipant)||void 0===i?void 0:i.connectionState)===d.ParticipantConnectionState.Connected&&a.state===d.CallState.Connected){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[158] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[162] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({event:d.SignalEvent.MEDIA_CONNECTED,callId:a.id,sessionId:a.sessionId,mediaFlow:a.mediaFlow,to:a.id},e)}if(a.mediaFlow!==d.MediaFlow.SFU||this.callParticipantsRTCMap[a.id]&&this.callParticipantsRTCMap[a.id][a.id]||a.state!==d.CallState.Connected){if(a.mediaFlow===d.MediaFlow.SFU&&a.serverParticipant&&a.state===d.CallState.Connected){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[199] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[203] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};f.info(`[205] [CallId: ${a.id}] Sending offer to server participant when server participant is not connected: ${a.serverParticipant.getFullId()}`,{color:"yellow"}),this.sendOfferPeerToPeer(a,a.serverParticipant,e)}}else{if((null===(t=a.serverParticipant)||void 0===t?void 0:t.id)!==a.id){const e=new s.Participant(a.id);a.setServerParticipant(e)}if(a.serverParticipant){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[181] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[185] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};f.info(`[188] [CallId: ${a.id}] Sending offer to server participant when there is no server participant in the call: ${a.serverParticipant.getFullId()}`,{color:"yellow"}),this.sendOfferPeerToPeer(a,a.serverParticipant,e)}}}else a.localParticipant.state===d.ParticipantState.Joined&&this.leaveCall(a,!1,"syncActiveCalls")}this.activeCalls=this.activeCalls.filter((i=>{var t;return!(!(null===(t=null==e?void 0:e.calls)||void 0===t?void 0:t.find((e=>e.id===i.id)))&&i.sessionId&&(i.clearEventsQueue(),i.participants.forEach((e=>{this.signalingClient.clearParticipantSignals(i.id,e.getFullId())})),this.signalingClient.clearCallSignals(i.id),1))})),e.calls.forEach((e=>{!this.activeCalls.find((i=>(null==i?void 0:i.id)===(null==e?void 0:e.id)))&&e.id&&e.sessionId&&(this.promoteFromPrepared(e.id,e)?f.info(`[syncActiveCalls] [CallId: ${e.id}] Promoted from prepareCalls to activeCalls`,{color:"cyan"}):this.findOrCreateCall({id:e.id,sessionId:e.sessionId,mediaFlow:e.mediaFlow,participants:[],metadata:e.metadata,createdBy:e.createdBy,callOptions:null==e?void 0:e.options},e.participants))})),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}catch(e){f.error(`[248] [CallId: GLOBAL_LOGS] Error syncing calls after reconnection: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}setCallEvent(e,i){this.callEvents[e]=i}handleSignalMessage(e){var i,t,n,a,l,s,o,r;switch(e.callOptions=Object.assign(Object.assign({},e.callOptions||{}),{settings:Object.assign(Object.assign({},(null===(i=null==e?void 0:e.callOptions)||void 0===i?void 0:i.settings)||{}),{permissions:{allowPublishAudio:!(null===(a=null===(n=null===(t=null==e?void 0:e.callOptions)||void 0===t?void 0:t.settings)||void 0===n?void 0:n.permissions)||void 0===a?void 0:a.audioPublishingDisabled),allowPublishVideo:!(null===(o=null===(s=null===(l=null==e?void 0:e.callOptions)||void 0===l?void 0:l.settings)||void 0===s?void 0:s.permissions)||void 0===o?void 0:o.videoPublishingDisabled)}})}),e.calls=null===(r=e.calls)||void 0===r?void 0:r.map((e=>{var i,t,n,a,l,s,o;return Object.assign(Object.assign({},e),{options:Object.assign(Object.assign({},(null==e?void 0:e.options)||{}),{settings:Object.assign(Object.assign({},(null===(i=null==e?void 0:e.options)||void 0===i?void 0:i.settings)||{}),{permissions:{allowPublishAudio:!(null===(a=null===(n=null===(t=null==e?void 0:e.options)||void 0===t?void 0:t.settings)||void 0===n?void 0:n.permissions)||void 0===a?void 0:a.audioPublishingDisabled),allowPublishVideo:!(null===(o=null===(s=null===(l=null==e?void 0:e.options)||void 0===l?void 0:l.settings)||void 0===s?void 0:s.permissions)||void 0===o?void 0:o.videoPublishingDisabled)}})})})})),f.info(`[253] [CallId: ${e.callId}] Received message ${d.SignalEvent[e.event]}: ${JSON.stringify(Object.assign({},e))}`,{color:"green"}),e.event||0){case d.SignalEvent.OFFER:this.handleOfferSignal(e);break;case d.SignalEvent.ANSWER:this.handleAnswerSignal(e);break;case d.SignalEvent.JOIN:this.handleJoinSignal(e);break;case d.SignalEvent.LEAVE:this.handleLeaveSignal(e);break;case d.SignalEvent.INVITE:this.handleInviteSignal(e);break;case d.SignalEvent.CLOSE:this.handleCloseSignal(e);break;case d.SignalEvent.DECLINE:this.handleDeclineSignal(e);break;case d.SignalEvent.RINGING:this.handleRingingSignal(e);break;case d.SignalEvent.SWITCH_MEDIA_FLOW:this.handleSwitchMediaFlowSignal(e);break;case d.SignalEvent.ICE:this.handleIceSignal(e);break;case d.SignalEvent.VIDEO_ON:this.handleVideoOnSignal(e);break;case d.SignalEvent.VIDEO_OFF:this.handleVideoOffSignal(e);break;case d.SignalEvent.SCREEN_SHARE_ON:this.handleScreenShareOnSignal(e);break;case d.SignalEvent.SCREEN_SHARE_OFF:this.handleScreenShareOffSignal(e);break;case d.SignalEvent.MUTE:this.handleMuteSignal(e);break;case d.SignalEvent.UNMUTE:this.handleUnmuteSignal(e);break;case d.SignalEvent.HOLD:this.handleHoldSignal(e);break;case d.SignalEvent.UNHOLD:this.handleUnholdSignal(e);break;case d.SignalEvent.KICK:this.handleKickSignal(e);break;case d.SignalEvent.UPDATE:this.handleUpdateSignal(e);break;case d.SignalEvent.NO_ANSWER:this.handleNoAnswerSignal(e);break;case d.SignalEvent.MEDIA_CONNECTED:this.handleMediaConnectedSignal(e);break;case d.SignalEvent.CONNECT:this.handleConnectSignal(e);break;case d.SignalEvent.SESSION_RENEWED:this.handleSessionRenewedSignal(e);break;case d.SignalEvent.CALL_PERMISSIONS_UPDATE:this.handleCallPermissionsUpdateSignal(e);break;case d.SignalEvent.DISABLE_REMOTE_AUDIO:this.handleDisableRemoteAudioSignal(e);break;case d.SignalEvent.DISABLE_REMOTE_VIDEO:this.handleDisableRemoteVideoSignal(e);break;case d.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE:this.handleParticipantPermissionsUpdateSignal(e);break;default:f.info(`[254] [CallId: ${e.callId}] unhandled signal message: ${JSON.stringify(e)}`,{color:"green"})}}getParticipantId(e){return`${e.id}${(null==e?void 0:e.clientId)?"/"+(null==e?void 0:e.clientId):""}`}handleOfferSignal(e){var i,t,a,l,s;if(!this.activeCalls)return void f.warn(`[342] [CallId: ${e.callId}] No active calls found for send offer participant: ${e.from}`,{color:"red"});let o;try{const r=this.activeCalls.find((i=>i.id===e.callId));if(!r)return void f.warn(`[348] [CallId: ${e.callId}] No active call found for send offer participant: ${e.from}`,{color:"red"});if(r.state!==d.CallState.Connected&&r.state!==d.CallState.Connecting)return void f.warn(`[353] [CallId: ${e.callId}] Call is not connected for send offer participant: ${e.from}`,{color:"red"});let c=null==r?void 0:r.participants.find((i=>i.getFullId()===e.from));if(c){o=c.getFullId();const u=this.callParticipantsRTCMap[r.id]&&(null===(i=this.callParticipantsRTCMap[r.id])||void 0===i?void 0:i[c.getFullId()]);let p=null==u?void 0:u.getSessionId();!c.shouldResetPeerConnection&&u&&p===(null===(t=e.sessionData)||void 0===t?void 0:t.id)||(this.closePeerConnections(r.id,c.getFullId()),r.activeSpeakerManager.removeParticipant(c),this.addParticipantToRTCMap(r,c),c.setShouldResetPeerConnection(!1),(this.callParticipantsRTCMap[r.id]&&(null===(a=this.callParticipantsRTCMap[r.id])||void 0===a?void 0:a[c.getFullId()])).setSessionId((null===(l=e.sessionData)||void 0===l?void 0:l.id)||"")),this.signalingClient.clearParticipantSignals(r.id,c.getFullId()),f.info(`[394] [CallId: ${r.id}] setRemoteDescription (offer) for participant: ${c.getFullId()}, sessionId: ${null===(s=e.sessionData)||void 0===s?void 0:s.id}`,{color:"blue"}),this.setRemoteDescription(r.id,c.getFullId(),(0,v.toSessionDescription)(e.sessionData,"offer")).then((()=>n(this,void 0,void 0,(function*(){var i,t,n,a,l;if(!c)return void f.info(`[392] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});const s=this.callParticipantsRTCMap[r.id][c.getFullId()],o=this.activeCalls.find((e=>e.id===r.id));o&&(o.mediaFlow!==d.MediaFlow.SFU||o.mediaFlow===d.MediaFlow.SFU&&c.id===(null===(i=null==o?void 0:o.serverParticipant)||void 0===i?void 0:i.id))&&(yield this.addTracksToPeerConnection(r,c.getFullId(),!1)),f.info(`[393] [CallId: ${r.id}] createAnswer for participant: ${c.getFullId()}, sessionId: ${null===(t=e.sessionData)||void 0===t?void 0:t.id}, version: ${null===(n=e.sessionData)||void 0===n?void 0:n.version}`,{color:"blue"}),s.createAnswer((null===(a=e.sessionData)||void 0===a?void 0:a.id)||"",(null===(l=e.sessionData)||void 0===l?void 0:l.version)||"",r.mediaFlow).then((i=>{if(!c)return void f.info(`[392] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});if(!i)return void f.error(`[456] [CallId: ${r.id}] Failed to create answer for participant: ${c.getFullId()}`,{color:"red"});const t=s.getRemoteSdpUfrag();if(t&&s.iceQueueMap[c.getFullId()]){const e=s.iceQueueMap[c.getFullId()][t];if(e&&e.length>0)for(const i of e)s.addIceCandidate(i,c.getFullId())}this.signalingClient.sendSignalMessage({to:e.from,mediaFlow:e.mediaFlow,callId:r.id,event:d.SignalEvent.ANSWER,sessionData:i,sessionId:e.sessionId,metadata:e.metadata},(e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[386] [CallId: ${r.id}] SYNC ANSWER failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[389] [CallId: ${r.id}] SYNC ANSWER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})}))}))}))))}else f.info(`[402] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"})}catch(i){f.error(`[406] [CallId: ${e.callId}] Failed to handle offer: ${o} message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"})}}handleAnswerSignal(e){var i;try{const t=this.activeCalls.find((i=>i.id===e.callId));if(t){let n;if(n=t.mediaFlow===d.MediaFlow.SFU&&t.serverParticipant&&t.serverParticipant.getFullId()===e.from?t.serverParticipant:t.participants.find((i=>i.getFullId()===e.from)),n){const a=null===(i=e.sessionData)||void 0===i?void 0:i.version;if(!a||a!==this.callParticipantsRTCMap[t.id][n.getFullId()].getVersion())return void f.warn(`[412] [CallId: ${t.id}] Version is not set or is the same as the current version: ${a}`,{color:"red"});this.callParticipantsRTCMap[t.id][n.getFullId()].setVersion(a),this.setRemoteDescription(t.id,n.getFullId(),(0,v.toSessionDescription)(e.sessionData,"answer")).then((()=>{if(!n)return void f.info(`[462] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});const i=this.callParticipantsRTCMap[t.id][n.getFullId()].getRemoteSdpUfrag();if(i&&this.callParticipantsRTCMap[t.id][n.getFullId()].iceQueueMap[n.getFullId()]){const e=this.callParticipantsRTCMap[t.id][n.getFullId()].iceQueueMap[n.getFullId()][i];if(e&&e.length>0)for(const i of e)this.callParticipantsRTCMap[t.id][n.getFullId()].addIceCandidate(i,n.getFullId())}}))}}}catch(i){f.error(`[435] [CallId: ${e.callId}] Failed to handle answer: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"})}}sendOfferPeerToPeer(e,i,t){return n(this,void 0,void 0,(function*(){this.callParticipantsRTCMap.hasOwnProperty(e.id)&&this.callParticipantsRTCMap[e.id].hasOwnProperty(i.getFullId())||this.addParticipantToRTCMap(e,i),yield this.addTracksToPeerConnection(e,i.getFullId(),!0);const n=this.callParticipantsRTCMap[e.id][i.getFullId()];let a=n.getVersion();n.setVersion(a?String(Number(a)+1):"1"),a=n.getVersion();let l=n.getSessionId();l||(l=(0,h.v4)(),n.setSessionId(l)),n.createOffer(l,a,e.mediaFlow).then((n=>{n?this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.OFFER,sessionData:n,to:i.getFullId(),sessionId:e.sessionId},t):f.error(`[456] [CallId: ${e.id}] Failed to create offer for participant: ${i.getFullId()}`,{color:"red"})}))}))}handleJoinSignal(e){var i,t,n,a,l,o,r,c;try{let u=this.activeCalls.find((i=>i.id===e.callId));if(!u){let t=null;if(t=(null===(i=null==e?void 0:e.calls)||void 0===i?void 0:i.length)?e.calls[0]:this.signalMessageToICall(e),!t||!this.promoteFromPrepared(t.id,t)){const{call:e}=this.findOrCreateCall({id:t.id,sessionId:t.sessionId,mediaFlow:t.mediaFlow,participants:[],metadata:t.metadata},t.participants);u=e}return}if(u&&!u.sessionId&&(u.setSessionId(e.sessionId),u.setIsCreatedRemotely(!0)),u){let i;(null===(t=e.participants)||void 0===t?void 0:t.length)&&(i=e.participants[0]);let p=!1,h=u.participants.find((i=>i.getFullId()===e.from));if(h?h&&(h.setMediaVideoState((null===(l=null==i?void 0:i.mediaState)||void 0===l?void 0:l.video)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u),h.setMediaAudioState((null===(o=null==i?void 0:i.mediaState)||void 0===o?void 0:o.audio)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u)):(h=u.participants.find((i=>{var t;return i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&(i.clientId===e.from.split("/")[1]||!i.clientId)})),h?(h.clientId=e.from.split("/")[1],h.setMediaVideoState((null===(n=null==i?void 0:i.mediaState)||void 0===n?void 0:n.video)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u),h.setMediaAudioState((null===(a=null==i?void 0:i.mediaState)||void 0===a?void 0:a.audio)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u)):h=void 0),h||(h=new s.Participant(e.from),h.setMediaVideoState((null===(r=null==i?void 0:i.mediaState)||void 0===r?void 0:r.video)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u),h.setMediaAudioState((null===(c=null==i?void 0:i.mediaState)||void 0===c?void 0:c.audio)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u),u.addParticipantToList(h),p=!0),u.mediaFlow===d.MediaFlow.P2P&&u.localParticipant.state===d.ParticipantState.Joined&&this.isPolitePeer(e.from,u.localParticipant.getFullId())){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[495] [CallId: ${null==u?void 0:u.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[499] [CallId: ${null==u?void 0:u.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};f.info(`[503] [CallId: ${u.id}] Sending offer to participant: ${h.getFullId()}`),this.sendOfferPeerToPeer(u,h,e)}h.state=d.ParticipantState.Joined,f.info(`[503] [CallId: ${u.id}] Participant joined call shouldSendEventInvited: ${p}`),p?u.emitParticipantsAdded([h]):u.emitParticipantStateChanged(h,d.ParticipantState.Joined)}}catch(i){f.error(`[514] [CallId: ${e.callId}] Failed to handle USER_JOINED: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"})}}handleLeaveSignal(e){var i,t;const n=this.activeCalls.find((i=>i.id===e.callId));if(n){const a=null==n?void 0:n.participants.find((i=>{var t;return i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&(i.clientId===e.from.split("/")[1]||!i.clientId)}));a&&a.updateState(d.ParticipantState.Left,n)&&(this.closePeerConnections(n.id,a.getFullId()),n.activeSpeakerManager.removeParticipant(a),a.setMediaScreenShareState({enabled:!1,changedBy:null===(t=null===(i=null==a?void 0:a.mediaState)||void 0===i?void 0:i.screenShare)||void 0===t?void 0:t.changedBy},n),a.setHold(!1,n),a.updateConnectionState(d.ParticipantConnectionState.Idle,n))}}handleInviteSignal(e){if(!e||!e.callId)return void f.warn(`[545] [CallId: ${e.callId}] Received invalid invite signal message`);let i=this.activeCalls.find((i=>i.id===e.callId));i||(i=this.promoteFromPrepared(e.callId,this.signalMessageToICall(e)));const t=(null==e?void 0:e.to)===this.user.id;if(t&&i)for(let e=0;e<i.participants.length;e++){const t=i.participants[e];t.id===this.user.id&&(t.updateConnectionState(d.ParticipantConnectionState.Idle,i),t.updateState(d.ParticipantState.Idle,i))}i?this.handleExistingCallInvite(i,e,t):this.handleNewCallInvite(e,t),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}handleExistingCallInvite(e,i,t){var n,a;if(t){e.localParticipant.updateConnectionState(d.ParticipantConnectionState.Connecting,e)&&(e.participants.find((e=>e.id===this.user.id&&e.clientId===this.clientId))||e.addParticipantToList(e.localParticipant),e.emitParticipantConnectionStateChanged(e.localParticipant,d.ParticipantConnectionState.Connecting));const t=(null===(a=null===(n=i.participants)||void 0===n?void 0:n.find((e=>e.id===this.user.id&&e.clientId===this.clientId)))||void 0===a?void 0:a.isCallSilenced)||!1;e.setIsCallSilenced(t),this.callEvents.onInvitedToCall&&this.callEvents.onInvitedToCall(e)}else{const t=this.addNewParticipantsToCall(e,i);t.length>0&&e.emitParticipantsAdded(t)}}handleNewCallInvite(e,i){var t,n,a,o,r,p,h;const g=new s.Participant(this.user.id,this.clientId);g.connectionState=d.ParticipantConnectionState.Connecting;let v=!1;const S=null===(t=e.participants)||void 0===t?void 0:t.map((e=>{var i,t,n,a,l,o,r,c;if(e.id===this.user.id&&!e.clientId)return v=e.isCallSilenced||!1,g;const u=new s.Participant(e.id,null==e?void 0:e.clientId);return u.state=e.state||d.ParticipantState.Idle,u.setMediaAudioState({enabled:!!(null===(t=null===(i=null==e?void 0:e.mediaState)||void 0===i?void 0:i.audio)||void 0===t?void 0:t.enabled),changedBy:null===(a=null===(n=e.mediaState)||void 0===n?void 0:n.video)||void 0===a?void 0:a.changedBy},e.permissions||{}),u.setMediaVideoState({enabled:(null===(o=null===(l=e.mediaState)||void 0===l?void 0:l.video)||void 0===o?void 0:o.enabled)||!1,changedBy:null===(c=null===(r=e.mediaState)||void 0===r?void 0:r.video)||void 0===c?void 0:c.changedBy},e.permissions||{}),u}));if(!i&&!(null==S?void 0:S.find((i=>i.getFullId()===e.from)))&&(null===(n=null==e?void 0:e.from)||void 0===n?void 0:n.split("/")[0])===this.user.id&&e.from.split("/")[1]!==this.clientId){const i=new s.Participant(e.from,e.from.split("/")[1]);i.state=d.ParticipantState.Joined,null==S||S.push(i)}const f=(0,u.makeFirstById)(S||[],this.user.id,this.clientId),C=new c.Call({id:e.callId,sessionId:e.sessionId,mediaFlow:e.mediaFlow,createdBy:e.from,localParticipant:g,metadata:e.metadata,participants:f,chatClient:this.chatClient,isCallSilenced:v});if(C.setVideoCall("true"===(null===(a=e.metadata)||void 0===a?void 0:a.videoCall)),e.callOptions){const i=e.callOptions,t=i.settings;C.setSettings(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==i.callType&&{callType:i.callType}),void 0!==(null==t?void 0:t.startsAt)&&{startsAt:l.default.isLong(t.startsAt)?t.startsAt.toNumber():t.startsAt}),void 0!==(null==t?void 0:t.expiresAt)&&{expiresAt:l.default.isLong(t.expiresAt)?t.expiresAt.toNumber():t.expiresAt}),void 0!==(null==t?void 0:t.persistent)&&{persistent:t.persistent}),void 0!==(null==t?void 0:t.broadcastOptions)&&{broadcastSettings:t.broadcastOptions}),{permissions:{allowPublishAudio:null!==(r=null===(o=null==t?void 0:t.permissions)||void 0===o?void 0:o.allowPublishAudio)&&void 0!==r&&r,allowPublishVideo:null!==(h=null===(p=null==t?void 0:t.permissions)||void 0===p?void 0:p.allowPublishVideo)&&void 0!==h&&h}}))}this.activeCalls.push(C),this.callEvents.onInvitedToCall&&i&&this.callEvents.onInvitedToCall(C),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}addNewParticipantsToCall(e,i){var t;const n=[];return null===(t=i.participants)||void 0===t||t.forEach((i=>{var t,a,l,o;const r=i.id!==this.user.id?e.participants.find((e=>e.id===i.id)):void 0,c=r||new s.Participant(i.id,null==i?void 0:i.clientId);r?i.state!==d.ParticipantState.Joined&&(c.updateState(i.state||d.ParticipantState.Idle,e),c.updateConnectionState(d.ParticipantConnectionState.Idle,e),c.setMediaVideoState({enabled:(null===(a=null===(t=i.mediaState)||void 0===t?void 0:t.video)||void 0===a?void 0:a.enabled)||!1,changedBy:null===(o=null===(l=i.mediaState)||void 0===l?void 0:l.video)||void 0===o?void 0:o.changedBy},i.permissions||{},e)):(c.updateState(i.state||d.ParticipantState.Idle,e),n.push(c),e.addParticipantToList(c))})),n}handleCloseSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));i&&this.closeCall(i)}handleDeclineSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(t)if(this.getParticipantId({id:this.user.id,clientId:this.clientId})===e.from)this.leaveCall(t,!0,"Current user declined the call"),t.setState(d.CallState.Idle,"Current user declined the call");else{let n=null==t?void 0:t.participants.find((i=>i.getFullId()===e.from));n||(n=null==t?void 0:t.participants.find((i=>{var t;return i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&!i.clientId})),n?n.clientId=e.from.split("/")[1]:(n=new s.Participant(e.from),t.addParticipantToList(n),t.emitParticipantsAdded([n]))),n&&n.updateState(d.ParticipantState.Declined,t,(null===(i=null==e?void 0:e.metadata)||void 0===i?void 0:i.reason)||"")}}handleRingingSignal(e){var i,t,n;const a=this.activeCalls.find((i=>i.id===e.callId));if(a){let l=null==a?void 0:a.participants.find((i=>{var t;return i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&(i.clientId===e.from.split("/")[1]||!i.clientId)}));if(!l){let o;l=new s.Participant(e.from),(null===(i=e.participants)||void 0===i?void 0:i.length)&&(o=e.participants[0],l.setMediaAudioState((null===(t=null==o?void 0:o.mediaState)||void 0===t?void 0:t.audio)||{enabled:!1,changedBy:""},o.permissions||{},a),l.setMediaVideoState((null===(n=null==o?void 0:o.mediaState)||void 0===n?void 0:n.video)||{enabled:!1,changedBy:""},o.permissions||{},a)),a.addParticipantToList(l),a.emitParticipantsAdded([l])}l&&l.connectionState!==d.ParticipantConnectionState.Connected&&(l.clientId||(l.clientId=e.from.split("/")[1]),l.updateState(d.ParticipantState.Ringing,a))}}handleSwitchMediaFlowSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(i&&i.localParticipant.state===d.ParticipantState.Joined){i.changeMediaFlow(d.MediaFlow.SFU);const e=new s.Participant(i.id);i.setServerParticipant(e);const t=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[738] [CallId: ${i.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`):e.event!==d.SignalEvent.ERROR||f.error(`[742] [CallId: ${i.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};f.info(`[747] [CallId: ${i.id}] Sending offer to server participant: ${e.getFullId()}`),this.sendOfferPeerToPeer(i,e,t),i.participants.forEach((e=>{e.setShouldResetPeerConnection(!0)}))}else i&&i.changeMediaFlow(d.MediaFlow.SFU)}handleIceSignal(e){var i;if(!e.callId||!e.ice)return void f.warn(`[756] [CallId: ${e.callId}] Invalid ICE signal: missing callId or ice data`);const t=this.activeCalls.find((i=>i.id===e.callId));if(!t)return void f.warn(`[763] [CallId: ${e.callId}] ICE candidate received for unknown call: ${e.callId}`);const n=t.participants.find((i=>i.getFullId()===e.from));if(n)try{if(!this.callParticipantsRTCMap[t.id])return void f.error(`[774] [CallId: ${t.id}] No RTC map found for call ${t.id}`);null===(i=this.callParticipantsRTCMap[t.id][n.getFullId()])||void 0===i||i.addIceCandidate(e.ice,n.getFullId())}catch(e){f.error(`[787] [CallId: ${t.id}] Failed to add ICE candidate for participant ${n.getFullId()} in call ${t.id}: ${e instanceof Error?e.message:JSON.stringify(e)}`)}else f.warn(`[768] [CallId: ${e.callId}] ICE candidate received from unknown participant: ${e.from} in call ${e.callId}`)}handleVideoOnSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(!t)return;const n=t.participants.find((i=>{var t;return i.getFullId()===e.from||i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&!i.clientId}));n&&n.setMediaVideoState({enabled:!0,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},n.permissions||{},t)}handleVideoOffSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(!t)return;const n=t.participants.find((i=>{var t;return i.getFullId()===e.from||i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&!i.clientId}));n&&n.setMediaVideoState({enabled:!1,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},n.permissions||{},t)}handleScreenShareOnSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(t){const n=null==t?void 0:t.participants.find((i=>i.getFullId()===e.from));n&&n.setMediaScreenShareState({enabled:!0,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},t)}}handleScreenShareOffSignal(e){var i,t,n;const a=this.activeCalls.find((i=>i.id===e.callId));if(a){const l=null==a?void 0:a.participants.find((i=>i.getFullId()===e.from));l&&(l.setMediaScreenShareState({enabled:!1,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},a),(null===(n=null===(t=l.mediaState)||void 0===t?void 0:t.video)||void 0===n?void 0:n.enabled)&&l.setMediaVideoState({enabled:!0,changedBy:l.mediaState.video.changedBy},l.permissions||{},a))}}handleMuteSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(!t)return;const n=t.participants.find((i=>i.getFullId()===e.from));n&&n.setMediaAudioState({enabled:!1,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},n.permissions||{},t)}handleUnmuteSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(!t)return;const n=t.participants.find((i=>i.getFullId()===e.from));n&&n.setMediaAudioState({enabled:!0,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},n.permissions||{},t)}handleUpdateCallSettingsSignal(e,i){var t,n,a,l,s,o,r,c,u,p,h,g,v,S,f,C;const I=i||this.activeCalls.find((i=>i.id===e.callId));if(!I)return;const m=null===(n=null===(t=e.callOptions)||void 0===t?void 0:t.settings)||void 0===n?void 0:n.permissions;if(!m)return void I.emitCallPermissionsUpdated({allowPublishAudio:!1,allowPublishVideo:!1});const E=null===(a=I.createdBy)||void 0===a?void 0:a.split("/")[0],P=I.localParticipant.id===E;I.permissions=m,m.allowPublishAudio?(I.participants.forEach((i=>{var t,n;i.permissions&&!i.permissions.canPublishAudio&&i.setMediaAudioState((null===(t=i.mediaState)||void 0===t?void 0:t.audio)||{enabled:!1,changedBy:null===(n=null==e?void 0:e.from)||void 0===n?void 0:n.split("/")[0]},i.permissions,I)})),!1!==(null===(o=I.localParticipant.permissions)||void 0===o?void 0:o.canPublishAudio)||P||I.localParticipant.setMediaAudioState((null===(r=I.localParticipant.mediaState)||void 0===r?void 0:r.audio)||{enabled:!1,changedBy:null===(c=null==e?void 0:e.from)||void 0===c?void 0:c.split("/")[0]},I.localParticipant.permissions,I)):(I.participants.forEach((i=>{var t;i.state===d.ParticipantState.Joined&&i.id!==E&&i.setMediaAudioState({enabled:!1,changedBy:null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0]},(null==i?void 0:i.permissions)||{},I)})),P||I.localParticipant.setMediaAudioState({enabled:!1,changedBy:null===(l=null==e?void 0:e.from)||void 0===l?void 0:l.split("/")[0]},(null===(s=I.localParticipant)||void 0===s?void 0:s.permissions)||{},I)),m.allowPublishVideo?(I.participants.forEach((i=>{var t,n;i.permissions&&!i.permissions.canPublishVideo&&i.setMediaVideoState((null===(t=i.mediaState)||void 0===t?void 0:t.video)||{enabled:!1,changedBy:null===(n=null==e?void 0:e.from)||void 0===n?void 0:n.split("/")[0]},i.permissions||{},I)})),!1!==(null===(S=I.localParticipant.permissions)||void 0===S?void 0:S.canPublishVideo)||P||I.localParticipant.setMediaVideoState((null===(f=I.localParticipant.mediaState)||void 0===f?void 0:f.video)||{enabled:!1,changedBy:null===(C=null==e?void 0:e.from)||void 0===C?void 0:C.split("/")[0]},I.localParticipant.permissions||{},I)):(I.participants.forEach((i=>{var t,n,a,l;i.state===d.ParticipantState.Joined&&i.id!==E&&(i.setMediaVideoState({enabled:!1,changedBy:null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0]},(null==i?void 0:i.permissions)||{},I),(null===(a=null===(n=i.mediaState)||void 0===n?void 0:n.screenShare)||void 0===a?void 0:a.enabled)&&i.setMediaScreenShareState({enabled:!1,changedBy:null===(l=null==e?void 0:e.from)||void 0===l?void 0:l.split("/")[0]},I))})),P||(I.localParticipant.setMediaVideoState({enabled:!1,changedBy:null===(u=null==e?void 0:e.from)||void 0===u?void 0:u.split("/")[0]},(null===(p=I.localParticipant)||void 0===p?void 0:p.permissions)||{},I),I.videoEnabled=!1,(null===(g=null===(h=I.localParticipant.mediaState)||void 0===h?void 0:h.screenShare)||void 0===g?void 0:g.enabled)&&(I.localParticipant.setMediaScreenShareState({enabled:!1,changedBy:null===(v=null==e?void 0:e.from)||void 0===v?void 0:v.split("/")[0]}),this.forceStopLocalScreenShare(I)))),I.emitCallPermissionsUpdated(m)}handleCallPermissionsUpdateSignal(e){this.handleUpdateCallSettingsSignal(e)}handleDisableRemoteAudioSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(!i)return;const t=e.to===C?i.participants.filter((e=>{var t;return e.state===d.ParticipantState.Joined&&e.id!==(null===(t=i.createdBy)||void 0===t?void 0:t.split("/")[0])})):i.participants.filter((i=>{var t;return i.id===(null===(t=e.to)||void 0===t?void 0:t.split("/")[0])&&i.state===d.ParticipantState.Joined}));t.forEach((t=>{var n,a,l;t.setMediaAudioState({enabled:!1,changedBy:null===(n=null==e?void 0:e.from)||void 0===n?void 0:n.split("/")[0]},{canPublishAudio:null!==(l=null===(a=t.permissions)||void 0===a?void 0:a.canPublishAudio)&&void 0!==l&&l},i)})),t.some((e=>{var t;return e.id===(null===(t=i.localParticipant)||void 0===t?void 0:t.id)}))&&(i.muted=!0)}handleDisableRemoteVideoSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(!i)return;const t=e.to===C?i.participants.filter((e=>{var t;return e.state===d.ParticipantState.Joined&&e.id!==(null===(t=i.createdBy)||void 0===t?void 0:t.split("/")[0])})):i.participants.filter((i=>{var t;return i.id===(null===(t=e.to)||void 0===t?void 0:t.split("/")[0])&&i.state===d.ParticipantState.Joined}));t.forEach((t=>{var n,a,l,s,o,r;const d=t.id===(null===(n=i.localParticipant)||void 0===n?void 0:n.id)&&(null===(l=null===(a=t.mediaState)||void 0===a?void 0:a.screenShare)||void 0===l?void 0:l.enabled);t.setMediaVideoState({enabled:!1,changedBy:null===(s=null==e?void 0:e.from)||void 0===s?void 0:s.split("/")[0]},{canPublishVideo:null!==(r=null===(o=t.permissions)||void 0===o?void 0:o.canPublishVideo)&&void 0!==r&&r},i),d&&this.forceStopLocalScreenShare(i)})),t.some((e=>{var t;return e.id===(null===(t=i.localParticipant)||void 0===t?void 0:t.id)}))&&(i.videoEnabled=!1)}handleParticipantPermissionsUpdateSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(!i)return;const t=i.participants.filter((i=>{var t;return(null===(t=e.participants)||void 0===t?void 0:t.some((e=>e.id===i.id)))&&i.state===d.ParticipantState.Joined})),n=t.some((e=>{var t,n,a;return e.id===(null===(t=i.localParticipant)||void 0===t?void 0:t.id)&&(null===(a=null===(n=e.mediaState)||void 0===n?void 0:n.screenShare)||void 0===a?void 0:a.enabled)}));t.forEach((t=>{var n,a,l,s,o,r,d,c,u,p,h,g,v,S,f,C;const I=null!==(a=null===(n=e.participants)||void 0===n?void 0:n.find((e=>e.id===t.id)))&&void 0!==a?a:null===(l=e.participants)||void 0===l?void 0:l[0];if(!(null==I?void 0:I.permissions))return;const m=I.permissions.canPublishAudio,E=I.permissions.canPublishVideo;!1===m?t.setMediaAudioState({enabled:!1,changedBy:null===(s=null==e?void 0:e.from)||void 0===s?void 0:s.split("/")[0]},{canPublishAudio:!1},i):!0===m&&(t.permissions?t.setMediaAudioState((null===(d=t.mediaState)||void 0===d?void 0:d.audio)||{enabled:!1,changedBy:null===(c=null==e?void 0:e.from)||void 0===c?void 0:c.split("/")[0]},Object.assign(Object.assign({},t.permissions),{canPublishAudio:!0}),i):t.setMediaAudioState((null===(o=t.mediaState)||void 0===o?void 0:o.audio)||{enabled:!1,changedBy:null===(r=null==e?void 0:e.from)||void 0===r?void 0:r.split("/")[0]},{canPublishAudio:!0,canPublishVideo:!0},i)),!1===E?(t.setMediaVideoState({enabled:!1,changedBy:null===(u=null==e?void 0:e.from)||void 0===u?void 0:u.split("/")[0]},{canPublishVideo:!1},i),(null===(h=null===(p=t.mediaState)||void 0===p?void 0:p.screenShare)||void 0===h?void 0:h.enabled)&&t.setMediaScreenShareState({enabled:!1,changedBy:null===(g=null==e?void 0:e.from)||void 0===g?void 0:g.split("/")[0]},i)):!0===E&&(t.permissions?t.setMediaVideoState((null===(f=t.mediaState)||void 0===f?void 0:f.video)||{enabled:!1,changedBy:null===(C=null==e?void 0:e.from)||void 0===C?void 0:C.split("/")[0]},Object.assign(Object.assign({},t.permissions),{canPublishVideo:!0}),i):t.setMediaVideoState((null===(v=t.mediaState)||void 0===v?void 0:v.video)||{enabled:!1,changedBy:null===(S=null==e?void 0:e.from)||void 0===S?void 0:S.split("/")[0]},{canPublishAudio:!0,canPublishVideo:!0},i)),i.emitParticipantPermissionsUpdated(t,t.permissions||{canPublishAudio:!1,canPublishVideo:!1})})),n&&this.forceStopLocalScreenShare(i)}handleHoldSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(i){const t=null==i?void 0:i.participants.find((i=>i.getFullId()===e.from));t&&t.setHold(!0,i)}}handleUnholdSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(i){const t=null==i?void 0:i.participants.find((i=>i.getFullId()===e.from));t&&t.setHold(!1,i)}}handleKickSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(i){const t=e.participants;if(t&&t.length)for(let e=0;e<t.length;e++){const n=t[e],a=null==i?void 0:i.participants.find((e=>e.getFullId()===this.getParticipantId(n)));a&&(a.updateState(d.ParticipantState.Kicked,i),a.getFullId()===i.localParticipant.getFullId()&&this.leaveCall(i,!1,"kickedParticipant",d.ParticipantState.Kicked))}}}handleUpdateSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));t&&e.metadata&&(t.metadata=e.metadata,t.setVideoCall("true"===(null===(i=e.metadata)||void 0===i?void 0:i.videoCall)))}handleNoAnswerSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));t&&(null===(i=e.participants)||void 0===i||i.forEach((e=>{(null==t?void 0:t.participants.filter((i=>i.id===e.id&&(i.clientId===e.clientId||!e.clientId)))).forEach((e=>{e.updateState(d.ParticipantState.NoAnswer,t)}))})))}static getInstance(){if(!I.instance)throw new Error("InternalCallHandler has not been initialized. Call new InternalCallHandler(chatClient) first.");return I.instance}setRTCConfig(e){this.rtcConfig=e}onIceCandidateListener(e,i){return t=>{this.onIceCandidate(e,t,i)}}onSignalingStateChangeListener(e,i){return t=>{var n;const a=(null===(n=null==t?void 0:t.currentTarget)||void 0===n?void 0:n.signalingState)||"unknown";f.info(`[1067] [CallId: ${i.id}] Signaling state change: ${a}, participantID: ${e.getFullId()}`,{color:"blue"})}}isPolitePeer(e,i){return i>e}onIceConnectionStateChangeListener(e,i){return t=>{var n;const a=(null===(n=null==t?void 0:t.currentTarget)||void 0===n?void 0:n.iceConnectionState)||"unknown";f.info(`[1078] [CallId: ${i.id}] ICE connection state change: ${a}, participantID: ${e.getFullId()}`,{color:"blue"})}}onConnectionStateChangeListener(e,i){return t=>{var n,a,l,s,o;const r=t.currentTarget.connectionState;f.info(`[1078] [CallId: ${i.id}] PC connection state changed: ${r}, participantID: ${e.getFullId()}`,{color:"disconnected"===r?"orange":"failed"===r?"red":"blue"});const c=this.activeCalls.find((e=>e.id===i.id))||i,u=(null==c?void 0:c.participants.find((i=>i.getFullId()===e.getFullId())))||e.id===(null===(n=null==c?void 0:c.serverParticipant)||void 0===n?void 0:n.id)&&e;if(!u)return;let p=0,h=null;const v=(t,n)=>{f.info(`[1089] [CallId: ${i.id}] stopRetrying: ${n}, participant: ${e.getFullId()}`,{color:"orange"}),p=0,h&&(clearInterval(h),h=null),t&&clearTimeout(t)},S=(t,n=!1)=>{f.info(`[1089] [CallId: ${i.id}] start renegotiation send ${t} to participant ${u.getFullId()}`,{color:"blue"});const a=a=>{var l;const s=this.activeCalls.find((e=>e.id===i.id))||i,o=s.participants.find((i=>i.getFullId()===e.getFullId()))||e.id===(null===(l=s.serverParticipant)||void 0===l?void 0:l.id)&&e||e,r="Connected"===this.chatClient.connectionState,c=o.connectionState!==d.ParticipantConnectionState.Connected,u=s.state===d.CallState.Connected;if(f.info(`[1190] [CallId: ${i.id}] send() guard check — chatConnected: ${r}, participantConnState: ${o.connectionState} (notConnected: ${c}), callState: ${s.state} (connected: ${u}), participant: ${o.getFullId()}`,{color:"cyan"}),r&&c&&u){const e=this.isPolitePeer(o.getFullId(),s.localParticipant.getFullId()||"");if(f.info(`[1190] [CallId: ${i.id}] send() proceeding — type: ${t}, checkPolitePeer: ${n}, isPolitePeer: ${e}, participant: ${o.getFullId()}`,{color:"blue"}),"offer"!==t||n&&!e)if("connect"!==t||n&&!e)f.warn(`[1190] [CallId: ${i.id}] send() skipped — type: ${t}, checkPolitePeer: ${n}, isPolitePeer: ${e}`,{color:"yellow"});else{f.info(`[1214] [CallId: ${i.id}] ${d.MediaFlow.SFU} sendConnect to participant 1 ${JSON.stringify(o)}`,{color:"blue"});try{this.signalingClient.clearParticipantSignals(s.id,o.getFullId()),this.signalingClient.sendSignalMessage({mediaFlow:s.mediaFlow,callId:s.id,sessionId:s.sessionId,event:d.SignalEvent.CONNECT,to:o.getFullId()},a)}catch(e){f.error(`[1236] [CallId: ${i.id}] Failed to send connect to participant ${o.getFullId()}: message: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}else try{f.info(`[1211] [CallId: ${i.id}] Sending offer to participant: ${o.getFullId()}`),this.sendOfferPeerToPeer(s,o,a)}catch(e){f.error(`[1211] [CallId: ${i.id}] Failed to send offer to participant ${o.getFullId()}: ${e instanceof Error?e.message:JSON.stringify(e)}`)}}else f.warn(`[1190] [CallId: ${i.id}] send() blocked — chatConnected: ${r}, participantNotConnected: ${c}, callConnected: ${u}`,{color:"yellow"})};h&&(clearInterval(h),h=null);let l=null;h=setInterval((()=>{var n,s,o;const r=this.activeCalls.find((e=>e.id===i.id))||i,c=r.participants.find((i=>i.getFullId()===e.getFullId()))||e.id===(null===(n=r.serverParticipant)||void 0===n?void 0:n.id)&&e||e,u=null===(o=null===(s=this.callParticipantsRTCMap[i.id])||void 0===s?void 0:s[c.getFullId()])||void 0===o?void 0:o.peerConnection;return f.info(`[1182] [CallId: ${i.id}] interval tick — retry: ${p+1}, type: ${t}, participant: ${c.getFullId()}, participantConnState: ${c.connectionState}, participantState: ${c.state}, callState: ${null==r?void 0:r.state}, signalingState: ${null==u?void 0:u.signalingState}`,{color:"green"}),r&&r.state===d.CallState.Connected?c.connectionState===d.ParticipantConnectionState.Connected&&"stable"===(null==u?void 0:u.signalingState)?(v(l,`participant already connected and signaling stable (connState: ${c.connectionState}, signalingState: ${null==u?void 0:u.signalingState})`),void(l=null)):c.state!==d.ParticipantState.Joined&&c.id!==r.id?(v(l,`participant not joined (state: ${c.state})`),void(l=null)):(p+=1,p>=10?(f.warn(`[1182] [CallId: ${i.id}] Max retries reached for ${t} to ${c.getFullId()}, giving up`,{color:"red"}),c.updateConnectionState(d.ParticipantConnectionState.Disconnected,i),v(l,"max retries reached"),void(l=null)):void a((e=>{var n;return e instanceof g.SceytCallException||e instanceof Error?(f.error(`[1202] [CallId: ${i.id}] SYNC ${t} failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}),void("NotAllowed"===e.name&&(c.updateConnectionState(d.ParticipantConnectionState.Disconnected,i),v(l,"signal NotAllowed error"),l=null))):e.event===d.SignalEvent.ERROR?(f.error(`[1205] [CallId: ${i.id}] SYNC ${t} failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"}),void(4002===(null===(n=e.error)||void 0===n?void 0:n.code)&&(c.updateConnectionState(d.ParticipantConnectionState.Disconnected,i),v(l,"signal error code 4002"),l=null))):void 0}))):(v(l,`call not connected (state: ${null==r?void 0:r.state})`),void(l=null))}),4e3),l=setTimeout((()=>{l=null,f.info(`[1089] [CallId: ${i.id}] initial 2s attempt firing, type: ${t}, participant: ${u.getFullId()}`,{color:"blue"}),a((e=>{var t;return e instanceof g.SceytCallException||e instanceof Error?(f.error(`[1202] [CallId: ${i.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}),void(("NotAllowed"===e.name||e instanceof g.SceytCallException&&4002===e.code)&&u.updateConnectionState(d.ParticipantConnectionState.Disconnected,i))):e.event===d.SignalEvent.ERROR?(f.error(`[1205] [CallId: ${i.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"}),void(4002===(null===(t=e.error)||void 0===t?void 0:t.code)&&u.updateConnectionState(d.ParticipantConnectionState.Disconnected,i))):void 0}))}),2e3)},C=()=>{var t;h||u&&c&&(c.mediaFlow===d.MediaFlow.SFU&&e.id===(null===(t=null==c?void 0:c.serverParticipant)||void 0===t?void 0:t.id)&&this.callParticipantsRTCMap[c.id]&&this.callParticipantsRTCMap[c.id][e.getFullId()]&&c.localParticipant.state===d.ParticipantState.Joined?(f.info(`[1258] [CallId: ${i.id}] start renegotiation ${d.MediaFlow.SFU} sendOffer to participant ${u.getFullId()}`,{color:"blue"}),S("offer",!1)):c.mediaFlow===d.MediaFlow.SFU&&this.callParticipantsRTCMap[c.id]&&this.callParticipantsRTCMap[c.id][e.getFullId()]&&c.localParticipant.state===d.ParticipantState.Joined&&S("connect",!1),c.mediaFlow===d.MediaFlow.S2W&&u.state===d.ParticipantState.Joined&&this.callParticipantsRTCMap[c.id]&&this.callParticipantsRTCMap[c.id][u.getFullId()]&&c.localParticipant.state===d.ParticipantState.Joined&&(f.info(`[1263] [CallId: ${i.id}] start renegotiation ${d.MediaFlow.SFU} sendConnect to participant ${u.getFullId()}`,{color:"blue"}),S("offer",!1)))};switch(r){case"new":break;case"connecting":i.mediaFlow===d.MediaFlow.SFU&&u.id===(null===(a=null==c?void 0:c.serverParticipant)||void 0===a?void 0:a.id)&&c.localParticipant.updateConnectionState(d.ParticipantConnectionState.Connecting,i),u.updateConnectionState(d.ParticipantConnectionState.Connecting,i);break;case"connected":if(i.mediaFlow===d.MediaFlow.SFU&&u.id===(null===(l=null==c?void 0:c.serverParticipant)||void 0===l?void 0:l.id)&&c.localParticipant.updateConnectionState(d.ParticipantConnectionState.Connected,i),u.updateConnectionState(d.ParticipantConnectionState.Connected,i),u&&c&&"Connected"===this.chatClient.connectionState&&(c.mediaFlow!==d.MediaFlow.SFU||c.mediaFlow===d.MediaFlow.SFU&&u.id===(null==c?void 0:c.id))){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[1098] [CallId: ${c.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[1102] [CallId: ${c.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage(Object.assign({mediaFlow:c.mediaFlow,callId:c.id,sessionId:c.sessionId,event:d.SignalEvent.MEDIA_CONNECTED},c.mediaFlow!==d.MediaFlow.SFU?{to:c.id}:{}),e)}break;case"disconnected":i.mediaFlow===d.MediaFlow.SFU&&u.id===(null===(s=null==c?void 0:c.serverParticipant)||void 0===s?void 0:s.id)&&c.localParticipant.updateConnectionState(d.ParticipantConnectionState.Reconnecting,i),u.updateConnectionState(d.ParticipantConnectionState.Reconnecting,i),i.mediaFlow!==d.MediaFlow.S2W&&C();break;case"failed":u&&c&&(c.mediaFlow===d.MediaFlow.P2P&&u.state===d.ParticipantState.Joined&&this.callParticipantsRTCMap[c.id]&&this.callParticipantsRTCMap[c.id][u.getFullId()]&&c.localParticipant.state===d.ParticipantState.Joined?(f.info(`[1268] [CallId: ${i.id}] start renegotiation ${c.mediaFlow} sendOffer to participant ${u.getFullId()}`,{color:"blue"}),S("offer",!0)):C());break;case"closed":i.mediaFlow===d.MediaFlow.SFU&&u.id===(null===(o=null==c?void 0:c.serverParticipant)||void 0===o?void 0:o.id)&&c.localParticipant.updateConnectionState(d.ParticipantConnectionState.Idle,i),u.updateConnectionState(d.ParticipantConnectionState.Idle,i)}}}onIceCandidateErrorListener(e,i){return t=>{f.error(`[1284] [CallId: ${i.id}] ICE candidate error participantID: ${e.getFullId()}, error - code: ${t.errorCode}, message: ${t.errorText}, url: ${t.url}`,{color:"red"})}}onTrackListener(e,i){return t=>{this.onTrack(i,e,t)}}closePeerConnections(e,i){if(!this.callParticipantsRTCMap[e])return;const t=this.callParticipantsRTCMap[e][i];t?(t.listeners?(Object.keys(t.listeners).forEach((e=>{t.removeEventListener(e,t.listeners[e])})),f.info(`[1313] [CallId: ${e}] Removed all listeners for WebRTCClient of participant ${i}`,{color:"cyan"})):f.info(`[1316] [CallId: ${e}] No listeners found for WebRTCClient of participant ${i}`,{color:"cyan"}),t.close(),t.peerConnection.onicecandidate=null,t.peerConnection.ontrack=null,t.peerConnection.onconnectionstatechange=null,t.peerConnection.oniceconnectionstatechange=null,t.peerConnection.onsignalingstatechange=null,this.callParticipantsRTCMap[e][i]=null,delete this.callParticipantsRTCMap[e][i]):f.info(`[1375] [CallId: ${e}] No WebRTCClient found for participant ${i}`,{color:"cyan"})}addParticipantToRTCMap(e,i){this.callParticipantsRTCMap.hasOwnProperty(e.id)||(this.callParticipantsRTCMap[e.id]={});const t=new o.WebRTCClient(e.id,this.rtcConfig);this.callParticipantsRTCMap[e.id][i.getFullId()]=t;const n=this.onIceCandidateListener(i,e),a=this.onSignalingStateChangeListener(i,e),l=this.onIceConnectionStateChangeListener(i,e),s=this.onConnectionStateChangeListener(i,e),r=this.onTrackListener(i,e),d=this.onIceCandidateErrorListener(i,e);return t.addEventListener("icecandidate",n),t.addEventListener("signalingstatechange",a),t.addEventListener("connectionstatechange",s),t.addEventListener("track",r),t.addEventListener("icecandidateerror",d),t.addEventListener("iceconnectionstatechange",l),t.setListeners({icecandidate:n,signalingstatechange:a,connectionstatechange:s,track:r,icecandidateerror:d,iceconnectionstatechange:l}),f.info(`[1371] [CallId: ${e.id}] Added Event Listeners to RTC Map: participantID: ${i.getFullId()}`,{color:"blue"}),e.activeSpeakerManager.addParticipant(i),i}joinToCall(e,i){return this.signalingClient.sendSignalMessage(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({mediaFlow:e.mediaFlow,callId:e.callId},e.sessionId&&{sessionId:e.sessionId}),{event:d.SignalEvent.JOIN,participants:e.participants}),(null==e?void 0:e.metadata)&&{metadata:e.metadata}),e.callOptions&&{callOptions:e.callOptions}),{joinOptions:e.joinOptions}),i)}sendRinging(e,i){return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:d.SignalEvent.RINGING},(t=>t instanceof g.SceytCallException||t instanceof Error?(f.error(`[1389] [CallId: ${e.id}] SYNC RINGING failed message: ${t.message} code: ${t instanceof g.SceytCallException?t.code:""}`,{color:"red"}),void(null==i||i({error:(0,S.toCallException)(t)}))):t.event===d.SignalEvent.ERROR?(f.error(`[1393] [CallId: ${e.id}] SYNC RINGING failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"}),void(null==i||i({error:(0,S.toCallException)(new Error("Failed to send ringing signal"))}))):void e.localParticipant.updateState(d.ParticipantState.Ringing,e))),{success:!0}}rejectCall(e,i,t){try{const n=this.activeCalls.find((i=>i.id===e.id));n&&(n.setState(d.CallState.Idle,"rejectCall"),n.localParticipant.updateState(d.ParticipantState.Declined,e),n.localParticipant.updateConnectionState(d.ParticipantConnectionState.Idle,e),this.closeTracksAndPeerConnections(n));const a=i=>i instanceof g.SceytCallException||i instanceof Error?(f.error(`[1420] [CallId: ${e.id}] SYNC DECLINE failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`,{color:"red"}),void(null==t||t({error:(0,S.toCallException)(i)}))):i.event===d.SignalEvent.ERROR?(f.error(`[1424] [CallId: ${e.id}] SYNC DECLINE failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"}),void(null==t||t({error:(0,S.toCallException)(i.error||new Error("Failed to send decline signal"))}))):void 0;return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:d.SignalEvent.DECLINE,metadata:Object.assign(Object.assign({},e.metadata),{reason:i||""})},a),{success:!0}}catch(i){return f.error(`[1432] [CallId: ${e.id}] Failed to reject call: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"}),{success:!1,error:(0,S.toCallException)(i)}}}closeTracksAndPeerConnections(e){e.localAudioTracks.forEach((e=>{e.stop()})),e.localVideoTracks.forEach((e=>{e.stop()})),e.participants.forEach((i=>{i.videoTracks.forEach((e=>{e.stop()})),i.audioTracks.forEach((e=>{e.stop()})),this.closePeerConnections(e.id,i.getFullId()),e.activeSpeakerManager.removeParticipant(i)})),e.localParticipant.videoTracks.forEach((e=>{e.stop()})),e.localParticipant.audioTracks.forEach((e=>{e.stop()})),e.mediaFlow===d.MediaFlow.SFU&&e.serverParticipant&&(e.serverParticipant.videoTracks.forEach((e=>{e.stop()})),e.serverParticipant.audioTracks.forEach((e=>{e.stop()})),this.closePeerConnections(e.id,e.serverParticipant.getFullId()))}closeCall(e){e.setState(d.CallState.Closed,"closeCall"),this.closeTracksAndPeerConnections(e);const i=this.activeCalls.findIndex((i=>i.id===e.id));this.activeCalls.splice(i,1),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls),delete this.callParticipantsRTCMap[e.id],f.info(`[1474] [CallId: ${e.id}] closed call and removed from active calls: callId: ${e.id}`,{color:"light-green"})}leaveCall(e,i=!0,t,n=d.ParticipantState.Left){var a,l,s;const o=this.activeCalls.find((i=>i.id===e.id));if(o){this.signalingClient.cancelJoinIfPossible(e.id),this.signalingClient.clearCallSignals(e.id);const r=o.setState(d.CallState.Idle,`leaveCall: ${t}`);if(i&&r){const i=i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[1487] [CallId: ${e.id}] SYNC LEAVE failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`,{color:"red"}):i.event!==d.SignalEvent.ERROR||f.error(`[1491] [CallId: ${e.id}] SYNC LEAVE failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:d.SignalEvent.LEAVE},i)}this.closeTracksAndPeerConnections(o),delete this.callParticipantsRTCMap[o.id],o.localParticipant.updateState(n,e),o.localParticipant.setMediaScreenShareState({enabled:!1,changedBy:null===(s=null===(l=null===(a=o.localParticipant)||void 0===a?void 0:a.mediaState)||void 0===l?void 0:l.screenShare)||void 0===s?void 0:s.changedBy},o),o.localParticipant.updateConnectionState(d.ParticipantConnectionState.Idle,e),o.participants.forEach((i=>{i.updateConnectionState(d.ParticipantConnectionState.Idle,e)})),e.sessionId||(this.activeCalls=this.activeCalls.filter((e=>e.id!=o.id))),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}}setRemoteDescription(e,i,t){var n;const a=null===(n=this.callParticipantsRTCMap[e])||void 0===n?void 0:n[i];return a?a.setRemoteDescription(t):(f.error(`[setRemoteDescription] [CallId: ${e}] No WebRTCClient found for participant ${i}`,{color:"red"}),Promise.reject(new Error(`No WebRTCClient found for participant ${i} in call ${e}`)))}changeVideoTracks(e,i,t,a){var l;return n(this,void 0,void 0,(function*(){if(f.info(`[1594] [CallId: ${e.id}], mediaFlow: ${e.mediaFlow}, changeVideoTracks ${t}, serverParticipant: ${(null===(l=e.serverParticipant)||void 0===l?void 0:l.id)||"null"}`,{color:"cyan"}),e.mediaFlow!==d.MediaFlow.SFU)for(let n=0;n<e.participants.length;n++){const l=e.participants[n];(l.id!==this.user.id||l.clientId!==this.clientId)&&l.clientId&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][l.getFullId()]&&(yield this.callParticipantsRTCMap[e.id][l.getFullId()].enableVideoOnPeerConnection(t,i,!!a))}else this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][e.id]&&(yield this.callParticipantsRTCMap[e.id][e.id].enableVideoOnPeerConnection(t,i,!!a))}))}changeAudioTracks(e,i,t){return n(this,void 0,void 0,(function*(){e.mediaFlow!==d.MediaFlow.SFU?e.participants.forEach((n=>{(n.id!==this.user.id||n.clientId!==this.clientId)&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][n.getFullId()]&&(f.info(`[1561] [CallId: ${e.id}] Enabling audio on peer connection: ${n.getFullId()}`,{color:"cyan"}),this.callParticipantsRTCMap[e.id][n.getFullId()].enableAudioOnPeerConnection(t,i))})):(f.info(`[1565] [CallId: ${e.id}] Enabling audio on peer connection: ${e.id}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][e.id].enableAudioOnPeerConnection(t,i))}))}sendVideoEnabled(e,i,t){var n,a;if(i&&(!1===(null===(n=e.localParticipant.permissions)||void 0===n?void 0:n.canPublishVideo)||!1===(null===(a=e.permissions)||void 0===a?void 0:a.allowPublishVideo)))return f.warn(`[CallId: ${e.id}] sendVideoEnabled: blocked — video host-disabled or call locked`),void(null==t||t({error:(0,S.toCallException)({message:"Cannot enable video: you have been disabled by the host",code:403})}));if(this.activeCalls.find((i=>i.id===e.id)))try{const n=i=>i instanceof g.SceytCallException||i instanceof Error?(f.error(`[1632] [CallId: ${e.id}] SYNC VIDEO_ON failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`),void(null==t||t({error:(0,S.toCallException)(i)}))):i.event===d.SignalEvent.ERROR?(f.error(`[1636] [CallId: ${e.id}] SYNC VIDEO_ON failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`),void(null==t||t({error:(0,S.toCallException)(i.error||i)}))):void 0;this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:i?d.SignalEvent.VIDEO_ON:d.SignalEvent.VIDEO_OFF,sessionId:e.sessionId},n)}catch(i){return f.error(`[1645] [CallId: ${e.id}] Failed to send video enabled signal: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"}),null==t||t({error:(0,S.toCallException)(i)}),!1}}sendScreenShare(e,i,t){var a,l;return n(this,void 0,void 0,(function*(){const n=this.activeCalls.find((i=>i.id===e.id));try{if(n){if(i){const e=n.localParticipant;if(!1===(null===(a=e.permissions)||void 0===a?void 0:a.canPublishVideo)||!1===(null===(l=n.permissions)||void 0===l?void 0:l.allowPublishVideo))return null==t||t({error:new g.SceytCallException("NOT_ALLOWED Screen share blocked: host-disabled")}),!1}return this.sendSignalScreenShare(e,i,t)}}catch(i){return f.error(`[1668] [CallId: ${e.id}] Failed to send screen share signal: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"}),null==t||t({error:(0,S.toCallException)(i)}),!1}}))}forceStopLocalScreenShare(e){e.screenSharing=!1,e.localVideoTracks.forEach((e=>e.stop())),e.localVideoTracks=[],e.localParticipant.setVideoTracks([],e),this.sendSignalScreenShare(e,!1)}sendAudioEnable(e,i,t){return n(this,void 0,void 0,(function*(){if(this.activeCalls.find((i=>i.id===e.id))){const a=a=>n(this,void 0,void 0,(function*(){try{if(a instanceof g.SceytCallException||a instanceof Error)return f.error(`[1704] [CallId: ${e.id}] SYNC HOLD failed message: ${a.message} code: ${a instanceof g.SceytCallException?a.code:""}`),void(null==t||t({error:(0,S.toCallException)(a)}));if(a.event===d.SignalEvent.ERROR)return f.error(`[1708] [CallId: ${e.id}] SYNC HOLD failed message: ${a.error?`${a.error.message} code: ${a.error.code}`:""}`),void(null==t||t({error:(0,S.toCallException)(a.error)}));if(e.mediaFlow!==d.MediaFlow.SFU)for(let t=0;t<e.participants.length;t++){const n=e.participants[t];(n.id!==this.user.id||n.clientId!==this.clientId)&&n.clientId&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][n.getFullId()]&&(f.info(`[1712] [CallId: ${e.id}] Enabling audio on peer connection: ${n.getFullId()}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][n.getFullId()].enableAudioOnPeerConnection(i))}else this.callParticipantsRTCMap&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][e.serverParticipant.getFullId()]&&(f.info(`[1712] [CallId: ${e.id}] Enabling audio on peer connection: ${e.serverParticipant.getFullId()}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][e.serverParticipant.getFullId()].enableAudioOnPeerConnection(i));e.localParticipant.audioTracks.forEach((e=>{e.enabled=!i}))}catch(i){f.error(`[1725] [CallId: ${e.id}] Failed to enable audio on peer connection: ${i instanceof Error?i.message:JSON.stringify(i)}`),null==t||t({error:(0,S.toCallException)(i)})}}));return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:i?d.SignalEvent.MUTE:d.SignalEvent.UNMUTE,sessionId:e.sessionId},a)}}))}makeErrorCallback(e,i,t){return a=>n(this,void 0,void 0,(function*(){var n;try{if(a instanceof g.SceytCallException||a instanceof Error)return f.error(`[CallId: ${e.id}] ${i} failed: ${a.message}`),void(null==t||t({error:(0,S.toCallException)(a)}));a.event===d.SignalEvent.ERROR&&(f.error(`[CallId: ${e.id}] ${i} error: ${null===(n=a.error)||void 0===n?void 0:n.message}`),null==t||t({error:(0,S.toCallException)(a.error)}))}catch(n){f.error(`[CallId: ${e.id}] ${i} exception: ${n instanceof Error?n.message:JSON.stringify(n)}`),null==t||t({error:(0,S.toCallException)(n)})}}))}muteAllRemoteParticipants(e,i){return e.participants.forEach((i=>{var t;i.state===d.ParticipantState.Joined&&i.id!==(null===(t=e.createdBy)||void 0===t?void 0:t.split("/")[0])&&i.setMediaAudioState({enabled:!1,changedBy:e.localParticipant.id},i.permissions||{},e)})),this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.DISABLE_REMOTE_AUDIO,sessionId:e.sessionId,to:C},this.makeErrorCallback(e,"muteAllRemoteParticipants",i))}muteAllParticipants(e,i){return this.muteAllRemoteParticipants(e,i)}videoOffAllRemoteParticipants(e,i){return e.participants.forEach((i=>{var t,n,a;i.state===d.ParticipantState.Joined&&i.id!==(null===(t=e.createdBy)||void 0===t?void 0:t.split("/")[0])&&i.setMediaVideoState({enabled:!1,changedBy:e.localParticipant.id},{canPublishVideo:null!==(a=null===(n=i.permissions)||void 0===n?void 0:n.canPublishVideo)&&void 0!==a&&a},e)})),this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.DISABLE_REMOTE_VIDEO,sessionId:e.sessionId,to:C},this.makeErrorCallback(e,"videoOffAllRemoteParticipants",i))}muteRemoteParticipant(e,i,t){for(const t of e.participants)t.id===i&&t.state===d.ParticipantState.Joined&&t.setMediaAudioState({enabled:!1,changedBy:e.localParticipant.id},t.permissions||{},e);return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.DISABLE_REMOTE_AUDIO,sessionId:e.sessionId,to:i},this.makeErrorCallback(e,"muteRemoteParticipant",t))}disableRemoteParticipantAudio(e,i,t){var n,a;const l=[];for(const t of e.participants)if(t.id===i&&t.state===d.ParticipantState.Joined){const i={canPublishAudio:!1,canPublishVideo:null!==(a=null===(n=t.permissions)||void 0===n?void 0:n.canPublishVideo)&&void 0!==a&&a};t.setMediaAudioState({enabled:!1,changedBy:e.localParticipant.id},i,e),l.push({id:t.id,clientId:t.clientId,permissions:i})}return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE,sessionId:e.sessionId,to:i,participants:l},this.makeErrorCallback(e,"disableRemoteParticipantAudio",t))}enableRemoteParticipantAudio(e,i,t){var n,a;const l=[];for(const t of e.participants)if(t.id===i&&t.state===d.ParticipantState.Joined){const e={canPublishAudio:!0,canPublishVideo:null===(a=null===(n=t.permissions)||void 0===n?void 0:n.canPublishVideo)||void 0===a||a};t.permissions?t.permissions=Object.assign(Object.assign({},t.permissions),e):t.permissions=e,l.push({id:t.id,clientId:t.clientId,permissions:e})}return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE,sessionId:e.sessionId,to:i,participants:l},this.makeErrorCallback(e,"enableRemoteParticipantAudio",t))}videoOffRemoteParticipant(e,i,t){var n,a;const l=e.participants.find((e=>e.id===i&&e.state===d.ParticipantState.Joined));return l&&l.setMediaVideoState({enabled:!1,changedBy:e.localParticipant.id},{canPublishVideo:null===(a=null===(n=l.permissions)||void 0===n?void 0:n.canPublishVideo)||void 0===a||a},e),this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.DISABLE_REMOTE_VIDEO,sessionId:e.sessionId,to:i},this.makeErrorCallback(e,"videoOffRemoteParticipant",t))}updateCallPermissions(e,i,t){var n,a,l,s,o;const r=this.activeCalls.find((i=>i.id===e.id));if(r){const e=null===(n=r.createdBy)||void 0===n?void 0:n.split("/")[0],t=r.localParticipant.id===e;r.permissions=i,i.allowPublishAudio?(r.participants.forEach((e=>{e.permissions&&!e.permissions.canPublishAudio&&(e.permissions=Object.assign(Object.assign({},e.permissions),{canPublishAudio:!0}))})),!1!==(null===(a=r.localParticipant.permissions)||void 0===a?void 0:a.canPublishAudio)||t||(r.localParticipant.permissions=Object.assign(Object.assign({},r.localParticipant.permissions),{canPublishAudio:!0}))):(r.participants.forEach((i=>{i.state===d.ParticipantState.Joined&&i.id!==e&&i.setMediaAudioState({enabled:!1,changedBy:e},{canPublishAudio:!1},r)})),t||(r.localParticipant.setMediaAudioState({enabled:!1,changedBy:e},{canPublishAudio:!1},r),r.muted=!0)),i.allowPublishVideo?(r.participants.forEach((e=>{e.permissions&&!e.permissions.canPublishVideo&&(e.permissions=Object.assign(Object.assign({},e.permissions),{canPublishVideo:!0}))})),!1!==(null===(o=r.localParticipant.permissions)||void 0===o?void 0:o.canPublishVideo)||t||(r.localParticipant.permissions=Object.assign(Object.assign({},r.localParticipant.permissions),{canPublishVideo:!0}))):(r.participants.forEach((i=>{var t,n;i.state===d.ParticipantState.Joined&&i.id!==e&&(i.setMediaVideoState({enabled:!1,changedBy:e},{canPublishVideo:!1},r),(null===(n=null===(t=i.mediaState)||void 0===t?void 0:t.screenShare)||void 0===n?void 0:n.enabled)&&i.setMediaScreenShareState({enabled:!1,changedBy:e},r))})),t||(r.localParticipant.setMediaVideoState({enabled:!1,changedBy:e},{canPublishVideo:!1},r),r.videoEnabled=!1,(null===(s=null===(l=r.localParticipant.mediaState)||void 0===l?void 0:l.screenShare)||void 0===s?void 0:s.enabled)&&(r.localParticipant.setMediaScreenShareState({enabled:!1,changedBy:e}),this.forceStopLocalScreenShare(r)))),r.emitCallPermissionsUpdated(i)}return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.CALL_PERMISSIONS_UPDATE,sessionId:e.sessionId,callOptions:{settings:{permissions:i}}},this.makeErrorCallback(e,"updateCallPermissions",t))}updateParticipantPermissions(e,i,t,n){var a,l;for(const n of e.participants)n.id===i&&(t.canPublishAudio?n.permissions&&(n.permissions=Object.assign(Object.assign({},n.permissions),{canPublishAudio:!0})):n.setMediaAudioState({enabled:!1,changedBy:e.localParticipant.id},Object.assign({},t),e),t.canPublishVideo?n.permissions&&(n.permissions=Object.assign(Object.assign({},n.permissions),{canPublishVideo:!0})):(n.setMediaVideoState({enabled:!1,changedBy:e.localParticipant.id},Object.assign({},t),e),(null===(l=null===(a=n.mediaState)||void 0===a?void 0:a.screenShare)||void 0===l?void 0:l.enabled)&&n.setMediaScreenShareState({enabled:!1,changedBy:e.localParticipant.id},e)));return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE,sessionId:e.sessionId,to:i,participants:[{id:i,clientId:"",permissions:t}]},this.makeErrorCallback(e,"updateParticipantPermissions",n))}sendHold(e,i,t){if(this.activeCalls.find((i=>i.id===e.id))){const t=i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[1741] [CallId: ${e.id}] SYNC HOLD failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`):i.event!==d.SignalEvent.ERROR||f.error(`[1745] [CallId: ${e.id}] SYNC HOLD failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`)};return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:i?d.SignalEvent.HOLD:d.SignalEvent.UNHOLD,sessionId:e.sessionId},t)}}addTracksToPeerConnection(e,i,t=!0){var a,l;return n(this,void 0,void 0,(function*(){let n=e.localVideoTracks;console.log(n,"localVideoTracks, localVideoTracks");const s=e.localAudioTracks,o=this.callParticipantsRTCMap[e.id][i];try{t?yield o.addTransceiverToPeerConnection(s[0],e.mediaFlow):yield o.setStreamsToTransceiver(s[0])}catch(i){f.warn(`[1766] [CallId: ${e.id}] Failed to add track to peer connection: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"})}n&&n.length>0||(f.info(`[1960] [CallId: ${e.id}] getting empty video track:`),n=(0,u.getEmptyVideoTrack)());try{t?yield o.addTransceiverToPeerConnection(n[0],e.mediaFlow):yield o.setStreamsToTransceiver(n[0])}catch(i){f.warn(`[1775] [CallId: ${e.id}] Failed to add track to peer connection: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"})}e.videoEnabled&&(yield o.enableVideoOnPeerConnection(e.videoEnabled,null===(a=e.localVideoTracks)||void 0===a?void 0:a[0])),e.muted||(yield o.enableAudioOnPeerConnection(e.muted,null===(l=e.localAudioTracks)||void 0===l?void 0:l[0]))}))}switchCallToSfu(e,i){try{const t=t=>{if(t instanceof g.SceytCallException||t instanceof Error)return f.error(`[1785] [CallId: ${e.id}] SYNC SWITCH_MEDIA_FLOW signal sent failed message: ${t.message} code: ${t instanceof g.SceytCallException?t.code:""}`),void(null==i||i({error:(0,S.toCallException)(t)}));if(t.event===d.SignalEvent.ERROR)return f.error(`[1789] [CallId: ${e.id}] SYNC SWITCH_MEDIA_FLOW signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`),void(null==i||i({error:(0,S.toCallException)(t)}));const n=new s.Participant(e.id);return e.setServerParticipant(n),e.participants.forEach((i=>{i.id===this.user.id&&i.clientId===this.clientId||i.updateConnectionState(d.ParticipantConnectionState.Idle,e),i.setShouldResetPeerConnection(!0)})),e.changeMediaFlow(d.MediaFlow.SFU),f.info(`[1818] [CallId: ${e.id}] Sending offer to server participant: ${n.getFullId()}`),this.sendOfferPeerToPeer(e,n,(i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[1805] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`):i.event!==d.SignalEvent.ERROR||f.error(`[1809] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`)})),!0};return this.signalingClient.sendSignalMessage({mediaFlow:d.MediaFlow.SFU,callId:e.id,event:d.SignalEvent.SWITCH_MEDIA_FLOW,sessionId:e.sessionId},t),f.info(`[1823] [CallId: ${e.id}] Switched call ${e.id} to SFU`,{color:"light-green"}),{success:!0}}catch(i){return f.error(`[1827] [CallId: ${e.id}] Failed to switch ${d.MediaFlow.SFU} message: ${i instanceof Error?i.message:JSON.stringify(i)}`),{success:!1,error:(0,S.toCallException)(i)}}}getCallById(e,i){return this.signalingClient.sendSignalMessage({callId:e,sessionId:i,event:d.SignalEvent.GET_CALL},(i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[1833] [CallId: ${e}] SYNC GET_CALL signal sent failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`):i.event!==d.SignalEvent.ERROR||f.error(`[1837] [CallId: ${e}] SYNC GET_CALL signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`)}),e)}getCalls(){return this.signalingClient.sendSignalMessage({callId:"",event:d.SignalEvent.GET_CALL},(e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[1849] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`):e.event!==d.SignalEvent.ERROR?this.syncActiveCalls(e):f.error("[1853] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: "+(e.error?`${e.error.message} code: ${e.error.code}`:""))}),"get_call")}createParticipants(e){let i=null,t=!1;return{participants:null==e?void 0:e.map((e=>{var n,a,l,o,r,c,u,p,h,g,v,S;const f=new s.Participant(e.id,e.clientId);return f.setMediaAudioState({enabled:!!(null===(a=null===(n=null==e?void 0:e.mediaState)||void 0===n?void 0:n.audio)||void 0===a?void 0:a.enabled),changedBy:null===(o=null===(l=null==e?void 0:e.mediaState)||void 0===l?void 0:l.audio)||void 0===o?void 0:o.changedBy},(null==e?void 0:e.permissions)||{canPublishAudio:!1,canPublishVideo:!1}),f.setMediaVideoState({enabled:!!(null===(c=null===(r=null==e?void 0:e.mediaState)||void 0===r?void 0:r.video)||void 0===c?void 0:c.enabled),changedBy:null===(p=null===(u=null==e?void 0:e.mediaState)||void 0===u?void 0:u.video)||void 0===p?void 0:p.changedBy},(null==e?void 0:e.permissions)||{canPublishAudio:!1,canPublishVideo:!1}),f.setMediaScreenShareState({enabled:!!(null===(g=null===(h=null==e?void 0:e.mediaState)||void 0===h?void 0:h.screenShare)||void 0===g?void 0:g.enabled),changedBy:null===(S=null===(v=null==e?void 0:e.mediaState)||void 0===v?void 0:v.screenShare)||void 0===S?void 0:S.changedBy}),f.setHold(!!(null==e?void 0:e.onHold)),(null==e?void 0:e.connectionState)&&(null==e?void 0:e.connectionState)>d.ParticipantConnectionState.Connected&&(null==e?void 0:e.id)!==this.user.id&&(null==e?void 0:e.clientId)!==this.clientId&&(f.connectionState=(null==e?void 0:e.connectionState)||d.ParticipantConnectionState.Idle),f.state=(null==e?void 0:e.state)||0,t=(null==e?void 0:e.isCallSilenced)||!1,(null==f?void 0:f.id)===this.user.id&&(null==f?void 0:f.clientId)===this.clientId&&(i=f),f})),localParticipant:i,isCallSilenced:t}}findOrCreateCall(e,i){var t;let n=new s.Participant(this.user.id,this.clientId),a=[],l=!1;if(i){const e=this.createParticipants(i);a=e.participants,l=e.isCallSilenced,e.localParticipant&&(n=e.localParticipant)}else a=null!==(t=e.participants)&&void 0!==t?t:[];let o=this.activeCalls.find((i=>i.id===e.id));return o?this.applyOptionsToExistingCall(o,e,i,a):o=this.initializeNewCall(e,n,a,l),{call:o}}initializeNewCall(e,i,t,n){var a,l,s,o,r;const d=e.id||(0,h.v4)();f.info(`[1869] [CallId: ${d}] Creating new call`,{color:"cyan"});const p=(0,u.makeFirstById)([...t,i],this.user.id,this.clientId),g=new c.Call({id:d,sessionId:e.sessionId,mediaFlow:e.mediaFlow,localParticipant:i,participants:p,metadata:e.metadata,createdBy:e.createdBy,chatClient:this.chatClient,isCallSilenced:n});return e.metadata&&g.setVideoCall("true"===e.metadata.videoCall),e.callOptions&&g.setSettings(this.callOptionsToSettings(e.callOptions)),g.localAudioTracks=e.localAudioTracks||[],g.localVideoTracks=e.localVideoTracks||[],g.localParticipant.setAudioTracks(e.localAudioTracks||[],g),g.localParticipant.setVideoTracks(e.localVideoTracks||[],g),null!=(null===(a=e.audioSettings)||void 0===a?void 0:a.preferredAudioRoute)&&g.setAudioDeviceId(e.audioSettings.preferredAudioRoute),g.localParticipant.setMediaAudioState({enabled:!!(null===(l=e.audioSettings)||void 0===l?void 0:l.publishAudio)},g.localParticipant.permissions||{},g),g.setVideoEnabled(!!(null===(s=e.videoSettings)||void 0===s?void 0:s.publishVideo)),g.localParticipantVideoEnable(!!(null===(o=e.videoSettings)||void 0===o?void 0:o.publishVideo),void 0,!1,!1),g.localParticipant.setMediaVideoState({enabled:!!(null===(r=e.videoSettings)||void 0===r?void 0:r.publishVideo),changedBy:""},g.localParticipant.permissions||{},g),this.activeCalls.push(g),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls),g}applyOptionsToExistingCall(e,i,t,n){var a,l;if(f.info(`[1911] [CallId: ${e.id}] Using existing call`,{color:"cyan"}),void 0!==i.mediaFlow&&e.changeMediaFlow(i.mediaFlow),i.sessionId&&e.setSessionId(i.sessionId),i.createdBy&&e.setCreatedBy(i.createdBy),i.callOptions&&e.setSettings(this.callOptionsToSettings(i.callOptions)),i.metadata&&(e.metadata=i.metadata,e.setVideoCall("true"===i.metadata.videoCall)),i.participants&&!t){const t=new Set(e.participants.map((e=>e.id))),n=i.participants.filter((({id:e})=>!t.has(e)&&e!==this.user.id)).map((({id:e})=>new s.Participant(e)));n.length>0&&(e.participants=(0,u.makeFirstById)([...e.participants,...n],this.user.id,this.clientId),e.emitParticipantsAdded(n))}else e.participants=n;e.participants.some((e=>e.id===this.user.id&&e.clientId===this.clientId))||e.localParticipant.id!==this.user.id||e.localParticipant.clientId!==this.clientId||(e.participants=(0,u.makeFirstById)([...e.participants,e.localParticipant],this.user.id,this.clientId),e.emitParticipantsAdded([e.localParticipant])),(null===(a=i.localAudioTracks)||void 0===a?void 0:a.length)&&(e.localAudioTracks=i.localAudioTracks,e.localParticipant.setAudioTracks(i.localAudioTracks,e)),(null===(l=i.localVideoTracks)||void 0===l?void 0:l.length)&&(e.localVideoTracks=i.localVideoTracks,e.localParticipant.setVideoTracks(i.localVideoTracks,e)),i.audioSettings&&(null!=i.audioSettings.preferredAudioRoute&&e.setAudioDeviceId(i.audioSettings.preferredAudioRoute),e.setMuted(!i.audioSettings.publishAudio),e.localParticipant.setMediaAudioState({enabled:!!i.audioSettings.publishAudio,changedBy:""},e.localParticipant.permissions||{},e)),i.videoSettings&&(e.setVideoEnabled(!!i.videoSettings.publishVideo),e.localParticipantVideoEnable(!!i.videoSettings.publishVideo,void 0,!1,!1),e.localParticipant.setMediaVideoState({enabled:!!i.videoSettings.publishVideo,changedBy:""},e.localParticipant.permissions||{},e))}processJoinAcknowledgment(e,i,t){var n,a,l,s;if(i.event===d.SignalEvent.ERROR)throw f.error(`[1955] [CallId: ${e.id}] Join failed: message: ${null===(n=i.error)||void 0===n?void 0:n.message} code: ${null===(a=i.error)||void 0===a?void 0:a.code}`),this.leaveCall(e,!0,"processJoinAcknowledgment"),(0,S.checkCode)((null===(l=i.error)||void 0===l?void 0:l.code)||0,null===(s=i.error)||void 0===s?void 0:s.message);if(i.event===d.SignalEvent.SUCCESS)return e.eventsQueue.forEach((e=>{e()})),e.eventsQueue.clear(),this.configureRTCServers(e,i,t),e;throw f.warn(`[1969] [CallId: ${e.id}] Unexpected join event: ${i.event}`),(0,S.checkCode)(4e3,`Unexpected event type: ${i.event}`)}configureRTCServers(e,i,t){var n;(null===(n=i.turnServers)||void 0===n?void 0:n.length)&&this.setRTCConfig(Object.assign(Object.assign({},e.mediaFlow===d.MediaFlow.SFU?{}:{iceServers:i.turnServers.map((e=>({urls:[`${e.url}?transport=tcp`,`${e.url}?transport=udp`],credential:e.password,username:e.username})))}),{bundlePolicy:"max-bundle",rtcpMuxPolicy:"require"})),this.processRemoteParticipants(e,(null==i?void 0:i.participants)||[]),this.reconcileParticipants(e,i.participants||[]),this.handleUpdateCallSettingsSignal(i,e),e.mediaFlow===d.MediaFlow.SFU?this.setupSFUConnection(e,t,i):e.participants.forEach((i=>{e.mediaFlow===d.MediaFlow.P2P&&i.getFullId()!=e.localParticipant.getFullId()&&i.state===d.ParticipantState.Joined&&this.isPolitePeer(i.getFullId(),e.localParticipant.getFullId())&&(f.info(`[2008] [CallId: ${e.id}] Sending offer to participant: ${i.getFullId()}`),this.sendOfferPeerToPeer(e,i,(i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[2005] [CallId: ${e.id}] SYNC OFFER failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`):i.event!==d.SignalEvent.ERROR||f.error(`[2010] [CallId: ${e.id}] SYNC OFFER failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`)})))}))}setupSFUConnection(e,i,t){const n=new s.Participant(e.id);f.info(`[2005] [CallId: ${e.id}] [serverParticipant.id:${n.getFullId()}] Adding server participant to RTC map`,{color:"cyan"});try{e.setServerParticipant(n);const a=n=>{n instanceof g.SceytCallException||n instanceof Error?f.error(`[2011] [CallId: ${e.id}] SYNC OFFER failed message: ${n.message} code: ${n instanceof g.SceytCallException?n.code:""}`):(n.event===d.SignalEvent.ERROR&&f.error(`[2015] [CallId: ${e.id}] SYNC OFFER failed message: ${n.error?`${n.error.message} code: ${n.error.code}`:""}`),n.event!==d.SignalEvent.ERROR&&(f.info(`[2019] [CallId: ${e.id}] offerAck: ${JSON.stringify(n)}`,{color:"cyan"}),e.participants.forEach((n=>{var a;if(n.id===this.user.id&&n.clientId===this.clientId||!(null===(a=null==t?void 0:t.participants)||void 0===a?void 0:a.find((e=>e.id===n.id&&e.clientId===n.clientId&&e.connectionState===d.ParticipantConnectionState.Connected))))n.connectionState&&n.connectionState>d.ParticipantConnectionState.Connected&&n.id!==this.user.id&&n.clientId!==this.clientId&&n.getFullId()!=e.localParticipant.getFullId()&&n.updateConnectionState(n.connectionState,e);else{const a=i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[2023] [CallId: ${e.id}] SYNC CONNECT failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`):i.event!==d.SignalEvent.ERROR||f.error(`[2028] [CallId: ${e.id}] SYNC CONNECT failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`)};this.signalingClient.clearParticipantSignals(e.id,n.getFullId()),this.signalingClient.sendSignalMessage({mediaFlow:i,callId:e.id,event:d.SignalEvent.CONNECT,sessionId:t.sessionId,to:n.getFullId(),metadata:e.metadata},a)}}))))};f.info(`[2067] [CallId: ${e.id}] Sending offer to server participant: ${n.getFullId()}`),this.sendOfferPeerToPeer(e,n,a)}catch(i){throw f.error(`[2049] [CallId: ${e.id}] SFU setup error: message: ${i instanceof Error?i.message:JSON.stringify(i)}`),(0,S.toCallException)(i)}}processRemoteParticipants(e,i){i.length&&(i.forEach((i=>{var t,n,a,l,o,r,c,u,p,h,g,v,S,f,C,I,m,E;let P=e.participants.find((e=>e.getFullId()===this.getParticipantId(i)));if(P||(P=e.participants.find((e=>e.id===i.id&&(e.clientId===i.clientId||!e.clientId))),P&&!P.clientId&&(P.clientId=i.clientId)),P)P&&(P.presenter=!!i.presenter,P.setMediaVideoState((null===(h=i.mediaState)||void 0===h?void 0:h.video)||{enabled:!1,changedBy:null===(v=null===(g=i.mediaState)||void 0===g?void 0:g.video)||void 0===v?void 0:v.changedBy},i.permissions||{canPublishVideo:!1},e),P.setMediaAudioState((null===(S=i.mediaState)||void 0===S?void 0:S.audio)||{enabled:!1,changedBy:null===(C=null===(f=i.mediaState)||void 0===f?void 0:f.audio)||void 0===C?void 0:C.changedBy},i.permissions||{canPublishAudio:!1},e),P.setHold(!!i.hasOwnProperty("onHold")&&!!i.onHold,e),P.setMediaScreenShareState((null===(I=i.mediaState)||void 0===I?void 0:I.screenShare)||{enabled:!1,changedBy:null===(E=null===(m=i.mediaState)||void 0===m?void 0:m.screenShare)||void 0===E?void 0:E.changedBy},e),P.getFullId()!==(null==e?void 0:e.localParticipant.getFullId())&&P.state!=i.state&&void 0!==i.state&&P.updateState(i.state||d.ParticipantState.Idle,e));else{const h=new s.Participant(i.id,i.clientId);h.getFullId()!==(null==e?void 0:e.localParticipant.getFullId())&&(h.state=i.state||d.ParticipantState.Idle),h.setMediaVideoState((null===(t=i.mediaState)||void 0===t?void 0:t.video)||{enabled:!1,changedBy:null===(a=null===(n=i.mediaState)||void 0===n?void 0:n.video)||void 0===a?void 0:a.changedBy},i.permissions||{canPublishVideo:!1},e),h.setMediaAudioState((null===(l=i.mediaState)||void 0===l?void 0:l.audio)||{enabled:!1,changedBy:null===(r=null===(o=i.mediaState)||void 0===o?void 0:o.audio)||void 0===r?void 0:r.changedBy},i.permissions||{canPublishAudio:!1},e),h.setHold(!!i.hasOwnProperty("onHold")&&!!i.onHold,e),h.setMediaScreenShareState((null===(c=i.mediaState)||void 0===c?void 0:c.screenShare)||{enabled:!1,changedBy:null===(p=null===(u=i.mediaState)||void 0===u?void 0:u.screenShare)||void 0===p?void 0:p.changedBy},e),e.addParticipantToList(h),e.emitParticipantsAdded([h])}})),f.info(`[2098] [CallId: ${e.id}] Processed participants - Added and Updated`,{color:"cyan"}))}reconcileParticipants(e,i){if(!(null==i?void 0:i.length))return;const t=e.participants.filter((t=>(t.id!==e.localParticipant.id||t.clientId!==e.localParticipant.clientId)&&!i.some((e=>!(e.id!==t.id||e.clientId!==t.clientId&&e.clientId&&t.clientId)))));t.length&&(e.participants=e.participants.filter((e=>!t.includes(e))),e.emitParticipantsRemoved(t))}processJoinCall(e,i,t){e.mediaFlow!==d.MediaFlow.SFU&&e.localParticipant.updateConnectionState(d.ParticipantConnectionState.Connected,e);const n=i.mediaFlow||d.MediaFlow.P2P;e.setSessionId(i.sessionId),e.changeMediaFlow(n),e.localParticipant.updateState(d.ParticipantState.Joined,e),e.setState(d.CallState.Connected,t)?this.processJoinAcknowledgment(e,i,n):this.leaveCall(e,!0,"processJoinCall")}startCall(e,i,t){const a=i.mediaFlow,s=e.participants.filter((e=>!(e.id===this.user.id&&e.clientId===this.clientId))).map((e=>e.serialize()));e.mediaFlow!==d.MediaFlow.SFU&&e.localParticipant.updateConnectionState(d.ParticipantConnectionState.Connecting,e);const o=(i,o)=>{var r,c,u,p,h,v,C,I,m,E,P;if(e.state==d.CallState.Idle)return i.forEach((e=>{e.stop()})),void(null==t||t({error:(0,S.checkCode)(5002,"Call was ended before media setup completed")}));o&&o.length>0&&(e.localParticipant.setVideoTracks(o,e),e.localVideoTracks=o,e.setVideoDeviceId(o[0].getSettings().deviceId||null)),e.localParticipant.setAudioTracks(i,e),e.localAudioTracks=i,this.joinToCall({mediaFlow:a,callId:e.id,sessionId:e.sessionId,participants:s,metadata:e.metadata,callOptions:Object.assign(Object.assign({},void 0!==(null===(r=e.settings)||void 0===r?void 0:r.callType)&&{callType:e.settings.callType}),{settings:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==(null===(c=e.settings)||void 0===c?void 0:c.broadcastSettings)&&{broadcastSettings:e.settings.broadcastSettings}),void 0!==(null===(u=e.settings)||void 0===u?void 0:u.startsAt)&&{startsAt:l.default.fromNumber(e.settings.startsAt)}),void 0!==(null===(p=e.settings)||void 0===p?void 0:p.expiresAt)&&{expiresAt:l.default.fromNumber(e.settings.expiresAt)}),void 0!==(null===(h=e.settings)||void 0===h?void 0:h.persistent)&&{persistent:e.settings.persistent}),{permissions:{allowPublishAudio:null!==(I=null===(C=null===(v=null==e?void 0:e.settings)||void 0===v?void 0:v.permissions)||void 0===C?void 0:C.allowPublishAudio)&&void 0!==I&&I,allowPublishVideo:null!==(P=null===(E=null===(m=null==e?void 0:e.settings)||void 0===m?void 0:m.permissions)||void 0===E?void 0:E.allowPublishVideo)&&void 0!==P&&P}})}),joinOptions:{muted:e.muted,videoEnabled:e.videoEnabled}},(i=>n(this,void 0,void 0,(function*(){var n;return i instanceof g.SceytCallException||i instanceof Error?(f.error(`[2137] [CallId: ${e.id}] SYNC JOIN failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`),e.setState(d.CallState.Closed,"joinCall failed"),void(null==t||t({error:(0,S.toCallException)(i)}))):i.event===d.SignalEvent.ERROR?(f.error(`[2141] [CallId: ${e.id}] SYNC JOIN failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`),void(null==t||t({error:(0,S.checkCode)(5003,(null===(n=i.error)||void 0===n?void 0:n.message)||"Unknown error")}))):void this.processJoinCall(e,i,"from joinCall")}))))};return e.localAudioTracks&&e.localAudioTracks.length>0||e.localVideoTracks&&e.localVideoTracks.length>0?!(e.localAudioTracks&&e.localAudioTracks.length>0)&&e.localVideoTracks&&e.localVideoTracks.length>0?this.setupMediaStream(e).then((({audioTracks:e})=>{o(e,i.localVideoTracks||[])})):e.localAudioTracks&&e.localAudioTracks.length>0&&!(e.localVideoTracks&&e.localVideoTracks.length>0)?o(i.localAudioTracks||[]):o(e.localAudioTracks||[],e.localVideoTracks||[]):this.setupMediaStream(e).then((({audioTracks:e})=>{o(e)})),e}promoteFromPrepared(e,i){var t;const n=this.prepareCalls.findIndex((i=>i.id===e));if(-1===n)return;const a=this.prepareCalls[n];return this.prepareCalls.splice(n,1),this.activeCalls.push(a),i&&(this.updateCallMetadata(a,i),(null===(t=i.participants)||void 0===t?void 0:t.length)&&this.syncParticipants(a,i.participants)),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls),a}prepareCall(e,i,t){var n,a,l;try{const o=e||(0,h.v4)();f.info(`[2155] [CallId: ${e}] prepareCall, creating call object`,{color:"blue"});const r=this.activeCalls.find((i=>i.id===e));if(r)return{success:!0,data:r};const u=this.prepareCalls.find((i=>i.id===e));if(u)return this.applyCreateOptions(u,i),this.applyServerCall(u,t),{success:!0,data:u};const p=null!==(a=null!==(n=null==t?void 0:t.mediaFlow)&&void 0!==n?n:null==i?void 0:i.mediaFlow)&&void 0!==a?a:0,g=new s.Participant(this.user.id,this.clientId),v=new c.Call({id:o,sessionId:null==t?void 0:t.sessionId,mediaFlow:null!=p?p:d.MediaFlow.P2P,localParticipant:g,participants:[g],createdBy:null!==(l=null==t?void 0:t.createdBy)&&void 0!==l?l:this.user.id,chatClient:this.chatClient,isCallSilenced:!1});return this.applyCreateOptions(v,i),this.applyServerCall(v,t),this.prepareCalls.push(v),{success:!0,data:v}}catch(i){return f.error(`[2158] [CallId: ${e}] prepareCall failed: ${i.message||JSON.stringify(i)}`,{color:"red"}),{success:!1,error:(0,S.toCallException)(i)}}}prepareCallFromCallID(e){return n(this,void 0,void 0,(function*(){return new Promise((i=>{this.signalingClient.sendSignalMessage({event:d.SignalEvent.GET_CALL,callId:e},(t=>{var n,a,l,s;if(t instanceof g.SceytCallException||t instanceof Error)return f.error(`[2160] prepareCallFromCallID GET_CALL failed: ${t.message}`,{color:"red"}),void i({success:!1,error:(0,S.toCallException)(t)});if(t.event===d.SignalEvent.ERROR)return f.error(`[2161] prepareCallFromCallID GET_CALL failed: ${null===(n=t.error)||void 0===n?void 0:n.message}`,{color:"red"}),void i({success:!1,error:(0,S.checkCode)((null===(a=t.error)||void 0===a?void 0:a.code)||5e3,(null===(l=t.error)||void 0===l?void 0:l.message)||"GET_CALL failed")});const o=null===(s=t.calls)||void 0===s?void 0:s.find((i=>i.id===e));if(!o)return void i({success:!1,error:g.SceytCallException.BadRequest(4004,`Call ${e} not found`)});const r=this.prepareCall(e,{mediaFlow:o.mediaFlow},o);r.success&&r.data&&this.updateCallMetadata(r.data,o),i(r)}),"get_call")}))}))}joinCall(e,i,t){let n=null;try{f.info(`[2159] [CallId: ${e.id}] joinCall, start call`,{color:"blue"});const a={id:e.id,sessionId:e.sessionId||void 0,mediaFlow:e.mediaFlow,participants:e.participants.filter((({id:e})=>e!==this.user.id)),metadata:e.metadata,createdBy:e.createdBy,localAudioTracks:i.localAudioTracks,localVideoTracks:i.localVideoTracks,audioSettings:i.audioSettings,videoSettings:i.videoSettings},l=e.setState(d.CallState.Connecting,"joinCall");let s=this.promoteFromPrepared(e.id);if(s)this.applyOptionsToExistingCall(s,a,s.participants,s.participants);else{const{call:e}=this.findOrCreateCall(a);s=e}return l?(s.localParticipant.clientId=this.clientId,n=this.startCall(s,a,t),{success:!0,data:s}):{success:!1,error:(0,S.checkCode)(5001,`Failed to set call state from ${s.state} to connecting`)}}catch(e){return f.error(`[2173] [CallId: ${null==n?void 0:n.id}] Join call failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,S.toCallException)(e)}}}createCall(e){var i,t,a,s;return n(this,void 0,void 0,(function*(){try{f.info(`[2180] [CallId: ${e.id}] createCall, creating call link`,{color:"blue"});const n=e.settings;if(void 0!==(null==n?void 0:n.startsAt)&&void 0!==(null==n?void 0:n.expiresAt)&&n.startsAt>=n.expiresAt)return{success:!1,error:g.SceytCallException.BadRequest(4001,"startsAt must be before expiresAt")};const o=[...new Set(e.participants.filter((e=>!(e.id===this.user.id&&e.clientId===this.clientId))).map((e=>e.id)))],r=null!==(i=this.prepareCalls.find((i=>i.id===e.id)))&&void 0!==i?i:e,c=yield new Promise((e=>{var i,t,a,s;this.signalingClient.sendSignalMessage(Object.assign(Object.assign({event:d.SignalEvent.CREATE,callId:r.id,mediaFlow:r.mediaFlow,participants:o.map((e=>({id:e,clientId:""})))},r.metadata&&{metadata:r.metadata}),{callOptions:Object.assign(Object.assign({},void 0!==(null==n?void 0:n.callType)&&{callType:n.callType}),{settings:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==(null==n?void 0:n.broadcastSettings)&&{broadcastOptions:n.broadcastSettings}),void 0!==(null==n?void 0:n.startsAt)&&{startsAt:l.default.fromNumber(n.startsAt)}),void 0!==(null==n?void 0:n.expiresAt)&&{expiresAt:l.default.fromNumber(n.expiresAt)}),void 0!==(null==n?void 0:n.persistent)&&{persistent:n.persistent}),void 0!==(null==n?void 0:n.notifyOnParticipantJoin)&&{notifyOnParticipantJoin:n.notifyOnParticipantJoin}),void 0!==(null==n?void 0:n.maxParticipantsCount)&&{maxParticipantsCount:n.maxParticipantsCount}),{permissions:{allowPublishAudio:null!==(t=null===(i=null==n?void 0:n.permissions)||void 0===i?void 0:i.allowPublishAudio)&&void 0!==t&&t,allowPublishVideo:null!==(s=null===(a=null==n?void 0:n.permissions)||void 0===a?void 0:a.allowPublishVideo)&&void 0!==s&&s}})})}),e)}));return c instanceof g.SceytCallException||c instanceof Error?(f.error(`[2210] [CallId: ${r.id}] CREATE signal failed: ${c.message}`,{color:"red"}),{success:!1,error:(0,S.toCallException)(c)}):c.event===d.SignalEvent.ERROR?(f.error(`[2219] [CallId: ${r.id}] CREATE signal failed: ${c.error?`${c.error.message} code: ${c.error.code}`:""}`,{color:"red"}),{success:!1,error:(0,S.checkCode)((null===(t=c.error)||void 0===t?void 0:t.code)||5e3,(null===(a=c.error)||void 0===a?void 0:a.message)||"Create call failed")}):(f.info(`[2228] [CallId: ${r.id}] Call link created successfully`,{color:"blue"}),c.sessionId&&(this.promoteFromPrepared(r.id),r.setSessionId(c.sessionId),r.setIsCreatedRemotely(!0)),(null===(s=c.participants)||void 0===s?void 0:s.length)&&this.reconcileParticipants(r,c.participants),{success:!0,data:r})}catch(i){return f.error(`[2238] [CallId: ${e.id}] createCall failed: ${i.message||JSON.stringify(i)}`,{color:"red"}),{success:!1,error:(0,S.toCallException)(i)}}}))}callOptionsToSettings(e){var i,t,n,a;const s=e.settings;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==e.callType&&{callType:e.callType}),void 0!==(null==s?void 0:s.startsAt)&&{startsAt:l.default.isLong(s.startsAt)?s.startsAt.toNumber():s.startsAt}),void 0!==(null==s?void 0:s.expiresAt)&&{expiresAt:l.default.isLong(s.expiresAt)?s.expiresAt.toNumber():s.expiresAt}),void 0!==(null==s?void 0:s.persistent)&&{persistent:s.persistent}),void 0!==(null==s?void 0:s.broadcastOptions)&&{broadcastSettings:s.broadcastOptions}),void 0!==(null==s?void 0:s.notifyOnParticipantJoin)&&{notifyOnParticipantJoin:s.notifyOnParticipantJoin}),void 0!==(null==s?void 0:s.maxParticipantsCount)&&{maxParticipantsCount:s.maxParticipantsCount}),{permissions:{allowPublishAudio:null!==(t=null===(i=null==s?void 0:s.permissions)||void 0===i?void 0:i.allowPublishAudio)&&void 0!==t&&t,allowPublishVideo:null!==(a=null===(n=null==s?void 0:s.permissions)||void 0===n?void 0:n.allowPublishVideo)&&void 0!==a&&a}})}signalMessageToICall(e){return Object.assign({id:e.callId,sessionId:e.sessionId,mediaFlow:e.mediaFlow,createdBy:e.createdBy,metadata:e.metadata||{},participants:e.participants||[],createdAt:l.default.isLong(e.createdAt)?e.createdAt.toNumber():e.createdAt},e.callOptions&&{options:e.callOptions})}applyCreateOptions(e,i){if(!i)return;const t=i.videoCall?Object.assign(Object.assign({},i.metadata),{videoCall:"true"}):i.metadata;if(t&&(e.metadata=t),i.videoCall&&e.setVideoCall(!0),i.settings&&e.setSettings(i.settings),i.participantIds){const t=[...new Set(i.participantIds.filter((e=>e!==this.user.id)))],n=new Set(e.participants.map((e=>e.id))),a=t.filter((e=>!n.has(e))).map((e=>new s.Participant(e)));a.length>0&&(e.participants=(0,u.makeFirstById)([...e.participants,...a],this.user.id,this.clientId))}}applyServerCall(e,i){var t,n;i&&(i.sessionId&&e.setSessionId(i.sessionId),void 0!==i.mediaFlow&&(e.mediaFlow=i.mediaFlow),i.metadata&&(null===(t=Object.values(i.metadata))||void 0===t?void 0:t.length)&&(e.metadata=i.metadata),i.createdBy&&(e.createdBy=i.createdBy),i.options&&e.setSettings(this.callOptionsToSettings(i.options)),(null===(n=i.participants)||void 0===n?void 0:n.length)&&this.syncParticipants(e,i.participants))}updateCallMetadata(e,i){var t,n;i.metadata&&(null===(t=Object.values(i.metadata))||void 0===t?void 0:t.length)&&(e.metadata=i.metadata||{}),e.createdBy=i.createdBy,e.sessionId=i.sessionId,e.id=i.id,e.setVideoCall("true"===(null===(n=e.metadata)||void 0===n?void 0:n.videoCall)),e.mediaFlow!==d.MediaFlow.SFU&&i.mediaFlow===d.MediaFlow.SFU&&e.changeMediaFlow(d.MediaFlow.SFU),i.options&&e.setSettings(this.callOptionsToSettings(i.options)),f.info(`[2187] [CallId: ${e.id}] Updated call metadata for call ${e.id}`,{color:"light-blue"})}syncParticipants(e,i){f.info(`[2198] [CallId: ${e.id}] Syncing participants for call ${e.id}`,{color:"light-blue"}),e.participants=e.participants.filter((t=>{const n=i.find((e=>!(e.id!==t.id||e.clientId!==t.clientId&&e.clientId&&t.clientId)));return n||(t.state=d.ParticipantState.Left,e.emitParticipantStateChanged(t,d.ParticipantState.Left)),!!n})),f.info(`[2216] [CallId: ${e.id}] Syncing participants for call ${e.id}`,{color:"light-blue"});for(const t of i){const i=e.participants.find((e=>!(e.id!==t.id||e.clientId!==t.clientId&&t.clientId&&e.clientId)));if(f.info(`[2219] [CallId: ${e.id}] Syncing participant ${null==i?void 0:i.getFullId()} for call ${e.id}`,{color:"light-blue"}),i){if(i.clientId||(i.clientId=t.clientId),i.id===e.localParticipant.id&&i.clientId===e.localParticipant.clientId){e.localParticipant.state===d.ParticipantState.Joined&&(t.state||0)>d.ParticipantState.Joined&&this.leaveCall(e,!0,"syncParticipants"),this.syncParticipantMediaState(e,i,t);continue}i.state=t.state||d.ParticipantState.Idle,e.emitParticipantStateChanged(i,t.state||d.ParticipantState.Idle),i.state!==d.ParticipantState.Joined?i.getFullId()!==e.localParticipant.getFullId()&&(this.closePeerConnections(e.id,i.getFullId()),e.activeSpeakerManager.removeParticipant(i)):i.id!==e.localParticipant.id&&i.clientId!==e.localParticipant.clientId&&e.state===d.CallState.Connected&&this.handleNewParticipant(e,i),i.getFullId()===e.localParticipant.getFullId()&&(e.localParticipant=i),this.syncParticipantMediaState(e,i,t),f.info(`[2254] [CallId: ${e.id}] Syncing existing participants: ${i.getFullId()} for call ${e.id}`,{color:"light-blue"})}else{const i=new s.Participant(t.id,t.clientId);i.state=t.state||d.ParticipantState.Idle,e.addParticipantToList(i),this.syncParticipantMediaState(e,i,t),f.info(`[2263] [CallId: ${e.id}] Syncing no existing participants: ${i.getFullId()} for call ${e.id}`,{color:"light-blue"}),e.emitParticipantsAdded([i]),(e.mediaFlow!==d.MediaFlow.SFU&&t.state===d.ParticipantState.Joined||e.mediaFlow===d.MediaFlow.SFU&&t.connectionState===d.ParticipantConnectionState.Connected&&e.state===d.CallState.Connected)&&this.handleNewParticipant(e,i)}}}syncParticipantMediaState(e,i,t){var n,a,l;if(i.getFullId()===t.id+(t.clientId?"/"+t.clientId:"")){const s=!!t.hasOwnProperty("onHold")&&!!t.onHold,o=!!t.hasOwnProperty("isCallSilenced")&&!!t.isCallSilenced;f.info(`[syncParticipantMediaState] [CallId: ${e.id}] Media state sync for participant ${i.getFullId()} - current: ${JSON.stringify(i.mediaState)} server: ${JSON.stringify(null==t?void 0:t.mediaState)}`,{color:"light-blue"}),f.info(`[syncParticipantMediaState] [CallId: ${e.id}] Permissions sync for participant ${i.getFullId()} - current: ${JSON.stringify(i.permissions)} server: ${JSON.stringify(null==t?void 0:t.permissions)}`,{color:"light-blue"}),i.setMediaAudioState((null===(n=null==t?void 0:t.mediaState)||void 0===n?void 0:n.audio)||{enabled:!1,changedBy:""},(null==t?void 0:t.permissions)||{},e),i.setMediaVideoState((null===(a=null==t?void 0:t.mediaState)||void 0===a?void 0:a.video)||{enabled:!1,changedBy:""},(null==t?void 0:t.permissions)||{},e),i.setMediaScreenShareState((null===(l=null==t?void 0:t.mediaState)||void 0===l?void 0:l.screenShare)||{enabled:!1,changedBy:""},e),s!==i.onHold&&(f.info(`[2317] [CallId: ${e.id}] Participant ${i.getFullId()} hold state changed: ${i.onHold} -> ${s}`,{color:"light-blue"}),i.setHold(s,e)),i.getFullId()===e.localParticipant.getFullId()&&(f.info(`[2327] [CallId: ${e.id}] Participant ${i.getFullId()} ring allowed state changed: ${o}`,{color:"light-blue"}),e.setIsCallSilenced(o))}}handleNewParticipant(e,i){if(f.info(`[2333] [CallId: ${e.id}] Call media flow: ${e.mediaFlow}`,{color:"light-blue"}),e.mediaFlow!==d.MediaFlow.SFU){if(i.updateState(d.ParticipantState.Joined,e),i.getFullId()!==e.localParticipant.getFullId()&&i.connectionState!==d.ParticipantConnectionState.Connected&&i.connectionState!==d.ParticipantConnectionState.Reconnecting){const t=i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[2341] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`,{color:"red"}):i.event!==d.SignalEvent.ERROR||f.error(`[2345] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"})};f.info(`[2370] [CallId: ${e.id}] Sending offer to participant: ${i.getFullId()}`),e.localParticipant.state===d.ParticipantState.Joined&&e.mediaFlow===d.MediaFlow.P2P&&this.isPolitePeer(i.getFullId(),e.localParticipant.getFullId())?this.sendOfferPeerToPeer(e,i,t):e.localParticipant.state===d.ParticipantState.Joined&&(this.signalingClient.clearParticipantSignals(e.id,i.getFullId()),this.signalingClient.sendSignalMessage({to:i.getFullId(),mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.CONNECT,sessionId:e.sessionId},t))}}else if(i.getFullId()!==e.localParticipant.getFullId()&&i.connectionState!==d.ParticipantConnectionState.Reconnecting){const t=i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[2354] [CallId: ${e.id}] SYNC CONNECT signal sent failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`,{color:"red"}):i.event!==d.SignalEvent.ERROR||f.error(`[2358] [CallId: ${e.id}] SYNC CONNECT signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"})};this.signalingClient.clearParticipantSignals(e.id,i.getFullId()),this.signalingClient.sendSignalMessage({to:i.getFullId(),mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.CONNECT,sessionId:e.sessionId},t)}}handleSessionRenewedSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(!i)return void f.warn(`[SessionRenewed] [CallId: ${e.callId}] No active call found`,{color:"red"});const t=e.sessionId;f.info(`[SessionRenewed] [CallId: ${i.id}] Session renewed: ${i.sessionId} -> ${t}`,{color:"cyan"}),i.setSessionId(t),i.emitSessionRenewed(t)}handleConnectSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(i){let t=i.participants.find((i=>i.getFullId()===e.from));t&&this.sendOfferPeerToPeer(i,t,(e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[2417] [CallId: ${i.id}] SYNC OFFER signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[2421] [CallId: ${i.id}] SYNC OFFER signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})}))}}handleMediaFlowSwitch(e){f.info(`[2375] [CallId: ${e.id}] Switching call ${e.id} from P2P to SFU`,{color:"light-blue"});const i=new s.Participant(e.id);e.setServerParticipant(i),f.info(`[2395] [CallId: ${e.id}] Sending offer to server participant: ${i.getFullId()}`),this.sendOfferPeerToPeer(e,i,(i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[2386] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`,{color:"red"}):i.event!==d.SignalEvent.ERROR||f.error(`[2390] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"})})),e.participants.forEach((e=>{e.setShouldResetPeerConnection(!0)}))}}i.InternalCallHandler=I},787:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Participant=void 0;const n=t(578),a=t(758),l=t(645),s=(0,l.createLogger)("ParticipantState"),o=(0,l.createLogger)("ConnectionState");i.Participant=class{constructor(e,i){this.clientId="",this.onHold=!1,this.presenter=!1,this.audioTracks=[],this.videoTracks=[],this.shouldResetPeerConnection=!1,this.state=n.ParticipantState.Idle,this.connectionState=n.ParticipantConnectionState.Idle;const t=e.split("/");this.id=t[0],this.clientId=i||t[1]||""}updateState(e,i,t){const n=null==i?void 0:i.id,l=new a.ParticipantStateMachine(this.id,n).updateState(e,this.state);return l&&(this.state=e,i.emitParticipantStateChanged(this,e,t),s.info(`[35] [CallId: ${n}] Updating state: ${e}, participantID: ${this.getFullId()}`,{color:"blue"})),l}updateConnectionState(e,i){const t=null==i?void 0:i.id,n=new a.ParticipantStateMachine(this.id,t).updateConnectionState(e,this.connectionState);return n&&(this.connectionState=e,i.emitParticipantConnectionStateChanged(this,e),o.info(`[45] [CallId: ${t}] Updating connection state: ${e}, participantID: ${this.getFullId()}`,{color:"blue"})),n}setShouldResetPeerConnection(e){this.shouldResetPeerConnection=e}setMediaAudioState(e,i,t){this.audioTracks.forEach((i=>{i.enabled=e.enabled})),this.mediaState||(this.mediaState={audio:{enabled:!1},video:{enabled:!1},screenShare:{enabled:!1}}),this.mediaState.audio=e,this.permissions||(this.permissions={canPublishAudio:!1,canPublishVideo:!1}),this.permissions.canPublishAudio=!!(null==i?void 0:i.canPublishAudio),t&&t.emitParticipantEvent(this,this.mediaState.audio.enabled?"Unmute":"Mute",e.changedBy)}setMediaVideoState(e,i,t){this.mediaState||(this.mediaState={audio:{enabled:!1},video:{enabled:!1},screenShare:{enabled:!1}}),this.mediaState.video=e,this.permissions||(this.permissions={canPublishAudio:!1,canPublishVideo:!1}),this.permissions.canPublishVideo=!!(null==i?void 0:i.canPublishVideo),this.videoTracks.forEach((i=>{i.enabled=e.enabled})),t&&t.emitParticipantEvent(this,e.enabled?"VideoEnabled":"VideoDisabled",e.changedBy)}setMediaScreenShareState(e,i){this.mediaState||(this.mediaState={audio:{enabled:!0},video:{enabled:!1},screenShare:{enabled:!1}}),this.mediaState.screenShare=e,this.videoTracks.forEach((i=>{i.enabled=e.enabled})),i&&i.emitParticipantEvent(this,e.enabled?"ScreenSharingStarted":"ScreenSharingStopped",e.changedBy)}setPresenter(e){this.presenter=e}setAudioTracks(e,i){this.audioTracks=e,this.audioTracks.forEach((e=>{var i;e.enabled=!!(null===(i=this.mediaState)||void 0===i?void 0:i.audio.enabled)})),i.emitAudioTrackAdded(this,e[0])}setVideoTracks(e,i){this.videoTracks=e,this.videoTracks.forEach((e=>{var i;e.enabled=!!(null===(i=this.mediaState)||void 0===i?void 0:i.video.enabled)})),i.emitVideoTrackAdded(this,e[0])}setHold(e,i){this.onHold=e,i&&i.emitParticipantEvent(this,this.onHold?"Hold":"Unhold")}serialize(){return{id:this.id,clientId:this.clientId}}getFullId(){return this.id+(this.clientId?"/"+this.clientId:"")}}},816:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.QueryBuilder=void 0,i.QueryBuilder=class{constructor(){this.count=10}}},185:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.RecentCallQueryBuilder=void 0;const n=t(578),a=t(650),l=t(816),s=t(343),o=t(228);class r extends l.QueryBuilder{constructor(){super(...arguments),this.order=n.CDRRequestOrder.ASC,this.count=10,this.participantCount=10,this.event=n.CDRRequestEvent.GET_RECENT_CALLS,this.direction=n.CDRRequestDirection.NEXT,this.setSessionIdList=e=>(this.sessionIdList=e,this),this.setEvent=e=>(this.event=e,this),this.setSessionId=e=>(this.sessionId=e,this),this.limit=e=>(this.count=e,this),this.setParticipantCount=e=>(this.participantCount=e,this),this.setOrder=e=>(this.order=e,this),this.setDirection=e=>(this.direction=e,this),this.setCallTypes=e=>(this.callTypes=e,this),this.build=()=>{const e=a.InternalCallHandler.getInstance();this.chatClient=e.chatClient;try{return new s.RecentCallQuery(this)}catch(e){throw(0,o.toCallException)(e)}}}}i.RecentCallQueryBuilder=r},343:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.RecentCallQuery=void 0;const a=t(578),l=t(645),s=t(228),o=(0,l.createLogger)("RecentCallQuery");i.RecentCallQuery=class{constructor(e){this.count=10,this.hasNext=!0,this.loading=!1,this.order=a.CDRRequestOrder.ASC,this.participantCount=10,this.event=a.CDRRequestEvent.GET_RECENT_CALLS,this.direction=a.CDRRequestDirection.NEXT,this.loadNextPage=()=>n(this,void 0,void 0,(function*(){if(this.loading)throw o.info("QUERY_IN_PROGRESS"),(0,s.checkCode)(5001,"QUERY_IN_PROGRESS");if(this.hasNext){this.loading=!0;const e=yield this.chatClient.sendCallDetailsRecord(Object.assign(Object.assign({event:this.event,order:this.order,limit:this.count,participantCount:this.participantCount,direction:this.direction},this.nextToken||this.sessionId?{position:Object.assign(Object.assign({},this.sessionId?{sessionId:this.sessionId}:{}),this.nextToken?{nextToken:this.nextToken}:{})}:{}),void 0!==this.callTypes&&{filter:{callTypes:this.callTypes}}));this.loading=!1;const{getRecentCallsResponse:{records:i,nextToken:t}}=e;return this.hasNext=!!t,this.nextToken=t,{records:i,hasNext:this.hasNext}}return{records:[],hasNext:this.hasNext}})),this.deleteCalls=()=>n(this,void 0,void 0,(function*(){var e;if(null===(e=this.sessionIdList)||void 0===e?void 0:e.length)return yield this.chatClient.sendCallDetailsRecord({event:a.CDRRequestEvent.DELETE_RECENT_CALLS,sessionIdList:{items:this.sessionIdList}})})),this.order=e.order,this.count=e.count,this.participantCount=e.participantCount,this.sessionId=e.sessionId,this.event=e.event,this.direction=e.direction,this.chatClient=e.chatClient,this.sessionIdList=e.sessionIdList,this.callTypes=e.callTypes}set limit(e){this.count=e}get limit(){return this.count}}},680:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.toSessionDescription=i.toSessionData=void 0;const n=t(578),a=t(645),l=t(19),s=(0,a.createLogger)("SignalingExtensions");i.toSessionData=function(e,i){const t=e.sdp.sdp||"",a=1e3*Date.now()+performance.now()%1*1e3;s.info(`[32] [CALL_TIME_TO_SESSION_DATA_START: ${a}]`,{color:"blue"});const o=l.SdpConverter.parseToSdpData(t,l.CODEC_NAME_TO_VIDEO_CODEC,i===n.MediaFlow.S2W?l.CODEC_NAME_TO_AUDIO_CODEC_S2W:l.CODEC_NAME_TO_AUDIO_CODEC),r=1e3*Date.now()+performance.now()%1*1e3;return s.info(`[35] [CALL_TIME_TO_SESSION_DATA_END: ${r}]`,{color:"blue"}),{id:e.sessionId,version:e.versionId,sdpData:o}},i.toSessionDescription=function(e,i){if(e.sdpData){const t=l.SdpConverter.reconstructFromSDPData(e.sdpData);return s.info(`[53] [CallId: ${e.id}] toSessionDescription in sdp-converter: sdp: ${t}`,{color:"blue"}),{type:i,sdp:t}}return s.error("SessionData has neither sdpData nor sdp field"),null}},19:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SdpConverter=i.CODEC_NAME_TO_AUDIO_CODEC_S2W=i.CODEC_NAME_TO_AUDIO_CODEC=i.CODEC_NAME_TO_VIDEO_CODEC=void 0;const n=t(645),a=t(228),l=t(799),s=(0,n.createLogger)("SdpConverter");i.CODEC_NAME_TO_VIDEO_CODEC=["vp8","rtx","red"],i.CODEC_NAME_TO_AUDIO_CODEC=["opus","red"],i.CODEC_NAME_TO_AUDIO_CODEC_S2W=["opus","red","pcmu","pcma"];class o{static parseToSdpData(e,t=i.CODEC_NAME_TO_VIDEO_CODEC,n=i.CODEC_NAME_TO_AUDIO_CODEC){var a,l,s;const r=[],d=e.split("\n").map((e=>e.trim())).filter((e=>e.length>0)),c=o.extractSessionId(d)||"",u=o.extractSessionVersion(d)||0,p=o.extractOriginAddress(d)||"127.0.0.1",h=(null===(a=d.find((e=>e.startsWith("s="))))||void 0===a?void 0:a.substring(2))||"-",g=(null===(l=d.find(((e,i)=>e.startsWith("c=")&&!o.inMediaSection(d,i))))||void 0===l?void 0:l.split(" ").slice(2)[0])||"",v=(null===(s=o.firstValueStartingWith(d,"a=msid-semantic:"))||void 0===s?void 0:s.trim())||"WMS",S=o.parseBundleGroup(d),f=d.findIndex((e=>e.startsWith("m="))),C=f>0?d.slice(0,f):d,I=o.firstValueStartingWith(C,"a=ice-ufrag:")||"",m=o.firstValueStartingWith(C,"a=ice-pwd:")||"",E=o.parseIceOptions(C),P=o.parseFingerprint(C),b=o.parseSetup(C),y=C.some((e=>"a=ice-lite"===e)),O=C.some((e=>"a=extmap-allow-mixed"===e));return{sessionId:c,sessionVersion:u,bundleGroup:S,iceUfrag:I,icePwd:m,iceOptions:E,fingerprint:P,setup:b,media:o.parseMediaSections(d,r,t,n),sessionName:h,originAddress:p,connectionAddress:g,msidSemantic:v,iceLite:y,extmapAllowMixed:O,stringPool:r}}static reconstructFromSDPData(e){var i,t,n,l,r,d;try{const c=[];if(c.push("v=0\r\n"),c.push(`o=- ${e.sessionId} ${e.sessionVersion} IN IP4 ${e.originAddress}\r\n`),c.push(`s=${e.sessionName}\r\n`),c.push("t=0 0\r\n"),(null===(t=null===(i=e.fingerprint)||void 0===i?void 0:i.hashValue)||void 0===t?void 0:t.length)>0&&c.push(`a=fingerprint:${o.fingerprintToString(e.fingerprint)}\r\n`),(null===(n=null==e?void 0:e.bundleGroup)||void 0===n?void 0:n.length)>0){const i=e.media.map((e=>e.mid)).join(" ");c.push(`a=group:BUNDLE ${i}\r\n`)}(null===(l=null==e?void 0:e.iceOptions)||void 0===l?void 0:l.length)>0&&c.push(`a=ice-options:${e.iceOptions.join(" ")}\r\n`),(null==e?void 0:e.extmapAllowMixed)&&c.push("a=extmap-allow-mixed\r\n"),(null===(r=null==e?void 0:e.msidSemantic)||void 0===r?void 0:r.length)>0&&c.push(`a=msid-semantic: ${e.msidSemantic}\r\n`),(null==e?void 0:e.iceLite)&&c.push("a=ice-lite\r\n"),null===(d=null==e?void 0:e.media)||void 0===d||d.forEach((i=>{o.buildMediaSection(c,i,e)}));const u=c.join("");if(s.debug(`Reconstructed SDP (${null==u?void 0:u.length} bytes)`),!(null==u?void 0:u.includes("m=")))throw(0,a.checkCode)(4e3,"Reconstructed SDP missing media lines");if(!(null==u?void 0:u.includes("a=ice-ufrag:"))&&!(null==u?void 0:u.includes("a=ice-pwd:")))throw(0,a.checkCode)(4e3,"Reconstructed SDP missing ICE credentials");return u}catch(e){throw s.error(`[647] [CallId: GLOBAL_LOGS] Failed to reconstruct SDP: ${e.message}`,{color:"red"}),s.error(e,{color:"red"}),(0,a.toCallException)(e)}}static extractSessionId(e){const i=e.find((e=>e.startsWith("o=")));return i&&i.split(" ")[1]||null}static extractSessionVersion(e){const i=e.find((e=>e.startsWith("o=")));if(!i)return null;const t=i.split(" "),n=parseInt(t[2]||"0",10);return isNaN(n)?null:n}static extractOriginAddress(e){const i=e.find((e=>e.startsWith("o=")));return i&&i.split(" ")[5]||null}static parseBundleGroup(e){const i=e.find((e=>e.startsWith("a=group:BUNDLE ")));return i?i.substring(15).split(" ").map((e=>parseInt(e,10))).filter((e=>!isNaN(e))):[]}static parseIceOptions(e){const i=e.find((e=>e.startsWith("a=ice-options:")));return i?i.substring(14).split(" "):[]}static parseFingerprint(e){var i;const t=e.find((e=>e.startsWith("a=fingerprint:")));if(t){const e=t.substring(14).split(" ",2);if(2===e.length){let t;switch(e[0].toLowerCase()){case"sha-256":default:t=l.HashFunction.SHA256;break;case"sha-1":t=l.HashFunction.SHA1;break;case"sha-384":t=l.HashFunction.SHA384;break;case"sha-512":t=l.HashFunction.SHA512;break;case"md5":t=l.HashFunction.MD5}const n=e[1].replace(/:/g,"");return{hashFunc:t,hashValue:new Uint8Array((null===(i=n.match(/.{1,2}/g))||void 0===i?void 0:i.map((e=>parseInt(e,16))))||[])}}}return{hashFunc:l.HashFunction.SHA256,hashValue:new Uint8Array(0)}}static parseSetup(e){const i=e.find((e=>e.startsWith("a=setup:")));switch(null==i?void 0:i.substring(8).toLowerCase()){case"active":return l.DTLSSetup.ACTIVE;case"passive":return l.DTLSSetup.PASSIVE;default:return l.DTLSSetup.ACTPASS}}static firstValueStartingWith(e,i){const t=e.find((e=>e.startsWith(i)));return t?t.substring(i.length):null}static inMediaSection(e,i){return e.map(((e,i)=>({line:e,index:i}))).filter((({line:e})=>e.startsWith("m="))).map((({index:e})=>e)).some((e=>e<i))}static parseMediaSections(e,i,t,n){const a=e.map(((e,i)=>({line:e,index:i}))).filter((({line:e})=>e.startsWith("m="))).map((({index:e})=>e));return a.map(((l,s)=>{const r=s<a.length-1?a[s+1]:e.length;return o.parseMediaSection(e.slice(l,r),i,t,n)})).filter((e=>null!==e))}static parseMediaSection(e,i,t,n){var a;try{const t=e[0].substring(2).split(" ");let n;switch(t[0].toLowerCase()){case"audio":n=l.MediaType.AUDIO;break;case"video":n=l.MediaType.VIDEO;break;default:n=l.MediaType.MEDIA_TYPE_UNSPECIFIED}if(n===l.MediaType.MEDIA_TYPE_UNSPECIFIED)return s.warn(`Skipping unknown media type: ${t[0]}`),null;const r=parseInt(t[1]||"9",10)||9,d=t.slice(3).map((e=>parseInt(e,10))).filter((e=>!isNaN(e))),c=o.firstValueStartingWith(e,"a=mid:")||"",u=o.parseDirection(e),p=o.firstValueStartingWith(e,"a=msid:"),[h,g,v]=o.parseMSID(p||null),S=e.some((e=>"a=rtcp-mux"===e)),f=e.some((e=>"a=rtcp-rsize"===e)),C=e.some((e=>"a=end-of-candidates"===e)),I=(null===(a=e.find((e=>e.startsWith("c="))))||void 0===a?void 0:a.split(" ")[2])||"",m=o.firstValueStartingWith(e,"a=rtcp:")||"",E=new Map,P=[];d.forEach((e=>{E.set(e,{codecName:{id:e,mapKey:0},fmtp:[],rtcpFeedbackIds:[]}),P.push(e)})),e.filter((e=>e.startsWith("a=rtpmap:"))).forEach((e=>{const i=e.substring(9).split(" ",2);if(2===i.length){const e=parseInt(i[0],10);if(!isNaN(e)){const t=i[1];o.dynamicCodecNames.set(e,t);const n=o.CODEC_NAME_TO_MAP_KEY.get(t)||0;if(E.has(e)){const i=E.get(e);E.set(e,{codecName:{id:e,mapKey:n},fmtp:i.fmtp,rtcpFeedbackIds:i.rtcpFeedbackIds})}}}})),e.filter((e=>e.startsWith("a=fmtp:"))).forEach((e=>{const i=e.substring(7).split(" ",2);if(2===i.length){const e=parseInt(i[0],10);if(!isNaN(e)&&E.has(e)){const t=o.parseFmtp(i[1]),n=E.get(e);E.set(e,{codecName:n.codecName,fmtp:t,rtcpFeedbackIds:n.rtcpFeedbackIds})}}})),e.filter((e=>e.startsWith("a=rtcp-fb:"))).forEach((e=>{const i=e.substring(10).split(" ");if(i.length>=2){const e=parseInt(i[0],10);if(!isNaN(e)){let t="";for(let e=1;e<i.length;e++)t+=i[e]+(e!==i.length-1?" ":"");const n=o.RTCP_FEEDBACK_STRING_TO_ID.get(t);if(void 0!==n&&E.has(e)){const i=E.get(e),t=[...i.rtcpFeedbackIds];t.includes(n)||t.push(n),E.set(e,{codecName:i.codecName,fmtp:i.fmtp,rtcpFeedbackIds:t})}}}}));const b=P.map((e=>E.get(e))).filter((e=>void 0!==e)),y=o.parseExtmaps(e),O=o.parseSsrcs(e),T=o.parseSsrcGroups(e),$=o.parseCandidates(e),A=o.firstValueStartingWith(e,"a=ice-ufrag:"),w=o.firstValueStartingWith(e,"a=ice-pwd:"),R=A?o.addToStringPool(i,A):0,F=w?o.addToStringPool(i,w):0,M=e.find((e=>e.startsWith("a=ice-options:"))),_=M?M.substring(14).split(" "):void 0,N=e.find((e=>e.startsWith("a=fingerprint:"))),k=N?o.parseFingerprint([N]):{hashFunc:l.HashFunction.SHA256,hashValue:new Uint8Array(0)},D=e.find((e=>e.startsWith("a=setup:")));return{type:n,mid:c,direction:u,msidStream:h,msidTrackLabel:g,msidTrackId:v,rtcpMux:S,rtcpRsize:f,extmaps:y,codecs:b,ssrcGroups:T,ssrcs:O,connectionAddress:I,candidates:$,endOfCandidates:C,rtcpAddress:m,iceUfragRef:R,icePwdRef:F,iceOptions:_,fingerprint:k,setup:D?o.parseSetup([D]):l.DTLSSetup.ACTPASS,port:r}}catch(e){return s.error(`[647] [CallId: GLOBAL_LOGS] Failed to parse media section: ${e.message}`,{color:"red"}),s.error(e,{color:"red"}),null}}static parseDirection(e){return e.some((e=>"a=sendrecv"===e))?l.MediaDirection.SENDRECV:e.some((e=>"a=sendonly"===e))?l.MediaDirection.SENDONLY:e.some((e=>"a=recvonly"===e))?l.MediaDirection.RECVONLY:e.some((e=>"a=inactive"===e))?l.MediaDirection.INACTIVE:l.MediaDirection.SENDRECV}static parseMSID(e){if(!e||0===e.trim().length)return["","",0];const i=e.split(" ",2);if(i.length<2)return[e,"",0];const t=i[0],n=i[1],a=n.lastIndexOf("_");if(a>0){const e=n.substring(a+1),i=parseInt(e,10);if(!isNaN(i))return[t,n.substring(0,a+1),i]}return[t,n,0]}static parseFmtp(e){if(0===e.trim().length)return[];const i=[];return e.split(";").forEach((e=>{const t=e.trim();if(0!==t.length)if(t.includes("=")){const e=t.split("=",2);i.push({key:e[0].trim(),value:e[1].trim()})}else i.push({key:"value",value:t})})),i}static parseExtmaps(e){return e.filter((e=>e.startsWith("a=extmap:"))).map((e=>{const i=e.substring(9).split(" ",2);if(2!==i.length)return null;const t=i[0].split("/")[0],n=parseInt(t,10);if(isNaN(n))return null;const a=i[1];return{id:n,mapKey:o.URI_TO_EXTMAP_ID.get(a)||0}})).filter((e=>null!==e))}static parseSsrcs(e){const i=new Map;return e.filter((e=>e.startsWith("a=ssrc:"))).forEach((e=>{const t=e.substring(7).split(" ");if(t.length>=2){const e=parseInt(t[0],10);if(isNaN(e))return;const n=e,a=i.get(n)||{};if(t[1].startsWith("cname:"))a.cname=t[1].substring(6);else if(t[1].startsWith("msid:")){let e="";for(let i=1;i<t.length;i++)e+=t[i].substring(1===i?5:0)+(t.length-1!==i?" ":"");a.msid=e}i.set(n,a)}})),Array.from(i.entries()).map((([e,i])=>({id:e,cname:i.cname||"",msid:i.msid||""})))}static parseSsrcGroups(e){return e.filter((e=>e.startsWith("a=ssrc-group:"))).map((e=>{const i=e.substring(13).split(" ");return i.length>=2?{semantics:i[0],ssrcs:i.slice(1).map((e=>parseInt(e,10))).filter((e=>!isNaN(e)))}:null})).filter((e=>null!==e))}static parseCandidates(e){return e.filter((e=>e.startsWith("a=candidate:"))).map((e=>o.parseCandidate(e.substring(12)))).filter((e=>null!==e))}static parseCandidate(e){const i=e.split(" ");if(i.length<8)return null;const t=parseInt(i[0],10);if(isNaN(t))return null;const n=parseInt(i[1],10);if(isNaN(n))return null;let a;switch(i[2].toLowerCase()){case"udp":default:a=l.IceCandidateProtocol.UDP;break;case"tcp":a=l.IceCandidateProtocol.TCP}const s=parseInt(i[3],10);if(isNaN(s))return null;const o=i[4].split("."),r=new Uint8Array(o.map((e=>parseInt(e,10)))),d=parseInt(i[5],10);if(isNaN(d))return null;let c;switch(i[7].toLowerCase()){case"host":default:c=l.IceCandidateType.HOST;break;case"srflx":c=l.IceCandidateType.SRFLX;break;case"prflx":c=l.IceCandidateType.PRFLX;break;case"relay":c=l.IceCandidateType.RELAY}let u=new Uint8Array(0),p=0,h=l.IceCandidateTcpType.ACTIVE,g=8;for(;g<i.length;){switch(i[g]){case"raddr":if(g+1<i.length){const e=i[++g];u=new Uint8Array(e.split(".").map((e=>parseInt(e,10))))}break;case"rport":g+1<i.length&&(p=parseInt(i[++g],10)||0);break;case"tcptype":if(g+1<i.length)switch(i[++g].toLowerCase()){case"active":default:h=l.IceCandidateTcpType.ACTIVE;break;case"passive":h=l.IceCandidateTcpType.PASSIVE;break;case"so":h=l.IceCandidateTcpType.SO}}g++}return{foundation:t,component:n,protocol:a,priority:s,ip:r,port:d,type:c,raddr:u,rport:p,tcptype:h}}static addToStringPool(e,i){if(0===i.length)return 0;const t=e.indexOf(i);return t>=0?t+1:(e.push(i),e.length)}static getFromStringPool(e,i){return 0===i||i>e.length?"":e[i-1]}static getCodecID(e){var i;return(null===(i=e.codecName)||void 0===i?void 0:i.id)||0}static getCodecName(e){if(!e.codecName)return null;const i=e.codecName;if(i.mapKey>0){const e=o.MAP_KEY_TO_CODEC_NAME.get(i.mapKey);if(e)return e}return o.dynamicCodecNames.get(i.id)||null}static filterVideoCodecs(e,i){if(0===i.length)return e;const t=[],n=new Set;return e.forEach((e=>{const a=o.getCodecName(e);if(!a)return;const l=a.split("/")[0];i.some((e=>e.toLowerCase()===l.toLowerCase()))&&(t.push(e),n.add(o.getCodecID(e)))})),e.forEach((e=>{const i=o.getCodecName(e);if(i&&i.toLowerCase().startsWith("rtx/")){const i=e.fmtp.find((e=>"apt"===e.key)),a=i?parseInt(i.value,10):null;null!==a&&!isNaN(a)&&n.has(a)&&t.push(e)}})),t}static buildMediaSection(e,i,t){var n,a,r,d,c,u,p,h,g,v;let S;switch(i.type){case l.MediaType.AUDIO:S="audio";break;case l.MediaType.VIDEO:S="video";break;case l.MediaType.MEDIA_TYPE_UNSPECIFIED:return void s.error("Cannot reconstruct MEDIA_TYPE_UNSPECIFIED")}const f=(null===(n=null==i?void 0:i.codecs)||void 0===n?void 0:n.map((e=>o.getCodecID(e).toString())).join(" "))||"";e.push(`m=${S} ${i.port} UDP/TLS/RTP/SAVPF ${f}\r\n`);const C=(null==i?void 0:i.connectionAddress)||(null==t?void 0:t.connectionAddress)||"0.0.0.0";e.push(`c=IN IP4 ${C}\r\n`),(null===(a=null==i?void 0:i.rtcpAddress)||void 0===a?void 0:a.length)>0&&e.push(`a=rtcp:${i.rtcpAddress}\r\n`);const I=(null==i?void 0:i.iceUfragRef)>0?o.getFromStringPool(null==t?void 0:t.stringPool,null==i?void 0:i.iceUfragRef):null==t?void 0:t.iceUfrag,m=(null==i?void 0:i.icePwdRef)>0?o.getFromStringPool(null==t?void 0:t.stringPool,null==i?void 0:i.icePwdRef):null==t?void 0:t.icePwd;I.length>0&&e.push(`a=ice-ufrag:${I}\r\n`),m.length>0&&e.push(`a=ice-pwd:${m}\r\n`);const E=(null==i?void 0:i.iceOptions)||(null==t?void 0:t.iceOptions);E.length>0&&e.push(`a=ice-options:${E.join(" ")}\r\n`);const P=(null===(d=null===(r=null==i?void 0:i.fingerprint)||void 0===r?void 0:r.hashValue)||void 0===d?void 0:d.length)>0?null==i?void 0:i.fingerprint:null==t?void 0:t.fingerprint;(null===(c=null==P?void 0:P.hashValue)||void 0===c?void 0:c.length)>0&&e.push(`a=fingerprint:${o.fingerprintToString(P)}\r\n`);const b=(null==i?void 0:i.setup)!==l.DTLSSetup.ACTPASS||(null==t?void 0:t.setup)===l.DTLSSetup.ACTPASS?i.setup:t.setup;e.push(`a=setup:${o.setupToString(b)}\r\n`),e.push(`a=mid:${null==i?void 0:i.mid}\r\n`),null===(u=null==i?void 0:i.extmaps)||void 0===u||u.forEach((i=>{const t=o.EXTMAP_ID_TO_URI.get(i.mapKey)||`urn:ietf:params:rtp-hdrext:extension-${i.id}`;e.push(`a=extmap:${i.id} ${t}\r\n`)})),e.push(`a=${o.directionToString(null==i?void 0:i.direction)}\r\n`);const y=o.reconstructMSID(null==i?void 0:i.msidStream,null==i?void 0:i.msidTrackLabel,null==i?void 0:i.msidTrackId);(null==y?void 0:y.length)>0&&e.push(`a=msid:${y}\r\n`),(null==i?void 0:i.rtcpMux)&&e.push("a=rtcp-mux\r\n"),(null==i?void 0:i.rtcpRsize)&&e.push("a=rtcp-rsize\r\n"),null===(p=null==i?void 0:i.codecs)||void 0===p||p.forEach((i=>{var t,n;const a=o.getCodecID(i),l=o.getCodecName(i);if(l&&e.push(`a=rtpmap:${a} ${l}\r\n`),null===(t=null==i?void 0:i.rtcpFeedbackIds)||void 0===t||t.forEach((i=>{const t=o.RTCP_FEEDBACK_ID_TO_STRING.get(i);t&&e.push(`a=rtcp-fb:${a} ${t}\r\n`)})),(null===(n=null==i?void 0:i.fmtp)||void 0===n?void 0:n.length)>0){const t=o.reconstructFmtp(i.fmtp);e.push(`a=fmtp:${a} ${t}\r\n`)}})),null===(h=null==i?void 0:i.ssrcGroups)||void 0===h||h.forEach((i=>{const t=i.ssrcs.map((e=>(e>>>0).toString())).join(" ");e.push(`a=ssrc-group:${i.semantics} ${t}\r\n`)})),null===(g=null==i?void 0:i.ssrcs)||void 0===g||g.forEach((i=>{var t,n;const a=(i.id>>>0).toString();(null===(t=null==i?void 0:i.cname)||void 0===t?void 0:t.length)>0&&e.push(`a=ssrc:${a} cname:${i.cname}\r\n`),(null===(n=null==i?void 0:i.msid)||void 0===n?void 0:n.length)>0&&e.push(`a=ssrc:${a} msid:${i.msid}\r\n`)})),null===(v=null==i?void 0:i.candidates)||void 0===v||v.forEach((i=>{e.push(`a=candidate:${o.reconstructCandidate(i)}\r\n`)})),(null==i?void 0:i.endOfCandidates)&&e.push("a=end-of-candidates\r\n")}static reconstructMSID(e,i,t){return 0===e.length?"":0===i.length&&0===t?e:t>0&&i.length>0?`${e} ${i}${t}`:i.length>0?`${e} ${i}`:e}static reconstructFmtp(e){return e.map((e=>"value"===e.key?e.value:`${e.key}=${e.value}`)).join(";")}static fingerprintToString(e){let i;switch(e.hashFunc){case l.HashFunction.SHA256:i="sha-256";break;case l.HashFunction.SHA1:i="sha-1";break;case l.HashFunction.SHA384:i="sha-384";break;case l.HashFunction.SHA512:i="sha-512";break;case l.HashFunction.MD5:i="md5"}return`${i} ${Array.from(e.hashValue).map((e=>e.toString(16).padStart(2,"0").toUpperCase())).join(":")}`}static setupToString(e){switch(e){case l.DTLSSetup.ACTIVE:return"active";case l.DTLSSetup.PASSIVE:return"passive";case l.DTLSSetup.ACTPASS:return"actpass"}}static directionToString(e){switch(e){case l.MediaDirection.SENDONLY:return"sendonly";case l.MediaDirection.RECVONLY:return"recvonly";case l.MediaDirection.INACTIVE:return"inactive";default:return"sendrecv"}}static reconstructCandidate(e){const i=e.protocol===l.IceCandidateProtocol.UDP?"udp":"tcp";let t;switch(e.type){case l.IceCandidateType.HOST:t="host";break;case l.IceCandidateType.SRFLX:t="srflx";break;case l.IceCandidateType.PRFLX:t="prflx";break;case l.IceCandidateType.RELAY:t="relay"}const n=[e.foundation.toString(),e.component.toString(),i,e.priority.toString(),Array.from(e.ip).map((e=>(255&e).toString())).join("."),e.port.toString(),"typ",t];if(e.raddr.length>0){n.push("raddr");const i=Array.from(e.raddr).map((e=>(255&e).toString())).join(".");n.push(i)}if(e.rport>0&&(n.push("rport"),n.push(e.rport.toString())),"tcp"===i){let i;switch(e.tcptype){case l.IceCandidateTcpType.ACTIVE:i="active";break;case l.IceCandidateTcpType.PASSIVE:i="passive";break;case l.IceCandidateTcpType.SO:i="so"}n.push("tcptype"),n.push(i)}return n.join(" ")}}i.SdpConverter=o,o.EXTMAP_ID_TO_URI=new Map([[1,"urn:ietf:params:rtp-hdrext:toffset"],[2,"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"],[3,"urn:3gpp:video-orientation"],[4,"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"],[5,"http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"],[6,"http://www.webrtc.org/experiments/rtp-hdrext/video-content-type"],[7,"http://www.webrtc.org/experiments/rtp-hdrext/video-timing"],[8,"http://www.webrtc.org/experiments/rtp-hdrext/color-space"],[9,"urn:ietf:params:rtp-hdrext:sdes:mid"],[10,"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"],[11,"urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"],[14,"urn:ietf:params:rtp-hdrext:ssrc-audio-level"],[15,"urn:ietf:params:rtp-hdrext:csrc-audio-level"]]),o.URI_TO_EXTMAP_ID=new Map(Array.from(o.EXTMAP_ID_TO_URI.entries()).map((([e,i])=>[i,e]))),o.RTCP_FEEDBACK_ID_TO_STRING=new Map([[1,"goog-remb"],[2,"transport-cc"],[3,"ccm fir"],[4,"nack"],[5,"nack pli"]]),o.RTCP_FEEDBACK_STRING_TO_ID=new Map(Array.from(o.RTCP_FEEDBACK_ID_TO_STRING.entries()).map((([e,i])=>[i,e]))),o.dynamicCodecNames=new Map,o.CODEC_NAME_TO_MAP_KEY=new Map([["VP8/90000",1],["VP9/90000",2],["AV1/90000",3],["H264/90000",4],["H265/90000",5],["rtx/90000",6],["red/90000",7],["ulpfec/90000",8],["opus/48000/2",9],["red/48000/2",10],["G722/8000",11],["G722/8000/1",11],["PCMU/8000",12],["PCMA/8000",13],["CN/8000",14],["telephone-event/48000",15],["telephone-event/8000",16],["telephone-event/8000/1",16],["ILBC/8000",17]]),o.MAP_KEY_TO_CODEC_NAME=new Map([[1,"VP8/90000"],[2,"VP9/90000"],[3,"AV1/90000"],[4,"H264/90000"],[5,"H265/90000"],[6,"rtx/90000"],[7,"red/90000"],[8,"ulpfec/90000"],[9,"opus/48000/2"],[10,"red/48000/2"],[11,"G722/8000"],[12,"PCMU/8000"],[13,"PCMA/8000"],[14,"CN/8000"],[15,"telephone-event/48000"],[16,"telephone-event/8000"],[17,"ILBC/8000"]])},799:(e,i)=>{"use strict";var t,n,a,l,s,o,r;Object.defineProperty(i,"__esModule",{value:!0}),i.IceCandidateTcpType=i.IceCandidateType=i.IceCandidateProtocol=i.MediaDirection=i.MediaType=i.DTLSSetup=i.HashFunction=void 0,function(e){e[e.SHA256=0]="SHA256",e[e.SHA1=1]="SHA1",e[e.SHA384=2]="SHA384",e[e.SHA512=3]="SHA512",e[e.MD5=4]="MD5"}(t||(i.HashFunction=t={})),function(e){e[e.ACTIVE=0]="ACTIVE",e[e.PASSIVE=1]="PASSIVE",e[e.ACTPASS=2]="ACTPASS"}(n||(i.DTLSSetup=n={})),function(e){e[e.AUDIO=0]="AUDIO",e[e.VIDEO=1]="VIDEO",e[e.MEDIA_TYPE_UNSPECIFIED=2]="MEDIA_TYPE_UNSPECIFIED"}(a||(i.MediaType=a={})),function(e){e[e.SENDRECV=0]="SENDRECV",e[e.SENDONLY=1]="SENDONLY",e[e.RECVONLY=2]="RECVONLY",e[e.INACTIVE=3]="INACTIVE"}(l||(i.MediaDirection=l={})),function(e){e[e.UDP=0]="UDP",e[e.TCP=1]="TCP"}(s||(i.IceCandidateProtocol=s={})),function(e){e[e.HOST=0]="HOST",e[e.SRFLX=1]="SRFLX",e[e.PRFLX=2]="PRFLX",e[e.RELAY=3]="RELAY"}(o||(i.IceCandidateType=o={})),function(e){e[e.ACTIVE=0]="ACTIVE",e[e.PASSIVE=1]="PASSIVE",e[e.SO=2]="SO"}(r||(i.IceCandidateTcpType=r={}))},828:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.QueuedSignal=void 0;const n=t(795),a=t(429);i.QueuedSignal=class{constructor(e,i,t=n.SignalQueueStrategy.getSignalPriority(e),l=Date.now(),s=0,o=(0,a.v4)()){this.signal=e,this.callback=i,this.priority=t,this.timestamp=l,this.requeueCount=s,this.uniqueKey=o}get callId(){return this.signal.callId}compareTo(e){const i=e.priority-this.priority;return 0!==i?i:this.timestamp-e.timestamp}toString(){return`QueuedSignal(signal=${JSON.stringify(this.signal)}, timestamp=${this.timestamp}, priority=${this.priority}, requeueCount=${this.requeueCount}, uniqueKey=${this.uniqueKey})`}}},795:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SignalQueueStrategy=i.SignalProcessingStrategy=void 0;const n=t(578),a=t(586),l=t(228);var s;!function(e){e[e.SEQUENTIAL=0]="SEQUENTIAL",e[e.IMMEDIATE=1]="IMMEDIATE"}(s||(i.SignalProcessingStrategy=s={}));class o{static getProcessingStrategy(e){return this.SEQUENTIAL_SIGNALS.has(e)?s.SEQUENTIAL:s.IMMEDIATE}static isSequentialSignal(e){return this.getProcessingStrategy(e)===s.SEQUENTIAL}static isImmediateSignal(e){return this.getProcessingStrategy(e)===s.IMMEDIATE}static getSignalPriorityValue(e){switch(e){case n.SignalEvent.JOIN:return 10;case n.SignalEvent.LEAVE:case n.SignalEvent.DECLINE:return 9;case n.SignalEvent.MEDIA_CONNECTED:return 8;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:case n.SignalEvent.CONNECT:case n.SignalEvent.ICE:return 7;case n.SignalEvent.KICK:case n.SignalEvent.INVITE:case n.SignalEvent.RINGING:case n.SignalEvent.INFO:case n.SignalEvent.UPDATE:case n.SignalEvent.GET_CALL:case n.SignalEvent.SWITCH_MEDIA_FLOW:return 6;case n.SignalEvent.MUTE:case n.SignalEvent.UNMUTE:case n.SignalEvent.VIDEO_ON:case n.SignalEvent.VIDEO_OFF:case n.SignalEvent.HOLD:case n.SignalEvent.UNHOLD:case n.SignalEvent.SCREEN_SHARE_ON:case n.SignalEvent.SCREEN_SHARE_OFF:case n.SignalEvent.DISABLE_REMOTE_AUDIO:case n.SignalEvent.DISABLE_REMOTE_VIDEO:case n.SignalEvent.CALL_PERMISSIONS_UPDATE:case n.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE:return 5;case n.SignalEvent.ERROR:case n.SignalEvent.SUCCESS:case n.SignalEvent.CLOSE:case n.SignalEvent.NO_ANSWER:throw(0,l.checkCode)(4e3,`SignalEvent ${e} should not be in queue`);default:return 0}}static getSignalPriority(e){if("number"!=typeof e.event)throw(0,l.checkCode)(4e3,`Signal event is not a number for signal: ${JSON.stringify(e)}`);return this.getSignalPriorityValue(e.event)}static getSignalLevel(e){switch(e.event){case n.SignalEvent.JOIN:case n.SignalEvent.LEAVE:case n.SignalEvent.DECLINE:return a.SignalLevel.GlobalBlocking;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:case n.SignalEvent.ICE:case n.SignalEvent.CONNECT:return a.SignalLevel.ParticipantLevel;default:return a.SignalLevel.Immediate}}}i.SignalQueueStrategy=o,o.SEQUENTIAL_SIGNALS=new Set([n.SignalEvent.JOIN,n.SignalEvent.LEAVE,n.SignalEvent.DECLINE,n.SignalEvent.OFFER,n.SignalEvent.ANSWER,n.SignalEvent.CONNECT])},586:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.SignalingQueue=i.SignalLevel=void 0;const a=t(795),l=t(645),s=t(578),o=(0,l.createLogger)("SignalingQueue");var r;!function(e){e[e.GlobalBlocking=0]="GlobalBlocking",e[e.ParticipantLevel=1]="ParticipantLevel",e[e.Immediate=2]="Immediate"}(r||(i.SignalLevel=r={})),i.SignalingQueue=class{constructor(e,i,t){this.id=e,this.isTransportConnected=i,this.sender=t,this.globalBlockingSignals=[],this.immediateSignals=[],this.participantSignals=new Map,this.processingSignalJobs=new Map,this.participantJobs=new Map,this.sentSignals=new Set}getSignalKey(e,i){return`${i}_${e.event}_${e.callId}_${e.sessionId||""}`}addSignalToQueue(e){const i=this.getSignalKey(e.signal,e.uniqueKey);if(this.sentSignals.has(i))return void o.info(`[38] [CallId: ${e.signal.callId}] Signal already sent, skipping: ${s.SignalEvent[e.signal.event]}`);const t=a.SignalQueueStrategy.getSignalLevel(e.signal);switch(t){case r.GlobalBlocking:this.globalBlockingSignals.push(e);break;case r.ParticipantLevel:const i=e.signal.to||"";this.participantSignals.has(i)||this.participantSignals.set(i,[]),this.participantSignals.get(i).push(e);break;case r.Immediate:this.immediateSignals.push(e)}o.info(`[61] [CallId: ${e.signal.callId}] Add signal to queue ===> level: ${t}, signal Event: ${s.SignalEvent[e.signal.event]}, uniqueKey: ${e.uniqueKey}`),this.invalidateToSendSignalsIfNeeded()}removeSignalFromQueue(e){const i=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.delete(i)}invalidateToSendSignalsIfNeeded(){this.isTransportConnected()?this.globalBlockingSignals.length>0?this.sendGlobalBlockingSignals():(this.sendParticipantSignals(),this.sendImmediateLevelSignals()):o.info(`[75] [CallId: ${this.id}] Connection is not established, skipping signal processing`)}triggerSignalProcessing(){this.invalidateToSendSignalsIfNeeded()}sendGlobalBlockingSignals(){return n(this,void 0,void 0,(function*(){if(!this.processingSignalJobs.get(r.GlobalBlocking)){this.processingSignalJobs.set(r.GlobalBlocking,!0);try{for(;this.isTransportConnected();){const e=this.globalBlockingSignals.shift();if(!e)break;const i=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.has(i)?o.info(`[107] [CallId: ${this.id}] Global blocking signal already sent, skipping: ${s.SignalEvent[e.signal.event]}`):(o.info(`[111] [CallId: ${this.id}] Sending ${r.GlobalBlocking} level signal: ${s.SignalEvent[e.signal.event]}`),yield this.sendSignal(e),this.sentSignals.add(i))}}finally{this.processingSignalJobs.delete(r.GlobalBlocking),0===this.globalBlockingSignals.length&&(this.sendParticipantSignals(),this.sendImmediateLevelSignals())}}}))}sendImmediateLevelSignals(){return n(this,void 0,void 0,(function*(){if(!(this.globalBlockingSignals.length>0||this.processingSignalJobs.get(r.Immediate))){this.processingSignalJobs.set(r.Immediate,!0);try{for(;this.isTransportConnected()&&0===this.globalBlockingSignals.length;){const e=this.immediateSignals.shift();if(!e)break;const i=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.has(i)?o.info(`[145] [CallId: ${this.id}] Immediate signal already sent, skipping: ${s.SignalEvent[e.signal.event]}`):(o.info(`[148] [CallId: ${this.id}] Sending ${r.Immediate} level signal: ${s.SignalEvent[e.signal.event]}`),yield this.sendSignal(e),this.sentSignals.add(i))}}finally{this.processingSignalJobs.delete(r.Immediate)}}}))}sendParticipantSignals(){if(!(this.globalBlockingSignals.length>0))for(const[e,i]of this.participantSignals.entries())i.length>0&&this.sendParticipantSignal(e,i)}sendParticipantSignal(e,i){return n(this,void 0,void 0,(function*(){if(!this.participantJobs.get(e)){this.participantJobs.set(e,!0);try{for(;this.isTransportConnected()&&0===this.globalBlockingSignals.length;){const t=i.shift();if(!t)break;const n=this.getSignalKey(t.signal,t.uniqueKey);this.sentSignals.has(n)?o.info(`[185] [CallId: ${this.id}] Participant signal already sent, skipping: ${s.SignalEvent[t.signal.event]}`):(o.info(`[188] [CallId: ${this.id}] Sending ${r.ParticipantLevel} level signal for identity ${e}: ${s.SignalEvent[t.signal.event]}`),yield this.sendSignal(t),this.sentSignals.add(n))}}finally{this.participantJobs.delete(e),0===i.length&&this.participantSignals.delete(e)}}}))}sendSignal(e){return n(this,void 0,void 0,(function*(){a.SignalQueueStrategy.getProcessingStrategy(e.signal.event)===a.SignalProcessingStrategy.SEQUENTIAL?yield this.sender(e):this.sender(e).catch((e=>{o.error(`[209] [CallId: ${this.id}] Error sending signal: ${e}`)}))}))}clearParticipantSignals(e){this.participantSignals.delete(e),this.participantJobs.delete(e),o.info(`[213] [CallId: ${this.id}] Cleared participant signals for identity: ${e}, queueId: ${this.id}`)}clearCallSignals(){this.globalBlockingSignals=[],this.immediateSignals=[],this.participantSignals.clear(),this.processingSignalJobs.clear(),this.participantJobs.clear(),this.sentSignals.clear(),o.info(`[227] [CallId: ${this.id}] Cleared all signals for queueId: ${this.id}`)}getGlobalBlockingSignals(){return this.globalBlockingSignals}}},786:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.Signaling=void 0;const a=t(578),l=t(645),s=t(828),o=t(586),r=t(228),d=t(65),c=t(429),u=(0,l.createLogger)("Signaling");class p{constructor(e,i){this.signalingQueues=new Map,this.chatClient=e;const t=new this.chatClient.ChannelListener;t.onSignal=e=>{i(e)},this.chatClient.addChannelListener("call_listeners",t)}calculateRetryDelay(e){return Math.min(p.BASE_DELAY_MS*Math.pow(2,e),p.MAX_DELAY_MS)}handleRetry(e,i,t,a){var l;return n(this,void 0,void 0,(function*(){if(i>=p.MAX_RETRIES)throw u.error(`[45] [CallId: ${e.signal.callId}] Max retries exceeded for signal: ${JSON.stringify(e.signal)}`,{color:"red"}),(0,r.toCallException)(t);t instanceof d.SceytCallException&&!t.isResendable&&(u.error(`[49] [CallId: ${e.signal.callId}] Signal sending failed with non-resendable exception: ${t.message}`,{color:"red"}),null===(l=e.callback)||void 0===l||l.call(e,t),a.removeSignalFromQueue(e));const n=this.calculateRetryDelay(i);u.error(`[53] [CallId: ${e.signal.callId}] Sending signal failed with error: ${t.message}, but ChatClient is connected. Retrying in ${n}ms (attempt ${i+1}/${p.MAX_RETRIES})`,{color:"red"}),yield new Promise((e=>setTimeout(e,n)));try{const i=yield this.sendSignalSuspended(e);return u.info(`[64] [CallId: ${e.signal.callId}] Retry sending signal success: ${JSON.stringify(i)}`),i}catch(t){return u.error(`[67] [CallId: ${e.signal.callId}] Retry sending signal failed: ${t instanceof Error?t.message:String(t)}`),this.handleRetry(e,i+1,t instanceof Error?t:new Error(String(t)),a)}}))}sendSignalSuspended(e){return n(this,void 0,void 0,(function*(){try{u.info(`[78] [CallId: ${e.signal.callId}] Sending signal ${a.SignalEvent[e.signal.event]} to chat client: version: 132`);const i=yield this.chatClient.sendSignal(e.signal,132);if(null==i?void 0:i.error)throw(0,r.toCallException)(i.error);return(0,r.handleAck)(i)}catch(e){throw(0,r.toCallException)(e)}}))}sendSignalMessage(e,i,t){var l,h,g,v,S,f,C;const I=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({mediaFlow:e.mediaFlow,callId:e.callId},e.sessionId&&{sessionId:e.sessionId}),{event:e.event}),e.sessionData&&{sessionData:e.sessionData}),e.to&&{to:e.to}),{participants:e.participants?e.participants:[]}),e.ice&&{ice:e.ice}),e.metadata?{metadata:e.metadata}:{metadata:{}}),e.callOptions&&{callOptions:Object.assign(Object.assign({},e.callOptions||{}),{settings:Object.assign(Object.assign({},(null===(l=null==e?void 0:e.callOptions)||void 0===l?void 0:l.settings)||{}),{permissions:{audioPublishingDisabled:!(null===(v=null===(g=null===(h=null==e?void 0:e.callOptions)||void 0===h?void 0:h.settings)||void 0===g?void 0:g.permissions)||void 0===v?void 0:v.allowPublishAudio),videoPublishingDisabled:!(null===(C=null===(f=null===(S=null==e?void 0:e.callOptions)||void 0===S?void 0:S.settings)||void 0===f?void 0:f.permissions)||void 0===C?void 0:C.allowPublishVideo)}})})}),e.joinOptions&&{joinOptions:e.joinOptions}),e.broadcastUsers&&{broadcastUsers:e.broadcastUsers});u.info(`[92] [CallId: ${e.callId}] Sending signal message request: ${a.SignalEvent[e.event]} uniqueKey: ${(0,c.v4)()} ${JSON.stringify(I)}`,{color:"yellow"});const m=t||e.callId;let E=this.signalingQueues.get(m);E||(E=new o.SignalingQueue(m,(()=>"Connected"===this.chatClient.connectionState),(e=>n(this,void 0,void 0,(function*(){var i,t,n,l,o,h,g,v,S,f,C,I,m,P,b;try{const s=yield this.sendSignalSuspended(e),d=Object.assign(Object.assign({},s),{callOptions:Object.assign(Object.assign({},s.callOptions||{}),{settings:Object.assign(Object.assign({},(null===(i=null==s?void 0:s.callOptions)||void 0===i?void 0:i.settings)||{}),{permissions:Object.assign(Object.assign({},(null===(n=null===(t=null==s?void 0:s.callOptions)||void 0===t?void 0:t.settings)||void 0===n?void 0:n.permissions)||{}),{allowPublishAudio:!(null===(h=null===(o=null===(l=null==s?void 0:s.callOptions)||void 0===l?void 0:l.settings)||void 0===o?void 0:o.permissions)||void 0===h?void 0:h.audioPublishingDisabled),allowPublishVideo:!(null===(S=null===(v=null===(g=null==s?void 0:s.callOptions)||void 0===g?void 0:g.settings)||void 0===v?void 0:v.permissions)||void 0===S?void 0:S.videoPublishingDisabled)})})}),calls:null===(f=null==s?void 0:s.calls)||void 0===f?void 0:f.map((e=>{var i,t,n,a,l,s,o;return Object.assign(Object.assign({},e),{options:Object.assign(Object.assign({},(null==e?void 0:e.options)||{}),{settings:Object.assign(Object.assign({},(null===(i=null==e?void 0:e.options)||void 0===i?void 0:i.settings)||{}),{permissions:{allowPublishAudio:!(null===(a=null===(n=null===(t=null==e?void 0:e.options)||void 0===t?void 0:t.settings)||void 0===n?void 0:n.permissions)||void 0===a?void 0:a.audioPublishingDisabled),allowPublishVideo:!(null===(o=null===(s=null===(l=null==e?void 0:e.options)||void 0===l?void 0:l.settings)||void 0===s?void 0:s.permissions)||void 0===o?void 0:o.videoPublishingDisabled)}})})})}))});if(u.info(`[115] [CallId: ${e.signal.callId||"GLOBAL_LOGS"}] Sent signal message response: ${a.SignalEvent[e.signal.event]} uniqueKey: ${e.uniqueKey} ${JSON.stringify(d)}`,{color:"magenta"}),(null==s?void 0:s.event)===a.SignalEvent.ERROR)throw(0,r.checkCode)((null===(C=null==s?void 0:s.error)||void 0===C?void 0:C.code)||0,(null===(I=null==s?void 0:s.error)||void 0===I?void 0:I.message)||"Unknown error");return null===(m=e.callback)||void 0===m||m.call(e,d),null==E||E.removeSignalFromQueue(e),s}catch(i){if(u.error(`[125] [CallId: ${e.signal.callId||"GLOBAL_LOGS"}] Signal message error: ${a.SignalEvent[e.signal.event]} uniqueKey: ${e.uniqueKey} error: ${i instanceof Error?i.message:String(i)}, resendable: ${i instanceof d.SceytCallException&&i.isResendable}`,{color:"red"}),i instanceof d.SceytCallException&&i.isResendable){const t=e.requeueCount;t<p.REQUEUE_LIMIT?null==E||E.addSignalToQueue(new s.QueuedSignal(e.signal,e.callback,e.priority,e.timestamp,t+1,(0,c.v4)())):(u.error(`[140] [CallId: ${e.signal.callId||"GLOBAL_LOGS"}] Max requeue limit reached for signal: ${JSON.stringify(e.signal)}, will not requeue again. uniqueKey: ${e.uniqueKey}`,{color:"red"}),null===(P=e.callback)||void 0===P||P.call(e,i),null==E||E.removeSignalFromQueue(e))}const t=i instanceof d.SceytCallException?i:new Error(i instanceof Error?i.message:String(i));null===(b=e.callback)||void 0===b||b.call(e,t),null==E||E.removeSignalFromQueue(e)}})))),this.signalingQueues.set(m,E)),E.addSignalToQueue(new s.QueuedSignal(I,i,0,0,0,(0,c.v4)()))}clearCallSignals(e){const i=this.signalingQueues.get(e);i&&(i.clearCallSignals(),this.signalingQueues.delete(e))}clearParticipantSignals(e,i){const t=this.signalingQueues.get(e);t&&t.clearParticipantSignals(i)}cancelJoinIfPossible(e){const i=this.signalingQueues.get(e);return!!i&&!!i.getGlobalBlockingSignals().find((e=>e.signal.event==a.SignalEvent.JOIN))&&(i.clearCallSignals(),!0)}}i.Signaling=p,p.REQUEUE_LIMIT=10,p.MAX_RETRIES=10,p.BASE_DELAY_MS=1e3,p.MAX_DELAY_MS=8e3},342:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ReceiveSignalValidator=void 0;const n=t(578),a=(0,t(645).createLogger)("ReceiveSignalValidator");class l{static canHandleSignal(e,i){const t=l.validateSignal(e,i.state,i.localParticipant);return t||a.warn(`Cannot handle signal ${e.event} in call state ${i.state} with local participant state ${i.localParticipant.state}`),t}static validateSignal(e,i,t){switch(e.event){case n.SignalEvent.JOIN:case n.SignalEvent.LEAVE:return!0;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:return i===n.CallState.Connected;case n.SignalEvent.KICK:return!0;case n.SignalEvent.INVITE:return!e.participants||!e.participants.some((e=>e.id===t.id))||i===n.CallState.Idle;case n.SignalEvent.DECLINE:case n.SignalEvent.RINGING:case n.SignalEvent.INFO:case n.SignalEvent.UPDATE:case n.SignalEvent.CLOSE:return!0;case n.SignalEvent.ICE:return i===n.CallState.Connected;case n.SignalEvent.SWITCH_MEDIA_FLOW:case n.SignalEvent.NO_ANSWER:case n.SignalEvent.MUTE:case n.SignalEvent.UNMUTE:case n.SignalEvent.HOLD:case n.SignalEvent.UNHOLD:case n.SignalEvent.VIDEO_ON:case n.SignalEvent.VIDEO_OFF:case n.SignalEvent.SCREEN_SHARE_ON:case n.SignalEvent.SCREEN_SHARE_OFF:case n.SignalEvent.DISABLE_REMOTE_AUDIO:case n.SignalEvent.DISABLE_REMOTE_VIDEO:case n.SignalEvent.CALL_PERMISSIONS_UPDATE:case n.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE:case n.SignalEvent.MEDIA_CONNECTED:case n.SignalEvent.CONNECT:case n.SignalEvent.GET_CALL:return!0;default:return a.warn(`Unknown signal event for handling: ${e.event}`),!1}}}i.ReceiveSignalValidator=l},771:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SendSignalValidator=void 0;const n=t(578),a=(0,t(645).createLogger)("SendSignalValidator");class l{canSendSignal(e,i){const t=l.validateSignalEvent(e.event,i.state);return t||a.warn(`Cannot send signal ${e.event} in call state ${i.state} with local participant state ${i.localParticipant.state}`),t}canSendSignalEvent(e,i){const t=l.validateSignalEvent(e,i.state);return t||a.warn(`Cannot send signal ${e} in call state ${i.state} with local participant state ${i.localParticipant.state}`),t}static validateSignalEvent(e,i){const t=i===n.CallState.Connected;switch(e){case n.SignalEvent.JOIN:return!0;case n.SignalEvent.LEAVE:return t;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:case n.SignalEvent.CONNECT:case n.SignalEvent.KICK:case n.SignalEvent.INVITE:return i===n.CallState.Connected;case n.SignalEvent.DECLINE:return i===n.CallState.Idle;case n.SignalEvent.RINGING:return i===n.CallState.Idle||i===n.CallState.Connecting;case n.SignalEvent.INFO:case n.SignalEvent.UPDATE:return i===n.CallState.Connected;case n.SignalEvent.ICE:case n.SignalEvent.GET_CALL:return!0;case n.SignalEvent.SWITCH_MEDIA_FLOW:case n.SignalEvent.MEDIA_CONNECTED:return i===n.CallState.Connected;case n.SignalEvent.MUTE:case n.SignalEvent.UNMUTE:case n.SignalEvent.HOLD:case n.SignalEvent.UNHOLD:case n.SignalEvent.VIDEO_ON:case n.SignalEvent.VIDEO_OFF:case n.SignalEvent.DISABLE_REMOTE_AUDIO:case n.SignalEvent.DISABLE_REMOTE_VIDEO:case n.SignalEvent.CALL_PERMISSIONS_UPDATE:case n.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE:return t;case n.SignalEvent.SCREEN_SHARE_ON:case n.SignalEvent.SCREEN_SHARE_OFF:return i===n.CallState.Connected;default:return a.warn(`Unknown signal event for sending: ${e}`),!1}}}i.SendSignalValidator=l},302:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ReceiveSignalValidator=i.SendSignalValidator=void 0;var n=t(771);Object.defineProperty(i,"SendSignalValidator",{enumerable:!0,get:function(){return n.SendSignalValidator}});var a=t(342);Object.defineProperty(i,"ReceiveSignalValidator",{enumerable:!0,get:function(){return a.ReceiveSignalValidator}})},740:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.VideoTrack=void 0,i.VideoTrack=class{constructor(e){this._enabled=!0,this.id=e.id,this.videoTrack=e}set enabled(e){this._enabled=e,this.videoTrack.enabled=e}get enabled(){return this._enabled}}},546:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.WebRTCClient=void 0;const a=t(578),l=t(645),s=t(19),o=t(680),r=(0,l.createLogger)("WebRTCClient");i.WebRTCClient=class{constructor(e,i){this.listeners={},this.sessionId=null,this.version=null,this.iceQueueMap={},this.configuration=i,this.peerConnection=new RTCPeerConnection(this.configuration),this.callId=e}setSessionId(e){this.sessionId=e}getSessionId(){return this.sessionId||""}setVersion(e){this.version=e}getVersion(){return this.version||""}setListeners(e){r.info(`[18] [CallId: ${this.callId}] setListeners in webrtcClient: listeners`,{color:"blue"}),this.listeners=e}setConfiguration(e){r.info(`[21] [CallId: ${this.callId}] setConfiguration in webrtcClient: configuration: ${e}`,{color:"blue"}),this.configuration=e}getPreferredAudioCodecs(e){const i=RTCRtpReceiver.getCapabilities("audio");return i?i.codecs.filter((i=>{const t=i.mimeType.split("/")[1].toLowerCase();return e===a.MediaFlow.S2W?s.CODEC_NAME_TO_AUDIO_CODEC_S2W.includes(t):s.CODEC_NAME_TO_AUDIO_CODEC.includes(t)})):[]}getPreferredVideoCodecs(){const e=RTCRtpSender.getCapabilities("video");if(!e)return[];const i=[];return s.CODEC_NAME_TO_VIDEO_CODEC.forEach((t=>{const n=e.codecs.find((e=>e.mimeType.split("/")[1].toLowerCase()===t.toLowerCase()));n&&i.push(n)})),i}setPreferredCodecs(e,i,t){if("video"===i){r.info(`[74] [CallId: ${this.callId}] setPreferredCodecs: video, mediaFlow: ${e}`,{color:"blue"});const i=this.getPreferredVideoCodecs(),n=[];i.forEach((e=>{n.push({mimeType:e.mimeType,clockRate:e.clockRate,sdpFmtpLine:e.sdpFmtpLine,channels:e.channels})})),t.setCodecPreferences(n)}else if("audio"===i){r.info(`[88] [CallId: ${this.callId}] setPreferredCodecs: audio, mediaFlow: ${e}`,{color:"blue"});const i=this.getPreferredAudioCodecs(e),n=[];i.forEach((e=>{n.push({mimeType:e.mimeType,clockRate:e.clockRate,sdpFmtpLine:e.sdpFmtpLine||"",channels:e.channels||void 0})})),t.setCodecPreferences(n)}}addTransceiverToPeerConnection(e,i){return n(this,void 0,void 0,(function*(){r.info(`[56] [CallId: ${this.callId}] addTransceiverToPeerConnection in webrtcClient: track: ${null==e?void 0:e.kind}`,{color:"blue"}),this.peerConnection.addTransceiver(e,{direction:"sendrecv"});const t=this.peerConnection.getTransceivers().find((i=>{var t;return(null===(t=i.receiver.track)||void 0===t?void 0:t.kind)===(null==e?void 0:e.kind)}));if(t&&"video"===(null==e?void 0:e.kind)){this.setPreferredCodecs(i,"video",t);try{const e=t.sender.getParameters();e.encodings&&e.encodings.length>0&&(e.encodings.forEach((e=>{e.maxBitrate=5e5})),yield t.sender.setParameters(e),r.info(`[57] [CallId: ${this.callId}] addTransceiverToPeerConnection: Set video max bitrate to 500 kbps`,{color:"blue"}))}catch(e){r.warn(`[58] [CallId: ${this.callId}] addTransceiverToPeerConnection: Failed to set video bitrate: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"yellow"})}}else t&&"audio"===(null==e?void 0:e.kind)&&this.setPreferredCodecs(i,"audio",t)}))}setStreamsToTransceiver(e){var i,t;return n(this,void 0,void 0,(function*(){r.info(`[61] [CallId: ${this.callId}] setStreamsToTransceiver in webrtcClient: track: ${null==e?void 0:e.kind}`,{color:"blue"});const n=this.peerConnection.getTransceivers();r.info(`[62] [CallId: ${this.callId}] setStreamsToTransceiver: transceivers: ${n.length}`,{color:"blue"});const a=null==e?void 0:e.kind;let l=n.find((e=>{var i,t;const n=null===(i=e.receiver.track)||void 0===i?void 0:i.kind,l=null===(t=e.sender.track)||void 0===t?void 0:t.kind;return n===a||l===a}));if(r.info(`[63] [CallId: ${this.callId}] setStreamsToTransceiver: transceiver found: ${!!l}, receiver track: ${null===(i=null==l?void 0:l.receiver.track)||void 0===i?void 0:i.kind}, sender track: ${null===(t=null==l?void 0:l.sender.track)||void 0===t?void 0:t.kind}, current direction: ${null==l?void 0:l.direction}, mid: ${null==l?void 0:l.mid}`,{color:"blue"}),l){if(null!==l.sender.track)return void r.info(`[64] [CallId: ${this.callId}] setStreamsToTransceiver: Track already attached, skipping to avoid renegotiation`,{color:"blue"});e&&(e.enabled=!0),l.direction="sendrecv",yield l.sender.replaceTrack(e);const i=l.direction,t=l.sender.track,n=t?t.kind:"null";r.info(`[65] [CallId: ${this.callId}] setStreamsToTransceiver: Attached local ${a} track to transceiver, direction: ${i}, sender track: ${n}, track enabled: ${null==e?void 0:e.enabled}, track id: ${null==e?void 0:e.id}`,{color:"blue"}),t||r.error(`[66] [CallId: ${this.callId}] setStreamsToTransceiver: Failed to attach ${a} track - sender track is still null after replaceTrack`,{color:"red"})}else{const e=n.map((e=>{var i,t;return{mid:e.mid,receiverKind:(null===(i=e.receiver.track)||void 0===i?void 0:i.kind)||"null",senderKind:(null===(t=e.sender.track)||void 0===t?void 0:t.kind)||"null",direction:e.direction}}));r.warn(`[67] [CallId: ${this.callId}] setStreamsToTransceiver: No transceiver found for track kind: ${a}. Available transceivers: ${JSON.stringify(e)}`,{color:"yellow"})}}))}enableVideoOnPeerConnection(e,i,t=!1){return n(this,void 0,void 0,(function*(){r.info(`[27] [CallId: ${this.callId}] enableVideoOnPeerConnection in webrtcClient: enable: ${e}, kind: ${null==i?void 0:i.kind}`,{color:"blue"});const n=this.peerConnection.getTransceivers();for(let a=0;a<n.length;a++){const l=n[a];if(l.sender.track&&"video"===l.sender.track.kind){i?(i.enabled=e,yield l.sender.replaceTrack(i)):l.sender.track.enabled=e;const n=l.sender.getParameters();n.encodings&&n.encodings.length>0&&(n.encodings.forEach((e=>{e.maxBitrate=t?75e4:5e5})),yield l.sender.setParameters(n),r.info(`[184] [CallId: ${this.callId}] enableVideoOnPeerConnection: Set video max bitrate to ${t?75e4:5e5} kbps`,{color:"blue"}))}}}))}enableAudioOnPeerConnection(e,i){return n(this,void 0,void 0,(function*(){r.info(`[33] [CallId: ${this.callId}] enableAudioOnPeerConnection in webrtcClient: mute: ${e}, kind: ${null==i?void 0:i.kind}`,{color:"blue"});const t=this.peerConnection.getTransceivers();for(let n=0;n<t.length;n++){const a=t[n];a.sender.track&&"audio"===a.sender.track.kind&&(i?(i.enabled=!e,yield a.sender.replaceTrack(i)):a.sender.track.enabled=!e)}}))}createOffer(e,i,t){return n(this,void 0,void 0,(function*(){try{r.info(`[36] [CallId: ${this.callId}] createOffer in webrtcClient`,{color:"blue"});const n=yield this.peerConnection.createOffer({iceRestart:!0,offerToReceiveAudio:!0,offerToReceiveVideo:!0});return yield this.setLocalDescription(n),(0,o.toSessionData)({sdp:n,sessionId:e,versionId:i},t)}catch(e){return r.error(`[37] [CallId: ${this.callId}] createOffer in webrtcClient failed: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),!1}}))}createAnswer(e,i,t){return n(this,void 0,void 0,(function*(){try{r.info(`[75] [CallId: ${this.callId}] createAnswer in webrtcClient`,{color:"blue"});const n=yield this.peerConnection.createAnswer();return yield this.setLocalDescription(n),(0,o.toSessionData)({sdp:n,sessionId:e,versionId:i},t)}catch(e){return r.error(`[70] [CallId: ${this.callId}] createAnswer in webrtcClient failed: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),!1}}))}setLocalDescription(e){var i;return r.info(`[44] [CallId: ${this.callId}] setLocalDescription in webrtcClient: sdp sliced 50: ${null===(i=null==e?void 0:e.sdp)||void 0===i?void 0:i.slice(0,50)}...`,{color:"blue"}),this.peerConnection.setLocalDescription(e)}setRemoteDescription(e){var i;return r.info(`[48] [CallId: ${this.callId}] setRemoteDescription in webrtcClient: sdp sliced 50: ${null===(i=e.sdp)||void 0===i?void 0:i.slice(0,50)}...`,{color:"blue"}),this.peerConnection.setRemoteDescription(e)}getLocalSdpUfrag(){var e;const i=((null===(e=this.peerConnection.localDescription)||void 0===e?void 0:e.sdp)||"").match(/a=ice-ufrag:(\S+)/);return i?i[1]:null}getRemoteSdpUfrag(){var e;const i=((null===(e=this.peerConnection.remoteDescription)||void 0===e?void 0:e.sdp)||"").match(/a=ice-ufrag:(\S+)/);return i?i[1]:null}getIceCandidateUfrag(e){const i=e.match(/ufrag\s+(\S+)/);return i?i[1]:null}isUfragEqualsSdpUfrag(e){return{equals:this.getIceCandidateUfrag(e)===this.getRemoteSdpUfrag(),ufrag:this.getIceCandidateUfrag(e),sdpUfrag:this.getRemoteSdpUfrag()}}addIceCandidate(e,i){if(r.info(`[52] [CallId: ${this.callId}] addIceCandidate in webrtcClient: candidate: ${e.candidate}`,{color:"blue"}),e.candidate){const t=this.isUfragEqualsSdpUfrag(e.candidate);if(!t.equals)return this.iceQueueMap[i]||(this.iceQueueMap[i]={}),void(t.ufrag&&(this.iceQueueMap[i][t.ufrag]||(this.iceQueueMap[i][t.ufrag]=[]),this.iceQueueMap[i][t.ufrag].push(e)))}return this.peerConnection.addIceCandidate(e)}addEventListener(e,i){this.peerConnection.addEventListener(e,i)}removeEventListener(e,i){this.peerConnection.removeEventListener(e,i)}close(){r.info(`[56] [CallId: ${this.callId}] close in webrtcClient`,{color:"blue"}),this.peerConnection.close()}getConnectionStats(){return n(this,void 0,void 0,(function*(){return yield this.peerConnection.getStats()}))}}},297:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.TypedEventEmitter=void 0,i.TypedEventEmitter=class{constructor(){this.listeners=new Map}on(e,i){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(i),()=>{var t;null===(t=this.listeners.get(e))||void 0===t||t.delete(i)}}emit(e,i){var t;null===(t=this.listeners.get(e))||void 0===t||t.forEach((t=>{try{t(i)}catch(i){console.error(`Error in event handler for "${String(e)}":`,i)}}))}off(e,i){var t;i?null===(t=this.listeners.get(e))||void 0===t||t.delete(i):this.listeners.delete(e)}removeAllListeners(){this.listeners.clear()}listenerCount(e){var i,t;return null!==(t=null===(i=this.listeners.get(e))||void 0===i?void 0:i.size)&&void 0!==t?t:0}}},578:(e,i)=>{"use strict";var t,n,a,l,s,o,r,d;Object.defineProperty(i,"__esModule",{value:!0}),i.CDRRequestDirection=i.CDRRequestEvent=i.CDRRequestOrder=i.MediaFlow=i.SignalEvent=i.CallState=i.ParticipantConnectionState=i.ParticipantState=void 0,function(e){e[e.Idle=0]="Idle",e[e.Ringing=1]="Ringing",e[e.Joined=2]="Joined",e[e.Left=3]="Left",e[e.Declined=4]="Declined",e[e.Kicked=5]="Kicked",e[e.NoAnswer=6]="NoAnswer"}(t||(i.ParticipantState=t={})),function(e){e[e.Idle=0]="Idle",e[e.Connecting=1]="Connecting",e[e.Connected=2]="Connected",e[e.Reconnecting=3]="Reconnecting",e[e.Disconnected=4]="Disconnected"}(n||(i.ParticipantConnectionState=n={})),function(e){e.Idle="idle",e.Connecting="connecting",e.Connected="connected",e.Closed="closed"}(a||(i.CallState=a={})),function(e){e[e.JOIN=0]="JOIN",e[e.LEAVE=1]="LEAVE",e[e.OFFER=2]="OFFER",e[e.ANSWER=3]="ANSWER",e[e.CONNECT=4]="CONNECT",e[e.ERROR=5]="ERROR",e[e.KICK=6]="KICK",e[e.SUCCESS=7]="SUCCESS",e[e.INVITE=8]="INVITE",e[e.DECLINE=9]="DECLINE",e[e.RINGING=10]="RINGING",e[e.INFO=11]="INFO",e[e.UPDATE=12]="UPDATE",e[e.CLOSE=13]="CLOSE",e[e.ICE=14]="ICE",e[e.GET_CALL=15]="GET_CALL",e[e.SWITCH_MEDIA_FLOW=16]="SWITCH_MEDIA_FLOW",e[e.NO_ANSWER=17]="NO_ANSWER",e[e.MEDIA_CONNECTED=18]="MEDIA_CONNECTED",e[e.MUTE=19]="MUTE",e[e.UNMUTE=20]="UNMUTE",e[e.HOLD=21]="HOLD",e[e.UNHOLD=22]="UNHOLD",e[e.VIDEO_ON=23]="VIDEO_ON",e[e.VIDEO_OFF=24]="VIDEO_OFF",e[e.SCREEN_SHARE_ON=25]="SCREEN_SHARE_ON",e[e.SCREEN_SHARE_OFF=26]="SCREEN_SHARE_OFF",e[e.CREATE=27]="CREATE",e[e.SESSION_RENEWED=28]="SESSION_RENEWED",e[e.DISABLE_REMOTE_AUDIO=29]="DISABLE_REMOTE_AUDIO",e[e.DISABLE_REMOTE_VIDEO=30]="DISABLE_REMOTE_VIDEO",e[e.CALL_PERMISSIONS_UPDATE=31]="CALL_PERMISSIONS_UPDATE",e[e.PARTICIPANT_PERMISSIONS_UPDATE=32]="PARTICIPANT_PERMISSIONS_UPDATE"}(l||(i.SignalEvent=l={})),function(e){e[e.P2P=0]="P2P",e[e.SFU=1]="SFU",e[e.S2W=2]="S2W"}(s||(i.MediaFlow=s={})),function(e){e[e.ASC=0]="ASC",e[e.DESC=1]="DESC"}(o||(i.CDRRequestOrder=o={})),function(e){e[e.GET_RECENT_CALLS=0]="GET_RECENT_CALLS",e[e.GET_CALLS_BY_SESSION_IDS=1]="GET_CALLS_BY_SESSION_IDS",e[e.DELETE_RECENT_CALLS=2]="DELETE_RECENT_CALLS"}(r||(i.CDRRequestEvent=r={})),function(e){e[e.NEXT=0]="NEXT",e[e.PREVIOUS=1]="PREVIOUS"}(d||(i.CDRRequestDirection=d={}))},489:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.makeFirstById=i.getEmptyVideoTrack=void 0,i.getEmptyVideoTrack=()=>{const e=document.createElement("canvas");return e.getContext("2d"),e.width=640,e.height=480,e.captureStream().getVideoTracks()},i.makeFirstById=(e,i,t)=>{const n=new Set,a=e.filter((e=>{const i=`${e.id}${e.clientId?`/${e.clientId}`:""}`;return!n.has(i)&&(n.add(i),!0)})),l=a.findIndex((e=>e.id===i&&(e.clientId===t||!e.clientId)));if(l>-1){const[e]=a.splice(l,1);a.unshift(e)}return a}},607:function(e,i,t){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,i,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(i,t);a&&!("get"in a?!i.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return i[t]}}),Object.defineProperty(e,n,a)}:function(e,i,t,n){void 0===n&&(n=t),e[n]=i[t]}),a=this&&this.__exportStar||function(e,i){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(i,t)||n(i,e,t)};Object.defineProperty(i,"__esModule",{value:!0});const l=t(838);a(t(838),i),i.default=l.SceytCallClient},838:function(e,i,t){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,i,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(i,t);a&&!("get"in a?!i.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return i[t]}}),Object.defineProperty(e,n,a)}:function(e,i,t,n){void 0===n&&(n=t),e[n]=i[t]}),a=this&&this.__exportStar||function(e,i){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(i,t)||n(i,e,t)};Object.defineProperty(i,"__esModule",{value:!0}),i.CDRRequestDirection=i.CDRRequestEvent=i.CDRRequestOrder=i.ParticipantConnectionState=i.ParticipantState=i.CallState=i.MediaFlow=i.VideoTrack=i.AudioTrack=i.Participant=i.Call=void 0,a(t(271),i);var l=t(998);Object.defineProperty(i,"Call",{enumerable:!0,get:function(){return l.Call}});var s=t(787);Object.defineProperty(i,"Participant",{enumerable:!0,get:function(){return s.Participant}});var o=t(250);Object.defineProperty(i,"AudioTrack",{enumerable:!0,get:function(){return o.AudioTrack}});var r=t(740);Object.defineProperty(i,"VideoTrack",{enumerable:!0,get:function(){return r.VideoTrack}});var d=t(578);Object.defineProperty(i,"MediaFlow",{enumerable:!0,get:function(){return d.MediaFlow}}),Object.defineProperty(i,"CallState",{enumerable:!0,get:function(){return d.CallState}}),Object.defineProperty(i,"ParticipantState",{enumerable:!0,get:function(){return d.ParticipantState}}),Object.defineProperty(i,"ParticipantConnectionState",{enumerable:!0,get:function(){return d.ParticipantConnectionState}}),Object.defineProperty(i,"CDRRequestOrder",{enumerable:!0,get:function(){return d.CDRRequestOrder}}),Object.defineProperty(i,"CDRRequestEvent",{enumerable:!0,get:function(){return d.CDRRequestEvent}}),Object.defineProperty(i,"CDRRequestDirection",{enumerable:!0,get:function(){return d.CDRRequestDirection}}),a(t(645),i)},645:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.createLogger=i.removeLogListener=i.addLogListener=void 0;const t={green:"",blue:"","light-green":"","light-blue":"",yellow:"",magenta:"",cyan:"",reset:"",orange:"",red:"",white:""},n=[];i.addLogListener=e=>{n.push(e)},i.removeLogListener=e=>{const i=n.indexOf(e);-1!==i&&n.splice(i,1)},i.createLogger=(e,i="white")=>{const a=`[SceytCallClient] ${e?`[${e}]`:""}:`,l=(e,l,s,o)=>{var r;const d=null!==(r=null==o?void 0:o.color)&&void 0!==r?r:i,c={level:e,message:l,prefix:a,args:s.filter((e=>!(null==e?void 0:e.color)&&!(null==e?void 0:e.time))),color:t[d],time:(null==o?void 0:o.time)||(new Date).toISOString()};n.forEach((e=>e(c)))};return{trace:(e,i)=>{l("trace",e,[],i)},debug:(e,i)=>{l("debug",e,[],i)},info:(e,i)=>{l("info",e,[],i)},warn:(e,i)=>{l("warn",e,[],i)},error:(e,i)=>{l("error",e,[],i)}}},i.default=(0,i.createLogger)("SceytCallClient")},429:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),Object.defineProperty(i,"NIL",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(i,"parse",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(i,"stringify",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(i,"v1",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(i,"v3",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(i,"v4",{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(i,"v5",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(i,"validate",{enumerable:!0,get:function(){return d.default}}),Object.defineProperty(i,"version",{enumerable:!0,get:function(){return r.default}});var n=p(t(990)),a=p(t(237)),l=p(t(355)),s=p(t(764)),o=p(t(314)),r=p(t(464)),d=p(t(435)),c=p(t(8)),u=p(t(222));function p(e){return e&&e.__esModule?e:{default:e}}},163:(e,i)=>{"use strict";function t(e){return 14+(e+64>>>9<<4)+1}function n(e,i){const t=(65535&e)+(65535&i);return(e>>16)+(i>>16)+(t>>16)<<16|65535&t}function a(e,i,t,a,l,s){return n((o=n(n(i,e),n(a,s)))<<(r=l)|o>>>32-r,t);var o,r}function l(e,i,t,n,l,s,o){return a(i&t|~i&n,e,i,l,s,o)}function s(e,i,t,n,l,s,o){return a(i&n|t&~n,e,i,l,s,o)}function o(e,i,t,n,l,s,o){return a(i^t^n,e,i,l,s,o)}function r(e,i,t,n,l,s,o){return a(t^(i|~n),e,i,l,s,o)}Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;i.default=function(e){if("string"==typeof e){const i=unescape(encodeURIComponent(e));e=new Uint8Array(i.length);for(let t=0;t<i.length;++t)e[t]=i.charCodeAt(t)}return function(e){const i=[],t=32*e.length,n="0123456789abcdef";for(let a=0;a<t;a+=8){const t=e[a>>5]>>>a%32&255,l=parseInt(n.charAt(t>>>4&15)+n.charAt(15&t),16);i.push(l)}return i}(function(e,i){e[i>>5]|=128<<i%32,e[t(i)-1]=i;let a=1732584193,d=-271733879,c=-1732584194,u=271733878;for(let i=0;i<e.length;i+=16){const t=a,p=d,h=c,g=u;a=l(a,d,c,u,e[i],7,-680876936),u=l(u,a,d,c,e[i+1],12,-389564586),c=l(c,u,a,d,e[i+2],17,606105819),d=l(d,c,u,a,e[i+3],22,-1044525330),a=l(a,d,c,u,e[i+4],7,-176418897),u=l(u,a,d,c,e[i+5],12,1200080426),c=l(c,u,a,d,e[i+6],17,-1473231341),d=l(d,c,u,a,e[i+7],22,-45705983),a=l(a,d,c,u,e[i+8],7,1770035416),u=l(u,a,d,c,e[i+9],12,-1958414417),c=l(c,u,a,d,e[i+10],17,-42063),d=l(d,c,u,a,e[i+11],22,-1990404162),a=l(a,d,c,u,e[i+12],7,1804603682),u=l(u,a,d,c,e[i+13],12,-40341101),c=l(c,u,a,d,e[i+14],17,-1502002290),d=l(d,c,u,a,e[i+15],22,1236535329),a=s(a,d,c,u,e[i+1],5,-165796510),u=s(u,a,d,c,e[i+6],9,-1069501632),c=s(c,u,a,d,e[i+11],14,643717713),d=s(d,c,u,a,e[i],20,-373897302),a=s(a,d,c,u,e[i+5],5,-701558691),u=s(u,a,d,c,e[i+10],9,38016083),c=s(c,u,a,d,e[i+15],14,-660478335),d=s(d,c,u,a,e[i+4],20,-405537848),a=s(a,d,c,u,e[i+9],5,568446438),u=s(u,a,d,c,e[i+14],9,-1019803690),c=s(c,u,a,d,e[i+3],14,-187363961),d=s(d,c,u,a,e[i+8],20,1163531501),a=s(a,d,c,u,e[i+13],5,-1444681467),u=s(u,a,d,c,e[i+2],9,-51403784),c=s(c,u,a,d,e[i+7],14,1735328473),d=s(d,c,u,a,e[i+12],20,-1926607734),a=o(a,d,c,u,e[i+5],4,-378558),u=o(u,a,d,c,e[i+8],11,-2022574463),c=o(c,u,a,d,e[i+11],16,1839030562),d=o(d,c,u,a,e[i+14],23,-35309556),a=o(a,d,c,u,e[i+1],4,-1530992060),u=o(u,a,d,c,e[i+4],11,1272893353),c=o(c,u,a,d,e[i+7],16,-155497632),d=o(d,c,u,a,e[i+10],23,-1094730640),a=o(a,d,c,u,e[i+13],4,681279174),u=o(u,a,d,c,e[i],11,-358537222),c=o(c,u,a,d,e[i+3],16,-722521979),d=o(d,c,u,a,e[i+6],23,76029189),a=o(a,d,c,u,e[i+9],4,-640364487),u=o(u,a,d,c,e[i+12],11,-421815835),c=o(c,u,a,d,e[i+15],16,530742520),d=o(d,c,u,a,e[i+2],23,-995338651),a=r(a,d,c,u,e[i],6,-198630844),u=r(u,a,d,c,e[i+7],10,1126891415),c=r(c,u,a,d,e[i+14],15,-1416354905),d=r(d,c,u,a,e[i+5],21,-57434055),a=r(a,d,c,u,e[i+12],6,1700485571),u=r(u,a,d,c,e[i+3],10,-1894986606),c=r(c,u,a,d,e[i+10],15,-1051523),d=r(d,c,u,a,e[i+1],21,-2054922799),a=r(a,d,c,u,e[i+8],6,1873313359),u=r(u,a,d,c,e[i+15],10,-30611744),c=r(c,u,a,d,e[i+6],15,-1560198380),d=r(d,c,u,a,e[i+13],21,1309151649),a=r(a,d,c,u,e[i+4],6,-145523070),u=r(u,a,d,c,e[i+11],10,-1120210379),c=r(c,u,a,d,e[i+2],15,718787259),d=r(d,c,u,a,e[i+9],21,-343485551),a=n(a,t),d=n(d,p),c=n(c,h),u=n(u,g)}return[a,d,c,u]}(function(e){if(0===e.length)return[];const i=8*e.length,n=new Uint32Array(t(i));for(let t=0;t<i;t+=8)n[t>>5]|=(255&e[t/8])<<t%32;return n}(e),8*e.length))}},790:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var t={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};i.default=t},314:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0,i.default="00000000-0000-0000-0000-000000000000"},222:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n,a=(n=t(435))&&n.__esModule?n:{default:n};i.default=function(e){if(!(0,a.default)(e))throw TypeError("Invalid UUID");let i;const t=new Uint8Array(16);return t[0]=(i=parseInt(e.slice(0,8),16))>>>24,t[1]=i>>>16&255,t[2]=i>>>8&255,t[3]=255&i,t[4]=(i=parseInt(e.slice(9,13),16))>>>8,t[5]=255&i,t[6]=(i=parseInt(e.slice(14,18),16))>>>8,t[7]=255&i,t[8]=(i=parseInt(e.slice(19,23),16))>>>8,t[9]=255&i,t[10]=(i=parseInt(e.slice(24,36),16))/1099511627776&255,t[11]=i/4294967296&255,t[12]=i>>>24&255,t[13]=i>>>16&255,t[14]=i>>>8&255,t[15]=255&i,t}},58:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0,i.default=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i},319:(e,i)=>{"use strict";let t;Object.defineProperty(i,"__esModule",{value:!0}),i.default=function(){if(!t&&(t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!t))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return t(n)};const n=new Uint8Array(16)},757:(e,i)=>{"use strict";function t(e,i,t,n){switch(e){case 0:return i&t^~i&n;case 1:case 3:return i^t^n;case 2:return i&t^i&n^t&n}}function n(e,i){return e<<i|e>>>32-i}Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;i.default=function(e){const i=[1518500249,1859775393,2400959708,3395469782],a=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const i=unescape(encodeURIComponent(e));e=[];for(let t=0;t<i.length;++t)e.push(i.charCodeAt(t))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);const l=e.length/4+2,s=Math.ceil(l/16),o=new Array(s);for(let i=0;i<s;++i){const t=new Uint32Array(16);for(let n=0;n<16;++n)t[n]=e[64*i+4*n]<<24|e[64*i+4*n+1]<<16|e[64*i+4*n+2]<<8|e[64*i+4*n+3];o[i]=t}o[s-1][14]=8*(e.length-1)/Math.pow(2,32),o[s-1][14]=Math.floor(o[s-1][14]),o[s-1][15]=8*(e.length-1)&4294967295;for(let e=0;e<s;++e){const l=new Uint32Array(80);for(let i=0;i<16;++i)l[i]=o[e][i];for(let e=16;e<80;++e)l[e]=n(l[e-3]^l[e-8]^l[e-14]^l[e-16],1);let s=a[0],r=a[1],d=a[2],c=a[3],u=a[4];for(let e=0;e<80;++e){const a=Math.floor(e/20),o=n(s,5)+t(a,r,d,c)+u+i[a]+l[e]>>>0;u=c,c=d,d=n(r,30)>>>0,r=s,s=o}a[0]=a[0]+s>>>0,a[1]=a[1]+r>>>0,a[2]=a[2]+d>>>0,a[3]=a[3]+c>>>0,a[4]=a[4]+u>>>0}return[a[0]>>24&255,a[0]>>16&255,a[0]>>8&255,255&a[0],a[1]>>24&255,a[1]>>16&255,a[1]>>8&255,255&a[1],a[2]>>24&255,a[2]>>16&255,a[2]>>8&255,255&a[2],a[3]>>24&255,a[3]>>16&255,a[3]>>8&255,255&a[3],a[4]>>24&255,a[4]>>16&255,a[4]>>8&255,255&a[4]]}},8:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0,i.unsafeStringify=s;var n,a=(n=t(435))&&n.__esModule?n:{default:n};const l=[];for(let e=0;e<256;++e)l.push((e+256).toString(16).slice(1));function s(e,i=0){return l[e[i+0]]+l[e[i+1]]+l[e[i+2]]+l[e[i+3]]+"-"+l[e[i+4]]+l[e[i+5]]+"-"+l[e[i+6]]+l[e[i+7]]+"-"+l[e[i+8]]+l[e[i+9]]+"-"+l[e[i+10]]+l[e[i+11]]+l[e[i+12]]+l[e[i+13]]+l[e[i+14]]+l[e[i+15]]}i.default=function(e,i=0){const t=s(e,i);if(!(0,a.default)(t))throw TypeError("Stringified UUID is invalid");return t}},990:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n,a=(n=t(319))&&n.__esModule?n:{default:n},l=t(8);let s,o,r=0,d=0;i.default=function(e,i,t){let n=i&&t||0;const c=i||new Array(16);let u=(e=e||{}).node||s,p=void 0!==e.clockseq?e.clockseq:o;if(null==u||null==p){const i=e.random||(e.rng||a.default)();null==u&&(u=s=[1|i[0],i[1],i[2],i[3],i[4],i[5]]),null==p&&(p=o=16383&(i[6]<<8|i[7]))}let h=void 0!==e.msecs?e.msecs:Date.now(),g=void 0!==e.nsecs?e.nsecs:d+1;const v=h-r+(g-d)/1e4;if(v<0&&void 0===e.clockseq&&(p=p+1&16383),(v<0||h>r)&&void 0===e.nsecs&&(g=0),g>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");r=h,d=g,o=p,h+=122192928e5;const S=(1e4*(268435455&h)+g)%4294967296;c[n++]=S>>>24&255,c[n++]=S>>>16&255,c[n++]=S>>>8&255,c[n++]=255&S;const f=h/4294967296*1e4&268435455;c[n++]=f>>>8&255,c[n++]=255&f,c[n++]=f>>>24&15|16,c[n++]=f>>>16&255,c[n++]=p>>>8|128,c[n++]=255&p;for(let e=0;e<6;++e)c[n+e]=u[e];return i||(0,l.unsafeStringify)(c)}},237:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n=l(t(925)),a=l(t(163));function l(e){return e&&e.__esModule?e:{default:e}}var s=(0,n.default)("v3",48,a.default);i.default=s},925:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.URL=i.DNS=void 0,i.default=function(e,i,t){function n(e,n,s,o){var r;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const i=[];for(let t=0;t<e.length;++t)i.push(e.charCodeAt(t));return i}(e)),"string"==typeof n&&(n=(0,l.default)(n)),16!==(null===(r=n)||void 0===r?void 0:r.length))throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let d=new Uint8Array(16+e.length);if(d.set(n),d.set(e,n.length),d=t(d),d[6]=15&d[6]|i,d[8]=63&d[8]|128,s){o=o||0;for(let e=0;e<16;++e)s[o+e]=d[e];return s}return(0,a.unsafeStringify)(d)}try{n.name=e}catch(e){}return n.DNS=s,n.URL=o,n};var n,a=t(8),l=(n=t(222))&&n.__esModule?n:{default:n};const s="6ba7b810-9dad-11d1-80b4-00c04fd430c8";i.DNS=s;const o="6ba7b811-9dad-11d1-80b4-00c04fd430c8";i.URL=o},355:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n=s(t(790)),a=s(t(319)),l=t(8);function s(e){return e&&e.__esModule?e:{default:e}}i.default=function(e,i,t){if(n.default.randomUUID&&!i&&!e)return n.default.randomUUID();const s=(e=e||{}).random||(e.rng||a.default)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,i){t=t||0;for(let e=0;e<16;++e)i[t+e]=s[e];return i}return(0,l.unsafeStringify)(s)}},764:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n=l(t(925)),a=l(t(757));function l(e){return e&&e.__esModule?e:{default:e}}var s=(0,n.default)("v5",80,a.default);i.default=s},435:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n,a=(n=t(58))&&n.__esModule?n:{default:n};i.default=function(e){return"string"==typeof e&&a.default.test(e)}},464:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n,a=(n=t(435))&&n.__esModule?n:{default:n};i.default=function(e){if(!(0,a.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)}},583:function(e,i){var t;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self&&self,t=function(){var e={};return function(e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var i=null;try{i=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}function t(e,i,t){this.low=0|e,this.high=0|i,this.unsigned=!!t}function n(e){return!0===(e&&e.__isLong__)}function a(e){var i=Math.clz32(e&-e);return e?31-i:i}t.prototype.__isLong__,Object.defineProperty(t.prototype,"__isLong__",{value:!0}),t.isLong=n;var l={},s={};function o(e,i){var t,n,a;return i?(a=0<=(e>>>=0)&&e<256)&&(n=s[e])?n:(t=d(e,0,!0),a&&(s[e]=t),t):(a=-128<=(e|=0)&&e<128)&&(n=l[e])?n:(t=d(e,e<0?-1:0,!1),a&&(l[e]=t),t)}function r(e,i){if(isNaN(e))return i?C:f;if(i){if(e<0)return C;if(e>=g)return b}else{if(e<=-v)return y;if(e+1>=v)return P}return e<0?r(-e,i).neg():d(e%h|0,e/h|0,i)}function d(e,i,n){return new t(e,i,n)}t.fromInt=o,t.fromNumber=r,t.fromBits=d;var c=Math.pow;function u(e,i,t){if(0===e.length)throw Error("empty string");if("number"==typeof i?(t=i,i=!1):i=!!i,"NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return i?C:f;if((t=t||10)<2||36<t)throw RangeError("radix");var n;if((n=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===n)return u(e.substring(1),i,t).neg();for(var a=r(c(t,8)),l=f,s=0;s<e.length;s+=8){var o=Math.min(8,e.length-s),d=parseInt(e.substring(s,s+o),t);if(o<8){var p=r(c(t,o));l=l.mul(p).add(r(d))}else l=(l=l.mul(a)).add(r(d))}return l.unsigned=i,l}function p(e,i){return"number"==typeof e?r(e,i):"string"==typeof e?u(e,i):d(e.low,e.high,"boolean"==typeof i?i:e.unsigned)}t.fromString=u,t.fromValue=p;var h=4294967296,g=h*h,v=g/2,S=o(1<<24),f=o(0);t.ZERO=f;var C=o(0,!0);t.UZERO=C;var I=o(1);t.ONE=I;var m=o(1,!0);t.UONE=m;var E=o(-1);t.NEG_ONE=E;var P=d(-1,2147483647,!1);t.MAX_VALUE=P;var b=d(-1,-1,!0);t.MAX_UNSIGNED_VALUE=b;var y=d(0,-2147483648,!1);t.MIN_VALUE=y;var O=t.prototype;O.toInt=function(){return this.unsigned?this.low>>>0:this.low},O.toNumber=function(){return this.unsigned?(this.high>>>0)*h+(this.low>>>0):this.high*h+(this.low>>>0)},O.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(y)){var i=r(e),t=this.div(i),n=t.mul(i).sub(this);return t.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var a=r(c(e,6),this.unsigned),l=this,s="";;){var o=l.div(a),d=(l.sub(o.mul(a)).toInt()>>>0).toString(e);if((l=o).isZero())return d+s;for(;d.length<6;)d="0"+d;s=""+d+s}},O.getHighBits=function(){return this.high},O.getHighBitsUnsigned=function(){return this.high>>>0},O.getLowBits=function(){return this.low},O.getLowBitsUnsigned=function(){return this.low>>>0},O.getNumBitsAbs=function(){if(this.isNegative())return this.eq(y)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,i=31;i>0&&0==(e&1<<i);i--);return 0!=this.high?i+33:i+1},O.isSafeInteger=function(){var e=this.high>>21;return!e||!this.unsigned&&-1===e&&!(0===this.low&&-2097152===this.high)},O.isZero=function(){return 0===this.high&&0===this.low},O.eqz=O.isZero,O.isNegative=function(){return!this.unsigned&&this.high<0},O.isPositive=function(){return this.unsigned||this.high>=0},O.isOdd=function(){return 1==(1&this.low)},O.isEven=function(){return 0==(1&this.low)},O.equals=function(e){return n(e)||(e=p(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&this.high===e.high&&this.low===e.low},O.eq=O.equals,O.notEquals=function(e){return!this.eq(e)},O.neq=O.notEquals,O.ne=O.notEquals,O.lessThan=function(e){return this.comp(e)<0},O.lt=O.lessThan,O.lessThanOrEqual=function(e){return this.comp(e)<=0},O.lte=O.lessThanOrEqual,O.le=O.lessThanOrEqual,O.greaterThan=function(e){return this.comp(e)>0},O.gt=O.greaterThan,O.greaterThanOrEqual=function(e){return this.comp(e)>=0},O.gte=O.greaterThanOrEqual,O.ge=O.greaterThanOrEqual,O.compare=function(e){if(n(e)||(e=p(e)),this.eq(e))return 0;var i=this.isNegative(),t=e.isNegative();return i&&!t?-1:!i&&t?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},O.comp=O.compare,O.negate=function(){return!this.unsigned&&this.eq(y)?y:this.not().add(I)},O.neg=O.negate,O.add=function(e){n(e)||(e=p(e));var i=this.high>>>16,t=65535&this.high,a=this.low>>>16,l=65535&this.low,s=e.high>>>16,o=65535&e.high,r=e.low>>>16,c=0,u=0,h=0,g=0;return h+=(g+=l+(65535&e.low))>>>16,u+=(h+=a+r)>>>16,c+=(u+=t+o)>>>16,c+=i+s,d((h&=65535)<<16|(g&=65535),(c&=65535)<<16|(u&=65535),this.unsigned)},O.subtract=function(e){return n(e)||(e=p(e)),this.add(e.neg())},O.sub=O.subtract,O.multiply=function(e){if(this.isZero())return this;if(n(e)||(e=p(e)),i)return d(i.mul(this.low,this.high,e.low,e.high),i.get_high(),this.unsigned);if(e.isZero())return this.unsigned?C:f;if(this.eq(y))return e.isOdd()?y:f;if(e.eq(y))return this.isOdd()?y:f;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(S)&&e.lt(S))return r(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,a=65535&this.high,l=this.low>>>16,s=65535&this.low,o=e.high>>>16,c=65535&e.high,u=e.low>>>16,h=65535&e.low,g=0,v=0,I=0,m=0;return I+=(m+=s*h)>>>16,v+=(I+=l*h)>>>16,I&=65535,v+=(I+=s*u)>>>16,g+=(v+=a*h)>>>16,v&=65535,g+=(v+=l*u)>>>16,v&=65535,g+=(v+=s*c)>>>16,g+=t*h+a*u+l*c+s*o,d((I&=65535)<<16|(m&=65535),(g&=65535)<<16|(v&=65535),this.unsigned)},O.mul=O.multiply,O.divide=function(e){if(n(e)||(e=p(e)),e.isZero())throw Error("division by zero");var t,a,l;if(i)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?d((this.unsigned?i.div_u:i.div_s)(this.low,this.high,e.low,e.high),i.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?C:f;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return C;if(e.gt(this.shru(1)))return m;l=C}else{if(this.eq(y))return e.eq(I)||e.eq(E)?y:e.eq(y)?I:(t=this.shr(1).div(e).shl(1)).eq(f)?e.isNegative()?I:E:(a=this.sub(e.mul(t)),l=t.add(a.div(e)));if(e.eq(y))return this.unsigned?C:f;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();l=f}for(a=this;a.gte(e);){t=Math.max(1,Math.floor(a.toNumber()/e.toNumber()));for(var s=Math.ceil(Math.log(t)/Math.LN2),o=s<=48?1:c(2,s-48),u=r(t),h=u.mul(e);h.isNegative()||h.gt(a);)h=(u=r(t-=o,this.unsigned)).mul(e);u.isZero()&&(u=I),l=l.add(u),a=a.sub(h)}return l},O.div=O.divide,O.modulo=function(e){return n(e)||(e=p(e)),i?d((this.unsigned?i.rem_u:i.rem_s)(this.low,this.high,e.low,e.high),i.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},O.mod=O.modulo,O.rem=O.modulo,O.not=function(){return d(~this.low,~this.high,this.unsigned)},O.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32},O.clz=O.countLeadingZeros,O.countTrailingZeros=function(){return this.low?a(this.low):a(this.high)+32},O.ctz=O.countTrailingZeros,O.and=function(e){return n(e)||(e=p(e)),d(this.low&e.low,this.high&e.high,this.unsigned)},O.or=function(e){return n(e)||(e=p(e)),d(this.low|e.low,this.high|e.high,this.unsigned)},O.xor=function(e){return n(e)||(e=p(e)),d(this.low^e.low,this.high^e.high,this.unsigned)},O.shiftLeft=function(e){return n(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?d(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):d(0,this.low<<e-32,this.unsigned)},O.shl=O.shiftLeft,O.shiftRight=function(e){return n(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?d(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):d(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},O.shr=O.shiftRight,O.shiftRightUnsigned=function(e){return n(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?d(this.low>>>e|this.high<<32-e,this.high>>>e,this.unsigned):d(32===e?this.high:this.high>>>e-32,0,this.unsigned)},O.shru=O.shiftRightUnsigned,O.shr_u=O.shiftRightUnsigned,O.rotateLeft=function(e){var i;return n(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?d(this.high,this.low,this.unsigned):e<32?(i=32-e,d(this.low<<e|this.high>>>i,this.high<<e|this.low>>>i,this.unsigned)):(i=32-(e-=32),d(this.high<<e|this.low>>>i,this.low<<e|this.high>>>i,this.unsigned))},O.rotl=O.rotateLeft,O.rotateRight=function(e){var i;return n(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?d(this.high,this.low,this.unsigned):e<32?(i=32-e,d(this.high<<i|this.low>>>e,this.low<<i|this.high>>>e,this.unsigned)):(i=32-(e-=32),d(this.low<<i|this.high>>>e,this.high<<i|this.low>>>e,this.unsigned))},O.rotr=O.rotateRight,O.toSigned=function(){return this.unsigned?d(this.low,this.high,!1):this},O.toUnsigned=function(){return this.unsigned?this:d(this.low,this.high,!0)},O.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},O.toBytesLE=function(){var e=this.high,i=this.low;return[255&i,i>>>8&255,i>>>16&255,i>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},O.toBytesBE=function(){var e=this.high,i=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,i>>>24,i>>>16&255,i>>>8&255,255&i]},t.fromBytes=function(e,i,n){return n?t.fromBytesLE(e,i):t.fromBytesBE(e,i)},t.fromBytesLE=function(e,i){return new t(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,i)},t.fromBytesBE=function(e,i){return new t(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],i)},"function"==typeof BigInt&&(t.fromBigInt=function(e,i){return d(Number(BigInt.asIntN(32,e)),Number(BigInt.asIntN(32,e>>BigInt(32))),i)},t.fromValue=function(e,i){return"bigint"==typeof e?t.fromBigInt(e,i):p(e,i)},O.toBigInt=function(){var e=BigInt(this.low>>>0);return BigInt(this.unsigned?this.high>>>0:this.high)<<BigInt(32)|e}),e.default=t}(e),function(e){return e.default||e}(e)}.apply(i,[]),void 0===t||(e.exports=t)}},i={},function t(n){var a=i[n];if(void 0!==a)return a.exports;var l=i[n]={exports:{}};return e[n].call(l.exports,l,l.exports,t),l.exports}(607);var e,i}));
2
+ !function(e,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?exports["sceyt-call"]=i():e["sceyt-call"]=i()}(this,(()=>{return e={547:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.CallStateMachine=void 0;const n=t(578),a=(0,t(645).createLogger)("CallStateMachine");class l{constructor(e){this.callId=e}isValidStateTransition(e,i){var t,n;return null!==(n=null===(t=l.validStateTransitions.get(i))||void 0===t?void 0:t.has(e))&&void 0!==n&&n}setState(e,i,t){return this.isValidStateTransition(e,i)?(a.info(`[25] [CallId: ${this.callId}] Call state changed ${i} -> ${e}, reason: ${t}`,{color:"cyan"}),!0):(a.warn(`[28] [CallId: ${this.callId}] Invalid CallState changed ${i} -> ${e}, reason: ${t}`,{color:"red"}),!1)}updateState(e,i,t){return this.setState(e,i,t)}}i.CallStateMachine=l,l.validStateTransitions=new Map([[n.CallState.Idle,new Set([n.CallState.Connecting,n.CallState.Closed])],[n.CallState.Connecting,new Set([n.CallState.Connected,n.CallState.Closed,n.CallState.Idle])],[n.CallState.Connected,new Set([n.CallState.Closed,n.CallState.Idle])],[n.CallState.Closed,new Set([])]])},758:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ParticipantStateMachine=void 0;const n=t(578),a=(0,t(645).createLogger)("ParticipantStateMachine");class l{constructor(e,i){this.userId=e,this.callId=i}isValidParticipantStateTransition(e,i){var t,n;return null!==(n=null===(t=l.validParticipantStateTransitions.get(i))||void 0===t?void 0:t.has(e))&&void 0!==n&&n}isValidConnectionTransition(e,i){var t,n;return null!==(n=null===(t=l.validConnectionTransitions.get(i))||void 0===t?void 0:t.has(e))&&void 0!==n&&n}setState(e,i,t,l){let s=!1;void 0!==e&&void 0!==t&&this.isValidParticipantStateTransition(e,t)?(a.debug(`[43] [CallId: ${this.callId}] Participant state transition: ${t} -> ${e}`),s=!0):e&&a.warn(`[46] [CallId: ${this.callId}] Invalid ParticipantState transition from ${t?n.ParticipantState[t]:"undefined"} to ${e?n.ParticipantState[e]:"undefined"}`,{color:"yellow"}),void 0!==i&&void 0!==l&&this.isValidConnectionTransition(i,l)?(a.debug(`[50] [CallId: ${this.callId}] Connection state transition: ${l} -> ${i}`),s=!0):i&&a.warn(`[53] [CallId: ${this.callId}] Invalid ConnectionState transition from ${l?n.ParticipantConnectionState[l]:"undefined"} to ${i?n.ParticipantConnectionState[i]:"undefined"}`,{color:"yellow"})}updateState(e,i){return this.isValidParticipantStateTransition(e,i)?(this.setState(e,void 0,i,void 0),!0):(a.warn(`[63] [CallId: ${this.callId}] Invalid ParticipantState transition from ${n.ParticipantState[i]} to ${n.ParticipantState[e]}`,{color:"yellow"}),!1)}updateConnectionState(e,i){return this.isValidConnectionTransition(e,i)?(this.setState(void 0,e,void 0,i),!0):(a.warn(`[71] [CallId: ${this.callId}] Invalid ConnectionState transition from ${n.ParticipantConnectionState[i]} to ${n.ParticipantConnectionState[e]}`,{color:"yellow"}),!1)}}i.ParticipantStateMachine=l,l.validParticipantStateTransitions=new Map([[n.ParticipantState.Idle,new Set([n.ParticipantState.Ringing,n.ParticipantState.Declined,n.ParticipantState.Kicked,n.ParticipantState.NoAnswer,n.ParticipantState.Joined,n.ParticipantState.Left])],[n.ParticipantState.Ringing,new Set([n.ParticipantState.Joined,n.ParticipantState.Declined,n.ParticipantState.Kicked,n.ParticipantState.NoAnswer,n.ParticipantState.Idle])],[n.ParticipantState.Joined,new Set([n.ParticipantState.Left,n.ParticipantState.Kicked,n.ParticipantState.Idle])],[n.ParticipantState.Left,new Set([n.ParticipantState.Idle,n.ParticipantState.Joined])],[n.ParticipantState.Declined,new Set([n.ParticipantState.Idle,n.ParticipantState.Joined])],[n.ParticipantState.Kicked,new Set([n.ParticipantState.Idle,n.ParticipantState.Joined])],[n.ParticipantState.NoAnswer,new Set([n.ParticipantState.Idle,n.ParticipantState.Joined])]]),l.validConnectionTransitions=new Map([[n.ParticipantConnectionState.Idle,new Set([n.ParticipantConnectionState.Connecting])],[n.ParticipantConnectionState.Connecting,new Set([n.ParticipantConnectionState.Connected,n.ParticipantConnectionState.Disconnected,n.ParticipantConnectionState.Idle])],[n.ParticipantConnectionState.Connected,new Set([n.ParticipantConnectionState.Reconnecting,n.ParticipantConnectionState.Disconnected,n.ParticipantConnectionState.Idle])],[n.ParticipantConnectionState.Reconnecting,new Set([n.ParticipantConnectionState.Connected,n.ParticipantConnectionState.Connecting,n.ParticipantConnectionState.Disconnected,n.ParticipantConnectionState.Idle])],[n.ParticipantConnectionState.Disconnected,new Set([n.ParticipantConnectionState.Idle,n.ParticipantConnectionState.Reconnecting,n.ParticipantConnectionState.Connected])]])},258:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.ActiveSpeakerManager=void 0;const a=t(645),l=t(578),s=(0,a.createLogger)("ActiveSpeakerManager");class o{constructor(e){this.speakingStates=new Map,this.activeSpeakers=[],this.dominantSpeaker=null,this.lastActiveSpeakers=[],this.lastDominantSpeaker=null,this.dominantSpeakerLastChangeTime=0,this.processingInterval=null,this.call=null,this.internalCallHandler=null,this.call=e}start(e){var i,t;this.processingInterval||(this.internalCallHandler=e,this.internalCallHandler&&this.call?(this.processingInterval=setInterval((()=>n(this,void 0,void 0,(function*(){var e,i,t,n,a,o,r;try{if(this.call&&this.internalCallHandler){if(this.call.localParticipant){let n=0;if(this.call.mediaFlow!==l.MediaFlow.SFU){const i=this.call.participants.find((e=>{var i,t,n,a;return e.id!==(null===(t=null===(i=this.call)||void 0===i?void 0:i.localParticipant)||void 0===t?void 0:t.id)||e.clientId!==(null===(a=null===(n=this.call)||void 0===n?void 0:n.localParticipant)||void 0===a?void 0:a.clientId)}));if(i){const t=null===(e=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===e?void 0:e[i.getFullId()];if(t){const e=yield t.getConnectionStats(),i=Array.from(e.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));n=i.length>0?Math.max(...i):0}}}else{const e=this.call.serverParticipant;if(e){const t=null===(i=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===i?void 0:i[e.getFullId()];if(t){const e=yield t.getConnectionStats(),i=Array.from(e.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));n=i.length>0?Math.max(...i):0}}}(null===(t=this.call.localParticipant.mediaState)||void 0===t?void 0:t.audio.enabled)||(n=0),this.processAudioLevels(this.call.localParticipant,n)}for(const e of this.call.participants){if(e.id===this.call.localParticipant.id&&e.clientId===this.call.localParticipant.clientId)continue;let i=0;if(this.call.mediaFlow!==l.MediaFlow.SFU){const t=null===(n=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===n?void 0:n[e.getFullId()];if(t){const e=yield t.getConnectionStats(),n=Array.from(e.values()).filter((e=>this.isInboundAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));i=n.length>0?Math.max(...n):0}}else{const t=null===(a=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===a?void 0:a[e.getFullId()];if(t){const e=yield t.getConnectionStats(),n=Array.from(e.values()).filter((e=>this.isInboundAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));i=n.length>0?Math.max(...n):0}}(null===(o=e.mediaState)||void 0===o?void 0:o.audio.enabled)||(i=0),this.processAudioLevels(e,i)}}this.processActiveSpeakers(),this.call&&(this.call.emitActiveSpeakersChanged(this.activeSpeakers),this.call.emitDominantSpeakerChanged(this.dominantSpeaker))}catch(e){s.error(`[137] [CallId: ${null===(r=this.call)||void 0===r?void 0:r.id}] Error processing audio levels: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}))),o.POLLING_INTERVAL_MS),s.info(`[141] [CallId: ${null===(t=this.call)||void 0===t?void 0:t.id}] Active speaker detection started`)):s.error(`[47] [CallId: ${null===(i=this.call)||void 0===i?void 0:i.id}] Call or InternalCallHandler is not set`,{color:"red"}))}getActiveSpeakers(){return this.activeSpeakers}stop(){var e;this.processingInterval&&(clearInterval(this.processingInterval),this.processingInterval=null),this.activeSpeakers=[],this.dominantSpeaker=null,this.speakingStates.clear(),this.lastActiveSpeakers=[],this.lastDominantSpeaker=null,s.info(`[154] [CallId: ${null===(e=this.call)||void 0===e?void 0:e.id}] Active speaker detection stopped`)}addParticipant(e){var i;const t=this.getParticipantKey(e);this.speakingStates.has(t)||(this.speakingStates.set(t,{participant:e,audioLevel:0,smoothedAudioLevel:0,isSpeaking:!1,speakingStartTime:0}),s.info(`[167] [CallId: ${null===(i=this.call)||void 0===i?void 0:i.id}] Added participant for active speaker detection: ${e.getFullId()}`))}updateParticipant(e){const i=this.getParticipantKey(e),t=this.speakingStates.get(i);t&&this.speakingStates.set(i,Object.assign(Object.assign({},t),{participant:e}))}removeParticipant(e){var i,t,n;const a=this.getParticipantKey(e);this.speakingStates.delete(a),this.lastActiveSpeakers.some((i=>i.participant.id===e.id&&i.participant.clientId===e.clientId))&&this.processActiveSpeakers(),(null===(i=this.lastDominantSpeaker)||void 0===i?void 0:i.participant.id)===e.id&&(null===(t=this.lastDominantSpeaker)||void 0===t?void 0:t.participant.clientId)===e.clientId&&(this.dominantSpeaker=null,this.lastDominantSpeaker=null),s.info(`[199] [CallId: ${null===(n=this.call)||void 0===n?void 0:n.id}] Removed participant from active speaker detection: ${e.getFullId()}`)}getAudioLevel(e){var i,t;const n=this.getParticipantKey(e);return null!==(t=null===(i=this.speakingStates.get(n))||void 0===i?void 0:i.smoothedAudioLevel)&&void 0!==t?t:null}isSpeaking(e){var i,t;const n=this.getParticipantKey(e);return null!==(t=null===(i=this.speakingStates.get(n))||void 0===i?void 0:i.isSpeaking)&&void 0!==t&&t}isDominantSpeaker(e){var i,t;return(null===(i=this.dominantSpeaker)||void 0===i?void 0:i.participant.id)===e.id&&(null===(t=this.dominantSpeaker)||void 0===t?void 0:t.participant.clientId)===e.clientId}processActiveSpeakers(){const e=Date.now(),i=new Map;this.speakingStates.forEach(((t,n)=>{i.set(n,this.updateSpeakingState(t,e))})),this.speakingStates=i;const t=Array.from(this.speakingStates.values()).filter((e=>e.isSpeaking)).sort(((e,i)=>i.smoothedAudioLevel-e.smoothedAudioLevel));JSON.stringify(t)!==JSON.stringify(this.lastActiveSpeakers)&&(this.activeSpeakers=t,this.lastActiveSpeakers=t),this.updateDominantSpeaker(t,e)}updateDominantSpeaker(e,i){if(0===e.length)return void(this.lastDominantSpeaker&&i-this.dominantSpeakerLastChangeTime>o.DOMINANT_SPEAKER_HYSTERESIS_MS&&(this.dominantSpeaker=null,this.lastDominantSpeaker=null));if(!this.lastDominantSpeaker)return this.dominantSpeaker=e[0],this.lastDominantSpeaker=e[0],void(this.dominantSpeakerLastChangeTime=i);const t=e[0];t.participant.id===this.lastDominantSpeaker.participant.id&&t.participant.clientId===this.lastDominantSpeaker.participant.clientId||t.smoothedAudioLevel>.5&&i-t.speakingStartTime>o.DOMINANT_SPEAKER_HYSTERESIS_MS&&(this.dominantSpeaker=t,this.lastDominantSpeaker=t,this.dominantSpeakerLastChangeTime=i)}updateSpeakingState(e,i){const t=e.audioLevel>e.smoothedAudioLevel?Math.max(e.smoothedAudioLevel,e.smoothedAudioLevel+(e.audioLevel-e.smoothedAudioLevel)*o.ACTIVE_LEVEL_BOOST):Math.max(0,e.smoothedAudioLevel-(e.smoothedAudioLevel-e.audioLevel)*o.ACTIVE_LEVEL_DECAY);let n=e.isSpeaking,a=e.speakingStartTime;return t>=o.AUDIO_LEVEL_THRESHOLD?e.isSpeaking||(n=!0,a=i):e.isSpeaking&&i-e.speakingStartTime>o.SPEAKING_TIME_THRESHOLD_MS&&(n=!1),Object.assign(Object.assign({},e),{smoothedAudioLevel:t,isSpeaking:n,speakingStartTime:a})}processAudioLevels(e,i){var t,n;try{let n=null;if(null===(t=e.mediaState)||void 0===t?void 0:t.audio.enabled)if("number"==typeof i)n=i;else{const e=Array.from(i.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));n=e.length>0?Math.max(...e):0}else n=0;if(null!==n){const i=this.getParticipantKey(e),t=this.speakingStates.get(i);t&&this.speakingStates.set(i,Object.assign(Object.assign({},t),{audioLevel:n}))}}catch(e){s.error(`[330] [CallId: ${null===(n=this.call)||void 0===n?void 0:n.id}] Error processing audio levels: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}getParticipantKey(e){return`${e.id}/${e.clientId}`}isOutboundAudio(e){return"outbound-rtp"===e.type&&"audio"===e.kind}isMediaSourceAudio(e){return"media-source"===e.type&&"audio"===e.kind}getStatsAudioLevel(e){var i;return null!==(i=e.audioLevel)&&void 0!==i?i:null}isInboundAudio(e){return"inbound-rtp"===e.type&&"audio"===e.kind}}i.ActiveSpeakerManager=o,o.AUDIO_LEVEL_THRESHOLD=.1,o.SPEAKING_TIME_THRESHOLD_MS=250,o.DOMINANT_SPEAKER_HYSTERESIS_MS=1e3,o.ACTIVE_LEVEL_DECAY=.2,o.ACTIVE_LEVEL_BOOST=1.5,o.POLLING_INTERVAL_MS=150},250:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.AudioTrack=void 0,i.AudioTrack=class{constructor(e){this._enabled=!0,this.id=e.id,this.audioTrack=e}set enabled(e){this._enabled=e,this.audioTrack.enabled=e}get enabled(){return this._enabled}}},271:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SceytCallClient=void 0;const n=t(650),a=t(645),l=t(185),s=t(297),o=t(228),r=(0,a.createLogger)("CallClient");class d extends s.TypedEventEmitter{constructor(e){super(),this.fetchCall=e=>{r.info(`[20] [CallId: ${e}] Get call from server`,{color:"cyan"});const i=this.internalCallHandler.activeCalls.find((i=>i.id===e));return i?Promise.resolve({success:!0,data:i}):this.internalCallHandler.prepareCallFromCallID(e)},this.getOngoingCalls=()=>(this.internalCallHandler.getCalls(),this.internalCallHandler.activeCalls),this.onLog=e=>((0,a.addLogListener)(e),()=>(0,a.removeLogListener)(e)),this.internalCallHandler=new n.InternalCallHandler(e),this.setupInternalEventBridge()}setupInternalEventBridge(){this.internalCallHandler.setCallEvent("onInvitedToCall",(e=>{this.emit("invitedToCall",{call:e})})),this.internalCallHandler.setCallEvent("onOngoingCallsUpdated",(e=>{this.emit("ongoingCallsUpdated",{calls:e})}))}get activeCalls(){return this.internalCallHandler.activeCalls}prepareCall(e,i){r.info(`[19] [CallId: ${e}] Prepare call`,{color:"cyan"});try{return this.internalCallHandler.prepareCall(e,i)}catch(i){return r.error(`[19] [CallId: ${e}] Prepare call failed: ${i.message||JSON.stringify(i)}`,{color:"red"}),{success:!1,error:(0,o.toCallException)(i)}}}get RecentCallQueryBuilder(){return l.RecentCallQueryBuilder}}i.SceytCallClient=d},998:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.Call=void 0;const a=t(302),l=t(65),s=t(650),o=t(578),r=t(547),d=t(645),c=t(258),u=t(297),p=t(228),h=(0,d.createLogger)("Call");class g extends u.TypedEventEmitter{get activeSpeakers(){return this._activeSpeakers}set activeSpeakers(e){this._activeSpeakers=e}constructor({id:e,sessionId:i="",mediaFlow:t,createdBy:a="",localParticipant:l,participants:r,metadata:d,chatClient:u,isCallSilenced:g}){super(),this.state=o.CallState.Idle,this._localAudioTracks=[],this._localVideoTracks=[],this._muted=!1,this._onHold=!1,this._screenSharing=!1,this._activeSpeakers=[],this.videoEnabled=!1,this.eventsQueue=new Map,this.isCallSilenced=!1,this.videoCall=!1,this.isCreatedRemotely=!1,this.videoDeviceId=null,this.audioDeviceId=null,this.getStats=()=>n(this,void 0,void 0,(function*(){try{const e=[];for(const i of this.participants){const t=yield this.getParticipantStats(i);t.success&&t.data&&e.push(t.data)}return{success:!0,data:e}}catch(e){return h.error(`[502] [CallId: ${this.id}] Error getting call stats ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}})),this.getParticipantStats=e=>n(this,void 0,void 0,(function*(){try{h.info(`[503] [CallId: ${this.id}] getParticipantStats for ${e.getFullId()}`,{color:"cyan"});const i=s.InternalCallHandler.getInstance().callParticipantsRTCMap[this.id],t=null==i?void 0:i[e.getFullId()];return t?{success:!0,data:yield t.getConnectionStats()}:{success:!1,error:(0,p.toCallException)(new Error("Participant RTC client not found"))}}catch(e){return h.error(`[504] [CallId: ${this.id}] Error getting participant stats ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}})),this.id=e,this.sessionId=i,this.createdBy=a,this.participants=r,this.localParticipant=l,this.mediaFlow=t,this.metadata=d,this.activeSpeakerManager=new c.ActiveSpeakerManager(this),this.chatClient=u,this.isCallSilenced=g}emitAudioTrackAdded(e,i){this.emit("audioTrackAdded",{call:this,participant:e,track:i})}emitAudioTrackRemoved(e){this.emit("audioTrackRemoved",{call:this,participant:e})}emitVideoTrackAdded(e,i){this.emit("videoTrackAdded",{call:this,participant:e,track:i})}emitVideoTrackRemoved(e){this.emit("videoTrackRemoved",{call:this,participant:e})}emitCallStateChanged(e){this.emit("callStateChanged",{call:this,state:e})}emitParticipantStateChanged(e,i,t){this.emit("participantStateChanged",{call:this,participant:e,state:i,reason:t})}emitParticipantConnectionStateChanged(e,i){this.emit("participantConnectionStateChanged",{call:this,participant:e,state:i})}emitParticipantEvent(e,i,t){this.emit("participantEvent",{call:this,participant:e,event:i,changedBy:t})}emitCallPermissionsUpdated(e){this.emit("callPermissionsUpdated",{call:this,permissions:e})}emitParticipantPermissionsUpdated(e,i){this.emit("participantPermissionsUpdated",{call:this,participant:e,permissions:i})}emitParticipantsAdded(e){this.emit("participantsAdded",{call:this,participants:e})}emitParticipantsRemoved(e){this.emit("participantsRemoved",{call:this,participants:e})}emitActiveSpeakersChanged(e){this._activeSpeakers=e,this.emit("activeSpeakersChanged",{call:this,activeSpeakers:e})}emitDominantSpeakerChanged(e){this.emit("dominantSpeakerChanged",{call:this,dominantSpeaker:e})}emitMediaFlowChanged(e){this.emit("mediaFlowChanged",{call:this,mediaFlow:e})}emitSessionRenewed(e){this.emit("sessionRenewed",{call:this,sessionId:e})}clearEventsQueue(){this.eventsQueue.clear()}setState(e,i){const t=new r.CallStateMachine(this.id).updateState(e,this.state,i);return t&&(this.state=e,e===o.CallState.Connected?this.activeSpeakerManager.start(s.InternalCallHandler.getInstance()):this.activeSpeakerManager.stop(),this.emitCallStateChanged(e)),t}addParticipants(e){const i=e=>s.InternalCallHandler.getInstance().addParticipantsToCall(e,this);return this.sessionId?i(e):this.eventsQueue.set("ADD_PARTICIPANTS",(()=>i(e))),{success:!0}}join(e,i){h.info(`[J1] [CallId: ${this.id}] Join call`,{color:"cyan"});try{if(!(new a.SendSignalValidator).canSendSignalEvent(o.SignalEvent.JOIN,this)){const e=`Cannot join call with ID ${this.id} due to invalid call state or participant state.`;return h.warn(`[J2] [CallId: ${this.id}] ${e}`,{color:"red"}),{success:!1,error:l.SceytCallException.BadRequest(4006,e)}}const t=s.InternalCallHandler.getInstance().joinCall(this,e,i);return(null==t?void 0:t.data)&&t.data.activeSpeakerManager.addParticipant(t.data.localParticipant),t}catch(e){return h.error(`[J3] [CallId: ${this.id}] Join failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}reject(e,i){try{return h.info(`[R1] [CallId: ${this.id}] Rejecting call`,{color:"cyan"}),s.InternalCallHandler.getInstance().rejectCall(this,e,i),this.activeSpeakerManager.removeParticipant(this.localParticipant),{success:!0}}catch(e){return h.error(`[R2] [CallId: ${this.id}] Rejection failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}leave(){try{return h.info(`[L1] [CallId: ${this.id}] Leaving call`,{color:"cyan"}),s.InternalCallHandler.getInstance().leaveCall(this,!0,"leave"),this.activeSpeakerManager.removeParticipant(this.localParticipant),{success:!0}}catch(e){return h.error(`[L2] [CallId: ${this.id}] Leave failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}create(){return n(this,void 0,void 0,(function*(){h.info(`[C1] [CallId: ${this.id}] Create call`,{color:"cyan"});try{const e=s.InternalCallHandler.getInstance();return yield e.createCall(this)}catch(e){return h.error(`[C3] [CallId: ${this.id}] create failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}addParticipantToList(e){this.participants.push(e)}kickParticipants(e){const i=e=>{const i=null==e?void 0:e.map((e=>({id:e})));return this.kickParticipantsFromList(i),!0};return this.sessionId?i(e):this.eventsQueue.set("KICK_PARTICIPANT",(()=>i(e))),{success:!0}}kickParticipantsFromList(e,i=!0){if(i)return s.InternalCallHandler.getInstance().kickParticipantsFromCall(e,this)}setSessionId(e){this.sessionId=e}setCreatedBy(e){this.createdBy=e}setVideoCall(e){this.videoCall=e}changeMediaFlow(e){this.mediaFlow!=e&&(this.mediaFlow=e,this.emitMediaFlowChanged(e))}switchToSFU(e){return n(this,void 0,void 0,(function*(){const i=i=>{h.info(`[159] [CallId: ${this.id}] handle switch call to ${o.MediaFlow.SFU}`,{color:"cyan"});const t=s.InternalCallHandler.getInstance(),n=t.activeCalls.find((e=>e.id===i));return t.switchCallToSfu(n,e)};return this.sessionId?i(this.id):this.eventsQueue.set(o.SignalEvent.SWITCH_MEDIA_FLOW,(()=>i(this.id))),{success:!0}}))}mute(e,i){var t,n;if(!e&&!1===(null===(t=this.localParticipant.permissions)||void 0===t?void 0:t.canPublishAudio))return{success:!1,error:new l.SceytCallException("Cannot unmute: you have been hard-muted by the host",403)};if(!e&&!1===(null===(n=this.permissions)||void 0===n?void 0:n.allowPublishAudio))return{success:!1,error:new l.SceytCallException("Cannot unmute: audio is locked for this call",403)};this.muted=e,this.localParticipant.setMediaAudioState({enabled:!e},this.localParticipant.permissions||{},this);const a=e=>{s.InternalCallHandler.getInstance().sendAudioEnable(this,e,i)};return this.sessionId?a(e):this.eventsQueue.set(o.SignalEvent.MUTE,(()=>a(e))),{success:!0}}muteAllRemoteParticipants(e){const i=()=>{s.InternalCallHandler.getInstance().muteAllRemoteParticipants(this,e)};return this.sessionId?i():this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_AUDIO,(()=>i())),{success:!0}}videoOffAllRemoteParticipants(e){const i=()=>{s.InternalCallHandler.getInstance().videoOffAllRemoteParticipants(this,e)};return this.sessionId?i():this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_VIDEO,(()=>i())),{success:!0}}disableAllRemoteParticipantsVideo(e){return this.videoOffAllRemoteParticipants(e)}updateParticipantPermissions(e,i,t){const n=e=>{s.InternalCallHandler.getInstance().updateParticipantPermissions(this,e,i,t)};return this.sessionId?n(e):this.eventsQueue.set(o.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE,(()=>n(e))),{success:!0}}muteRemoteParticipant(e,i){const t=e=>{s.InternalCallHandler.getInstance().muteRemoteParticipant(this,e,i)};return this.sessionId?t(e):this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_AUDIO,(()=>t(e))),{success:!0}}disableRemoteParticipantAudio(e,i){const t=e=>{s.InternalCallHandler.getInstance().disableRemoteParticipantAudio(this,e,i)};return this.sessionId?t(e):this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_AUDIO,(()=>t(e))),{success:!0}}enableRemoteParticipantAudio(e,i){const t=e=>{s.InternalCallHandler.getInstance().enableRemoteParticipantAudio(this,e,i)};return this.sessionId?t(e):this.eventsQueue.set(o.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE,(()=>t(e))),{success:!0}}enableCallAudio(e){var i,t;return this.updateCallPermissions({allowPublishAudio:!0,allowPublishVideo:null===(t=null===(i=this.permissions)||void 0===i?void 0:i.allowPublishVideo)||void 0===t||t},e)}disableCallAudio(e){var i,t;return this.updateCallPermissions({allowPublishAudio:!1,allowPublishVideo:null===(t=null===(i=this.permissions)||void 0===i?void 0:i.allowPublishVideo)||void 0===t||t},e)}disableRemoteParticipantVideo(e,i){const t=e=>{s.InternalCallHandler.getInstance().videoOffRemoteParticipant(this,e,i)};return this.sessionId?t(e):this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_VIDEO,(()=>t(e))),{success:!0}}videoOffRemoteParticipant(e,i){const t=e=>{s.InternalCallHandler.getInstance().videoOffRemoteParticipant(this,e,i)};return this.sessionId?t(e):this.eventsQueue.set(o.SignalEvent.DISABLE_REMOTE_VIDEO,(()=>t(e))),{success:!0}}disableCallVideo(e){var i,t;return this.updateCallPermissions({allowPublishAudio:null===(t=null===(i=this.permissions)||void 0===i?void 0:i.allowPublishAudio)||void 0===t||t,allowPublishVideo:!1},e)}enableCallVideo(e){var i,t;return this.updateCallPermissions({allowPublishAudio:null===(t=null===(i=this.permissions)||void 0===i?void 0:i.allowPublishAudio)||void 0===t||t,allowPublishVideo:!0},e)}updateCallPermissions(e,i){const t=()=>{s.InternalCallHandler.getInstance().updateCallPermissions(this,e,i)};return this.sessionId?t():this.eventsQueue.set(o.SignalEvent.CALL_PERMISSIONS_UPDATE,(()=>t())),{success:!0}}hold(e){this.onHold=e,this.localAudioTracks.forEach((i=>{i.enabled=!e})),this.localVideoTracks.forEach((i=>{i.enabled=!e})),this.localParticipant.audioTracks.forEach((i=>{i.enabled=!e})),this.localParticipant.videoTracks.forEach((i=>{i.enabled=!e}));const i=e=>{s.InternalCallHandler.getInstance().sendHold(this,e)};return this.sessionId?i(e):this.eventsQueue.set(o.SignalEvent.HOLD,(()=>i(e))),{success:!0}}set localAudioTracks(e){this._localAudioTracks=e}get localAudioTracks(){return this._localAudioTracks}set localVideoTracks(e){this._localVideoTracks=e}get localVideoTracks(){return this._localVideoTracks}setServerParticipant(e){this.serverParticipant=e}set muted(e){this._muted=e}get muted(){return this._muted}set screenSharing(e){this._screenSharing=e}get screenSharing(){return this._screenSharing}set onHold(e){this._onHold=e}get onHold(){return this._onHold}setIsCallSilenced(e){this.isCallSilenced=e}getIsCallSilenced(){return this.isCallSilenced}setVideoDeviceId(e){this.videoDeviceId=e}getVideoDeviceId(){return this.videoDeviceId}setAudioDeviceId(e){this.audioDeviceId=e}getAudioDeviceId(){return this.audioDeviceId}setIsCreatedRemotely(e){this.isCreatedRemotely=e}getIsCreatedRemotely(){return this.isCreatedRemotely}enableVideo(e,i){return n(this,void 0,void 0,(function*(){return this.localParticipantVideoEnable(e,i)}))}localParticipantVideoEnable(e,i,t,a=!0){return n(this,void 0,void 0,(function*(){const t=s.InternalCallHandler.getInstance();let l=[];return e||(this.localVideoTracks.forEach((e=>{e.stop()})),this.localParticipant.videoTracks.forEach((e=>{e.enabled=!1}))),yield(()=>n(this,void 0,void 0,(function*(){var s,r,d,c,u,g;try{if(e){const e=(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind));this.videoDeviceId&&(e.some((e=>e.deviceId===this.videoDeviceId))||(h.warn(`Previously selected video device with ID ${this.videoDeviceId} not found. Falling back to default camera.`),this.setVideoDeviceId(null)));const i=null===(s=this.localVideoTracks[0])||void 0===s?void 0:s.getSettings().deviceId;if(this.videoDeviceId&&i===this.videoDeviceId&&"live"===(null===(r=this.localVideoTracks[0])||void 0===r?void 0:r.readyState))l=this.localVideoTracks;else{this.localVideoTracks.forEach((e=>{e.stop()})),this.localParticipant.videoTracks.forEach((e=>{e.enabled=!1}));const e=yield navigator.mediaDevices.getUserMedia({video:Object.assign(Object.assign({},this.videoDeviceId?{deviceId:{exact:this.videoDeviceId}}:{}),{width:{min:640,max:1280},height:{min:480,max:720}})});l=e.getVideoTracks(),l.sort((e=>(e.getSettings().deviceId||"")===this.videoDeviceId?-1:1)),this.setVideoDeviceId((null===(d=l[0])||void 0===d?void 0:d.getSettings().deviceId)||null)}}else l=this.localVideoTracks;!this.videoDeviceId&&l.length>0&&this.setVideoDeviceId((null===(c=l[0])||void 0===c?void 0:c.getSettings().deviceId)||null),this.localVideoTracks=l,this.localParticipant.setVideoTracks(l,this),this.localParticipant.setMediaVideoState({enabled:e,changedBy:null===(u=this.localParticipant.mediaState)||void 0===u?void 0:u.video.changedBy},this.localParticipant.permissions||{},this),this.localParticipant.videoTracks.forEach((i=>{i.enabled=e})),this.localVideoTracks&&(null===(g=this.localVideoTracks)||void 0===g?void 0:g.length)&&(yield t.changeVideoTracks(this,this.localVideoTracks[0],e));const v=e=>n(this,void 0,void 0,(function*(){try{t.sendVideoEnabled(this,e,i)}catch(e){return h.error(`[323] [CallId: ${this.id}] Failed to send video enabled signal: message: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),void(null==i||i({error:(0,p.toCallException)(e)}))}}));a&&(this.sessionId?v(e):this.eventsQueue.set(e?o.SignalEvent.VIDEO_ON:o.SignalEvent.VIDEO_OFF,(()=>v(e))))}catch(e){return h.error(`[325] [CallId: ${this.id}] Error enabling video ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}})))(),{success:!0}}))}shareScreen(e,i){var t,a,l,r,d;return n(this,void 0,void 0,(function*(){let c=[];this.screenSharing=e;try{if(e){const i=yield navigator.mediaDevices.getDisplayMedia({video:{width:{max:1280},height:{max:720},frameRate:{max:30}}});if(this.localVideoTracks.forEach((e=>{e.stop()})),c=i.getVideoTracks(),i.addEventListener("inactive",(()=>{var e;(null===(e=this.localParticipant.mediaState)||void 0===e?void 0:e.screenShare.enabled)&&this.stopScreenShare()})),this.localVideoTracks=c,this.localParticipant.setVideoTracks(c,this),this.localParticipant.videoTracks.forEach((i=>{i.enabled=e})),c&&c.length){const i=s.InternalCallHandler.getInstance();yield i.changeVideoTracks(this,c[0],e,!0)}this.localParticipant.setMediaScreenShareState({enabled:e,changedBy:null===(t=this.localParticipant.mediaState)||void 0===t?void 0:t.screenShare.changedBy},this)}else(null===(l=null===(a=this.localParticipant.mediaState)||void 0===a?void 0:a.video)||void 0===l?void 0:l.enabled)&&!e?(this.localParticipant.setMediaScreenShareState({enabled:e,changedBy:null===(r=this.localParticipant.mediaState)||void 0===r?void 0:r.screenShare.changedBy},this),yield this.localParticipantVideoEnable(!0,i,!0)):this.localParticipant.setMediaScreenShareState({enabled:e,changedBy:null===(d=this.localParticipant.mediaState)||void 0===d?void 0:d.screenShare.changedBy},this);const u=e=>n(this,void 0,void 0,(function*(){const t=s.InternalCallHandler.getInstance();this.videoEnabled&&e?yield t.sendVideoEnabled(this,!1,i):this.videoEnabled&&!e&&(yield t.sendVideoEnabled(this,!0,i)),yield t.sendScreenShare(this,e,i)}));return this.sessionId?u(e):this.eventsQueue.set(e?o.SignalEvent.SCREEN_SHARE_ON:o.SignalEvent.SCREEN_SHARE_OFF,(()=>u(e))),{success:!0}}catch(e){return h.error(`[324] [CallId: ${this.id}] Error sharing screen ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}startScreenShare(e){return n(this,void 0,void 0,(function*(){return this.shareScreen(!0,e)}))}stopScreenShare(e){return n(this,void 0,void 0,(function*(){return yield this.shareScreen(!1,e)}))}getAvailableVideoDevices(){return n(this,void 0,void 0,(function*(){try{return{success:!0,data:(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind))}}catch(e){return h.error(`[306] [CallId: ${this.id}] Error getting video devices ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}getAvailableAudioDevices(){return n(this,void 0,void 0,(function*(){try{return{success:!0,data:(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"audioinput"===e.kind))}}catch(e){return h.error(`[307] [CallId: ${this.id}] Error getting audio devices ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}selectVideoDevice(e){var i,t;return n(this,void 0,void 0,(function*(){if(this.setVideoDeviceId(e),!this.videoEnabled||(null===(i=this.localParticipant.mediaState)||void 0===i?void 0:i.screenShare.enabled))return{success:!0};try{this.localVideoTracks.forEach((e=>{e.stop()}));const i=(yield navigator.mediaDevices.getUserMedia({video:{deviceId:{exact:e},width:{min:640,max:1280},height:{min:480,max:720}}})).getVideoTracks();this.localVideoTracks=i,this.localParticipant.setVideoTracks(i,this);const n=s.InternalCallHandler.getInstance();return yield n.changeVideoTracks(this,i[0],!!(null===(t=this.localParticipant.mediaState)||void 0===t?void 0:t.video.enabled)),{success:!0}}catch(e){return h.error(`[308] [CallId: ${this.id}] Error selecting video device ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}selectAudioDevice(e){var i,t;return n(this,void 0,void 0,(function*(){try{const n=s.InternalCallHandler.getInstance(),a=(yield navigator.mediaDevices.getUserMedia({audio:{deviceId:{exact:e}}})).getAudioTracks();return this.localAudioTracks=a,this.localParticipant.setAudioTracks(a,this),this.setAudioDeviceId((null===(i=a[0])||void 0===i?void 0:i.getSettings().deviceId)||null),yield n.changeAudioTracks(this,a[0],!(null===(t=this.localParticipant.mediaState)||void 0===t?void 0:t.audio.enabled)),{success:!0}}catch(e){return h.error(`[309] [CallId: ${this.id}] Error selecting audio device ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,p.toCallException)(e)}}}))}setVideoEnabled(e){this.videoEnabled=e}setMuted(e){this._muted=e}getParticipant(e,i){return this.participants.find((t=>t.id===e&&t.clientId===i))}sendRinging(e){return s.InternalCallHandler.getInstance().sendRinging(this,e)}setSettings(e){return void 0!==(null==e?void 0:e.callType)&&(this.callType=e.callType),this.settings=e,{success:!0}}toJson(){return{id:this.id,sessionId:this.sessionId,mediaFlow:this.mediaFlow,participants:this.participants,localParticipant:this.localParticipant,createdBy:this.createdBy,metadata:this.metadata,state:this.state,activeSpeakerManager:this.activeSpeakerManager,eventsQueue:this.eventsQueue,chatClient:this.chatClient,serverParticipant:this.serverParticipant,videoEnabled:this.videoEnabled,onHold:this.onHold,localAudioTracks:this.localAudioTracks,localVideoTracks:this.localVideoTracks,muted:this.muted,isCallSilenced:this.isCallSilenced}}}i.Call=g},228:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.checkCode=i.toCallException=i.handleAck=void 0;const n=t(65);function a(e,i){switch(e){case 4e3:return n.SceytCallException.BadSignal(e,i);case 4001:return n.SceytCallException.CallNotFound(e,i);case 4002:return n.SceytCallException.ParticipantNotFound(e,i);case 4005:case 4003:return n.SceytCallException.NotAllowed(e,i);case 4004:return n.SceytCallException.ParticipantAlreadyExists(e,i);case 5001:return n.SceytCallException.InternalError(e,i);case 9901:case 9903:case 9904:return n.SceytCallException.NetworkError(e,i);case 9902:return n.SceytCallException.Timeout(e,i);case 4006:return n.SceytCallException.BadRequest(e,i);default:return n.SceytCallException.Unknown(e,i)}}i.handleAck=function(e){return e.error&&a(e.error.code,e.error.message),e},i.toCallException=function(e){try{if(null==e?void 0:e.code)return a(e.code,e.message)}catch(e){if(e instanceof n.SceytCallException)return e}return n.SceytCallException.Unknown(void 0,(null==e?void 0:e.message)||String(e))},i.checkCode=a},65:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SceytCallException=void 0;class t extends Error{get isResendable(){return this._isResendable}constructor(e,i,t="SceytCallException"){super(e),this.code=i,this.name=t,this._isResendable=!1,this.name=t}static BadSignal(e,i){return new t(i,e,"BadSignal")}static CallNotFound(e,i){return new t(i,e,"CallNotFound")}static ParticipantNotFound(e,i){return new t(i,e,"ParticipantNotFound")}static NotAllowed(e,i){return new t(i,e,"NotAllowed")}static ParticipantAlreadyExists(e,i){return new t(i,e,"ParticipantAlreadyExists")}static InternalError(e,i){const n=new t(i,e,"InternalError");return n._isResendable=!0,n}static NetworkError(e,i){const n=new t(i,e,"NetworkError");return n._isResendable=!0,n}static Timeout(e,i){const n=new t(i,e,"Timeout");return n._isResendable=!0,n}static BadRequest(e,i){return new t(i,e,"BadRequest")}static Unknown(e,i){return new t(i,e)}}i.SceytCallException=t},650:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(i,"__esModule",{value:!0}),i.InternalCallHandler=void 0;const l=a(t(583)),s=t(787),o=t(546),r=t(786),d=t(578),c=t(998),u=t(489),p=t(645),h=t(429),g=t(65),v=t(680),S=t(228),f=(0,p.createLogger)("InternalCallHandler"),C="$all";class I{constructor(e){this.callParticipantsRTCMap={},this.activeCalls=[],this.prepareCalls=[],this.callEvents={},this.handleMediaConnectedSignal=e=>{const i=this.activeCalls.find((i=>i.id===e.callId));if(i){let t=null==i?void 0:i.participants.find((i=>i.getFullId()===e.from));if(t||(t=i.participants.find((i=>{var t;return i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&!i.clientId})),t?t.clientId=e.from.split("/")[1]:(t=new s.Participant(e.from),i.addParticipantToList(t),i.emitParticipantsAdded([t]))),t&&i.localParticipant.state===d.ParticipantState.Joined&&i.localParticipant.getFullId()!==t.getFullId()&&(!this.callParticipantsRTCMap[i.id]||!this.callParticipantsRTCMap[i.id][t.getFullId()]||(null==t?void 0:t.shouldResetPeerConnection)||(null==t?void 0:t.connectionState)!==d.ParticipantConnectionState.Connected)){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[968] [CallId: ${i.id}] SYNC CONNECT failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`):e.event!==d.SignalEvent.ERROR||f.error(`[971] [CallId: ${i.id}] SYNC CONNECT failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};f.info(`[975] [CallId: ${i.id}] SYNC CONNECT to participant ${t.getFullId()}`,{color:"blue"}),this.signalingClient.clearParticipantSignals(i.id,t.getFullId()),this.signalingClient.sendSignalMessage({to:t.getFullId(),event:d.SignalEvent.CONNECT,mediaFlow:i.mediaFlow,callId:i.id,sessionId:i.sessionId},e)}}},this.onIceCandidate=(e,i,t)=>{var n,a;if(t.mediaFlow!==d.MediaFlow.SFU)if(f.info(`[996] [CallId: ${t.id}] onIceCandidate, participantID: ${e.getFullId()}, candidate: ${null===(n=i.candidate)||void 0===n?void 0:n.candidate}, type: ${null===(a=i.candidate)||void 0===a?void 0:a.type}`,{color:"blue"}),i.candidate&&i.candidate.candidate){let n="";if(!/\bufrag\s+\S+/i.test(i.candidate.candidate)&&this.callParticipantsRTCMap[t.id]&&this.callParticipantsRTCMap[t.id][e.getFullId()]){const i=this.callParticipantsRTCMap[t.id][e.getFullId()];i&&(n=` ufrag ${i.getLocalSdpUfrag()}`)}const a={candidate:i.candidate.candidate+n,sdpMid:i.candidate.sdpMid||"",sdpMLineIndex:i.candidate.sdpMLineIndex||0};try{const i=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[1007] [CallId: ${t.id}] SYNC ICE failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`):e.event!==d.SignalEvent.ERROR||f.error(`[1011] [CallId: ${t.id}] SYNC ICE failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};this.signalingClient.sendSignalMessage({to:this.getParticipantId(e),event:d.SignalEvent.ICE,mediaFlow:t.mediaFlow,callId:t.id,sessionId:t.sessionId,ice:a},i)}catch(i){f.error(`[1023] [CallId: ${t.id}] Failed to send ICE candidate to ${e.getFullId()}: ${i instanceof Error?i.message:JSON.stringify(i)}`)}}else f.info(`[1025] [CallId: ${t.id}] ICE gathering complete for participant ${e.getFullId()} (null candidate)`,{color:"blue"});else f.info(`[1024] [CallId: ${t.id}] onIceCandidate, participantID: ${e.getFullId()}, skip for SFU`,{color:"blue"})},this.onTrack=(e,i,t)=>{const n=null==t?void 0:t.track;f.info(`[1032] [CallId: ${e.id}] onTrack, participantID: ${i.getFullId()}, kind: ${n.kind}`,{color:"blue"}),"audio"===(null==n?void 0:n.kind)?(i.setAudioTracks([n],e),n.onended=()=>{f.info(`[1038] [CallId: ${e.id}] Audio track ended for participant ${i.getFullId()}`,{color:"yellow"}),i.setAudioTracks([],e),e.emitAudioTrackRemoved(i)}):"video"===(null==n?void 0:n.kind)&&(i.setVideoTracks([n],e),n.onended=()=>{f.info(`[1052] [CallId: ${e.id}] Video track ended for participant ${i.getFullId()}`,{color:"yellow"}),i.setVideoTracks([],e),e.emitVideoTrackRemoved(i)})},this.kickParticipantsFromCall=(e,i)=>{this.signalingClient.sendSignalMessage({mediaFlow:i.mediaFlow,callId:i.id,event:d.SignalEvent.KICK,sessionId:i.sessionId,participants:e.map((e=>({id:e.id,clientId:""})))},(t=>{if(t instanceof g.SceytCallException||t instanceof Error)f.error(`[1642] [CallId: ${i.id}] Kick participant failed: ${t.message} code: ${t instanceof g.SceytCallException?t.code:""}`,{color:"red"});else if(t.event!==d.SignalEvent.ERROR)for(let t=0;t<e.length;t++){const n=e[t];i.participants.forEach((e=>{e.id===n.id&&(this.closePeerConnections(i.id,e.getFullId()),i.activeSpeakerManager.removeParticipant(e),e.updateState(d.ParticipantState.Kicked,i),e.updateConnectionState(d.ParticipantConnectionState.Idle,i))}))}else f.error(`[1646] [CallId: ${i.id}] Kick participant failed: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"})}))},this.addParticipantsToCall=(e,i)=>{try{if(e.forEach((e=>{const t=i.participants.filter((i=>i.id===e));if(t.length>0)for(const e of t)e.state!==d.ParticipantState.Joined&&e.state!==d.ParticipantState.Ringing&&(e.updateState(d.ParticipantState.Idle,i),e.updateConnectionState(d.ParticipantConnectionState.Idle,i));else{const t=new s.Participant(e);i.addParticipantToList(t),i.emitParticipantsAdded([t])}})),f.info(`[1547] [CallId: ${i.id}] added participants to call: ${e}, callId: ${i.id}`,{color:"light-green"}),e.length>0){const t=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[1551] [CallId: ${i.id}] SYNC INVITE failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[1555] [CallId: ${i.id}] SYNC INVITE failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};return this.signalingClient.sendSignalMessage({callId:i.id,sessionId:i.sessionId,event:d.SignalEvent.INVITE,participants:e.map((e=>new s.Participant(e).serialize()))},t),!0}return!1}catch(t){return f.error(`[1567] [CallId: ${i.id}] Failed to add participants to call: ${e}, callId: ${i.id} message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"}),!1}},this.sendSignalScreenShare=(e,i,t)=>{try{const n=i=>i instanceof g.SceytCallException||i instanceof Error?(f.error(`[1679] [CallId: ${e.id}] SYNC SCREEN_SHARE_ON failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`),void(null==t||t({error:(0,S.toCallException)(i)}))):i.event===d.SignalEvent.ERROR?(f.error(`[1683] [CallId: ${e.id}] SYNC SCREEN_SHARE_ON failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`),void(null==t||t({error:(0,S.toCallException)(i.error)}))):void 0;return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:i?d.SignalEvent.SCREEN_SHARE_ON:d.SignalEvent.SCREEN_SHARE_OFF,sessionId:e.sessionId},n),!0}catch(i){return f.error(`[1694] [CallId: ${e.id}] Failed to send screen share signal: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"}),null==t||t({error:(0,S.toCallException)(i)}),!1}},this.setupMediaStream=e=>n(this,void 0,void 0,(function*(){var i,t;try{const n=!e.getAudioDeviceId()||{deviceId:{exact:e.getAudioDeviceId()}},a=(yield navigator.mediaDevices.getUserMedia({video:!1,audio:n})).getAudioTracks();if(e.localAudioTracks=a,e.setAudioDeviceId((null===(i=a[0])||void 0===i?void 0:i.getSettings().deviceId)||null),!(null==e?void 0:e.localVideoTracks)||!(null===(t=e.localVideoTracks)||void 0===t?void 0:t.length)){const i=(0,u.getEmptyVideoTrack)();i.forEach((e=>e.enabled=!1)),e.localVideoTracks=i,e.localParticipant.setVideoTracks(i,e)}return e.localParticipant.audioTracks=a,{audioTracks:a}}catch(i){throw f.error(`[1945] [CallId: ${e.id}] Failed to get media: message: ${i instanceof Error?i.message:JSON.stringify(i)}`),(0,S.toCallException)(i)}})),this.chatClient=e,this.user=e.user,this.clientId=e.clientId,this.signalingClient=new r.Signaling(e,this.handleSignalMessage.bind(this));const i=new this.chatClient.ConnectionListener;i.onConnectionStateChanged=e=>{f.info(`[46] [CallId: GLOBAL_LOGS] Signaling connection state changed: ${e}`,{color:"cyan"}),"Connected"===e&&(this.activeCalls.forEach((e=>{const i=this.signalingClient.signalingQueues.get(e.id);i&&i.triggerSignalProcessing()})),setTimeout((()=>{this.signalingClient.sendSignalMessage({event:d.SignalEvent.GET_CALL,callId:""},(e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[57] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed ${e instanceof g.SceytCallException||e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}):e.event!==d.SignalEvent.ERROR?this.syncActiveCalls(e):f.error("[63] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: "+(e.error?`${e.error.message} code: ${e.error.code}`:""),{color:"red"})}),"get_call")}),1e3))},this.chatClient.addConnectionListener("listener_id",i),"Connected"===this.chatClient.connectionState&&setTimeout((()=>{this.signalingClient.sendSignalMessage({event:d.SignalEvent.GET_CALL,callId:""},(e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[74] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR?this.syncActiveCalls(e):f.error("[77] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: "+(e.error?`${e.error.message} code: ${e.error.code}`:""),{color:"red"})}),"get_call")}),1e3),I.instance=this}syncActiveCalls(e){var i,t;const n=this.activeCalls;try{if(!(null==e?void 0:e.calls))return;if(e.event!==d.SignalEvent.SUCCESS)return void f.error("[98] [CallId: GLOBAL_LOGS] Failed to get call information after reconnection message: "+(e.error?`${e.error.message} code: ${e.error.code}`:""),{color:"red"});for(const a of n){const n=e.calls.find((e=>(null==e?void 0:e.id)===a.id));if(!n&&!(null==a?void 0:a.sessionId))continue;if(!n){this.closeCall(a);continue}if(n.sessionId!==a.sessionId){f.info(`[syncActiveCalls] [CallId: ${a.id}] sessionId changed (${a.sessionId} → ${n.sessionId}), closing stale call`,{color:"yellow"}),this.closeCall(a),this.promoteFromPrepared(n.id,n)?f.info(`[syncActiveCalls] [CallId: ${n.id}] Promoted from prepareCalls to activeCalls`,{color:"cyan"}):this.findOrCreateCall({id:n.id,sessionId:n.sessionId,mediaFlow:n.mediaFlow,participants:[],metadata:n.metadata,createdBy:n.createdBy,callOptions:null==n?void 0:n.options},n.participants);continue}const l=a.mediaFlow!==d.MediaFlow.SFU&&n.mediaFlow===d.MediaFlow.SFU;if(this.updateCallMetadata(a,n),l&&this.handleMediaFlowSwitch(a),this.syncParticipants(a,n.participants),a.localParticipant.state<=d.ParticipantState.Joined&&(a.state===d.CallState.Connected||a.state===d.CallState.Connecting)){for(const e of a.participants)if(a.mediaFlow!==d.MediaFlow.SFU&&e.connectionState===d.ParticipantConnectionState.Connected&&e.id!==a.localParticipant.id&&e.clientId!==a.localParticipant.clientId){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[139] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[143] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({event:d.SignalEvent.MEDIA_CONNECTED,callId:a.id,sessionId:a.sessionId,mediaFlow:a.mediaFlow,to:a.id},e)}if(a.mediaFlow===d.MediaFlow.SFU&&(null===(i=a.serverParticipant)||void 0===i?void 0:i.connectionState)===d.ParticipantConnectionState.Connected&&a.state===d.CallState.Connected){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[158] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[162] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({event:d.SignalEvent.MEDIA_CONNECTED,callId:a.id,sessionId:a.sessionId,mediaFlow:a.mediaFlow,to:a.id},e)}if(a.mediaFlow!==d.MediaFlow.SFU||this.callParticipantsRTCMap[a.id]&&this.callParticipantsRTCMap[a.id][a.id]||a.state!==d.CallState.Connected){if(a.mediaFlow===d.MediaFlow.SFU&&a.serverParticipant&&a.state===d.CallState.Connected){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[199] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[203] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};f.info(`[205] [CallId: ${a.id}] Sending offer to server participant when server participant is not connected: ${a.serverParticipant.getFullId()}`,{color:"yellow"}),this.sendOfferPeerToPeer(a,a.serverParticipant,e)}}else{if((null===(t=a.serverParticipant)||void 0===t?void 0:t.id)!==a.id){const e=new s.Participant(a.id);a.setServerParticipant(e)}if(a.serverParticipant){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[181] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[185] [CallId: ${a.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};f.info(`[188] [CallId: ${a.id}] Sending offer to server participant when there is no server participant in the call: ${a.serverParticipant.getFullId()}`,{color:"yellow"}),this.sendOfferPeerToPeer(a,a.serverParticipant,e)}}}else a.localParticipant.state===d.ParticipantState.Joined&&this.leaveCall(a,!1,"syncActiveCalls")}this.activeCalls=this.activeCalls.filter((i=>{var t;return!(!(null===(t=null==e?void 0:e.calls)||void 0===t?void 0:t.find((e=>e.id===i.id)))&&i.sessionId&&(i.clearEventsQueue(),i.participants.forEach((e=>{this.signalingClient.clearParticipantSignals(i.id,e.getFullId())})),this.signalingClient.clearCallSignals(i.id),1))})),e.calls.forEach((e=>{!this.activeCalls.find((i=>(null==i?void 0:i.id)===(null==e?void 0:e.id)))&&e.id&&e.sessionId&&(this.promoteFromPrepared(e.id,e)?f.info(`[syncActiveCalls] [CallId: ${e.id}] Promoted from prepareCalls to activeCalls`,{color:"cyan"}):this.findOrCreateCall({id:e.id,sessionId:e.sessionId,mediaFlow:e.mediaFlow,participants:[],metadata:e.metadata,createdBy:e.createdBy,callOptions:null==e?void 0:e.options},e.participants))})),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}catch(e){f.error(`[248] [CallId: GLOBAL_LOGS] Error syncing calls after reconnection: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}setCallEvent(e,i){this.callEvents[e]=i}handleSignalMessage(e){var i,t,n,a,l,s,o,r;switch(e.callOptions=Object.assign(Object.assign({},e.callOptions||{}),{settings:Object.assign(Object.assign({},(null===(i=null==e?void 0:e.callOptions)||void 0===i?void 0:i.settings)||{}),{permissions:{allowPublishAudio:!(null===(a=null===(n=null===(t=null==e?void 0:e.callOptions)||void 0===t?void 0:t.settings)||void 0===n?void 0:n.permissions)||void 0===a?void 0:a.audioPublishingDisabled),allowPublishVideo:!(null===(o=null===(s=null===(l=null==e?void 0:e.callOptions)||void 0===l?void 0:l.settings)||void 0===s?void 0:s.permissions)||void 0===o?void 0:o.videoPublishingDisabled)}})}),e.calls=null===(r=e.calls)||void 0===r?void 0:r.map((e=>{var i,t,n,a,l,s,o;return Object.assign(Object.assign({},e),{options:Object.assign(Object.assign({},(null==e?void 0:e.options)||{}),{settings:Object.assign(Object.assign({},(null===(i=null==e?void 0:e.options)||void 0===i?void 0:i.settings)||{}),{permissions:{allowPublishAudio:!(null===(a=null===(n=null===(t=null==e?void 0:e.options)||void 0===t?void 0:t.settings)||void 0===n?void 0:n.permissions)||void 0===a?void 0:a.audioPublishingDisabled),allowPublishVideo:!(null===(o=null===(s=null===(l=null==e?void 0:e.options)||void 0===l?void 0:l.settings)||void 0===s?void 0:s.permissions)||void 0===o?void 0:o.videoPublishingDisabled)}})})})})),f.info(`[253] [CallId: ${e.callId}] Received message ${d.SignalEvent[e.event]}: ${JSON.stringify(Object.assign({},e))}`,{color:"green"}),e.event||0){case d.SignalEvent.OFFER:this.handleOfferSignal(e);break;case d.SignalEvent.ANSWER:this.handleAnswerSignal(e);break;case d.SignalEvent.JOIN:this.handleJoinSignal(e);break;case d.SignalEvent.LEAVE:this.handleLeaveSignal(e);break;case d.SignalEvent.INVITE:this.handleInviteSignal(e);break;case d.SignalEvent.CLOSE:this.handleCloseSignal(e);break;case d.SignalEvent.DECLINE:this.handleDeclineSignal(e);break;case d.SignalEvent.RINGING:this.handleRingingSignal(e);break;case d.SignalEvent.SWITCH_MEDIA_FLOW:this.handleSwitchMediaFlowSignal(e);break;case d.SignalEvent.ICE:this.handleIceSignal(e);break;case d.SignalEvent.VIDEO_ON:this.handleVideoOnSignal(e);break;case d.SignalEvent.VIDEO_OFF:this.handleVideoOffSignal(e);break;case d.SignalEvent.SCREEN_SHARE_ON:this.handleScreenShareOnSignal(e);break;case d.SignalEvent.SCREEN_SHARE_OFF:this.handleScreenShareOffSignal(e);break;case d.SignalEvent.MUTE:this.handleMuteSignal(e);break;case d.SignalEvent.UNMUTE:this.handleUnmuteSignal(e);break;case d.SignalEvent.HOLD:this.handleHoldSignal(e);break;case d.SignalEvent.UNHOLD:this.handleUnholdSignal(e);break;case d.SignalEvent.KICK:this.handleKickSignal(e);break;case d.SignalEvent.UPDATE:this.handleUpdateSignal(e);break;case d.SignalEvent.NO_ANSWER:this.handleNoAnswerSignal(e);break;case d.SignalEvent.MEDIA_CONNECTED:this.handleMediaConnectedSignal(e);break;case d.SignalEvent.CONNECT:this.handleConnectSignal(e);break;case d.SignalEvent.SESSION_RENEWED:this.handleSessionRenewedSignal(e);break;case d.SignalEvent.CALL_PERMISSIONS_UPDATE:this.handleCallPermissionsUpdateSignal(e);break;case d.SignalEvent.DISABLE_REMOTE_AUDIO:this.handleDisableRemoteAudioSignal(e);break;case d.SignalEvent.DISABLE_REMOTE_VIDEO:this.handleDisableRemoteVideoSignal(e);break;case d.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE:this.handleParticipantPermissionsUpdateSignal(e);break;default:f.info(`[254] [CallId: ${e.callId}] unhandled signal message: ${JSON.stringify(e)}`,{color:"green"})}}getParticipantId(e){return`${e.id}${(null==e?void 0:e.clientId)?"/"+(null==e?void 0:e.clientId):""}`}handleOfferSignal(e){var i,t,a,l,s;if(!this.activeCalls)return void f.warn(`[342] [CallId: ${e.callId}] No active calls found for send offer participant: ${e.from}`,{color:"red"});let o;try{const r=this.activeCalls.find((i=>i.id===e.callId));if(!r)return void f.warn(`[348] [CallId: ${e.callId}] No active call found for send offer participant: ${e.from}`,{color:"red"});if(r.state!==d.CallState.Connected&&r.state!==d.CallState.Connecting)return void f.warn(`[353] [CallId: ${e.callId}] Call is not connected for send offer participant: ${e.from}`,{color:"red"});let c=null==r?void 0:r.participants.find((i=>i.getFullId()===e.from));if(c){o=c.getFullId();const u=this.callParticipantsRTCMap[r.id]&&(null===(i=this.callParticipantsRTCMap[r.id])||void 0===i?void 0:i[c.getFullId()]);let p=null==u?void 0:u.getSessionId();!c.shouldResetPeerConnection&&u&&p===(null===(t=e.sessionData)||void 0===t?void 0:t.id)||(this.closePeerConnections(r.id,c.getFullId()),r.activeSpeakerManager.removeParticipant(c),this.addParticipantToRTCMap(r,c),c.setShouldResetPeerConnection(!1),(this.callParticipantsRTCMap[r.id]&&(null===(a=this.callParticipantsRTCMap[r.id])||void 0===a?void 0:a[c.getFullId()])).setSessionId((null===(l=e.sessionData)||void 0===l?void 0:l.id)||"")),this.signalingClient.clearParticipantSignals(r.id,c.getFullId()),f.info(`[394] [CallId: ${r.id}] setRemoteDescription (offer) for participant: ${c.getFullId()}, sessionId: ${null===(s=e.sessionData)||void 0===s?void 0:s.id}`,{color:"blue"}),this.setRemoteDescription(r.id,c.getFullId(),(0,v.toSessionDescription)(e.sessionData,"offer")).then((()=>n(this,void 0,void 0,(function*(){var i,t,n,a,l;if(!c)return void f.info(`[392] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});const s=this.callParticipantsRTCMap[r.id][c.getFullId()],o=this.activeCalls.find((e=>e.id===r.id));o&&(o.mediaFlow!==d.MediaFlow.SFU||o.mediaFlow===d.MediaFlow.SFU&&c.id===(null===(i=null==o?void 0:o.serverParticipant)||void 0===i?void 0:i.id))&&(yield this.addTracksToPeerConnection(r,c.getFullId(),!1)),f.info(`[393] [CallId: ${r.id}] createAnswer for participant: ${c.getFullId()}, sessionId: ${null===(t=e.sessionData)||void 0===t?void 0:t.id}, version: ${null===(n=e.sessionData)||void 0===n?void 0:n.version}`,{color:"blue"}),s.createAnswer((null===(a=e.sessionData)||void 0===a?void 0:a.id)||"",(null===(l=e.sessionData)||void 0===l?void 0:l.version)||"",r.mediaFlow).then((i=>{if(!c)return void f.info(`[392] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});if(!i)return void f.error(`[456] [CallId: ${r.id}] Failed to create answer for participant: ${c.getFullId()}`,{color:"red"});const t=s.getRemoteSdpUfrag();if(t&&s.iceQueueMap[c.getFullId()]){const e=s.iceQueueMap[c.getFullId()][t];if(e&&e.length>0)for(const i of e)s.addIceCandidate(i,c.getFullId())}this.signalingClient.sendSignalMessage({to:e.from,mediaFlow:e.mediaFlow,callId:r.id,event:d.SignalEvent.ANSWER,sessionData:i,sessionId:e.sessionId,metadata:e.metadata},(e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[386] [CallId: ${r.id}] SYNC ANSWER failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[389] [CallId: ${r.id}] SYNC ANSWER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})}))}))}))))}else f.info(`[402] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"})}catch(i){f.error(`[406] [CallId: ${e.callId}] Failed to handle offer: ${o} message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"})}}handleAnswerSignal(e){var i;try{const t=this.activeCalls.find((i=>i.id===e.callId));if(t){let n;if(n=t.mediaFlow===d.MediaFlow.SFU&&t.serverParticipant&&t.serverParticipant.getFullId()===e.from?t.serverParticipant:t.participants.find((i=>i.getFullId()===e.from)),n){const a=null===(i=e.sessionData)||void 0===i?void 0:i.version;if(!a||a!==this.callParticipantsRTCMap[t.id][n.getFullId()].getVersion())return void f.warn(`[412] [CallId: ${t.id}] Version is not set or is the same as the current version: ${a}`,{color:"red"});this.callParticipantsRTCMap[t.id][n.getFullId()].setVersion(a),this.setRemoteDescription(t.id,n.getFullId(),(0,v.toSessionDescription)(e.sessionData,"answer")).then((()=>{if(!n)return void f.info(`[462] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});const i=this.callParticipantsRTCMap[t.id][n.getFullId()].getRemoteSdpUfrag();if(i&&this.callParticipantsRTCMap[t.id][n.getFullId()].iceQueueMap[n.getFullId()]){const e=this.callParticipantsRTCMap[t.id][n.getFullId()].iceQueueMap[n.getFullId()][i];if(e&&e.length>0)for(const i of e)this.callParticipantsRTCMap[t.id][n.getFullId()].addIceCandidate(i,n.getFullId())}}))}}}catch(i){f.error(`[435] [CallId: ${e.callId}] Failed to handle answer: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"})}}sendOfferPeerToPeer(e,i,t){return n(this,void 0,void 0,(function*(){this.callParticipantsRTCMap.hasOwnProperty(e.id)&&this.callParticipantsRTCMap[e.id].hasOwnProperty(i.getFullId())||this.addParticipantToRTCMap(e,i),yield this.addTracksToPeerConnection(e,i.getFullId(),!0);const n=this.callParticipantsRTCMap[e.id][i.getFullId()];let a=n.getVersion();n.setVersion(a?String(Number(a)+1):"1"),a=n.getVersion();let l=n.getSessionId();l||(l=(0,h.v4)(),n.setSessionId(l)),n.createOffer(l,a,e.mediaFlow).then((n=>{n?this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.OFFER,sessionData:n,to:i.getFullId(),sessionId:e.sessionId},t):f.error(`[456] [CallId: ${e.id}] Failed to create offer for participant: ${i.getFullId()}`,{color:"red"})}))}))}handleJoinSignal(e){var i,t,n,a,l,o,r,c;try{let u=this.activeCalls.find((i=>i.id===e.callId));if(!u){let t=null;if(t=(null===(i=null==e?void 0:e.calls)||void 0===i?void 0:i.length)?e.calls[0]:this.signalMessageToICall(e),!t||!this.promoteFromPrepared(t.id,t)){const{call:e}=this.findOrCreateCall({id:t.id,sessionId:t.sessionId,mediaFlow:t.mediaFlow,participants:[],metadata:t.metadata},t.participants);u=e}return}if(u&&!u.sessionId&&(u.setSessionId(e.sessionId),u.setIsCreatedRemotely(!0)),u){let i;(null===(t=e.participants)||void 0===t?void 0:t.length)&&(i=e.participants[0]);let p=!1,h=u.participants.find((i=>i.getFullId()===e.from));if(h?h&&(h.setMediaVideoState((null===(l=null==i?void 0:i.mediaState)||void 0===l?void 0:l.video)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u),h.setMediaAudioState((null===(o=null==i?void 0:i.mediaState)||void 0===o?void 0:o.audio)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u)):(h=u.participants.find((i=>{var t;return i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&(i.clientId===e.from.split("/")[1]||!i.clientId)})),h?(h.clientId=e.from.split("/")[1],h.setMediaVideoState((null===(n=null==i?void 0:i.mediaState)||void 0===n?void 0:n.video)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u),h.setMediaAudioState((null===(a=null==i?void 0:i.mediaState)||void 0===a?void 0:a.audio)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u)):h=void 0),h||(h=new s.Participant(e.from),h.setMediaVideoState((null===(r=null==i?void 0:i.mediaState)||void 0===r?void 0:r.video)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u),h.setMediaAudioState((null===(c=null==i?void 0:i.mediaState)||void 0===c?void 0:c.audio)||{enabled:!1,changedBy:""},(null==i?void 0:i.permissions)||{},u),u.addParticipantToList(h),p=!0),u.mediaFlow===d.MediaFlow.P2P&&u.localParticipant.state===d.ParticipantState.Joined&&this.isPolitePeer(e.from,u.localParticipant.getFullId())){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[495] [CallId: ${null==u?void 0:u.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[499] [CallId: ${null==u?void 0:u.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};f.info(`[503] [CallId: ${u.id}] Sending offer to participant: ${h.getFullId()}`),this.sendOfferPeerToPeer(u,h,e)}h.state=d.ParticipantState.Joined,f.info(`[503] [CallId: ${u.id}] Participant joined call shouldSendEventInvited: ${p}`),p?u.emitParticipantsAdded([h]):u.emitParticipantStateChanged(h,d.ParticipantState.Joined)}}catch(i){f.error(`[514] [CallId: ${e.callId}] Failed to handle USER_JOINED: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"})}}handleLeaveSignal(e){var i,t;const n=this.activeCalls.find((i=>i.id===e.callId));if(n){const a=null==n?void 0:n.participants.find((i=>{var t;return i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&(i.clientId===e.from.split("/")[1]||!i.clientId)}));a&&a.updateState(d.ParticipantState.Left,n)&&(this.closePeerConnections(n.id,a.getFullId()),n.activeSpeakerManager.removeParticipant(a),a.setMediaScreenShareState({enabled:!1,changedBy:null===(t=null===(i=null==a?void 0:a.mediaState)||void 0===i?void 0:i.screenShare)||void 0===t?void 0:t.changedBy},n),a.setHold(!1,n),a.updateConnectionState(d.ParticipantConnectionState.Idle,n))}}handleInviteSignal(e){if(!e||!e.callId)return void f.warn(`[545] [CallId: ${e.callId}] Received invalid invite signal message`);let i=this.activeCalls.find((i=>i.id===e.callId));i||(i=this.promoteFromPrepared(e.callId,this.signalMessageToICall(e)));const t=(null==e?void 0:e.to)===this.user.id;if(t&&i)for(let e=0;e<i.participants.length;e++){const t=i.participants[e];t.id===this.user.id&&(t.updateConnectionState(d.ParticipantConnectionState.Idle,i),t.updateState(d.ParticipantState.Idle,i))}i?this.handleExistingCallInvite(i,e,t):this.handleNewCallInvite(e,t),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}handleExistingCallInvite(e,i,t){var n,a;if(t){e.localParticipant.updateConnectionState(d.ParticipantConnectionState.Connecting,e)&&(e.participants.find((e=>e.id===this.user.id&&e.clientId===this.clientId))||e.addParticipantToList(e.localParticipant),e.emitParticipantConnectionStateChanged(e.localParticipant,d.ParticipantConnectionState.Connecting));const t=(null===(a=null===(n=i.participants)||void 0===n?void 0:n.find((e=>e.id===this.user.id&&e.clientId===this.clientId)))||void 0===a?void 0:a.isCallSilenced)||!1;e.setIsCallSilenced(t),this.callEvents.onInvitedToCall&&this.callEvents.onInvitedToCall(e)}else{const t=this.addNewParticipantsToCall(e,i);t.length>0&&e.emitParticipantsAdded(t)}}handleNewCallInvite(e,i){var t,n,a,o,r,p,h;const g=new s.Participant(this.user.id,this.clientId);g.connectionState=d.ParticipantConnectionState.Connecting;let v=!1;const S=null===(t=e.participants)||void 0===t?void 0:t.map((e=>{var i,t,n,a,l,o,r,c;if(e.id===this.user.id&&!e.clientId)return v=e.isCallSilenced||!1,g;const u=new s.Participant(e.id,null==e?void 0:e.clientId);return u.state=e.state||d.ParticipantState.Idle,u.setMediaAudioState({enabled:!!(null===(t=null===(i=null==e?void 0:e.mediaState)||void 0===i?void 0:i.audio)||void 0===t?void 0:t.enabled),changedBy:null===(a=null===(n=e.mediaState)||void 0===n?void 0:n.video)||void 0===a?void 0:a.changedBy},e.permissions||{}),u.setMediaVideoState({enabled:(null===(o=null===(l=e.mediaState)||void 0===l?void 0:l.video)||void 0===o?void 0:o.enabled)||!1,changedBy:null===(c=null===(r=e.mediaState)||void 0===r?void 0:r.video)||void 0===c?void 0:c.changedBy},e.permissions||{}),u}));if(!i&&!(null==S?void 0:S.find((i=>i.getFullId()===e.from)))&&(null===(n=null==e?void 0:e.from)||void 0===n?void 0:n.split("/")[0])===this.user.id&&e.from.split("/")[1]!==this.clientId){const i=new s.Participant(e.from,e.from.split("/")[1]);i.state=d.ParticipantState.Joined,null==S||S.push(i)}const f=(0,u.makeFirstById)(S||[],this.user.id,this.clientId),C=new c.Call({id:e.callId,sessionId:e.sessionId,mediaFlow:e.mediaFlow,createdBy:e.from,localParticipant:g,metadata:e.metadata,participants:f,chatClient:this.chatClient,isCallSilenced:v});if(C.setVideoCall("true"===(null===(a=e.metadata)||void 0===a?void 0:a.videoCall)),e.callOptions){const i=e.callOptions,t=i.settings;C.setSettings(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==i.callType&&{callType:i.callType}),void 0!==(null==t?void 0:t.startsAt)&&{startsAt:l.default.isLong(t.startsAt)?t.startsAt.toNumber():t.startsAt}),void 0!==(null==t?void 0:t.expiresAt)&&{expiresAt:l.default.isLong(t.expiresAt)?t.expiresAt.toNumber():t.expiresAt}),void 0!==(null==t?void 0:t.persistent)&&{persistent:t.persistent}),void 0!==(null==t?void 0:t.broadcastOptions)&&{broadcastSettings:t.broadcastOptions}),{permissions:{allowPublishAudio:null!==(r=null===(o=null==t?void 0:t.permissions)||void 0===o?void 0:o.allowPublishAudio)&&void 0!==r&&r,allowPublishVideo:null!==(h=null===(p=null==t?void 0:t.permissions)||void 0===p?void 0:p.allowPublishVideo)&&void 0!==h&&h}}))}this.activeCalls.push(C),this.callEvents.onInvitedToCall&&i&&this.callEvents.onInvitedToCall(C),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}addNewParticipantsToCall(e,i){var t;const n=[];return null===(t=i.participants)||void 0===t||t.forEach((i=>{var t,a,l,o;const r=i.id!==this.user.id?e.participants.find((e=>e.id===i.id)):void 0,c=r||new s.Participant(i.id,null==i?void 0:i.clientId);r?i.state!==d.ParticipantState.Joined&&(c.updateState(i.state||d.ParticipantState.Idle,e),c.updateConnectionState(d.ParticipantConnectionState.Idle,e),c.setMediaVideoState({enabled:(null===(a=null===(t=i.mediaState)||void 0===t?void 0:t.video)||void 0===a?void 0:a.enabled)||!1,changedBy:null===(o=null===(l=i.mediaState)||void 0===l?void 0:l.video)||void 0===o?void 0:o.changedBy},i.permissions||{},e)):(c.updateState(i.state||d.ParticipantState.Idle,e),n.push(c),e.addParticipantToList(c))})),n}handleCloseSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));i&&this.closeCall(i)}handleDeclineSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(t)if(this.getParticipantId({id:this.user.id,clientId:this.clientId})===e.from)this.leaveCall(t,!0,"Current user declined the call"),t.setState(d.CallState.Idle,"Current user declined the call");else{let n=null==t?void 0:t.participants.find((i=>i.getFullId()===e.from));n||(n=null==t?void 0:t.participants.find((i=>{var t;return i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&!i.clientId})),n?n.clientId=e.from.split("/")[1]:(n=new s.Participant(e.from),t.addParticipantToList(n),t.emitParticipantsAdded([n]))),n&&n.updateState(d.ParticipantState.Declined,t,(null===(i=null==e?void 0:e.metadata)||void 0===i?void 0:i.reason)||"")}}handleRingingSignal(e){var i,t,n;const a=this.activeCalls.find((i=>i.id===e.callId));if(a){let l=null==a?void 0:a.participants.find((i=>{var t;return i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&(i.clientId===e.from.split("/")[1]||!i.clientId)}));if(!l){let o;l=new s.Participant(e.from),(null===(i=e.participants)||void 0===i?void 0:i.length)&&(o=e.participants[0],l.setMediaAudioState((null===(t=null==o?void 0:o.mediaState)||void 0===t?void 0:t.audio)||{enabled:!1,changedBy:""},o.permissions||{},a),l.setMediaVideoState((null===(n=null==o?void 0:o.mediaState)||void 0===n?void 0:n.video)||{enabled:!1,changedBy:""},o.permissions||{},a)),a.addParticipantToList(l),a.emitParticipantsAdded([l])}l&&l.connectionState!==d.ParticipantConnectionState.Connected&&(l.clientId||(l.clientId=e.from.split("/")[1]),l.updateState(d.ParticipantState.Ringing,a))}}handleSwitchMediaFlowSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(i&&i.localParticipant.state===d.ParticipantState.Joined){i.changeMediaFlow(d.MediaFlow.SFU);const e=new s.Participant(i.id);i.setServerParticipant(e);const t=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[738] [CallId: ${i.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`):e.event!==d.SignalEvent.ERROR||f.error(`[742] [CallId: ${i.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};f.info(`[747] [CallId: ${i.id}] Sending offer to server participant: ${e.getFullId()}`),this.sendOfferPeerToPeer(i,e,t),i.participants.forEach((e=>{e.setShouldResetPeerConnection(!0)}))}else i&&i.changeMediaFlow(d.MediaFlow.SFU)}handleIceSignal(e){var i;if(!e.callId||!e.ice)return void f.warn(`[756] [CallId: ${e.callId}] Invalid ICE signal: missing callId or ice data`);const t=this.activeCalls.find((i=>i.id===e.callId));if(!t)return void f.warn(`[763] [CallId: ${e.callId}] ICE candidate received for unknown call: ${e.callId}`);const n=t.participants.find((i=>i.getFullId()===e.from));if(n)try{if(!this.callParticipantsRTCMap[t.id])return void f.error(`[774] [CallId: ${t.id}] No RTC map found for call ${t.id}`);null===(i=this.callParticipantsRTCMap[t.id][n.getFullId()])||void 0===i||i.addIceCandidate(e.ice,n.getFullId())}catch(e){f.error(`[787] [CallId: ${t.id}] Failed to add ICE candidate for participant ${n.getFullId()} in call ${t.id}: ${e instanceof Error?e.message:JSON.stringify(e)}`)}else f.warn(`[768] [CallId: ${e.callId}] ICE candidate received from unknown participant: ${e.from} in call ${e.callId}`)}handleVideoOnSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(!t)return;const n=t.participants.find((i=>{var t;return i.getFullId()===e.from||i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&!i.clientId}));n&&n.setMediaVideoState({enabled:!0,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},n.permissions||{},t)}handleVideoOffSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(!t)return;const n=t.participants.find((i=>{var t;return i.getFullId()===e.from||i.id===(null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0])&&!i.clientId}));n&&n.setMediaVideoState({enabled:!1,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},n.permissions||{},t)}handleScreenShareOnSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(t){const n=null==t?void 0:t.participants.find((i=>i.getFullId()===e.from));n&&n.setMediaScreenShareState({enabled:!0,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},t)}}handleScreenShareOffSignal(e){var i,t,n;const a=this.activeCalls.find((i=>i.id===e.callId));if(a){const l=null==a?void 0:a.participants.find((i=>i.getFullId()===e.from));l&&(l.setMediaScreenShareState({enabled:!1,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},a),(null===(n=null===(t=l.mediaState)||void 0===t?void 0:t.video)||void 0===n?void 0:n.enabled)&&l.setMediaVideoState({enabled:!0,changedBy:l.mediaState.video.changedBy},l.permissions||{},a))}}handleMuteSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(!t)return;const n=t.participants.find((i=>i.getFullId()===e.from));n&&n.setMediaAudioState({enabled:!1,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},n.permissions||{},t)}handleUnmuteSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));if(!t)return;const n=t.participants.find((i=>i.getFullId()===e.from));n&&n.setMediaAudioState({enabled:!0,changedBy:null===(i=null==e?void 0:e.from)||void 0===i?void 0:i.split("/")[0]},n.permissions||{},t)}handleUpdateCallSettingsSignal(e,i){var t,n,a,l,s,o,r,c,u,p,h,g,v,S,f,C;const I=i||this.activeCalls.find((i=>i.id===e.callId));if(!I)return;const m=null===(n=null===(t=e.callOptions)||void 0===t?void 0:t.settings)||void 0===n?void 0:n.permissions;if(!m)return void I.emitCallPermissionsUpdated({allowPublishAudio:!1,allowPublishVideo:!1});const E=null===(a=I.createdBy)||void 0===a?void 0:a.split("/")[0],P=I.localParticipant.id===E;I.permissions=m,m.allowPublishAudio?(I.participants.forEach((i=>{var t,n;i.permissions&&!i.permissions.canPublishAudio&&i.setMediaAudioState((null===(t=i.mediaState)||void 0===t?void 0:t.audio)||{enabled:!1,changedBy:null===(n=null==e?void 0:e.from)||void 0===n?void 0:n.split("/")[0]},i.permissions,I)})),!1!==(null===(o=I.localParticipant.permissions)||void 0===o?void 0:o.canPublishAudio)||P||I.localParticipant.setMediaAudioState((null===(r=I.localParticipant.mediaState)||void 0===r?void 0:r.audio)||{enabled:!1,changedBy:null===(c=null==e?void 0:e.from)||void 0===c?void 0:c.split("/")[0]},I.localParticipant.permissions,I)):(I.participants.forEach((i=>{var t;i.state===d.ParticipantState.Joined&&i.id!==E&&i.setMediaAudioState({enabled:!1,changedBy:null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0]},(null==i?void 0:i.permissions)||{},I)})),P||I.localParticipant.setMediaAudioState({enabled:!1,changedBy:null===(l=null==e?void 0:e.from)||void 0===l?void 0:l.split("/")[0]},(null===(s=I.localParticipant)||void 0===s?void 0:s.permissions)||{},I)),m.allowPublishVideo?(I.participants.forEach((i=>{var t,n;i.permissions&&!i.permissions.canPublishVideo&&i.setMediaVideoState((null===(t=i.mediaState)||void 0===t?void 0:t.video)||{enabled:!1,changedBy:null===(n=null==e?void 0:e.from)||void 0===n?void 0:n.split("/")[0]},i.permissions||{},I)})),!1!==(null===(S=I.localParticipant.permissions)||void 0===S?void 0:S.canPublishVideo)||P||I.localParticipant.setMediaVideoState((null===(f=I.localParticipant.mediaState)||void 0===f?void 0:f.video)||{enabled:!1,changedBy:null===(C=null==e?void 0:e.from)||void 0===C?void 0:C.split("/")[0]},I.localParticipant.permissions||{},I)):(I.participants.forEach((i=>{var t,n,a,l;i.state===d.ParticipantState.Joined&&i.id!==E&&(i.setMediaVideoState({enabled:!1,changedBy:null===(t=null==e?void 0:e.from)||void 0===t?void 0:t.split("/")[0]},(null==i?void 0:i.permissions)||{},I),(null===(a=null===(n=i.mediaState)||void 0===n?void 0:n.screenShare)||void 0===a?void 0:a.enabled)&&i.setMediaScreenShareState({enabled:!1,changedBy:null===(l=null==e?void 0:e.from)||void 0===l?void 0:l.split("/")[0]},I))})),P||(I.localParticipant.setMediaVideoState({enabled:!1,changedBy:null===(u=null==e?void 0:e.from)||void 0===u?void 0:u.split("/")[0]},(null===(p=I.localParticipant)||void 0===p?void 0:p.permissions)||{},I),I.videoEnabled=!1,(null===(g=null===(h=I.localParticipant.mediaState)||void 0===h?void 0:h.screenShare)||void 0===g?void 0:g.enabled)&&(I.localParticipant.setMediaScreenShareState({enabled:!1,changedBy:null===(v=null==e?void 0:e.from)||void 0===v?void 0:v.split("/")[0]}),this.forceStopLocalScreenShare(I)))),I.emitCallPermissionsUpdated(m)}handleCallPermissionsUpdateSignal(e){this.handleUpdateCallSettingsSignal(e)}handleDisableRemoteAudioSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(!i)return;const t=e.to===C?i.participants.filter((e=>{var t;return e.state===d.ParticipantState.Joined&&e.id!==(null===(t=i.createdBy)||void 0===t?void 0:t.split("/")[0])})):i.participants.filter((i=>{var t;return i.id===(null===(t=e.to)||void 0===t?void 0:t.split("/")[0])&&i.state===d.ParticipantState.Joined}));t.forEach((t=>{var n,a,l;t.setMediaAudioState({enabled:!1,changedBy:null===(n=null==e?void 0:e.from)||void 0===n?void 0:n.split("/")[0]},{canPublishAudio:null!==(l=null===(a=t.permissions)||void 0===a?void 0:a.canPublishAudio)&&void 0!==l&&l},i)})),t.some((e=>{var t;return e.id===(null===(t=i.localParticipant)||void 0===t?void 0:t.id)}))&&(i.muted=!0)}handleDisableRemoteVideoSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(!i)return;const t=e.to===C?i.participants.filter((e=>{var t;return e.state===d.ParticipantState.Joined&&e.id!==(null===(t=i.createdBy)||void 0===t?void 0:t.split("/")[0])})):i.participants.filter((i=>{var t;return i.id===(null===(t=e.to)||void 0===t?void 0:t.split("/")[0])&&i.state===d.ParticipantState.Joined}));t.forEach((t=>{var n,a,l,s,o,r;const d=t.id===(null===(n=i.localParticipant)||void 0===n?void 0:n.id)&&(null===(l=null===(a=t.mediaState)||void 0===a?void 0:a.screenShare)||void 0===l?void 0:l.enabled);t.setMediaVideoState({enabled:!1,changedBy:null===(s=null==e?void 0:e.from)||void 0===s?void 0:s.split("/")[0]},{canPublishVideo:null!==(r=null===(o=t.permissions)||void 0===o?void 0:o.canPublishVideo)&&void 0!==r&&r},i),d&&this.forceStopLocalScreenShare(i)})),t.some((e=>{var t;return e.id===(null===(t=i.localParticipant)||void 0===t?void 0:t.id)}))&&(i.videoEnabled=!1)}handleParticipantPermissionsUpdateSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(!i)return;const t=i.participants.filter((i=>{var t;return(null===(t=e.participants)||void 0===t?void 0:t.some((e=>e.id===i.id)))&&i.state===d.ParticipantState.Joined})),n=t.some((e=>{var t,n,a;return e.id===(null===(t=i.localParticipant)||void 0===t?void 0:t.id)&&(null===(a=null===(n=e.mediaState)||void 0===n?void 0:n.screenShare)||void 0===a?void 0:a.enabled)}));t.forEach((t=>{var n,a,l,s,o,r,d,c,u,p,h,g,v,S,f,C;const I=null!==(a=null===(n=e.participants)||void 0===n?void 0:n.find((e=>e.id===t.id)))&&void 0!==a?a:null===(l=e.participants)||void 0===l?void 0:l[0];if(!(null==I?void 0:I.permissions))return;const m=I.permissions.canPublishAudio,E=I.permissions.canPublishVideo;!1===m?t.setMediaAudioState({enabled:!1,changedBy:null===(s=null==e?void 0:e.from)||void 0===s?void 0:s.split("/")[0]},{canPublishAudio:!1},i):!0===m&&(t.permissions?t.setMediaAudioState((null===(d=t.mediaState)||void 0===d?void 0:d.audio)||{enabled:!1,changedBy:null===(c=null==e?void 0:e.from)||void 0===c?void 0:c.split("/")[0]},Object.assign(Object.assign({},t.permissions),{canPublishAudio:!0}),i):t.setMediaAudioState((null===(o=t.mediaState)||void 0===o?void 0:o.audio)||{enabled:!1,changedBy:null===(r=null==e?void 0:e.from)||void 0===r?void 0:r.split("/")[0]},{canPublishAudio:!0,canPublishVideo:!0},i)),!1===E?(t.setMediaVideoState({enabled:!1,changedBy:null===(u=null==e?void 0:e.from)||void 0===u?void 0:u.split("/")[0]},{canPublishVideo:!1},i),(null===(h=null===(p=t.mediaState)||void 0===p?void 0:p.screenShare)||void 0===h?void 0:h.enabled)&&t.setMediaScreenShareState({enabled:!1,changedBy:null===(g=null==e?void 0:e.from)||void 0===g?void 0:g.split("/")[0]},i)):!0===E&&(t.permissions?t.setMediaVideoState((null===(f=t.mediaState)||void 0===f?void 0:f.video)||{enabled:!1,changedBy:null===(C=null==e?void 0:e.from)||void 0===C?void 0:C.split("/")[0]},Object.assign(Object.assign({},t.permissions),{canPublishVideo:!0}),i):t.setMediaVideoState((null===(v=t.mediaState)||void 0===v?void 0:v.video)||{enabled:!1,changedBy:null===(S=null==e?void 0:e.from)||void 0===S?void 0:S.split("/")[0]},{canPublishAudio:!0,canPublishVideo:!0},i)),i.emitParticipantPermissionsUpdated(t,t.permissions||{canPublishAudio:!1,canPublishVideo:!1})})),n&&this.forceStopLocalScreenShare(i)}handleHoldSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(i){const t=null==i?void 0:i.participants.find((i=>i.getFullId()===e.from));t&&t.setHold(!0,i)}}handleUnholdSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(i){const t=null==i?void 0:i.participants.find((i=>i.getFullId()===e.from));t&&t.setHold(!1,i)}}handleKickSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(i){const t=e.participants;if(t&&t.length)for(let e=0;e<t.length;e++){const n=t[e],a=null==i?void 0:i.participants.find((e=>e.getFullId()===this.getParticipantId(n)));a&&(a.updateState(d.ParticipantState.Kicked,i),a.getFullId()===i.localParticipant.getFullId()&&this.leaveCall(i,!1,"kickedParticipant",d.ParticipantState.Kicked))}}}handleUpdateSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));t&&e.metadata&&(t.metadata=e.metadata,t.setVideoCall("true"===(null===(i=e.metadata)||void 0===i?void 0:i.videoCall)))}handleNoAnswerSignal(e){var i;const t=this.activeCalls.find((i=>i.id===e.callId));t&&(null===(i=e.participants)||void 0===i||i.forEach((e=>{(null==t?void 0:t.participants.filter((i=>i.id===e.id&&(i.clientId===e.clientId||!e.clientId)))).forEach((e=>{e.updateState(d.ParticipantState.NoAnswer,t)}))})))}static getInstance(){if(!I.instance)throw new Error("InternalCallHandler has not been initialized. Call new InternalCallHandler(chatClient) first.");return I.instance}setRTCConfig(e){this.rtcConfig=e}onIceCandidateListener(e,i){return t=>{this.onIceCandidate(e,t,i)}}onSignalingStateChangeListener(e,i){return t=>{var n;const a=(null===(n=null==t?void 0:t.currentTarget)||void 0===n?void 0:n.signalingState)||"unknown";f.info(`[1067] [CallId: ${i.id}] Signaling state change: ${a}, participantID: ${e.getFullId()}`,{color:"blue"})}}isPolitePeer(e,i){return i>e}onIceConnectionStateChangeListener(e,i){return t=>{var n;const a=(null===(n=null==t?void 0:t.currentTarget)||void 0===n?void 0:n.iceConnectionState)||"unknown";f.info(`[1078] [CallId: ${i.id}] ICE connection state change: ${a}, participantID: ${e.getFullId()}`,{color:"blue"})}}onConnectionStateChangeListener(e,i){return t=>{var n,a,l,s,o;const r=t.currentTarget.connectionState;f.info(`[1078] [CallId: ${i.id}] PC connection state changed: ${r}, participantID: ${e.getFullId()}`,{color:"disconnected"===r?"orange":"failed"===r?"red":"blue"});const c=this.activeCalls.find((e=>e.id===i.id))||i,u=(null==c?void 0:c.participants.find((i=>i.getFullId()===e.getFullId())))||e.id===(null===(n=null==c?void 0:c.serverParticipant)||void 0===n?void 0:n.id)&&e;if(!u)return;let p=0,h=null;const v=(t,n)=>{f.info(`[1089] [CallId: ${i.id}] stopRetrying: ${n}, participant: ${e.getFullId()}`,{color:"orange"}),p=0,h&&(clearInterval(h),h=null),t&&clearTimeout(t)},S=(t,n=!1)=>{f.info(`[1089] [CallId: ${i.id}] start renegotiation send ${t} to participant ${u.getFullId()}`,{color:"blue"});const a=a=>{var l;const s=this.activeCalls.find((e=>e.id===i.id))||i,o=s.participants.find((i=>i.getFullId()===e.getFullId()))||e.id===(null===(l=s.serverParticipant)||void 0===l?void 0:l.id)&&e||e,r="Connected"===this.chatClient.connectionState,c=o.connectionState!==d.ParticipantConnectionState.Connected,u=s.state===d.CallState.Connected;if(f.info(`[1190] [CallId: ${i.id}] send() guard check — chatConnected: ${r}, participantConnState: ${o.connectionState} (notConnected: ${c}), callState: ${s.state} (connected: ${u}), participant: ${o.getFullId()}`,{color:"cyan"}),r&&c&&u){const e=this.isPolitePeer(o.getFullId(),s.localParticipant.getFullId()||"");if(f.info(`[1190] [CallId: ${i.id}] send() proceeding — type: ${t}, checkPolitePeer: ${n}, isPolitePeer: ${e}, participant: ${o.getFullId()}`,{color:"blue"}),"offer"!==t||n&&!e)if("connect"!==t||n&&!e)f.warn(`[1190] [CallId: ${i.id}] send() skipped — type: ${t}, checkPolitePeer: ${n}, isPolitePeer: ${e}`,{color:"yellow"});else{f.info(`[1214] [CallId: ${i.id}] ${d.MediaFlow.SFU} sendConnect to participant 1 ${JSON.stringify(o)}`,{color:"blue"});try{this.signalingClient.clearParticipantSignals(s.id,o.getFullId()),this.signalingClient.sendSignalMessage({mediaFlow:s.mediaFlow,callId:s.id,sessionId:s.sessionId,event:d.SignalEvent.CONNECT,to:o.getFullId()},a)}catch(e){f.error(`[1236] [CallId: ${i.id}] Failed to send connect to participant ${o.getFullId()}: message: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}else try{f.info(`[1211] [CallId: ${i.id}] Sending offer to participant: ${o.getFullId()}`),this.sendOfferPeerToPeer(s,o,a)}catch(e){f.error(`[1211] [CallId: ${i.id}] Failed to send offer to participant ${o.getFullId()}: ${e instanceof Error?e.message:JSON.stringify(e)}`)}}else f.warn(`[1190] [CallId: ${i.id}] send() blocked — chatConnected: ${r}, participantNotConnected: ${c}, callConnected: ${u}`,{color:"yellow"})};h&&(clearInterval(h),h=null);let l=null;h=setInterval((()=>{var n,s,o;const r=this.activeCalls.find((e=>e.id===i.id))||i,c=r.participants.find((i=>i.getFullId()===e.getFullId()))||e.id===(null===(n=r.serverParticipant)||void 0===n?void 0:n.id)&&e||e,u=null===(o=null===(s=this.callParticipantsRTCMap[i.id])||void 0===s?void 0:s[c.getFullId()])||void 0===o?void 0:o.peerConnection;return f.info(`[1182] [CallId: ${i.id}] interval tick — retry: ${p+1}, type: ${t}, participant: ${c.getFullId()}, participantConnState: ${c.connectionState}, participantState: ${c.state}, callState: ${null==r?void 0:r.state}, signalingState: ${null==u?void 0:u.signalingState}`,{color:"green"}),r&&r.state===d.CallState.Connected?c.connectionState===d.ParticipantConnectionState.Connected&&"stable"===(null==u?void 0:u.signalingState)?(v(l,`participant already connected and signaling stable (connState: ${c.connectionState}, signalingState: ${null==u?void 0:u.signalingState})`),void(l=null)):c.state!==d.ParticipantState.Joined&&c.id!==r.id?(v(l,`participant not joined (state: ${c.state})`),void(l=null)):(p+=1,p>=10?(f.warn(`[1182] [CallId: ${i.id}] Max retries reached for ${t} to ${c.getFullId()}, giving up`,{color:"red"}),c.updateConnectionState(d.ParticipantConnectionState.Disconnected,i),v(l,"max retries reached"),void(l=null)):void a((e=>{var n;return e instanceof g.SceytCallException||e instanceof Error?(f.error(`[1202] [CallId: ${i.id}] SYNC ${t} failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}),void("NotAllowed"===e.name&&(c.updateConnectionState(d.ParticipantConnectionState.Disconnected,i),v(l,"signal NotAllowed error"),l=null))):e.event===d.SignalEvent.ERROR?(f.error(`[1205] [CallId: ${i.id}] SYNC ${t} failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"}),void(4002===(null===(n=e.error)||void 0===n?void 0:n.code)&&(c.updateConnectionState(d.ParticipantConnectionState.Disconnected,i),v(l,"signal error code 4002"),l=null))):void 0}))):(v(l,`call not connected (state: ${null==r?void 0:r.state})`),void(l=null))}),4e3),l=setTimeout((()=>{l=null,f.info(`[1089] [CallId: ${i.id}] initial 2s attempt firing, type: ${t}, participant: ${u.getFullId()}`,{color:"blue"}),a((e=>{var t;return e instanceof g.SceytCallException||e instanceof Error?(f.error(`[1202] [CallId: ${i.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}),void(("NotAllowed"===e.name||e instanceof g.SceytCallException&&4002===e.code)&&u.updateConnectionState(d.ParticipantConnectionState.Disconnected,i))):e.event===d.SignalEvent.ERROR?(f.error(`[1205] [CallId: ${i.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"}),void(4002===(null===(t=e.error)||void 0===t?void 0:t.code)&&u.updateConnectionState(d.ParticipantConnectionState.Disconnected,i))):void 0}))}),2e3)},C=()=>{var t;h||u&&c&&(c.mediaFlow===d.MediaFlow.SFU&&e.id===(null===(t=null==c?void 0:c.serverParticipant)||void 0===t?void 0:t.id)&&this.callParticipantsRTCMap[c.id]&&this.callParticipantsRTCMap[c.id][e.getFullId()]&&c.localParticipant.state===d.ParticipantState.Joined?(f.info(`[1258] [CallId: ${i.id}] start renegotiation ${d.MediaFlow.SFU} sendOffer to participant ${u.getFullId()}`,{color:"blue"}),S("offer",!1)):c.mediaFlow===d.MediaFlow.SFU&&this.callParticipantsRTCMap[c.id]&&this.callParticipantsRTCMap[c.id][e.getFullId()]&&c.localParticipant.state===d.ParticipantState.Joined&&S("connect",!1),c.mediaFlow===d.MediaFlow.S2W&&u.state===d.ParticipantState.Joined&&this.callParticipantsRTCMap[c.id]&&this.callParticipantsRTCMap[c.id][u.getFullId()]&&c.localParticipant.state===d.ParticipantState.Joined&&(f.info(`[1263] [CallId: ${i.id}] start renegotiation ${d.MediaFlow.SFU} sendConnect to participant ${u.getFullId()}`,{color:"blue"}),S("offer",!1)))};switch(r){case"new":break;case"connecting":i.mediaFlow===d.MediaFlow.SFU&&u.id===(null===(a=null==c?void 0:c.serverParticipant)||void 0===a?void 0:a.id)&&c.localParticipant.updateConnectionState(d.ParticipantConnectionState.Connecting,i),u.updateConnectionState(d.ParticipantConnectionState.Connecting,i);break;case"connected":if(i.mediaFlow===d.MediaFlow.SFU&&u.id===(null===(l=null==c?void 0:c.serverParticipant)||void 0===l?void 0:l.id)&&c.localParticipant.updateConnectionState(d.ParticipantConnectionState.Connected,i),u.updateConnectionState(d.ParticipantConnectionState.Connected,i),u&&c&&"Connected"===this.chatClient.connectionState&&(c.mediaFlow!==d.MediaFlow.SFU||c.mediaFlow===d.MediaFlow.SFU&&u.id===(null==c?void 0:c.id))){const e=e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[1098] [CallId: ${c.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[1102] [CallId: ${c.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage(Object.assign({mediaFlow:c.mediaFlow,callId:c.id,sessionId:c.sessionId,event:d.SignalEvent.MEDIA_CONNECTED},c.mediaFlow!==d.MediaFlow.SFU?{to:c.id}:{}),e)}break;case"disconnected":i.mediaFlow===d.MediaFlow.SFU&&u.id===(null===(s=null==c?void 0:c.serverParticipant)||void 0===s?void 0:s.id)&&c.localParticipant.updateConnectionState(d.ParticipantConnectionState.Reconnecting,i),u.updateConnectionState(d.ParticipantConnectionState.Reconnecting,i),i.mediaFlow!==d.MediaFlow.S2W&&C();break;case"failed":u&&c&&(c.mediaFlow===d.MediaFlow.P2P&&u.state===d.ParticipantState.Joined&&this.callParticipantsRTCMap[c.id]&&this.callParticipantsRTCMap[c.id][u.getFullId()]&&c.localParticipant.state===d.ParticipantState.Joined?(f.info(`[1268] [CallId: ${i.id}] start renegotiation ${c.mediaFlow} sendOffer to participant ${u.getFullId()}`,{color:"blue"}),S("offer",!0)):C());break;case"closed":i.mediaFlow===d.MediaFlow.SFU&&u.id===(null===(o=null==c?void 0:c.serverParticipant)||void 0===o?void 0:o.id)&&c.localParticipant.updateConnectionState(d.ParticipantConnectionState.Idle,i),u.updateConnectionState(d.ParticipantConnectionState.Idle,i)}}}onIceCandidateErrorListener(e,i){return t=>{f.error(`[1284] [CallId: ${i.id}] ICE candidate error participantID: ${e.getFullId()}, error - code: ${t.errorCode}, message: ${t.errorText}, url: ${t.url}`,{color:"red"})}}onTrackListener(e,i){return t=>{this.onTrack(i,e,t)}}closePeerConnections(e,i){if(!this.callParticipantsRTCMap[e])return;const t=this.callParticipantsRTCMap[e][i];t?(t.listeners?(Object.keys(t.listeners).forEach((e=>{t.removeEventListener(e,t.listeners[e])})),f.info(`[1313] [CallId: ${e}] Removed all listeners for WebRTCClient of participant ${i}`,{color:"cyan"})):f.info(`[1316] [CallId: ${e}] No listeners found for WebRTCClient of participant ${i}`,{color:"cyan"}),t.close(),t.peerConnection.onicecandidate=null,t.peerConnection.ontrack=null,t.peerConnection.onconnectionstatechange=null,t.peerConnection.oniceconnectionstatechange=null,t.peerConnection.onsignalingstatechange=null,this.callParticipantsRTCMap[e][i]=null,delete this.callParticipantsRTCMap[e][i]):f.info(`[1375] [CallId: ${e}] No WebRTCClient found for participant ${i}`,{color:"cyan"})}addParticipantToRTCMap(e,i){this.callParticipantsRTCMap.hasOwnProperty(e.id)||(this.callParticipantsRTCMap[e.id]={});const t=new o.WebRTCClient(e.id,this.rtcConfig);this.callParticipantsRTCMap[e.id][i.getFullId()]=t;const n=this.onIceCandidateListener(i,e),a=this.onSignalingStateChangeListener(i,e),l=this.onIceConnectionStateChangeListener(i,e),s=this.onConnectionStateChangeListener(i,e),r=this.onTrackListener(i,e),d=this.onIceCandidateErrorListener(i,e);return t.addEventListener("icecandidate",n),t.addEventListener("signalingstatechange",a),t.addEventListener("connectionstatechange",s),t.addEventListener("track",r),t.addEventListener("icecandidateerror",d),t.addEventListener("iceconnectionstatechange",l),t.setListeners({icecandidate:n,signalingstatechange:a,connectionstatechange:s,track:r,icecandidateerror:d,iceconnectionstatechange:l}),f.info(`[1371] [CallId: ${e.id}] Added Event Listeners to RTC Map: participantID: ${i.getFullId()}`,{color:"blue"}),e.activeSpeakerManager.addParticipant(i),i}joinToCall(e,i){return this.signalingClient.sendSignalMessage(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({mediaFlow:e.mediaFlow,callId:e.callId},e.sessionId&&{sessionId:e.sessionId}),{event:d.SignalEvent.JOIN,participants:e.participants}),(null==e?void 0:e.metadata)&&{metadata:e.metadata}),e.callOptions&&{callOptions:e.callOptions}),{joinOptions:e.joinOptions}),i)}sendRinging(e,i){return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:d.SignalEvent.RINGING},(t=>t instanceof g.SceytCallException||t instanceof Error?(f.error(`[1389] [CallId: ${e.id}] SYNC RINGING failed message: ${t.message} code: ${t instanceof g.SceytCallException?t.code:""}`,{color:"red"}),void(null==i||i({error:(0,S.toCallException)(t)}))):t.event===d.SignalEvent.ERROR?(f.error(`[1393] [CallId: ${e.id}] SYNC RINGING failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"}),void(null==i||i({error:(0,S.toCallException)(new Error("Failed to send ringing signal"))}))):void e.localParticipant.updateState(d.ParticipantState.Ringing,e))),{success:!0}}rejectCall(e,i,t){try{const n=this.activeCalls.find((i=>i.id===e.id));n&&(n.setState(d.CallState.Idle,"rejectCall"),n.localParticipant.updateState(d.ParticipantState.Declined,e),n.localParticipant.updateConnectionState(d.ParticipantConnectionState.Idle,e),this.closeTracksAndPeerConnections(n));const a=i=>i instanceof g.SceytCallException||i instanceof Error?(f.error(`[1420] [CallId: ${e.id}] SYNC DECLINE failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`,{color:"red"}),void(null==t||t({error:(0,S.toCallException)(i)}))):i.event===d.SignalEvent.ERROR?(f.error(`[1424] [CallId: ${e.id}] SYNC DECLINE failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"}),void(null==t||t({error:(0,S.toCallException)(i.error||new Error("Failed to send decline signal"))}))):void 0;return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:d.SignalEvent.DECLINE,metadata:Object.assign(Object.assign({},e.metadata),{reason:i||""})},a),{success:!0}}catch(i){return f.error(`[1432] [CallId: ${e.id}] Failed to reject call: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"}),{success:!1,error:(0,S.toCallException)(i)}}}closeTracksAndPeerConnections(e){e.localAudioTracks.forEach((e=>{e.stop()})),e.localVideoTracks.forEach((e=>{e.stop()})),e.participants.forEach((i=>{i.videoTracks.forEach((e=>{e.stop()})),i.audioTracks.forEach((e=>{e.stop()})),this.closePeerConnections(e.id,i.getFullId()),e.activeSpeakerManager.removeParticipant(i)})),e.localParticipant.videoTracks.forEach((e=>{e.stop()})),e.localParticipant.audioTracks.forEach((e=>{e.stop()})),e.mediaFlow===d.MediaFlow.SFU&&e.serverParticipant&&(e.serverParticipant.videoTracks.forEach((e=>{e.stop()})),e.serverParticipant.audioTracks.forEach((e=>{e.stop()})),this.closePeerConnections(e.id,e.serverParticipant.getFullId()))}closeCall(e){e.setState(d.CallState.Closed,"closeCall"),this.closeTracksAndPeerConnections(e);const i=this.activeCalls.findIndex((i=>i.id===e.id));this.activeCalls.splice(i,1),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls),delete this.callParticipantsRTCMap[e.id],f.info(`[1474] [CallId: ${e.id}] closed call and removed from active calls: callId: ${e.id}`,{color:"light-green"})}leaveCall(e,i=!0,t,n=d.ParticipantState.Left){var a,l,s;const o=this.activeCalls.find((i=>i.id===e.id));if(o){this.signalingClient.cancelJoinIfPossible(e.id),this.signalingClient.clearCallSignals(e.id);const r=o.setState(d.CallState.Idle,`leaveCall: ${t}`);if(i&&r){const i=i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[1487] [CallId: ${e.id}] SYNC LEAVE failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`,{color:"red"}):i.event!==d.SignalEvent.ERROR||f.error(`[1491] [CallId: ${e.id}] SYNC LEAVE failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:d.SignalEvent.LEAVE},i)}this.closeTracksAndPeerConnections(o),delete this.callParticipantsRTCMap[o.id],o.localParticipant.updateState(n,e),o.localParticipant.setMediaScreenShareState({enabled:!1,changedBy:null===(s=null===(l=null===(a=o.localParticipant)||void 0===a?void 0:a.mediaState)||void 0===l?void 0:l.screenShare)||void 0===s?void 0:s.changedBy},o),o.localParticipant.updateConnectionState(d.ParticipantConnectionState.Idle,e),o.participants.forEach((i=>{i.updateConnectionState(d.ParticipantConnectionState.Idle,e)})),e.sessionId||(this.activeCalls=this.activeCalls.filter((e=>e.id!=o.id))),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}}setRemoteDescription(e,i,t){var n;const a=null===(n=this.callParticipantsRTCMap[e])||void 0===n?void 0:n[i];return a?a.setRemoteDescription(t):(f.error(`[setRemoteDescription] [CallId: ${e}] No WebRTCClient found for participant ${i}`,{color:"red"}),Promise.reject(new Error(`No WebRTCClient found for participant ${i} in call ${e}`)))}changeVideoTracks(e,i,t,a){var l;return n(this,void 0,void 0,(function*(){if(f.info(`[1594] [CallId: ${e.id}], mediaFlow: ${e.mediaFlow}, changeVideoTracks ${t}, serverParticipant: ${(null===(l=e.serverParticipant)||void 0===l?void 0:l.id)||"null"}`,{color:"cyan"}),e.mediaFlow!==d.MediaFlow.SFU)for(let n=0;n<e.participants.length;n++){const l=e.participants[n];(l.id!==this.user.id||l.clientId!==this.clientId)&&l.clientId&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][l.getFullId()]&&(yield this.callParticipantsRTCMap[e.id][l.getFullId()].enableVideoOnPeerConnection(t,i,!!a))}else this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][e.id]&&(yield this.callParticipantsRTCMap[e.id][e.id].enableVideoOnPeerConnection(t,i,!!a))}))}changeAudioTracks(e,i,t){return n(this,void 0,void 0,(function*(){e.mediaFlow!==d.MediaFlow.SFU?e.participants.forEach((n=>{(n.id!==this.user.id||n.clientId!==this.clientId)&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][n.getFullId()]&&(f.info(`[1561] [CallId: ${e.id}] Enabling audio on peer connection: ${n.getFullId()}`,{color:"cyan"}),this.callParticipantsRTCMap[e.id][n.getFullId()].enableAudioOnPeerConnection(t,i))})):(f.info(`[1565] [CallId: ${e.id}] Enabling audio on peer connection: ${e.id}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][e.id].enableAudioOnPeerConnection(t,i))}))}sendVideoEnabled(e,i,t){var n,a;if(i&&(!1===(null===(n=e.localParticipant.permissions)||void 0===n?void 0:n.canPublishVideo)||!1===(null===(a=e.permissions)||void 0===a?void 0:a.allowPublishVideo)))return f.warn(`[CallId: ${e.id}] sendVideoEnabled: blocked — video host-disabled or call locked`),void(null==t||t({error:(0,S.toCallException)({message:"Cannot enable video: you have been disabled by the host",code:403})}));if(this.activeCalls.find((i=>i.id===e.id)))try{const n=i=>i instanceof g.SceytCallException||i instanceof Error?(f.error(`[1632] [CallId: ${e.id}] SYNC VIDEO_ON failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`),void(null==t||t({error:(0,S.toCallException)(i)}))):i.event===d.SignalEvent.ERROR?(f.error(`[1636] [CallId: ${e.id}] SYNC VIDEO_ON failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`),void(null==t||t({error:(0,S.toCallException)(i.error||i)}))):void 0;this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:i?d.SignalEvent.VIDEO_ON:d.SignalEvent.VIDEO_OFF,sessionId:e.sessionId},n)}catch(i){return f.error(`[1645] [CallId: ${e.id}] Failed to send video enabled signal: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"}),null==t||t({error:(0,S.toCallException)(i)}),!1}}sendScreenShare(e,i,t){var a,l;return n(this,void 0,void 0,(function*(){const n=this.activeCalls.find((i=>i.id===e.id));try{if(n){if(i){const e=n.localParticipant;if(!1===(null===(a=e.permissions)||void 0===a?void 0:a.canPublishVideo)||!1===(null===(l=n.permissions)||void 0===l?void 0:l.allowPublishVideo))return null==t||t({error:new g.SceytCallException("NOT_ALLOWED Screen share blocked: host-disabled")}),!1}return this.sendSignalScreenShare(e,i,t)}}catch(i){return f.error(`[1668] [CallId: ${e.id}] Failed to send screen share signal: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"}),null==t||t({error:(0,S.toCallException)(i)}),!1}}))}forceStopLocalScreenShare(e){e.screenSharing=!1,e.localVideoTracks.forEach((e=>e.stop())),e.localVideoTracks=[],e.localParticipant.setVideoTracks([],e),this.sendSignalScreenShare(e,!1)}sendAudioEnable(e,i,t){return n(this,void 0,void 0,(function*(){if(this.activeCalls.find((i=>i.id===e.id))){const a=a=>n(this,void 0,void 0,(function*(){try{if(a instanceof g.SceytCallException||a instanceof Error)return f.error(`[1704] [CallId: ${e.id}] SYNC HOLD failed message: ${a.message} code: ${a instanceof g.SceytCallException?a.code:""}`),void(null==t||t({error:(0,S.toCallException)(a)}));if(a.event===d.SignalEvent.ERROR)return f.error(`[1708] [CallId: ${e.id}] SYNC HOLD failed message: ${a.error?`${a.error.message} code: ${a.error.code}`:""}`),void(null==t||t({error:(0,S.toCallException)(a.error)}));if(e.mediaFlow!==d.MediaFlow.SFU)for(let t=0;t<e.participants.length;t++){const n=e.participants[t];(n.id!==this.user.id||n.clientId!==this.clientId)&&n.clientId&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][n.getFullId()]&&(f.info(`[1712] [CallId: ${e.id}] Enabling audio on peer connection: ${n.getFullId()}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][n.getFullId()].enableAudioOnPeerConnection(i))}else this.callParticipantsRTCMap&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][e.serverParticipant.getFullId()]&&(f.info(`[1712] [CallId: ${e.id}] Enabling audio on peer connection: ${e.serverParticipant.getFullId()}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][e.serverParticipant.getFullId()].enableAudioOnPeerConnection(i));e.localParticipant.audioTracks.forEach((e=>{e.enabled=!i}))}catch(i){f.error(`[1725] [CallId: ${e.id}] Failed to enable audio on peer connection: ${i instanceof Error?i.message:JSON.stringify(i)}`),null==t||t({error:(0,S.toCallException)(i)})}}));return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:i?d.SignalEvent.MUTE:d.SignalEvent.UNMUTE,sessionId:e.sessionId},a)}}))}makeErrorCallback(e,i,t){return a=>n(this,void 0,void 0,(function*(){var n;try{if(a instanceof g.SceytCallException||a instanceof Error)return f.error(`[CallId: ${e.id}] ${i} failed: ${a.message}`),void(null==t||t({error:(0,S.toCallException)(a)}));a.event===d.SignalEvent.ERROR&&(f.error(`[CallId: ${e.id}] ${i} error: ${null===(n=a.error)||void 0===n?void 0:n.message}`),null==t||t({error:(0,S.toCallException)(a.error)}))}catch(n){f.error(`[CallId: ${e.id}] ${i} exception: ${n instanceof Error?n.message:JSON.stringify(n)}`),null==t||t({error:(0,S.toCallException)(n)})}}))}muteAllRemoteParticipants(e,i){return e.participants.forEach((i=>{var t;i.state===d.ParticipantState.Joined&&i.id!==(null===(t=e.createdBy)||void 0===t?void 0:t.split("/")[0])&&i.setMediaAudioState({enabled:!1,changedBy:e.localParticipant.id},i.permissions||{},e)})),this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.DISABLE_REMOTE_AUDIO,sessionId:e.sessionId,to:C},this.makeErrorCallback(e,"muteAllRemoteParticipants",i))}muteAllParticipants(e,i){return this.muteAllRemoteParticipants(e,i)}videoOffAllRemoteParticipants(e,i){return e.participants.forEach((i=>{var t,n,a;i.state===d.ParticipantState.Joined&&i.id!==(null===(t=e.createdBy)||void 0===t?void 0:t.split("/")[0])&&i.setMediaVideoState({enabled:!1,changedBy:e.localParticipant.id},{canPublishVideo:null!==(a=null===(n=i.permissions)||void 0===n?void 0:n.canPublishVideo)&&void 0!==a&&a},e)})),this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.DISABLE_REMOTE_VIDEO,sessionId:e.sessionId,to:C},this.makeErrorCallback(e,"videoOffAllRemoteParticipants",i))}muteRemoteParticipant(e,i,t){for(const t of e.participants)t.id===i&&t.state===d.ParticipantState.Joined&&t.setMediaAudioState({enabled:!1,changedBy:e.localParticipant.id},t.permissions||{},e);return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.DISABLE_REMOTE_AUDIO,sessionId:e.sessionId,to:i},this.makeErrorCallback(e,"muteRemoteParticipant",t))}disableRemoteParticipantAudio(e,i,t){var n,a;const l=[];for(const t of e.participants)if(t.id===i&&t.state===d.ParticipantState.Joined){const i={canPublishAudio:!1,canPublishVideo:null!==(a=null===(n=t.permissions)||void 0===n?void 0:n.canPublishVideo)&&void 0!==a&&a};t.setMediaAudioState({enabled:!1,changedBy:e.localParticipant.id},i,e),l.push({id:t.id,clientId:t.clientId,permissions:i})}return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE,sessionId:e.sessionId,to:i,participants:l},this.makeErrorCallback(e,"disableRemoteParticipantAudio",t))}enableRemoteParticipantAudio(e,i,t){var n,a;const l=[];for(const t of e.participants)if(t.id===i&&t.state===d.ParticipantState.Joined){const e={canPublishAudio:!0,canPublishVideo:null===(a=null===(n=t.permissions)||void 0===n?void 0:n.canPublishVideo)||void 0===a||a};t.permissions?t.permissions=Object.assign(Object.assign({},t.permissions),e):t.permissions=e,l.push({id:t.id,clientId:t.clientId,permissions:e})}return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE,sessionId:e.sessionId,to:i,participants:l},this.makeErrorCallback(e,"enableRemoteParticipantAudio",t))}videoOffRemoteParticipant(e,i,t){var n,a;const l=e.participants.find((e=>e.id===i&&e.state===d.ParticipantState.Joined));return l&&l.setMediaVideoState({enabled:!1,changedBy:e.localParticipant.id},{canPublishVideo:null===(a=null===(n=l.permissions)||void 0===n?void 0:n.canPublishVideo)||void 0===a||a},e),this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.DISABLE_REMOTE_VIDEO,sessionId:e.sessionId,to:i},this.makeErrorCallback(e,"videoOffRemoteParticipant",t))}updateCallPermissions(e,i,t){var n,a,l,s,o;const r=this.activeCalls.find((i=>i.id===e.id));if(r){const e=null===(n=r.createdBy)||void 0===n?void 0:n.split("/")[0],t=r.localParticipant.id===e;r.permissions=i,i.allowPublishAudio?(r.participants.forEach((e=>{e.permissions&&!e.permissions.canPublishAudio&&(e.permissions=Object.assign(Object.assign({},e.permissions),{canPublishAudio:!0}))})),!1!==(null===(a=r.localParticipant.permissions)||void 0===a?void 0:a.canPublishAudio)||t||(r.localParticipant.permissions=Object.assign(Object.assign({},r.localParticipant.permissions),{canPublishAudio:!0}))):(r.participants.forEach((i=>{i.state===d.ParticipantState.Joined&&i.id!==e&&i.setMediaAudioState({enabled:!1,changedBy:e},{canPublishAudio:!1},r)})),t||(r.localParticipant.setMediaAudioState({enabled:!1,changedBy:e},{canPublishAudio:!1},r),r.muted=!0)),i.allowPublishVideo?(r.participants.forEach((e=>{e.permissions&&!e.permissions.canPublishVideo&&(e.permissions=Object.assign(Object.assign({},e.permissions),{canPublishVideo:!0}))})),!1!==(null===(o=r.localParticipant.permissions)||void 0===o?void 0:o.canPublishVideo)||t||(r.localParticipant.permissions=Object.assign(Object.assign({},r.localParticipant.permissions),{canPublishVideo:!0}))):(r.participants.forEach((i=>{var t,n;i.state===d.ParticipantState.Joined&&i.id!==e&&(i.setMediaVideoState({enabled:!1,changedBy:e},{canPublishVideo:!1},r),(null===(n=null===(t=i.mediaState)||void 0===t?void 0:t.screenShare)||void 0===n?void 0:n.enabled)&&i.setMediaScreenShareState({enabled:!1,changedBy:e},r))})),t||(r.localParticipant.setMediaVideoState({enabled:!1,changedBy:e},{canPublishVideo:!1},r),r.videoEnabled=!1,(null===(s=null===(l=r.localParticipant.mediaState)||void 0===l?void 0:l.screenShare)||void 0===s?void 0:s.enabled)&&(r.localParticipant.setMediaScreenShareState({enabled:!1,changedBy:e}),this.forceStopLocalScreenShare(r)))),r.emitCallPermissionsUpdated(i)}return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.CALL_PERMISSIONS_UPDATE,sessionId:e.sessionId,callOptions:{settings:{permissions:i}}},this.makeErrorCallback(e,"updateCallPermissions",t))}updateParticipantPermissions(e,i,t,n){var a,l;for(const n of e.participants)n.id===i&&(t.canPublishAudio?n.permissions&&(n.permissions=Object.assign(Object.assign({},n.permissions),{canPublishAudio:!0})):n.setMediaAudioState({enabled:!1,changedBy:e.localParticipant.id},Object.assign({},t),e),t.canPublishVideo?n.permissions&&(n.permissions=Object.assign(Object.assign({},n.permissions),{canPublishVideo:!0})):(n.setMediaVideoState({enabled:!1,changedBy:e.localParticipant.id},Object.assign({},t),e),(null===(l=null===(a=n.mediaState)||void 0===a?void 0:a.screenShare)||void 0===l?void 0:l.enabled)&&n.setMediaScreenShareState({enabled:!1,changedBy:e.localParticipant.id},e)));return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE,sessionId:e.sessionId,to:i,participants:[{id:i,clientId:"",permissions:t}]},this.makeErrorCallback(e,"updateParticipantPermissions",n))}sendHold(e,i,t){if(this.activeCalls.find((i=>i.id===e.id))){const t=i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[1741] [CallId: ${e.id}] SYNC HOLD failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`):i.event!==d.SignalEvent.ERROR||f.error(`[1745] [CallId: ${e.id}] SYNC HOLD failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`)};return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:i?d.SignalEvent.HOLD:d.SignalEvent.UNHOLD,sessionId:e.sessionId},t)}}addTracksToPeerConnection(e,i,t=!0){var a,l;return n(this,void 0,void 0,(function*(){let n=e.localVideoTracks;console.log(n,"localVideoTracks, localVideoTracks");const s=e.localAudioTracks,o=this.callParticipantsRTCMap[e.id][i];try{t?yield o.addTransceiverToPeerConnection(s[0],e.mediaFlow):yield o.setStreamsToTransceiver(s[0])}catch(i){f.warn(`[1766] [CallId: ${e.id}] Failed to add track to peer connection: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"})}n&&n.length>0||(f.info(`[1960] [CallId: ${e.id}] getting empty video track:`),n=(0,u.getEmptyVideoTrack)());try{t?yield o.addTransceiverToPeerConnection(n[0],e.mediaFlow):yield o.setStreamsToTransceiver(n[0])}catch(i){f.warn(`[1775] [CallId: ${e.id}] Failed to add track to peer connection: message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"})}e.videoEnabled&&(yield o.enableVideoOnPeerConnection(e.videoEnabled,null===(a=e.localVideoTracks)||void 0===a?void 0:a[0])),e.muted||(yield o.enableAudioOnPeerConnection(e.muted,null===(l=e.localAudioTracks)||void 0===l?void 0:l[0]))}))}switchCallToSfu(e,i){try{const t=t=>{if(t instanceof g.SceytCallException||t instanceof Error)return f.error(`[1785] [CallId: ${e.id}] SYNC SWITCH_MEDIA_FLOW signal sent failed message: ${t.message} code: ${t instanceof g.SceytCallException?t.code:""}`),void(null==i||i({error:(0,S.toCallException)(t)}));if(t.event===d.SignalEvent.ERROR)return f.error(`[1789] [CallId: ${e.id}] SYNC SWITCH_MEDIA_FLOW signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`),void(null==i||i({error:(0,S.toCallException)(t)}));const n=new s.Participant(e.id);return e.setServerParticipant(n),e.participants.forEach((i=>{i.id===this.user.id&&i.clientId===this.clientId||i.updateConnectionState(d.ParticipantConnectionState.Idle,e),i.setShouldResetPeerConnection(!0)})),e.changeMediaFlow(d.MediaFlow.SFU),f.info(`[1818] [CallId: ${e.id}] Sending offer to server participant: ${n.getFullId()}`),this.sendOfferPeerToPeer(e,n,(i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[1805] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`):i.event!==d.SignalEvent.ERROR||f.error(`[1809] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`)})),!0};return this.signalingClient.sendSignalMessage({mediaFlow:d.MediaFlow.SFU,callId:e.id,event:d.SignalEvent.SWITCH_MEDIA_FLOW,sessionId:e.sessionId},t),f.info(`[1823] [CallId: ${e.id}] Switched call ${e.id} to SFU`,{color:"light-green"}),{success:!0}}catch(i){return f.error(`[1827] [CallId: ${e.id}] Failed to switch ${d.MediaFlow.SFU} message: ${i instanceof Error?i.message:JSON.stringify(i)}`),{success:!1,error:(0,S.toCallException)(i)}}}getCallById(e,i){return this.signalingClient.sendSignalMessage({callId:e,sessionId:i,event:d.SignalEvent.GET_CALL},(i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[1833] [CallId: ${e}] SYNC GET_CALL signal sent failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`):i.event!==d.SignalEvent.ERROR||f.error(`[1837] [CallId: ${e}] SYNC GET_CALL signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`)}),e)}getCalls(){return this.signalingClient.sendSignalMessage({callId:"",event:d.SignalEvent.GET_CALL},(e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[1849] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`):e.event!==d.SignalEvent.ERROR?this.syncActiveCalls(e):f.error("[1853] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: "+(e.error?`${e.error.message} code: ${e.error.code}`:""))}),"get_call")}createParticipants(e){let i=null,t=!1;return{participants:null==e?void 0:e.map((e=>{var n,a,l,o,r,c,u,p,h,g,v,S;const f=new s.Participant(e.id,e.clientId);return f.setMediaAudioState({enabled:!!(null===(a=null===(n=null==e?void 0:e.mediaState)||void 0===n?void 0:n.audio)||void 0===a?void 0:a.enabled),changedBy:null===(o=null===(l=null==e?void 0:e.mediaState)||void 0===l?void 0:l.audio)||void 0===o?void 0:o.changedBy},(null==e?void 0:e.permissions)||{canPublishAudio:!1,canPublishVideo:!1}),f.setMediaVideoState({enabled:!!(null===(c=null===(r=null==e?void 0:e.mediaState)||void 0===r?void 0:r.video)||void 0===c?void 0:c.enabled),changedBy:null===(p=null===(u=null==e?void 0:e.mediaState)||void 0===u?void 0:u.video)||void 0===p?void 0:p.changedBy},(null==e?void 0:e.permissions)||{canPublishAudio:!1,canPublishVideo:!1}),f.setMediaScreenShareState({enabled:!!(null===(g=null===(h=null==e?void 0:e.mediaState)||void 0===h?void 0:h.screenShare)||void 0===g?void 0:g.enabled),changedBy:null===(S=null===(v=null==e?void 0:e.mediaState)||void 0===v?void 0:v.screenShare)||void 0===S?void 0:S.changedBy}),f.setHold(!!(null==e?void 0:e.onHold)),(null==e?void 0:e.connectionState)&&(null==e?void 0:e.connectionState)>d.ParticipantConnectionState.Connected&&(null==e?void 0:e.id)!==this.user.id&&(null==e?void 0:e.clientId)!==this.clientId&&(f.connectionState=(null==e?void 0:e.connectionState)||d.ParticipantConnectionState.Idle),f.state=(null==e?void 0:e.state)||0,t=(null==e?void 0:e.isCallSilenced)||!1,(null==f?void 0:f.id)===this.user.id&&(null==f?void 0:f.clientId)===this.clientId&&(i=f),f})),localParticipant:i,isCallSilenced:t}}findOrCreateCall(e,i){var t;let n=new s.Participant(this.user.id,this.clientId),a=[],l=!1;if(i){const e=this.createParticipants(i);a=e.participants,l=e.isCallSilenced,e.localParticipant&&(n=e.localParticipant)}else a=null!==(t=e.participants)&&void 0!==t?t:[];let o=this.activeCalls.find((i=>i.id===e.id));return o?this.applyOptionsToExistingCall(o,e,i,a):o=this.initializeNewCall(e,n,a,l),{call:o}}initializeNewCall(e,i,t,n){var a,l,s,o,r;const d=e.id||(0,h.v4)();f.info(`[1869] [CallId: ${d}] Creating new call`,{color:"cyan"});const p=(0,u.makeFirstById)([...t,i],this.user.id,this.clientId),g=new c.Call({id:d,sessionId:e.sessionId,mediaFlow:e.mediaFlow,localParticipant:i,participants:p,metadata:e.metadata,createdBy:e.createdBy,chatClient:this.chatClient,isCallSilenced:n});return e.metadata&&g.setVideoCall("true"===e.metadata.videoCall),e.callOptions&&g.setSettings(this.callOptionsToSettings(e.callOptions)),g.localAudioTracks=e.localAudioTracks||[],g.localVideoTracks=e.localVideoTracks||[],g.localParticipant.setAudioTracks(e.localAudioTracks||[],g),g.localParticipant.setVideoTracks(e.localVideoTracks||[],g),null!=(null===(a=e.audioSettings)||void 0===a?void 0:a.preferredAudioRoute)&&g.setAudioDeviceId(e.audioSettings.preferredAudioRoute),g.localParticipant.setMediaAudioState({enabled:!!(null===(l=e.audioSettings)||void 0===l?void 0:l.publishAudio)},g.localParticipant.permissions||{},g),g.setVideoEnabled(!!(null===(s=e.videoSettings)||void 0===s?void 0:s.publishVideo)),g.localParticipantVideoEnable(!!(null===(o=e.videoSettings)||void 0===o?void 0:o.publishVideo),void 0,!1,!1),g.localParticipant.setMediaVideoState({enabled:!!(null===(r=e.videoSettings)||void 0===r?void 0:r.publishVideo),changedBy:""},g.localParticipant.permissions||{},g),this.activeCalls.push(g),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls),g}applyOptionsToExistingCall(e,i,t,n){var a,l;if(f.info(`[1911] [CallId: ${e.id}] Using existing call`,{color:"cyan"}),void 0!==i.mediaFlow&&e.changeMediaFlow(i.mediaFlow),i.sessionId&&e.setSessionId(i.sessionId),i.createdBy&&e.setCreatedBy(i.createdBy),i.callOptions&&e.setSettings(this.callOptionsToSettings(i.callOptions)),i.metadata&&(e.metadata=i.metadata,e.setVideoCall("true"===i.metadata.videoCall)),i.participants&&!t){const t=new Set(e.participants.map((e=>e.id))),n=i.participants.filter((({id:e})=>!t.has(e)&&e!==this.user.id)).map((({id:e})=>new s.Participant(e)));n.length>0&&(e.participants=(0,u.makeFirstById)([...e.participants,...n],this.user.id,this.clientId),e.emitParticipantsAdded(n))}else e.participants=n;e.participants.some((e=>e.id===this.user.id&&e.clientId===this.clientId))||e.localParticipant.id!==this.user.id||e.localParticipant.clientId!==this.clientId||(e.participants=(0,u.makeFirstById)([...e.participants,e.localParticipant],this.user.id,this.clientId),e.emitParticipantsAdded([e.localParticipant])),(null===(a=i.localAudioTracks)||void 0===a?void 0:a.length)&&(e.localAudioTracks=i.localAudioTracks,e.localParticipant.setAudioTracks(i.localAudioTracks,e)),(null===(l=i.localVideoTracks)||void 0===l?void 0:l.length)&&(e.localVideoTracks=i.localVideoTracks,e.localParticipant.setVideoTracks(i.localVideoTracks,e)),i.audioSettings&&(null!=i.audioSettings.preferredAudioRoute&&e.setAudioDeviceId(i.audioSettings.preferredAudioRoute),e.setMuted(!i.audioSettings.publishAudio),e.localParticipant.setMediaAudioState({enabled:!!i.audioSettings.publishAudio,changedBy:""},e.localParticipant.permissions||{},e)),i.videoSettings&&(e.setVideoEnabled(!!i.videoSettings.publishVideo),e.localParticipantVideoEnable(!!i.videoSettings.publishVideo,void 0,!1,!1),e.localParticipant.setMediaVideoState({enabled:!!i.videoSettings.publishVideo,changedBy:""},e.localParticipant.permissions||{},e))}processJoinAcknowledgment(e,i,t){var n,a,l,s;if(i.event===d.SignalEvent.ERROR)throw f.error(`[1955] [CallId: ${e.id}] Join failed: message: ${null===(n=i.error)||void 0===n?void 0:n.message} code: ${null===(a=i.error)||void 0===a?void 0:a.code}`),this.leaveCall(e,!0,"processJoinAcknowledgment"),(0,S.checkCode)((null===(l=i.error)||void 0===l?void 0:l.code)||0,null===(s=i.error)||void 0===s?void 0:s.message);if(i.event===d.SignalEvent.SUCCESS)return e.eventsQueue.forEach((e=>{e()})),e.eventsQueue.clear(),this.configureRTCServers(e,i,t),e;throw f.warn(`[1969] [CallId: ${e.id}] Unexpected join event: ${i.event}`),(0,S.checkCode)(4e3,`Unexpected event type: ${i.event}`)}configureRTCServers(e,i,t){var n;(null===(n=i.turnServers)||void 0===n?void 0:n.length)&&this.setRTCConfig(Object.assign(Object.assign({},e.mediaFlow===d.MediaFlow.SFU?{}:{iceServers:i.turnServers.map((e=>({urls:[`${e.url}?transport=tcp`,`${e.url}?transport=udp`],credential:e.password,username:e.username})))}),{bundlePolicy:"max-bundle",rtcpMuxPolicy:"require"})),this.processRemoteParticipants(e,(null==i?void 0:i.participants)||[]),this.reconcileParticipants(e,i.participants||[]),this.handleUpdateCallSettingsSignal(i,e),e.mediaFlow===d.MediaFlow.SFU?this.setupSFUConnection(e,t,i):e.participants.forEach((i=>{e.mediaFlow===d.MediaFlow.P2P&&i.getFullId()!=e.localParticipant.getFullId()&&i.state===d.ParticipantState.Joined&&this.isPolitePeer(i.getFullId(),e.localParticipant.getFullId())&&(f.info(`[2008] [CallId: ${e.id}] Sending offer to participant: ${i.getFullId()}`),this.sendOfferPeerToPeer(e,i,(i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[2005] [CallId: ${e.id}] SYNC OFFER failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`):i.event!==d.SignalEvent.ERROR||f.error(`[2010] [CallId: ${e.id}] SYNC OFFER failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`)})))}))}setupSFUConnection(e,i,t){const n=new s.Participant(e.id);f.info(`[2005] [CallId: ${e.id}] [serverParticipant.id:${n.getFullId()}] Adding server participant to RTC map`,{color:"cyan"});try{e.setServerParticipant(n);const a=n=>{n instanceof g.SceytCallException||n instanceof Error?f.error(`[2011] [CallId: ${e.id}] SYNC OFFER failed message: ${n.message} code: ${n instanceof g.SceytCallException?n.code:""}`):(n.event===d.SignalEvent.ERROR&&f.error(`[2015] [CallId: ${e.id}] SYNC OFFER failed message: ${n.error?`${n.error.message} code: ${n.error.code}`:""}`),n.event!==d.SignalEvent.ERROR&&(f.info(`[2019] [CallId: ${e.id}] offerAck: ${JSON.stringify(n)}`,{color:"cyan"}),e.participants.forEach((n=>{var a;if(n.id===this.user.id&&n.clientId===this.clientId||!(null===(a=null==t?void 0:t.participants)||void 0===a?void 0:a.find((e=>e.id===n.id&&e.clientId===n.clientId&&e.connectionState===d.ParticipantConnectionState.Connected))))n.connectionState&&n.connectionState>d.ParticipantConnectionState.Connected&&n.id!==this.user.id&&n.clientId!==this.clientId&&n.getFullId()!=e.localParticipant.getFullId()&&n.updateConnectionState(n.connectionState,e);else{const a=i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[2023] [CallId: ${e.id}] SYNC CONNECT failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`):i.event!==d.SignalEvent.ERROR||f.error(`[2028] [CallId: ${e.id}] SYNC CONNECT failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`)};this.signalingClient.clearParticipantSignals(e.id,n.getFullId()),this.signalingClient.sendSignalMessage({mediaFlow:i,callId:e.id,event:d.SignalEvent.CONNECT,sessionId:t.sessionId,to:n.getFullId(),metadata:e.metadata},a)}}))))};f.info(`[2067] [CallId: ${e.id}] Sending offer to server participant: ${n.getFullId()}`),this.sendOfferPeerToPeer(e,n,a)}catch(i){throw f.error(`[2049] [CallId: ${e.id}] SFU setup error: message: ${i instanceof Error?i.message:JSON.stringify(i)}`),(0,S.toCallException)(i)}}processRemoteParticipants(e,i){i.length&&(i.forEach((i=>{var t,n,a,l,o,r,c,u,p,h,g,v,S,f,C,I,m,E;let P=e.participants.find((e=>e.getFullId()===this.getParticipantId(i)));if(P||(P=e.participants.find((e=>e.id===i.id&&(e.clientId===i.clientId||!e.clientId))),P&&!P.clientId&&(P.clientId=i.clientId)),P)P&&(P.presenter=!!i.presenter,P.setMediaScreenShareState((null===(h=i.mediaState)||void 0===h?void 0:h.screenShare)||{enabled:!1,changedBy:null===(v=null===(g=i.mediaState)||void 0===g?void 0:g.screenShare)||void 0===v?void 0:v.changedBy},e),P.setMediaVideoState((null===(S=i.mediaState)||void 0===S?void 0:S.video)||{enabled:!1,changedBy:null===(C=null===(f=i.mediaState)||void 0===f?void 0:f.video)||void 0===C?void 0:C.changedBy},i.permissions||{canPublishVideo:!1},e),P.setMediaAudioState((null===(I=i.mediaState)||void 0===I?void 0:I.audio)||{enabled:!1,changedBy:null===(E=null===(m=i.mediaState)||void 0===m?void 0:m.audio)||void 0===E?void 0:E.changedBy},i.permissions||{canPublishAudio:!1},e),P.setHold(!!i.hasOwnProperty("onHold")&&!!i.onHold,e),P.state!=i.state&&void 0!==i.state&&P.updateState(i.state||d.ParticipantState.Idle,e));else{const h=new s.Participant(i.id,i.clientId);h.getFullId()!==(null==e?void 0:e.localParticipant.getFullId())&&(h.state=i.state||d.ParticipantState.Idle),h.setMediaVideoState((null===(t=i.mediaState)||void 0===t?void 0:t.video)||{enabled:!1,changedBy:null===(a=null===(n=i.mediaState)||void 0===n?void 0:n.video)||void 0===a?void 0:a.changedBy},i.permissions||{canPublishVideo:!1},e),h.setMediaAudioState((null===(l=i.mediaState)||void 0===l?void 0:l.audio)||{enabled:!1,changedBy:null===(r=null===(o=i.mediaState)||void 0===o?void 0:o.audio)||void 0===r?void 0:r.changedBy},i.permissions||{canPublishAudio:!1},e),h.setHold(!!i.hasOwnProperty("onHold")&&!!i.onHold,e),h.setMediaScreenShareState((null===(c=i.mediaState)||void 0===c?void 0:c.screenShare)||{enabled:!1,changedBy:null===(p=null===(u=i.mediaState)||void 0===u?void 0:u.screenShare)||void 0===p?void 0:p.changedBy},e),e.addParticipantToList(h),e.emitParticipantsAdded([h])}})),f.info(`[2098] [CallId: ${e.id}] Processed participants - Added and Updated`,{color:"cyan"}))}reconcileParticipants(e,i){if(!(null==i?void 0:i.length))return;const t=e.participants.filter((t=>(t.id!==e.localParticipant.id||t.clientId!==e.localParticipant.clientId)&&!i.some((e=>!(e.id!==t.id||e.clientId!==t.clientId&&e.clientId&&t.clientId)))));t.length&&(e.participants=e.participants.filter((e=>!t.includes(e))),e.emitParticipantsRemoved(t))}processJoinCall(e,i,t){e.mediaFlow!==d.MediaFlow.SFU&&e.localParticipant.updateConnectionState(d.ParticipantConnectionState.Connected,e);const n=i.mediaFlow||d.MediaFlow.P2P;e.setSessionId(i.sessionId),e.changeMediaFlow(n),e.localParticipant.updateState(d.ParticipantState.Joined,e),e.setState(d.CallState.Connected,t)?this.processJoinAcknowledgment(e,i,n):this.leaveCall(e,!0,"processJoinCall")}startCall(e,i,t){const a=i.mediaFlow,s=e.participants.filter((e=>!(e.id===this.user.id&&e.clientId===this.clientId))).map((e=>e.serialize()));e.mediaFlow!==d.MediaFlow.SFU&&e.localParticipant.updateConnectionState(d.ParticipantConnectionState.Connecting,e);const o=(i,o)=>{var r,c,u,p,h,v,C,I,m,E,P;if(e.state==d.CallState.Idle)return i.forEach((e=>{e.stop()})),void(null==t||t({error:(0,S.checkCode)(5002,"Call was ended before media setup completed")}));o&&o.length>0&&(e.localParticipant.setVideoTracks(o,e),e.localVideoTracks=o,e.setVideoDeviceId(o[0].getSettings().deviceId||null)),e.localParticipant.setAudioTracks(i,e),e.localAudioTracks=i,this.joinToCall({mediaFlow:a,callId:e.id,sessionId:e.sessionId,participants:s,metadata:e.metadata,callOptions:Object.assign(Object.assign({},void 0!==(null===(r=e.settings)||void 0===r?void 0:r.callType)&&{callType:e.settings.callType}),{settings:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==(null===(c=e.settings)||void 0===c?void 0:c.broadcastSettings)&&{broadcastSettings:e.settings.broadcastSettings}),void 0!==(null===(u=e.settings)||void 0===u?void 0:u.startsAt)&&{startsAt:l.default.fromNumber(e.settings.startsAt)}),void 0!==(null===(p=e.settings)||void 0===p?void 0:p.expiresAt)&&{expiresAt:l.default.fromNumber(e.settings.expiresAt)}),void 0!==(null===(h=e.settings)||void 0===h?void 0:h.persistent)&&{persistent:e.settings.persistent}),{permissions:{allowPublishAudio:null!==(I=null===(C=null===(v=null==e?void 0:e.settings)||void 0===v?void 0:v.permissions)||void 0===C?void 0:C.allowPublishAudio)&&void 0!==I&&I,allowPublishVideo:null!==(P=null===(E=null===(m=null==e?void 0:e.settings)||void 0===m?void 0:m.permissions)||void 0===E?void 0:E.allowPublishVideo)&&void 0!==P&&P}})}),joinOptions:{muted:e.muted,videoEnabled:e.videoEnabled}},(i=>n(this,void 0,void 0,(function*(){var n;return i instanceof g.SceytCallException||i instanceof Error?(f.error(`[2137] [CallId: ${e.id}] SYNC JOIN failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`),e.setState(d.CallState.Closed,"joinCall failed"),void(null==t||t({error:(0,S.toCallException)(i)}))):i.event===d.SignalEvent.ERROR?(f.error(`[2141] [CallId: ${e.id}] SYNC JOIN failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`),void(null==t||t({error:(0,S.checkCode)(5003,(null===(n=i.error)||void 0===n?void 0:n.message)||"Unknown error")}))):void this.processJoinCall(e,i,"from joinCall")}))))};return e.localAudioTracks&&e.localAudioTracks.length>0||e.localVideoTracks&&e.localVideoTracks.length>0?!(e.localAudioTracks&&e.localAudioTracks.length>0)&&e.localVideoTracks&&e.localVideoTracks.length>0?this.setupMediaStream(e).then((({audioTracks:e})=>{o(e,i.localVideoTracks||[])})):e.localAudioTracks&&e.localAudioTracks.length>0&&!(e.localVideoTracks&&e.localVideoTracks.length>0)?o(i.localAudioTracks||[]):o(e.localAudioTracks||[],e.localVideoTracks||[]):this.setupMediaStream(e).then((({audioTracks:e})=>{o(e)})),e}promoteFromPrepared(e,i){var t;const n=this.prepareCalls.findIndex((i=>i.id===e));if(-1===n)return;const a=this.prepareCalls[n];return this.prepareCalls.splice(n,1),this.activeCalls.push(a),i&&(this.updateCallMetadata(a,i),(null===(t=i.participants)||void 0===t?void 0:t.length)&&this.syncParticipants(a,i.participants)),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls),a}prepareCall(e,i,t){var n,a,l;try{const o=e||(0,h.v4)();f.info(`[2155] [CallId: ${e}] prepareCall, creating call object`,{color:"blue"});const r=this.activeCalls.find((i=>i.id===e));if(r)return{success:!0,data:r};const u=this.prepareCalls.find((i=>i.id===e));if(u)return this.applyCreateOptions(u,i),this.applyServerCall(u,t),{success:!0,data:u};const p=null!==(a=null!==(n=null==t?void 0:t.mediaFlow)&&void 0!==n?n:null==i?void 0:i.mediaFlow)&&void 0!==a?a:0,g=new s.Participant(this.user.id,this.clientId),v=new c.Call({id:o,sessionId:null==t?void 0:t.sessionId,mediaFlow:null!=p?p:d.MediaFlow.P2P,localParticipant:g,participants:[g],createdBy:null!==(l=null==t?void 0:t.createdBy)&&void 0!==l?l:this.user.id,chatClient:this.chatClient,isCallSilenced:!1});return this.applyCreateOptions(v,i),this.applyServerCall(v,t),this.prepareCalls.push(v),{success:!0,data:v}}catch(i){return f.error(`[2158] [CallId: ${e}] prepareCall failed: ${i.message||JSON.stringify(i)}`,{color:"red"}),{success:!1,error:(0,S.toCallException)(i)}}}prepareCallFromCallID(e){return n(this,void 0,void 0,(function*(){return new Promise((i=>{this.signalingClient.sendSignalMessage({event:d.SignalEvent.GET_CALL,callId:e},(t=>{var n,a,l,s;if(t instanceof g.SceytCallException||t instanceof Error)return f.error(`[2160] prepareCallFromCallID GET_CALL failed: ${t.message}`,{color:"red"}),void i({success:!1,error:(0,S.toCallException)(t)});if(t.event===d.SignalEvent.ERROR)return f.error(`[2161] prepareCallFromCallID GET_CALL failed: ${null===(n=t.error)||void 0===n?void 0:n.message}`,{color:"red"}),void i({success:!1,error:(0,S.checkCode)((null===(a=t.error)||void 0===a?void 0:a.code)||5e3,(null===(l=t.error)||void 0===l?void 0:l.message)||"GET_CALL failed")});const o=null===(s=t.calls)||void 0===s?void 0:s.find((i=>i.id===e));if(!o)return void i({success:!1,error:g.SceytCallException.BadRequest(4004,`Call ${e} not found`)});const r=this.prepareCall(e,{mediaFlow:o.mediaFlow},o);r.success&&r.data&&this.updateCallMetadata(r.data,o),i(r)}),"get_call")}))}))}joinCall(e,i,t){let n=null;try{f.info(`[2159] [CallId: ${e.id}] joinCall, start call`,{color:"blue"});const a={id:e.id,sessionId:e.sessionId||void 0,mediaFlow:e.mediaFlow,participants:e.participants.filter((({id:e})=>e!==this.user.id)),metadata:e.metadata,createdBy:e.createdBy,localAudioTracks:i.localAudioTracks,localVideoTracks:i.localVideoTracks,audioSettings:i.audioSettings,videoSettings:i.videoSettings},l=e.setState(d.CallState.Connecting,"joinCall");let s=this.promoteFromPrepared(e.id);if(s)this.applyOptionsToExistingCall(s,a,s.participants,s.participants);else{const{call:e}=this.findOrCreateCall(a);s=e}return l?(s.localParticipant.clientId=this.clientId,n=this.startCall(s,a,t),{success:!0,data:s}):{success:!1,error:(0,S.checkCode)(5001,`Failed to set call state from ${s.state} to connecting`)}}catch(e){return f.error(`[2173] [CallId: ${null==n?void 0:n.id}] Join call failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,S.toCallException)(e)}}}createCall(e){var i,t,a,s;return n(this,void 0,void 0,(function*(){try{f.info(`[2180] [CallId: ${e.id}] createCall, creating call link`,{color:"blue"});const n=e.settings;if(void 0!==(null==n?void 0:n.startsAt)&&void 0!==(null==n?void 0:n.expiresAt)&&n.startsAt>=n.expiresAt)return{success:!1,error:g.SceytCallException.BadRequest(4001,"startsAt must be before expiresAt")};const o=[...new Set(e.participants.filter((e=>!(e.id===this.user.id&&e.clientId===this.clientId))).map((e=>e.id)))],r=null!==(i=this.prepareCalls.find((i=>i.id===e.id)))&&void 0!==i?i:e,c=yield new Promise((e=>{var i,t,a,s;this.signalingClient.sendSignalMessage(Object.assign(Object.assign({event:d.SignalEvent.CREATE,callId:r.id,mediaFlow:r.mediaFlow,participants:o.map((e=>({id:e,clientId:""})))},r.metadata&&{metadata:r.metadata}),{callOptions:Object.assign(Object.assign({},void 0!==(null==n?void 0:n.callType)&&{callType:n.callType}),{settings:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==(null==n?void 0:n.broadcastSettings)&&{broadcastOptions:n.broadcastSettings}),void 0!==(null==n?void 0:n.startsAt)&&{startsAt:l.default.fromNumber(n.startsAt)}),void 0!==(null==n?void 0:n.expiresAt)&&{expiresAt:l.default.fromNumber(n.expiresAt)}),void 0!==(null==n?void 0:n.persistent)&&{persistent:n.persistent}),void 0!==(null==n?void 0:n.notifyOnParticipantJoin)&&{notifyOnParticipantJoin:n.notifyOnParticipantJoin}),void 0!==(null==n?void 0:n.maxParticipantsCount)&&{maxParticipantsCount:n.maxParticipantsCount}),{permissions:{allowPublishAudio:null!==(t=null===(i=null==n?void 0:n.permissions)||void 0===i?void 0:i.allowPublishAudio)&&void 0!==t&&t,allowPublishVideo:null!==(s=null===(a=null==n?void 0:n.permissions)||void 0===a?void 0:a.allowPublishVideo)&&void 0!==s&&s}})})}),e)}));return c instanceof g.SceytCallException||c instanceof Error?(f.error(`[2210] [CallId: ${r.id}] CREATE signal failed: ${c.message}`,{color:"red"}),{success:!1,error:(0,S.toCallException)(c)}):c.event===d.SignalEvent.ERROR?(f.error(`[2219] [CallId: ${r.id}] CREATE signal failed: ${c.error?`${c.error.message} code: ${c.error.code}`:""}`,{color:"red"}),{success:!1,error:(0,S.checkCode)((null===(t=c.error)||void 0===t?void 0:t.code)||5e3,(null===(a=c.error)||void 0===a?void 0:a.message)||"Create call failed")}):(f.info(`[2228] [CallId: ${r.id}] Call link created successfully`,{color:"blue"}),c.sessionId&&(this.promoteFromPrepared(r.id),r.setSessionId(c.sessionId),r.setIsCreatedRemotely(!0)),(null===(s=c.participants)||void 0===s?void 0:s.length)&&this.reconcileParticipants(r,c.participants),{success:!0,data:r})}catch(i){return f.error(`[2238] [CallId: ${e.id}] createCall failed: ${i.message||JSON.stringify(i)}`,{color:"red"}),{success:!1,error:(0,S.toCallException)(i)}}}))}callOptionsToSettings(e){var i,t,n,a;const s=e.settings;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},void 0!==e.callType&&{callType:e.callType}),void 0!==(null==s?void 0:s.startsAt)&&{startsAt:l.default.isLong(s.startsAt)?s.startsAt.toNumber():s.startsAt}),void 0!==(null==s?void 0:s.expiresAt)&&{expiresAt:l.default.isLong(s.expiresAt)?s.expiresAt.toNumber():s.expiresAt}),void 0!==(null==s?void 0:s.persistent)&&{persistent:s.persistent}),void 0!==(null==s?void 0:s.broadcastOptions)&&{broadcastSettings:s.broadcastOptions}),void 0!==(null==s?void 0:s.notifyOnParticipantJoin)&&{notifyOnParticipantJoin:s.notifyOnParticipantJoin}),void 0!==(null==s?void 0:s.maxParticipantsCount)&&{maxParticipantsCount:s.maxParticipantsCount}),{permissions:{allowPublishAudio:null!==(t=null===(i=null==s?void 0:s.permissions)||void 0===i?void 0:i.allowPublishAudio)&&void 0!==t&&t,allowPublishVideo:null!==(a=null===(n=null==s?void 0:s.permissions)||void 0===n?void 0:n.allowPublishVideo)&&void 0!==a&&a}})}signalMessageToICall(e){return Object.assign({id:e.callId,sessionId:e.sessionId,mediaFlow:e.mediaFlow,createdBy:e.createdBy,metadata:e.metadata||{},participants:e.participants||[],createdAt:l.default.isLong(e.createdAt)?e.createdAt.toNumber():e.createdAt},e.callOptions&&{options:e.callOptions})}applyCreateOptions(e,i){if(!i)return;const t=i.videoCall?Object.assign(Object.assign({},i.metadata),{videoCall:"true"}):i.metadata;if(t&&(e.metadata=t),i.videoCall&&e.setVideoCall(!0),i.settings&&e.setSettings(i.settings),i.participantIds){const t=[...new Set(i.participantIds.filter((e=>e!==this.user.id)))],n=new Set(e.participants.map((e=>e.id))),a=t.filter((e=>!n.has(e))).map((e=>new s.Participant(e)));a.length>0&&(e.participants=(0,u.makeFirstById)([...e.participants,...a],this.user.id,this.clientId))}}applyServerCall(e,i){var t,n;i&&(i.sessionId&&e.setSessionId(i.sessionId),void 0!==i.mediaFlow&&(e.mediaFlow=i.mediaFlow),i.metadata&&(null===(t=Object.values(i.metadata))||void 0===t?void 0:t.length)&&(e.metadata=i.metadata),i.createdBy&&(e.createdBy=i.createdBy),i.options&&e.setSettings(this.callOptionsToSettings(i.options)),(null===(n=i.participants)||void 0===n?void 0:n.length)&&this.syncParticipants(e,i.participants))}updateCallMetadata(e,i){var t,n;i.metadata&&(null===(t=Object.values(i.metadata))||void 0===t?void 0:t.length)&&(e.metadata=i.metadata||{}),e.createdBy=i.createdBy,e.sessionId=i.sessionId,e.id=i.id,e.setVideoCall("true"===(null===(n=e.metadata)||void 0===n?void 0:n.videoCall)),e.mediaFlow!==d.MediaFlow.SFU&&i.mediaFlow===d.MediaFlow.SFU&&e.changeMediaFlow(d.MediaFlow.SFU),i.options&&e.setSettings(this.callOptionsToSettings(i.options)),f.info(`[2187] [CallId: ${e.id}] Updated call metadata for call ${e.id}`,{color:"light-blue"})}syncParticipants(e,i){f.info(`[2198] [CallId: ${e.id}] Syncing participants for call ${e.id}`,{color:"light-blue"}),e.participants=e.participants.filter((t=>{const n=i.find((e=>!(e.id!==t.id||e.clientId!==t.clientId&&e.clientId&&t.clientId)));return n||(t.state=d.ParticipantState.Left,e.emitParticipantStateChanged(t,d.ParticipantState.Left)),!!n})),f.info(`[2216] [CallId: ${e.id}] Syncing participants for call ${e.id}`,{color:"light-blue"});for(const t of i){const i=e.participants.find((e=>!(e.id!==t.id||e.clientId!==t.clientId&&t.clientId&&e.clientId)));if(f.info(`[2219] [CallId: ${e.id}] Syncing participant ${null==i?void 0:i.getFullId()} for call ${e.id}`,{color:"light-blue"}),i){if(i.clientId||(i.clientId=t.clientId),i.id===e.localParticipant.id&&i.clientId===e.localParticipant.clientId){e.localParticipant.state===d.ParticipantState.Joined&&(t.state||0)>d.ParticipantState.Joined&&this.leaveCall(e,!0,"syncParticipants"),this.syncParticipantMediaState(e,i,t);continue}i.state=t.state||d.ParticipantState.Idle,e.emitParticipantStateChanged(i,t.state||d.ParticipantState.Idle),i.state!==d.ParticipantState.Joined?i.getFullId()!==e.localParticipant.getFullId()&&(this.closePeerConnections(e.id,i.getFullId()),e.activeSpeakerManager.removeParticipant(i)):i.id!==e.localParticipant.id&&i.clientId!==e.localParticipant.clientId&&e.state===d.CallState.Connected&&this.handleNewParticipant(e,i),i.getFullId()===e.localParticipant.getFullId()&&(e.localParticipant=i),this.syncParticipantMediaState(e,i,t),f.info(`[2254] [CallId: ${e.id}] Syncing existing participants: ${i.getFullId()} for call ${e.id}`,{color:"light-blue"})}else{const i=new s.Participant(t.id,t.clientId);i.state=t.state||d.ParticipantState.Idle,e.addParticipantToList(i),this.syncParticipantMediaState(e,i,t),f.info(`[2263] [CallId: ${e.id}] Syncing no existing participants: ${i.getFullId()} for call ${e.id}`,{color:"light-blue"}),e.emitParticipantsAdded([i]),(e.mediaFlow!==d.MediaFlow.SFU&&t.state===d.ParticipantState.Joined||e.mediaFlow===d.MediaFlow.SFU&&t.connectionState===d.ParticipantConnectionState.Connected&&e.state===d.CallState.Connected)&&this.handleNewParticipant(e,i)}}}syncParticipantMediaState(e,i,t){var n,a,l;if(i.getFullId()===t.id+(t.clientId?"/"+t.clientId:"")){const s=!!t.hasOwnProperty("onHold")&&!!t.onHold,o=!!t.hasOwnProperty("isCallSilenced")&&!!t.isCallSilenced;f.info(`[syncParticipantMediaState] [CallId: ${e.id}] Media state sync for participant ${i.getFullId()} - current: ${JSON.stringify(i.mediaState)} server: ${JSON.stringify(null==t?void 0:t.mediaState)}`,{color:"light-blue"}),f.info(`[syncParticipantMediaState] [CallId: ${e.id}] Permissions sync for participant ${i.getFullId()} - current: ${JSON.stringify(i.permissions)} server: ${JSON.stringify(null==t?void 0:t.permissions)}`,{color:"light-blue"}),i.setMediaAudioState((null===(n=null==t?void 0:t.mediaState)||void 0===n?void 0:n.audio)||{enabled:!1,changedBy:""},(null==t?void 0:t.permissions)||{},e),i.setMediaVideoState((null===(a=null==t?void 0:t.mediaState)||void 0===a?void 0:a.video)||{enabled:!1,changedBy:""},(null==t?void 0:t.permissions)||{},e),i.setMediaScreenShareState((null===(l=null==t?void 0:t.mediaState)||void 0===l?void 0:l.screenShare)||{enabled:!1,changedBy:""},e),s!==i.onHold&&(f.info(`[2317] [CallId: ${e.id}] Participant ${i.getFullId()} hold state changed: ${i.onHold} -> ${s}`,{color:"light-blue"}),i.setHold(s,e)),i.getFullId()===e.localParticipant.getFullId()&&(f.info(`[2327] [CallId: ${e.id}] Participant ${i.getFullId()} ring allowed state changed: ${o}`,{color:"light-blue"}),e.setIsCallSilenced(o))}}handleNewParticipant(e,i){if(f.info(`[2333] [CallId: ${e.id}] Call media flow: ${e.mediaFlow}`,{color:"light-blue"}),e.mediaFlow!==d.MediaFlow.SFU){if(i.updateState(d.ParticipantState.Joined,e),i.getFullId()!==e.localParticipant.getFullId()&&i.connectionState!==d.ParticipantConnectionState.Connected&&i.connectionState!==d.ParticipantConnectionState.Reconnecting){const t=i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[2341] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`,{color:"red"}):i.event!==d.SignalEvent.ERROR||f.error(`[2345] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"})};f.info(`[2370] [CallId: ${e.id}] Sending offer to participant: ${i.getFullId()}`),e.localParticipant.state===d.ParticipantState.Joined&&e.mediaFlow===d.MediaFlow.P2P&&this.isPolitePeer(i.getFullId(),e.localParticipant.getFullId())?this.sendOfferPeerToPeer(e,i,t):e.localParticipant.state===d.ParticipantState.Joined&&(this.signalingClient.clearParticipantSignals(e.id,i.getFullId()),this.signalingClient.sendSignalMessage({to:i.getFullId(),mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.CONNECT,sessionId:e.sessionId},t))}}else if(i.getFullId()!==e.localParticipant.getFullId()&&i.connectionState!==d.ParticipantConnectionState.Reconnecting){const t=i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[2354] [CallId: ${e.id}] SYNC CONNECT signal sent failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`,{color:"red"}):i.event!==d.SignalEvent.ERROR||f.error(`[2358] [CallId: ${e.id}] SYNC CONNECT signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"})};this.signalingClient.clearParticipantSignals(e.id,i.getFullId()),this.signalingClient.sendSignalMessage({to:i.getFullId(),mediaFlow:e.mediaFlow,callId:e.id,event:d.SignalEvent.CONNECT,sessionId:e.sessionId},t)}}handleSessionRenewedSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(!i)return void f.warn(`[SessionRenewed] [CallId: ${e.callId}] No active call found`,{color:"red"});const t=e.sessionId;f.info(`[SessionRenewed] [CallId: ${i.id}] Session renewed: ${i.sessionId} -> ${t}`,{color:"cyan"}),i.setSessionId(t),i.emitSessionRenewed(t)}handleConnectSignal(e){const i=this.activeCalls.find((i=>i.id===e.callId));if(i){let t=i.participants.find((i=>i.getFullId()===e.from));t&&this.sendOfferPeerToPeer(i,t,(e=>{e instanceof g.SceytCallException||e instanceof Error?f.error(`[2417] [CallId: ${i.id}] SYNC OFFER signal sent failed message: ${e.message} code: ${e instanceof g.SceytCallException?e.code:""}`,{color:"red"}):e.event!==d.SignalEvent.ERROR||f.error(`[2421] [CallId: ${i.id}] SYNC OFFER signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})}))}}handleMediaFlowSwitch(e){f.info(`[2375] [CallId: ${e.id}] Switching call ${e.id} from P2P to SFU`,{color:"light-blue"});const i=new s.Participant(e.id);e.setServerParticipant(i),f.info(`[2395] [CallId: ${e.id}] Sending offer to server participant: ${i.getFullId()}`),this.sendOfferPeerToPeer(e,i,(i=>{i instanceof g.SceytCallException||i instanceof Error?f.error(`[2386] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.message} code: ${i instanceof g.SceytCallException?i.code:""}`,{color:"red"}):i.event!==d.SignalEvent.ERROR||f.error(`[2390] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"})})),e.participants.forEach((e=>{e.setShouldResetPeerConnection(!0)}))}}i.InternalCallHandler=I},787:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.Participant=void 0;const n=t(578),a=t(758),l=t(645),s=(0,l.createLogger)("ParticipantState"),o=(0,l.createLogger)("ConnectionState");i.Participant=class{constructor(e,i){this.clientId="",this.onHold=!1,this.presenter=!1,this.audioTracks=[],this.videoTracks=[],this.shouldResetPeerConnection=!1,this.state=n.ParticipantState.Idle,this.connectionState=n.ParticipantConnectionState.Idle;const t=e.split("/");this.id=t[0],this.clientId=i||t[1]||""}updateState(e,i,t){const n=null==i?void 0:i.id,l=new a.ParticipantStateMachine(this.id,n).updateState(e,this.state);return l&&(this.state=e,i.emitParticipantStateChanged(this,e,t),s.info(`[35] [CallId: ${n}] Updating state: ${e}, participantID: ${this.getFullId()}`,{color:"blue"})),l}updateConnectionState(e,i){const t=null==i?void 0:i.id,n=new a.ParticipantStateMachine(this.id,t).updateConnectionState(e,this.connectionState);return n&&(this.connectionState=e,i.emitParticipantConnectionStateChanged(this,e),o.info(`[45] [CallId: ${t}] Updating connection state: ${e}, participantID: ${this.getFullId()}`,{color:"blue"})),n}setShouldResetPeerConnection(e){this.shouldResetPeerConnection=e}setMediaAudioState(e,i,t){this.audioTracks.forEach((i=>{i.enabled=e.enabled})),this.mediaState||(this.mediaState={audio:{enabled:!1},video:{enabled:!1},screenShare:{enabled:!1}}),this.mediaState.audio=e,this.permissions||(this.permissions={canPublishAudio:!1,canPublishVideo:!1}),this.permissions.canPublishAudio=!!(null==i?void 0:i.canPublishAudio),t&&t.emitParticipantEvent(this,this.mediaState.audio.enabled?"Unmute":"Mute",e.changedBy)}setMediaVideoState(e,i,t){this.mediaState||(this.mediaState={audio:{enabled:!1},video:{enabled:!1},screenShare:{enabled:!1}}),this.mediaState.video=e,this.permissions||(this.permissions={canPublishAudio:!1,canPublishVideo:!1}),this.permissions.canPublishVideo=!!(null==i?void 0:i.canPublishVideo),this.videoTracks.forEach((i=>{i.enabled=e.enabled})),t&&t.emitParticipantEvent(this,e.enabled?"VideoEnabled":"VideoDisabled",e.changedBy)}setMediaScreenShareState(e,i){this.mediaState||(this.mediaState={audio:{enabled:!0},video:{enabled:!1},screenShare:{enabled:!1}}),this.mediaState.screenShare=e,this.videoTracks.forEach((i=>{i.enabled=e.enabled})),i&&i.emitParticipantEvent(this,e.enabled?"ScreenSharingStarted":"ScreenSharingStopped",e.changedBy)}setPresenter(e){this.presenter=e}setAudioTracks(e,i){this.audioTracks=e,this.audioTracks.forEach((e=>{var i;e.enabled=!!(null===(i=this.mediaState)||void 0===i?void 0:i.audio.enabled)})),i.emitAudioTrackAdded(this,e[0])}setVideoTracks(e,i){this.videoTracks=e,this.videoTracks.forEach((e=>{var i;e.enabled=!!(null===(i=this.mediaState)||void 0===i?void 0:i.video.enabled)})),i.emitVideoTrackAdded(this,e[0])}setHold(e,i){this.onHold=e,i&&i.emitParticipantEvent(this,this.onHold?"Hold":"Unhold")}serialize(){return{id:this.id,clientId:this.clientId}}getFullId(){return this.id+(this.clientId?"/"+this.clientId:"")}}},816:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.QueryBuilder=void 0,i.QueryBuilder=class{constructor(){this.count=10}}},185:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.RecentCallQueryBuilder=void 0;const n=t(578),a=t(650),l=t(816),s=t(343),o=t(228);class r extends l.QueryBuilder{constructor(){super(...arguments),this.order=n.CDRRequestOrder.ASC,this.count=10,this.participantCount=10,this.event=n.CDRRequestEvent.GET_RECENT_CALLS,this.direction=n.CDRRequestDirection.NEXT,this.setSessionIdList=e=>(this.sessionIdList=e,this),this.setEvent=e=>(this.event=e,this),this.setSessionId=e=>(this.sessionId=e,this),this.limit=e=>(this.count=e,this),this.setParticipantCount=e=>(this.participantCount=e,this),this.setOrder=e=>(this.order=e,this),this.setDirection=e=>(this.direction=e,this),this.setCallTypes=e=>(this.callTypes=e,this),this.build=()=>{const e=a.InternalCallHandler.getInstance();this.chatClient=e.chatClient;try{return new s.RecentCallQuery(this)}catch(e){throw(0,o.toCallException)(e)}}}}i.RecentCallQueryBuilder=r},343:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.RecentCallQuery=void 0;const a=t(578),l=t(645),s=t(228),o=(0,l.createLogger)("RecentCallQuery");i.RecentCallQuery=class{constructor(e){this.count=10,this.hasNext=!0,this.loading=!1,this.order=a.CDRRequestOrder.ASC,this.participantCount=10,this.event=a.CDRRequestEvent.GET_RECENT_CALLS,this.direction=a.CDRRequestDirection.NEXT,this.loadNextPage=()=>n(this,void 0,void 0,(function*(){if(this.loading)throw o.info("QUERY_IN_PROGRESS"),(0,s.checkCode)(5001,"QUERY_IN_PROGRESS");if(this.hasNext){this.loading=!0;const e=yield this.chatClient.sendCallDetailsRecord(Object.assign(Object.assign({event:this.event,order:this.order,limit:this.count,participantCount:this.participantCount,direction:this.direction},this.nextToken||this.sessionId?{position:Object.assign(Object.assign({},this.sessionId?{sessionId:this.sessionId}:{}),this.nextToken?{nextToken:this.nextToken}:{})}:{}),void 0!==this.callTypes&&{filter:{callTypes:this.callTypes}}));this.loading=!1;const{getRecentCallsResponse:{records:i,nextToken:t}}=e;return this.hasNext=!!t,this.nextToken=t,{records:i,hasNext:this.hasNext}}return{records:[],hasNext:this.hasNext}})),this.deleteCalls=()=>n(this,void 0,void 0,(function*(){var e;if(null===(e=this.sessionIdList)||void 0===e?void 0:e.length)return yield this.chatClient.sendCallDetailsRecord({event:a.CDRRequestEvent.DELETE_RECENT_CALLS,sessionIdList:{items:this.sessionIdList}})})),this.order=e.order,this.count=e.count,this.participantCount=e.participantCount,this.sessionId=e.sessionId,this.event=e.event,this.direction=e.direction,this.chatClient=e.chatClient,this.sessionIdList=e.sessionIdList,this.callTypes=e.callTypes}set limit(e){this.count=e}get limit(){return this.count}}},680:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.toSessionDescription=i.toSessionData=void 0;const n=t(578),a=t(645),l=t(19),s=(0,a.createLogger)("SignalingExtensions");i.toSessionData=function(e,i){const t=e.sdp.sdp||"",a=1e3*Date.now()+performance.now()%1*1e3;s.info(`[32] [CALL_TIME_TO_SESSION_DATA_START: ${a}]`,{color:"blue"});const o=l.SdpConverter.parseToSdpData(t,l.CODEC_NAME_TO_VIDEO_CODEC,i===n.MediaFlow.S2W?l.CODEC_NAME_TO_AUDIO_CODEC_S2W:l.CODEC_NAME_TO_AUDIO_CODEC),r=1e3*Date.now()+performance.now()%1*1e3;return s.info(`[35] [CALL_TIME_TO_SESSION_DATA_END: ${r}]`,{color:"blue"}),{id:e.sessionId,version:e.versionId,sdpData:o}},i.toSessionDescription=function(e,i){if(e.sdpData){const t=l.SdpConverter.reconstructFromSDPData(e.sdpData);return s.info(`[53] [CallId: ${e.id}] toSessionDescription in sdp-converter: sdp: ${t}`,{color:"blue"}),{type:i,sdp:t}}return s.error("SessionData has neither sdpData nor sdp field"),null}},19:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SdpConverter=i.CODEC_NAME_TO_AUDIO_CODEC_S2W=i.CODEC_NAME_TO_AUDIO_CODEC=i.CODEC_NAME_TO_VIDEO_CODEC=void 0;const n=t(645),a=t(228),l=t(799),s=(0,n.createLogger)("SdpConverter");i.CODEC_NAME_TO_VIDEO_CODEC=["vp8","rtx","red"],i.CODEC_NAME_TO_AUDIO_CODEC=["opus","red"],i.CODEC_NAME_TO_AUDIO_CODEC_S2W=["opus","red","pcmu","pcma"];class o{static parseToSdpData(e,t=i.CODEC_NAME_TO_VIDEO_CODEC,n=i.CODEC_NAME_TO_AUDIO_CODEC){var a,l,s;const r=[],d=e.split("\n").map((e=>e.trim())).filter((e=>e.length>0)),c=o.extractSessionId(d)||"",u=o.extractSessionVersion(d)||0,p=o.extractOriginAddress(d)||"127.0.0.1",h=(null===(a=d.find((e=>e.startsWith("s="))))||void 0===a?void 0:a.substring(2))||"-",g=(null===(l=d.find(((e,i)=>e.startsWith("c=")&&!o.inMediaSection(d,i))))||void 0===l?void 0:l.split(" ").slice(2)[0])||"",v=(null===(s=o.firstValueStartingWith(d,"a=msid-semantic:"))||void 0===s?void 0:s.trim())||"WMS",S=o.parseBundleGroup(d),f=d.findIndex((e=>e.startsWith("m="))),C=f>0?d.slice(0,f):d,I=o.firstValueStartingWith(C,"a=ice-ufrag:")||"",m=o.firstValueStartingWith(C,"a=ice-pwd:")||"",E=o.parseIceOptions(C),P=o.parseFingerprint(C),b=o.parseSetup(C),y=C.some((e=>"a=ice-lite"===e)),O=C.some((e=>"a=extmap-allow-mixed"===e));return{sessionId:c,sessionVersion:u,bundleGroup:S,iceUfrag:I,icePwd:m,iceOptions:E,fingerprint:P,setup:b,media:o.parseMediaSections(d,r,t,n),sessionName:h,originAddress:p,connectionAddress:g,msidSemantic:v,iceLite:y,extmapAllowMixed:O,stringPool:r}}static reconstructFromSDPData(e){var i,t,n,l,r,d;try{const c=[];if(c.push("v=0\r\n"),c.push(`o=- ${e.sessionId} ${e.sessionVersion} IN IP4 ${e.originAddress}\r\n`),c.push(`s=${e.sessionName}\r\n`),c.push("t=0 0\r\n"),(null===(t=null===(i=e.fingerprint)||void 0===i?void 0:i.hashValue)||void 0===t?void 0:t.length)>0&&c.push(`a=fingerprint:${o.fingerprintToString(e.fingerprint)}\r\n`),(null===(n=null==e?void 0:e.bundleGroup)||void 0===n?void 0:n.length)>0){const i=e.media.map((e=>e.mid)).join(" ");c.push(`a=group:BUNDLE ${i}\r\n`)}(null===(l=null==e?void 0:e.iceOptions)||void 0===l?void 0:l.length)>0&&c.push(`a=ice-options:${e.iceOptions.join(" ")}\r\n`),(null==e?void 0:e.extmapAllowMixed)&&c.push("a=extmap-allow-mixed\r\n"),(null===(r=null==e?void 0:e.msidSemantic)||void 0===r?void 0:r.length)>0&&c.push(`a=msid-semantic: ${e.msidSemantic}\r\n`),(null==e?void 0:e.iceLite)&&c.push("a=ice-lite\r\n"),null===(d=null==e?void 0:e.media)||void 0===d||d.forEach((i=>{o.buildMediaSection(c,i,e)}));const u=c.join("");if(s.debug(`Reconstructed SDP (${null==u?void 0:u.length} bytes)`),!(null==u?void 0:u.includes("m=")))throw(0,a.checkCode)(4e3,"Reconstructed SDP missing media lines");if(!(null==u?void 0:u.includes("a=ice-ufrag:"))&&!(null==u?void 0:u.includes("a=ice-pwd:")))throw(0,a.checkCode)(4e3,"Reconstructed SDP missing ICE credentials");return u}catch(e){throw s.error(`[647] [CallId: GLOBAL_LOGS] Failed to reconstruct SDP: ${e.message}`,{color:"red"}),s.error(e,{color:"red"}),(0,a.toCallException)(e)}}static extractSessionId(e){const i=e.find((e=>e.startsWith("o=")));return i&&i.split(" ")[1]||null}static extractSessionVersion(e){const i=e.find((e=>e.startsWith("o=")));if(!i)return null;const t=i.split(" "),n=parseInt(t[2]||"0",10);return isNaN(n)?null:n}static extractOriginAddress(e){const i=e.find((e=>e.startsWith("o=")));return i&&i.split(" ")[5]||null}static parseBundleGroup(e){const i=e.find((e=>e.startsWith("a=group:BUNDLE ")));return i?i.substring(15).split(" ").map((e=>parseInt(e,10))).filter((e=>!isNaN(e))):[]}static parseIceOptions(e){const i=e.find((e=>e.startsWith("a=ice-options:")));return i?i.substring(14).split(" "):[]}static parseFingerprint(e){var i;const t=e.find((e=>e.startsWith("a=fingerprint:")));if(t){const e=t.substring(14).split(" ",2);if(2===e.length){let t;switch(e[0].toLowerCase()){case"sha-256":default:t=l.HashFunction.SHA256;break;case"sha-1":t=l.HashFunction.SHA1;break;case"sha-384":t=l.HashFunction.SHA384;break;case"sha-512":t=l.HashFunction.SHA512;break;case"md5":t=l.HashFunction.MD5}const n=e[1].replace(/:/g,"");return{hashFunc:t,hashValue:new Uint8Array((null===(i=n.match(/.{1,2}/g))||void 0===i?void 0:i.map((e=>parseInt(e,16))))||[])}}}return{hashFunc:l.HashFunction.SHA256,hashValue:new Uint8Array(0)}}static parseSetup(e){const i=e.find((e=>e.startsWith("a=setup:")));switch(null==i?void 0:i.substring(8).toLowerCase()){case"active":return l.DTLSSetup.ACTIVE;case"passive":return l.DTLSSetup.PASSIVE;default:return l.DTLSSetup.ACTPASS}}static firstValueStartingWith(e,i){const t=e.find((e=>e.startsWith(i)));return t?t.substring(i.length):null}static inMediaSection(e,i){return e.map(((e,i)=>({line:e,index:i}))).filter((({line:e})=>e.startsWith("m="))).map((({index:e})=>e)).some((e=>e<i))}static parseMediaSections(e,i,t,n){const a=e.map(((e,i)=>({line:e,index:i}))).filter((({line:e})=>e.startsWith("m="))).map((({index:e})=>e));return a.map(((l,s)=>{const r=s<a.length-1?a[s+1]:e.length;return o.parseMediaSection(e.slice(l,r),i,t,n)})).filter((e=>null!==e))}static parseMediaSection(e,i,t,n){var a;try{const t=e[0].substring(2).split(" ");let n;switch(t[0].toLowerCase()){case"audio":n=l.MediaType.AUDIO;break;case"video":n=l.MediaType.VIDEO;break;default:n=l.MediaType.MEDIA_TYPE_UNSPECIFIED}if(n===l.MediaType.MEDIA_TYPE_UNSPECIFIED)return s.warn(`Skipping unknown media type: ${t[0]}`),null;const r=parseInt(t[1]||"9",10)||9,d=t.slice(3).map((e=>parseInt(e,10))).filter((e=>!isNaN(e))),c=o.firstValueStartingWith(e,"a=mid:")||"",u=o.parseDirection(e),p=o.firstValueStartingWith(e,"a=msid:"),[h,g,v]=o.parseMSID(p||null),S=e.some((e=>"a=rtcp-mux"===e)),f=e.some((e=>"a=rtcp-rsize"===e)),C=e.some((e=>"a=end-of-candidates"===e)),I=(null===(a=e.find((e=>e.startsWith("c="))))||void 0===a?void 0:a.split(" ")[2])||"",m=o.firstValueStartingWith(e,"a=rtcp:")||"",E=new Map,P=[];d.forEach((e=>{E.set(e,{codecName:{id:e,mapKey:0},fmtp:[],rtcpFeedbackIds:[]}),P.push(e)})),e.filter((e=>e.startsWith("a=rtpmap:"))).forEach((e=>{const i=e.substring(9).split(" ",2);if(2===i.length){const e=parseInt(i[0],10);if(!isNaN(e)){const t=i[1];o.dynamicCodecNames.set(e,t);const n=o.CODEC_NAME_TO_MAP_KEY.get(t)||0;if(E.has(e)){const i=E.get(e);E.set(e,{codecName:{id:e,mapKey:n},fmtp:i.fmtp,rtcpFeedbackIds:i.rtcpFeedbackIds})}}}})),e.filter((e=>e.startsWith("a=fmtp:"))).forEach((e=>{const i=e.substring(7).split(" ",2);if(2===i.length){const e=parseInt(i[0],10);if(!isNaN(e)&&E.has(e)){const t=o.parseFmtp(i[1]),n=E.get(e);E.set(e,{codecName:n.codecName,fmtp:t,rtcpFeedbackIds:n.rtcpFeedbackIds})}}})),e.filter((e=>e.startsWith("a=rtcp-fb:"))).forEach((e=>{const i=e.substring(10).split(" ");if(i.length>=2){const e=parseInt(i[0],10);if(!isNaN(e)){let t="";for(let e=1;e<i.length;e++)t+=i[e]+(e!==i.length-1?" ":"");const n=o.RTCP_FEEDBACK_STRING_TO_ID.get(t);if(void 0!==n&&E.has(e)){const i=E.get(e),t=[...i.rtcpFeedbackIds];t.includes(n)||t.push(n),E.set(e,{codecName:i.codecName,fmtp:i.fmtp,rtcpFeedbackIds:t})}}}}));const b=P.map((e=>E.get(e))).filter((e=>void 0!==e)),y=o.parseExtmaps(e),O=o.parseSsrcs(e),T=o.parseSsrcGroups(e),$=o.parseCandidates(e),A=o.firstValueStartingWith(e,"a=ice-ufrag:"),w=o.firstValueStartingWith(e,"a=ice-pwd:"),R=A?o.addToStringPool(i,A):0,F=w?o.addToStringPool(i,w):0,M=e.find((e=>e.startsWith("a=ice-options:"))),_=M?M.substring(14).split(" "):void 0,N=e.find((e=>e.startsWith("a=fingerprint:"))),k=N?o.parseFingerprint([N]):{hashFunc:l.HashFunction.SHA256,hashValue:new Uint8Array(0)},D=e.find((e=>e.startsWith("a=setup:")));return{type:n,mid:c,direction:u,msidStream:h,msidTrackLabel:g,msidTrackId:v,rtcpMux:S,rtcpRsize:f,extmaps:y,codecs:b,ssrcGroups:T,ssrcs:O,connectionAddress:I,candidates:$,endOfCandidates:C,rtcpAddress:m,iceUfragRef:R,icePwdRef:F,iceOptions:_,fingerprint:k,setup:D?o.parseSetup([D]):l.DTLSSetup.ACTPASS,port:r}}catch(e){return s.error(`[647] [CallId: GLOBAL_LOGS] Failed to parse media section: ${e.message}`,{color:"red"}),s.error(e,{color:"red"}),null}}static parseDirection(e){return e.some((e=>"a=sendrecv"===e))?l.MediaDirection.SENDRECV:e.some((e=>"a=sendonly"===e))?l.MediaDirection.SENDONLY:e.some((e=>"a=recvonly"===e))?l.MediaDirection.RECVONLY:e.some((e=>"a=inactive"===e))?l.MediaDirection.INACTIVE:l.MediaDirection.SENDRECV}static parseMSID(e){if(!e||0===e.trim().length)return["","",0];const i=e.split(" ",2);if(i.length<2)return[e,"",0];const t=i[0],n=i[1],a=n.lastIndexOf("_");if(a>0){const e=n.substring(a+1),i=parseInt(e,10);if(!isNaN(i))return[t,n.substring(0,a+1),i]}return[t,n,0]}static parseFmtp(e){if(0===e.trim().length)return[];const i=[];return e.split(";").forEach((e=>{const t=e.trim();if(0!==t.length)if(t.includes("=")){const e=t.split("=",2);i.push({key:e[0].trim(),value:e[1].trim()})}else i.push({key:"value",value:t})})),i}static parseExtmaps(e){return e.filter((e=>e.startsWith("a=extmap:"))).map((e=>{const i=e.substring(9).split(" ",2);if(2!==i.length)return null;const t=i[0].split("/")[0],n=parseInt(t,10);if(isNaN(n))return null;const a=i[1];return{id:n,mapKey:o.URI_TO_EXTMAP_ID.get(a)||0}})).filter((e=>null!==e))}static parseSsrcs(e){const i=new Map;return e.filter((e=>e.startsWith("a=ssrc:"))).forEach((e=>{const t=e.substring(7).split(" ");if(t.length>=2){const e=parseInt(t[0],10);if(isNaN(e))return;const n=e,a=i.get(n)||{};if(t[1].startsWith("cname:"))a.cname=t[1].substring(6);else if(t[1].startsWith("msid:")){let e="";for(let i=1;i<t.length;i++)e+=t[i].substring(1===i?5:0)+(t.length-1!==i?" ":"");a.msid=e}i.set(n,a)}})),Array.from(i.entries()).map((([e,i])=>({id:e,cname:i.cname||"",msid:i.msid||""})))}static parseSsrcGroups(e){return e.filter((e=>e.startsWith("a=ssrc-group:"))).map((e=>{const i=e.substring(13).split(" ");return i.length>=2?{semantics:i[0],ssrcs:i.slice(1).map((e=>parseInt(e,10))).filter((e=>!isNaN(e)))}:null})).filter((e=>null!==e))}static parseCandidates(e){return e.filter((e=>e.startsWith("a=candidate:"))).map((e=>o.parseCandidate(e.substring(12)))).filter((e=>null!==e))}static parseCandidate(e){const i=e.split(" ");if(i.length<8)return null;const t=parseInt(i[0],10);if(isNaN(t))return null;const n=parseInt(i[1],10);if(isNaN(n))return null;let a;switch(i[2].toLowerCase()){case"udp":default:a=l.IceCandidateProtocol.UDP;break;case"tcp":a=l.IceCandidateProtocol.TCP}const s=parseInt(i[3],10);if(isNaN(s))return null;const o=i[4].split("."),r=new Uint8Array(o.map((e=>parseInt(e,10)))),d=parseInt(i[5],10);if(isNaN(d))return null;let c;switch(i[7].toLowerCase()){case"host":default:c=l.IceCandidateType.HOST;break;case"srflx":c=l.IceCandidateType.SRFLX;break;case"prflx":c=l.IceCandidateType.PRFLX;break;case"relay":c=l.IceCandidateType.RELAY}let u=new Uint8Array(0),p=0,h=l.IceCandidateTcpType.ACTIVE,g=8;for(;g<i.length;){switch(i[g]){case"raddr":if(g+1<i.length){const e=i[++g];u=new Uint8Array(e.split(".").map((e=>parseInt(e,10))))}break;case"rport":g+1<i.length&&(p=parseInt(i[++g],10)||0);break;case"tcptype":if(g+1<i.length)switch(i[++g].toLowerCase()){case"active":default:h=l.IceCandidateTcpType.ACTIVE;break;case"passive":h=l.IceCandidateTcpType.PASSIVE;break;case"so":h=l.IceCandidateTcpType.SO}}g++}return{foundation:t,component:n,protocol:a,priority:s,ip:r,port:d,type:c,raddr:u,rport:p,tcptype:h}}static addToStringPool(e,i){if(0===i.length)return 0;const t=e.indexOf(i);return t>=0?t+1:(e.push(i),e.length)}static getFromStringPool(e,i){return 0===i||i>e.length?"":e[i-1]}static getCodecID(e){var i;return(null===(i=e.codecName)||void 0===i?void 0:i.id)||0}static getCodecName(e){if(!e.codecName)return null;const i=e.codecName;if(i.mapKey>0){const e=o.MAP_KEY_TO_CODEC_NAME.get(i.mapKey);if(e)return e}return o.dynamicCodecNames.get(i.id)||null}static filterVideoCodecs(e,i){if(0===i.length)return e;const t=[],n=new Set;return e.forEach((e=>{const a=o.getCodecName(e);if(!a)return;const l=a.split("/")[0];i.some((e=>e.toLowerCase()===l.toLowerCase()))&&(t.push(e),n.add(o.getCodecID(e)))})),e.forEach((e=>{const i=o.getCodecName(e);if(i&&i.toLowerCase().startsWith("rtx/")){const i=e.fmtp.find((e=>"apt"===e.key)),a=i?parseInt(i.value,10):null;null!==a&&!isNaN(a)&&n.has(a)&&t.push(e)}})),t}static buildMediaSection(e,i,t){var n,a,r,d,c,u,p,h,g,v;let S;switch(i.type){case l.MediaType.AUDIO:S="audio";break;case l.MediaType.VIDEO:S="video";break;case l.MediaType.MEDIA_TYPE_UNSPECIFIED:return void s.error("Cannot reconstruct MEDIA_TYPE_UNSPECIFIED")}const f=(null===(n=null==i?void 0:i.codecs)||void 0===n?void 0:n.map((e=>o.getCodecID(e).toString())).join(" "))||"";e.push(`m=${S} ${i.port} UDP/TLS/RTP/SAVPF ${f}\r\n`);const C=(null==i?void 0:i.connectionAddress)||(null==t?void 0:t.connectionAddress)||"0.0.0.0";e.push(`c=IN IP4 ${C}\r\n`),(null===(a=null==i?void 0:i.rtcpAddress)||void 0===a?void 0:a.length)>0&&e.push(`a=rtcp:${i.rtcpAddress}\r\n`);const I=(null==i?void 0:i.iceUfragRef)>0?o.getFromStringPool(null==t?void 0:t.stringPool,null==i?void 0:i.iceUfragRef):null==t?void 0:t.iceUfrag,m=(null==i?void 0:i.icePwdRef)>0?o.getFromStringPool(null==t?void 0:t.stringPool,null==i?void 0:i.icePwdRef):null==t?void 0:t.icePwd;I.length>0&&e.push(`a=ice-ufrag:${I}\r\n`),m.length>0&&e.push(`a=ice-pwd:${m}\r\n`);const E=(null==i?void 0:i.iceOptions)||(null==t?void 0:t.iceOptions);E.length>0&&e.push(`a=ice-options:${E.join(" ")}\r\n`);const P=(null===(d=null===(r=null==i?void 0:i.fingerprint)||void 0===r?void 0:r.hashValue)||void 0===d?void 0:d.length)>0?null==i?void 0:i.fingerprint:null==t?void 0:t.fingerprint;(null===(c=null==P?void 0:P.hashValue)||void 0===c?void 0:c.length)>0&&e.push(`a=fingerprint:${o.fingerprintToString(P)}\r\n`);const b=(null==i?void 0:i.setup)!==l.DTLSSetup.ACTPASS||(null==t?void 0:t.setup)===l.DTLSSetup.ACTPASS?i.setup:t.setup;e.push(`a=setup:${o.setupToString(b)}\r\n`),e.push(`a=mid:${null==i?void 0:i.mid}\r\n`),null===(u=null==i?void 0:i.extmaps)||void 0===u||u.forEach((i=>{const t=o.EXTMAP_ID_TO_URI.get(i.mapKey)||`urn:ietf:params:rtp-hdrext:extension-${i.id}`;e.push(`a=extmap:${i.id} ${t}\r\n`)})),e.push(`a=${o.directionToString(null==i?void 0:i.direction)}\r\n`);const y=o.reconstructMSID(null==i?void 0:i.msidStream,null==i?void 0:i.msidTrackLabel,null==i?void 0:i.msidTrackId);(null==y?void 0:y.length)>0&&e.push(`a=msid:${y}\r\n`),(null==i?void 0:i.rtcpMux)&&e.push("a=rtcp-mux\r\n"),(null==i?void 0:i.rtcpRsize)&&e.push("a=rtcp-rsize\r\n"),null===(p=null==i?void 0:i.codecs)||void 0===p||p.forEach((i=>{var t,n;const a=o.getCodecID(i),l=o.getCodecName(i);if(l&&e.push(`a=rtpmap:${a} ${l}\r\n`),null===(t=null==i?void 0:i.rtcpFeedbackIds)||void 0===t||t.forEach((i=>{const t=o.RTCP_FEEDBACK_ID_TO_STRING.get(i);t&&e.push(`a=rtcp-fb:${a} ${t}\r\n`)})),(null===(n=null==i?void 0:i.fmtp)||void 0===n?void 0:n.length)>0){const t=o.reconstructFmtp(i.fmtp);e.push(`a=fmtp:${a} ${t}\r\n`)}})),null===(h=null==i?void 0:i.ssrcGroups)||void 0===h||h.forEach((i=>{const t=i.ssrcs.map((e=>(e>>>0).toString())).join(" ");e.push(`a=ssrc-group:${i.semantics} ${t}\r\n`)})),null===(g=null==i?void 0:i.ssrcs)||void 0===g||g.forEach((i=>{var t,n;const a=(i.id>>>0).toString();(null===(t=null==i?void 0:i.cname)||void 0===t?void 0:t.length)>0&&e.push(`a=ssrc:${a} cname:${i.cname}\r\n`),(null===(n=null==i?void 0:i.msid)||void 0===n?void 0:n.length)>0&&e.push(`a=ssrc:${a} msid:${i.msid}\r\n`)})),null===(v=null==i?void 0:i.candidates)||void 0===v||v.forEach((i=>{e.push(`a=candidate:${o.reconstructCandidate(i)}\r\n`)})),(null==i?void 0:i.endOfCandidates)&&e.push("a=end-of-candidates\r\n")}static reconstructMSID(e,i,t){return 0===e.length?"":0===i.length&&0===t?e:t>0&&i.length>0?`${e} ${i}${t}`:i.length>0?`${e} ${i}`:e}static reconstructFmtp(e){return e.map((e=>"value"===e.key?e.value:`${e.key}=${e.value}`)).join(";")}static fingerprintToString(e){let i;switch(e.hashFunc){case l.HashFunction.SHA256:i="sha-256";break;case l.HashFunction.SHA1:i="sha-1";break;case l.HashFunction.SHA384:i="sha-384";break;case l.HashFunction.SHA512:i="sha-512";break;case l.HashFunction.MD5:i="md5"}return`${i} ${Array.from(e.hashValue).map((e=>e.toString(16).padStart(2,"0").toUpperCase())).join(":")}`}static setupToString(e){switch(e){case l.DTLSSetup.ACTIVE:return"active";case l.DTLSSetup.PASSIVE:return"passive";case l.DTLSSetup.ACTPASS:return"actpass"}}static directionToString(e){switch(e){case l.MediaDirection.SENDONLY:return"sendonly";case l.MediaDirection.RECVONLY:return"recvonly";case l.MediaDirection.INACTIVE:return"inactive";default:return"sendrecv"}}static reconstructCandidate(e){const i=e.protocol===l.IceCandidateProtocol.UDP?"udp":"tcp";let t;switch(e.type){case l.IceCandidateType.HOST:t="host";break;case l.IceCandidateType.SRFLX:t="srflx";break;case l.IceCandidateType.PRFLX:t="prflx";break;case l.IceCandidateType.RELAY:t="relay"}const n=[e.foundation.toString(),e.component.toString(),i,e.priority.toString(),Array.from(e.ip).map((e=>(255&e).toString())).join("."),e.port.toString(),"typ",t];if(e.raddr.length>0){n.push("raddr");const i=Array.from(e.raddr).map((e=>(255&e).toString())).join(".");n.push(i)}if(e.rport>0&&(n.push("rport"),n.push(e.rport.toString())),"tcp"===i){let i;switch(e.tcptype){case l.IceCandidateTcpType.ACTIVE:i="active";break;case l.IceCandidateTcpType.PASSIVE:i="passive";break;case l.IceCandidateTcpType.SO:i="so"}n.push("tcptype"),n.push(i)}return n.join(" ")}}i.SdpConverter=o,o.EXTMAP_ID_TO_URI=new Map([[1,"urn:ietf:params:rtp-hdrext:toffset"],[2,"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"],[3,"urn:3gpp:video-orientation"],[4,"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"],[5,"http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"],[6,"http://www.webrtc.org/experiments/rtp-hdrext/video-content-type"],[7,"http://www.webrtc.org/experiments/rtp-hdrext/video-timing"],[8,"http://www.webrtc.org/experiments/rtp-hdrext/color-space"],[9,"urn:ietf:params:rtp-hdrext:sdes:mid"],[10,"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"],[11,"urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"],[14,"urn:ietf:params:rtp-hdrext:ssrc-audio-level"],[15,"urn:ietf:params:rtp-hdrext:csrc-audio-level"]]),o.URI_TO_EXTMAP_ID=new Map(Array.from(o.EXTMAP_ID_TO_URI.entries()).map((([e,i])=>[i,e]))),o.RTCP_FEEDBACK_ID_TO_STRING=new Map([[1,"goog-remb"],[2,"transport-cc"],[3,"ccm fir"],[4,"nack"],[5,"nack pli"]]),o.RTCP_FEEDBACK_STRING_TO_ID=new Map(Array.from(o.RTCP_FEEDBACK_ID_TO_STRING.entries()).map((([e,i])=>[i,e]))),o.dynamicCodecNames=new Map,o.CODEC_NAME_TO_MAP_KEY=new Map([["VP8/90000",1],["VP9/90000",2],["AV1/90000",3],["H264/90000",4],["H265/90000",5],["rtx/90000",6],["red/90000",7],["ulpfec/90000",8],["opus/48000/2",9],["red/48000/2",10],["G722/8000",11],["G722/8000/1",11],["PCMU/8000",12],["PCMA/8000",13],["CN/8000",14],["telephone-event/48000",15],["telephone-event/8000",16],["telephone-event/8000/1",16],["ILBC/8000",17]]),o.MAP_KEY_TO_CODEC_NAME=new Map([[1,"VP8/90000"],[2,"VP9/90000"],[3,"AV1/90000"],[4,"H264/90000"],[5,"H265/90000"],[6,"rtx/90000"],[7,"red/90000"],[8,"ulpfec/90000"],[9,"opus/48000/2"],[10,"red/48000/2"],[11,"G722/8000"],[12,"PCMU/8000"],[13,"PCMA/8000"],[14,"CN/8000"],[15,"telephone-event/48000"],[16,"telephone-event/8000"],[17,"ILBC/8000"]])},799:(e,i)=>{"use strict";var t,n,a,l,s,o,r;Object.defineProperty(i,"__esModule",{value:!0}),i.IceCandidateTcpType=i.IceCandidateType=i.IceCandidateProtocol=i.MediaDirection=i.MediaType=i.DTLSSetup=i.HashFunction=void 0,function(e){e[e.SHA256=0]="SHA256",e[e.SHA1=1]="SHA1",e[e.SHA384=2]="SHA384",e[e.SHA512=3]="SHA512",e[e.MD5=4]="MD5"}(t||(i.HashFunction=t={})),function(e){e[e.ACTIVE=0]="ACTIVE",e[e.PASSIVE=1]="PASSIVE",e[e.ACTPASS=2]="ACTPASS"}(n||(i.DTLSSetup=n={})),function(e){e[e.AUDIO=0]="AUDIO",e[e.VIDEO=1]="VIDEO",e[e.MEDIA_TYPE_UNSPECIFIED=2]="MEDIA_TYPE_UNSPECIFIED"}(a||(i.MediaType=a={})),function(e){e[e.SENDRECV=0]="SENDRECV",e[e.SENDONLY=1]="SENDONLY",e[e.RECVONLY=2]="RECVONLY",e[e.INACTIVE=3]="INACTIVE"}(l||(i.MediaDirection=l={})),function(e){e[e.UDP=0]="UDP",e[e.TCP=1]="TCP"}(s||(i.IceCandidateProtocol=s={})),function(e){e[e.HOST=0]="HOST",e[e.SRFLX=1]="SRFLX",e[e.PRFLX=2]="PRFLX",e[e.RELAY=3]="RELAY"}(o||(i.IceCandidateType=o={})),function(e){e[e.ACTIVE=0]="ACTIVE",e[e.PASSIVE=1]="PASSIVE",e[e.SO=2]="SO"}(r||(i.IceCandidateTcpType=r={}))},828:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.QueuedSignal=void 0;const n=t(795),a=t(429);i.QueuedSignal=class{constructor(e,i,t=n.SignalQueueStrategy.getSignalPriority(e),l=Date.now(),s=0,o=(0,a.v4)()){this.signal=e,this.callback=i,this.priority=t,this.timestamp=l,this.requeueCount=s,this.uniqueKey=o}get callId(){return this.signal.callId}compareTo(e){const i=e.priority-this.priority;return 0!==i?i:this.timestamp-e.timestamp}toString(){return`QueuedSignal(signal=${JSON.stringify(this.signal)}, timestamp=${this.timestamp}, priority=${this.priority}, requeueCount=${this.requeueCount}, uniqueKey=${this.uniqueKey})`}}},795:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SignalQueueStrategy=i.SignalProcessingStrategy=void 0;const n=t(578),a=t(586),l=t(228);var s;!function(e){e[e.SEQUENTIAL=0]="SEQUENTIAL",e[e.IMMEDIATE=1]="IMMEDIATE"}(s||(i.SignalProcessingStrategy=s={}));class o{static getProcessingStrategy(e){return this.SEQUENTIAL_SIGNALS.has(e)?s.SEQUENTIAL:s.IMMEDIATE}static isSequentialSignal(e){return this.getProcessingStrategy(e)===s.SEQUENTIAL}static isImmediateSignal(e){return this.getProcessingStrategy(e)===s.IMMEDIATE}static getSignalPriorityValue(e){switch(e){case n.SignalEvent.JOIN:return 10;case n.SignalEvent.LEAVE:case n.SignalEvent.DECLINE:return 9;case n.SignalEvent.MEDIA_CONNECTED:return 8;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:case n.SignalEvent.CONNECT:case n.SignalEvent.ICE:return 7;case n.SignalEvent.KICK:case n.SignalEvent.INVITE:case n.SignalEvent.RINGING:case n.SignalEvent.INFO:case n.SignalEvent.UPDATE:case n.SignalEvent.GET_CALL:case n.SignalEvent.SWITCH_MEDIA_FLOW:return 6;case n.SignalEvent.MUTE:case n.SignalEvent.UNMUTE:case n.SignalEvent.VIDEO_ON:case n.SignalEvent.VIDEO_OFF:case n.SignalEvent.HOLD:case n.SignalEvent.UNHOLD:case n.SignalEvent.SCREEN_SHARE_ON:case n.SignalEvent.SCREEN_SHARE_OFF:case n.SignalEvent.DISABLE_REMOTE_AUDIO:case n.SignalEvent.DISABLE_REMOTE_VIDEO:case n.SignalEvent.CALL_PERMISSIONS_UPDATE:case n.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE:return 5;case n.SignalEvent.ERROR:case n.SignalEvent.SUCCESS:case n.SignalEvent.CLOSE:case n.SignalEvent.NO_ANSWER:throw(0,l.checkCode)(4e3,`SignalEvent ${e} should not be in queue`);default:return 0}}static getSignalPriority(e){if("number"!=typeof e.event)throw(0,l.checkCode)(4e3,`Signal event is not a number for signal: ${JSON.stringify(e)}`);return this.getSignalPriorityValue(e.event)}static getSignalLevel(e){switch(e.event){case n.SignalEvent.JOIN:case n.SignalEvent.LEAVE:case n.SignalEvent.DECLINE:return a.SignalLevel.GlobalBlocking;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:case n.SignalEvent.ICE:case n.SignalEvent.CONNECT:return a.SignalLevel.ParticipantLevel;default:return a.SignalLevel.Immediate}}}i.SignalQueueStrategy=o,o.SEQUENTIAL_SIGNALS=new Set([n.SignalEvent.JOIN,n.SignalEvent.LEAVE,n.SignalEvent.DECLINE,n.SignalEvent.OFFER,n.SignalEvent.ANSWER,n.SignalEvent.CONNECT])},586:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.SignalingQueue=i.SignalLevel=void 0;const a=t(795),l=t(645),s=t(578),o=(0,l.createLogger)("SignalingQueue");var r;!function(e){e[e.GlobalBlocking=0]="GlobalBlocking",e[e.ParticipantLevel=1]="ParticipantLevel",e[e.Immediate=2]="Immediate"}(r||(i.SignalLevel=r={})),i.SignalingQueue=class{constructor(e,i,t){this.id=e,this.isTransportConnected=i,this.sender=t,this.globalBlockingSignals=[],this.immediateSignals=[],this.participantSignals=new Map,this.processingSignalJobs=new Map,this.participantJobs=new Map,this.sentSignals=new Set}getSignalKey(e,i){return`${i}_${e.event}_${e.callId}_${e.sessionId||""}`}addSignalToQueue(e){const i=this.getSignalKey(e.signal,e.uniqueKey);if(this.sentSignals.has(i))return void o.info(`[38] [CallId: ${e.signal.callId}] Signal already sent, skipping: ${s.SignalEvent[e.signal.event]}`);const t=a.SignalQueueStrategy.getSignalLevel(e.signal);switch(t){case r.GlobalBlocking:this.globalBlockingSignals.push(e);break;case r.ParticipantLevel:const i=e.signal.to||"";this.participantSignals.has(i)||this.participantSignals.set(i,[]),this.participantSignals.get(i).push(e);break;case r.Immediate:this.immediateSignals.push(e)}o.info(`[61] [CallId: ${e.signal.callId}] Add signal to queue ===> level: ${t}, signal Event: ${s.SignalEvent[e.signal.event]}, uniqueKey: ${e.uniqueKey}`),this.invalidateToSendSignalsIfNeeded()}removeSignalFromQueue(e){const i=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.delete(i)}invalidateToSendSignalsIfNeeded(){this.isTransportConnected()?this.globalBlockingSignals.length>0?this.sendGlobalBlockingSignals():(this.sendParticipantSignals(),this.sendImmediateLevelSignals()):o.info(`[75] [CallId: ${this.id}] Connection is not established, skipping signal processing`)}triggerSignalProcessing(){this.invalidateToSendSignalsIfNeeded()}sendGlobalBlockingSignals(){return n(this,void 0,void 0,(function*(){if(!this.processingSignalJobs.get(r.GlobalBlocking)){this.processingSignalJobs.set(r.GlobalBlocking,!0);try{for(;this.isTransportConnected();){const e=this.globalBlockingSignals.shift();if(!e)break;const i=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.has(i)?o.info(`[107] [CallId: ${this.id}] Global blocking signal already sent, skipping: ${s.SignalEvent[e.signal.event]}`):(o.info(`[111] [CallId: ${this.id}] Sending ${r.GlobalBlocking} level signal: ${s.SignalEvent[e.signal.event]}`),yield this.sendSignal(e),this.sentSignals.add(i))}}finally{this.processingSignalJobs.delete(r.GlobalBlocking),0===this.globalBlockingSignals.length&&(this.sendParticipantSignals(),this.sendImmediateLevelSignals())}}}))}sendImmediateLevelSignals(){return n(this,void 0,void 0,(function*(){if(!(this.globalBlockingSignals.length>0||this.processingSignalJobs.get(r.Immediate))){this.processingSignalJobs.set(r.Immediate,!0);try{for(;this.isTransportConnected()&&0===this.globalBlockingSignals.length;){const e=this.immediateSignals.shift();if(!e)break;const i=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.has(i)?o.info(`[145] [CallId: ${this.id}] Immediate signal already sent, skipping: ${s.SignalEvent[e.signal.event]}`):(o.info(`[148] [CallId: ${this.id}] Sending ${r.Immediate} level signal: ${s.SignalEvent[e.signal.event]}`),yield this.sendSignal(e),this.sentSignals.add(i))}}finally{this.processingSignalJobs.delete(r.Immediate)}}}))}sendParticipantSignals(){if(!(this.globalBlockingSignals.length>0))for(const[e,i]of this.participantSignals.entries())i.length>0&&this.sendParticipantSignal(e,i)}sendParticipantSignal(e,i){return n(this,void 0,void 0,(function*(){if(!this.participantJobs.get(e)){this.participantJobs.set(e,!0);try{for(;this.isTransportConnected()&&0===this.globalBlockingSignals.length;){const t=i.shift();if(!t)break;const n=this.getSignalKey(t.signal,t.uniqueKey);this.sentSignals.has(n)?o.info(`[185] [CallId: ${this.id}] Participant signal already sent, skipping: ${s.SignalEvent[t.signal.event]}`):(o.info(`[188] [CallId: ${this.id}] Sending ${r.ParticipantLevel} level signal for identity ${e}: ${s.SignalEvent[t.signal.event]}`),yield this.sendSignal(t),this.sentSignals.add(n))}}finally{this.participantJobs.delete(e),0===i.length&&this.participantSignals.delete(e)}}}))}sendSignal(e){return n(this,void 0,void 0,(function*(){a.SignalQueueStrategy.getProcessingStrategy(e.signal.event)===a.SignalProcessingStrategy.SEQUENTIAL?yield this.sender(e):this.sender(e).catch((e=>{o.error(`[209] [CallId: ${this.id}] Error sending signal: ${e}`)}))}))}clearParticipantSignals(e){this.participantSignals.delete(e),this.participantJobs.delete(e),o.info(`[213] [CallId: ${this.id}] Cleared participant signals for identity: ${e}, queueId: ${this.id}`)}clearCallSignals(){this.globalBlockingSignals=[],this.immediateSignals=[],this.participantSignals.clear(),this.processingSignalJobs.clear(),this.participantJobs.clear(),this.sentSignals.clear(),o.info(`[227] [CallId: ${this.id}] Cleared all signals for queueId: ${this.id}`)}getGlobalBlockingSignals(){return this.globalBlockingSignals}}},786:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.Signaling=void 0;const a=t(578),l=t(645),s=t(828),o=t(586),r=t(228),d=t(65),c=t(429),u=(0,l.createLogger)("Signaling");class p{constructor(e,i){this.signalingQueues=new Map,this.chatClient=e;const t=new this.chatClient.ChannelListener;t.onSignal=e=>{i(e)},this.chatClient.addChannelListener("call_listeners",t)}calculateRetryDelay(e){return Math.min(p.BASE_DELAY_MS*Math.pow(2,e),p.MAX_DELAY_MS)}handleRetry(e,i,t,a){var l;return n(this,void 0,void 0,(function*(){if(i>=p.MAX_RETRIES)throw u.error(`[45] [CallId: ${e.signal.callId}] Max retries exceeded for signal: ${JSON.stringify(e.signal)}`,{color:"red"}),(0,r.toCallException)(t);t instanceof d.SceytCallException&&!t.isResendable&&(u.error(`[49] [CallId: ${e.signal.callId}] Signal sending failed with non-resendable exception: ${t.message}`,{color:"red"}),null===(l=e.callback)||void 0===l||l.call(e,t),a.removeSignalFromQueue(e));const n=this.calculateRetryDelay(i);u.error(`[53] [CallId: ${e.signal.callId}] Sending signal failed with error: ${t.message}, but ChatClient is connected. Retrying in ${n}ms (attempt ${i+1}/${p.MAX_RETRIES})`,{color:"red"}),yield new Promise((e=>setTimeout(e,n)));try{const i=yield this.sendSignalSuspended(e);return u.info(`[64] [CallId: ${e.signal.callId}] Retry sending signal success: ${JSON.stringify(i)}`),i}catch(t){return u.error(`[67] [CallId: ${e.signal.callId}] Retry sending signal failed: ${t instanceof Error?t.message:String(t)}`),this.handleRetry(e,i+1,t instanceof Error?t:new Error(String(t)),a)}}))}sendSignalSuspended(e){return n(this,void 0,void 0,(function*(){try{u.info(`[78] [CallId: ${e.signal.callId}] Sending signal ${a.SignalEvent[e.signal.event]} to chat client: version: 132`);const i=yield this.chatClient.sendSignal(e.signal,132);if(null==i?void 0:i.error)throw(0,r.toCallException)(i.error);return(0,r.handleAck)(i)}catch(e){throw(0,r.toCallException)(e)}}))}sendSignalMessage(e,i,t){var l,h,g,v,S,f,C;const I=Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({mediaFlow:e.mediaFlow,callId:e.callId},e.sessionId&&{sessionId:e.sessionId}),{event:e.event}),e.sessionData&&{sessionData:e.sessionData}),e.to&&{to:e.to}),{participants:e.participants?e.participants:[]}),e.ice&&{ice:e.ice}),e.metadata?{metadata:e.metadata}:{metadata:{}}),e.callOptions&&{callOptions:Object.assign(Object.assign({},e.callOptions||{}),{settings:Object.assign(Object.assign({},(null===(l=null==e?void 0:e.callOptions)||void 0===l?void 0:l.settings)||{}),{permissions:{audioPublishingDisabled:!(null===(v=null===(g=null===(h=null==e?void 0:e.callOptions)||void 0===h?void 0:h.settings)||void 0===g?void 0:g.permissions)||void 0===v?void 0:v.allowPublishAudio),videoPublishingDisabled:!(null===(C=null===(f=null===(S=null==e?void 0:e.callOptions)||void 0===S?void 0:S.settings)||void 0===f?void 0:f.permissions)||void 0===C?void 0:C.allowPublishVideo)}})})}),e.joinOptions&&{joinOptions:e.joinOptions}),e.broadcastUsers&&{broadcastUsers:e.broadcastUsers});u.info(`[92] [CallId: ${e.callId}] Sending signal message request: ${a.SignalEvent[e.event]} uniqueKey: ${(0,c.v4)()} ${JSON.stringify(I)}`,{color:"yellow"});const m=t||e.callId;let E=this.signalingQueues.get(m);E||(E=new o.SignalingQueue(m,(()=>"Connected"===this.chatClient.connectionState),(e=>n(this,void 0,void 0,(function*(){var i,t,n,l,o,h,g,v,S,f,C,I,m,P,b;try{const s=yield this.sendSignalSuspended(e),d=Object.assign(Object.assign({},s),{callOptions:Object.assign(Object.assign({},s.callOptions||{}),{settings:Object.assign(Object.assign({},(null===(i=null==s?void 0:s.callOptions)||void 0===i?void 0:i.settings)||{}),{permissions:Object.assign(Object.assign({},(null===(n=null===(t=null==s?void 0:s.callOptions)||void 0===t?void 0:t.settings)||void 0===n?void 0:n.permissions)||{}),{allowPublishAudio:!(null===(h=null===(o=null===(l=null==s?void 0:s.callOptions)||void 0===l?void 0:l.settings)||void 0===o?void 0:o.permissions)||void 0===h?void 0:h.audioPublishingDisabled),allowPublishVideo:!(null===(S=null===(v=null===(g=null==s?void 0:s.callOptions)||void 0===g?void 0:g.settings)||void 0===v?void 0:v.permissions)||void 0===S?void 0:S.videoPublishingDisabled)})})}),calls:null===(f=null==s?void 0:s.calls)||void 0===f?void 0:f.map((e=>{var i,t,n,a,l,s,o;return Object.assign(Object.assign({},e),{options:Object.assign(Object.assign({},(null==e?void 0:e.options)||{}),{settings:Object.assign(Object.assign({},(null===(i=null==e?void 0:e.options)||void 0===i?void 0:i.settings)||{}),{permissions:{allowPublishAudio:!(null===(a=null===(n=null===(t=null==e?void 0:e.options)||void 0===t?void 0:t.settings)||void 0===n?void 0:n.permissions)||void 0===a?void 0:a.audioPublishingDisabled),allowPublishVideo:!(null===(o=null===(s=null===(l=null==e?void 0:e.options)||void 0===l?void 0:l.settings)||void 0===s?void 0:s.permissions)||void 0===o?void 0:o.videoPublishingDisabled)}})})})}))});if(u.info(`[115] [CallId: ${e.signal.callId||"GLOBAL_LOGS"}] Sent signal message response: ${a.SignalEvent[e.signal.event]} uniqueKey: ${e.uniqueKey} ${JSON.stringify(d)}`,{color:"magenta"}),(null==s?void 0:s.event)===a.SignalEvent.ERROR)throw(0,r.checkCode)((null===(C=null==s?void 0:s.error)||void 0===C?void 0:C.code)||0,(null===(I=null==s?void 0:s.error)||void 0===I?void 0:I.message)||"Unknown error");return null===(m=e.callback)||void 0===m||m.call(e,d),null==E||E.removeSignalFromQueue(e),s}catch(i){if(u.error(`[125] [CallId: ${e.signal.callId||"GLOBAL_LOGS"}] Signal message error: ${a.SignalEvent[e.signal.event]} uniqueKey: ${e.uniqueKey} error: ${i instanceof Error?i.message:String(i)}, resendable: ${i instanceof d.SceytCallException&&i.isResendable}`,{color:"red"}),i instanceof d.SceytCallException&&i.isResendable){const t=e.requeueCount;t<p.REQUEUE_LIMIT?null==E||E.addSignalToQueue(new s.QueuedSignal(e.signal,e.callback,e.priority,e.timestamp,t+1,(0,c.v4)())):(u.error(`[140] [CallId: ${e.signal.callId||"GLOBAL_LOGS"}] Max requeue limit reached for signal: ${JSON.stringify(e.signal)}, will not requeue again. uniqueKey: ${e.uniqueKey}`,{color:"red"}),null===(P=e.callback)||void 0===P||P.call(e,i),null==E||E.removeSignalFromQueue(e))}const t=i instanceof d.SceytCallException?i:new Error(i instanceof Error?i.message:String(i));null===(b=e.callback)||void 0===b||b.call(e,t),null==E||E.removeSignalFromQueue(e)}})))),this.signalingQueues.set(m,E)),E.addSignalToQueue(new s.QueuedSignal(I,i,0,0,0,(0,c.v4)()))}clearCallSignals(e){const i=this.signalingQueues.get(e);i&&(i.clearCallSignals(),this.signalingQueues.delete(e))}clearParticipantSignals(e,i){const t=this.signalingQueues.get(e);t&&t.clearParticipantSignals(i)}cancelJoinIfPossible(e){const i=this.signalingQueues.get(e);return!!i&&!!i.getGlobalBlockingSignals().find((e=>e.signal.event==a.SignalEvent.JOIN))&&(i.clearCallSignals(),!0)}}i.Signaling=p,p.REQUEUE_LIMIT=10,p.MAX_RETRIES=10,p.BASE_DELAY_MS=1e3,p.MAX_DELAY_MS=8e3},342:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ReceiveSignalValidator=void 0;const n=t(578),a=(0,t(645).createLogger)("ReceiveSignalValidator");class l{static canHandleSignal(e,i){const t=l.validateSignal(e,i.state,i.localParticipant);return t||a.warn(`Cannot handle signal ${e.event} in call state ${i.state} with local participant state ${i.localParticipant.state}`),t}static validateSignal(e,i,t){switch(e.event){case n.SignalEvent.JOIN:case n.SignalEvent.LEAVE:return!0;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:return i===n.CallState.Connected;case n.SignalEvent.KICK:return!0;case n.SignalEvent.INVITE:return!e.participants||!e.participants.some((e=>e.id===t.id))||i===n.CallState.Idle;case n.SignalEvent.DECLINE:case n.SignalEvent.RINGING:case n.SignalEvent.INFO:case n.SignalEvent.UPDATE:case n.SignalEvent.CLOSE:return!0;case n.SignalEvent.ICE:return i===n.CallState.Connected;case n.SignalEvent.SWITCH_MEDIA_FLOW:case n.SignalEvent.NO_ANSWER:case n.SignalEvent.MUTE:case n.SignalEvent.UNMUTE:case n.SignalEvent.HOLD:case n.SignalEvent.UNHOLD:case n.SignalEvent.VIDEO_ON:case n.SignalEvent.VIDEO_OFF:case n.SignalEvent.SCREEN_SHARE_ON:case n.SignalEvent.SCREEN_SHARE_OFF:case n.SignalEvent.DISABLE_REMOTE_AUDIO:case n.SignalEvent.DISABLE_REMOTE_VIDEO:case n.SignalEvent.CALL_PERMISSIONS_UPDATE:case n.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE:case n.SignalEvent.MEDIA_CONNECTED:case n.SignalEvent.CONNECT:case n.SignalEvent.GET_CALL:return!0;default:return a.warn(`Unknown signal event for handling: ${e.event}`),!1}}}i.ReceiveSignalValidator=l},771:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.SendSignalValidator=void 0;const n=t(578),a=(0,t(645).createLogger)("SendSignalValidator");class l{canSendSignal(e,i){const t=l.validateSignalEvent(e.event,i.state);return t||a.warn(`Cannot send signal ${e.event} in call state ${i.state} with local participant state ${i.localParticipant.state}`),t}canSendSignalEvent(e,i){const t=l.validateSignalEvent(e,i.state);return t||a.warn(`Cannot send signal ${e} in call state ${i.state} with local participant state ${i.localParticipant.state}`),t}static validateSignalEvent(e,i){const t=i===n.CallState.Connected;switch(e){case n.SignalEvent.JOIN:return!0;case n.SignalEvent.LEAVE:return t;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:case n.SignalEvent.CONNECT:case n.SignalEvent.KICK:case n.SignalEvent.INVITE:return i===n.CallState.Connected;case n.SignalEvent.DECLINE:return i===n.CallState.Idle;case n.SignalEvent.RINGING:return i===n.CallState.Idle||i===n.CallState.Connecting;case n.SignalEvent.INFO:case n.SignalEvent.UPDATE:return i===n.CallState.Connected;case n.SignalEvent.ICE:case n.SignalEvent.GET_CALL:return!0;case n.SignalEvent.SWITCH_MEDIA_FLOW:case n.SignalEvent.MEDIA_CONNECTED:return i===n.CallState.Connected;case n.SignalEvent.MUTE:case n.SignalEvent.UNMUTE:case n.SignalEvent.HOLD:case n.SignalEvent.UNHOLD:case n.SignalEvent.VIDEO_ON:case n.SignalEvent.VIDEO_OFF:case n.SignalEvent.DISABLE_REMOTE_AUDIO:case n.SignalEvent.DISABLE_REMOTE_VIDEO:case n.SignalEvent.CALL_PERMISSIONS_UPDATE:case n.SignalEvent.PARTICIPANT_PERMISSIONS_UPDATE:return t;case n.SignalEvent.SCREEN_SHARE_ON:case n.SignalEvent.SCREEN_SHARE_OFF:return i===n.CallState.Connected;default:return a.warn(`Unknown signal event for sending: ${e}`),!1}}}i.SendSignalValidator=l},302:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.ReceiveSignalValidator=i.SendSignalValidator=void 0;var n=t(771);Object.defineProperty(i,"SendSignalValidator",{enumerable:!0,get:function(){return n.SendSignalValidator}});var a=t(342);Object.defineProperty(i,"ReceiveSignalValidator",{enumerable:!0,get:function(){return a.ReceiveSignalValidator}})},740:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.VideoTrack=void 0,i.VideoTrack=class{constructor(e){this._enabled=!0,this.id=e.id,this.videoTrack=e}set enabled(e){this._enabled=e,this.videoTrack.enabled=e}get enabled(){return this._enabled}}},546:function(e,i,t){"use strict";var n=this&&this.__awaiter||function(e,i,t,n){return new(t||(t=Promise))((function(a,l){function s(e){try{r(n.next(e))}catch(e){l(e)}}function o(e){try{r(n.throw(e))}catch(e){l(e)}}function r(e){var i;e.done?a(e.value):(i=e.value,i instanceof t?i:new t((function(e){e(i)}))).then(s,o)}r((n=n.apply(e,i||[])).next())}))};Object.defineProperty(i,"__esModule",{value:!0}),i.WebRTCClient=void 0;const a=t(578),l=t(645),s=t(19),o=t(680),r=(0,l.createLogger)("WebRTCClient");i.WebRTCClient=class{constructor(e,i){this.listeners={},this.sessionId=null,this.version=null,this.iceQueueMap={},this.configuration=i,this.peerConnection=new RTCPeerConnection(this.configuration),this.callId=e}setSessionId(e){this.sessionId=e}getSessionId(){return this.sessionId||""}setVersion(e){this.version=e}getVersion(){return this.version||""}setListeners(e){r.info(`[18] [CallId: ${this.callId}] setListeners in webrtcClient: listeners`,{color:"blue"}),this.listeners=e}setConfiguration(e){r.info(`[21] [CallId: ${this.callId}] setConfiguration in webrtcClient: configuration: ${e}`,{color:"blue"}),this.configuration=e}getPreferredAudioCodecs(e){const i=RTCRtpReceiver.getCapabilities("audio");return i?i.codecs.filter((i=>{const t=i.mimeType.split("/")[1].toLowerCase();return e===a.MediaFlow.S2W?s.CODEC_NAME_TO_AUDIO_CODEC_S2W.includes(t):s.CODEC_NAME_TO_AUDIO_CODEC.includes(t)})):[]}getPreferredVideoCodecs(){const e=RTCRtpSender.getCapabilities("video");if(!e)return[];const i=[];return s.CODEC_NAME_TO_VIDEO_CODEC.forEach((t=>{const n=e.codecs.find((e=>e.mimeType.split("/")[1].toLowerCase()===t.toLowerCase()));n&&i.push(n)})),i}setPreferredCodecs(e,i,t){if("video"===i){r.info(`[74] [CallId: ${this.callId}] setPreferredCodecs: video, mediaFlow: ${e}`,{color:"blue"});const i=this.getPreferredVideoCodecs(),n=[];i.forEach((e=>{n.push({mimeType:e.mimeType,clockRate:e.clockRate,sdpFmtpLine:e.sdpFmtpLine,channels:e.channels})})),t.setCodecPreferences(n)}else if("audio"===i){r.info(`[88] [CallId: ${this.callId}] setPreferredCodecs: audio, mediaFlow: ${e}`,{color:"blue"});const i=this.getPreferredAudioCodecs(e),n=[];i.forEach((e=>{n.push({mimeType:e.mimeType,clockRate:e.clockRate,sdpFmtpLine:e.sdpFmtpLine||"",channels:e.channels||void 0})})),t.setCodecPreferences(n)}}addTransceiverToPeerConnection(e,i){return n(this,void 0,void 0,(function*(){r.info(`[56] [CallId: ${this.callId}] addTransceiverToPeerConnection in webrtcClient: track: ${null==e?void 0:e.kind}`,{color:"blue"}),this.peerConnection.addTransceiver(e,{direction:"sendrecv"});const t=this.peerConnection.getTransceivers().find((i=>{var t;return(null===(t=i.receiver.track)||void 0===t?void 0:t.kind)===(null==e?void 0:e.kind)}));if(t&&"video"===(null==e?void 0:e.kind)){this.setPreferredCodecs(i,"video",t);try{const e=t.sender.getParameters();e.encodings&&e.encodings.length>0&&(e.encodings.forEach((e=>{e.maxBitrate=5e5})),yield t.sender.setParameters(e),r.info(`[57] [CallId: ${this.callId}] addTransceiverToPeerConnection: Set video max bitrate to 500 kbps`,{color:"blue"}))}catch(e){r.warn(`[58] [CallId: ${this.callId}] addTransceiverToPeerConnection: Failed to set video bitrate: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"yellow"})}}else t&&"audio"===(null==e?void 0:e.kind)&&this.setPreferredCodecs(i,"audio",t)}))}setStreamsToTransceiver(e){var i,t;return n(this,void 0,void 0,(function*(){r.info(`[61] [CallId: ${this.callId}] setStreamsToTransceiver in webrtcClient: track: ${null==e?void 0:e.kind}`,{color:"blue"});const n=this.peerConnection.getTransceivers();r.info(`[62] [CallId: ${this.callId}] setStreamsToTransceiver: transceivers: ${n.length}`,{color:"blue"});const a=null==e?void 0:e.kind;let l=n.find((e=>{var i,t;const n=null===(i=e.receiver.track)||void 0===i?void 0:i.kind,l=null===(t=e.sender.track)||void 0===t?void 0:t.kind;return n===a||l===a}));if(r.info(`[63] [CallId: ${this.callId}] setStreamsToTransceiver: transceiver found: ${!!l}, receiver track: ${null===(i=null==l?void 0:l.receiver.track)||void 0===i?void 0:i.kind}, sender track: ${null===(t=null==l?void 0:l.sender.track)||void 0===t?void 0:t.kind}, current direction: ${null==l?void 0:l.direction}, mid: ${null==l?void 0:l.mid}`,{color:"blue"}),l){if(null!==l.sender.track)return void r.info(`[64] [CallId: ${this.callId}] setStreamsToTransceiver: Track already attached, skipping to avoid renegotiation`,{color:"blue"});e&&(e.enabled=!0),l.direction="sendrecv",yield l.sender.replaceTrack(e);const i=l.direction,t=l.sender.track,n=t?t.kind:"null";r.info(`[65] [CallId: ${this.callId}] setStreamsToTransceiver: Attached local ${a} track to transceiver, direction: ${i}, sender track: ${n}, track enabled: ${null==e?void 0:e.enabled}, track id: ${null==e?void 0:e.id}`,{color:"blue"}),t||r.error(`[66] [CallId: ${this.callId}] setStreamsToTransceiver: Failed to attach ${a} track - sender track is still null after replaceTrack`,{color:"red"})}else{const e=n.map((e=>{var i,t;return{mid:e.mid,receiverKind:(null===(i=e.receiver.track)||void 0===i?void 0:i.kind)||"null",senderKind:(null===(t=e.sender.track)||void 0===t?void 0:t.kind)||"null",direction:e.direction}}));r.warn(`[67] [CallId: ${this.callId}] setStreamsToTransceiver: No transceiver found for track kind: ${a}. Available transceivers: ${JSON.stringify(e)}`,{color:"yellow"})}}))}enableVideoOnPeerConnection(e,i,t=!1){return n(this,void 0,void 0,(function*(){r.info(`[27] [CallId: ${this.callId}] enableVideoOnPeerConnection in webrtcClient: enable: ${e}, kind: ${null==i?void 0:i.kind}`,{color:"blue"});const n=this.peerConnection.getTransceivers();for(let a=0;a<n.length;a++){const l=n[a];if(l.sender.track&&"video"===l.sender.track.kind){i?(i.enabled=e,yield l.sender.replaceTrack(i)):l.sender.track.enabled=e;const n=l.sender.getParameters();n.encodings&&n.encodings.length>0&&(n.encodings.forEach((e=>{e.maxBitrate=t?75e4:5e5})),yield l.sender.setParameters(n),r.info(`[184] [CallId: ${this.callId}] enableVideoOnPeerConnection: Set video max bitrate to ${t?75e4:5e5} kbps`,{color:"blue"}))}}}))}enableAudioOnPeerConnection(e,i){return n(this,void 0,void 0,(function*(){r.info(`[33] [CallId: ${this.callId}] enableAudioOnPeerConnection in webrtcClient: mute: ${e}, kind: ${null==i?void 0:i.kind}`,{color:"blue"});const t=this.peerConnection.getTransceivers();for(let n=0;n<t.length;n++){const a=t[n];a.sender.track&&"audio"===a.sender.track.kind&&(i?(i.enabled=!e,yield a.sender.replaceTrack(i)):a.sender.track.enabled=!e)}}))}createOffer(e,i,t){return n(this,void 0,void 0,(function*(){try{r.info(`[36] [CallId: ${this.callId}] createOffer in webrtcClient`,{color:"blue"});const n=yield this.peerConnection.createOffer({iceRestart:!0,offerToReceiveAudio:!0,offerToReceiveVideo:!0});return yield this.setLocalDescription(n),(0,o.toSessionData)({sdp:n,sessionId:e,versionId:i},t)}catch(e){return r.error(`[37] [CallId: ${this.callId}] createOffer in webrtcClient failed: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),!1}}))}createAnswer(e,i,t){return n(this,void 0,void 0,(function*(){try{r.info(`[75] [CallId: ${this.callId}] createAnswer in webrtcClient`,{color:"blue"});const n=yield this.peerConnection.createAnswer();return yield this.setLocalDescription(n),(0,o.toSessionData)({sdp:n,sessionId:e,versionId:i},t)}catch(e){return r.error(`[70] [CallId: ${this.callId}] createAnswer in webrtcClient failed: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),!1}}))}setLocalDescription(e){var i;return r.info(`[44] [CallId: ${this.callId}] setLocalDescription in webrtcClient: sdp sliced 50: ${null===(i=null==e?void 0:e.sdp)||void 0===i?void 0:i.slice(0,50)}...`,{color:"blue"}),this.peerConnection.setLocalDescription(e)}setRemoteDescription(e){var i;return r.info(`[48] [CallId: ${this.callId}] setRemoteDescription in webrtcClient: sdp sliced 50: ${null===(i=e.sdp)||void 0===i?void 0:i.slice(0,50)}...`,{color:"blue"}),this.peerConnection.setRemoteDescription(e)}getLocalSdpUfrag(){var e;const i=((null===(e=this.peerConnection.localDescription)||void 0===e?void 0:e.sdp)||"").match(/a=ice-ufrag:(\S+)/);return i?i[1]:null}getRemoteSdpUfrag(){var e;const i=((null===(e=this.peerConnection.remoteDescription)||void 0===e?void 0:e.sdp)||"").match(/a=ice-ufrag:(\S+)/);return i?i[1]:null}getIceCandidateUfrag(e){const i=e.match(/ufrag\s+(\S+)/);return i?i[1]:null}isUfragEqualsSdpUfrag(e){return{equals:this.getIceCandidateUfrag(e)===this.getRemoteSdpUfrag(),ufrag:this.getIceCandidateUfrag(e),sdpUfrag:this.getRemoteSdpUfrag()}}addIceCandidate(e,i){if(r.info(`[52] [CallId: ${this.callId}] addIceCandidate in webrtcClient: candidate: ${e.candidate}`,{color:"blue"}),e.candidate){const t=this.isUfragEqualsSdpUfrag(e.candidate);if(!t.equals)return this.iceQueueMap[i]||(this.iceQueueMap[i]={}),void(t.ufrag&&(this.iceQueueMap[i][t.ufrag]||(this.iceQueueMap[i][t.ufrag]=[]),this.iceQueueMap[i][t.ufrag].push(e)))}return this.peerConnection.addIceCandidate(e)}addEventListener(e,i){this.peerConnection.addEventListener(e,i)}removeEventListener(e,i){this.peerConnection.removeEventListener(e,i)}close(){r.info(`[56] [CallId: ${this.callId}] close in webrtcClient`,{color:"blue"}),this.peerConnection.close()}getConnectionStats(){return n(this,void 0,void 0,(function*(){return yield this.peerConnection.getStats()}))}}},297:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.TypedEventEmitter=void 0,i.TypedEventEmitter=class{constructor(){this.listeners=new Map}on(e,i){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(i),()=>{var t;null===(t=this.listeners.get(e))||void 0===t||t.delete(i)}}emit(e,i){var t;null===(t=this.listeners.get(e))||void 0===t||t.forEach((t=>{try{t(i)}catch(i){console.error(`Error in event handler for "${String(e)}":`,i)}}))}off(e,i){var t;i?null===(t=this.listeners.get(e))||void 0===t||t.delete(i):this.listeners.delete(e)}removeAllListeners(){this.listeners.clear()}listenerCount(e){var i,t;return null!==(t=null===(i=this.listeners.get(e))||void 0===i?void 0:i.size)&&void 0!==t?t:0}}},578:(e,i)=>{"use strict";var t,n,a,l,s,o,r,d;Object.defineProperty(i,"__esModule",{value:!0}),i.CDRRequestDirection=i.CDRRequestEvent=i.CDRRequestOrder=i.MediaFlow=i.SignalEvent=i.CallState=i.ParticipantConnectionState=i.ParticipantState=void 0,function(e){e[e.Idle=0]="Idle",e[e.Ringing=1]="Ringing",e[e.Joined=2]="Joined",e[e.Left=3]="Left",e[e.Declined=4]="Declined",e[e.Kicked=5]="Kicked",e[e.NoAnswer=6]="NoAnswer"}(t||(i.ParticipantState=t={})),function(e){e[e.Idle=0]="Idle",e[e.Connecting=1]="Connecting",e[e.Connected=2]="Connected",e[e.Reconnecting=3]="Reconnecting",e[e.Disconnected=4]="Disconnected"}(n||(i.ParticipantConnectionState=n={})),function(e){e.Idle="idle",e.Connecting="connecting",e.Connected="connected",e.Closed="closed"}(a||(i.CallState=a={})),function(e){e[e.JOIN=0]="JOIN",e[e.LEAVE=1]="LEAVE",e[e.OFFER=2]="OFFER",e[e.ANSWER=3]="ANSWER",e[e.CONNECT=4]="CONNECT",e[e.ERROR=5]="ERROR",e[e.KICK=6]="KICK",e[e.SUCCESS=7]="SUCCESS",e[e.INVITE=8]="INVITE",e[e.DECLINE=9]="DECLINE",e[e.RINGING=10]="RINGING",e[e.INFO=11]="INFO",e[e.UPDATE=12]="UPDATE",e[e.CLOSE=13]="CLOSE",e[e.ICE=14]="ICE",e[e.GET_CALL=15]="GET_CALL",e[e.SWITCH_MEDIA_FLOW=16]="SWITCH_MEDIA_FLOW",e[e.NO_ANSWER=17]="NO_ANSWER",e[e.MEDIA_CONNECTED=18]="MEDIA_CONNECTED",e[e.MUTE=19]="MUTE",e[e.UNMUTE=20]="UNMUTE",e[e.HOLD=21]="HOLD",e[e.UNHOLD=22]="UNHOLD",e[e.VIDEO_ON=23]="VIDEO_ON",e[e.VIDEO_OFF=24]="VIDEO_OFF",e[e.SCREEN_SHARE_ON=25]="SCREEN_SHARE_ON",e[e.SCREEN_SHARE_OFF=26]="SCREEN_SHARE_OFF",e[e.CREATE=27]="CREATE",e[e.SESSION_RENEWED=28]="SESSION_RENEWED",e[e.DISABLE_REMOTE_AUDIO=29]="DISABLE_REMOTE_AUDIO",e[e.DISABLE_REMOTE_VIDEO=30]="DISABLE_REMOTE_VIDEO",e[e.CALL_PERMISSIONS_UPDATE=31]="CALL_PERMISSIONS_UPDATE",e[e.PARTICIPANT_PERMISSIONS_UPDATE=32]="PARTICIPANT_PERMISSIONS_UPDATE"}(l||(i.SignalEvent=l={})),function(e){e[e.P2P=0]="P2P",e[e.SFU=1]="SFU",e[e.S2W=2]="S2W"}(s||(i.MediaFlow=s={})),function(e){e[e.ASC=0]="ASC",e[e.DESC=1]="DESC"}(o||(i.CDRRequestOrder=o={})),function(e){e[e.GET_RECENT_CALLS=0]="GET_RECENT_CALLS",e[e.GET_CALLS_BY_SESSION_IDS=1]="GET_CALLS_BY_SESSION_IDS",e[e.DELETE_RECENT_CALLS=2]="DELETE_RECENT_CALLS"}(r||(i.CDRRequestEvent=r={})),function(e){e[e.NEXT=0]="NEXT",e[e.PREVIOUS=1]="PREVIOUS"}(d||(i.CDRRequestDirection=d={}))},489:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.makeFirstById=i.getEmptyVideoTrack=void 0,i.getEmptyVideoTrack=()=>{const e=document.createElement("canvas");return e.getContext("2d"),e.width=640,e.height=480,e.captureStream().getVideoTracks()},i.makeFirstById=(e,i,t)=>{const n=new Set,a=e.filter((e=>{const i=`${e.id}${e.clientId?`/${e.clientId}`:""}`;return!n.has(i)&&(n.add(i),!0)})),l=a.findIndex((e=>e.id===i&&(e.clientId===t||!e.clientId)));if(l>-1){const[e]=a.splice(l,1);a.unshift(e)}return a}},607:function(e,i,t){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,i,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(i,t);a&&!("get"in a?!i.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return i[t]}}),Object.defineProperty(e,n,a)}:function(e,i,t,n){void 0===n&&(n=t),e[n]=i[t]}),a=this&&this.__exportStar||function(e,i){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(i,t)||n(i,e,t)};Object.defineProperty(i,"__esModule",{value:!0});const l=t(838);a(t(838),i),i.default=l.SceytCallClient},838:function(e,i,t){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,i,t,n){void 0===n&&(n=t);var a=Object.getOwnPropertyDescriptor(i,t);a&&!("get"in a?!i.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return i[t]}}),Object.defineProperty(e,n,a)}:function(e,i,t,n){void 0===n&&(n=t),e[n]=i[t]}),a=this&&this.__exportStar||function(e,i){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(i,t)||n(i,e,t)};Object.defineProperty(i,"__esModule",{value:!0}),i.CDRRequestDirection=i.CDRRequestEvent=i.CDRRequestOrder=i.ParticipantConnectionState=i.ParticipantState=i.CallState=i.MediaFlow=i.VideoTrack=i.AudioTrack=i.Participant=i.Call=void 0,a(t(271),i);var l=t(998);Object.defineProperty(i,"Call",{enumerable:!0,get:function(){return l.Call}});var s=t(787);Object.defineProperty(i,"Participant",{enumerable:!0,get:function(){return s.Participant}});var o=t(250);Object.defineProperty(i,"AudioTrack",{enumerable:!0,get:function(){return o.AudioTrack}});var r=t(740);Object.defineProperty(i,"VideoTrack",{enumerable:!0,get:function(){return r.VideoTrack}});var d=t(578);Object.defineProperty(i,"MediaFlow",{enumerable:!0,get:function(){return d.MediaFlow}}),Object.defineProperty(i,"CallState",{enumerable:!0,get:function(){return d.CallState}}),Object.defineProperty(i,"ParticipantState",{enumerable:!0,get:function(){return d.ParticipantState}}),Object.defineProperty(i,"ParticipantConnectionState",{enumerable:!0,get:function(){return d.ParticipantConnectionState}}),Object.defineProperty(i,"CDRRequestOrder",{enumerable:!0,get:function(){return d.CDRRequestOrder}}),Object.defineProperty(i,"CDRRequestEvent",{enumerable:!0,get:function(){return d.CDRRequestEvent}}),Object.defineProperty(i,"CDRRequestDirection",{enumerable:!0,get:function(){return d.CDRRequestDirection}}),a(t(645),i)},645:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.createLogger=i.removeLogListener=i.addLogListener=void 0;const t={green:"",blue:"","light-green":"","light-blue":"",yellow:"",magenta:"",cyan:"",reset:"",orange:"",red:"",white:""},n=[];i.addLogListener=e=>{n.push(e)},i.removeLogListener=e=>{const i=n.indexOf(e);-1!==i&&n.splice(i,1)},i.createLogger=(e,i="white")=>{const a=`[SceytCallClient] ${e?`[${e}]`:""}:`,l=(e,l,s,o)=>{var r;const d=null!==(r=null==o?void 0:o.color)&&void 0!==r?r:i,c={level:e,message:l,prefix:a,args:s.filter((e=>!(null==e?void 0:e.color)&&!(null==e?void 0:e.time))),color:t[d],time:(null==o?void 0:o.time)||(new Date).toISOString()};n.forEach((e=>e(c)))};return{trace:(e,i)=>{l("trace",e,[],i)},debug:(e,i)=>{l("debug",e,[],i)},info:(e,i)=>{l("info",e,[],i)},warn:(e,i)=>{l("warn",e,[],i)},error:(e,i)=>{l("error",e,[],i)}}},i.default=(0,i.createLogger)("SceytCallClient")},429:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),Object.defineProperty(i,"NIL",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(i,"parse",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(i,"stringify",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(i,"v1",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(i,"v3",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(i,"v4",{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(i,"v5",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(i,"validate",{enumerable:!0,get:function(){return d.default}}),Object.defineProperty(i,"version",{enumerable:!0,get:function(){return r.default}});var n=p(t(990)),a=p(t(237)),l=p(t(355)),s=p(t(764)),o=p(t(314)),r=p(t(464)),d=p(t(435)),c=p(t(8)),u=p(t(222));function p(e){return e&&e.__esModule?e:{default:e}}},163:(e,i)=>{"use strict";function t(e){return 14+(e+64>>>9<<4)+1}function n(e,i){const t=(65535&e)+(65535&i);return(e>>16)+(i>>16)+(t>>16)<<16|65535&t}function a(e,i,t,a,l,s){return n((o=n(n(i,e),n(a,s)))<<(r=l)|o>>>32-r,t);var o,r}function l(e,i,t,n,l,s,o){return a(i&t|~i&n,e,i,l,s,o)}function s(e,i,t,n,l,s,o){return a(i&n|t&~n,e,i,l,s,o)}function o(e,i,t,n,l,s,o){return a(i^t^n,e,i,l,s,o)}function r(e,i,t,n,l,s,o){return a(t^(i|~n),e,i,l,s,o)}Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;i.default=function(e){if("string"==typeof e){const i=unescape(encodeURIComponent(e));e=new Uint8Array(i.length);for(let t=0;t<i.length;++t)e[t]=i.charCodeAt(t)}return function(e){const i=[],t=32*e.length,n="0123456789abcdef";for(let a=0;a<t;a+=8){const t=e[a>>5]>>>a%32&255,l=parseInt(n.charAt(t>>>4&15)+n.charAt(15&t),16);i.push(l)}return i}(function(e,i){e[i>>5]|=128<<i%32,e[t(i)-1]=i;let a=1732584193,d=-271733879,c=-1732584194,u=271733878;for(let i=0;i<e.length;i+=16){const t=a,p=d,h=c,g=u;a=l(a,d,c,u,e[i],7,-680876936),u=l(u,a,d,c,e[i+1],12,-389564586),c=l(c,u,a,d,e[i+2],17,606105819),d=l(d,c,u,a,e[i+3],22,-1044525330),a=l(a,d,c,u,e[i+4],7,-176418897),u=l(u,a,d,c,e[i+5],12,1200080426),c=l(c,u,a,d,e[i+6],17,-1473231341),d=l(d,c,u,a,e[i+7],22,-45705983),a=l(a,d,c,u,e[i+8],7,1770035416),u=l(u,a,d,c,e[i+9],12,-1958414417),c=l(c,u,a,d,e[i+10],17,-42063),d=l(d,c,u,a,e[i+11],22,-1990404162),a=l(a,d,c,u,e[i+12],7,1804603682),u=l(u,a,d,c,e[i+13],12,-40341101),c=l(c,u,a,d,e[i+14],17,-1502002290),d=l(d,c,u,a,e[i+15],22,1236535329),a=s(a,d,c,u,e[i+1],5,-165796510),u=s(u,a,d,c,e[i+6],9,-1069501632),c=s(c,u,a,d,e[i+11],14,643717713),d=s(d,c,u,a,e[i],20,-373897302),a=s(a,d,c,u,e[i+5],5,-701558691),u=s(u,a,d,c,e[i+10],9,38016083),c=s(c,u,a,d,e[i+15],14,-660478335),d=s(d,c,u,a,e[i+4],20,-405537848),a=s(a,d,c,u,e[i+9],5,568446438),u=s(u,a,d,c,e[i+14],9,-1019803690),c=s(c,u,a,d,e[i+3],14,-187363961),d=s(d,c,u,a,e[i+8],20,1163531501),a=s(a,d,c,u,e[i+13],5,-1444681467),u=s(u,a,d,c,e[i+2],9,-51403784),c=s(c,u,a,d,e[i+7],14,1735328473),d=s(d,c,u,a,e[i+12],20,-1926607734),a=o(a,d,c,u,e[i+5],4,-378558),u=o(u,a,d,c,e[i+8],11,-2022574463),c=o(c,u,a,d,e[i+11],16,1839030562),d=o(d,c,u,a,e[i+14],23,-35309556),a=o(a,d,c,u,e[i+1],4,-1530992060),u=o(u,a,d,c,e[i+4],11,1272893353),c=o(c,u,a,d,e[i+7],16,-155497632),d=o(d,c,u,a,e[i+10],23,-1094730640),a=o(a,d,c,u,e[i+13],4,681279174),u=o(u,a,d,c,e[i],11,-358537222),c=o(c,u,a,d,e[i+3],16,-722521979),d=o(d,c,u,a,e[i+6],23,76029189),a=o(a,d,c,u,e[i+9],4,-640364487),u=o(u,a,d,c,e[i+12],11,-421815835),c=o(c,u,a,d,e[i+15],16,530742520),d=o(d,c,u,a,e[i+2],23,-995338651),a=r(a,d,c,u,e[i],6,-198630844),u=r(u,a,d,c,e[i+7],10,1126891415),c=r(c,u,a,d,e[i+14],15,-1416354905),d=r(d,c,u,a,e[i+5],21,-57434055),a=r(a,d,c,u,e[i+12],6,1700485571),u=r(u,a,d,c,e[i+3],10,-1894986606),c=r(c,u,a,d,e[i+10],15,-1051523),d=r(d,c,u,a,e[i+1],21,-2054922799),a=r(a,d,c,u,e[i+8],6,1873313359),u=r(u,a,d,c,e[i+15],10,-30611744),c=r(c,u,a,d,e[i+6],15,-1560198380),d=r(d,c,u,a,e[i+13],21,1309151649),a=r(a,d,c,u,e[i+4],6,-145523070),u=r(u,a,d,c,e[i+11],10,-1120210379),c=r(c,u,a,d,e[i+2],15,718787259),d=r(d,c,u,a,e[i+9],21,-343485551),a=n(a,t),d=n(d,p),c=n(c,h),u=n(u,g)}return[a,d,c,u]}(function(e){if(0===e.length)return[];const i=8*e.length,n=new Uint32Array(t(i));for(let t=0;t<i;t+=8)n[t>>5]|=(255&e[t/8])<<t%32;return n}(e),8*e.length))}},790:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var t={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};i.default=t},314:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0,i.default="00000000-0000-0000-0000-000000000000"},222:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n,a=(n=t(435))&&n.__esModule?n:{default:n};i.default=function(e){if(!(0,a.default)(e))throw TypeError("Invalid UUID");let i;const t=new Uint8Array(16);return t[0]=(i=parseInt(e.slice(0,8),16))>>>24,t[1]=i>>>16&255,t[2]=i>>>8&255,t[3]=255&i,t[4]=(i=parseInt(e.slice(9,13),16))>>>8,t[5]=255&i,t[6]=(i=parseInt(e.slice(14,18),16))>>>8,t[7]=255&i,t[8]=(i=parseInt(e.slice(19,23),16))>>>8,t[9]=255&i,t[10]=(i=parseInt(e.slice(24,36),16))/1099511627776&255,t[11]=i/4294967296&255,t[12]=i>>>24&255,t[13]=i>>>16&255,t[14]=i>>>8&255,t[15]=255&i,t}},58:(e,i)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0,i.default=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i},319:(e,i)=>{"use strict";let t;Object.defineProperty(i,"__esModule",{value:!0}),i.default=function(){if(!t&&(t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!t))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return t(n)};const n=new Uint8Array(16)},757:(e,i)=>{"use strict";function t(e,i,t,n){switch(e){case 0:return i&t^~i&n;case 1:case 3:return i^t^n;case 2:return i&t^i&n^t&n}}function n(e,i){return e<<i|e>>>32-i}Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;i.default=function(e){const i=[1518500249,1859775393,2400959708,3395469782],a=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const i=unescape(encodeURIComponent(e));e=[];for(let t=0;t<i.length;++t)e.push(i.charCodeAt(t))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);const l=e.length/4+2,s=Math.ceil(l/16),o=new Array(s);for(let i=0;i<s;++i){const t=new Uint32Array(16);for(let n=0;n<16;++n)t[n]=e[64*i+4*n]<<24|e[64*i+4*n+1]<<16|e[64*i+4*n+2]<<8|e[64*i+4*n+3];o[i]=t}o[s-1][14]=8*(e.length-1)/Math.pow(2,32),o[s-1][14]=Math.floor(o[s-1][14]),o[s-1][15]=8*(e.length-1)&4294967295;for(let e=0;e<s;++e){const l=new Uint32Array(80);for(let i=0;i<16;++i)l[i]=o[e][i];for(let e=16;e<80;++e)l[e]=n(l[e-3]^l[e-8]^l[e-14]^l[e-16],1);let s=a[0],r=a[1],d=a[2],c=a[3],u=a[4];for(let e=0;e<80;++e){const a=Math.floor(e/20),o=n(s,5)+t(a,r,d,c)+u+i[a]+l[e]>>>0;u=c,c=d,d=n(r,30)>>>0,r=s,s=o}a[0]=a[0]+s>>>0,a[1]=a[1]+r>>>0,a[2]=a[2]+d>>>0,a[3]=a[3]+c>>>0,a[4]=a[4]+u>>>0}return[a[0]>>24&255,a[0]>>16&255,a[0]>>8&255,255&a[0],a[1]>>24&255,a[1]>>16&255,a[1]>>8&255,255&a[1],a[2]>>24&255,a[2]>>16&255,a[2]>>8&255,255&a[2],a[3]>>24&255,a[3]>>16&255,a[3]>>8&255,255&a[3],a[4]>>24&255,a[4]>>16&255,a[4]>>8&255,255&a[4]]}},8:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0,i.unsafeStringify=s;var n,a=(n=t(435))&&n.__esModule?n:{default:n};const l=[];for(let e=0;e<256;++e)l.push((e+256).toString(16).slice(1));function s(e,i=0){return l[e[i+0]]+l[e[i+1]]+l[e[i+2]]+l[e[i+3]]+"-"+l[e[i+4]]+l[e[i+5]]+"-"+l[e[i+6]]+l[e[i+7]]+"-"+l[e[i+8]]+l[e[i+9]]+"-"+l[e[i+10]]+l[e[i+11]]+l[e[i+12]]+l[e[i+13]]+l[e[i+14]]+l[e[i+15]]}i.default=function(e,i=0){const t=s(e,i);if(!(0,a.default)(t))throw TypeError("Stringified UUID is invalid");return t}},990:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n,a=(n=t(319))&&n.__esModule?n:{default:n},l=t(8);let s,o,r=0,d=0;i.default=function(e,i,t){let n=i&&t||0;const c=i||new Array(16);let u=(e=e||{}).node||s,p=void 0!==e.clockseq?e.clockseq:o;if(null==u||null==p){const i=e.random||(e.rng||a.default)();null==u&&(u=s=[1|i[0],i[1],i[2],i[3],i[4],i[5]]),null==p&&(p=o=16383&(i[6]<<8|i[7]))}let h=void 0!==e.msecs?e.msecs:Date.now(),g=void 0!==e.nsecs?e.nsecs:d+1;const v=h-r+(g-d)/1e4;if(v<0&&void 0===e.clockseq&&(p=p+1&16383),(v<0||h>r)&&void 0===e.nsecs&&(g=0),g>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");r=h,d=g,o=p,h+=122192928e5;const S=(1e4*(268435455&h)+g)%4294967296;c[n++]=S>>>24&255,c[n++]=S>>>16&255,c[n++]=S>>>8&255,c[n++]=255&S;const f=h/4294967296*1e4&268435455;c[n++]=f>>>8&255,c[n++]=255&f,c[n++]=f>>>24&15|16,c[n++]=f>>>16&255,c[n++]=p>>>8|128,c[n++]=255&p;for(let e=0;e<6;++e)c[n+e]=u[e];return i||(0,l.unsafeStringify)(c)}},237:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n=l(t(925)),a=l(t(163));function l(e){return e&&e.__esModule?e:{default:e}}var s=(0,n.default)("v3",48,a.default);i.default=s},925:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.URL=i.DNS=void 0,i.default=function(e,i,t){function n(e,n,s,o){var r;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const i=[];for(let t=0;t<e.length;++t)i.push(e.charCodeAt(t));return i}(e)),"string"==typeof n&&(n=(0,l.default)(n)),16!==(null===(r=n)||void 0===r?void 0:r.length))throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let d=new Uint8Array(16+e.length);if(d.set(n),d.set(e,n.length),d=t(d),d[6]=15&d[6]|i,d[8]=63&d[8]|128,s){o=o||0;for(let e=0;e<16;++e)s[o+e]=d[e];return s}return(0,a.unsafeStringify)(d)}try{n.name=e}catch(e){}return n.DNS=s,n.URL=o,n};var n,a=t(8),l=(n=t(222))&&n.__esModule?n:{default:n};const s="6ba7b810-9dad-11d1-80b4-00c04fd430c8";i.DNS=s;const o="6ba7b811-9dad-11d1-80b4-00c04fd430c8";i.URL=o},355:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n=s(t(790)),a=s(t(319)),l=t(8);function s(e){return e&&e.__esModule?e:{default:e}}i.default=function(e,i,t){if(n.default.randomUUID&&!i&&!e)return n.default.randomUUID();const s=(e=e||{}).random||(e.rng||a.default)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,i){t=t||0;for(let e=0;e<16;++e)i[t+e]=s[e];return i}return(0,l.unsafeStringify)(s)}},764:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n=l(t(925)),a=l(t(757));function l(e){return e&&e.__esModule?e:{default:e}}var s=(0,n.default)("v5",80,a.default);i.default=s},435:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n,a=(n=t(58))&&n.__esModule?n:{default:n};i.default=function(e){return"string"==typeof e&&a.default.test(e)}},464:(e,i,t)=>{"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var n,a=(n=t(435))&&n.__esModule?n:{default:n};i.default=function(e){if(!(0,a.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)}},583:function(e,i){var t;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self&&self,t=function(){var e={};return function(e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var i=null;try{i=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}function t(e,i,t){this.low=0|e,this.high=0|i,this.unsigned=!!t}function n(e){return!0===(e&&e.__isLong__)}function a(e){var i=Math.clz32(e&-e);return e?31-i:i}t.prototype.__isLong__,Object.defineProperty(t.prototype,"__isLong__",{value:!0}),t.isLong=n;var l={},s={};function o(e,i){var t,n,a;return i?(a=0<=(e>>>=0)&&e<256)&&(n=s[e])?n:(t=d(e,0,!0),a&&(s[e]=t),t):(a=-128<=(e|=0)&&e<128)&&(n=l[e])?n:(t=d(e,e<0?-1:0,!1),a&&(l[e]=t),t)}function r(e,i){if(isNaN(e))return i?C:f;if(i){if(e<0)return C;if(e>=g)return b}else{if(e<=-v)return y;if(e+1>=v)return P}return e<0?r(-e,i).neg():d(e%h|0,e/h|0,i)}function d(e,i,n){return new t(e,i,n)}t.fromInt=o,t.fromNumber=r,t.fromBits=d;var c=Math.pow;function u(e,i,t){if(0===e.length)throw Error("empty string");if("number"==typeof i?(t=i,i=!1):i=!!i,"NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return i?C:f;if((t=t||10)<2||36<t)throw RangeError("radix");var n;if((n=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===n)return u(e.substring(1),i,t).neg();for(var a=r(c(t,8)),l=f,s=0;s<e.length;s+=8){var o=Math.min(8,e.length-s),d=parseInt(e.substring(s,s+o),t);if(o<8){var p=r(c(t,o));l=l.mul(p).add(r(d))}else l=(l=l.mul(a)).add(r(d))}return l.unsigned=i,l}function p(e,i){return"number"==typeof e?r(e,i):"string"==typeof e?u(e,i):d(e.low,e.high,"boolean"==typeof i?i:e.unsigned)}t.fromString=u,t.fromValue=p;var h=4294967296,g=h*h,v=g/2,S=o(1<<24),f=o(0);t.ZERO=f;var C=o(0,!0);t.UZERO=C;var I=o(1);t.ONE=I;var m=o(1,!0);t.UONE=m;var E=o(-1);t.NEG_ONE=E;var P=d(-1,2147483647,!1);t.MAX_VALUE=P;var b=d(-1,-1,!0);t.MAX_UNSIGNED_VALUE=b;var y=d(0,-2147483648,!1);t.MIN_VALUE=y;var O=t.prototype;O.toInt=function(){return this.unsigned?this.low>>>0:this.low},O.toNumber=function(){return this.unsigned?(this.high>>>0)*h+(this.low>>>0):this.high*h+(this.low>>>0)},O.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(y)){var i=r(e),t=this.div(i),n=t.mul(i).sub(this);return t.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var a=r(c(e,6),this.unsigned),l=this,s="";;){var o=l.div(a),d=(l.sub(o.mul(a)).toInt()>>>0).toString(e);if((l=o).isZero())return d+s;for(;d.length<6;)d="0"+d;s=""+d+s}},O.getHighBits=function(){return this.high},O.getHighBitsUnsigned=function(){return this.high>>>0},O.getLowBits=function(){return this.low},O.getLowBitsUnsigned=function(){return this.low>>>0},O.getNumBitsAbs=function(){if(this.isNegative())return this.eq(y)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,i=31;i>0&&0==(e&1<<i);i--);return 0!=this.high?i+33:i+1},O.isSafeInteger=function(){var e=this.high>>21;return!e||!this.unsigned&&-1===e&&!(0===this.low&&-2097152===this.high)},O.isZero=function(){return 0===this.high&&0===this.low},O.eqz=O.isZero,O.isNegative=function(){return!this.unsigned&&this.high<0},O.isPositive=function(){return this.unsigned||this.high>=0},O.isOdd=function(){return 1==(1&this.low)},O.isEven=function(){return 0==(1&this.low)},O.equals=function(e){return n(e)||(e=p(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&this.high===e.high&&this.low===e.low},O.eq=O.equals,O.notEquals=function(e){return!this.eq(e)},O.neq=O.notEquals,O.ne=O.notEquals,O.lessThan=function(e){return this.comp(e)<0},O.lt=O.lessThan,O.lessThanOrEqual=function(e){return this.comp(e)<=0},O.lte=O.lessThanOrEqual,O.le=O.lessThanOrEqual,O.greaterThan=function(e){return this.comp(e)>0},O.gt=O.greaterThan,O.greaterThanOrEqual=function(e){return this.comp(e)>=0},O.gte=O.greaterThanOrEqual,O.ge=O.greaterThanOrEqual,O.compare=function(e){if(n(e)||(e=p(e)),this.eq(e))return 0;var i=this.isNegative(),t=e.isNegative();return i&&!t?-1:!i&&t?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},O.comp=O.compare,O.negate=function(){return!this.unsigned&&this.eq(y)?y:this.not().add(I)},O.neg=O.negate,O.add=function(e){n(e)||(e=p(e));var i=this.high>>>16,t=65535&this.high,a=this.low>>>16,l=65535&this.low,s=e.high>>>16,o=65535&e.high,r=e.low>>>16,c=0,u=0,h=0,g=0;return h+=(g+=l+(65535&e.low))>>>16,u+=(h+=a+r)>>>16,c+=(u+=t+o)>>>16,c+=i+s,d((h&=65535)<<16|(g&=65535),(c&=65535)<<16|(u&=65535),this.unsigned)},O.subtract=function(e){return n(e)||(e=p(e)),this.add(e.neg())},O.sub=O.subtract,O.multiply=function(e){if(this.isZero())return this;if(n(e)||(e=p(e)),i)return d(i.mul(this.low,this.high,e.low,e.high),i.get_high(),this.unsigned);if(e.isZero())return this.unsigned?C:f;if(this.eq(y))return e.isOdd()?y:f;if(e.eq(y))return this.isOdd()?y:f;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(S)&&e.lt(S))return r(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,a=65535&this.high,l=this.low>>>16,s=65535&this.low,o=e.high>>>16,c=65535&e.high,u=e.low>>>16,h=65535&e.low,g=0,v=0,I=0,m=0;return I+=(m+=s*h)>>>16,v+=(I+=l*h)>>>16,I&=65535,v+=(I+=s*u)>>>16,g+=(v+=a*h)>>>16,v&=65535,g+=(v+=l*u)>>>16,v&=65535,g+=(v+=s*c)>>>16,g+=t*h+a*u+l*c+s*o,d((I&=65535)<<16|(m&=65535),(g&=65535)<<16|(v&=65535),this.unsigned)},O.mul=O.multiply,O.divide=function(e){if(n(e)||(e=p(e)),e.isZero())throw Error("division by zero");var t,a,l;if(i)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?d((this.unsigned?i.div_u:i.div_s)(this.low,this.high,e.low,e.high),i.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?C:f;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return C;if(e.gt(this.shru(1)))return m;l=C}else{if(this.eq(y))return e.eq(I)||e.eq(E)?y:e.eq(y)?I:(t=this.shr(1).div(e).shl(1)).eq(f)?e.isNegative()?I:E:(a=this.sub(e.mul(t)),l=t.add(a.div(e)));if(e.eq(y))return this.unsigned?C:f;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();l=f}for(a=this;a.gte(e);){t=Math.max(1,Math.floor(a.toNumber()/e.toNumber()));for(var s=Math.ceil(Math.log(t)/Math.LN2),o=s<=48?1:c(2,s-48),u=r(t),h=u.mul(e);h.isNegative()||h.gt(a);)h=(u=r(t-=o,this.unsigned)).mul(e);u.isZero()&&(u=I),l=l.add(u),a=a.sub(h)}return l},O.div=O.divide,O.modulo=function(e){return n(e)||(e=p(e)),i?d((this.unsigned?i.rem_u:i.rem_s)(this.low,this.high,e.low,e.high),i.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},O.mod=O.modulo,O.rem=O.modulo,O.not=function(){return d(~this.low,~this.high,this.unsigned)},O.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32},O.clz=O.countLeadingZeros,O.countTrailingZeros=function(){return this.low?a(this.low):a(this.high)+32},O.ctz=O.countTrailingZeros,O.and=function(e){return n(e)||(e=p(e)),d(this.low&e.low,this.high&e.high,this.unsigned)},O.or=function(e){return n(e)||(e=p(e)),d(this.low|e.low,this.high|e.high,this.unsigned)},O.xor=function(e){return n(e)||(e=p(e)),d(this.low^e.low,this.high^e.high,this.unsigned)},O.shiftLeft=function(e){return n(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?d(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):d(0,this.low<<e-32,this.unsigned)},O.shl=O.shiftLeft,O.shiftRight=function(e){return n(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?d(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):d(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},O.shr=O.shiftRight,O.shiftRightUnsigned=function(e){return n(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?d(this.low>>>e|this.high<<32-e,this.high>>>e,this.unsigned):d(32===e?this.high:this.high>>>e-32,0,this.unsigned)},O.shru=O.shiftRightUnsigned,O.shr_u=O.shiftRightUnsigned,O.rotateLeft=function(e){var i;return n(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?d(this.high,this.low,this.unsigned):e<32?(i=32-e,d(this.low<<e|this.high>>>i,this.high<<e|this.low>>>i,this.unsigned)):(i=32-(e-=32),d(this.high<<e|this.low>>>i,this.low<<e|this.high>>>i,this.unsigned))},O.rotl=O.rotateLeft,O.rotateRight=function(e){var i;return n(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?d(this.high,this.low,this.unsigned):e<32?(i=32-e,d(this.high<<i|this.low>>>e,this.low<<i|this.high>>>e,this.unsigned)):(i=32-(e-=32),d(this.low<<i|this.high>>>e,this.high<<i|this.low>>>e,this.unsigned))},O.rotr=O.rotateRight,O.toSigned=function(){return this.unsigned?d(this.low,this.high,!1):this},O.toUnsigned=function(){return this.unsigned?this:d(this.low,this.high,!0)},O.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},O.toBytesLE=function(){var e=this.high,i=this.low;return[255&i,i>>>8&255,i>>>16&255,i>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},O.toBytesBE=function(){var e=this.high,i=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,i>>>24,i>>>16&255,i>>>8&255,255&i]},t.fromBytes=function(e,i,n){return n?t.fromBytesLE(e,i):t.fromBytesBE(e,i)},t.fromBytesLE=function(e,i){return new t(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,i)},t.fromBytesBE=function(e,i){return new t(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],i)},"function"==typeof BigInt&&(t.fromBigInt=function(e,i){return d(Number(BigInt.asIntN(32,e)),Number(BigInt.asIntN(32,e>>BigInt(32))),i)},t.fromValue=function(e,i){return"bigint"==typeof e?t.fromBigInt(e,i):p(e,i)},O.toBigInt=function(){var e=BigInt(this.low>>>0);return BigInt(this.unsigned?this.high>>>0:this.high)<<BigInt(32)|e}),e.default=t}(e),function(e){return e.default||e}(e)}.apply(i,[]),void 0===t||(e.exports=t)}},i={},function t(n){var a=i[n];if(void 0!==a)return a.exports;var l=i[n]={exports:{}};return e[n].call(l.exports,l,l.exports,t),l.exports}(607);var e,i}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sceyt-call",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "JavaScript Call SDK",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",