sceyt-call 1.1.0 → 1.1.2

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 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["sceyt-call"]=t():e["sceyt-call"]=t()}(this,(()=>(()=>{"use strict";var e={547:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CallStateMachine=void 0;const n=i(578),a=(0,i(645).createLogger)("CallStateMachine");class l{constructor(e){this.callId=e}isValidStateTransition(e,t){var i,n;return null!==(n=null===(i=l.validStateTransitions.get(t))||void 0===i?void 0:i.has(e))&&void 0!==n&&n}setState(e,t,i){return this.isValidStateTransition(e,t)?(a.info(`[25] [CallId: ${this.callId}] Call state changed ${t} -> ${e}, reason: ${i}`,{color:"cyan"}),!0):(a.warn(`[28] [CallId: ${this.callId}] Invalid CallState changed ${t} -> ${e}, reason: ${i}`,{color:"red"}),!1)}updateState(e,t,i){return this.setState(e,t,i)}}t.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,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ParticipantStateMachine=void 0;const n=i(578),a=(0,i(645).createLogger)("ParticipantStateMachine");class l{constructor(e,t){this.userId=e,this.callId=t}isValidParticipantStateTransition(e,t){var i,n;return null!==(n=null===(i=l.validParticipantStateTransitions.get(t))||void 0===i?void 0:i.has(e))&&void 0!==n&&n}isValidConnectionTransition(e,t){var i,n;return null!==(n=null===(i=l.validConnectionTransitions.get(t))||void 0===i?void 0:i.has(e))&&void 0!==n&&n}setState(e,t,i,l){let r=!1;void 0!==e&&void 0!==i&&this.isValidParticipantStateTransition(e,i)?(a.debug(`[43] [CallId: ${this.callId}] Participant state transition: ${i} -> ${e}`),r=!0):e&&a.warn(`[46] [CallId: ${this.callId}] Invalid ParticipantState transition from ${i?n.ParticipantState[i]:"undefined"} to ${e?n.ParticipantState[e]:"undefined"}`,{color:"yellow"}),void 0!==t&&void 0!==l&&this.isValidConnectionTransition(t,l)?(a.debug(`[50] [CallId: ${this.callId}] Connection state transition: ${l} -> ${t}`),r=!0):t&&a.warn(`[53] [CallId: ${this.callId}] Invalid ConnectionState transition from ${l?n.ParticipantConnectionState[l]:"undefined"} to ${t?n.ParticipantConnectionState[t]:"undefined"}`,{color:"yellow"})}updateState(e,t){return this.isValidParticipantStateTransition(e,t)?(this.setState(e,void 0,t,void 0),!0):(a.warn(`[63] [CallId: ${this.callId}] Invalid ParticipantState transition from ${n.ParticipantState[t]} to ${n.ParticipantState[e]}`,{color:"yellow"}),!1)}updateConnectionState(e,t){return this.isValidConnectionTransition(e,t)?(this.setState(void 0,e,void 0,t),!0):(a.warn(`[71] [CallId: ${this.callId}] Invalid ConnectionState transition from ${n.ParticipantConnectionState[t]} to ${n.ParticipantConnectionState[e]}`,{color:"yellow"}),!1)}}t.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,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{o(n.next(e))}catch(e){l(e)}}function s(e){try{o(n.throw(e))}catch(e){l(e)}}function o(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,s)}o((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ActiveSpeakerManager=void 0;const a=i(645),l=i(578),r=(0,a.createLogger)("ActiveSpeakerManager");class s{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 t,i;this.processingInterval||(this.internalCallHandler=e,this.internalCallHandler&&this.call?(this.processingInterval=setInterval((()=>n(this,void 0,void 0,(function*(){var e,t,i,n,a;try{if(this.call&&this.internalCallHandler){if(this.call.localParticipant){let i=0;if(this.call.mediaFlow!==l.MediaFlow.SFU){const t=this.call.participants.find((e=>{var t,i,n,a;return e.id!==(null===(i=null===(t=this.call)||void 0===t?void 0:t.localParticipant)||void 0===i?void 0:i.id)||e.clientId!==(null===(a=null===(n=this.call)||void 0===n?void 0:n.localParticipant)||void 0===a?void 0:a.clientId)}));if(t){const n=null===(e=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===e?void 0:e[t.getFullId()];if(n){const e=yield n.getConnectionStats(),t=Array.from(e.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));i=t.length>0?Math.max(...t):0}}}else{const e=this.call.serverParticipant;if(e){const n=null===(t=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===t?void 0:t[e.getFullId()];if(n){const e=yield n.getConnectionStats(),t=Array.from(e.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));i=t.length>0?Math.max(...t):0}}}this.call.localParticipant.muted&&(i=0),this.processAudioLevels(this.call.localParticipant,i)}for(const e of this.call.participants){if(e.id===this.call.localParticipant.id&&e.clientId===this.call.localParticipant.clientId)continue;let t=0;if(this.call.mediaFlow!==l.MediaFlow.SFU){const n=null===(i=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===i?void 0:i[e.getFullId()];if(n){const e=yield n.getConnectionStats(),i=Array.from(e.values()).filter((e=>this.isInboundAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));t=i.length>0?Math.max(...i):0}}else{const i=null===(n=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===n?void 0:n[e.getFullId()];if(i){const e=yield i.getConnectionStats(),n=Array.from(e.values()).filter((e=>this.isInboundAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));t=n.length>0?Math.max(...n):0}}e.muted&&(t=0),this.processAudioLevels(e,t)}}this.processActiveSpeakers(),this.call&&(this.call.emitActiveSpeakersChanged(this.activeSpeakers),this.call.emitDominantSpeakerChanged(this.dominantSpeaker))}catch(e){r.error(`[137] [CallId: ${null===(a=this.call)||void 0===a?void 0:a.id}] Error processing audio levels: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}))),s.POLLING_INTERVAL_MS),r.info(`[141] [CallId: ${null===(i=this.call)||void 0===i?void 0:i.id}] Active speaker detection started`)):r.error(`[47] [CallId: ${null===(t=this.call)||void 0===t?void 0:t.id}] Call or InternalCallHandler is not set`,{color:"red"}))}stop(){var e;this.processingInterval&&(clearInterval(this.processingInterval),this.processingInterval=null),this.activeSpeakers=[],this.dominantSpeaker=null,this.speakingStates.clear(),this.lastActiveSpeakers=[],this.lastDominantSpeaker=null,r.info(`[154] [CallId: ${null===(e=this.call)||void 0===e?void 0:e.id}] Active speaker detection stopped`)}addParticipant(e){var t;const i=this.getParticipantKey(e);this.speakingStates.has(i)||(this.speakingStates.set(i,{participant:e,audioLevel:0,smoothedAudioLevel:0,isSpeaking:!1,speakingStartTime:0}),r.info(`[167] [CallId: ${null===(t=this.call)||void 0===t?void 0:t.id}] Added participant for active speaker detection: ${e.getFullId()}`))}updateParticipant(e){const t=this.getParticipantKey(e),i=this.speakingStates.get(t);i&&this.speakingStates.set(t,Object.assign(Object.assign({},i),{participant:e}))}removeParticipant(e){var t,i,n;const a=this.getParticipantKey(e);this.speakingStates.delete(a),this.lastActiveSpeakers.some((t=>t.participant.id===e.id&&t.participant.clientId===e.clientId))&&this.processActiveSpeakers(),(null===(t=this.lastDominantSpeaker)||void 0===t?void 0:t.participant.id)===e.id&&(null===(i=this.lastDominantSpeaker)||void 0===i?void 0:i.participant.clientId)===e.clientId&&(this.dominantSpeaker=null,this.lastDominantSpeaker=null),r.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 t,i;const n=this.getParticipantKey(e);return null!==(i=null===(t=this.speakingStates.get(n))||void 0===t?void 0:t.smoothedAudioLevel)&&void 0!==i?i:null}isSpeaking(e){var t,i;const n=this.getParticipantKey(e);return null!==(i=null===(t=this.speakingStates.get(n))||void 0===t?void 0:t.isSpeaking)&&void 0!==i&&i}isDominantSpeaker(e){var t,i;return(null===(t=this.dominantSpeaker)||void 0===t?void 0:t.participant.id)===e.id&&(null===(i=this.dominantSpeaker)||void 0===i?void 0:i.participant.clientId)===e.clientId}processActiveSpeakers(){const e=Date.now(),t=new Map;this.speakingStates.forEach(((i,n)=>{t.set(n,this.updateSpeakingState(i,e))})),this.speakingStates=t;const i=Array.from(this.speakingStates.values()).filter((e=>e.isSpeaking)).sort(((e,t)=>t.smoothedAudioLevel-e.smoothedAudioLevel));JSON.stringify(i)!==JSON.stringify(this.lastActiveSpeakers)&&(this.activeSpeakers=i,this.lastActiveSpeakers=i),this.updateDominantSpeaker(i,e)}updateDominantSpeaker(e,t){if(0===e.length)return void(this.lastDominantSpeaker&&t-this.dominantSpeakerLastChangeTime>s.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=t);const i=e[0];i.participant.id===this.lastDominantSpeaker.participant.id&&i.participant.clientId===this.lastDominantSpeaker.participant.clientId||i.smoothedAudioLevel>.5&&t-i.speakingStartTime>s.DOMINANT_SPEAKER_HYSTERESIS_MS&&(this.dominantSpeaker=i,this.lastDominantSpeaker=i,this.dominantSpeakerLastChangeTime=t)}updateSpeakingState(e,t){const i=e.audioLevel>e.smoothedAudioLevel?Math.max(e.smoothedAudioLevel,e.smoothedAudioLevel+(e.audioLevel-e.smoothedAudioLevel)*s.ACTIVE_LEVEL_BOOST):Math.max(0,e.smoothedAudioLevel-(e.smoothedAudioLevel-e.audioLevel)*s.ACTIVE_LEVEL_DECAY);let n=e.isSpeaking,a=e.speakingStartTime;return i>=s.AUDIO_LEVEL_THRESHOLD?e.isSpeaking||(n=!0,a=t):e.isSpeaking&&t-e.speakingStartTime>s.SPEAKING_TIME_THRESHOLD_MS&&(n=!1),Object.assign(Object.assign({},e),{smoothedAudioLevel:i,isSpeaking:n,speakingStartTime:a})}processAudioLevels(e,t){var i;try{let i=null;if(e.muted)i=0;else if("number"==typeof t)i=t;else{const e=Array.from(t.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));i=e.length>0?Math.max(...e):0}if(null!==i){const t=this.getParticipantKey(e),n=this.speakingStates.get(t);n&&this.speakingStates.set(t,Object.assign(Object.assign({},n),{audioLevel:i}))}}catch(e){r.error(`[330] [CallId: ${null===(i=this.call)||void 0===i?void 0:i.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 t;return null!==(t=e.audioLevel)&&void 0!==t?t:null}isInboundAudio(e){return"inbound-rtp"===e.type&&"audio"===e.kind}}t.ActiveSpeakerManager=s,s.AUDIO_LEVEL_THRESHOLD=.1,s.SPEAKING_TIME_THRESHOLD_MS=250,s.DOMINANT_SPEAKER_HYSTERESIS_MS=1e3,s.ACTIVE_LEVEL_DECAY=.2,s.ACTIVE_LEVEL_BOOST=1.5,s.POLLING_INTERVAL_MS=150},250:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AudioTrack=void 0,t.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,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SceytCallClient=void 0;const n=i(650),a=i(645),l=i(185),r=i(297),s=i(228),o=i(65),c=i(302),d=i(578),u=(0,a.createLogger)("CallClient");class p extends r.TypedEventEmitter{constructor(e){super(),this.join=(e,t)=>{u.info(`[20] [CallId: ${e.id||"new"}] Join call`,{color:"cyan"});try{const i=this.getCall(e.id);if(i&&!this.sendSignalValidator.canSendSignalEvent(d.SignalEvent.JOIN,i)){const t=`Cannot join call with ID ${e.id||"new"} due to invalid call state or participant state.`;return u.warn(`[25] [CallId: ${e.id||"new"}] ${t}`,{color:"red"}),{success:!1,error:o.SceytCallException.BadRequest(4006,t)}}const n=this.internalCallHandler.joinCall(e,t);return(null==n?void 0:n.data)&&(null==n||n.data.activeSpeakerManager.addParticipant(n.data.localParticipant)),n}catch(t){return u.error(`[29] [CallId: ${e.id||"new"}] Join failed: ${t.message||JSON.stringify(t)}`,{color:"red"}),{success:!1,error:(0,s.toCallException)(t)}}},this.reject=(e,t,i)=>{if(!e)return u.warn("[39] [CallId: GLOBAL_LOGS] [REJECT] Attempted to reject a null call"),{success:!1,error:o.SceytCallException.BadRequest(4006,"Call object is null")};try{u.info(`[41] [CallId: ${e.id}] Rejecting call`,{color:"cyan"});const n=this.getCall(e.id);return n?(this.internalCallHandler.rejectCall(n,t,i),n.activeSpeakerManager.removeParticipant(n.localParticipant),{success:!0}):{success:!1,error:o.SceytCallException.BadRequest(4006,"Call not found")}}catch(t){return u.error(`[51] [CallId: ${e.id}] Rejection failed: ${t.message||JSON.stringify(t)}`,{color:"red"}),{success:!1,error:(0,s.toCallException)(t)}}},this.leave=e=>{if(!e)return u.warn("[57] [CallId: GLOBAL_LOGS] [LEAVE] Attempted to leave a null call"),{success:!1,error:o.SceytCallException.BadRequest(4006,"Call object is null")};try{u.info(`[62] [CallId: ${null==e?void 0:e.id}] Leaving call`,{color:"cyan"});const t=this.getCall(null==e?void 0:e.id);return t?(this.internalCallHandler.leaveCall(t,!0,"leave"),t.activeSpeakerManager.removeParticipant(t.localParticipant),{success:!0}):{success:!1,error:o.SceytCallException.BadRequest(4006,"Call not found")}}catch(t){return u.error(`[71] [CallId: ${null==e?void 0:e.id}] Leave failed: ${t.message||JSON.stringify(t)}`,{color:"red"}),{success:!1,error:(0,s.toCallException)(t)}}},this.getCall=e=>this.internalCallHandler.activeCalls.find((t=>t.id===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.sendSignalValidator=new c.SendSignalValidator,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}get RecentCallQueryBuilder(){return l.RecentCallQueryBuilder}}t.SceytCallClient=p},998:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{o(n.next(e))}catch(e){l(e)}}function s(e){try{o(n.throw(e))}catch(e){l(e)}}function o(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,s)}o((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Call=void 0;const a=i(650),l=i(578),r=i(547),s=i(645),o=i(258),c=i(297),d=i(228),u=(0,s.createLogger)("Call");class p extends c.TypedEventEmitter{constructor({id:e,sessionId:t="",mediaFlow:i,createdBy:r="",localParticipant:s,participants:c,metadata:p,chatClient:g,isCallSilenced:h}){super(),this.state=l.CallState.Idle,this._localAudioTracks=[],this._localVideoTracks=[],this._muted=!1,this._onHold=!1,this.videoEnabled=!1,this.eventsQueue=new Map,this.isCallSilenced=!1,this.videoDeviceId=null,this.getStats=()=>n(this,void 0,void 0,(function*(){try{const e=[];for(const t of this.participants){const i=yield this.getParticipantStats(t);i.success&&i.data&&e.push(i.data)}return{success:!0,data:e}}catch(e){return u.error(`[502] [CallId: ${this.id}] Error getting call stats ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}})),this.getParticipantStats=e=>n(this,void 0,void 0,(function*(){try{u.info(`[503] [CallId: ${this.id}] getParticipantStats for ${e.getFullId()}`,{color:"cyan"});const t=a.InternalCallHandler.getInstance().callParticipantsRTCMap[this.id],i=null==t?void 0:t[e.getFullId()];return i?{success:!0,data:yield i.getConnectionStats()}:{success:!1,error:(0,d.toCallException)(new Error("Participant RTC client not found"))}}catch(e){return u.error(`[504] [CallId: ${this.id}] Error getting participant stats ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}})),this.id=e,this.sessionId=t,this.createdBy=r,this.participants=c,this.localParticipant=s,this.mediaFlow=i,this.metadata=p,this.activeSpeakerManager=new o.ActiveSpeakerManager(this),this.chatClient=g,this.isCallSilenced=h}emitAudioTrackAdded(e,t){this.emit("audioTrackAdded",{call:this,participant:e,track:t})}emitAudioTrackRemoved(e){this.emit("audioTrackRemoved",{call:this,participant:e})}emitVideoTrackAdded(e,t){this.emit("videoTrackAdded",{call:this,participant:e,track:t})}emitVideoTrackRemoved(e){this.emit("videoTrackRemoved",{call:this,participant:e})}emitCallStateChanged(e){this.emit("callStateChanged",{call:this,state:e})}emitParticipantStateChanged(e,t,i){this.emit("participantStateChanged",{call:this,participant:e,state:t,reason:i})}emitParticipantConnectionStateChanged(e,t){this.emit("participantConnectionStateChanged",{call:this,participant:e,state:t})}emitParticipantEvent(e,t){this.emit("participantEvent",{call:this,participant:e,event:t})}emitParticipantsAdded(e,t){this.emit("participantsAdded",{call:this,participants:e,entryType:t})}emitActiveSpeakersChanged(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})}clearEventsQueue(){this.eventsQueue.clear()}setState(e,t){const i=new r.CallStateMachine(this.id).updateState(e,this.state,t);return i&&(this.state=e,e===l.CallState.Connected?this.activeSpeakerManager.start(a.InternalCallHandler.getInstance()):this.activeSpeakerManager.stop(),this.emitCallStateChanged(e)),i}addParticipants(e){const t=e=>a.InternalCallHandler.getInstance().addParticipantsToCall(e,this);return this.sessionId?t(e):this.eventsQueue.set("ADD_PARTICIPANTS",(()=>t(e))),{success:!0}}addParticipantToList(e){this.participants.push(e)}kickParticipantFromList(e){this.participants=this.participants.filter((t=>t.id!==e.id&&t.clientId!==e.clientId))}setSessionId(e){this.sessionId=e}setCreatedBy(e){this.createdBy=e}changeMediaFlow(e){this.mediaFlow!=e&&(this.mediaFlow=e,this.emitMediaFlowChanged(e))}switchToSFU(e){return n(this,void 0,void 0,(function*(){const t=t=>{u.info(`[159] [CallId: ${this.id}] handle switch call to ${l.MediaFlow.SFU}`,{color:"cyan"});const i=a.InternalCallHandler.getInstance(),n=i.activeCalls.find((e=>e.id===t));return i.switchCallToSfu(n,e)};return this.sessionId?t(this.id):this.eventsQueue.set(l.SignalEvent.SWITCH_MEDIA_FLOW,(()=>t(this.id))),{success:!0}}))}mute(e,t){this.muted=e,this.localParticipant.setMuted(e),this.emitParticipantEvent(this.localParticipant,e?"Mute":"Unmute");const i=e=>{a.InternalCallHandler.getInstance().sendAudioEnable(this,e,t)};return this.sessionId?i(e):this.eventsQueue.set(l.SignalEvent.MUTE,(()=>i(e))),{success:!0}}hold(e){this.onHold=e;const t=e=>{a.InternalCallHandler.getInstance().sendHold(this,e)};return this.sessionId?t(e):this.eventsQueue.set(l.SignalEvent.HOLD,(()=>t(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 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}enableVideo(e,t,i){return n(this,void 0,void 0,(function*(){const r=a.InternalCallHandler.getInstance();let s=[];return this.localVideoTracks.forEach((e=>{e.stop()})),this.localParticipant.videoTracks.forEach((e=>{e.enabled=!1})),yield(()=>n(this,void 0,void 0,(function*(){var a,o,c;try{if(e){const e=(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind));this.videoDeviceId&&(e.some((e=>e.deviceId===this.videoDeviceId))||(u.warn(`Previously selected video device with ID ${this.videoDeviceId} not found. Falling back to default camera.`),this.setVideoDeviceId(null)));const t=yield navigator.mediaDevices.getUserMedia({video:{deviceId:this.videoDeviceId?{exact:this.videoDeviceId}:void 0,width:{min:640,max:1280},height:{min:480,max:720}}});s=t.getVideoTracks(),s.sort(((e,t)=>(e.getSettings().deviceId||"")===this.videoDeviceId?-1:1)),this.setVideoDeviceId((null===(a=s[0])||void 0===a?void 0:a.getSettings().deviceId)||null)}else s=this.localVideoTracks;!this.videoDeviceId&&s.length>0&&this.setVideoDeviceId((null===(o=s[0])||void 0===o?void 0:o.getSettings().deviceId)||null),this.localVideoTracks=s,this.localParticipant.setVideoTracks(s),this.localParticipant.videoEnabled=e,this.emitVideoTrackAdded(this.localParticipant,s[0]),this.emitParticipantEvent(this.localParticipant,e?"VideoEnabled":"VideoDisabled"),this.localParticipant.videoTracks.forEach((t=>{t.enabled=e})),this.localVideoTracks&&(null===(c=this.localVideoTracks)||void 0===c?void 0:c.length)&&(yield r.changeVideoTracks(this,this.localVideoTracks[0],e));const p=(e,i)=>n(this,void 0,void 0,(function*(){try{yield r.changeVideoTracks(this,i,e),r.sendVideoEnabled(this,e,t)}catch(e){return u.error(`[323] [CallId: ${this.id}] Failed to send video enabled signal: message: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),void(null==t||t({error:(0,d.toCallException)(e)}))}}));i||(this.sessionId?p(e,s[0]):this.eventsQueue.set(e?l.SignalEvent.VIDEO_ON:l.SignalEvent.VIDEO_OFF,(()=>p(e,s[0]))))}catch(e){return u.error(`[325] [CallId: ${this.id}] Error enabling video ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}})))(),{success:!0}}))}shareScreen(e,t){return n(this,void 0,void 0,(function*(){let i=[];try{if(this.localParticipant.setScreenSharing(e),e){const t=yield navigator.mediaDevices.getDisplayMedia({video:{width:{max:1280},height:{max:720},frameRate:{max:30}}});if(this.localVideoTracks.forEach((e=>{e.stop()})),i=t.getVideoTracks(),t.addEventListener("inactive",(()=>{this.localParticipant.screenSharing&&this.stopScreenShare()})),this.localVideoTracks=i,this.localParticipant.setVideoTracks(i),this.emitVideoTrackAdded(this.localParticipant,i[0]),this.localParticipant.videoTracks.forEach((t=>{t.enabled=e})),i&&i.length){const t=a.InternalCallHandler.getInstance();yield t.changeVideoTracks(this,i[0],e,!0)}this.emitParticipantEvent(this.localParticipant,"ScreenSharingStarted")}else this.localParticipant.videoEnabled&&!e?(this.emitParticipantEvent(this.localParticipant,"ScreenSharingStopped"),yield this.enableVideo(!0,t,!0)):this.emitParticipantEvent(this.localParticipant,e?"ScreenSharingStarted":"ScreenSharingStopped");const r=e=>n(this,void 0,void 0,(function*(){const i=a.InternalCallHandler.getInstance();yield i.sendScreenShare(this,e,t)}));return this.sessionId?r(e):this.eventsQueue.set(e?l.SignalEvent.SCREEN_SHARE_ON:l.SignalEvent.SCREEN_SHARE_OFF,(()=>r(e))),{success:!0}}catch(e){return u.error(`[324] [CallId: ${this.id}] Error sharing screen ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.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 u.error(`[306] [CallId: ${this.id}] Error getting video devices ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.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 u.error(`[307] [CallId: ${this.id}] Error getting audio devices ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}}))}selectVideoDevice(e){return n(this,void 0,void 0,(function*(){if(this.setVideoDeviceId(e),!this.videoEnabled)return{success:!0};try{this.localVideoTracks.forEach((e=>{e.stop()}));const t=(yield navigator.mediaDevices.getUserMedia({video:{deviceId:{exact:e},width:{min:640,max:1280},height:{min:480,max:720}}})).getVideoTracks();this.localVideoTracks=t,this.localParticipant.setVideoTracks(t),this.emitVideoTrackAdded(this.localParticipant,t[0]);const i=a.InternalCallHandler.getInstance();return yield i.changeVideoTracks(this,t[0],this.localParticipant.videoEnabled),{success:!0}}catch(e){return u.error(`[308] [CallId: ${this.id}] Error selecting video device ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}}))}selectAudioDevice(e){return n(this,void 0,void 0,(function*(){try{const t=a.InternalCallHandler.getInstance(),i=(yield navigator.mediaDevices.getUserMedia({audio:{deviceId:{exact:e}}})).getAudioTracks();return this.localAudioTracks=i,this.localParticipant.setAudioTracks(i),yield t.changeAudioTracks(this,i[0],this.localParticipant.muted),{success:!0}}catch(e){return u.error(`[309] [CallId: ${this.id}] Error selecting audio device ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}}))}setVideoEnabled(e){this.videoEnabled=e}getParticipant(e,t){return this.participants.find((i=>i.id===e&&i.clientId===t))}sendRinging(e){return a.InternalCallHandler.getInstance().sendRinging(this,e)}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}}}t.Call=p},228:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.checkCode=t.toCallException=t.handleAck=void 0;const n=i(65);function a(e,t){switch(e){case 4e3:return n.SceytCallException.BadSignal(e,t);case 4001:return n.SceytCallException.CallNotFound(e,t);case 4002:return n.SceytCallException.ParticipantNotFound(e,t);case 4005:case 4003:return n.SceytCallException.NotAllowed(e,t);case 4004:return n.SceytCallException.ParticipantAlreadyExists(e,t);case 5001:return n.SceytCallException.InternalError(e,t);case 9901:case 9903:case 9904:return n.SceytCallException.NetworkError(e,t);case 9902:return n.SceytCallException.Timeout(e,t);case 4006:return n.SceytCallException.BadRequest(e,t);default:return n.SceytCallException.Unknown(e,t)}}t.handleAck=function(e){return e.error&&a(e.error.code,e.error.message),e},t.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))},t.checkCode=a},65:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SceytCallException=void 0;class i extends Error{get isResendable(){return this._isResendable}constructor(e,t,i="SceytCallException"){super(e),this.code=t,this.name=i,this._isResendable=!1,this.name=i}static BadSignal(e,t){return new i(t,e,"BadSignal")}static CallNotFound(e,t){return new i(t,e,"CallNotFound")}static ParticipantNotFound(e,t){return new i(t,e,"ParticipantNotFound")}static NotAllowed(e,t){return new i(t,e,"NotAllowed")}static ParticipantAlreadyExists(e,t){return new i(t,e,"ParticipantAlreadyExists")}static InternalError(e,t){const n=new i(t,e,"InternalError");return n._isResendable=!0,n}static NetworkError(e,t){const n=new i(t,e,"NetworkError");return n._isResendable=!0,n}static Timeout(e,t){const n=new i(t,e,"Timeout");return n._isResendable=!0,n}static BadRequest(e,t){return new i(t,e,"BadRequest")}static Unknown(e,t){return new i(t,e)}}t.SceytCallException=i},650:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{o(n.next(e))}catch(e){l(e)}}function s(e){try{o(n.throw(e))}catch(e){l(e)}}function o(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,s)}o((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.InternalCallHandler=void 0;const a=i(787),l=i(546),r=i(786),s=i(578),o=i(998),c=i(489),d=i(645),u=i(429),p=i(65),g=i(680),h=i(228),S=(0,d.createLogger)("InternalCallHandler");class C{constructor(e){this.callParticipantsRTCMap={},this.activeCalls=[],this.callEvents={},this.handleMediaConnectedSignal=e=>{if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){let i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));if(i||(i=t.participants.find((t=>t.id===e.from.split("/")[0]&&!t.clientId)),i?i.clientId=e.from.split("/")[1]:(i=new a.Participant(e.from),t.addParticipantToList(i),t.emitParticipantsAdded([i],s.ParticipantEntryType.ADDED))),i&&t.localParticipant.state===s.ParticipantState.Joined&&t.localParticipant.getFullId()!==i.getFullId()&&(!this.callParticipantsRTCMap[t.id]||!this.callParticipantsRTCMap[t.id][i.getFullId()]||(null==i?void 0:i.shouldResetPeerConnection))){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[968] [CallId: ${t.id}] SYNC CONNECT failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`):e.event!==s.SignalEvent.ERROR||S.error(`[971] [CallId: ${t.id}] SYNC CONNECT failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};S.info(`[975] [CallId: ${t.id}] SYNC CONNECT to participant ${i.getFullId()}`,{color:"blue"}),this.signalingClient.clearParticipantSignals(t.id,i.getFullId()),this.signalingClient.sendSignalMessage({to:i.getFullId(),event:s.SignalEvent.CONNECT,mediaFlow:t.mediaFlow,callId:t.id,sessionId:t.sessionId},e)}}},this.onIceCandidate=(e,t,i)=>{var n,a;if(i.mediaFlow!==s.MediaFlow.SFU)if(S.info(`[996] [CallId: ${i.id}] onIceCandidate, participantID: ${e.getFullId()}, candidate: ${null===(n=t.candidate)||void 0===n?void 0:n.candidate}, type: ${null===(a=t.candidate)||void 0===a?void 0:a.type}`,{color:"blue"}),t.candidate&&t.candidate.candidate){let n="";if(!/\bufrag\s+\S+/i.test(t.candidate.candidate)&&this.callParticipantsRTCMap[i.id]&&this.callParticipantsRTCMap[i.id][e.getFullId()]){const t=this.callParticipantsRTCMap[i.id][e.getFullId()];t&&(n=` ufrag ${t.getLocalSdpUfrag()}`)}const a={candidate:t.candidate.candidate+n,sdpMid:t.candidate.sdpMid||"",sdpMLineIndex:t.candidate.sdpMLineIndex||0};try{const t=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[1007] [CallId: ${i.id}] SYNC ICE failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`):e.event!==s.SignalEvent.ERROR||S.error(`[1011] [CallId: ${i.id}] SYNC ICE failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};this.signalingClient.sendSignalMessage({to:this.getParticipantId(e),event:s.SignalEvent.ICE,mediaFlow:i.mediaFlow,callId:i.id,sessionId:i.sessionId,ice:a},t)}catch(t){S.error(`[1023] [CallId: ${i.id}] Failed to send ICE candidate to ${e.getFullId()}: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}else S.info(`[1025] [CallId: ${i.id}] ICE gathering complete for participant ${e.getFullId()} (null candidate)`,{color:"blue"});else S.info(`[1024] [CallId: ${i.id}] onIceCandidate, participantID: ${e.getFullId()}, skip for SFU`,{color:"blue"})},this.onTrack=(e,t,i)=>{const n=null==i?void 0:i.track;S.info(`[1032] [CallId: ${e.id}] onTrack, participantID: ${t.getFullId()}, kind: ${n.kind}`,{color:"blue"}),"audio"===(null==n?void 0:n.kind)?(t.setAudioTracks([n]),e.emitAudioTrackAdded(t,n),n.onended=()=>{S.info(`[1038] [CallId: ${e.id}] Audio track ended for participant ${t.getFullId()}`,{color:"yellow"}),t.setAudioTracks([]),e.emitAudioTrackRemoved(t)}):"video"===(null==n?void 0:n.kind)&&(t.setVideoTracks([n]),e.videoEnabled&&!t.videoEnabled&&e.setVideoEnabled(!0),e.emitVideoTrackAdded(t,n),n.onended=()=>{S.info(`[1052] [CallId: ${e.id}] Video track ended for participant ${t.getFullId()}`,{color:"yellow"}),t.setVideoTracks([]),e.emitVideoTrackRemoved(t)})},this.addParticipantsToCall=(e,t)=>{try{if(e.forEach((e=>{const i=t.participants.filter((t=>t.id===e));if(i.length>0)for(const e of i)e?e.state!==s.ParticipantState.Joined&&e.state!==s.ParticipantState.Ringing&&(e.updateState(s.ParticipantState.Idle,t.id),e.updateConnectionState(s.ParticipantConnectionState.Idle,t.id),t.emitParticipantStateChanged(e,s.ParticipantState.Idle),t.emitParticipantConnectionStateChanged(e,s.ParticipantConnectionState.Idle)):(t.addParticipantToList(e),t.emitParticipantsAdded([e],s.ParticipantEntryType.ADDED));else{const i=new a.Participant(e);t.addParticipantToList(i),t.emitParticipantsAdded([i],s.ParticipantEntryType.ADDED)}})),S.info(`[1547] [CallId: ${t.id}] added participants to call: ${e}, callId: ${t.id}`,{color:"light-green"}),e.length>0){const i=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[1551] [CallId: ${t.id}] SYNC INVITE failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==s.SignalEvent.ERROR||S.error(`[1555] [CallId: ${t.id}] SYNC INVITE failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};return this.signalingClient.sendSignalMessage({callId:t.id,sessionId:t.sessionId,event:s.SignalEvent.INVITE,participants:e.map((e=>new a.Participant(e).serialize()))},i),!0}return!1}catch(i){return S.error(`[1567] [CallId: ${t.id}] Failed to add participants to call: ${e}, callId: ${t.id} message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"}),!1}},this.sendSignalScreenShare=(e,t,i)=>{try{const n=t=>t instanceof p.SceytCallException||t instanceof Error?(S.error(`[1679] [CallId: ${e.id}] SYNC SCREEN_SHARE_ON failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`),void(null==i||i({error:(0,h.toCallException)(t)}))):t.event===s.SignalEvent.ERROR?(S.error(`[1683] [CallId: ${e.id}] SYNC SCREEN_SHARE_ON failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`),void(null==i||i({error:(0,h.toCallException)(t.error)}))):void 0;return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:t?s.SignalEvent.SCREEN_SHARE_ON:s.SignalEvent.SCREEN_SHARE_OFF,sessionId:e.sessionId},n),!0}catch(t){return S.error(`[1694] [CallId: ${e.id}] Failed to send screen share signal: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"}),null==i||i({error:(0,h.toCallException)(t)}),!1}},this.setupMediaStream=e=>n(this,void 0,void 0,(function*(){try{const t=yield navigator.mediaDevices.getUserMedia({video:!1,audio:!0}),i=(0,c.getEmptyVideoTrack)(),n=t.getAudioTracks();return e.localAudioTracks=n,i.forEach((e=>e.enabled=!1)),e.localVideoTracks=i,e.localParticipant.setVideoTracks(i),e.localParticipant.audioTracks=n,{videoTracks:i,audioTracks:n}}catch(t){throw S.error(`[1945] [CallId: ${e.id}] Failed to get media: message: ${t instanceof Error?t.message:JSON.stringify(t)}`),(0,h.toCallException)(t)}})),this.chatClient=e,this.user=e.user,this.clientId=e.clientId,this.signalingClient=new r.Signaling(e,this.handleSignalMessage.bind(this));const t=new this.chatClient.ConnectionListener;if(t.onConnectionStateChanged=e=>{if(S.info(`[46] [CallId: GLOBAL_LOGS] Signaling connection state changed: ${e}`,{color:"cyan"}),"Connected"===e){this.activeCalls.forEach((e=>{const t=this.signalingClient.signalingQueues.get(e.id);t&&t.triggerSignalProcessing()}));const e=setTimeout((()=>{this.signalingClient.sendSignalMessage({event:s.SignalEvent.GET_CALL,callId:""},(e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[57] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed ${e instanceof p.SceytCallException||e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}):e.event!==s.SignalEvent.ERROR?this.syncActiveCalls(e):S.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"),clearTimeout(e)}),1e3)}},this.chatClient.addConnectionListener("listener_id",t),"Connected"===this.chatClient.connectionState){const e=setTimeout((()=>{this.signalingClient.sendSignalMessage({event:s.SignalEvent.GET_CALL,callId:""},(e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[74] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==s.SignalEvent.ERROR?this.syncActiveCalls(e):S.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"),clearTimeout(e)}),1e3)}C.instance=this}syncActiveCalls(e){var t,i,n;const l=this.activeCalls;try{if(!(null==e?void 0:e.calls)&&!(null==e?void 0:e.calls))return;if(e.event!==s.SignalEvent.SUCCESS)return void S.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 r of l){if(!(null==r?void 0:r.sessionId)){S.warn(`[105] [CallId: ${r.id}] Call has no sessionId, skipping`);continue}const l=e.calls.find((e=>(null==e?void 0:e.id)===r.id&&(null==e?void 0:e.sessionId)===r.sessionId));if(l)if(r.mediaFlow!==s.MediaFlow.SFU&&l.mediaFlow===s.MediaFlow.SFU&&(this.updateCallMetadata(r,l),this.handleMediaFlowSwitch(r)),this.syncParticipants(r,l.participants),r.localParticipant.state<=s.ParticipantState.Joined&&(r.state===s.CallState.Connected||r.state===s.CallState.Connecting)){for(const e of r.participants)if(r.mediaFlow!==s.MediaFlow.SFU&&e.connectionState===s.ParticipantConnectionState.Connected&&e.id!==r.localParticipant.id&&e.clientId!==r.localParticipant.clientId){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[139] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==s.SignalEvent.ERROR||S.error(`[143] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({event:s.SignalEvent.MEDIA_CONNECTED,callId:r.id,sessionId:r.sessionId,mediaFlow:r.mediaFlow,to:r.id},e)}if(r.mediaFlow===s.MediaFlow.SFU&&(null===(t=r.serverParticipant)||void 0===t?void 0:t.connectionState)===s.ParticipantConnectionState.Connected&&r.state===s.CallState.Connected){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[158] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==s.SignalEvent.ERROR||S.error(`[162] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({event:s.SignalEvent.MEDIA_CONNECTED,callId:r.id,sessionId:r.sessionId,mediaFlow:r.mediaFlow,to:r.id},e)}if(r.mediaFlow!==s.MediaFlow.SFU||this.callParticipantsRTCMap[r.id]&&this.callParticipantsRTCMap[r.id][r.id]||r.state!==s.CallState.Connected){if(r.mediaFlow===s.MediaFlow.SFU&&r.serverParticipant&&(null===(n=r.serverParticipant)||void 0===n?void 0:n.connectionState)!==s.ParticipantConnectionState.Reconnecting&&r.state===s.CallState.Connected){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[199] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==s.SignalEvent.ERROR||S.error(`[203] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};S.info(`[205] [CallId: ${r.id}] Sending offer to server participant when server participant is not connected: ${r.serverParticipant.getFullId()}`,{color:"yellow"}),this.sendOfferPeerToPeer(r,r.serverParticipant,e)}}else{if((null===(i=r.serverParticipant)||void 0===i?void 0:i.id)!==r.id){const e=new a.Participant(r.id);r.setServerParticipant(e)}if(r.serverParticipant){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[181] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==s.SignalEvent.ERROR||S.error(`[185] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};S.info(`[188] [CallId: ${r.id}] Sending offer to server participant when there is no server participant in the call: ${r.serverParticipant.getFullId()}`,{color:"yellow"}),this.sendOfferPeerToPeer(r,r.serverParticipant,e)}}}else this.leaveCall(r,!1,"syncActiveCalls");else this.closeCall(r)}const r=this.activeCalls.find((e=>e.state===s.CallState.Connected));r&&!e.calls.find((e=>e.id===r.id&&e.sessionId===r.sessionId))&&this.closeCall(r),this.activeCalls=this.activeCalls.filter((t=>{var i;return!(!(null===(i=null==e?void 0:e.calls)||void 0===i?void 0:i.find((e=>e.id===t.id)))&&t.sessionId&&(t.clearEventsQueue(),t.participants.forEach((e=>{this.signalingClient.clearParticipantSignals(t.id,e.getFullId())})),this.signalingClient.clearCallSignals(t.id),1))})),e.calls.forEach((e=>{!this.activeCalls.find((t=>(null==t?void 0:t.id)===(null==e?void 0:e.id)))&&e.id&&e.sessionId&&this.findOrCreateCall({id:e.id,sessionId:e.sessionId,mediaFlow:e.mediaFlow,participantIds:[],metadata:e.metadata,createdBy:e.createdBy},e.participants)})),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}catch(e){S.error(`[248] [CallId: GLOBAL_LOGS] Error syncing calls after reconnection: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}setCallEvent(e,t){this.callEvents[e]=t}handleSignalMessage(e){switch(S.info(`[253] [CallId: ${e.callId}] Received ${s.SignalEvent[e.event]}: ${JSON.stringify(Object.assign({},e))}`,{color:"green"}),e.event||0){case s.SignalEvent.OFFER:this.handleOfferSignal(e);break;case s.SignalEvent.ANSWER:this.handleAnswerSignal(e);break;case s.SignalEvent.JOIN:this.handleJoinSignal(e);break;case s.SignalEvent.LEAVE:this.handleLeaveSignal(e);break;case s.SignalEvent.INVITE:this.handleInviteSignal(e);break;case s.SignalEvent.CLOSE:this.handleCloseSignal(e);break;case s.SignalEvent.DECLINE:this.handleDeclineSignal(e);break;case s.SignalEvent.RINGING:this.handleRingingSignal(e);break;case s.SignalEvent.SWITCH_MEDIA_FLOW:this.handleSwitchMediaFlowSignal(e);break;case s.SignalEvent.ICE:this.handleIceSignal(e);break;case s.SignalEvent.VIDEO_ON:this.handleVideoOnSignal(e);break;case s.SignalEvent.VIDEO_OFF:this.handleVideoOffSignal(e);break;case s.SignalEvent.SCREEN_SHARE_ON:this.handleScreenShareOnSignal(e);break;case s.SignalEvent.SCREEN_SHARE_OFF:this.handleScreenShareOffSignal(e);break;case s.SignalEvent.MUTE:this.handleMuteSignal(e);break;case s.SignalEvent.UNMUTE:this.handleUnmuteSignal(e);break;case s.SignalEvent.HOLD:this.handleHoldSignal(e);break;case s.SignalEvent.UNHOLD:this.handleUnholdSignal(e);break;case s.SignalEvent.KICK:this.handleKickSignal(e);break;case s.SignalEvent.UPDATE:this.handleUpdateSignal(e);break;case s.SignalEvent.NO_ANSWER:this.handleNoAnswerSignal(e);break;case s.SignalEvent.MEDIA_CONNECTED:this.handleMediaConnectedSignal(e);break;case s.SignalEvent.CONNECT:this.handleConnectSignal(e);break;default:S.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 t,i,a,l;if(!this.activeCalls)return void S.warn(`[342] [CallId: ${e.callId}] No active calls found for send offer participant: ${e.from}`,{color:"red"});let r;try{const o=this.activeCalls.find((t=>t.id===e.callId));if(!o)return void S.warn(`[348] [CallId: ${e.callId}] No active call found for send offer participant: ${e.from}`,{color:"red"});if(o.state!==s.CallState.Connected)return void S.warn(`[353] [CallId: ${e.callId}] Call is not connected for send offer participant: ${e.from}`,{color:"red"});let c=null==o?void 0:o.participants.find((t=>t.getFullId()===e.from));if(c){r=c.getFullId();const d=this.callParticipantsRTCMap[o.id]&&(null===(t=this.callParticipantsRTCMap[o.id])||void 0===t?void 0:t[c.getFullId()]);let u=null==d?void 0:d.getSessionId();!c.shouldResetPeerConnection&&d&&u===(null===(i=e.sessionData)||void 0===i?void 0:i.id)||(this.closePeerConnections(o.id,c.getFullId()),o.activeSpeakerManager.removeParticipant(c),this.addParticipantToRTCMap(o,c),c.setShouldResetPeerConnection(!1),(this.callParticipantsRTCMap[o.id]&&(null===(a=this.callParticipantsRTCMap[o.id])||void 0===a?void 0:a[c.getFullId()])).setSessionId((null===(l=e.sessionData)||void 0===l?void 0:l.id)||"")),this.signalingClient.clearParticipantSignals(o.id,c.getFullId()),this.setRemoteDescription(o.id,c.getFullId(),(0,g.toSessionDescription)(e.sessionData,"offer")).then((()=>n(this,void 0,void 0,(function*(){var t,i,n;if(!c)return void S.info(`[392] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});const a=this.callParticipantsRTCMap[o.id][c.getFullId()],l=this.activeCalls.find((e=>e.id===o.id));l&&(l.mediaFlow!==s.MediaFlow.SFU||l.mediaFlow===s.MediaFlow.SFU&&c.id===(null===(t=null==l?void 0:l.serverParticipant)||void 0===t?void 0:t.id))&&(yield this.addTracksToPeerConnection(o,c.getFullId(),!1)),a.createAnswer((null===(i=e.sessionData)||void 0===i?void 0:i.id)||"",(null===(n=e.sessionData)||void 0===n?void 0:n.version)||"",o.mediaFlow).then((t=>{if(!c)return void S.info(`[392] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});if(!t)return void S.error(`[456] [CallId: ${o.id}] Failed to create answer for participant: ${c.getFullId()}`,{color:"red"});const i=a.getRemoteSdpUfrag();if(i&&a.iceQueueMap[c.getFullId()]){const e=a.iceQueueMap[c.getFullId()][i];if(e&&e.length>0)for(const t of e)a.addIceCandidate(t,c.getFullId())}this.signalingClient.sendSignalMessage({to:e.from,mediaFlow:e.mediaFlow,callId:o.id,event:s.SignalEvent.ANSWER,sessionData:t,sessionId:e.sessionId,metadata:e.metadata},(e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[386] [CallId: ${o.id}] SYNC ANSWER failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==s.SignalEvent.ERROR||S.error(`[389] [CallId: ${o.id}] SYNC ANSWER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})}))}))}))))}else S.info(`[402] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"})}catch(t){S.error(`[406] [CallId: ${e.callId}] Failed to handle offer: ${r} message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"})}}handleAnswerSignal(e){var t;if(this.activeCalls)try{const i=this.activeCalls.find((t=>t.id===e.callId));if(i){let n;if(n=i.serverParticipant&&i.serverParticipant.getFullId()===e.from?i.serverParticipant:i.participants.find((t=>t.getFullId()===e.from)),n){const a=null===(t=e.sessionData)||void 0===t?void 0:t.version;if(!a||a!==this.callParticipantsRTCMap[i.id][n.getFullId()].getVersion())return void S.warn(`[412] [CallId: ${i.id}] Version is not set or is the same as the current version: ${a}`,{color:"red"});this.callParticipantsRTCMap[i.id][n.getFullId()].setVersion(a),this.setRemoteDescription(i.id,n.getFullId(),(0,g.toSessionDescription)(e.sessionData,"answer")).then((()=>{if(!n)return void S.info(`[462] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});const t=this.callParticipantsRTCMap[i.id][n.getFullId()].getRemoteSdpUfrag();if(t&&this.callParticipantsRTCMap[i.id][n.getFullId()].iceQueueMap[n.getFullId()]){const e=this.callParticipantsRTCMap[i.id][n.getFullId()].iceQueueMap[n.getFullId()][t];if(e&&e.length>0)for(const t of e)this.callParticipantsRTCMap[i.id][n.getFullId()].addIceCandidate(t,n.getFullId())}}))}}}catch(t){S.error(`[435] [CallId: ${e.callId}] Failed to handle answer: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"})}}sendOfferPeerToPeer(e,t,i){return n(this,void 0,void 0,(function*(){this.callParticipantsRTCMap.hasOwnProperty(e.id)&&this.callParticipantsRTCMap[e.id].hasOwnProperty(t.getFullId())||(this.addParticipantToRTCMap(e,t),yield this.addTracksToPeerConnection(e,t.getFullId(),!0));const n=this.callParticipantsRTCMap[e.id][t.getFullId()];let a=n.getVersion();n.setVersion(a?String(Number(a)+1):"1"),a=n.getVersion();let l=n.getSessionId();l||(l=(0,u.v4)(),n.setSessionId(l)),n.createOffer(l,a,e.mediaFlow).then((n=>{n?this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:s.SignalEvent.OFFER,sessionData:n,to:t.getFullId(),sessionId:e.sessionId},i):S.error(`[456] [CallId: ${e.id}] Failed to create offer for participant: ${t.getFullId()}`,{color:"red"})}))}))}handleJoinSignal(e){if(this.activeCalls)try{const t=this.activeCalls.find((t=>t.id===e.callId));if(t){let i=!1,n=t.participants.find((t=>t.getFullId()===e.from));if(n||(n=t.participants.find((t=>t.id===e.from.split("/")[0]&&(t.clientId===e.from.split("/")[1]||!t.clientId))),n?n.clientId=e.from.split("/")[1]:n=void 0),!n&&t.localParticipant.screenSharing&&this.sendSignalScreenShare(t,!0),n||(n=new a.Participant(e.from),t.addParticipantToList(n),i=!0),t.mediaFlow===s.MediaFlow.P2P&&t.localParticipant.state===s.ParticipantState.Joined&&this.isPolitePeer(e.from,t.localParticipant.getFullId())){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[495] [CallId: ${t.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==s.SignalEvent.ERROR||S.error(`[499] [CallId: ${t.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};S.info(`[503] [CallId: ${t.id}] Sending offer to participant: ${n.getFullId()}`),this.sendOfferPeerToPeer(t,n,e)}n.updateState(s.ParticipantState.Joined,t.id),S.info(`[503] [CallId: ${t.id}] Participant joined call shouldSendEventInvited: ${i}`),i?t.emitParticipantsAdded([n],s.ParticipantEntryType.ADDED):t.emitParticipantStateChanged(n,s.ParticipantState.Joined)}}catch(t){S.error(`[514] [CallId: ${e.callId}] Failed to handle USER_JOINED: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"})}}handleLeaveSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.id===e.from.split("/")[0]&&(t.clientId===e.from.split("/")[1]||!t.clientId)));i&&i.updateState(s.ParticipantState.Left,t.id)&&(this.closePeerConnections(t.id,i.getFullId()),t.activeSpeakerManager.removeParticipant(i),i.setMuted(!1),t.emitParticipantEvent(i,"Mute"),i.setVideoEnabled(!1),t.emitParticipantEvent(i,"VideoDisabled"),i.setScreenSharing(!1),t.emitParticipantEvent(i,"ScreenSharingStopped"),i.setHold(!1),t.emitParticipantEvent(i,"Unhold"),t.emitParticipantStateChanged(i,s.ParticipantState.Left),i.updateConnectionState(s.ParticipantConnectionState.Idle,t.id)&&t.emitParticipantConnectionStateChanged(i,s.ParticipantConnectionState.Idle))}}handleInviteSignal(e){if(!e||!e.callId)return void S.warn(`[545] [CallId: ${e.callId}] Received invalid invite signal message`);const t=this.activeCalls.find((t=>t.id===e.callId)),i=(null==e?void 0:e.to)===this.user.id;i&&t&&t.participants.forEach((e=>{e.id===this.user.id&&(e.updateConnectionState(s.ParticipantConnectionState.Idle,t.id),e.updateState(s.ParticipantState.Idle,t.id),null==t||t.emitParticipantConnectionStateChanged(e,s.ParticipantConnectionState.Idle),null==t||t.emitParticipantStateChanged(e,s.ParticipantState.Idle))})),t?this.handleExistingCallInvite(t,e,i):this.handleNewCallInvite(e,i),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}handleExistingCallInvite(e,t,i){var n,a;if(i){e.localParticipant.updateConnectionState(s.ParticipantConnectionState.Connecting,e.id)&&(e.participants.find((e=>e.id===this.user.id&&e.clientId===this.clientId))||e.addParticipantToList(e.localParticipant),e.emitParticipantConnectionStateChanged(e.localParticipant,s.ParticipantConnectionState.Connecting));const i=(null===(a=null===(n=t.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(i),this.callEvents.onInvitedToCall&&this.callEvents.onInvitedToCall(e)}else{const i=this.addNewParticipantsToCall(e,t);i.length>0&&e.emitParticipantsAdded(i,s.ParticipantEntryType.ADDED)}}handleNewCallInvite(e,t){var i;const n=new a.Participant(this.user.id,this.clientId);n.updateConnectionState(s.ParticipantConnectionState.Connecting,e.callId);let l=!1;const r=null===(i=e.participants)||void 0===i?void 0:i.map((t=>{if(t.id===this.user.id&&!t.clientId)return l=t.isCallSilenced||!1,n;const i=new a.Participant(t.id,null==t?void 0:t.clientId);return i.updateState(t.state||s.ParticipantState.Idle,e.callId),i}));if(!t&&!(null==r?void 0:r.find((t=>t.getFullId()===e.from)))&&e.from.split("/")[0]===this.user.id&&e.from.split("/")[1]!==this.clientId){const t=new a.Participant(e.from,e.from.split("/")[1]);t.updateState(s.ParticipantState.Joined,e.callId),null==r||r.push(t)}const d=(0,c.makeFirstById)(r||[],this.user.id,this.clientId),u=new o.Call({id:e.callId,sessionId:e.sessionId,mediaFlow:e.mediaFlow,createdBy:e.from,localParticipant:n,metadata:e.metadata,participants:d,chatClient:this.chatClient,isCallSilenced:l});this.activeCalls.push(u),this.callEvents.onInvitedToCall&&t&&this.callEvents.onInvitedToCall(u),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}addNewParticipantsToCall(e,t){var i;const n=[];return null===(i=t.participants)||void 0===i||i.forEach((t=>{const i=t.id!==this.user.id?e.participants.find((e=>e.id===t.id)):void 0,l=i||new a.Participant(t.id,null==t?void 0:t.clientId);i?t.state!==s.ParticipantState.Joined&&(l.updateState(t.state||s.ParticipantState.Idle,e.id),l.updateConnectionState(s.ParticipantConnectionState.Idle,e.id),l.setVideoEnabled(t.videoEnabled||!1),e.emitParticipantStateChanged(l,s.ParticipantState.Idle),e.emitParticipantConnectionStateChanged(l,s.ParticipantConnectionState.Idle)):(l.updateState(t.state||s.ParticipantState.Idle,e.id),n.push(l),e.addParticipantToList(l))})),n}handleCloseSignal(e){if(this.activeCalls){const t=this.activeCalls.find((t=>t.id===e.callId));if(!t)return;t&&this.closeCall(t)}}handleDeclineSignal(e){var t;if(!this.activeCalls)return;const i=this.activeCalls.find((t=>t.id===e.callId));if(i)if(this.getParticipantId({id:this.user.id,clientId:this.clientId})===e.from)this.leaveCall(i,!0,"Current user declined the call"),i.setState(s.CallState.Idle,"Current user declined the call");else{let n=null==i?void 0:i.participants.find((t=>t.getFullId()===e.from));n||(n=null==i?void 0:i.participants.find((t=>t.id===e.from.split("/")[0]&&!t.clientId)),n?n.clientId=e.from.split("/")[1]:(n=new a.Participant(e.from),i.addParticipantToList(n),i.emitParticipantsAdded([n],s.ParticipantEntryType.ADDED))),n&&n.updateState(s.ParticipantState.Declined,i.id)&&i.emitParticipantStateChanged(n,s.ParticipantState.Declined,null===(t=e.metadata)||void 0===t?void 0:t.reason)}}handleRingingSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){let i=null==t?void 0:t.participants.find((t=>t.id===e.from.split("/")[0]&&(t.clientId===e.from.split("/")[1]||!t.clientId)));i||(i=new a.Participant(e.from),t.addParticipantToList(i),t.emitParticipantsAdded([i],s.ParticipantEntryType.ADDED)),i&&i.connectionState!==s.ParticipantConnectionState.Connected&&i.updateState(s.ParticipantState.Ringing,t.id)&&t.emitParticipantStateChanged(i,s.ParticipantState.Ringing)}}handleSwitchMediaFlowSignal(e){const t=this.activeCalls.find((t=>t.id===e.callId));if(t&&t.localParticipant.state===s.ParticipantState.Joined){t.changeMediaFlow(s.MediaFlow.SFU);const e=new a.Participant(t.id);t.setServerParticipant(e);const i=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[738] [CallId: ${t.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`):e.event!==s.SignalEvent.ERROR||S.error(`[742] [CallId: ${t.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};S.info(`[747] [CallId: ${t.id}] Sending offer to server participant: ${e.getFullId()}`),this.sendOfferPeerToPeer(t,e,i),t.participants.forEach((e=>{e.setShouldResetPeerConnection(!0)}))}else t&&t.changeMediaFlow(s.MediaFlow.SFU)}handleIceSignal(e){var t;if(!e.callId||!e.ice)return void S.warn(`[756] [CallId: ${e.callId}] Invalid ICE signal: missing callId or ice data`);const i=this.activeCalls.find((t=>t.id===e.callId));if(!i)return void S.warn(`[763] [CallId: ${e.callId}] ICE candidate received for unknown call: ${e.callId}`);const n=i.participants.find((t=>t.getFullId()===e.from));if(n)try{if(!this.callParticipantsRTCMap[i.id])return void S.error(`[774] [CallId: ${i.id}] No RTC map found for call ${i.id}`);null===(t=this.callParticipantsRTCMap[i.id][n.getFullId()])||void 0===t||t.addIceCandidate(e.ice,n.getFullId())}catch(e){S.error(`[787] [CallId: ${i.id}] Failed to add ICE candidate for participant ${n.getFullId()} in call ${i.id}: ${e instanceof Error?e.message:JSON.stringify(e)}`)}else S.warn(`[768] [CallId: ${e.callId}] ICE candidate received from unknown participant: ${e.from} in call ${e.callId}`)}handleVideoOnSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from||t.id===e.from.split("/")[0]&&!t.clientId));i&&(i.setVideoEnabled(!0),t.emitParticipantEvent(i,"VideoEnabled"),t.setVideoEnabled(!0))}}handleVideoOffSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){let i;null==t||t.participants.forEach((t=>{(t.getFullId()===e.from||t.id===e.from.split("/")[0]&&!t.clientId)&&(t.setVideoEnabled(!1),i=t)})),i&&t.emitParticipantEvent(i,"VideoDisabled")}}handleScreenShareOnSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setScreenSharing(!0),t.emitParticipantEvent(i,"ScreenSharingStarted"))}}handleScreenShareOffSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setScreenSharing(!1),t.emitParticipantEvent(i,"ScreenSharingStopped"),i.videoEnabled&&(i.setVideoEnabled(!0),t.emitParticipantEvent(i,"VideoEnabled"),t.setVideoEnabled(!0)))}}handleMuteSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setMuted(!0),t.emitParticipantEvent(i,"Mute"))}}handleUnmuteSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setMuted(!1),t.emitParticipantEvent(i,"Unmute"))}}handleHoldSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setHold(!0),t.emitParticipantEvent(i,"Hold"))}}handleUnholdSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setHold(!1),t.emitParticipantEvent(i,"Unhold"))}}handleKickSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&i.updateState(s.ParticipantState.Kicked,t.id)&&t.emitParticipantStateChanged(i,s.ParticipantState.Kicked)}}handleUpdateSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));t&&e.metadata&&(t.metadata=e.metadata)}handleNoAnswerSignal(e){var t;if(!this.activeCalls)return;const i=this.activeCalls.find((t=>t.id===e.callId));i&&(null===(t=e.participants)||void 0===t||t.forEach((e=>{(null==i?void 0:i.participants.filter((t=>t.id===e.id&&(t.clientId===e.clientId||!e.clientId)))).forEach((e=>{e.updateState(s.ParticipantState.NoAnswer,i.id)&&i.emitParticipantStateChanged(e,s.ParticipantState.NoAnswer)}))})))}static getInstance(){return C.instance}setRTCConfig(e){this.rtcConfig=e}onIceCandidateListener(e,t){return i=>{this.onIceCandidate(e,i,t)}}onSignalingStateChangeListener(e,t){return i=>{var n;const a=(null===(n=null==i?void 0:i.currentTarget)||void 0===n?void 0:n.signalingState)||"unknown";S.info(`[1067] [CallId: ${t.id}] Signaling state change: ${a}, participantID: ${e.getFullId()}`,{color:"blue"})}}isPolitePeer(e,t){return t>e}onIceConnectionStateChangeListener(e,t){return i=>{var n;const a=(null===(n=null==i?void 0:i.currentTarget)||void 0===n?void 0:n.iceConnectionState)||"unknown";S.info(`[1078] [CallId: ${t.id}] ICE connection state change: ${a}, participantID: ${e.getFullId()}`,{color:"blue"})}}onConnectionStateChangeListener(e,t){return i=>{var n,a,l,r,o;const c=i.currentTarget.connectionState;S.info(`[1078] [CallId: ${t.id}] PC connection state changed: ${c}, participantID: ${e.getFullId()}`,{color:"disconnected"===c?"orange":"failed"===c?"red":"blue"});const d=this.activeCalls.find((e=>e.id===t.id))||t,u=(null==d?void 0:d.participants.find((t=>t.getFullId()===e.getFullId())))||e.id===(null===(n=null==d?void 0:d.serverParticipant)||void 0===n?void 0:n.id)&&e||e;let g=0,h=null;const C=(i,n=!1)=>{S.info(`[1089] [CallId: ${t.id}] start renegotiation send ${i} to participant ${u.getFullId()}`,{color:"blue"});const a=e=>{if("Connected"===this.chatClient.connectionState&&u.connectionState!==s.ParticipantConnectionState.Connected&&d.state===s.CallState.Connected){S.info(`[1190] [CallId: ${t.id}] interval renegotiation send ${i} to participant ${u.getFullId()}`,{color:"blue"});try{if("offer"!==i||n&&!this.isPolitePeer(u.getFullId(),(null==d?void 0:d.localParticipant.getFullId())||"")){if("connect"===i&&(!n||this.isPolitePeer(u.getFullId(),(null==d?void 0:d.localParticipant.getFullId())||""))){S.info(`[1214] [CallId: ${t.id}] ${s.MediaFlow.SFU} sendConnect to participant 1 ${JSON.stringify(u)}`,{color:"blue"});try{this.signalingClient.clearParticipantSignals(t.id,u.getFullId()),this.signalingClient.sendSignalMessage({mediaFlow:t.mediaFlow,callId:t.id,sessionId:t.sessionId,event:s.SignalEvent.CONNECT,to:u.getFullId()},e)}catch(e){S.error(`[1236] [CallId: ${t.id}] Failed to send connect to participant ${u.getFullId()}: message: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}}else try{S.info(`[1211] [CallId: ${t.id}] Sending offer to participant: ${u.getFullId()}`),this.sendOfferPeerToPeer(t,u,e)}catch(e){S.error(`[1211] [CallId: ${t.id}] Failed to send offer to participant ${u.getFullId()}: ${e instanceof Error?e.message:JSON.stringify(e)}`)}}catch(e){S.error(`[1240] [CallId: ${t.id}] Failed to send offer to participant ${u.getFullId()}: message: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}};h=setInterval((()=>{var n,l,r;const o=this.activeCalls.find((e=>e.id===t.id))||t,c=(null==o?void 0:o.participants.find((t=>t.getFullId()===e.getFullId())))||e.id===(null===(n=null==o?void 0:o.serverParticipant)||void 0===n?void 0:n.id)&&e||e;S.info(`[1182] [CallId: ${t.id}] interval time: ${g+4}`,{color:"green"});const d=null===(r=null===(l=this.callParticipantsRTCMap[t.id])||void 0===l?void 0:l[c.getFullId()])||void 0===r?void 0:r.peerConnection;return o&&o.state===s.CallState.Connected?c.connectionState===s.ParticipantConnectionState.Connected&&"stable"===(null==d?void 0:d.signalingState)?(g=0,void(h&&(clearInterval(h),h=null))):(g+=4,a((e=>{var n;return e instanceof p.SceytCallException||e instanceof Error?(S.error(`[1202] [CallId: ${t.id}] SYNC ${i} failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}),void("NotAllowed"===e.name&&(c.updateConnectionState(s.ParticipantConnectionState.Disconnected,t.id),h&&(clearInterval(h),h=null)))):e.event===s.SignalEvent.ERROR?(S.error(`[1205] [CallId: ${t.id}] SYNC ${i} 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(s.ParticipantConnectionState.Disconnected,t.id),h&&(clearInterval(h),h=null)))):void 0})),void(o&&o.state===s.CallState.Connected||(g=0,h&&(clearInterval(h),h=null)))):(g=0,void(h&&(clearInterval(h),h=null)))}),4e3);const l=setTimeout((()=>{a((e=>{var i;return e instanceof p.SceytCallException||e instanceof Error?(S.error(`[1202] [CallId: ${t.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}),void(("NotAllowed"===e.name||e instanceof p.SceytCallException&&4002===e.code)&&u.updateConnectionState(s.ParticipantConnectionState.Disconnected,t.id))):e.event===s.SignalEvent.ERROR?(S.error(`[1205] [CallId: ${t.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"}),void(4002===(null===(i=e.error)||void 0===i?void 0:i.code)&&u.updateConnectionState(s.ParticipantConnectionState.Disconnected,t.id))):void 0})),clearTimeout(l)}),2e3)},v=()=>{var i;h||u&&d&&(d.mediaFlow===s.MediaFlow.SFU&&e.id===(null===(i=null==d?void 0:d.serverParticipant)||void 0===i?void 0:i.id)&&this.callParticipantsRTCMap[d.id]&&this.callParticipantsRTCMap[d.id][e.getFullId()]&&d.localParticipant.state===s.ParticipantState.Joined&&(S.info(`[1258] [CallId: ${t.id}] start renegotiation ${s.MediaFlow.SFU} sendOffer to participant ${u.getFullId()}`,{color:"blue"}),C("offer",!1)),d.mediaFlow===s.MediaFlow.S2W&&u.state===s.ParticipantState.Joined&&this.callParticipantsRTCMap[d.id]&&this.callParticipantsRTCMap[d.id][u.getFullId()]&&d.localParticipant.state===s.ParticipantState.Joined&&(S.info(`[1263] [CallId: ${t.id}] start renegotiation ${s.MediaFlow.SFU} sendConnect to participant ${u.getFullId()}`,{color:"blue"}),C("offer",!1)))};switch(c){case"new":break;case"connecting":t.mediaFlow===s.MediaFlow.SFU&&u.id===(null===(a=null==d?void 0:d.serverParticipant)||void 0===a?void 0:a.id)&&d.localParticipant.updateConnectionState(s.ParticipantConnectionState.Connecting,t.id)&&d.emitParticipantConnectionStateChanged(d.localParticipant,s.ParticipantConnectionState.Connecting),u.updateConnectionState(s.ParticipantConnectionState.Connecting,t.id)&&d.emitParticipantConnectionStateChanged(u,s.ParticipantConnectionState.Connecting);break;case"connected":if(t.mediaFlow===s.MediaFlow.SFU&&u.id===(null===(l=null==d?void 0:d.serverParticipant)||void 0===l?void 0:l.id)&&d.localParticipant.updateConnectionState(s.ParticipantConnectionState.Connected,t.id)&&d.emitParticipantConnectionStateChanged(d.localParticipant,s.ParticipantConnectionState.Connected),u.updateConnectionState(s.ParticipantConnectionState.Connected,t.id)&&d.emitParticipantConnectionStateChanged(u,s.ParticipantConnectionState.Connected),u&&d&&"Connected"===this.chatClient.connectionState&&(d.mediaFlow!==s.MediaFlow.SFU||d.mediaFlow===s.MediaFlow.SFU&&u.id===(null==d?void 0:d.id))){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[1098] [CallId: ${d.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==s.SignalEvent.ERROR||S.error(`[1102] [CallId: ${d.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:d.mediaFlow,callId:d.id,sessionId:d.sessionId,event:s.SignalEvent.MEDIA_CONNECTED},d.mediaFlow!==s.MediaFlow.SFU?{to:d.id}:{}),e)}break;case"disconnected":t.mediaFlow===s.MediaFlow.SFU&&u.id===(null===(r=null==d?void 0:d.serverParticipant)||void 0===r?void 0:r.id)&&d.localParticipant.updateConnectionState(s.ParticipantConnectionState.Reconnecting,t.id)&&d.emitParticipantConnectionStateChanged(d.localParticipant,s.ParticipantConnectionState.Reconnecting),u.updateConnectionState(s.ParticipantConnectionState.Reconnecting,t.id)&&d.emitParticipantConnectionStateChanged(u,s.ParticipantConnectionState.Reconnecting),S.info("[1250] I am here",{color:"blue"}),t.mediaFlow!==s.MediaFlow.S2W&&v();break;case"failed":u&&d&&(d.mediaFlow===s.MediaFlow.P2P&&u.state===s.ParticipantState.Joined&&this.callParticipantsRTCMap[d.id]&&this.callParticipantsRTCMap[d.id][u.getFullId()]&&d.localParticipant.state===s.ParticipantState.Joined?(S.info(`[1268] [CallId: ${t.id}] start renegotiation ${d.mediaFlow} sendOffer to participant ${u.getFullId()}`,{color:"blue"}),C("offer",!0)):v());break;case"closed":t.mediaFlow===s.MediaFlow.SFU&&u.id===(null===(o=null==d?void 0:d.serverParticipant)||void 0===o?void 0:o.id)&&d.localParticipant.updateConnectionState(s.ParticipantConnectionState.Idle,t.id)&&d.emitParticipantConnectionStateChanged(d.localParticipant,s.ParticipantConnectionState.Idle),u.updateConnectionState(s.ParticipantConnectionState.Idle,t.id)&&d.emitParticipantConnectionStateChanged(u,s.ParticipantConnectionState.Idle)}}}onIceCandidateErrorListener(e,t){return i=>{S.error(`[1284] [CallId: ${t.id}] ICE candidate error participantID: ${e.getFullId()}, error - code: ${i.errorCode}, message: ${i.errorText}, url: ${i.url}`,{color:"red"})}}onTrackListener(e,t){return i=>{this.onTrack(e,t,i)}}closePeerConnections(e,t){if(!this.callParticipantsRTCMap[e])return;const i=this.callParticipantsRTCMap[e][t];i?(i.listeners?(Object.keys(i.listeners).forEach((e=>{i.removeEventListener(e,i.listeners[e])})),S.info(`[1313] [CallId: ${e}] Removed all listeners for WebRTCClient of participant ${t}`,{color:"cyan"})):S.info(`[1316] [CallId: ${e}] No listeners found for WebRTCClient of participant ${t}`,{color:"cyan"}),i.close(),i.peerConnection.onicecandidate=null,i.peerConnection.ontrack=null,i.peerConnection.onconnectionstatechange=null,i.peerConnection.oniceconnectionstatechange=null,i.peerConnection.onsignalingstatechange=null,this.callParticipantsRTCMap[e][t]=null,delete this.callParticipantsRTCMap[e][t]):S.info(`[1375] [CallId: ${e}] No WebRTCClient found for participant ${t}`,{color:"cyan"})}addParticipantToRTCMap(e,t){this.callParticipantsRTCMap.hasOwnProperty(e.id)||(this.callParticipantsRTCMap[e.id]={});const i=new l.WebRTCClient(e.id,this.rtcConfig);this.callParticipantsRTCMap[e.id][t.getFullId()]=i;const n=this.onIceCandidateListener(t,e),a=this.onSignalingStateChangeListener(t,e),r=this.onIceConnectionStateChangeListener(t,e),s=this.onConnectionStateChangeListener(t,e),o=this.onTrackListener(e,t),c=this.onIceCandidateErrorListener(t,e);return i.addEventListener("icecandidate",n),i.addEventListener("signalingstatechange",a),i.addEventListener("connectionstatechange",s),i.addEventListener("track",o),i.addEventListener("icecandidateerror",c),i.addEventListener("iceconnectionstatechange",r),i.setListeners({iceCandidateListener:n,signalingStateChangeListener:a,connectionStateChangeListener:s,trackListener:o,iceCandidateErrorListener:c,iceConnectionStateChangeListener:r}),S.info(`[1371] [CallId: ${e.id}] Added Event Listeners to RTC Map: participantID: ${t.getFullId()}`,{color:"blue"}),e.activeSpeakerManager.addParticipant(t),t}joinToCall(e,t){return this.signalingClient.sendSignalMessage(Object.assign(Object.assign(Object.assign({mediaFlow:e.mediaFlow,callId:e.callId},e.sessionId&&{sessionId:e.sessionId}),{event:s.SignalEvent.JOIN,participants:e.participants}),(null==e?void 0:e.metadata)&&{metadata:e.metadata}),t)}sendRinging(e,t){return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:s.SignalEvent.RINGING},(i=>i instanceof p.SceytCallException||i instanceof Error?(S.error(`[1389] [CallId: ${e.id}] SYNC RINGING failed message: ${i.message} code: ${i instanceof p.SceytCallException?i.code:""}`,{color:"red"}),void(null==t||t({error:(0,h.toCallException)(i)}))):i.event===s.SignalEvent.ERROR?(S.error(`[1393] [CallId: ${e.id}] SYNC RINGING failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"}),void(null==t||t({error:(0,h.toCallException)(new Error("Failed to send ringing signal"))}))):(e.localParticipant.updateState(s.ParticipantState.Ringing,e.id),void e.emitParticipantStateChanged(e.localParticipant,s.ParticipantState.Ringing)))),{success:!0}}rejectCall(e,t,i){try{const n=this.activeCalls.find((t=>t.id===e.id));n&&(n.setState(s.CallState.Idle,"rejectCall"),n.localParticipant.updateState(s.ParticipantState.Declined,e.id)&&n.emitParticipantStateChanged(n.localParticipant,s.ParticipantState.Declined),n.localParticipant.updateConnectionState(s.ParticipantConnectionState.Idle,e.id)&&n.emitParticipantConnectionStateChanged(n.localParticipant,s.ParticipantConnectionState.Idle),this.closeTracksAndPeerConnections(n));const a=t=>t instanceof p.SceytCallException||t instanceof Error?(S.error(`[1420] [CallId: ${e.id}] SYNC DECLINE failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`,{color:"red"}),void(null==i||i({error:(0,h.toCallException)(t)}))):t.event===s.SignalEvent.ERROR?(S.error(`[1424] [CallId: ${e.id}] SYNC DECLINE failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"}),void(null==i||i({error:(0,h.toCallException)(t.error||new Error("Failed to send decline signal"))}))):void 0;return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:s.SignalEvent.DECLINE,metadata:Object.assign(Object.assign({},e.metadata),{reason:t||""})},a),{success:!0}}catch(t){return S.error(`[1432] [CallId: ${e.id}] Failed to reject call: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"}),{success:!1,error:(0,h.toCallException)(t)}}}closeTracksAndPeerConnections(e){e.localAudioTracks.forEach((e=>{e.stop()})),e.localVideoTracks.forEach((e=>{e.stop()})),e.participants.forEach((t=>{t.videoTracks.forEach((e=>{e.stop()})),t.audioTracks.forEach((e=>{e.stop()})),this.closePeerConnections(e.id,t.getFullId()),e.activeSpeakerManager.removeParticipant(t)})),e.localParticipant.videoTracks.forEach((e=>{e.stop()})),e.localParticipant.audioTracks.forEach((e=>{e.stop()})),e.mediaFlow===s.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(s.CallState.Closed,"closeCall"),this.closeTracksAndPeerConnections(e);const t=this.activeCalls.findIndex((t=>t.id===e.id));this.activeCalls.splice(t,1),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls),delete this.callParticipantsRTCMap[e.id],S.info(`[1474] [CallId: ${e.id}] closed call and removed from active calls: callId: ${e.id}`,{color:"light-green"})}leaveCall(e,t=!0,i){const n=this.activeCalls.find((t=>t.id===e.id));if(n){this.signalingClient.cancelJoinIfPossible(e.id);const a=n.setState(s.CallState.Idle,`leaveCall: ${i}`);if(t&&a){const t=t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[1487] [CallId: ${e.id}] SYNC LEAVE failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`,{color:"red"}):t.event!==s.SignalEvent.ERROR||S.error(`[1491] [CallId: ${e.id}] SYNC LEAVE failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:s.SignalEvent.LEAVE},t)}this.closeTracksAndPeerConnections(n),delete this.callParticipantsRTCMap[n.id],n.localParticipant.updateState(s.ParticipantState.Left,e.id)&&n.emitParticipantStateChanged(n.localParticipant,s.ParticipantState.Left),n.localParticipant.setVideoEnabled(!1),n.localParticipant.setScreenSharing(!1),n.localParticipant.setMuted(!1),n.localParticipant.connectionState!==s.ParticipantConnectionState.Idle&&n.localParticipant.updateConnectionState(s.ParticipantConnectionState.Idle,e.id),n.participants.forEach((t=>{t.connectionState!==s.ParticipantConnectionState.Idle&&(t.updateConnectionState(s.ParticipantConnectionState.Idle,e.id),n.emitParticipantConnectionStateChanged(t,s.ParticipantConnectionState.Idle))})),e.sessionId||(this.activeCalls=this.activeCalls.filter((e=>e.id!=n.id))),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}}setRemoteDescription(e,t,i){return this.callParticipantsRTCMap[e][t].setRemoteDescription(i)}changeVideoTracks(e,t,i,a){var l;return n(this,void 0,void 0,(function*(){if(S.info(`[1594] [CallId: ${e.id}], mediaFlow: ${e.mediaFlow}, changeVideoTracks ${i}, serverParticipant: ${(null===(l=e.serverParticipant)||void 0===l?void 0:l.id)||"null"}`,{color:"cyan"}),e.mediaFlow!==s.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(i,t,!!a))}else this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][e.id]&&(yield this.callParticipantsRTCMap[e.id][e.id].enableVideoOnPeerConnection(i,t,!!a))}))}changeAudioTracks(e,t,i){return n(this,void 0,void 0,(function*(){e.mediaFlow!==s.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()]&&(S.info(`[1561] [CallId: ${e.id}] Enabling audio on peer connection: ${n.getFullId()}`,{color:"cyan"}),this.callParticipantsRTCMap[e.id][n.getFullId()].enableAudioOnPeerConnection(i,t))})):(S.info(`[1565] [CallId: ${e.id}] Enabling audio on peer connection: ${e.id}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][e.id].enableAudioOnPeerConnection(i,t))}))}sendVideoEnabled(e,t,i){if(this.activeCalls.find((t=>t.id===e.id)))try{const n=t=>t instanceof p.SceytCallException||t instanceof Error?(S.error(`[1632] [CallId: ${e.id}] SYNC VIDEO_ON failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`),void(null==i||i({error:(0,h.toCallException)(t)}))):t.event===s.SignalEvent.ERROR?(S.error(`[1636] [CallId: ${e.id}] SYNC VIDEO_ON failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`),void(null==i||i({error:(0,h.toCallException)(t.error||t)}))):void 0;this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:t?s.SignalEvent.VIDEO_ON:s.SignalEvent.VIDEO_OFF,sessionId:e.sessionId},n)}catch(t){return S.error(`[1645] [CallId: ${e.id}] Failed to send video enabled signal: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"}),null==i||i({error:(0,h.toCallException)(t)}),!1}}sendScreenShare(e,t,i){return n(this,void 0,void 0,(function*(){const n=this.activeCalls.find((t=>t.id===e.id));try{if(n)return this.sendSignalScreenShare(e,t,i)}catch(t){return S.error(`[1668] [CallId: ${e.id}] Failed to send screen share signal: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"}),null==i||i({error:(0,h.toCallException)(t)}),!1}}))}sendAudioEnable(e,t,i){return n(this,void 0,void 0,(function*(){if(this.activeCalls.find((t=>t.id===e.id))){const a=a=>n(this,void 0,void 0,(function*(){try{if(a instanceof p.SceytCallException||a instanceof Error)return S.error(`[1704] [CallId: ${e.id}] SYNC HOLD failed message: ${a.message} code: ${a instanceof p.SceytCallException?a.code:""}`),void(null==i||i({error:(0,h.toCallException)(a)}));if(a.event===s.SignalEvent.ERROR)return S.error(`[1708] [CallId: ${e.id}] SYNC HOLD failed message: ${a.error?`${a.error.message} code: ${a.error.code}`:""}`),void(null==i||i({error:(0,h.toCallException)(a.error)}));if(e.mediaFlow!==s.MediaFlow.SFU)for(let i=0;i<e.participants.length;i++){const n=e.participants[i];(n.id!==this.user.id||n.clientId!==this.clientId)&&n.clientId&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][n.getFullId()]&&(S.info(`[1712] [CallId: ${e.id}] Enabling audio on peer connection: ${n.getFullId()}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][n.getFullId()].enableAudioOnPeerConnection(t))}else this.callParticipantsRTCMap&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][e.serverParticipant.id]&&(S.info(`[1712] [CallId: ${e.id}] Enabling audio on peer connection: ${e.serverParticipant.id}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][e.serverParticipant.id].enableAudioOnPeerConnection(t));e.localParticipant.audioTracks.forEach((e=>{e.enabled=!t}))}catch(t){S.error(`[1725] [CallId: ${e.id}] Failed to enable audio on peer connection: ${t instanceof Error?t.message:JSON.stringify(t)}`),null==i||i({error:(0,h.toCallException)(t)})}}));return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:t?s.SignalEvent.MUTE:s.SignalEvent.UNMUTE,sessionId:e.sessionId},a)}}))}sendHold(e,t,i){const n=this.activeCalls.find((t=>t.id===e.id));if(n){this.sendAudioEnable(n,!t,i);const a=t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[1741] [CallId: ${e.id}] SYNC HOLD failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`):t.event!==s.SignalEvent.ERROR||S.error(`[1745] [CallId: ${e.id}] SYNC HOLD failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`)};return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:t?s.SignalEvent.HOLD:s.SignalEvent.UNHOLD,sessionId:e.sessionId},a)}}addTracksToPeerConnection(e,t,i=!0){return n(this,void 0,void 0,(function*(){let n=e.localVideoTracks;const a=e.localAudioTracks,l=new MediaStream;a&&a.length>0&&l.addTrack(a[0]);try{i?yield this.callParticipantsRTCMap[e.id][t].addTransceiverToPeerConnection(a[0],e.mediaFlow):yield this.callParticipantsRTCMap[e.id][t].setStreamsToTransceiver(a[0])}catch(t){S.warn(`[1766] [CallId: ${e.id}] Failed to add track to peer connection: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"})}n&&n.length>0||(n=(0,c.getEmptyVideoTrack)()),l.addTrack(n[0]);try{i?yield this.callParticipantsRTCMap[e.id][t].addTransceiverToPeerConnection(n[0],e.mediaFlow):yield this.callParticipantsRTCMap[e.id][t].setStreamsToTransceiver(n[0])}catch(t){S.warn(`[1775] [CallId: ${e.id}] Failed to add track to peer connection: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"})}}))}switchCallToSfu(e,t){try{const i=i=>{if(i instanceof p.SceytCallException||i instanceof Error)return S.error(`[1785] [CallId: ${e.id}] SYNC SWITCH_MEDIA_FLOW signal sent failed message: ${i.message} code: ${i instanceof p.SceytCallException?i.code:""}`),void(null==t||t({error:(0,h.toCallException)(i)}));if(i.event===s.SignalEvent.ERROR)return S.error(`[1789] [CallId: ${e.id}] SYNC SWITCH_MEDIA_FLOW signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`),void(null==t||t({error:(0,h.toCallException)(i)}));const n=new a.Participant(e.id);return e.setServerParticipant(n),e.participants.forEach((t=>{t.id===this.user.id&&t.clientId===this.clientId||t.updateConnectionState(s.ParticipantConnectionState.Idle,e.id),t.setShouldResetPeerConnection(!0)})),e.changeMediaFlow(s.MediaFlow.SFU),S.info(`[1818] [CallId: ${e.id}] Sending offer to server participant: ${n.getFullId()}`),this.sendOfferPeerToPeer(e,n,(t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[1805] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`):t.event!==s.SignalEvent.ERROR||S.error(`[1809] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`)})),!0};return this.signalingClient.sendSignalMessage({mediaFlow:s.MediaFlow.SFU,callId:e.id,event:s.SignalEvent.SWITCH_MEDIA_FLOW,sessionId:e.sessionId},i),S.info(`[1823] [CallId: ${e.id}] Switched call ${e.id} to SFU`,{color:"light-green"}),{success:!0}}catch(t){return S.error(`[1827] [CallId: ${e.id}] Failed to switch ${s.MediaFlow.SFU} message: ${t instanceof Error?t.message:JSON.stringify(t)}`),{success:!1,error:(0,h.toCallException)(t)}}}getCallById(e,t){return this.signalingClient.sendSignalMessage({callId:e,sessionId:t,event:s.SignalEvent.GET_CALL},(t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[1833] [CallId: ${e}] SYNC GET_CALL signal sent failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`):t.event!==s.SignalEvent.ERROR||S.error(`[1837] [CallId: ${e}] SYNC GET_CALL signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`)}),e)}getCalls(){return this.signalingClient.sendSignalMessage({callId:"",event:s.SignalEvent.GET_CALL},(e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[1849] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`):e.event!==s.SignalEvent.ERROR?this.syncActiveCalls(e):S.error("[1853] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: "+(e.error?`${e.error.message} code: ${e.error.code}`:""))}),"get_call")}findOrCreateCall(e,t){var i,n;let l=this.activeCalls.find((t=>t.id===e.id)),r=!1,d=!1;if(l){if(S.info(`[1911] [CallId: ${l.id}] Using existing call`,{color:"cyan"}),r=!0,!l.participants.find((e=>e.id===this.user.id&&e.clientId===this.clientId))&&l.localParticipant.id===this.user.id&&l.localParticipant.clientId===this.clientId){const e=(0,c.makeFirstById)([...l.participants,l.localParticipant],this.user.id,this.clientId);l.participants=e,l.emitParticipantsAdded([l.localParticipant],s.ParticipantEntryType.ADDED)}e.localAudioTracks&&(null===(i=e.localAudioTracks)||void 0===i?void 0:i.length)&&(l.localAudioTracks=e.localAudioTracks||[],l.localParticipant.setAudioTracks(e.localAudioTracks||[])),e.localVideoTracks&&(null===(n=e.localVideoTracks)||void 0===n?void 0:n.length)&&(l.localVideoTracks=e.localVideoTracks||[],l.localParticipant.setVideoTracks(e.localVideoTracks||[]))}else{let i=new a.Participant(this.user.id,this.clientId);const n=e.id||(0,u.v4)();S.info(`[1869] [CallId: ${n}] Creating new call`,{color:"cyan"});const p=(t||e.participantIds).map((e=>{let n=new a.Participant(t?e.id:e,t?e.clientId:void 0);return t&&(n.setVideoEnabled(e.videoEnabled),n.setMuted(e.muted),n.state=e.state,e.connectionState>s.ParticipantConnectionState.Connected&&e.id!==this.user.id&&e.clientId!==this.clientId&&(n.connectionState=e.connectionState),this.user.id!==e.id||e.clientId!==this.clientId&&e.clientId||(d=(null==e?void 0:e.isCallSilenced)||!1,i=n)),n})),g=(0,c.makeFirstById)([...p,i],this.user.id,this.clientId);l=new o.Call({id:n,sessionId:e.sessionId,mediaFlow:e.mediaFlow,localParticipant:i,participants:g,metadata:e.metadata,createdBy:e.createdBy,chatClient:this.chatClient,isCallSilenced:d}),l.localAudioTracks=e.localAudioTracks||[],l.localVideoTracks=e.localVideoTracks||[],l.localParticipant.setVideoTracks(e.localVideoTracks||[]),l.localParticipant.setAudioTracks(e.localAudioTracks||[]),this.activeCalls.push(l),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls),r=!1}return{call:l,answer:r}}processJoinAcknowledgment(e,t,i){var n,a,l,r;if(t.event===s.SignalEvent.ERROR)throw S.error(`[1955] [CallId: ${e.id}] Join failed: message: ${null===(n=t.error)||void 0===n?void 0:n.message} code: ${null===(a=t.error)||void 0===a?void 0:a.code}`),this.leaveCall(e,!0,"processJoinAcknowledgment"),(0,h.checkCode)((null===(l=t.error)||void 0===l?void 0:l.code)||0,null===(r=t.error)||void 0===r?void 0:r.message);if(t.event===s.SignalEvent.SUCCESS)return e.eventsQueue.forEach((e=>{e()})),e.eventsQueue.clear(),this.configureRTCServers(e,t,i),e;throw S.warn(`[1969] [CallId: ${e.id}] Unexpected join event: ${t.event}`),(0,h.checkCode)(4e3,`Unexpected event type: ${t.event}`)}configureRTCServers(e,t,i){var n;(null===(n=t.turnServers)||void 0===n?void 0:n.length)&&this.setRTCConfig(Object.assign(Object.assign({},e.mediaFlow===s.MediaFlow.SFU?{}:{iceServers:t.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,t.participants),e.mediaFlow===s.MediaFlow.SFU?this.setupSFUConnection(e,i,t):e.participants.forEach((t=>{e.mediaFlow===s.MediaFlow.P2P&&t.getFullId()!=e.localParticipant.getFullId()&&t.state===s.ParticipantState.Joined&&this.isPolitePeer(t.getFullId(),e.localParticipant.getFullId())&&(S.info(`[2008] [CallId: ${e.id}] Sending offer to participant: ${t.getFullId()}`),this.sendOfferPeerToPeer(e,t,(t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[2005] [CallId: ${e.id}] SYNC OFFER failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`):t.event!==s.SignalEvent.ERROR||S.error(`[2010] [CallId: ${e.id}] SYNC OFFER failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`)})))}))}setupSFUConnection(e,t,i){const n=new a.Participant(e.id);S.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 p.SceytCallException||n instanceof Error?S.error(`[2011] [CallId: ${e.id}] SYNC OFFER failed message: ${n.message} code: ${n instanceof p.SceytCallException?n.code:""}`):(n.event===s.SignalEvent.ERROR&&S.error(`[2015] [CallId: ${e.id}] SYNC OFFER failed message: ${n.error?`${n.error.message} code: ${n.error.code}`:""}`),n.event!==s.SignalEvent.ERROR&&(S.info(`[2019] [CallId: ${e.id}] offerAck: ${JSON.stringify(n)}`,{color:"cyan"}),e.participants.forEach((n=>{if(n.id===this.user.id&&n.clientId===this.clientId||!i.participants.find((e=>e.id===n.id&&e.clientId===n.clientId&&e.connectionState===s.MediaConnectionState.Connected)))n.connectionState&&n.connectionState>s.ParticipantConnectionState.Connected&&n.id!==this.user.id&&n.clientId!==this.clientId&&n.getFullId()!=e.localParticipant.getFullId()&&(n.updateConnectionState(n.connectionState,e.id),e.emitParticipantConnectionStateChanged(n,n.connectionState));else{const a=t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[2023] [CallId: ${e.id}] SYNC CONNECT failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`):t.event!==s.SignalEvent.ERROR||S.error(`[2028] [CallId: ${e.id}] SYNC CONNECT failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`)};this.signalingClient.clearParticipantSignals(e.id,n.getFullId()),this.signalingClient.sendSignalMessage({mediaFlow:t,callId:e.id,event:s.SignalEvent.CONNECT,sessionId:i.sessionId,to:n.getFullId(),metadata:e.metadata},a)}}))))};S.info(`[2067] [CallId: ${e.id}] Sending offer to server participant: ${n.getFullId()}`),this.sendOfferPeerToPeer(e,n,a)}catch(t){throw S.error(`[2049] [CallId: ${e.id}] SFU setup error: message: ${t instanceof Error?t.message:JSON.stringify(t)}`),(0,h.toCallException)(t)}}processRemoteParticipants(e,t){t.length&&(t.forEach((t=>{let i=e.participants.find((e=>e.getFullId()===this.getParticipantId(t)));if(i||(i=e.participants.find((e=>e.id===t.id&&(e.clientId===t.clientId||!e.clientId))),i&&!i.clientId&&(i.clientId=t.clientId)),i||e.localParticipant.getFullId()===this.getParticipantId(t))i&&e.localParticipant.getFullId()!==this.getParticipantId(t)&&(i.presenter=t.presenter,i.setVideoEnabled(!!t.hasOwnProperty("videoEnabled")&&t.videoEnabled),e.emitParticipantEvent(i,t.hasOwnProperty("videoEnabled")?"VideoEnabled":"VideoDisabled"),i.setMuted(!!t.hasOwnProperty("muted")&&t.muted),e.emitParticipantEvent(i,t.hasOwnProperty("muted")?"Mute":"Unmute"),i.setHold(!!t.hasOwnProperty("onHold")&&t.onHold),e.emitParticipantEvent(i,t.hasOwnProperty("onHold")?"Hold":"Unhold"),i.setScreenSharing(!!t.hasOwnProperty("screenSharing")&&t.screenSharing),e.emitParticipantEvent(i,t.hasOwnProperty("screenSharing")?"ScreenSharingStarted":"ScreenSharingStopped"),i.state!=t.state&&void 0!==t.state&&(i.updateState(t.state||s.ParticipantState.Idle,e.id),e.emitParticipantStateChanged(i,t.state,"FromJoin")));else{const i=new a.Participant(t.id,t.clientId);i.updateState(t.state,e.id),i.setVideoEnabled(!!t.hasOwnProperty("videoEnabled")&&t.videoEnabled),i.setMuted(!!t.hasOwnProperty("muted")&&t.muted),i.setHold(!!t.hasOwnProperty("onHold")&&t.onHold),i.setScreenSharing(!!t.hasOwnProperty("screenSharing")&&t.screenSharing),e.addParticipantToList(i),e.emitParticipantsAdded([i],s.ParticipantEntryType.ADDED)}})),S.info(`[2098] [CallId: ${e.id}] Processed participants - Added and Updated`,{color:"cyan"}))}processJoinCall(e,t,i){e.mediaFlow!==s.MediaFlow.SFU&&e.localParticipant.updateConnectionState(s.ParticipantConnectionState.Connected,e.id);const n=t.mediaFlow||s.MediaFlow.P2P;e.setSessionId(t.sessionId),e.changeMediaFlow(n),e.localParticipant.updateState(s.ParticipantState.Joined,e.id),e.setState(s.CallState.Connected,i)?(e.emitParticipantStateChanged(e.localParticipant,s.ParticipantState.Joined),e.emitParticipantConnectionStateChanged(e.localParticipant,s.ParticipantConnectionState.Connected),this.processJoinAcknowledgment(e,t,n)):this.leaveCall(e,!0,"processJoinCall")}startCall(e,t,i,a){var l;const r=t.mediaFlow,o=e.participants.filter((e=>!(e.id===this.user.id&&e.clientId===this.clientId))).map((e=>e.serialize()));e.mediaFlow!==s.MediaFlow.SFU&&e.localParticipant.updateConnectionState(s.ParticipantConnectionState.Connecting,e.id);const c="true"===(null===(l=e.metadata)||void 0===l?void 0:l.videoCall),d=(t,l)=>{if(e.state==s.CallState.Idle)return t.forEach((e=>{e.stop()})),void(null==a||a({error:(0,h.checkCode)(5002,"Call was ended before media setup completed")}));e.emitAudioTrackAdded(e.localParticipant,t[0]),c&&l&&l.length>0&&(e.emitVideoTrackAdded(e.localParticipant,l[0]),e.localParticipant.setVideoTracks(l),e.localVideoTracks=l,e.setVideoDeviceId(l[0].getSettings().deviceId||null)),e.localParticipant.setAudioTracks(t),e.localAudioTracks=t,this.joinToCall({mediaFlow:r,callId:e.id,sessionId:e.sessionId,participants:i?[]:o,metadata:e.metadata},(t=>n(this,void 0,void 0,(function*(){var i;return t instanceof p.SceytCallException||t instanceof Error?(S.error(`[2137] [CallId: ${e.id}] SYNC JOIN failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`),e.setState(s.CallState.Closed,"joinCall failed"),void(null==a||a({error:(0,h.toCallException)(t)}))):t.event===s.SignalEvent.ERROR?(S.error(`[2141] [CallId: ${e.id}] SYNC JOIN failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`),void(null==a||a({error:(0,h.checkCode)(5003,(null===(i=t.error)||void 0===i?void 0:i.message)||"Unknown error")}))):void this.processJoinCall(e,t,"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})=>{d(e,t.localVideoTracks||[])})):!e.localAudioTracks||e.localVideoTracks&&e.localVideoTracks.length>0?d(e.localAudioTracks||[],e.localVideoTracks||[]):d(t.localAudioTracks||[]):this.setupMediaStream(e).then((({audioTracks:e})=>{d(e)})),e}joinCall(e,t){let i=null;try{S.info("[2159] [CallId: GLOBAL_LOGS] joinCall, start new call",{color:"blue"});const{call:n,answer:a}=this.findOrCreateCall(e);return n.setState(s.CallState.Connecting,"joinCall")?(n.localParticipant.state=s.ParticipantState.Joined,n.localParticipant.clientId=this.clientId,i=this.startCall(n,e,a,t),{success:!0,data:n}):{success:!1,error:(0,h.checkCode)(5001,`Failed to set call state from ${n.state} to connecting`)}}catch(e){return S.error(`[2173] [CallId: ${null==i?void 0:i.id}] Join call failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,h.toCallException)(e)}}}updateCallMetadata(e,t){e.metadata=t.metadata||0,e.createdBy=t.createdBy,e.sessionId=t.sessionId,e.id=t.id,S.info(`[2187] [CallId: ${e.id}] Updated call metadata for call ${e.id}`,{color:"light-blue"})}syncParticipants(e,t){S.info(`[2198] [CallId: ${e.id}] Syncing participants for call ${e.id}`,{color:"light-blue"}),e.participants=e.participants.filter((i=>{const n=t.find((e=>!(e.id!==i.id||e.clientId!==i.clientId&&e.clientId&&i.clientId)));return n||(S.info(`[2202] [CallId: ${e.id}] Removing participant ${i.id} who is no longer in the call`,{color:"light-blue"}),e.emitParticipantStateChanged(i,s.ParticipantState.Left),e.kickParticipantFromList(i)),!!n})),S.info(`[2216] [CallId: ${e.id}] Syncing participants for call ${e.id}`,{color:"light-blue"});for(const i of t){const t=e.participants.find((e=>!(e.id!==i.id||e.clientId!==i.clientId&&i.clientId&&e.clientId)));if(S.info(`[2219] [CallId: ${e.id}] Syncing participants for call ${e.id}`,{color:"light-blue"}),t){if(t.clientId||(t.clientId=i.clientId),t.id===e.localParticipant.id&&t.clientId===e.localParticipant.clientId){i.state===s.ParticipantState.Joined&&e.localParticipant.state>s.ParticipantState.Joined&&this.leaveCall(e,!0,"syncParticipants");continue}t.state=i.state,e.emitParticipantStateChanged(t,i.state),t.state!==s.ParticipantState.Joined?t.getFullId()!==e.localParticipant.getFullId()&&(this.closePeerConnections(e.id,t.getFullId()),e.activeSpeakerManager.removeParticipant(t)):t.id!==e.localParticipant.id&&t.clientId!==e.localParticipant.clientId&&e.state===s.CallState.Connected&&this.handleNewParticipant(e,t),t.getFullId()===e.localParticipant.getFullId()&&(e.localParticipant=t),this.syncParticipantMediaState(e,t,i),S.info(`[2254] [CallId: ${e.id}] Syncing existing participants: ${t.getFullId()} for call ${e.id}`,{color:"light-blue"})}else{const t=new a.Participant(i.id,i.clientId);t.state=i.state,e.addParticipantToList(t),this.syncParticipantMediaState(e,t,i),S.info(`[2263] [CallId: ${e.id}] Syncing no existing participants: ${t.getFullId()} for call ${e.id}`,{color:"light-blue"}),e.emitParticipantsAdded([t],s.ParticipantEntryType.ADDED),(e.mediaFlow!==s.MediaFlow.SFU&&i.state===s.ParticipantState.Joined||e.mediaFlow===s.MediaFlow.SFU&&i.connectionState===s.MediaConnectionState.Connected&&e.state===s.CallState.Connected)&&this.handleNewParticipant(e,t)}}}syncParticipantMediaState(e,t,i){if(t.getFullId()===i.id+(i.clientId?"/"+i.clientId:"")){const n=!!i.hasOwnProperty("muted")&&i.muted,a=!!i.hasOwnProperty("screenSharing")&&i.screenSharing,l=!!i.hasOwnProperty("videoEnabled")&&i.videoEnabled,r=!!i.hasOwnProperty("onHold")&&i.onHold,s=!!i.hasOwnProperty("isCallSilenced")&&i.isCallSilenced;n!==t.muted&&(S.info(`[2287] [CallId: ${e.id}] Participant ${t.getFullId()} audio state changed: ${t.muted} -> ${n}`,{color:"light-blue"}),t.setMuted(n),n?e.emitParticipantEvent(t,"Mute"):e.emitParticipantEvent(t,"Unmute")),l===t.videoEnabled||a||(S.info(`[2296] [CallId: ${e.id}] Participant ${t.getFullId()} video state changed: ${t.videoEnabled} -> ${l}`,{color:"light-blue"}),t.setVideoEnabled(l),l?e.emitParticipantEvent(t,"VideoEnabled"):e.emitParticipantEvent(t,"VideoDisabled")),a!==t.screenSharing&&(S.info(`[2307] [CallId: ${e.id}] Participant ${t.getFullId()} screen sharing state changed: ${t.screenSharing} -> ${a}`,{color:"light-blue"}),t.setScreenSharing(a),a?e.emitParticipantEvent(t,"ScreenSharingStarted"):e.emitParticipantEvent(t,"ScreenSharingStopped")),r!==t.onHold&&(S.info(`[2317] [CallId: ${e.id}] Participant ${t.getFullId()} hold state changed: ${t.onHold} -> ${r}`,{color:"light-blue"}),t.setHold(r),r?e.emitParticipantEvent(t,"Hold"):e.emitParticipantEvent(t,"Unhold")),s!==!!t.isCallSilenced&&(S.info(`[2327] [CallId: ${e.id}] Participant ${t.getFullId()} ring allowed state changed: ${t.isCallSilenced} -> ${s}`,{color:"light-blue"}),e.setIsCallSilenced(s))}}handleNewParticipant(e,t){if(S.info(`[2333] [CallId: ${e.id}] Call media flow: ${e.mediaFlow}`,{color:"light-blue"}),e.mediaFlow!==s.MediaFlow.SFU){if(t.updateState(s.ParticipantState.Joined,e.id),e.emitParticipantStateChanged(t,s.ParticipantState.Joined),t.getFullId()!==e.localParticipant.getFullId()&&t.connectionState!==s.ParticipantConnectionState.Connected&&t.connectionState!==s.ParticipantConnectionState.Reconnecting){const i=t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[2341] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`,{color:"red"}):t.event!==s.SignalEvent.ERROR||S.error(`[2345] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"})};S.info(`[2370] [CallId: ${e.id}] Sending offer to participant: ${t.getFullId()}`),e.mediaFlow===s.MediaFlow.P2P&&this.isPolitePeer(t.getFullId(),e.localParticipant.getFullId())?this.sendOfferPeerToPeer(e,t,i):(this.signalingClient.clearParticipantSignals(e.id,t.getFullId()),this.signalingClient.sendSignalMessage({to:t.getFullId(),mediaFlow:e.mediaFlow,callId:e.id,event:s.SignalEvent.CONNECT,sessionId:e.sessionId},i))}}else if(t.getFullId()!==e.localParticipant.getFullId()&&t.connectionState!==s.ParticipantConnectionState.Reconnecting){const i=t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[2354] [CallId: ${e.id}] SYNC CONNECT signal sent failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`,{color:"red"}):t.event!==s.SignalEvent.ERROR||S.error(`[2358] [CallId: ${e.id}] SYNC CONNECT signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"})};this.signalingClient.clearParticipantSignals(e.id,t.getFullId()),this.signalingClient.sendSignalMessage({to:t.getFullId(),mediaFlow:e.mediaFlow,callId:e.id,event:s.SignalEvent.CONNECT,sessionId:e.sessionId},i)}}handleConnectSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){let i=t.participants.find((t=>t.getFullId()===e.from));i&&this.sendOfferPeerToPeer(t,i,(e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[2417] [CallId: ${t.id}] SYNC OFFER signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==s.SignalEvent.ERROR||S.error(`[2421] [CallId: ${t.id}] SYNC OFFER signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})}))}}handleMediaFlowSwitch(e){S.info(`[2375] [CallId: ${e.id}] Switching call ${e.id} from P2P to SFU`,{color:"light-blue"}),e.changeMediaFlow(s.MediaFlow.SFU);const t=new a.Participant(e.id);e.setServerParticipant(t),S.info(`[2395] [CallId: ${e.id}] Sending offer to server participant: ${t.getFullId()}`),this.sendOfferPeerToPeer(e,t,(t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[2386] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`,{color:"red"}):t.event!==s.SignalEvent.ERROR||S.error(`[2390] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"})})),e.participants.forEach((e=>{e.setShouldResetPeerConnection(!0)}))}}t.InternalCallHandler=C},787:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Participant=void 0;const n=i(578),a=i(758),l=i(645),r=(0,l.createLogger)("ParticipantState"),s=(0,l.createLogger)("ConnectionState");t.Participant=class{constructor(e,t){this.clientId="",this.muted=!1,this.onHold=!1,this.videoEnabled=!1,this.screenSharing=!1,this.presenter=!1,this.audioTracks=[],this.videoTracks=[],this.shouldResetPeerConnection=!1,this.state=n.ParticipantState.Idle,this.connectionState=n.ParticipantConnectionState.Idle;const i=e.split("/");this.id=i[0],this.clientId=t||i[1]||""}updateState(e,t){const i=new a.ParticipantStateMachine(this.id,t).updateState(e,this.state);return i&&(this.state=e,r.info(`[35] [CallId: ${t}] Updating state: ${e}, participantID: ${this.getFullId()}`,{color:"blue"})),i}updateConnectionState(e,t){const i=new a.ParticipantStateMachine(this.id,t).updateConnectionState(e,this.connectionState);return i&&(this.connectionState=e,s.info(`[45] [CallId: ${t}] Updating connection state: ${e}, participantID: ${this.getFullId()}`,{color:"blue"})),i}setShouldResetPeerConnection(e){this.shouldResetPeerConnection=e}setMuted(e){this.audioTracks.forEach((t=>{t.enabled=!e})),this.muted=e}setVideoEnabled(e){this.videoTracks.forEach((t=>{t.enabled=e})),this.videoEnabled=e}setScreenSharing(e){this.videoTracks.forEach((t=>{t.enabled=e})),this.screenSharing=e}setPresenter(e){this.presenter=e}setAudioTracks(e){this.audioTracks=e}setVideoTracks(e){this.videoTracks=e}setHold(e){this.onHold=e}serialize(){return{id:this.id,clientId:this.clientId}}getFullId(){return this.id+(this.clientId?"/"+this.clientId:"")}}},816:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.QueryBuilder=void 0,t.QueryBuilder=class{constructor(){this.count=10}}},185:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RecentCallQueryBuilder=void 0;const n=i(578),a=i(650),l=i(816),r=i(343),s=i(228);class o 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.build=()=>{const e=a.InternalCallHandler.getInstance();this.chatClient=e.chatClient;try{return new r.RecentCallQuery(this)}catch(e){throw(0,s.toCallException)(e)}}}}t.RecentCallQueryBuilder=o},343:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{o(n.next(e))}catch(e){l(e)}}function s(e){try{o(n.throw(e))}catch(e){l(e)}}function o(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,s)}o((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.RecentCallQuery=void 0;const a=i(578),l=i(645),r=i(228),s=(0,l.createLogger)("RecentCallQuery");t.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 s.info("QUERY_IN_PROGRESS"),(0,r.checkCode)(5001,"QUERY_IN_PROGRESS");if(this.hasNext){this.loading=!0;const e=yield this.chatClient.sendCallDetailsRecord(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}:{})}:{}));this.loading=!1;const{getRecentCallsResponse:{records:t,nextToken:i}}=e;return this.hasNext=!!i,this.nextToken=i,{records:t,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}set limit(e){this.count=e}get limit(){return this.count}}},680:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.toSessionDescription=t.toSessionData=void 0;const n=i(578),a=i(645),l=i(19),r=(0,a.createLogger)("SignalingExtensions");t.toSessionData=function(e,t){const i=e.sdp.sdp||"",a=1e3*Date.now()+performance.now()%1*1e3;r.info(`[32] [CALL_TIME_TO_SESSION_DATA_START: ${a}]`,{color:"blue"});const s=l.SdpConverter.parseToSdpData(i,l.CODEC_NAME_TO_VIDEO_CODEC,t===n.MediaFlow.S2W?l.CODEC_NAME_TO_AUDIO_CODEC_S2W:l.CODEC_NAME_TO_AUDIO_CODEC),o=1e3*Date.now()+performance.now()%1*1e3;return r.info(`[35] [CALL_TIME_TO_SESSION_DATA_END: ${o}]`,{color:"blue"}),r.info(`[34] [CallId: ${e.sessionId}] toSessionData in sdp-converter: sdpData: ${JSON.stringify(s||{})}, type: ${e.sdp.type}, sessionId: ${e.sessionId}, versionId: ${e.versionId}`,{color:"blue"}),{id:e.sessionId,version:e.versionId,sdpData:s}},t.toSessionDescription=function(e,t){if(r.info(`[50] [CallId: ${e.id}] toSessionDescription in sdp-converter: sessionData: ${JSON.stringify((null==e?void 0:e.sdpData)||{})}, type: ${t}, id: ${e.id}, version: ${e.version}`,{color:"blue"}),e.sdpData){const i=l.SdpConverter.reconstructFromSDPData(e.sdpData);return r.info(`[53] [CallId: ${e.id}] toSessionDescription in sdp-converter: sdp: ${i}`,{color:"blue"}),{type:t,sdp:i}}return r.error("SessionData has neither sdpData nor sdp field"),null}},19:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdpConverter=t.CODEC_NAME_TO_AUDIO_CODEC_S2W=t.CODEC_NAME_TO_AUDIO_CODEC=t.CODEC_NAME_TO_VIDEO_CODEC=void 0;const n=i(645),a=i(228),l=i(799),r=(0,n.createLogger)("SdpConverter");t.CODEC_NAME_TO_VIDEO_CODEC=["vp8","rtx","red"],t.CODEC_NAME_TO_AUDIO_CODEC=["opus","red"],t.CODEC_NAME_TO_AUDIO_CODEC_S2W=["opus","red","pcmu","pcma"];class s{static parseToSdpData(e,i=t.CODEC_NAME_TO_VIDEO_CODEC,n=t.CODEC_NAME_TO_AUDIO_CODEC){var a,l,r;const o=[],c=e.split("\n").map((e=>e.trim())).filter((e=>e.length>0)),d=s.extractSessionId(c)||"",u=s.extractSessionVersion(c)||0,p=s.extractOriginAddress(c)||"127.0.0.1",g=(null===(a=c.find((e=>e.startsWith("s="))))||void 0===a?void 0:a.substring(2))||"-",h=(null===(l=c.find(((e,t)=>e.startsWith("c=")&&!s.inMediaSection(c,t))))||void 0===l?void 0:l.split(" ").slice(2)[0])||"",S=(null===(r=s.firstValueStartingWith(c,"a=msid-semantic:"))||void 0===r?void 0:r.trim())||"WMS",C=s.parseBundleGroup(c),v=c.findIndex((e=>e.startsWith("m="))),f=v>0?c.slice(0,v):c,I=s.firstValueStartingWith(f,"a=ice-ufrag:")||"",E=s.firstValueStartingWith(f,"a=ice-pwd:")||"",m=s.parseIceOptions(f),P=s.parseFingerprint(f),$=s.parseSetup(f),T=f.some((e=>"a=ice-lite"===e)),y=f.some((e=>"a=extmap-allow-mixed"===e));return{sessionId:d,sessionVersion:u,bundleGroup:C,iceUfrag:I,icePwd:E,iceOptions:m,fingerprint:P,setup:$,media:s.parseMediaSections(c,o,i,n),sessionName:g,originAddress:p,connectionAddress:h,msidSemantic:S,iceLite:T,extmapAllowMixed:y,stringPool:o}}static reconstructFromSDPData(e){var t,i,n,l,o,c;try{const d=[];if(d.push("v=0\r\n"),d.push(`o=- ${e.sessionId} ${e.sessionVersion} IN IP4 ${e.originAddress}\r\n`),d.push(`s=${e.sessionName}\r\n`),d.push("t=0 0\r\n"),(null===(i=null===(t=e.fingerprint)||void 0===t?void 0:t.hashValue)||void 0===i?void 0:i.length)>0&&d.push(`a=fingerprint:${s.fingerprintToString(e.fingerprint)}\r\n`),(null===(n=null==e?void 0:e.bundleGroup)||void 0===n?void 0:n.length)>0){const t=e.media.map((e=>e.mid)).join(" ");d.push(`a=group:BUNDLE ${t}\r\n`)}(null===(l=null==e?void 0:e.iceOptions)||void 0===l?void 0:l.length)>0&&d.push(`a=ice-options:${e.iceOptions.join(" ")}\r\n`),(null==e?void 0:e.extmapAllowMixed)&&d.push("a=extmap-allow-mixed\r\n"),(null===(o=null==e?void 0:e.msidSemantic)||void 0===o?void 0:o.length)>0&&d.push(`a=msid-semantic: ${e.msidSemantic}\r\n`),(null==e?void 0:e.iceLite)&&d.push("a=ice-lite\r\n"),null===(c=null==e?void 0:e.media)||void 0===c||c.forEach((t=>{s.buildMediaSection(d,t,e)}));const u=d.join("");if(r.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 r.error(`[647] [CallId: GLOBAL_LOGS] Failed to reconstruct SDP: ${e.message}`,{color:"red"}),r.error(e,{color:"red"}),(0,a.toCallException)(e)}}static extractSessionId(e){const t=e.find((e=>e.startsWith("o=")));return t&&t.split(" ")[1]||null}static extractSessionVersion(e){const t=e.find((e=>e.startsWith("o=")));if(!t)return null;const i=t.split(" "),n=parseInt(i[2]||"0",10);return isNaN(n)?null:n}static extractOriginAddress(e){const t=e.find((e=>e.startsWith("o=")));return t&&t.split(" ")[5]||null}static parseBundleGroup(e){const t=e.find((e=>e.startsWith("a=group:BUNDLE ")));return t?t.substring(15).split(" ").map((e=>parseInt(e,10))).filter((e=>!isNaN(e))):[]}static parseIceOptions(e){const t=e.find((e=>e.startsWith("a=ice-options:")));return t?t.substring(14).split(" "):[]}static parseFingerprint(e){var t;const i=e.find((e=>e.startsWith("a=fingerprint:")));if(i){const e=i.substring(14).split(" ",2);if(2===e.length){let i;switch(e[0].toLowerCase()){case"sha-256":default:i=l.HashFunction.SHA256;break;case"sha-1":i=l.HashFunction.SHA1;break;case"sha-384":i=l.HashFunction.SHA384;break;case"sha-512":i=l.HashFunction.SHA512;break;case"md5":i=l.HashFunction.MD5}const n=e[1].replace(/:/g,"");return{hashFunc:i,hashValue:new Uint8Array((null===(t=n.match(/.{1,2}/g))||void 0===t?void 0:t.map((e=>parseInt(e,16))))||[])}}}return{hashFunc:l.HashFunction.SHA256,hashValue:new Uint8Array(0)}}static parseSetup(e){const t=e.find((e=>e.startsWith("a=setup:")));switch(null==t?void 0:t.substring(8).toLowerCase()){case"active":return l.DTLSSetup.ACTIVE;case"passive":return l.DTLSSetup.PASSIVE;default:return l.DTLSSetup.ACTPASS}}static firstValueStartingWith(e,t){const i=e.find((e=>e.startsWith(t)));return i?i.substring(t.length):null}static inMediaSection(e,t){return e.map(((e,t)=>({line:e,index:t}))).filter((({line:e})=>e.startsWith("m="))).map((({index:e})=>e)).some((e=>e<t))}static parseMediaSections(e,t,i,n){const a=e.map(((e,t)=>({line:e,index:t}))).filter((({line:e})=>e.startsWith("m="))).map((({index:e})=>e));return a.map(((l,r)=>{const o=r<a.length-1?a[r+1]:e.length;return s.parseMediaSection(e.slice(l,o),t,i,n)})).filter((e=>null!==e))}static parseMediaSection(e,t,i,n){var a;try{const i=e[0].substring(2).split(" ");let n;switch(i[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 r.warn(`Skipping unknown media type: ${i[0]}`),null;const o=parseInt(i[1]||"9",10)||9,c=i.slice(3).map((e=>parseInt(e,10))).filter((e=>!isNaN(e))),d=s.firstValueStartingWith(e,"a=mid:")||"",u=s.parseDirection(e),p=s.firstValueStartingWith(e,"a=msid:"),[g,h,S]=s.parseMSID(p||null),C=e.some((e=>"a=rtcp-mux"===e)),v=e.some((e=>"a=rtcp-rsize"===e)),f=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])||"",E=s.firstValueStartingWith(e,"a=rtcp:")||"",m=new Map,P=[];c.forEach((e=>{m.set(e,{codecName:{id:e,mapKey:0},fmtp:[],rtcpFeedbackIds:[]}),P.push(e)})),e.filter((e=>e.startsWith("a=rtpmap:"))).forEach((e=>{const t=e.substring(9).split(" ",2);if(2===t.length){const e=parseInt(t[0],10);if(!isNaN(e)){const i=t[1];s.dynamicCodecNames.set(e,i);const n=s.CODEC_NAME_TO_MAP_KEY.get(i)||0;if(m.has(e)){const t=m.get(e);m.set(e,{codecName:{id:e,mapKey:n},fmtp:t.fmtp,rtcpFeedbackIds:t.rtcpFeedbackIds})}}}})),e.filter((e=>e.startsWith("a=fmtp:"))).forEach((e=>{const t=e.substring(7).split(" ",2);if(2===t.length){const e=parseInt(t[0],10);if(!isNaN(e)&&m.has(e)){const i=s.parseFmtp(t[1]),n=m.get(e);m.set(e,{codecName:n.codecName,fmtp:i,rtcpFeedbackIds:n.rtcpFeedbackIds})}}})),e.filter((e=>e.startsWith("a=rtcp-fb:"))).forEach((e=>{const t=e.substring(10).split(" ");if(t.length>=2){const e=parseInt(t[0],10);if(!isNaN(e)){let i="";for(let e=1;e<t.length;e++)i+=t[e]+(e!==t.length-1?" ":"");const n=s.RTCP_FEEDBACK_STRING_TO_ID.get(i);if(void 0!==n&&m.has(e)){const t=m.get(e),i=[...t.rtcpFeedbackIds];i.includes(n)||i.push(n),m.set(e,{codecName:t.codecName,fmtp:t.fmtp,rtcpFeedbackIds:i})}}}}));const $=P.map((e=>m.get(e))).filter((e=>void 0!==e)),T=s.parseExtmaps(e),y=s.parseSsrcs(e),O=s.parseSsrcGroups(e),F=s.parseCandidates(e),w=s.firstValueStartingWith(e,"a=ice-ufrag:"),R=s.firstValueStartingWith(e,"a=ice-pwd:"),A=w?s.addToStringPool(t,w):0,b=R?s.addToStringPool(t,R):0,N=e.find((e=>e.startsWith("a=ice-options:"))),k=N?N.substring(14).split(" "):void 0,_=e.find((e=>e.startsWith("a=fingerprint:"))),D=_?s.parseFingerprint([_]):{hashFunc:l.HashFunction.SHA256,hashValue:new Uint8Array(0)},M=e.find((e=>e.startsWith("a=setup:")));return{type:n,mid:d,direction:u,msidStream:g,msidTrackLabel:h,msidTrackId:S,rtcpMux:C,rtcpRsize:v,extmaps:T,codecs:$,ssrcGroups:O,ssrcs:y,connectionAddress:I,candidates:F,endOfCandidates:f,rtcpAddress:E,iceUfragRef:A,icePwdRef:b,iceOptions:k,fingerprint:D,setup:M?s.parseSetup([M]):l.DTLSSetup.ACTPASS,port:o}}catch(e){return r.error(`[647] [CallId: GLOBAL_LOGS] Failed to parse media section: ${e.message}`,{color:"red"}),r.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 t=e.split(" ",2);if(t.length<2)return[e,"",0];const i=t[0],n=t[1],a=n.lastIndexOf("_");if(a>0){const e=n.substring(a+1),t=parseInt(e,10);if(!isNaN(t))return[i,n.substring(0,a+1),t]}return[i,n,0]}static parseFmtp(e){if(0===e.trim().length)return[];const t=[];return e.split(";").forEach((e=>{const i=e.trim();if(0!==i.length)if(i.includes("=")){const e=i.split("=",2);t.push({key:e[0].trim(),value:e[1].trim()})}else t.push({key:"value",value:i})})),t}static parseExtmaps(e){return e.filter((e=>e.startsWith("a=extmap:"))).map((e=>{const t=e.substring(9).split(" ",2);if(2!==t.length)return null;const i=t[0].split("/")[0],n=parseInt(i,10);if(isNaN(n))return null;const a=t[1];return{id:n,mapKey:s.URI_TO_EXTMAP_ID.get(a)||0}})).filter((e=>null!==e))}static parseSsrcs(e){const t=new Map;return e.filter((e=>e.startsWith("a=ssrc:"))).forEach((e=>{const i=e.substring(7).split(" ");if(i.length>=2){const e=parseInt(i[0],10);if(isNaN(e))return;const n=e,a=t.get(n)||{};if(i[1].startsWith("cname:"))a.cname=i[1].substring(6);else if(i[1].startsWith("msid:")){let e="";for(let t=1;t<i.length;t++)e+=i[t].substring(1===t?5:0)+(i.length-1!==t?" ":"");a.msid=e}t.set(n,a)}})),Array.from(t.entries()).map((([e,t])=>({id:e,cname:t.cname||"",msid:t.msid||""})))}static parseSsrcGroups(e){return e.filter((e=>e.startsWith("a=ssrc-group:"))).map((e=>{const t=e.substring(13).split(" ");return t.length>=2?{semantics:t[0],ssrcs:t.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=>s.parseCandidate(e.substring(12)))).filter((e=>null!==e))}static parseCandidate(e){const t=e.split(" ");if(t.length<8)return null;const i=parseInt(t[0],10);if(isNaN(i))return null;const n=parseInt(t[1],10);if(isNaN(n))return null;let a;switch(t[2].toLowerCase()){case"udp":default:a=l.IceCandidateProtocol.UDP;break;case"tcp":a=l.IceCandidateProtocol.TCP}const r=parseInt(t[3],10);if(isNaN(r))return null;const s=t[4].split("."),o=new Uint8Array(s.map((e=>parseInt(e,10)))),c=parseInt(t[5],10);if(isNaN(c))return null;let d;switch(t[7].toLowerCase()){case"host":default:d=l.IceCandidateType.HOST;break;case"srflx":d=l.IceCandidateType.SRFLX;break;case"prflx":d=l.IceCandidateType.PRFLX;break;case"relay":d=l.IceCandidateType.RELAY}let u=new Uint8Array(0),p=0,g=l.IceCandidateTcpType.ACTIVE,h=8;for(;h<t.length;){switch(t[h]){case"raddr":if(h+1<t.length){const e=t[++h];u=new Uint8Array(e.split(".").map((e=>parseInt(e,10))))}break;case"rport":h+1<t.length&&(p=parseInt(t[++h],10)||0);break;case"tcptype":if(h+1<t.length)switch(t[++h].toLowerCase()){case"active":default:g=l.IceCandidateTcpType.ACTIVE;break;case"passive":g=l.IceCandidateTcpType.PASSIVE;break;case"so":g=l.IceCandidateTcpType.SO}}h++}return{foundation:i,component:n,protocol:a,priority:r,ip:o,port:c,type:d,raddr:u,rport:p,tcptype:g}}static addToStringPool(e,t){if(0===t.length)return 0;const i=e.indexOf(t);return i>=0?i+1:(e.push(t),e.length)}static getFromStringPool(e,t){return 0===t||t>e.length?"":e[t-1]}static getCodecID(e){var t;return(null===(t=e.codecName)||void 0===t?void 0:t.id)||0}static getCodecName(e){if(!e.codecName)return null;const t=e.codecName;if(t.mapKey>0){const e=s.MAP_KEY_TO_CODEC_NAME.get(t.mapKey);if(e)return e}return s.dynamicCodecNames.get(t.id)||null}static filterVideoCodecs(e,t){if(0===t.length)return e;const i=[],n=new Set;return e.forEach((e=>{const a=s.getCodecName(e);if(!a)return;const l=a.split("/")[0];t.some((e=>e.toLowerCase()===l.toLowerCase()))&&(i.push(e),n.add(s.getCodecID(e)))})),e.forEach((e=>{const t=s.getCodecName(e);if(t&&t.toLowerCase().startsWith("rtx/")){const t=e.fmtp.find((e=>"apt"===e.key)),a=t?parseInt(t.value,10):null;null!==a&&!isNaN(a)&&n.has(a)&&i.push(e)}})),i}static buildMediaSection(e,t,i){var n,a,o,c,d,u,p,g,h,S;let C;switch(t.type){case l.MediaType.AUDIO:C="audio";break;case l.MediaType.VIDEO:C="video";break;case l.MediaType.MEDIA_TYPE_UNSPECIFIED:return void r.error("Cannot reconstruct MEDIA_TYPE_UNSPECIFIED")}const v=(null===(n=null==t?void 0:t.codecs)||void 0===n?void 0:n.map((e=>s.getCodecID(e).toString())).join(" "))||"";e.push(`m=${C} ${t.port} UDP/TLS/RTP/SAVPF ${v}\r\n`);const f=(null==t?void 0:t.connectionAddress)||(null==i?void 0:i.connectionAddress)||"0.0.0.0";e.push(`c=IN IP4 ${f}\r\n`),(null===(a=null==t?void 0:t.rtcpAddress)||void 0===a?void 0:a.length)>0&&e.push(`a=rtcp:${t.rtcpAddress}\r\n`);const I=(null==t?void 0:t.iceUfragRef)>0?s.getFromStringPool(null==i?void 0:i.stringPool,null==t?void 0:t.iceUfragRef):null==i?void 0:i.iceUfrag,E=(null==t?void 0:t.icePwdRef)>0?s.getFromStringPool(null==i?void 0:i.stringPool,null==t?void 0:t.icePwdRef):null==i?void 0:i.icePwd;I.length>0&&e.push(`a=ice-ufrag:${I}\r\n`),E.length>0&&e.push(`a=ice-pwd:${E}\r\n`);const m=(null==t?void 0:t.iceOptions)||(null==i?void 0:i.iceOptions);m.length>0&&e.push(`a=ice-options:${m.join(" ")}\r\n`);const P=(null===(c=null===(o=null==t?void 0:t.fingerprint)||void 0===o?void 0:o.hashValue)||void 0===c?void 0:c.length)>0?null==t?void 0:t.fingerprint:null==i?void 0:i.fingerprint;(null===(d=null==P?void 0:P.hashValue)||void 0===d?void 0:d.length)>0&&e.push(`a=fingerprint:${s.fingerprintToString(P)}\r\n`);const $=(null==t?void 0:t.setup)!==l.DTLSSetup.ACTPASS||(null==i?void 0:i.setup)===l.DTLSSetup.ACTPASS?t.setup:i.setup;e.push(`a=setup:${s.setupToString($)}\r\n`),e.push(`a=mid:${null==t?void 0:t.mid}\r\n`),null===(u=null==t?void 0:t.extmaps)||void 0===u||u.forEach((t=>{const i=s.EXTMAP_ID_TO_URI.get(t.mapKey)||`urn:ietf:params:rtp-hdrext:extension-${t.id}`;e.push(`a=extmap:${t.id} ${i}\r\n`)})),e.push(`a=${s.directionToString(null==t?void 0:t.direction)}\r\n`);const T=s.reconstructMSID(null==t?void 0:t.msidStream,null==t?void 0:t.msidTrackLabel,null==t?void 0:t.msidTrackId);(null==T?void 0:T.length)>0&&e.push(`a=msid:${T}\r\n`),(null==t?void 0:t.rtcpMux)&&e.push("a=rtcp-mux\r\n"),(null==t?void 0:t.rtcpRsize)&&e.push("a=rtcp-rsize\r\n"),null===(p=null==t?void 0:t.codecs)||void 0===p||p.forEach((t=>{var i,n;const a=s.getCodecID(t),l=s.getCodecName(t);if(l&&e.push(`a=rtpmap:${a} ${l}\r\n`),null===(i=null==t?void 0:t.rtcpFeedbackIds)||void 0===i||i.forEach((t=>{const i=s.RTCP_FEEDBACK_ID_TO_STRING.get(t);i&&e.push(`a=rtcp-fb:${a} ${i}\r\n`)})),(null===(n=null==t?void 0:t.fmtp)||void 0===n?void 0:n.length)>0){const i=s.reconstructFmtp(t.fmtp);e.push(`a=fmtp:${a} ${i}\r\n`)}})),null===(g=null==t?void 0:t.ssrcGroups)||void 0===g||g.forEach((t=>{const i=t.ssrcs.map((e=>(e>>>0).toString())).join(" ");e.push(`a=ssrc-group:${t.semantics} ${i}\r\n`)})),null===(h=null==t?void 0:t.ssrcs)||void 0===h||h.forEach((t=>{var i,n;const a=(t.id>>>0).toString();(null===(i=null==t?void 0:t.cname)||void 0===i?void 0:i.length)>0&&e.push(`a=ssrc:${a} cname:${t.cname}\r\n`),(null===(n=null==t?void 0:t.msid)||void 0===n?void 0:n.length)>0&&e.push(`a=ssrc:${a} msid:${t.msid}\r\n`)})),null===(S=null==t?void 0:t.candidates)||void 0===S||S.forEach((t=>{e.push(`a=candidate:${s.reconstructCandidate(t)}\r\n`)})),(null==t?void 0:t.endOfCandidates)&&e.push("a=end-of-candidates\r\n")}static reconstructMSID(e,t,i){return 0===e.length?"":0===t.length&&0===i?e:i>0&&t.length>0?`${e} ${t}${i}`:t.length>0?`${e} ${t}`:e}static reconstructFmtp(e){return e.map((e=>"value"===e.key?e.value:`${e.key}=${e.value}`)).join(";")}static fingerprintToString(e){let t;switch(e.hashFunc){case l.HashFunction.SHA256:t="sha-256";break;case l.HashFunction.SHA1:t="sha-1";break;case l.HashFunction.SHA384:t="sha-384";break;case l.HashFunction.SHA512:t="sha-512";break;case l.HashFunction.MD5:t="md5"}return`${t} ${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 t=e.protocol===l.IceCandidateProtocol.UDP?"udp":"tcp";let i;switch(e.type){case l.IceCandidateType.HOST:i="host";break;case l.IceCandidateType.SRFLX:i="srflx";break;case l.IceCandidateType.PRFLX:i="prflx";break;case l.IceCandidateType.RELAY:i="relay"}const n=[e.foundation.toString(),e.component.toString(),t,e.priority.toString(),Array.from(e.ip).map((e=>(255&e).toString())).join("."),e.port.toString(),"typ",i];if(e.raddr.length>0){n.push("raddr");const t=Array.from(e.raddr).map((e=>(255&e).toString())).join(".");n.push(t)}if(e.rport>0&&(n.push("rport"),n.push(e.rport.toString())),"tcp"===t){let t;switch(e.tcptype){case l.IceCandidateTcpType.ACTIVE:t="active";break;case l.IceCandidateTcpType.PASSIVE:t="passive";break;case l.IceCandidateTcpType.SO:t="so"}n.push("tcptype"),n.push(t)}return n.join(" ")}}t.SdpConverter=s,s.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"]]),s.URI_TO_EXTMAP_ID=new Map(Array.from(s.EXTMAP_ID_TO_URI.entries()).map((([e,t])=>[t,e]))),s.RTCP_FEEDBACK_ID_TO_STRING=new Map([[1,"goog-remb"],[2,"transport-cc"],[3,"ccm fir"],[4,"nack"],[5,"nack pli"]]),s.RTCP_FEEDBACK_STRING_TO_ID=new Map(Array.from(s.RTCP_FEEDBACK_ID_TO_STRING.entries()).map((([e,t])=>[t,e]))),s.dynamicCodecNames=new Map,s.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]]),s.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,t)=>{var i,n,a,l,r,s,o;Object.defineProperty(t,"__esModule",{value:!0}),t.IceCandidateTcpType=t.IceCandidateType=t.IceCandidateProtocol=t.MediaDirection=t.MediaType=t.DTLSSetup=t.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"}(i||(t.HashFunction=i={})),function(e){e[e.ACTIVE=0]="ACTIVE",e[e.PASSIVE=1]="PASSIVE",e[e.ACTPASS=2]="ACTPASS"}(n||(t.DTLSSetup=n={})),function(e){e[e.AUDIO=0]="AUDIO",e[e.VIDEO=1]="VIDEO",e[e.MEDIA_TYPE_UNSPECIFIED=2]="MEDIA_TYPE_UNSPECIFIED"}(a||(t.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||(t.MediaDirection=l={})),function(e){e[e.UDP=0]="UDP",e[e.TCP=1]="TCP"}(r||(t.IceCandidateProtocol=r={})),function(e){e[e.HOST=0]="HOST",e[e.SRFLX=1]="SRFLX",e[e.PRFLX=2]="PRFLX",e[e.RELAY=3]="RELAY"}(s||(t.IceCandidateType=s={})),function(e){e[e.ACTIVE=0]="ACTIVE",e[e.PASSIVE=1]="PASSIVE",e[e.SO=2]="SO"}(o||(t.IceCandidateTcpType=o={}))},828:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.QueuedSignal=void 0;const n=i(795),a=i(429);class l{constructor(e,t,i=n.SignalQueueStrategy.getSignalPriority(e),l=Date.now(),r=0,s=(0,a.v4)()){this.signal=e,this.callback=t,this.priority=i,this.timestamp=l,this.requeueCount=r,this.uniqueKey=s}get callId(){return this.signal.callId}compareTo(e){const t=e.priority-this.priority;return 0!==t?t:this.timestamp-e.timestamp}equals(e){return e instanceof l&&e.signal===this.signal}toString(){return`QueuedSignal(signal=${JSON.stringify(this.signal)}, timestamp=${this.timestamp}, priority=${this.priority}, requeueCount=${this.requeueCount}, uniqueKey=${this.uniqueKey})`}}t.QueuedSignal=l},795:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SignalQueueStrategy=t.SignalProcessingStrategy=void 0;const n=i(578),a=i(586),l=i(228);var r;!function(e){e[e.SEQUENTIAL=0]="SEQUENTIAL",e[e.IMMEDIATE=1]="IMMEDIATE"}(r||(t.SignalProcessingStrategy=r={}));class s{static getProcessingStrategy(e){return this.SEQUENTIAL_SIGNALS.has(e)?r.SEQUENTIAL:r.IMMEDIATE}static isSequentialSignal(e){return this.getProcessingStrategy(e)===r.SEQUENTIAL}static isImmediateSignal(e){return this.getProcessingStrategy(e)===r.IMMEDIATE}static getSignalPriorityValue(e,t){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: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,e)}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}}}t.SignalQueueStrategy=s,s.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,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{o(n.next(e))}catch(e){l(e)}}function s(e){try{o(n.throw(e))}catch(e){l(e)}}function o(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,s)}o((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.SignalingQueue=t.SignalLevel=void 0;const a=i(795),l=(0,i(645).createLogger)("SignalingQueue");var r;!function(e){e[e.GlobalBlocking=0]="GlobalBlocking",e[e.ParticipantLevel=1]="ParticipantLevel",e[e.Immediate=2]="Immediate"}(r||(t.SignalLevel=r={})),t.SignalingQueue=class{constructor(e,t,i){this.id=e,this.isTransportConnected=t,this.sender=i,this.globalBlockingSignals=[],this.immediateSignals=[],this.participantSignals=new Map,this.processingSignalJobs=new Map,this.participantJobs=new Map,this.sentSignals=new Set}getSignalKey(e,t){return`${t}_${e.event}_${e.callId}_${e.sessionId||""}`}addSignalToQueue(e){const t=this.getSignalKey(e.signal,e.uniqueKey);if(this.sentSignals.has(t))return void l.info(`[38] [CallId: ${e.signal.callId}] Signal already sent, skipping: ${e.toString()}`);const i=a.SignalQueueStrategy.getSignalLevel(e.signal);switch(i){case r.GlobalBlocking:this.globalBlockingSignals.push(e);break;case r.ParticipantLevel:const t=e.signal.to||"";this.participantSignals.has(t)||this.participantSignals.set(t,[]),this.participantSignals.get(t).push(e);break;case r.Immediate:this.immediateSignals.push(e)}l.info(`[61] [CallId: ${e.signal.callId}] Add signal to queue ===> level: ${i}, signal: ${JSON.stringify({signal:e.signal,uniqueKey:e.uniqueKey})}`),this.invalidateToSendSignalsIfNeeded()}removeSignalFromQueue(e){const t=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.delete(t)}invalidateToSendSignalsIfNeeded(){this.isTransportConnected()?this.globalBlockingSignals.length>0?this.sendGlobalBlockingSignals():(this.sendParticipantSignals(),this.sendImmediateLevelSignals()):l.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 t=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.has(t)?l.info(`[107] [CallId: ${this.id}] Global blocking signal already sent, skipping: ${e.toString()}`):(l.info(`[111] [CallId: ${this.id}] Sending ${r.GlobalBlocking} level signal: ${e.toString()}`),yield this.sendSignal(e),this.sentSignals.add(t))}}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 t=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.has(t)?l.info(`[145] [CallId: ${this.id}] Immediate signal already sent, skipping: ${e.toString()}`):(l.info(`[148] [CallId: ${this.id}] Sending ${r.Immediate} level signal: ${e.toString()}`),yield this.sendSignal(e),this.sentSignals.add(t))}}finally{this.processingSignalJobs.delete(r.Immediate)}}}))}sendParticipantSignals(){if(!(this.globalBlockingSignals.length>0))for(const[e,t]of this.participantSignals.entries())t.length>0&&this.sendParticipantSignal(e,t)}sendParticipantSignal(e,t){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 i=t.shift();if(!i)break;const n=this.getSignalKey(i.signal,i.uniqueKey);this.sentSignals.has(n)?l.info(`[185] [CallId: ${this.id}] Participant signal already sent, skipping: ${i.toString()}`):(l.info(`[188] [CallId: ${this.id}] Sending ${r.ParticipantLevel} level signal for identity ${e}: ${i.toString()}`),yield this.sendSignal(i),this.sentSignals.add(n))}}finally{this.participantJobs.delete(e),0===t.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=>{l.error(`[209] [CallId: ${this.id}] Error sending signal: ${e}`)}))}))}clearParticipantSignals(e){this.participantSignals.delete(e),this.participantJobs.delete(e),l.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(),l.info(`[227] [CallId: ${this.id}] Cleared all signals for queueId: ${this.id}`)}getGlobalBlockingSignals(){return this.globalBlockingSignals}}},786:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{o(n.next(e))}catch(e){l(e)}}function s(e){try{o(n.throw(e))}catch(e){l(e)}}function o(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,s)}o((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Signaling=void 0;const a=i(578),l=i(645),r=i(828),s=i(586),o=i(228),c=i(65),d=i(429),u=(0,l.createLogger)("Signaling");class p{constructor(e,t){this.signalingQueues=new Map,this.chatClient=e;const i=new this.chatClient.ChannelListener;i.onSignal=e=>{t(e)},this.chatClient.addChannelListener("call_listeners",i)}calculateRetryDelay(e){return Math.min(p.BASE_DELAY_MS*Math.pow(2,e),p.MAX_DELAY_MS)}handleRetry(e,t,i,a){var l;return n(this,void 0,void 0,(function*(){if(t>=p.MAX_RETRIES)throw u.error(`[45] [CallId: ${e.signal.callId}] Max retries exceeded for signal: ${JSON.stringify(e.signal)}`,{color:"red"}),(0,o.toCallException)(i);i instanceof c.SceytCallException&&!i.isResendable&&(u.error(`[49] [CallId: ${e.signal.callId}] Signal sending failed with non-resendable exception: ${i.message}`,{color:"red"}),null===(l=e.callback)||void 0===l||l.call(e,i),a.removeSignalFromQueue(e));const n=this.calculateRetryDelay(t);u.error(`[53] [CallId: ${e.signal.callId}] Sending signal failed with error: ${i.message}, but ChatClient is connected. Retrying in ${n}ms (attempt ${t+1}/${p.MAX_RETRIES})`,{color:"red"}),yield new Promise((e=>setTimeout(e,n)));try{const t=yield this.sendSignalSuspended(e);return u.info(`[64] [CallId: ${e.signal.callId}] Retry sending signal success: ${JSON.stringify(t)}`),t}catch(i){return u.error(`[67] [CallId: ${e.signal.callId}] Retry sending signal failed: ${i instanceof Error?i.message:String(i)}`),this.handleRetry(e,t+1,i instanceof Error?i:new Error(String(i)),a)}}))}sendSignalSuspended(e){return n(this,void 0,void 0,(function*(){try{u.info(`[78] [CallId: ${e.signal.callId}] Sending signal to chat client: version: 132 ${JSON.stringify(e.signal)}`);const t=yield this.chatClient.sendSignal(e.signal,132);if(null==t?void 0:t.error)throw(0,o.toCallException)(t.error);return(0,o.handleAck)(t)}catch(e){throw(0,o.toCallException)(e)}}))}sendSignalMessage(e,t,i){u.info(`[92] [CallId: ${e.callId}] Sending signal message request: ${a.SignalEvent[e.event]} uniqueKey: ${(0,d.v4)()} ${JSON.stringify(e)}`,{color:"yellow"});const l=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}),g=i||e.callId;let h=this.signalingQueues.get(g);h||(h=new s.SignalingQueue(g,(()=>"Connected"===this.chatClient.connectionState),(e=>n(this,void 0,void 0,(function*(){var t,i,n,l,s;try{const l=yield this.sendSignalSuspended(e);if(u.info(`[115] [CallId: ${e.signal.callId||"GLOBAL_LOGS"}] Sent signal message response: ${a.SignalEvent[e.signal.event]} uniqueKey: ${e.uniqueKey} ${JSON.stringify(l)}`,{color:"magenta"}),(null==l?void 0:l.event)===a.SignalEvent.ERROR)throw(0,o.checkCode)((null===(t=null==l?void 0:l.error)||void 0===t?void 0:t.code)||0,(null===(i=null==l?void 0:l.error)||void 0===i?void 0:i.message)||"Unknown error");return null===(n=e.callback)||void 0===n||n.call(e,l),null==h||h.removeSignalFromQueue(e),l}catch(t){if(u.error(`[125] [CallId: ${e.signal.callId||"GLOBAL_LOGS"}] Signal message error: ${a.SignalEvent[e.signal.event]} uniqueKey: ${e.uniqueKey} error: ${t instanceof Error?t.message:String(t)}, resendable: ${t instanceof c.SceytCallException&&t.isResendable}`,{color:"red"}),t instanceof c.SceytCallException&&t.isResendable){const i=e.requeueCount;i<p.REQUEUE_LIMIT?null==h||h.addSignalToQueue(new r.QueuedSignal(e.signal,e.callback,e.priority,e.timestamp,i+1,(0,d.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===(l=e.callback)||void 0===l||l.call(e,t),null==h||h.removeSignalFromQueue(e))}const i=t instanceof c.SceytCallException?t:new Error(t instanceof Error?t.message:String(t));null===(s=e.callback)||void 0===s||s.call(e,i),null==h||h.removeSignalFromQueue(e)}})))),this.signalingQueues.set(g,h)),h.addSignalToQueue(new r.QueuedSignal(l,t,0,0,0,(0,d.v4)()))}clearCallSignals(e){const t=this.signalingQueues.get(e);t&&(t.clearCallSignals(),this.signalingQueues.delete(e))}clearParticipantSignals(e,t){const i=this.signalingQueues.get(e);i&&i.clearParticipantSignals(t)}cancelJoinIfPossible(e){const t=this.signalingQueues.get(e);return!!t&&(!!t.getGlobalBlockingSignals().find((e=>e.signal.event==a.SignalEvent.JOIN))&&(t.clearCallSignals(),!0))}}t.Signaling=p,p.REQUEUE_LIMIT=10,p.MAX_RETRIES=10,p.BASE_DELAY_MS=1e3,p.MAX_DELAY_MS=8e3},342:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ReceiveSignalValidator=void 0;const n=i(578),a=(0,i(645).createLogger)("ReceiveSignalValidator");class l{static canHandleSignal(e,t){const i=l.validateSignal(e,t.state,t.localParticipant);return i||a.warn(`Cannot handle signal ${e.event} in call state ${t.state} with local participant state ${t.localParticipant.state}`),i}static validateSignal(e,t,i){switch(e.event){case n.SignalEvent.JOIN:case n.SignalEvent.LEAVE:return!0;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:return t===n.CallState.Connected;case n.SignalEvent.KICK:return!0;case n.SignalEvent.INVITE:return!e.participants||!e.participants.some((e=>e.id===i.id))||t===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 t===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.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}}}t.ReceiveSignalValidator=l},771:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SendSignalValidator=void 0;const n=i(578),a=(0,i(645).createLogger)("SendSignalValidator");class l{canSendSignal(e,t){const i=l.validateSignalEvent(e.event,t.state);return i||a.warn(`Cannot send signal ${e.event} in call state ${t.state} with local participant state ${t.localParticipant.state}`),i}canSendSignalEvent(e,t){const i=l.validateSignalEvent(e,t.state);return i||a.warn(`Cannot send signal ${e} in call state ${t.state} with local participant state ${t.localParticipant.state}`),i}static validateSignalEvent(e,t){const i=t===n.CallState.Connected;switch(e){case n.SignalEvent.JOIN:return!0;case n.SignalEvent.LEAVE:return i;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:case n.SignalEvent.CONNECT:case n.SignalEvent.KICK:case n.SignalEvent.INVITE:return t===n.CallState.Connected;case n.SignalEvent.DECLINE:return t===n.CallState.Idle;case n.SignalEvent.RINGING:return t===n.CallState.Idle||t===n.CallState.Connecting;case n.SignalEvent.INFO:case n.SignalEvent.UPDATE:return t===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 t===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:return i;case n.SignalEvent.SCREEN_SHARE_ON:case n.SignalEvent.SCREEN_SHARE_OFF:return t===n.CallState.Connected;default:return a.warn(`Unknown signal event for sending: ${e}`),!1}}}t.SendSignalValidator=l},302:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ReceiveSignalValidator=t.SendSignalValidator=void 0;var n=i(771);Object.defineProperty(t,"SendSignalValidator",{enumerable:!0,get:function(){return n.SendSignalValidator}});var a=i(342);Object.defineProperty(t,"ReceiveSignalValidator",{enumerable:!0,get:function(){return a.ReceiveSignalValidator}})},740:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.VideoTrack=void 0,t.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,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{o(n.next(e))}catch(e){l(e)}}function s(e){try{o(n.throw(e))}catch(e){l(e)}}function o(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,s)}o((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.WebRTCClient=void 0;const a=i(578),l=i(645),r=i(19),s=i(680),o=(0,l.createLogger)("WebRTCClient");t.WebRTCClient=class{constructor(e,t){this.listeners={},this.sessionId=null,this.version=null,this.iceQueueMap={},this.configuration=t,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){o.info(`[18] [CallId: ${this.callId}] setListeners in webrtcClient: listeners`,{color:"blue"}),this.listeners=e}setConfiguration(e){o.info(`[21] [CallId: ${this.callId}] setConfiguration in webrtcClient: configuration: ${e}`,{color:"blue"}),this.configuration=e}getPreferredAudioCodecs(e){const t=RTCRtpReceiver.getCapabilities("audio");return t?t.codecs.filter((t=>{const i=t.mimeType.split("/")[1].toLowerCase();return e===a.MediaFlow.S2W?r.CODEC_NAME_TO_AUDIO_CODEC_S2W.includes(i):r.CODEC_NAME_TO_AUDIO_CODEC.includes(i)})):[]}getPreferredVideoCodecs(){const e=RTCRtpSender.getCapabilities("video");if(!e)return[];const t=[];return r.CODEC_NAME_TO_VIDEO_CODEC.forEach((i=>{const n=e.codecs.find((e=>e.mimeType.split("/")[1].toLowerCase()===i.toLowerCase()));n&&t.push(n)})),t}setPreferredCodecs(e,t,i){if("video"===t){o.info(`[74] [CallId: ${this.callId}] setPreferredCodecs: video, mediaFlow: ${e}`,{color:"blue"});const t=this.getPreferredVideoCodecs(),n=[];t.forEach((e=>{n.push({mimeType:e.mimeType,clockRate:e.clockRate,sdpFmtpLine:e.sdpFmtpLine,channels:e.channels})})),i.setCodecPreferences(n)}else if("audio"===t){o.info(`[88] [CallId: ${this.callId}] setPreferredCodecs: audio, mediaFlow: ${e}`,{color:"blue"});const t=this.getPreferredAudioCodecs(e),n=[];t.forEach((e=>{n.push({mimeType:e.mimeType,clockRate:e.clockRate,sdpFmtpLine:e.sdpFmtpLine||"",channels:e.channels||void 0})})),i.setCodecPreferences(n)}}addTransceiverToPeerConnection(e,t){o.info(`[56] [CallId: ${this.callId}] addTransceiverToPeerConnection in webrtcClient: track: ${null==e?void 0:e.kind}`,{color:"blue"}),this.peerConnection.addTransceiver(e,{direction:"sendrecv"});const i=this.peerConnection.getTransceivers().find((t=>{var i;return(null===(i=t.receiver.track)||void 0===i?void 0:i.kind)===(null==e?void 0:e.kind)}));if(i&&"video"===(null==e?void 0:e.kind)){this.setPreferredCodecs(t,"video",i);try{const e=i.sender.getParameters();e.encodings&&e.encodings.length>0&&(e.encodings.forEach((e=>{e.maxBitrate=5e5})),i.sender.setParameters(e),o.info(`[57] [CallId: ${this.callId}] addTransceiverToPeerConnection: Set video max bitrate to 500 kbps`,{color:"blue"}))}catch(e){o.warn(`[58] [CallId: ${this.callId}] addTransceiverToPeerConnection: Failed to set video bitrate: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"yellow"})}}else i&&"audio"===(null==e?void 0:e.kind)&&this.setPreferredCodecs(t,"audio",i)}setStreamsToTransceiver(e){var t,i;return n(this,void 0,void 0,(function*(){o.info(`[61] [CallId: ${this.callId}] setStreamsToTransceiver in webrtcClient: track: ${null==e?void 0:e.kind}`,{color:"blue"});const n=this.peerConnection.getTransceivers();o.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 t,i;const n=null===(t=e.receiver.track)||void 0===t?void 0:t.kind,l=null===(i=e.sender.track)||void 0===i?void 0:i.kind;return n===a||l===a}));if(o.info(`[63] [CallId: ${this.callId}] setStreamsToTransceiver: transceiver found: ${!!l}, receiver track: ${null===(t=null==l?void 0:l.receiver.track)||void 0===t?void 0:t.kind}, sender track: ${null===(i=null==l?void 0:l.sender.track)||void 0===i?void 0:i.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 o.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 t=l.direction,i=l.sender.track,n=i?i.kind:"null";o.info(`[65] [CallId: ${this.callId}] setStreamsToTransceiver: Attached local ${a} track to transceiver, direction: ${t}, sender track: ${n}, track enabled: ${null==e?void 0:e.enabled}, track id: ${null==e?void 0:e.id}`,{color:"blue"}),i||o.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 t,i;return{mid:e.mid,receiverKind:(null===(t=e.receiver.track)||void 0===t?void 0:t.kind)||"null",senderKind:(null===(i=e.sender.track)||void 0===i?void 0:i.kind)||"null",direction:e.direction}}));o.warn(`[67] [CallId: ${this.callId}] setStreamsToTransceiver: No transceiver found for track kind: ${a}. Available transceivers: ${JSON.stringify(e)}`,{color:"yellow"})}}))}enableVideoOnPeerConnection(e,t,i=!1){return n(this,void 0,void 0,(function*(){o.info(`[27] [CallId: ${this.callId}] enableVideoOnPeerConnection in webrtcClient: enable: ${e}, kind: ${null==t?void 0:t.kind}`,{color:"blue"});const n=this.peerConnection.getTransceivers();for(let a=0;a<n.length;a++){const l=n[a];l.sender.track&&"video"===l.sender.track.kind&&(t?(t.enabled=e,yield l.sender.replaceTrack(t)):l.sender.track.enabled=e);const r=l.sender.getParameters();r.encodings&&r.encodings.length>0&&(r.encodings.forEach((e=>{e.maxBitrate=i?75e4:5e5})),yield l.sender.setParameters(r),o.info(`[184] [CallId: ${this.callId}] enableVideoOnPeerConnection: Set video max bitrate to ${i?75e4:5e5} kbps`,{color:"blue"}))}}))}enableAudioOnPeerConnection(e,t){return n(this,void 0,void 0,(function*(){o.info(`[33] [CallId: ${this.callId}] enableAudioOnPeerConnection in webrtcClient: mute: ${e}, kind: ${null==t?void 0:t.kind}`,{color:"blue"});const i=this.peerConnection.getTransceivers();for(let n=0;n<i.length;n++){const a=i[n];a.sender.track&&"audio"===a.sender.track.kind&&(t?(t.enabled=!e,yield a.sender.replaceTrack(t)):a.sender.track.enabled=!e)}}))}createOffer(e,t,i){return n(this,void 0,void 0,(function*(){try{o.info(`[36] [CallId: ${this.callId}] createOffer in webrtcClient`,{color:"blue"});const n=yield this.peerConnection.createOffer({iceRestart:!0,offerToReceiveAudio:!0,offerToReceiveVideo:!0}),a=(0,s.toSessionData)({sdp:n,sessionId:e,versionId:t},i),l=(0,s.toSessionDescription)(a,"offer");return l?(yield this.setLocalDescription(l),a):(o.error(`[76] [CallId: ${this.callId}] createOffer in webrtcClient failed to convert session data to session description`,{color:"red"}),!1)}catch(e){return o.error(`[37] [CallId: ${this.callId}] createOffer in webrtcClient failed: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),!1}}))}createAnswer(e,t,i){return n(this,void 0,void 0,(function*(){try{o.info(`[75] [CallId: ${this.callId}] createAnswer in webrtcClient`,{color:"blue"});const n=yield this.peerConnection.createAnswer(),a=(0,s.toSessionData)({sdp:n,sessionId:e,versionId:t},i),l=(0,s.toSessionDescription)(a,"answer");return l?(yield this.setLocalDescription(l),a):(o.error(`[76] [CallId: ${this.callId}] createAnswer in webrtcClient failed to convert session data to session description`,{color:"red"}),!1)}catch(e){return o.error(`[70] [CallId: ${this.callId}] createAnswer in webrtcClient failed: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),!1}}))}setLocalDescription(e){var t;return o.info(`[44] [CallId: ${this.callId}] setLocalDescription in webrtcClient: sdp sliced 50: ${null===(t=null==e?void 0:e.sdp)||void 0===t?void 0:t.slice(0,50)}...`,{color:"blue"}),this.peerConnection.setLocalDescription(e)}setRemoteDescription(e){var t;return o.info(`[48] [CallId: ${this.callId}] setRemoteDescription in webrtcClient: sdp sliced 50: ${null===(t=e.sdp)||void 0===t?void 0:t.slice(0,50)}...`,{color:"blue"}),this.peerConnection.setRemoteDescription(e)}getLocalSdpUfrag(){var e;const t=((null===(e=this.peerConnection.localDescription)||void 0===e?void 0:e.sdp)||"").match(/a=ice-ufrag:(\S+)/);return t?t[1]:null}getRemoteSdpUfrag(){var e;const t=((null===(e=this.peerConnection.remoteDescription)||void 0===e?void 0:e.sdp)||"").match(/a=ice-ufrag:(\S+)/);return t?t[1]:null}getIceCandidateUfrag(e){const t=e.match(/ufrag\s+(\S+)/);return t?t[1]:null}isUfragEqualsSdpUfrag(e){return{equals:this.getIceCandidateUfrag(e)===this.getRemoteSdpUfrag(),ufrag:this.getIceCandidateUfrag(e),sdpUfrag:this.getRemoteSdpUfrag()}}addIceCandidate(e,t){if(o.info(`[52] [CallId: ${this.callId}] addIceCandidate in webrtcClient: candidate: ${e.candidate}`,{color:"blue"}),e.candidate){const i=this.isUfragEqualsSdpUfrag(e.candidate);if(!i.equals)return this.iceQueueMap[t]||(this.iceQueueMap[t]={}),void(i.ufrag&&(this.iceQueueMap[t][i.ufrag]||(this.iceQueueMap[t][i.ufrag]=[]),this.iceQueueMap[t][i.ufrag].push(e)))}return this.peerConnection.addIceCandidate(e)}addEventListener(e,t){this.peerConnection.addEventListener(e,t)}removeEventListener(e,t){this.peerConnection.removeEventListener(e,t)}close(){o.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,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TypedEventEmitter=void 0,t.TypedEventEmitter=class{constructor(){this.listeners=new Map}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{var i;null===(i=this.listeners.get(e))||void 0===i||i.delete(t)}}emit(e,t){var i;null===(i=this.listeners.get(e))||void 0===i||i.forEach((i=>{try{i(t)}catch(t){console.error(`Error in event handler for "${String(e)}":`,t)}}))}off(e,t){var i;t?null===(i=this.listeners.get(e))||void 0===i||i.delete(t):this.listeners.delete(e)}removeAllListeners(){this.listeners.clear()}listenerCount(e){var t,i;return null!==(i=null===(t=this.listeners.get(e))||void 0===t?void 0:t.size)&&void 0!==i?i:0}}},578:(e,t)=>{var i,n,a,l,r,s,o,c,d,u;Object.defineProperty(t,"__esModule",{value:!0}),t.CDRRequestDirection=t.CDRRequestEvent=t.CDRRequestOrder=t.ParticipantEntryType=t.MediaFlow=t.SignalEvent=t.CallState=t.MediaConnectionState=t.ParticipantConnectionState=t.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"}(i||(t.ParticipantState=i={})),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||(t.ParticipantConnectionState=n={})),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"}(a||(t.MediaConnectionState=a={})),function(e){e.Idle="idle",e.Connecting="connecting",e.Connected="connected",e.Closed="closed"}(l||(t.CallState=l={})),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"}(r||(t.SignalEvent=r={})),function(e){e[e.P2P=0]="P2P",e[e.SFU=1]="SFU",e[e.S2W=2]="S2W"}(s||(t.MediaFlow=s={})),function(e){e.ADDED="ADDED"}(o||(t.ParticipantEntryType=o={})),function(e){e[e.ASC=0]="ASC",e[e.DESC=1]="DESC"}(c||(t.CDRRequestOrder=c={})),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"}(d||(t.CDRRequestEvent=d={})),function(e){e[e.NEXT=0]="NEXT",e[e.PREVIOUS=1]="PREVIOUS"}(u||(t.CDRRequestDirection=u={}))},489:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.makeFirstById=t.getEmptyVideoTrack=void 0,t.getEmptyVideoTrack=()=>{const e=document.createElement("canvas");return e.getContext("2d"),e.width=640,e.height=480,e.captureStream().getVideoTracks()},t.makeFirstById=(e,t,i)=>{const n=new Set,a=e.filter((e=>{const t=`${e.id}${e.clientId?`/${e.clientId}`:""}`;return!n.has(t)&&(n.add(t),!0)})),l=a.findIndex((e=>e.id===t&&(e.clientId===i||!e.clientId)));if(l>-1){const[e]=a.splice(l,1);a.unshift(e)}return a}},607:function(e,t,i){var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var a=Object.getOwnPropertyDescriptor(t,i);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,a)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),a=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(t,"__esModule",{value:!0});const l=i(838);a(i(838),t),t.default=l.SceytCallClient},838:function(e,t,i){var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var a=Object.getOwnPropertyDescriptor(t,i);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,a)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),a=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(t,"__esModule",{value:!0}),t.CDRRequestDirection=t.CDRRequestEvent=t.CDRRequestOrder=t.ParticipantEntryType=t.MediaConnectionState=t.ParticipantConnectionState=t.ParticipantState=t.CallState=t.MediaFlow=t.VideoTrack=t.AudioTrack=t.Participant=t.Call=void 0,a(i(271),t);var l=i(998);Object.defineProperty(t,"Call",{enumerable:!0,get:function(){return l.Call}});var r=i(787);Object.defineProperty(t,"Participant",{enumerable:!0,get:function(){return r.Participant}});var s=i(250);Object.defineProperty(t,"AudioTrack",{enumerable:!0,get:function(){return s.AudioTrack}});var o=i(740);Object.defineProperty(t,"VideoTrack",{enumerable:!0,get:function(){return o.VideoTrack}});var c=i(578);Object.defineProperty(t,"MediaFlow",{enumerable:!0,get:function(){return c.MediaFlow}}),Object.defineProperty(t,"CallState",{enumerable:!0,get:function(){return c.CallState}}),Object.defineProperty(t,"ParticipantState",{enumerable:!0,get:function(){return c.ParticipantState}}),Object.defineProperty(t,"ParticipantConnectionState",{enumerable:!0,get:function(){return c.ParticipantConnectionState}}),Object.defineProperty(t,"MediaConnectionState",{enumerable:!0,get:function(){return c.MediaConnectionState}}),Object.defineProperty(t,"ParticipantEntryType",{enumerable:!0,get:function(){return c.ParticipantEntryType}}),Object.defineProperty(t,"CDRRequestOrder",{enumerable:!0,get:function(){return c.CDRRequestOrder}}),Object.defineProperty(t,"CDRRequestEvent",{enumerable:!0,get:function(){return c.CDRRequestEvent}}),Object.defineProperty(t,"CDRRequestDirection",{enumerable:!0,get:function(){return c.CDRRequestDirection}}),a(i(645),t)},645:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createLogger=t.removeLogListener=t.addLogListener=void 0;const i={green:"",blue:"","light-green":"","light-blue":"",yellow:"",magenta:"",cyan:"",reset:"",orange:"",red:"",white:""},n=[];t.addLogListener=e=>{n.push(e)},t.removeLogListener=e=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)},t.createLogger=(e,t="white")=>{const a=`[SceytCallClient] ${e?`[${e}]`:""}:`,l=(e,l,r,s)=>{var o;const c=null!==(o=null==s?void 0:s.color)&&void 0!==o?o:t,d={level:e,message:l,prefix:a,args:r.filter((e=>!(null==e?void 0:e.color)&&!(null==e?void 0:e.time))),color:i[c],time:(null==s?void 0:s.time)||(new Date).toISOString()};n.forEach((e=>e(d)))};return{trace:(e,t)=>{l("trace",e,[],t)},debug:(e,t)=>{l("debug",e,[],t)},info:(e,t)=>{l("info",e,[],t)},warn:(e,t)=>{l("warn",e,[],t)},error:(e,t)=>{l("error",e,[],t)}}},t.default=(0,t.createLogger)("SceytCallClient")},429:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"NIL",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(t,"parse",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(t,"stringify",{enumerable:!0,get:function(){return d.default}}),Object.defineProperty(t,"v1",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(t,"v3",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(t,"v4",{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(t,"v5",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(t,"validate",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(t,"version",{enumerable:!0,get:function(){return o.default}});var n=p(i(990)),a=p(i(237)),l=p(i(355)),r=p(i(764)),s=p(i(314)),o=p(i(464)),c=p(i(435)),d=p(i(8)),u=p(i(222));function p(e){return e&&e.__esModule?e:{default:e}}},163:(e,t)=>{function i(e){return 14+(e+64>>>9<<4)+1}function n(e,t){const i=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(i>>16)<<16|65535&i}function a(e,t,i,a,l,r){return n((s=n(n(t,e),n(a,r)))<<(o=l)|s>>>32-o,i);var s,o}function l(e,t,i,n,l,r,s){return a(t&i|~t&n,e,t,l,r,s)}function r(e,t,i,n,l,r,s){return a(t&n|i&~n,e,t,l,r,s)}function s(e,t,i,n,l,r,s){return a(t^i^n,e,t,l,r,s)}function o(e,t,i,n,l,r,s){return a(i^(t|~n),e,t,l,r,s)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default=function(e){if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(let i=0;i<t.length;++i)e[i]=t.charCodeAt(i)}return function(e){const t=[],i=32*e.length,n="0123456789abcdef";for(let a=0;a<i;a+=8){const i=e[a>>5]>>>a%32&255,l=parseInt(n.charAt(i>>>4&15)+n.charAt(15&i),16);t.push(l)}return t}(function(e,t){e[t>>5]|=128<<t%32,e[i(t)-1]=t;let a=1732584193,c=-271733879,d=-1732584194,u=271733878;for(let t=0;t<e.length;t+=16){const i=a,p=c,g=d,h=u;a=l(a,c,d,u,e[t],7,-680876936),u=l(u,a,c,d,e[t+1],12,-389564586),d=l(d,u,a,c,e[t+2],17,606105819),c=l(c,d,u,a,e[t+3],22,-1044525330),a=l(a,c,d,u,e[t+4],7,-176418897),u=l(u,a,c,d,e[t+5],12,1200080426),d=l(d,u,a,c,e[t+6],17,-1473231341),c=l(c,d,u,a,e[t+7],22,-45705983),a=l(a,c,d,u,e[t+8],7,1770035416),u=l(u,a,c,d,e[t+9],12,-1958414417),d=l(d,u,a,c,e[t+10],17,-42063),c=l(c,d,u,a,e[t+11],22,-1990404162),a=l(a,c,d,u,e[t+12],7,1804603682),u=l(u,a,c,d,e[t+13],12,-40341101),d=l(d,u,a,c,e[t+14],17,-1502002290),c=l(c,d,u,a,e[t+15],22,1236535329),a=r(a,c,d,u,e[t+1],5,-165796510),u=r(u,a,c,d,e[t+6],9,-1069501632),d=r(d,u,a,c,e[t+11],14,643717713),c=r(c,d,u,a,e[t],20,-373897302),a=r(a,c,d,u,e[t+5],5,-701558691),u=r(u,a,c,d,e[t+10],9,38016083),d=r(d,u,a,c,e[t+15],14,-660478335),c=r(c,d,u,a,e[t+4],20,-405537848),a=r(a,c,d,u,e[t+9],5,568446438),u=r(u,a,c,d,e[t+14],9,-1019803690),d=r(d,u,a,c,e[t+3],14,-187363961),c=r(c,d,u,a,e[t+8],20,1163531501),a=r(a,c,d,u,e[t+13],5,-1444681467),u=r(u,a,c,d,e[t+2],9,-51403784),d=r(d,u,a,c,e[t+7],14,1735328473),c=r(c,d,u,a,e[t+12],20,-1926607734),a=s(a,c,d,u,e[t+5],4,-378558),u=s(u,a,c,d,e[t+8],11,-2022574463),d=s(d,u,a,c,e[t+11],16,1839030562),c=s(c,d,u,a,e[t+14],23,-35309556),a=s(a,c,d,u,e[t+1],4,-1530992060),u=s(u,a,c,d,e[t+4],11,1272893353),d=s(d,u,a,c,e[t+7],16,-155497632),c=s(c,d,u,a,e[t+10],23,-1094730640),a=s(a,c,d,u,e[t+13],4,681279174),u=s(u,a,c,d,e[t],11,-358537222),d=s(d,u,a,c,e[t+3],16,-722521979),c=s(c,d,u,a,e[t+6],23,76029189),a=s(a,c,d,u,e[t+9],4,-640364487),u=s(u,a,c,d,e[t+12],11,-421815835),d=s(d,u,a,c,e[t+15],16,530742520),c=s(c,d,u,a,e[t+2],23,-995338651),a=o(a,c,d,u,e[t],6,-198630844),u=o(u,a,c,d,e[t+7],10,1126891415),d=o(d,u,a,c,e[t+14],15,-1416354905),c=o(c,d,u,a,e[t+5],21,-57434055),a=o(a,c,d,u,e[t+12],6,1700485571),u=o(u,a,c,d,e[t+3],10,-1894986606),d=o(d,u,a,c,e[t+10],15,-1051523),c=o(c,d,u,a,e[t+1],21,-2054922799),a=o(a,c,d,u,e[t+8],6,1873313359),u=o(u,a,c,d,e[t+15],10,-30611744),d=o(d,u,a,c,e[t+6],15,-1560198380),c=o(c,d,u,a,e[t+13],21,1309151649),a=o(a,c,d,u,e[t+4],6,-145523070),u=o(u,a,c,d,e[t+11],10,-1120210379),d=o(d,u,a,c,e[t+2],15,718787259),c=o(c,d,u,a,e[t+9],21,-343485551),a=n(a,i),c=n(c,p),d=n(d,g),u=n(u,h)}return[a,c,d,u]}(function(e){if(0===e.length)return[];const t=8*e.length,n=new Uint32Array(i(t));for(let i=0;i<t;i+=8)n[i>>5]|=(255&e[i/8])<<i%32;return n}(e),8*e.length))}},790:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};t.default=i},314:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.default="00000000-0000-0000-0000-000000000000"},222:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,a=(n=i(435))&&n.__esModule?n:{default:n};t.default=function(e){if(!(0,a.default)(e))throw TypeError("Invalid UUID");let t;const i=new Uint8Array(16);return i[0]=(t=parseInt(e.slice(0,8),16))>>>24,i[1]=t>>>16&255,i[2]=t>>>8&255,i[3]=255&t,i[4]=(t=parseInt(e.slice(9,13),16))>>>8,i[5]=255&t,i[6]=(t=parseInt(e.slice(14,18),16))>>>8,i[7]=255&t,i[8]=(t=parseInt(e.slice(19,23),16))>>>8,i[9]=255&t,i[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,i[11]=t/4294967296&255,i[12]=t>>>24&255,i[13]=t>>>16&255,i[14]=t>>>8&255,i[15]=255&t,i}},58:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.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,t)=>{let i;Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){if(!i&&(i="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!i))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return i(n)};const n=new Uint8Array(16)},757:(e,t)=>{function i(e,t,i,n){switch(e){case 0:return t&i^~t&n;case 1:case 3:return t^i^n;case 2:return t&i^t&n^i&n}}function n(e,t){return e<<t|e>>>32-t}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default=function(e){const t=[1518500249,1859775393,2400959708,3395469782],a=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=[];for(let i=0;i<t.length;++i)e.push(t.charCodeAt(i))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);const l=e.length/4+2,r=Math.ceil(l/16),s=new Array(r);for(let t=0;t<r;++t){const i=new Uint32Array(16);for(let n=0;n<16;++n)i[n]=e[64*t+4*n]<<24|e[64*t+4*n+1]<<16|e[64*t+4*n+2]<<8|e[64*t+4*n+3];s[t]=i}s[r-1][14]=8*(e.length-1)/Math.pow(2,32),s[r-1][14]=Math.floor(s[r-1][14]),s[r-1][15]=8*(e.length-1)&4294967295;for(let e=0;e<r;++e){const l=new Uint32Array(80);for(let t=0;t<16;++t)l[t]=s[e][t];for(let e=16;e<80;++e)l[e]=n(l[e-3]^l[e-8]^l[e-14]^l[e-16],1);let r=a[0],o=a[1],c=a[2],d=a[3],u=a[4];for(let e=0;e<80;++e){const a=Math.floor(e/20),s=n(r,5)+i(a,o,c,d)+u+t[a]+l[e]>>>0;u=d,d=c,c=n(o,30)>>>0,o=r,r=s}a[0]=a[0]+r>>>0,a[1]=a[1]+o>>>0,a[2]=a[2]+c>>>0,a[3]=a[3]+d>>>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,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.unsafeStringify=r;var n,a=(n=i(435))&&n.__esModule?n:{default:n};const l=[];for(let e=0;e<256;++e)l.push((e+256).toString(16).slice(1));function r(e,t=0){return l[e[t+0]]+l[e[t+1]]+l[e[t+2]]+l[e[t+3]]+"-"+l[e[t+4]]+l[e[t+5]]+"-"+l[e[t+6]]+l[e[t+7]]+"-"+l[e[t+8]]+l[e[t+9]]+"-"+l[e[t+10]]+l[e[t+11]]+l[e[t+12]]+l[e[t+13]]+l[e[t+14]]+l[e[t+15]]}t.default=function(e,t=0){const i=r(e,t);if(!(0,a.default)(i))throw TypeError("Stringified UUID is invalid");return i}},990:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,a=(n=i(319))&&n.__esModule?n:{default:n},l=i(8);let r,s,o=0,c=0;t.default=function(e,t,i){let n=t&&i||0;const d=t||new Array(16);let u=(e=e||{}).node||r,p=void 0!==e.clockseq?e.clockseq:s;if(null==u||null==p){const t=e.random||(e.rng||a.default)();null==u&&(u=r=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==p&&(p=s=16383&(t[6]<<8|t[7]))}let g=void 0!==e.msecs?e.msecs:Date.now(),h=void 0!==e.nsecs?e.nsecs:c+1;const S=g-o+(h-c)/1e4;if(S<0&&void 0===e.clockseq&&(p=p+1&16383),(S<0||g>o)&&void 0===e.nsecs&&(h=0),h>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");o=g,c=h,s=p,g+=122192928e5;const C=(1e4*(268435455&g)+h)%4294967296;d[n++]=C>>>24&255,d[n++]=C>>>16&255,d[n++]=C>>>8&255,d[n++]=255&C;const v=g/4294967296*1e4&268435455;d[n++]=v>>>8&255,d[n++]=255&v,d[n++]=v>>>24&15|16,d[n++]=v>>>16&255,d[n++]=p>>>8|128,d[n++]=255&p;for(let e=0;e<6;++e)d[n+e]=u[e];return t||(0,l.unsafeStringify)(d)}},237:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=l(i(925)),a=l(i(163));function l(e){return e&&e.__esModule?e:{default:e}}var r=(0,n.default)("v3",48,a.default);t.default=r},925:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.URL=t.DNS=void 0,t.default=function(e,t,i){function n(e,n,r,s){var o;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let i=0;i<e.length;++i)t.push(e.charCodeAt(i));return t}(e)),"string"==typeof n&&(n=(0,l.default)(n)),16!==(null===(o=n)||void 0===o?void 0:o.length))throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+e.length);if(c.set(n),c.set(e,n.length),c=i(c),c[6]=15&c[6]|t,c[8]=63&c[8]|128,r){s=s||0;for(let e=0;e<16;++e)r[s+e]=c[e];return r}return(0,a.unsafeStringify)(c)}try{n.name=e}catch(e){}return n.DNS=r,n.URL=s,n};var n,a=i(8),l=(n=i(222))&&n.__esModule?n:{default:n};const r="6ba7b810-9dad-11d1-80b4-00c04fd430c8";t.DNS=r;const s="6ba7b811-9dad-11d1-80b4-00c04fd430c8";t.URL=s},355:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=r(i(790)),a=r(i(319)),l=i(8);function r(e){return e&&e.__esModule?e:{default:e}}t.default=function(e,t,i){if(n.default.randomUUID&&!t&&!e)return n.default.randomUUID();const r=(e=e||{}).random||(e.rng||a.default)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){i=i||0;for(let e=0;e<16;++e)t[i+e]=r[e];return t}return(0,l.unsafeStringify)(r)}},764:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=l(i(925)),a=l(i(757));function l(e){return e&&e.__esModule?e:{default:e}}var r=(0,n.default)("v5",80,a.default);t.default=r},435:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,a=(n=i(58))&&n.__esModule?n:{default:n};t.default=function(e){return"string"==typeof e&&a.default.test(e)}},464:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,a=(n=i(435))&&n.__esModule?n:{default:n};t.default=function(e){if(!(0,a.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)}}},t={};return function i(n){var a=t[n];if(void 0!==a)return a.exports;var l=t[n]={exports:{}};return e[n].call(l.exports,l,l.exports,i),l.exports}(607)})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["sceyt-call"]=t():e["sceyt-call"]=t()}(this,(()=>(()=>{"use strict";var e={547:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CallStateMachine=void 0;const n=i(578),a=(0,i(645).createLogger)("CallStateMachine");class l{constructor(e){this.callId=e}isValidStateTransition(e,t){var i,n;return null!==(n=null===(i=l.validStateTransitions.get(t))||void 0===i?void 0:i.has(e))&&void 0!==n&&n}setState(e,t,i){return this.isValidStateTransition(e,t)?(a.info(`[25] [CallId: ${this.callId}] Call state changed ${t} -> ${e}, reason: ${i}`,{color:"cyan"}),!0):(a.warn(`[28] [CallId: ${this.callId}] Invalid CallState changed ${t} -> ${e}, reason: ${i}`,{color:"red"}),!1)}updateState(e,t,i){return this.setState(e,t,i)}}t.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,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ParticipantStateMachine=void 0;const n=i(578),a=(0,i(645).createLogger)("ParticipantStateMachine");class l{constructor(e,t){this.userId=e,this.callId=t}isValidParticipantStateTransition(e,t){var i,n;return null!==(n=null===(i=l.validParticipantStateTransitions.get(t))||void 0===i?void 0:i.has(e))&&void 0!==n&&n}isValidConnectionTransition(e,t){var i,n;return null!==(n=null===(i=l.validConnectionTransitions.get(t))||void 0===i?void 0:i.has(e))&&void 0!==n&&n}setState(e,t,i,l){let r=!1;void 0!==e&&void 0!==i&&this.isValidParticipantStateTransition(e,i)?(a.debug(`[43] [CallId: ${this.callId}] Participant state transition: ${i} -> ${e}`),r=!0):e&&a.warn(`[46] [CallId: ${this.callId}] Invalid ParticipantState transition from ${i?n.ParticipantState[i]:"undefined"} to ${e?n.ParticipantState[e]:"undefined"}`,{color:"yellow"}),void 0!==t&&void 0!==l&&this.isValidConnectionTransition(t,l)?(a.debug(`[50] [CallId: ${this.callId}] Connection state transition: ${l} -> ${t}`),r=!0):t&&a.warn(`[53] [CallId: ${this.callId}] Invalid ConnectionState transition from ${l?n.ParticipantConnectionState[l]:"undefined"} to ${t?n.ParticipantConnectionState[t]:"undefined"}`,{color:"yellow"})}updateState(e,t){return this.isValidParticipantStateTransition(e,t)?(this.setState(e,void 0,t,void 0),!0):(a.warn(`[63] [CallId: ${this.callId}] Invalid ParticipantState transition from ${n.ParticipantState[t]} to ${n.ParticipantState[e]}`,{color:"yellow"}),!1)}updateConnectionState(e,t){return this.isValidConnectionTransition(e,t)?(this.setState(void 0,e,void 0,t),!0):(a.warn(`[71] [CallId: ${this.callId}] Invalid ConnectionState transition from ${n.ParticipantConnectionState[t]} to ${n.ParticipantConnectionState[e]}`,{color:"yellow"}),!1)}}t.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,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{s(n.next(e))}catch(e){l(e)}}function o(e){try{s(n.throw(e))}catch(e){l(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}s((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ActiveSpeakerManager=void 0;const a=i(645),l=i(578),r=(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 t,i;this.processingInterval||(this.internalCallHandler=e,this.internalCallHandler&&this.call?(this.processingInterval=setInterval((()=>n(this,void 0,void 0,(function*(){var e,t,i,n,a;try{if(this.call&&this.internalCallHandler){if(this.call.localParticipant){let i=0;if(this.call.mediaFlow!==l.MediaFlow.SFU){const t=this.call.participants.find((e=>{var t,i,n,a;return e.id!==(null===(i=null===(t=this.call)||void 0===t?void 0:t.localParticipant)||void 0===i?void 0:i.id)||e.clientId!==(null===(a=null===(n=this.call)||void 0===n?void 0:n.localParticipant)||void 0===a?void 0:a.clientId)}));if(t){const n=null===(e=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===e?void 0:e[t.getFullId()];if(n){const e=yield n.getConnectionStats(),t=Array.from(e.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));i=t.length>0?Math.max(...t):0}}}else{const e=this.call.serverParticipant;if(e){const n=null===(t=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===t?void 0:t[e.getFullId()];if(n){const e=yield n.getConnectionStats(),t=Array.from(e.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));i=t.length>0?Math.max(...t):0}}}this.call.localParticipant.muted&&(i=0),this.processAudioLevels(this.call.localParticipant,i)}for(const e of this.call.participants){if(e.id===this.call.localParticipant.id&&e.clientId===this.call.localParticipant.clientId)continue;let t=0;if(this.call.mediaFlow!==l.MediaFlow.SFU){const n=null===(i=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===i?void 0:i[e.getFullId()];if(n){const e=yield n.getConnectionStats(),i=Array.from(e.values()).filter((e=>this.isInboundAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));t=i.length>0?Math.max(...i):0}}else{const i=null===(n=this.internalCallHandler.callParticipantsRTCMap[this.call.id])||void 0===n?void 0:n[e.getFullId()];if(i){const e=yield i.getConnectionStats(),n=Array.from(e.values()).filter((e=>this.isInboundAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));t=n.length>0?Math.max(...n):0}}e.muted&&(t=0),this.processAudioLevels(e,t)}}this.processActiveSpeakers(),this.call&&(this.call.emitActiveSpeakersChanged(this.activeSpeakers),this.call.emitDominantSpeakerChanged(this.dominantSpeaker))}catch(e){r.error(`[137] [CallId: ${null===(a=this.call)||void 0===a?void 0:a.id}] Error processing audio levels: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}))),o.POLLING_INTERVAL_MS),r.info(`[141] [CallId: ${null===(i=this.call)||void 0===i?void 0:i.id}] Active speaker detection started`)):r.error(`[47] [CallId: ${null===(t=this.call)||void 0===t?void 0:t.id}] Call or InternalCallHandler is not set`,{color:"red"}))}stop(){var e;this.processingInterval&&(clearInterval(this.processingInterval),this.processingInterval=null),this.activeSpeakers=[],this.dominantSpeaker=null,this.speakingStates.clear(),this.lastActiveSpeakers=[],this.lastDominantSpeaker=null,r.info(`[154] [CallId: ${null===(e=this.call)||void 0===e?void 0:e.id}] Active speaker detection stopped`)}addParticipant(e){var t;const i=this.getParticipantKey(e);this.speakingStates.has(i)||(this.speakingStates.set(i,{participant:e,audioLevel:0,smoothedAudioLevel:0,isSpeaking:!1,speakingStartTime:0}),r.info(`[167] [CallId: ${null===(t=this.call)||void 0===t?void 0:t.id}] Added participant for active speaker detection: ${e.getFullId()}`))}updateParticipant(e){const t=this.getParticipantKey(e),i=this.speakingStates.get(t);i&&this.speakingStates.set(t,Object.assign(Object.assign({},i),{participant:e}))}removeParticipant(e){var t,i,n;const a=this.getParticipantKey(e);this.speakingStates.delete(a),this.lastActiveSpeakers.some((t=>t.participant.id===e.id&&t.participant.clientId===e.clientId))&&this.processActiveSpeakers(),(null===(t=this.lastDominantSpeaker)||void 0===t?void 0:t.participant.id)===e.id&&(null===(i=this.lastDominantSpeaker)||void 0===i?void 0:i.participant.clientId)===e.clientId&&(this.dominantSpeaker=null,this.lastDominantSpeaker=null),r.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 t,i;const n=this.getParticipantKey(e);return null!==(i=null===(t=this.speakingStates.get(n))||void 0===t?void 0:t.smoothedAudioLevel)&&void 0!==i?i:null}isSpeaking(e){var t,i;const n=this.getParticipantKey(e);return null!==(i=null===(t=this.speakingStates.get(n))||void 0===t?void 0:t.isSpeaking)&&void 0!==i&&i}isDominantSpeaker(e){var t,i;return(null===(t=this.dominantSpeaker)||void 0===t?void 0:t.participant.id)===e.id&&(null===(i=this.dominantSpeaker)||void 0===i?void 0:i.participant.clientId)===e.clientId}processActiveSpeakers(){const e=Date.now(),t=new Map;this.speakingStates.forEach(((i,n)=>{t.set(n,this.updateSpeakingState(i,e))})),this.speakingStates=t;const i=Array.from(this.speakingStates.values()).filter((e=>e.isSpeaking)).sort(((e,t)=>t.smoothedAudioLevel-e.smoothedAudioLevel));JSON.stringify(i)!==JSON.stringify(this.lastActiveSpeakers)&&(this.activeSpeakers=i,this.lastActiveSpeakers=i),this.updateDominantSpeaker(i,e)}updateDominantSpeaker(e,t){if(0===e.length)return void(this.lastDominantSpeaker&&t-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=t);const i=e[0];i.participant.id===this.lastDominantSpeaker.participant.id&&i.participant.clientId===this.lastDominantSpeaker.participant.clientId||i.smoothedAudioLevel>.5&&t-i.speakingStartTime>o.DOMINANT_SPEAKER_HYSTERESIS_MS&&(this.dominantSpeaker=i,this.lastDominantSpeaker=i,this.dominantSpeakerLastChangeTime=t)}updateSpeakingState(e,t){const i=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 i>=o.AUDIO_LEVEL_THRESHOLD?e.isSpeaking||(n=!0,a=t):e.isSpeaking&&t-e.speakingStartTime>o.SPEAKING_TIME_THRESHOLD_MS&&(n=!1),Object.assign(Object.assign({},e),{smoothedAudioLevel:i,isSpeaking:n,speakingStartTime:a})}processAudioLevels(e,t){var i;try{let i=null;if(e.muted)i=0;else if("number"==typeof t)i=t;else{const e=Array.from(t.values()).filter((e=>this.isOutboundAudio(e)||this.isMediaSourceAudio(e))).map((e=>this.getStatsAudioLevel(e))).filter((e=>null!==e));i=e.length>0?Math.max(...e):0}if(null!==i){const t=this.getParticipantKey(e),n=this.speakingStates.get(t);n&&this.speakingStates.set(t,Object.assign(Object.assign({},n),{audioLevel:i}))}}catch(e){r.error(`[330] [CallId: ${null===(i=this.call)||void 0===i?void 0:i.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 t;return null!==(t=e.audioLevel)&&void 0!==t?t:null}isInboundAudio(e){return"inbound-rtp"===e.type&&"audio"===e.kind}}t.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,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AudioTrack=void 0,t.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,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SceytCallClient=void 0;const n=i(650),a=i(645),l=i(185),r=i(297),o=i(228),s=i(65),c=i(302),d=i(578),u=(0,a.createLogger)("CallClient");class p extends r.TypedEventEmitter{constructor(e){super(),this.join=(e,t)=>{u.info(`[20] [CallId: ${e.id||"new"}] Join call`,{color:"cyan"});try{const i=this.getCall(e.id);if(i&&!this.sendSignalValidator.canSendSignalEvent(d.SignalEvent.JOIN,i)){const t=`Cannot join call with ID ${e.id||"new"} due to invalid call state or participant state.`;return u.warn(`[25] [CallId: ${e.id||"new"}] ${t}`,{color:"red"}),{success:!1,error:s.SceytCallException.BadRequest(4006,t)}}const n=this.internalCallHandler.joinCall(e,t);return(null==n?void 0:n.data)&&(null==n||n.data.activeSpeakerManager.addParticipant(n.data.localParticipant)),n}catch(t){return u.error(`[29] [CallId: ${e.id||"new"}] Join failed: ${t.message||JSON.stringify(t)}`,{color:"red"}),{success:!1,error:(0,o.toCallException)(t)}}},this.reject=(e,t,i)=>{if(!e)return u.warn("[39] [CallId: GLOBAL_LOGS] [REJECT] Attempted to reject a null call"),{success:!1,error:s.SceytCallException.BadRequest(4006,"Call object is null")};try{u.info(`[41] [CallId: ${e.id}] Rejecting call`,{color:"cyan"});const n=this.getCall(e.id);return n?(this.internalCallHandler.rejectCall(n,t,i),n.activeSpeakerManager.removeParticipant(n.localParticipant),{success:!0}):{success:!1,error:s.SceytCallException.BadRequest(4006,"Call not found")}}catch(t){return u.error(`[51] [CallId: ${e.id}] Rejection failed: ${t.message||JSON.stringify(t)}`,{color:"red"}),{success:!1,error:(0,o.toCallException)(t)}}},this.leave=e=>{if(!e)return u.warn("[57] [CallId: GLOBAL_LOGS] [LEAVE] Attempted to leave a null call"),{success:!1,error:s.SceytCallException.BadRequest(4006,"Call object is null")};try{u.info(`[62] [CallId: ${null==e?void 0:e.id}] Leaving call`,{color:"cyan"});const t=this.getCall(null==e?void 0:e.id);return t?(this.internalCallHandler.leaveCall(t,!0,"leave"),t.activeSpeakerManager.removeParticipant(t.localParticipant),{success:!0}):{success:!1,error:s.SceytCallException.BadRequest(4006,"Call not found")}}catch(t){return u.error(`[71] [CallId: ${null==e?void 0:e.id}] Leave failed: ${t.message||JSON.stringify(t)}`,{color:"red"}),{success:!1,error:(0,o.toCallException)(t)}}},this.getCall=e=>this.internalCallHandler.activeCalls.find((t=>t.id===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.sendSignalValidator=new c.SendSignalValidator,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}get RecentCallQueryBuilder(){return l.RecentCallQueryBuilder}}t.SceytCallClient=p},998:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{s(n.next(e))}catch(e){l(e)}}function o(e){try{s(n.throw(e))}catch(e){l(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}s((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Call=void 0;const a=i(650),l=i(578),r=i(547),o=i(645),s=i(258),c=i(297),d=i(228),u=(0,o.createLogger)("Call");class p extends c.TypedEventEmitter{constructor({id:e,sessionId:t="",mediaFlow:i,createdBy:r="",localParticipant:o,participants:c,metadata:p,chatClient:g,isCallSilenced:h}){super(),this.state=l.CallState.Idle,this._localAudioTracks=[],this._localVideoTracks=[],this._muted=!1,this._onHold=!1,this.videoEnabled=!1,this.eventsQueue=new Map,this.isCallSilenced=!1,this.videoDeviceId=null,this.getStats=()=>n(this,void 0,void 0,(function*(){try{const e=[];for(const t of this.participants){const i=yield this.getParticipantStats(t);i.success&&i.data&&e.push(i.data)}return{success:!0,data:e}}catch(e){return u.error(`[502] [CallId: ${this.id}] Error getting call stats ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}})),this.getParticipantStats=e=>n(this,void 0,void 0,(function*(){try{u.info(`[503] [CallId: ${this.id}] getParticipantStats for ${e.getFullId()}`,{color:"cyan"});const t=a.InternalCallHandler.getInstance().callParticipantsRTCMap[this.id],i=null==t?void 0:t[e.getFullId()];return i?{success:!0,data:yield i.getConnectionStats()}:{success:!1,error:(0,d.toCallException)(new Error("Participant RTC client not found"))}}catch(e){return u.error(`[504] [CallId: ${this.id}] Error getting participant stats ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}})),this.id=e,this.sessionId=t,this.createdBy=r,this.participants=c,this.localParticipant=o,this.mediaFlow=i,this.metadata=p,this.activeSpeakerManager=new s.ActiveSpeakerManager(this),this.chatClient=g,this.isCallSilenced=h}emitAudioTrackAdded(e,t){this.emit("audioTrackAdded",{call:this,participant:e,track:t})}emitAudioTrackRemoved(e){this.emit("audioTrackRemoved",{call:this,participant:e})}emitVideoTrackAdded(e,t){this.emit("videoTrackAdded",{call:this,participant:e,track:t})}emitVideoTrackRemoved(e){this.emit("videoTrackRemoved",{call:this,participant:e})}emitCallStateChanged(e){this.emit("callStateChanged",{call:this,state:e})}emitParticipantStateChanged(e,t,i){this.emit("participantStateChanged",{call:this,participant:e,state:t,reason:i})}emitParticipantConnectionStateChanged(e,t){this.emit("participantConnectionStateChanged",{call:this,participant:e,state:t})}emitParticipantEvent(e,t){this.emit("participantEvent",{call:this,participant:e,event:t})}emitParticipantsAdded(e,t){this.emit("participantsAdded",{call:this,participants:e,entryType:t})}emitActiveSpeakersChanged(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})}clearEventsQueue(){this.eventsQueue.clear()}setState(e,t){const i=new r.CallStateMachine(this.id).updateState(e,this.state,t);return i&&(this.state=e,e===l.CallState.Connected?this.activeSpeakerManager.start(a.InternalCallHandler.getInstance()):this.activeSpeakerManager.stop(),this.emitCallStateChanged(e)),i}addParticipants(e){const t=e=>a.InternalCallHandler.getInstance().addParticipantsToCall(e,this);return this.sessionId?t(e):this.eventsQueue.set("ADD_PARTICIPANTS",(()=>t(e))),{success:!0}}addParticipantToList(e){this.participants.push(e)}kickParticipantFromList(e){return this.participants=this.participants.filter((t=>t.id!==e.id&&t.clientId!==e.clientId)),a.InternalCallHandler.getInstance().kickParticipantFromCall(e,this)}setSessionId(e){this.sessionId=e}setCreatedBy(e){this.createdBy=e}changeMediaFlow(e){this.mediaFlow!=e&&(this.mediaFlow=e,this.emitMediaFlowChanged(e))}switchToSFU(e){return n(this,void 0,void 0,(function*(){const t=t=>{u.info(`[159] [CallId: ${this.id}] handle switch call to ${l.MediaFlow.SFU}`,{color:"cyan"});const i=a.InternalCallHandler.getInstance(),n=i.activeCalls.find((e=>e.id===t));return i.switchCallToSfu(n,e)};return this.sessionId?t(this.id):this.eventsQueue.set(l.SignalEvent.SWITCH_MEDIA_FLOW,(()=>t(this.id))),{success:!0}}))}mute(e,t){this.muted=e,this.localParticipant.setMuted(e),this.emitParticipantEvent(this.localParticipant,e?"Mute":"Unmute");const i=e=>{a.InternalCallHandler.getInstance().sendAudioEnable(this,e,t)};return this.sessionId?i(e):this.eventsQueue.set(l.SignalEvent.MUTE,(()=>i(e))),{success:!0}}hold(e){this.onHold=e;const t=e=>{a.InternalCallHandler.getInstance().sendHold(this,e)};return this.sessionId?t(e):this.eventsQueue.set(l.SignalEvent.HOLD,(()=>t(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 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}enableVideo(e,t,i){return n(this,void 0,void 0,(function*(){const r=a.InternalCallHandler.getInstance();let o=[];return this.localVideoTracks.forEach((e=>{e.stop()})),this.localParticipant.videoTracks.forEach((e=>{e.enabled=!1})),yield(()=>n(this,void 0,void 0,(function*(){var a,s,c;try{if(e){const e=(yield navigator.mediaDevices.enumerateDevices()).filter((e=>"videoinput"===e.kind));this.videoDeviceId&&(e.some((e=>e.deviceId===this.videoDeviceId))||(u.warn(`Previously selected video device with ID ${this.videoDeviceId} not found. Falling back to default camera.`),this.setVideoDeviceId(null)));const t=yield navigator.mediaDevices.getUserMedia({video:{width:{min:640,max:1280},height:{min:480,max:720}}});o=t.getVideoTracks(),o.sort(((e,t)=>(e.getSettings().deviceId||"")===this.videoDeviceId?-1:1)),this.setVideoDeviceId((null===(a=o[0])||void 0===a?void 0:a.getSettings().deviceId)||null)}else o=this.localVideoTracks;!this.videoDeviceId&&o.length>0&&this.setVideoDeviceId((null===(s=o[0])||void 0===s?void 0:s.getSettings().deviceId)||null),this.localVideoTracks=o,this.localParticipant.setVideoTracks(o),this.localParticipant.videoEnabled=e,this.emitVideoTrackAdded(this.localParticipant,o[0]),this.emitParticipantEvent(this.localParticipant,e?"VideoEnabled":"VideoDisabled"),this.localParticipant.videoTracks.forEach((t=>{t.enabled=e})),this.localVideoTracks&&(null===(c=this.localVideoTracks)||void 0===c?void 0:c.length)&&(yield r.changeVideoTracks(this,this.localVideoTracks[0],e));const p=(e,i)=>n(this,void 0,void 0,(function*(){try{yield r.changeVideoTracks(this,i,e),r.sendVideoEnabled(this,e,t)}catch(e){return u.error(`[323] [CallId: ${this.id}] Failed to send video enabled signal: message: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),void(null==t||t({error:(0,d.toCallException)(e)}))}}));i||(this.sessionId?p(e,o[0]):this.eventsQueue.set(e?l.SignalEvent.VIDEO_ON:l.SignalEvent.VIDEO_OFF,(()=>p(e,o[0]))))}catch(e){return u.error(`[325] [CallId: ${this.id}] Error enabling video ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}})))(),{success:!0}}))}shareScreen(e,t){return n(this,void 0,void 0,(function*(){let i=[];try{if(this.localParticipant.setScreenSharing(e),e){const t=yield navigator.mediaDevices.getDisplayMedia({video:{width:{max:1280},height:{max:720},frameRate:{max:30}}});if(this.localVideoTracks.forEach((e=>{e.stop()})),i=t.getVideoTracks(),t.addEventListener("inactive",(()=>{this.localParticipant.screenSharing&&this.stopScreenShare()})),this.localVideoTracks=i,this.localParticipant.setVideoTracks(i),this.emitVideoTrackAdded(this.localParticipant,i[0]),this.localParticipant.videoTracks.forEach((t=>{t.enabled=e})),i&&i.length){const t=a.InternalCallHandler.getInstance();yield t.changeVideoTracks(this,i[0],e,!0)}this.emitParticipantEvent(this.localParticipant,"ScreenSharingStarted")}else this.localParticipant.videoEnabled&&!e?(this.emitParticipantEvent(this.localParticipant,"ScreenSharingStopped"),yield this.enableVideo(!0,t,!0)):this.emitParticipantEvent(this.localParticipant,e?"ScreenSharingStarted":"ScreenSharingStopped");const r=e=>n(this,void 0,void 0,(function*(){const i=a.InternalCallHandler.getInstance();yield i.sendScreenShare(this,e,t)}));return this.sessionId?r(e):this.eventsQueue.set(e?l.SignalEvent.SCREEN_SHARE_ON:l.SignalEvent.SCREEN_SHARE_OFF,(()=>r(e))),{success:!0}}catch(e){return u.error(`[324] [CallId: ${this.id}] Error sharing screen ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.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 u.error(`[306] [CallId: ${this.id}] Error getting video devices ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.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 u.error(`[307] [CallId: ${this.id}] Error getting audio devices ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}}))}selectVideoDevice(e){return n(this,void 0,void 0,(function*(){if(this.setVideoDeviceId(e),!this.videoEnabled||this.localParticipant.screenSharing)return{success:!0};try{this.localVideoTracks.forEach((e=>{e.stop()}));const t=(yield navigator.mediaDevices.getUserMedia({video:{deviceId:{exact:e},width:{min:640,max:1280},height:{min:480,max:720}}})).getVideoTracks();this.localVideoTracks=t,this.localParticipant.setVideoTracks(t),this.emitVideoTrackAdded(this.localParticipant,t[0]);const i=a.InternalCallHandler.getInstance();return yield i.changeVideoTracks(this,t[0],this.localParticipant.videoEnabled),{success:!0}}catch(e){return u.error(`[308] [CallId: ${this.id}] Error selecting video device ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}}))}selectAudioDevice(e){return n(this,void 0,void 0,(function*(){try{const t=a.InternalCallHandler.getInstance(),i=(yield navigator.mediaDevices.getUserMedia({audio:{deviceId:{exact:e}}})).getAudioTracks();return this.localAudioTracks=i,this.localParticipant.setAudioTracks(i),yield t.changeAudioTracks(this,i[0],this.localParticipant.muted),{success:!0}}catch(e){return u.error(`[309] [CallId: ${this.id}] Error selecting audio device ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,d.toCallException)(e)}}}))}setVideoEnabled(e){this.videoEnabled=e}getParticipant(e,t){return this.participants.find((i=>i.id===e&&i.clientId===t))}sendRinging(e){return a.InternalCallHandler.getInstance().sendRinging(this,e)}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}}}t.Call=p},228:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.checkCode=t.toCallException=t.handleAck=void 0;const n=i(65);function a(e,t){switch(e){case 4e3:return n.SceytCallException.BadSignal(e,t);case 4001:return n.SceytCallException.CallNotFound(e,t);case 4002:return n.SceytCallException.ParticipantNotFound(e,t);case 4005:case 4003:return n.SceytCallException.NotAllowed(e,t);case 4004:return n.SceytCallException.ParticipantAlreadyExists(e,t);case 5001:return n.SceytCallException.InternalError(e,t);case 9901:case 9903:case 9904:return n.SceytCallException.NetworkError(e,t);case 9902:return n.SceytCallException.Timeout(e,t);case 4006:return n.SceytCallException.BadRequest(e,t);default:return n.SceytCallException.Unknown(e,t)}}t.handleAck=function(e){return e.error&&a(e.error.code,e.error.message),e},t.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))},t.checkCode=a},65:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SceytCallException=void 0;class i extends Error{get isResendable(){return this._isResendable}constructor(e,t,i="SceytCallException"){super(e),this.code=t,this.name=i,this._isResendable=!1,this.name=i}static BadSignal(e,t){return new i(t,e,"BadSignal")}static CallNotFound(e,t){return new i(t,e,"CallNotFound")}static ParticipantNotFound(e,t){return new i(t,e,"ParticipantNotFound")}static NotAllowed(e,t){return new i(t,e,"NotAllowed")}static ParticipantAlreadyExists(e,t){return new i(t,e,"ParticipantAlreadyExists")}static InternalError(e,t){const n=new i(t,e,"InternalError");return n._isResendable=!0,n}static NetworkError(e,t){const n=new i(t,e,"NetworkError");return n._isResendable=!0,n}static Timeout(e,t){const n=new i(t,e,"Timeout");return n._isResendable=!0,n}static BadRequest(e,t){return new i(t,e,"BadRequest")}static Unknown(e,t){return new i(t,e)}}t.SceytCallException=i},650:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{s(n.next(e))}catch(e){l(e)}}function o(e){try{s(n.throw(e))}catch(e){l(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}s((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.InternalCallHandler=void 0;const a=i(787),l=i(546),r=i(786),o=i(578),s=i(998),c=i(489),d=i(645),u=i(429),p=i(65),g=i(680),h=i(228),S=(0,d.createLogger)("InternalCallHandler");class C{constructor(e){this.callParticipantsRTCMap={},this.activeCalls=[],this.callEvents={},this.handleMediaConnectedSignal=e=>{if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){let i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));if(i||(i=t.participants.find((t=>t.id===e.from.split("/")[0]&&!t.clientId)),i?i.clientId=e.from.split("/")[1]:(i=new a.Participant(e.from),t.addParticipantToList(i),t.emitParticipantsAdded([i],o.ParticipantEntryType.ADDED))),i&&t.localParticipant.state===o.ParticipantState.Joined&&t.localParticipant.getFullId()!==i.getFullId()&&(!this.callParticipantsRTCMap[t.id]||!this.callParticipantsRTCMap[t.id][i.getFullId()]||(null==i?void 0:i.shouldResetPeerConnection))){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[968] [CallId: ${t.id}] SYNC CONNECT failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`):e.event!==o.SignalEvent.ERROR||S.error(`[971] [CallId: ${t.id}] SYNC CONNECT failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};S.info(`[975] [CallId: ${t.id}] SYNC CONNECT to participant ${i.getFullId()}`,{color:"blue"}),this.signalingClient.clearParticipantSignals(t.id,i.getFullId()),this.signalingClient.sendSignalMessage({to:i.getFullId(),event:o.SignalEvent.CONNECT,mediaFlow:t.mediaFlow,callId:t.id,sessionId:t.sessionId},e)}}},this.onIceCandidate=(e,t,i)=>{var n,a;if(i.mediaFlow!==o.MediaFlow.SFU)if(S.info(`[996] [CallId: ${i.id}] onIceCandidate, participantID: ${e.getFullId()}, candidate: ${null===(n=t.candidate)||void 0===n?void 0:n.candidate}, type: ${null===(a=t.candidate)||void 0===a?void 0:a.type}`,{color:"blue"}),t.candidate&&t.candidate.candidate){let n="";if(!/\bufrag\s+\S+/i.test(t.candidate.candidate)&&this.callParticipantsRTCMap[i.id]&&this.callParticipantsRTCMap[i.id][e.getFullId()]){const t=this.callParticipantsRTCMap[i.id][e.getFullId()];t&&(n=` ufrag ${t.getLocalSdpUfrag()}`)}const a={candidate:t.candidate.candidate+n,sdpMid:t.candidate.sdpMid||"",sdpMLineIndex:t.candidate.sdpMLineIndex||0};try{const t=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[1007] [CallId: ${i.id}] SYNC ICE failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`):e.event!==o.SignalEvent.ERROR||S.error(`[1011] [CallId: ${i.id}] SYNC ICE failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};this.signalingClient.sendSignalMessage({to:this.getParticipantId(e),event:o.SignalEvent.ICE,mediaFlow:i.mediaFlow,callId:i.id,sessionId:i.sessionId,ice:a},t)}catch(t){S.error(`[1023] [CallId: ${i.id}] Failed to send ICE candidate to ${e.getFullId()}: ${t instanceof Error?t.message:JSON.stringify(t)}`)}}else S.info(`[1025] [CallId: ${i.id}] ICE gathering complete for participant ${e.getFullId()} (null candidate)`,{color:"blue"});else S.info(`[1024] [CallId: ${i.id}] onIceCandidate, participantID: ${e.getFullId()}, skip for SFU`,{color:"blue"})},this.onTrack=(e,t,i)=>{const n=null==i?void 0:i.track;S.info(`[1032] [CallId: ${e.id}] onTrack, participantID: ${t.getFullId()}, kind: ${n.kind}`,{color:"blue"}),"audio"===(null==n?void 0:n.kind)?(t.setAudioTracks([n]),e.emitAudioTrackAdded(t,n),n.onended=()=>{S.info(`[1038] [CallId: ${e.id}] Audio track ended for participant ${t.getFullId()}`,{color:"yellow"}),t.setAudioTracks([]),e.emitAudioTrackRemoved(t)}):"video"===(null==n?void 0:n.kind)&&(t.setVideoTracks([n]),e.videoEnabled&&!t.videoEnabled&&e.setVideoEnabled(!0),e.emitVideoTrackAdded(t,n),n.onended=()=>{S.info(`[1052] [CallId: ${e.id}] Video track ended for participant ${t.getFullId()}`,{color:"yellow"}),t.setVideoTracks([]),e.emitVideoTrackRemoved(t)})},this.kickParticipantFromCall=(e,t)=>{this.signalingClient.sendSignalMessage({mediaFlow:t.mediaFlow,callId:t.id,event:o.SignalEvent.KICK,sessionId:t.sessionId,participants:[{id:e.id,clientId:e.clientId}]},(e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[1642] [CallId: ${t.id}] Kick participant failed: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==o.SignalEvent.ERROR||S.error(`[1646] [CallId: ${t.id}] Kick participant failed: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})}))},this.addParticipantsToCall=(e,t)=>{try{if(e.forEach((e=>{const i=t.participants.filter((t=>t.id===e));if(i.length>0)for(const e of i)e?e.state!==o.ParticipantState.Joined&&e.state!==o.ParticipantState.Ringing&&(e.updateState(o.ParticipantState.Idle,t.id),e.updateConnectionState(o.ParticipantConnectionState.Idle,t.id),t.emitParticipantStateChanged(e,o.ParticipantState.Idle),t.emitParticipantConnectionStateChanged(e,o.ParticipantConnectionState.Idle)):(t.addParticipantToList(e),t.emitParticipantsAdded([e],o.ParticipantEntryType.ADDED));else{const i=new a.Participant(e);t.addParticipantToList(i),t.emitParticipantsAdded([i],o.ParticipantEntryType.ADDED)}})),S.info(`[1547] [CallId: ${t.id}] added participants to call: ${e}, callId: ${t.id}`,{color:"light-green"}),e.length>0){const i=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[1551] [CallId: ${t.id}] SYNC INVITE failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==o.SignalEvent.ERROR||S.error(`[1555] [CallId: ${t.id}] SYNC INVITE failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};return this.signalingClient.sendSignalMessage({callId:t.id,sessionId:t.sessionId,event:o.SignalEvent.INVITE,participants:e.map((e=>new a.Participant(e).serialize()))},i),!0}return!1}catch(i){return S.error(`[1567] [CallId: ${t.id}] Failed to add participants to call: ${e}, callId: ${t.id} message: ${i instanceof Error?i.message:JSON.stringify(i)}`,{color:"red"}),!1}},this.sendSignalScreenShare=(e,t,i)=>{try{const n=t=>t instanceof p.SceytCallException||t instanceof Error?(S.error(`[1679] [CallId: ${e.id}] SYNC SCREEN_SHARE_ON failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`),void(null==i||i({error:(0,h.toCallException)(t)}))):t.event===o.SignalEvent.ERROR?(S.error(`[1683] [CallId: ${e.id}] SYNC SCREEN_SHARE_ON failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`),void(null==i||i({error:(0,h.toCallException)(t.error)}))):void 0;return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:t?o.SignalEvent.SCREEN_SHARE_ON:o.SignalEvent.SCREEN_SHARE_OFF,sessionId:e.sessionId},n),!0}catch(t){return S.error(`[1694] [CallId: ${e.id}] Failed to send screen share signal: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"}),null==i||i({error:(0,h.toCallException)(t)}),!1}},this.setupMediaStream=e=>n(this,void 0,void 0,(function*(){var t;try{const i=yield navigator.mediaDevices.getUserMedia({video:!1,audio:!0}),n=((0,c.getEmptyVideoTrack)(),i.getAudioTracks());if(e.localAudioTracks=n,!(null==e?void 0:e.localVideoTracks)||!(null===(t=e.localVideoTracks)||void 0===t?void 0:t.length)){const t=(0,c.getEmptyVideoTrack)();t.forEach((e=>e.enabled=!1)),e.localVideoTracks=t,e.localParticipant.setVideoTracks(t)}return e.localParticipant.audioTracks=n,{audioTracks:n}}catch(t){throw S.error(`[1945] [CallId: ${e.id}] Failed to get media: message: ${t instanceof Error?t.message:JSON.stringify(t)}`),(0,h.toCallException)(t)}})),this.chatClient=e,this.user=e.user,this.clientId=e.clientId,this.signalingClient=new r.Signaling(e,this.handleSignalMessage.bind(this));const t=new this.chatClient.ConnectionListener;if(t.onConnectionStateChanged=e=>{if(S.info(`[46] [CallId: GLOBAL_LOGS] Signaling connection state changed: ${e}`,{color:"cyan"}),"Connected"===e){this.activeCalls.forEach((e=>{const t=this.signalingClient.signalingQueues.get(e.id);t&&t.triggerSignalProcessing()}));const e=setTimeout((()=>{this.signalingClient.sendSignalMessage({event:o.SignalEvent.GET_CALL,callId:""},(e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[57] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed ${e instanceof p.SceytCallException||e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}):e.event!==o.SignalEvent.ERROR?this.syncActiveCalls(e):S.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"),clearTimeout(e)}),1e3)}},this.chatClient.addConnectionListener("listener_id",t),"Connected"===this.chatClient.connectionState){const e=setTimeout((()=>{this.signalingClient.sendSignalMessage({event:o.SignalEvent.GET_CALL,callId:""},(e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[74] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==o.SignalEvent.ERROR?this.syncActiveCalls(e):S.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"),clearTimeout(e)}),1e3)}C.instance=this}syncActiveCalls(e){var t,i,n;const l=this.activeCalls;try{if(!(null==e?void 0:e.calls)&&!(null==e?void 0:e.calls))return;if(e.event!==o.SignalEvent.SUCCESS)return void S.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 r of l){if(!(null==r?void 0:r.sessionId)){S.warn(`[105] [CallId: ${r.id}] Call has no sessionId, skipping`);continue}const l=e.calls.find((e=>(null==e?void 0:e.id)===r.id&&(null==e?void 0:e.sessionId)===r.sessionId));if(l)if(r.mediaFlow!==o.MediaFlow.SFU&&l.mediaFlow===o.MediaFlow.SFU&&(this.updateCallMetadata(r,l),this.handleMediaFlowSwitch(r)),this.syncParticipants(r,l.participants),r.localParticipant.state<=o.ParticipantState.Joined&&(r.state===o.CallState.Connected||r.state===o.CallState.Connecting)){for(const e of r.participants)if(r.mediaFlow!==o.MediaFlow.SFU&&e.connectionState===o.ParticipantConnectionState.Connected&&e.id!==r.localParticipant.id&&e.clientId!==r.localParticipant.clientId){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[139] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==o.SignalEvent.ERROR||S.error(`[143] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({event:o.SignalEvent.MEDIA_CONNECTED,callId:r.id,sessionId:r.sessionId,mediaFlow:r.mediaFlow,to:r.id},e)}if(r.mediaFlow===o.MediaFlow.SFU&&(null===(t=r.serverParticipant)||void 0===t?void 0:t.connectionState)===o.ParticipantConnectionState.Connected&&r.state===o.CallState.Connected){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[158] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==o.SignalEvent.ERROR||S.error(`[162] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({event:o.SignalEvent.MEDIA_CONNECTED,callId:r.id,sessionId:r.sessionId,mediaFlow:r.mediaFlow,to:r.id},e)}if(r.mediaFlow!==o.MediaFlow.SFU||this.callParticipantsRTCMap[r.id]&&this.callParticipantsRTCMap[r.id][r.id]||r.state!==o.CallState.Connected){if(r.mediaFlow===o.MediaFlow.SFU&&r.serverParticipant&&(null===(n=r.serverParticipant)||void 0===n?void 0:n.connectionState)!==o.ParticipantConnectionState.Reconnecting&&r.state===o.CallState.Connected){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[199] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==o.SignalEvent.ERROR||S.error(`[203] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};S.info(`[205] [CallId: ${r.id}] Sending offer to server participant when server participant is not connected: ${r.serverParticipant.getFullId()}`,{color:"yellow"}),this.sendOfferPeerToPeer(r,r.serverParticipant,e)}}else{if((null===(i=r.serverParticipant)||void 0===i?void 0:i.id)!==r.id){const e=new a.Participant(r.id);r.setServerParticipant(e)}if(r.serverParticipant){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[181] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==o.SignalEvent.ERROR||S.error(`[185] [CallId: ${r.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};S.info(`[188] [CallId: ${r.id}] Sending offer to server participant when there is no server participant in the call: ${r.serverParticipant.getFullId()}`,{color:"yellow"}),this.sendOfferPeerToPeer(r,r.serverParticipant,e)}}}else this.leaveCall(r,!1,"syncActiveCalls");else this.closeCall(r)}const r=this.activeCalls.find((e=>e.state===o.CallState.Connected));r&&!e.calls.find((e=>e.id===r.id&&e.sessionId===r.sessionId))&&this.closeCall(r),this.activeCalls=this.activeCalls.filter((t=>{var i;return!(!(null===(i=null==e?void 0:e.calls)||void 0===i?void 0:i.find((e=>e.id===t.id)))&&t.sessionId&&(t.clearEventsQueue(),t.participants.forEach((e=>{this.signalingClient.clearParticipantSignals(t.id,e.getFullId())})),this.signalingClient.clearCallSignals(t.id),1))})),e.calls.forEach((e=>{!this.activeCalls.find((t=>(null==t?void 0:t.id)===(null==e?void 0:e.id)))&&e.id&&e.sessionId&&this.findOrCreateCall({id:e.id,sessionId:e.sessionId,mediaFlow:e.mediaFlow,participantIds:[],metadata:e.metadata,createdBy:e.createdBy},e.participants)})),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}catch(e){S.error(`[248] [CallId: GLOBAL_LOGS] Error syncing calls after reconnection: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}setCallEvent(e,t){this.callEvents[e]=t}handleSignalMessage(e){switch(S.info(`[253] [CallId: ${e.callId}] Received ${o.SignalEvent[e.event]}: ${JSON.stringify(Object.assign({},e))}`,{color:"green"}),e.event||0){case o.SignalEvent.OFFER:this.handleOfferSignal(e);break;case o.SignalEvent.ANSWER:this.handleAnswerSignal(e);break;case o.SignalEvent.JOIN:this.handleJoinSignal(e);break;case o.SignalEvent.LEAVE:this.handleLeaveSignal(e);break;case o.SignalEvent.INVITE:this.handleInviteSignal(e);break;case o.SignalEvent.CLOSE:this.handleCloseSignal(e);break;case o.SignalEvent.DECLINE:this.handleDeclineSignal(e);break;case o.SignalEvent.RINGING:this.handleRingingSignal(e);break;case o.SignalEvent.SWITCH_MEDIA_FLOW:this.handleSwitchMediaFlowSignal(e);break;case o.SignalEvent.ICE:this.handleIceSignal(e);break;case o.SignalEvent.VIDEO_ON:this.handleVideoOnSignal(e);break;case o.SignalEvent.VIDEO_OFF:this.handleVideoOffSignal(e);break;case o.SignalEvent.SCREEN_SHARE_ON:this.handleScreenShareOnSignal(e);break;case o.SignalEvent.SCREEN_SHARE_OFF:this.handleScreenShareOffSignal(e);break;case o.SignalEvent.MUTE:this.handleMuteSignal(e);break;case o.SignalEvent.UNMUTE:this.handleUnmuteSignal(e);break;case o.SignalEvent.HOLD:this.handleHoldSignal(e);break;case o.SignalEvent.UNHOLD:this.handleUnholdSignal(e);break;case o.SignalEvent.KICK:this.handleKickSignal(e);break;case o.SignalEvent.UPDATE:this.handleUpdateSignal(e);break;case o.SignalEvent.NO_ANSWER:this.handleNoAnswerSignal(e);break;case o.SignalEvent.MEDIA_CONNECTED:this.handleMediaConnectedSignal(e);break;case o.SignalEvent.CONNECT:this.handleConnectSignal(e);break;default:S.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 t,i,a,l;if(!this.activeCalls)return void S.warn(`[342] [CallId: ${e.callId}] No active calls found for send offer participant: ${e.from}`,{color:"red"});let r;try{const s=this.activeCalls.find((t=>t.id===e.callId));if(!s)return void S.warn(`[348] [CallId: ${e.callId}] No active call found for send offer participant: ${e.from}`,{color:"red"});if(s.state!==o.CallState.Connected)return void S.warn(`[353] [CallId: ${e.callId}] Call is not connected for send offer participant: ${e.from}`,{color:"red"});let c=null==s?void 0:s.participants.find((t=>t.getFullId()===e.from));if(c){r=c.getFullId();const d=this.callParticipantsRTCMap[s.id]&&(null===(t=this.callParticipantsRTCMap[s.id])||void 0===t?void 0:t[c.getFullId()]);let u=null==d?void 0:d.getSessionId();!c.shouldResetPeerConnection&&d&&u===(null===(i=e.sessionData)||void 0===i?void 0:i.id)||(this.closePeerConnections(s.id,c.getFullId()),s.activeSpeakerManager.removeParticipant(c),this.addParticipantToRTCMap(s,c),c.setShouldResetPeerConnection(!1),(this.callParticipantsRTCMap[s.id]&&(null===(a=this.callParticipantsRTCMap[s.id])||void 0===a?void 0:a[c.getFullId()])).setSessionId((null===(l=e.sessionData)||void 0===l?void 0:l.id)||"")),this.signalingClient.clearParticipantSignals(s.id,c.getFullId()),this.setRemoteDescription(s.id,c.getFullId(),(0,g.toSessionDescription)(e.sessionData,"offer")).then((()=>n(this,void 0,void 0,(function*(){var t,i,n;if(!c)return void S.info(`[392] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});const a=this.callParticipantsRTCMap[s.id][c.getFullId()],l=this.activeCalls.find((e=>e.id===s.id));l&&(l.mediaFlow!==o.MediaFlow.SFU||l.mediaFlow===o.MediaFlow.SFU&&c.id===(null===(t=null==l?void 0:l.serverParticipant)||void 0===t?void 0:t.id))&&(yield this.addTracksToPeerConnection(s,c.getFullId(),!1)),a.createAnswer((null===(i=e.sessionData)||void 0===i?void 0:i.id)||"",(null===(n=e.sessionData)||void 0===n?void 0:n.version)||"",s.mediaFlow).then((t=>{if(!c)return void S.info(`[392] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});if(!t)return void S.error(`[456] [CallId: ${s.id}] Failed to create answer for participant: ${c.getFullId()}`,{color:"red"});const i=a.getRemoteSdpUfrag();if(i&&a.iceQueueMap[c.getFullId()]){const e=a.iceQueueMap[c.getFullId()][i];if(e&&e.length>0)for(const t of e)a.addIceCandidate(t,c.getFullId())}this.signalingClient.sendSignalMessage({to:e.from,mediaFlow:e.mediaFlow,callId:s.id,event:o.SignalEvent.ANSWER,sessionData:t,sessionId:e.sessionId,metadata:e.metadata},(e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[386] [CallId: ${s.id}] SYNC ANSWER failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==o.SignalEvent.ERROR||S.error(`[389] [CallId: ${s.id}] SYNC ANSWER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})}))}))}))))}else S.info(`[402] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"})}catch(t){S.error(`[406] [CallId: ${e.callId}] Failed to handle offer: ${r} message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"})}}handleAnswerSignal(e){var t;if(this.activeCalls)try{const i=this.activeCalls.find((t=>t.id===e.callId));if(i){let n;if(n=i.serverParticipant&&i.serverParticipant.getFullId()===e.from?i.serverParticipant:i.participants.find((t=>t.getFullId()===e.from)),n){const a=null===(t=e.sessionData)||void 0===t?void 0:t.version;if(!a||a!==this.callParticipantsRTCMap[i.id][n.getFullId()].getVersion())return void S.warn(`[412] [CallId: ${i.id}] Version is not set or is the same as the current version: ${a}`,{color:"red"});this.callParticipantsRTCMap[i.id][n.getFullId()].setVersion(a),this.setRemoteDescription(i.id,n.getFullId(),(0,g.toSessionDescription)(e.sessionData,"answer")).then((()=>{if(!n)return void S.info(`[462] [CallId: ${e.callId}] Participant not found in call: ${e.from}`,{color:"cyan"});const t=this.callParticipantsRTCMap[i.id][n.getFullId()].getRemoteSdpUfrag();if(t&&this.callParticipantsRTCMap[i.id][n.getFullId()].iceQueueMap[n.getFullId()]){const e=this.callParticipantsRTCMap[i.id][n.getFullId()].iceQueueMap[n.getFullId()][t];if(e&&e.length>0)for(const t of e)this.callParticipantsRTCMap[i.id][n.getFullId()].addIceCandidate(t,n.getFullId())}}))}}}catch(t){S.error(`[435] [CallId: ${e.callId}] Failed to handle answer: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"})}}sendOfferPeerToPeer(e,t,i){return n(this,void 0,void 0,(function*(){this.callParticipantsRTCMap.hasOwnProperty(e.id)&&this.callParticipantsRTCMap[e.id].hasOwnProperty(t.getFullId())||(this.addParticipantToRTCMap(e,t),yield this.addTracksToPeerConnection(e,t.getFullId(),!0));const n=this.callParticipantsRTCMap[e.id][t.getFullId()];let a=n.getVersion();n.setVersion(a?String(Number(a)+1):"1"),a=n.getVersion();let l=n.getSessionId();l||(l=(0,u.v4)(),n.setSessionId(l)),n.createOffer(l,a,e.mediaFlow).then((n=>{n?this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:o.SignalEvent.OFFER,sessionData:n,to:t.getFullId(),sessionId:e.sessionId},i):S.error(`[456] [CallId: ${e.id}] Failed to create offer for participant: ${t.getFullId()}`,{color:"red"})}))}))}handleJoinSignal(e){if(this.activeCalls)try{const t=this.activeCalls.find((t=>t.id===e.callId));if(t){let i=!1,n=t.participants.find((t=>t.getFullId()===e.from));if(n||(n=t.participants.find((t=>t.id===e.from.split("/")[0]&&(t.clientId===e.from.split("/")[1]||!t.clientId))),n?n.clientId=e.from.split("/")[1]:n=void 0),!n&&t.localParticipant.screenSharing&&this.sendSignalScreenShare(t,!0),n||(n=new a.Participant(e.from),t.addParticipantToList(n),i=!0),t.mediaFlow===o.MediaFlow.P2P&&t.localParticipant.state===o.ParticipantState.Joined&&this.isPolitePeer(e.from,t.localParticipant.getFullId())){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[495] [CallId: ${t.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==o.SignalEvent.ERROR||S.error(`[499] [CallId: ${t.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})};S.info(`[503] [CallId: ${t.id}] Sending offer to participant: ${n.getFullId()}`),this.sendOfferPeerToPeer(t,n,e)}n.updateState(o.ParticipantState.Joined,t.id),S.info(`[503] [CallId: ${t.id}] Participant joined call shouldSendEventInvited: ${i}`),i?t.emitParticipantsAdded([n],o.ParticipantEntryType.ADDED):t.emitParticipantStateChanged(n,o.ParticipantState.Joined)}}catch(t){S.error(`[514] [CallId: ${e.callId}] Failed to handle USER_JOINED: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"})}}handleLeaveSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.id===e.from.split("/")[0]&&(t.clientId===e.from.split("/")[1]||!t.clientId)));i&&i.updateState(o.ParticipantState.Left,t.id)&&(this.closePeerConnections(t.id,i.getFullId()),t.activeSpeakerManager.removeParticipant(i),i.setMuted(!1),t.emitParticipantEvent(i,"Mute"),i.setVideoEnabled(!1),t.emitParticipantEvent(i,"VideoDisabled"),i.setScreenSharing(!1),t.emitParticipantEvent(i,"ScreenSharingStopped"),i.setHold(!1),t.emitParticipantEvent(i,"Unhold"),t.emitParticipantStateChanged(i,o.ParticipantState.Left),i.updateConnectionState(o.ParticipantConnectionState.Idle,t.id)&&t.emitParticipantConnectionStateChanged(i,o.ParticipantConnectionState.Idle))}}handleInviteSignal(e){if(!e||!e.callId)return void S.warn(`[545] [CallId: ${e.callId}] Received invalid invite signal message`);const t=this.activeCalls.find((t=>t.id===e.callId)),i=(null==e?void 0:e.to)===this.user.id;i&&t&&t.participants.forEach((e=>{e.id===this.user.id&&(e.updateConnectionState(o.ParticipantConnectionState.Idle,t.id),e.updateState(o.ParticipantState.Idle,t.id),null==t||t.emitParticipantConnectionStateChanged(e,o.ParticipantConnectionState.Idle),null==t||t.emitParticipantStateChanged(e,o.ParticipantState.Idle))})),t?this.handleExistingCallInvite(t,e,i):this.handleNewCallInvite(e,i),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}handleExistingCallInvite(e,t,i){var n,a;if(i){e.localParticipant.updateConnectionState(o.ParticipantConnectionState.Connecting,e.id)&&(e.participants.find((e=>e.id===this.user.id&&e.clientId===this.clientId))||e.addParticipantToList(e.localParticipant),e.emitParticipantConnectionStateChanged(e.localParticipant,o.ParticipantConnectionState.Connecting));const i=(null===(a=null===(n=t.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(i),this.callEvents.onInvitedToCall&&this.callEvents.onInvitedToCall(e)}else{const i=this.addNewParticipantsToCall(e,t);i.length>0&&e.emitParticipantsAdded(i,o.ParticipantEntryType.ADDED)}}handleNewCallInvite(e,t){var i;const n=new a.Participant(this.user.id,this.clientId);n.updateConnectionState(o.ParticipantConnectionState.Connecting,e.callId);let l=!1;const r=null===(i=e.participants)||void 0===i?void 0:i.map((t=>{if(t.id===this.user.id&&!t.clientId)return l=t.isCallSilenced||!1,n;const i=new a.Participant(t.id,null==t?void 0:t.clientId);return i.updateState(t.state||o.ParticipantState.Idle,e.callId),i}));if(!t&&!(null==r?void 0:r.find((t=>t.getFullId()===e.from)))&&e.from.split("/")[0]===this.user.id&&e.from.split("/")[1]!==this.clientId){const t=new a.Participant(e.from,e.from.split("/")[1]);t.updateState(o.ParticipantState.Joined,e.callId),null==r||r.push(t)}const d=(0,c.makeFirstById)(r||[],this.user.id,this.clientId),u=new s.Call({id:e.callId,sessionId:e.sessionId,mediaFlow:e.mediaFlow,createdBy:e.from,localParticipant:n,metadata:e.metadata,participants:d,chatClient:this.chatClient,isCallSilenced:l});this.activeCalls.push(u),this.callEvents.onInvitedToCall&&t&&this.callEvents.onInvitedToCall(u),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}addNewParticipantsToCall(e,t){var i;const n=[];return null===(i=t.participants)||void 0===i||i.forEach((t=>{const i=t.id!==this.user.id?e.participants.find((e=>e.id===t.id)):void 0,l=i||new a.Participant(t.id,null==t?void 0:t.clientId);i?t.state!==o.ParticipantState.Joined&&(l.updateState(t.state||o.ParticipantState.Idle,e.id),l.updateConnectionState(o.ParticipantConnectionState.Idle,e.id),l.setVideoEnabled(t.videoEnabled||!1),e.emitParticipantStateChanged(l,o.ParticipantState.Idle),e.emitParticipantConnectionStateChanged(l,o.ParticipantConnectionState.Idle)):(l.updateState(t.state||o.ParticipantState.Idle,e.id),n.push(l),e.addParticipantToList(l))})),n}handleCloseSignal(e){if(this.activeCalls){const t=this.activeCalls.find((t=>t.id===e.callId));if(!t)return;t&&this.closeCall(t)}}handleDeclineSignal(e){var t;if(!this.activeCalls)return;const i=this.activeCalls.find((t=>t.id===e.callId));if(i)if(this.getParticipantId({id:this.user.id,clientId:this.clientId})===e.from)this.leaveCall(i,!0,"Current user declined the call"),i.setState(o.CallState.Idle,"Current user declined the call");else{let n=null==i?void 0:i.participants.find((t=>t.getFullId()===e.from));n||(n=null==i?void 0:i.participants.find((t=>t.id===e.from.split("/")[0]&&!t.clientId)),n?n.clientId=e.from.split("/")[1]:(n=new a.Participant(e.from),i.addParticipantToList(n),i.emitParticipantsAdded([n],o.ParticipantEntryType.ADDED))),n&&n.updateState(o.ParticipantState.Declined,i.id)&&i.emitParticipantStateChanged(n,o.ParticipantState.Declined,null===(t=e.metadata)||void 0===t?void 0:t.reason)}}handleRingingSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){let i=null==t?void 0:t.participants.find((t=>t.id===e.from.split("/")[0]&&(t.clientId===e.from.split("/")[1]||!t.clientId)));i||(i=new a.Participant(e.from),t.addParticipantToList(i),t.emitParticipantsAdded([i],o.ParticipantEntryType.ADDED)),i&&i.connectionState!==o.ParticipantConnectionState.Connected&&i.updateState(o.ParticipantState.Ringing,t.id)&&t.emitParticipantStateChanged(i,o.ParticipantState.Ringing)}}handleSwitchMediaFlowSignal(e){const t=this.activeCalls.find((t=>t.id===e.callId));if(t&&t.localParticipant.state===o.ParticipantState.Joined){t.changeMediaFlow(o.MediaFlow.SFU);const e=new a.Participant(t.id);t.setServerParticipant(e);const i=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[738] [CallId: ${t.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`):e.event!==o.SignalEvent.ERROR||S.error(`[742] [CallId: ${t.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`)};S.info(`[747] [CallId: ${t.id}] Sending offer to server participant: ${e.getFullId()}`),this.sendOfferPeerToPeer(t,e,i),t.participants.forEach((e=>{e.setShouldResetPeerConnection(!0)}))}else t&&t.changeMediaFlow(o.MediaFlow.SFU)}handleIceSignal(e){var t;if(!e.callId||!e.ice)return void S.warn(`[756] [CallId: ${e.callId}] Invalid ICE signal: missing callId or ice data`);const i=this.activeCalls.find((t=>t.id===e.callId));if(!i)return void S.warn(`[763] [CallId: ${e.callId}] ICE candidate received for unknown call: ${e.callId}`);const n=i.participants.find((t=>t.getFullId()===e.from));if(n)try{if(!this.callParticipantsRTCMap[i.id])return void S.error(`[774] [CallId: ${i.id}] No RTC map found for call ${i.id}`);null===(t=this.callParticipantsRTCMap[i.id][n.getFullId()])||void 0===t||t.addIceCandidate(e.ice,n.getFullId())}catch(e){S.error(`[787] [CallId: ${i.id}] Failed to add ICE candidate for participant ${n.getFullId()} in call ${i.id}: ${e instanceof Error?e.message:JSON.stringify(e)}`)}else S.warn(`[768] [CallId: ${e.callId}] ICE candidate received from unknown participant: ${e.from} in call ${e.callId}`)}handleVideoOnSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from||t.id===e.from.split("/")[0]&&!t.clientId));i&&(i.setVideoEnabled(!0),t.emitParticipantEvent(i,"VideoEnabled"),t.setVideoEnabled(!0))}}handleVideoOffSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){let i;null==t||t.participants.forEach((t=>{(t.getFullId()===e.from||t.id===e.from.split("/")[0]&&!t.clientId)&&(t.setVideoEnabled(!1),i=t)})),i&&t.emitParticipantEvent(i,"VideoDisabled")}}handleScreenShareOnSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setScreenSharing(!0),t.emitParticipantEvent(i,"ScreenSharingStarted"))}}handleScreenShareOffSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setScreenSharing(!1),t.emitParticipantEvent(i,"ScreenSharingStopped"),i.videoEnabled&&(i.setVideoEnabled(!0),t.emitParticipantEvent(i,"VideoEnabled"),t.setVideoEnabled(!0)))}}handleMuteSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setMuted(!0),t.emitParticipantEvent(i,"Mute"))}}handleUnmuteSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setMuted(!1),t.emitParticipantEvent(i,"Unmute"))}}handleHoldSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setHold(!0),t.emitParticipantEvent(i,"Hold"))}}handleUnholdSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&(i.setHold(!1),t.emitParticipantEvent(i,"Unhold"))}}handleKickSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){const i=null==t?void 0:t.participants.find((t=>t.getFullId()===e.from));i&&i.updateState(o.ParticipantState.Kicked,t.id)&&t.emitParticipantStateChanged(i,o.ParticipantState.Kicked)}}handleUpdateSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));t&&e.metadata&&(t.metadata=e.metadata)}handleNoAnswerSignal(e){var t;if(!this.activeCalls)return;const i=this.activeCalls.find((t=>t.id===e.callId));i&&(null===(t=e.participants)||void 0===t||t.forEach((e=>{(null==i?void 0:i.participants.filter((t=>t.id===e.id&&(t.clientId===e.clientId||!e.clientId)))).forEach((e=>{e.updateState(o.ParticipantState.NoAnswer,i.id)&&i.emitParticipantStateChanged(e,o.ParticipantState.NoAnswer)}))})))}static getInstance(){return C.instance}setRTCConfig(e){this.rtcConfig=e}onIceCandidateListener(e,t){return i=>{this.onIceCandidate(e,i,t)}}onSignalingStateChangeListener(e,t){return i=>{var n;const a=(null===(n=null==i?void 0:i.currentTarget)||void 0===n?void 0:n.signalingState)||"unknown";S.info(`[1067] [CallId: ${t.id}] Signaling state change: ${a}, participantID: ${e.getFullId()}`,{color:"blue"})}}isPolitePeer(e,t){return t>e}onIceConnectionStateChangeListener(e,t){return i=>{var n;const a=(null===(n=null==i?void 0:i.currentTarget)||void 0===n?void 0:n.iceConnectionState)||"unknown";S.info(`[1078] [CallId: ${t.id}] ICE connection state change: ${a}, participantID: ${e.getFullId()}`,{color:"blue"})}}onConnectionStateChangeListener(e,t){return i=>{var n,a,l,r,s;const c=i.currentTarget.connectionState;S.info(`[1078] [CallId: ${t.id}] PC connection state changed: ${c}, participantID: ${e.getFullId()}`,{color:"disconnected"===c?"orange":"failed"===c?"red":"blue"});const d=this.activeCalls.find((e=>e.id===t.id))||t,u=(null==d?void 0:d.participants.find((t=>t.getFullId()===e.getFullId())))||e.id===(null===(n=null==d?void 0:d.serverParticipant)||void 0===n?void 0:n.id)&&e||e;let g=0,h=null;const C=(i,n=!1)=>{S.info(`[1089] [CallId: ${t.id}] start renegotiation send ${i} to participant ${u.getFullId()}`,{color:"blue"});const a=e=>{if("Connected"===this.chatClient.connectionState&&u.connectionState!==o.ParticipantConnectionState.Connected&&d.state===o.CallState.Connected){S.info(`[1190] [CallId: ${t.id}] interval renegotiation send ${i} to participant ${u.getFullId()}`,{color:"blue"});try{if("offer"!==i||n&&!this.isPolitePeer(u.getFullId(),(null==d?void 0:d.localParticipant.getFullId())||"")){if("connect"===i&&(!n||this.isPolitePeer(u.getFullId(),(null==d?void 0:d.localParticipant.getFullId())||""))){S.info(`[1214] [CallId: ${t.id}] ${o.MediaFlow.SFU} sendConnect to participant 1 ${JSON.stringify(u)}`,{color:"blue"});try{this.signalingClient.clearParticipantSignals(t.id,u.getFullId()),this.signalingClient.sendSignalMessage({mediaFlow:t.mediaFlow,callId:t.id,sessionId:t.sessionId,event:o.SignalEvent.CONNECT,to:u.getFullId()},e)}catch(e){S.error(`[1236] [CallId: ${t.id}] Failed to send connect to participant ${u.getFullId()}: message: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}}else try{S.info(`[1211] [CallId: ${t.id}] Sending offer to participant: ${u.getFullId()}`),this.sendOfferPeerToPeer(t,u,e)}catch(e){S.error(`[1211] [CallId: ${t.id}] Failed to send offer to participant ${u.getFullId()}: ${e instanceof Error?e.message:JSON.stringify(e)}`)}}catch(e){S.error(`[1240] [CallId: ${t.id}] Failed to send offer to participant ${u.getFullId()}: message: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"})}}};h=setInterval((()=>{var n,l,r;const s=this.activeCalls.find((e=>e.id===t.id))||t,c=(null==s?void 0:s.participants.find((t=>t.getFullId()===e.getFullId())))||e.id===(null===(n=null==s?void 0:s.serverParticipant)||void 0===n?void 0:n.id)&&e||e;S.info(`[1182] [CallId: ${t.id}] interval time: ${g+4}`,{color:"green"});const d=null===(r=null===(l=this.callParticipantsRTCMap[t.id])||void 0===l?void 0:l[c.getFullId()])||void 0===r?void 0:r.peerConnection;return s&&s.state===o.CallState.Connected?c.connectionState===o.ParticipantConnectionState.Connected&&"stable"===(null==d?void 0:d.signalingState)?(g=0,void(h&&(clearInterval(h),h=null))):(g+=4,a((e=>{var n;return e instanceof p.SceytCallException||e instanceof Error?(S.error(`[1202] [CallId: ${t.id}] SYNC ${i} failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}),void("NotAllowed"===e.name&&(c.updateConnectionState(o.ParticipantConnectionState.Disconnected,t.id),h&&(clearInterval(h),h=null)))):e.event===o.SignalEvent.ERROR?(S.error(`[1205] [CallId: ${t.id}] SYNC ${i} 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(o.ParticipantConnectionState.Disconnected,t.id),h&&(clearInterval(h),h=null)))):void 0})),void(s&&s.state===o.CallState.Connected||(g=0,h&&(clearInterval(h),h=null)))):(g=0,void(h&&(clearInterval(h),h=null)))}),4e3);const l=setTimeout((()=>{a((e=>{var i;return e instanceof p.SceytCallException||e instanceof Error?(S.error(`[1202] [CallId: ${t.id}] SYNC OFFER failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}),void(("NotAllowed"===e.name||e instanceof p.SceytCallException&&4002===e.code)&&u.updateConnectionState(o.ParticipantConnectionState.Disconnected,t.id))):e.event===o.SignalEvent.ERROR?(S.error(`[1205] [CallId: ${t.id}] SYNC OFFER failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"}),void(4002===(null===(i=e.error)||void 0===i?void 0:i.code)&&u.updateConnectionState(o.ParticipantConnectionState.Disconnected,t.id))):void 0})),clearTimeout(l)}),2e3)},v=()=>{var i;h||u&&d&&(d.mediaFlow===o.MediaFlow.SFU&&e.id===(null===(i=null==d?void 0:d.serverParticipant)||void 0===i?void 0:i.id)&&this.callParticipantsRTCMap[d.id]&&this.callParticipantsRTCMap[d.id][e.getFullId()]&&d.localParticipant.state===o.ParticipantState.Joined&&(S.info(`[1258] [CallId: ${t.id}] start renegotiation ${o.MediaFlow.SFU} sendOffer to participant ${u.getFullId()}`,{color:"blue"}),C("offer",!1)),d.mediaFlow===o.MediaFlow.S2W&&u.state===o.ParticipantState.Joined&&this.callParticipantsRTCMap[d.id]&&this.callParticipantsRTCMap[d.id][u.getFullId()]&&d.localParticipant.state===o.ParticipantState.Joined&&(S.info(`[1263] [CallId: ${t.id}] start renegotiation ${o.MediaFlow.SFU} sendConnect to participant ${u.getFullId()}`,{color:"blue"}),C("offer",!1)))};switch(c){case"new":break;case"connecting":t.mediaFlow===o.MediaFlow.SFU&&u.id===(null===(a=null==d?void 0:d.serverParticipant)||void 0===a?void 0:a.id)&&d.localParticipant.updateConnectionState(o.ParticipantConnectionState.Connecting,t.id)&&d.emitParticipantConnectionStateChanged(d.localParticipant,o.ParticipantConnectionState.Connecting),u.updateConnectionState(o.ParticipantConnectionState.Connecting,t.id)&&d.emitParticipantConnectionStateChanged(u,o.ParticipantConnectionState.Connecting);break;case"connected":if(t.mediaFlow===o.MediaFlow.SFU&&u.id===(null===(l=null==d?void 0:d.serverParticipant)||void 0===l?void 0:l.id)&&d.localParticipant.updateConnectionState(o.ParticipantConnectionState.Connected,t.id)&&d.emitParticipantConnectionStateChanged(d.localParticipant,o.ParticipantConnectionState.Connected),u.updateConnectionState(o.ParticipantConnectionState.Connected,t.id)&&d.emitParticipantConnectionStateChanged(u,o.ParticipantConnectionState.Connected),u&&d&&"Connected"===this.chatClient.connectionState&&(d.mediaFlow!==o.MediaFlow.SFU||d.mediaFlow===o.MediaFlow.SFU&&u.id===(null==d?void 0:d.id))){const e=e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[1098] [CallId: ${d.id}] SYNC MEDIA_CONNECTED signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==o.SignalEvent.ERROR||S.error(`[1102] [CallId: ${d.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:d.mediaFlow,callId:d.id,sessionId:d.sessionId,event:o.SignalEvent.MEDIA_CONNECTED},d.mediaFlow!==o.MediaFlow.SFU?{to:d.id}:{}),e)}break;case"disconnected":t.mediaFlow===o.MediaFlow.SFU&&u.id===(null===(r=null==d?void 0:d.serverParticipant)||void 0===r?void 0:r.id)&&d.localParticipant.updateConnectionState(o.ParticipantConnectionState.Reconnecting,t.id)&&d.emitParticipantConnectionStateChanged(d.localParticipant,o.ParticipantConnectionState.Reconnecting),u.updateConnectionState(o.ParticipantConnectionState.Reconnecting,t.id)&&d.emitParticipantConnectionStateChanged(u,o.ParticipantConnectionState.Reconnecting),S.info("[1250] I am here",{color:"blue"}),t.mediaFlow!==o.MediaFlow.S2W&&v();break;case"failed":u&&d&&(d.mediaFlow===o.MediaFlow.P2P&&u.state===o.ParticipantState.Joined&&this.callParticipantsRTCMap[d.id]&&this.callParticipantsRTCMap[d.id][u.getFullId()]&&d.localParticipant.state===o.ParticipantState.Joined?(S.info(`[1268] [CallId: ${t.id}] start renegotiation ${d.mediaFlow} sendOffer to participant ${u.getFullId()}`,{color:"blue"}),C("offer",!0)):v());break;case"closed":t.mediaFlow===o.MediaFlow.SFU&&u.id===(null===(s=null==d?void 0:d.serverParticipant)||void 0===s?void 0:s.id)&&d.localParticipant.updateConnectionState(o.ParticipantConnectionState.Idle,t.id)&&d.emitParticipantConnectionStateChanged(d.localParticipant,o.ParticipantConnectionState.Idle),u.updateConnectionState(o.ParticipantConnectionState.Idle,t.id)&&d.emitParticipantConnectionStateChanged(u,o.ParticipantConnectionState.Idle)}}}onIceCandidateErrorListener(e,t){return i=>{S.error(`[1284] [CallId: ${t.id}] ICE candidate error participantID: ${e.getFullId()}, error - code: ${i.errorCode}, message: ${i.errorText}, url: ${i.url}`,{color:"red"})}}onTrackListener(e,t){return i=>{this.onTrack(e,t,i)}}closePeerConnections(e,t){if(!this.callParticipantsRTCMap[e])return;const i=this.callParticipantsRTCMap[e][t];i?(i.listeners?(Object.keys(i.listeners).forEach((e=>{i.removeEventListener(e,i.listeners[e])})),S.info(`[1313] [CallId: ${e}] Removed all listeners for WebRTCClient of participant ${t}`,{color:"cyan"})):S.info(`[1316] [CallId: ${e}] No listeners found for WebRTCClient of participant ${t}`,{color:"cyan"}),i.close(),i.peerConnection.onicecandidate=null,i.peerConnection.ontrack=null,i.peerConnection.onconnectionstatechange=null,i.peerConnection.oniceconnectionstatechange=null,i.peerConnection.onsignalingstatechange=null,this.callParticipantsRTCMap[e][t]=null,delete this.callParticipantsRTCMap[e][t]):S.info(`[1375] [CallId: ${e}] No WebRTCClient found for participant ${t}`,{color:"cyan"})}addParticipantToRTCMap(e,t){this.callParticipantsRTCMap.hasOwnProperty(e.id)||(this.callParticipantsRTCMap[e.id]={});const i=new l.WebRTCClient(e.id,this.rtcConfig);this.callParticipantsRTCMap[e.id][t.getFullId()]=i;const n=this.onIceCandidateListener(t,e),a=this.onSignalingStateChangeListener(t,e),r=this.onIceConnectionStateChangeListener(t,e),o=this.onConnectionStateChangeListener(t,e),s=this.onTrackListener(e,t),c=this.onIceCandidateErrorListener(t,e);return i.addEventListener("icecandidate",n),i.addEventListener("signalingstatechange",a),i.addEventListener("connectionstatechange",o),i.addEventListener("track",s),i.addEventListener("icecandidateerror",c),i.addEventListener("iceconnectionstatechange",r),i.setListeners({iceCandidateListener:n,signalingStateChangeListener:a,connectionStateChangeListener:o,trackListener:s,iceCandidateErrorListener:c,iceConnectionStateChangeListener:r}),S.info(`[1371] [CallId: ${e.id}] Added Event Listeners to RTC Map: participantID: ${t.getFullId()}`,{color:"blue"}),e.activeSpeakerManager.addParticipant(t),t}joinToCall(e,t){return this.signalingClient.sendSignalMessage(Object.assign(Object.assign(Object.assign({mediaFlow:e.mediaFlow,callId:e.callId},e.sessionId&&{sessionId:e.sessionId}),{event:o.SignalEvent.JOIN,participants:e.participants}),(null==e?void 0:e.metadata)&&{metadata:e.metadata}),t)}sendRinging(e,t){return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:o.SignalEvent.RINGING},(i=>i instanceof p.SceytCallException||i instanceof Error?(S.error(`[1389] [CallId: ${e.id}] SYNC RINGING failed message: ${i.message} code: ${i instanceof p.SceytCallException?i.code:""}`,{color:"red"}),void(null==t||t({error:(0,h.toCallException)(i)}))):i.event===o.SignalEvent.ERROR?(S.error(`[1393] [CallId: ${e.id}] SYNC RINGING failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`,{color:"red"}),void(null==t||t({error:(0,h.toCallException)(new Error("Failed to send ringing signal"))}))):(e.localParticipant.updateState(o.ParticipantState.Ringing,e.id),void e.emitParticipantStateChanged(e.localParticipant,o.ParticipantState.Ringing)))),{success:!0}}rejectCall(e,t,i){try{const n=this.activeCalls.find((t=>t.id===e.id));n&&(n.setState(o.CallState.Idle,"rejectCall"),n.localParticipant.updateState(o.ParticipantState.Declined,e.id)&&n.emitParticipantStateChanged(n.localParticipant,o.ParticipantState.Declined),n.localParticipant.updateConnectionState(o.ParticipantConnectionState.Idle,e.id)&&n.emitParticipantConnectionStateChanged(n.localParticipant,o.ParticipantConnectionState.Idle),this.closeTracksAndPeerConnections(n));const a=t=>t instanceof p.SceytCallException||t instanceof Error?(S.error(`[1420] [CallId: ${e.id}] SYNC DECLINE failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`,{color:"red"}),void(null==i||i({error:(0,h.toCallException)(t)}))):t.event===o.SignalEvent.ERROR?(S.error(`[1424] [CallId: ${e.id}] SYNC DECLINE failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"}),void(null==i||i({error:(0,h.toCallException)(t.error||new Error("Failed to send decline signal"))}))):void 0;return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:o.SignalEvent.DECLINE,metadata:Object.assign(Object.assign({},e.metadata),{reason:t||""})},a),{success:!0}}catch(t){return S.error(`[1432] [CallId: ${e.id}] Failed to reject call: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"}),{success:!1,error:(0,h.toCallException)(t)}}}closeTracksAndPeerConnections(e){e.localAudioTracks.forEach((e=>{e.stop()})),e.localVideoTracks.forEach((e=>{e.stop()})),e.participants.forEach((t=>{t.videoTracks.forEach((e=>{e.stop()})),t.audioTracks.forEach((e=>{e.stop()})),this.closePeerConnections(e.id,t.getFullId()),e.activeSpeakerManager.removeParticipant(t)})),e.localParticipant.videoTracks.forEach((e=>{e.stop()})),e.localParticipant.audioTracks.forEach((e=>{e.stop()})),e.mediaFlow===o.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(o.CallState.Closed,"closeCall"),this.closeTracksAndPeerConnections(e);const t=this.activeCalls.findIndex((t=>t.id===e.id));this.activeCalls.splice(t,1),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls),delete this.callParticipantsRTCMap[e.id],S.info(`[1474] [CallId: ${e.id}] closed call and removed from active calls: callId: ${e.id}`,{color:"light-green"})}leaveCall(e,t=!0,i){const n=this.activeCalls.find((t=>t.id===e.id));if(n){this.signalingClient.cancelJoinIfPossible(e.id);const a=n.setState(o.CallState.Idle,`leaveCall: ${i}`);if(t&&a){const t=t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[1487] [CallId: ${e.id}] SYNC LEAVE failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`,{color:"red"}):t.event!==o.SignalEvent.ERROR||S.error(`[1491] [CallId: ${e.id}] SYNC LEAVE failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"})};this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,sessionId:e.sessionId,event:o.SignalEvent.LEAVE},t)}this.closeTracksAndPeerConnections(n),delete this.callParticipantsRTCMap[n.id],n.localParticipant.updateState(o.ParticipantState.Left,e.id)&&n.emitParticipantStateChanged(n.localParticipant,o.ParticipantState.Left),n.localParticipant.setVideoEnabled(!1),n.localParticipant.setScreenSharing(!1),n.localParticipant.setMuted(!1),n.localParticipant.connectionState!==o.ParticipantConnectionState.Idle&&n.localParticipant.updateConnectionState(o.ParticipantConnectionState.Idle,e.id),n.participants.forEach((t=>{t.connectionState!==o.ParticipantConnectionState.Idle&&(t.updateConnectionState(o.ParticipantConnectionState.Idle,e.id),n.emitParticipantConnectionStateChanged(t,o.ParticipantConnectionState.Idle))})),e.sessionId||(this.activeCalls=this.activeCalls.filter((e=>e.id!=n.id))),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls)}}setRemoteDescription(e,t,i){return this.callParticipantsRTCMap[e][t].setRemoteDescription(i)}changeVideoTracks(e,t,i,a){var l;return n(this,void 0,void 0,(function*(){if(S.info(`[1594] [CallId: ${e.id}], mediaFlow: ${e.mediaFlow}, changeVideoTracks ${i}, serverParticipant: ${(null===(l=e.serverParticipant)||void 0===l?void 0:l.id)||"null"}`,{color:"cyan"}),e.mediaFlow!==o.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(i,t,!!a))}else this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][e.id]&&(yield this.callParticipantsRTCMap[e.id][e.id].enableVideoOnPeerConnection(i,t,!!a))}))}changeAudioTracks(e,t,i){return n(this,void 0,void 0,(function*(){e.mediaFlow!==o.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()]&&(S.info(`[1561] [CallId: ${e.id}] Enabling audio on peer connection: ${n.getFullId()}`,{color:"cyan"}),this.callParticipantsRTCMap[e.id][n.getFullId()].enableAudioOnPeerConnection(i,t))})):(S.info(`[1565] [CallId: ${e.id}] Enabling audio on peer connection: ${e.id}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][e.id].enableAudioOnPeerConnection(i,t))}))}sendVideoEnabled(e,t,i){if(this.activeCalls.find((t=>t.id===e.id)))try{const n=t=>t instanceof p.SceytCallException||t instanceof Error?(S.error(`[1632] [CallId: ${e.id}] SYNC VIDEO_ON failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`),void(null==i||i({error:(0,h.toCallException)(t)}))):t.event===o.SignalEvent.ERROR?(S.error(`[1636] [CallId: ${e.id}] SYNC VIDEO_ON failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`),void(null==i||i({error:(0,h.toCallException)(t.error||t)}))):void 0;this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:t?o.SignalEvent.VIDEO_ON:o.SignalEvent.VIDEO_OFF,sessionId:e.sessionId},n)}catch(t){return S.error(`[1645] [CallId: ${e.id}] Failed to send video enabled signal: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"}),null==i||i({error:(0,h.toCallException)(t)}),!1}}sendScreenShare(e,t,i){return n(this,void 0,void 0,(function*(){const n=this.activeCalls.find((t=>t.id===e.id));try{if(n)return this.sendSignalScreenShare(e,t,i)}catch(t){return S.error(`[1668] [CallId: ${e.id}] Failed to send screen share signal: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"}),null==i||i({error:(0,h.toCallException)(t)}),!1}}))}sendAudioEnable(e,t,i){return n(this,void 0,void 0,(function*(){if(this.activeCalls.find((t=>t.id===e.id))){const a=a=>n(this,void 0,void 0,(function*(){try{if(a instanceof p.SceytCallException||a instanceof Error)return S.error(`[1704] [CallId: ${e.id}] SYNC HOLD failed message: ${a.message} code: ${a instanceof p.SceytCallException?a.code:""}`),void(null==i||i({error:(0,h.toCallException)(a)}));if(a.event===o.SignalEvent.ERROR)return S.error(`[1708] [CallId: ${e.id}] SYNC HOLD failed message: ${a.error?`${a.error.message} code: ${a.error.code}`:""}`),void(null==i||i({error:(0,h.toCallException)(a.error)}));if(e.mediaFlow!==o.MediaFlow.SFU)for(let i=0;i<e.participants.length;i++){const n=e.participants[i];(n.id!==this.user.id||n.clientId!==this.clientId)&&n.clientId&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][n.getFullId()]&&(S.info(`[1712] [CallId: ${e.id}] Enabling audio on peer connection: ${n.getFullId()}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][n.getFullId()].enableAudioOnPeerConnection(t))}else this.callParticipantsRTCMap&&this.callParticipantsRTCMap[e.id]&&this.callParticipantsRTCMap[e.id][e.serverParticipant.id]&&(S.info(`[1712] [CallId: ${e.id}] Enabling audio on peer connection: ${e.serverParticipant.id}`,{color:"cyan"}),yield this.callParticipantsRTCMap[e.id][e.serverParticipant.id].enableAudioOnPeerConnection(t));e.localParticipant.audioTracks.forEach((e=>{e.enabled=!t}))}catch(t){S.error(`[1725] [CallId: ${e.id}] Failed to enable audio on peer connection: ${t instanceof Error?t.message:JSON.stringify(t)}`),null==i||i({error:(0,h.toCallException)(t)})}}));return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:t?o.SignalEvent.MUTE:o.SignalEvent.UNMUTE,sessionId:e.sessionId},a)}}))}sendHold(e,t,i){const n=this.activeCalls.find((t=>t.id===e.id));if(n){this.sendAudioEnable(n,!t,i);const a=t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[1741] [CallId: ${e.id}] SYNC HOLD failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`):t.event!==o.SignalEvent.ERROR||S.error(`[1745] [CallId: ${e.id}] SYNC HOLD failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`)};return this.signalingClient.sendSignalMessage({mediaFlow:e.mediaFlow,callId:e.id,event:t?o.SignalEvent.HOLD:o.SignalEvent.UNHOLD,sessionId:e.sessionId},a)}}addTracksToPeerConnection(e,t,i=!0){return n(this,void 0,void 0,(function*(){let n=e.localVideoTracks;const a=e.localAudioTracks,l=new MediaStream;a&&a.length>0&&l.addTrack(a[0]);try{i?yield this.callParticipantsRTCMap[e.id][t].addTransceiverToPeerConnection(a[0],e.mediaFlow):yield this.callParticipantsRTCMap[e.id][t].setStreamsToTransceiver(a[0])}catch(t){S.warn(`[1766] [CallId: ${e.id}] Failed to add track to peer connection: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"})}n&&n.length>0||(n=(0,c.getEmptyVideoTrack)()),l.addTrack(n[0]);try{i?yield this.callParticipantsRTCMap[e.id][t].addTransceiverToPeerConnection(n[0],e.mediaFlow):yield this.callParticipantsRTCMap[e.id][t].setStreamsToTransceiver(n[0])}catch(t){S.warn(`[1775] [CallId: ${e.id}] Failed to add track to peer connection: message: ${t instanceof Error?t.message:JSON.stringify(t)}`,{color:"red"})}}))}switchCallToSfu(e,t){try{const i=i=>{if(i instanceof p.SceytCallException||i instanceof Error)return S.error(`[1785] [CallId: ${e.id}] SYNC SWITCH_MEDIA_FLOW signal sent failed message: ${i.message} code: ${i instanceof p.SceytCallException?i.code:""}`),void(null==t||t({error:(0,h.toCallException)(i)}));if(i.event===o.SignalEvent.ERROR)return S.error(`[1789] [CallId: ${e.id}] SYNC SWITCH_MEDIA_FLOW signal sent failed message: ${i.error?`${i.error.message} code: ${i.error.code}`:""}`),void(null==t||t({error:(0,h.toCallException)(i)}));const n=new a.Participant(e.id);return e.setServerParticipant(n),e.participants.forEach((t=>{t.id===this.user.id&&t.clientId===this.clientId||t.updateConnectionState(o.ParticipantConnectionState.Idle,e.id),t.setShouldResetPeerConnection(!0)})),e.changeMediaFlow(o.MediaFlow.SFU),S.info(`[1818] [CallId: ${e.id}] Sending offer to server participant: ${n.getFullId()}`),this.sendOfferPeerToPeer(e,n,(t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[1805] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`):t.event!==o.SignalEvent.ERROR||S.error(`[1809] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`)})),!0};return this.signalingClient.sendSignalMessage({mediaFlow:o.MediaFlow.SFU,callId:e.id,event:o.SignalEvent.SWITCH_MEDIA_FLOW,sessionId:e.sessionId},i),S.info(`[1823] [CallId: ${e.id}] Switched call ${e.id} to SFU`,{color:"light-green"}),{success:!0}}catch(t){return S.error(`[1827] [CallId: ${e.id}] Failed to switch ${o.MediaFlow.SFU} message: ${t instanceof Error?t.message:JSON.stringify(t)}`),{success:!1,error:(0,h.toCallException)(t)}}}getCallById(e,t){return this.signalingClient.sendSignalMessage({callId:e,sessionId:t,event:o.SignalEvent.GET_CALL},(t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[1833] [CallId: ${e}] SYNC GET_CALL signal sent failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`):t.event!==o.SignalEvent.ERROR||S.error(`[1837] [CallId: ${e}] SYNC GET_CALL signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`)}),e)}getCalls(){return this.signalingClient.sendSignalMessage({callId:"",event:o.SignalEvent.GET_CALL},(e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[1849] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`):e.event!==o.SignalEvent.ERROR?this.syncActiveCalls(e):S.error("[1853] [CallId: GLOBAL_LOGS] SYNC GET_CALL signal sent failed message: "+(e.error?`${e.error.message} code: ${e.error.code}`:""))}),"get_call")}findOrCreateCall(e,t){var i,n;let l=this.activeCalls.find((t=>t.id===e.id)),r=!1,d=!1;if(l){if(S.info(`[1911] [CallId: ${l.id}] Using existing call`,{color:"cyan"}),r=!0,!l.participants.find((e=>e.id===this.user.id&&e.clientId===this.clientId))&&l.localParticipant.id===this.user.id&&l.localParticipant.clientId===this.clientId){const e=(0,c.makeFirstById)([...l.participants,l.localParticipant],this.user.id,this.clientId);l.participants=e,l.emitParticipantsAdded([l.localParticipant],o.ParticipantEntryType.ADDED)}e.localAudioTracks&&(null===(i=e.localAudioTracks)||void 0===i?void 0:i.length)&&(l.localAudioTracks=e.localAudioTracks||[],l.localParticipant.setAudioTracks(e.localAudioTracks||[])),e.localVideoTracks&&(null===(n=e.localVideoTracks)||void 0===n?void 0:n.length)&&(l.localVideoTracks=e.localVideoTracks||[],l.localParticipant.setVideoTracks(e.localVideoTracks||[]))}else{let i=new a.Participant(this.user.id,this.clientId);const n=e.id||(0,u.v4)();S.info(`[1869] [CallId: ${n}] Creating new call`,{color:"cyan"});const p=(t||e.participantIds).map((e=>{let n=new a.Participant(t?e.id:e,t?e.clientId:void 0);return t&&(n.setVideoEnabled(e.videoEnabled),n.setMuted(e.muted),n.state=e.state,e.connectionState>o.ParticipantConnectionState.Connected&&e.id!==this.user.id&&e.clientId!==this.clientId&&(n.connectionState=e.connectionState),this.user.id!==e.id||e.clientId!==this.clientId&&e.clientId||(d=(null==e?void 0:e.isCallSilenced)||!1,i=n)),n})),g=(0,c.makeFirstById)([...p,i],this.user.id,this.clientId);l=new s.Call({id:n,sessionId:e.sessionId,mediaFlow:e.mediaFlow,localParticipant:i,participants:g,metadata:e.metadata,createdBy:e.createdBy,chatClient:this.chatClient,isCallSilenced:d}),l.localAudioTracks=e.localAudioTracks||[],l.localVideoTracks=e.localVideoTracks||[],l.localParticipant.setVideoTracks(e.localVideoTracks||[]),l.localParticipant.setAudioTracks(e.localAudioTracks||[]),this.activeCalls.push(l),this.callEvents.onOngoingCallsUpdated&&this.callEvents.onOngoingCallsUpdated(this.activeCalls),r=!1}return{call:l,answer:r}}processJoinAcknowledgment(e,t,i){var n,a,l,r;if(t.event===o.SignalEvent.ERROR)throw S.error(`[1955] [CallId: ${e.id}] Join failed: message: ${null===(n=t.error)||void 0===n?void 0:n.message} code: ${null===(a=t.error)||void 0===a?void 0:a.code}`),this.leaveCall(e,!0,"processJoinAcknowledgment"),(0,h.checkCode)((null===(l=t.error)||void 0===l?void 0:l.code)||0,null===(r=t.error)||void 0===r?void 0:r.message);if(t.event===o.SignalEvent.SUCCESS)return e.eventsQueue.forEach((e=>{e()})),e.eventsQueue.clear(),this.configureRTCServers(e,t,i),e;throw S.warn(`[1969] [CallId: ${e.id}] Unexpected join event: ${t.event}`),(0,h.checkCode)(4e3,`Unexpected event type: ${t.event}`)}configureRTCServers(e,t,i){var n;(null===(n=t.turnServers)||void 0===n?void 0:n.length)&&this.setRTCConfig(Object.assign(Object.assign({},e.mediaFlow===o.MediaFlow.SFU?{}:{iceServers:t.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,t.participants),e.mediaFlow===o.MediaFlow.SFU?this.setupSFUConnection(e,i,t):e.participants.forEach((t=>{e.mediaFlow===o.MediaFlow.P2P&&t.getFullId()!=e.localParticipant.getFullId()&&t.state===o.ParticipantState.Joined&&this.isPolitePeer(t.getFullId(),e.localParticipant.getFullId())&&(S.info(`[2008] [CallId: ${e.id}] Sending offer to participant: ${t.getFullId()}`),this.sendOfferPeerToPeer(e,t,(t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[2005] [CallId: ${e.id}] SYNC OFFER failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`):t.event!==o.SignalEvent.ERROR||S.error(`[2010] [CallId: ${e.id}] SYNC OFFER failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`)})))}))}setupSFUConnection(e,t,i){const n=new a.Participant(e.id);S.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 p.SceytCallException||n instanceof Error?S.error(`[2011] [CallId: ${e.id}] SYNC OFFER failed message: ${n.message} code: ${n instanceof p.SceytCallException?n.code:""}`):(n.event===o.SignalEvent.ERROR&&S.error(`[2015] [CallId: ${e.id}] SYNC OFFER failed message: ${n.error?`${n.error.message} code: ${n.error.code}`:""}`),n.event!==o.SignalEvent.ERROR&&(S.info(`[2019] [CallId: ${e.id}] offerAck: ${JSON.stringify(n)}`,{color:"cyan"}),e.participants.forEach((n=>{if(n.id===this.user.id&&n.clientId===this.clientId||!i.participants.find((e=>e.id===n.id&&e.clientId===n.clientId&&e.connectionState===o.MediaConnectionState.Connected)))n.connectionState&&n.connectionState>o.ParticipantConnectionState.Connected&&n.id!==this.user.id&&n.clientId!==this.clientId&&n.getFullId()!=e.localParticipant.getFullId()&&(n.updateConnectionState(n.connectionState,e.id),e.emitParticipantConnectionStateChanged(n,n.connectionState));else{const a=t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[2023] [CallId: ${e.id}] SYNC CONNECT failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`):t.event!==o.SignalEvent.ERROR||S.error(`[2028] [CallId: ${e.id}] SYNC CONNECT failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`)};this.signalingClient.clearParticipantSignals(e.id,n.getFullId()),this.signalingClient.sendSignalMessage({mediaFlow:t,callId:e.id,event:o.SignalEvent.CONNECT,sessionId:i.sessionId,to:n.getFullId(),metadata:e.metadata},a)}}))))};S.info(`[2067] [CallId: ${e.id}] Sending offer to server participant: ${n.getFullId()}`),this.sendOfferPeerToPeer(e,n,a)}catch(t){throw S.error(`[2049] [CallId: ${e.id}] SFU setup error: message: ${t instanceof Error?t.message:JSON.stringify(t)}`),(0,h.toCallException)(t)}}processRemoteParticipants(e,t){t.length&&(t.forEach((t=>{let i=e.participants.find((e=>e.getFullId()===this.getParticipantId(t)));if(i||(i=e.participants.find((e=>e.id===t.id&&(e.clientId===t.clientId||!e.clientId))),i&&!i.clientId&&(i.clientId=t.clientId)),i||e.localParticipant.getFullId()===this.getParticipantId(t))i&&e.localParticipant.getFullId()!==this.getParticipantId(t)&&(i.presenter=t.presenter,i.setVideoEnabled(!!t.hasOwnProperty("videoEnabled")&&t.videoEnabled),e.emitParticipantEvent(i,t.hasOwnProperty("videoEnabled")?"VideoEnabled":"VideoDisabled"),i.setMuted(!!t.hasOwnProperty("muted")&&t.muted),e.emitParticipantEvent(i,t.hasOwnProperty("muted")?"Mute":"Unmute"),i.setHold(!!t.hasOwnProperty("onHold")&&t.onHold),e.emitParticipantEvent(i,t.hasOwnProperty("onHold")?"Hold":"Unhold"),i.setScreenSharing(!!t.hasOwnProperty("screenSharing")&&t.screenSharing),e.emitParticipantEvent(i,t.hasOwnProperty("screenSharing")?"ScreenSharingStarted":"ScreenSharingStopped"),i.state!=t.state&&void 0!==t.state&&(i.updateState(t.state||o.ParticipantState.Idle,e.id),e.emitParticipantStateChanged(i,t.state,"FromJoin")));else{const i=new a.Participant(t.id,t.clientId);i.updateState(t.state,e.id),i.setVideoEnabled(!!t.hasOwnProperty("videoEnabled")&&t.videoEnabled),i.setMuted(!!t.hasOwnProperty("muted")&&t.muted),i.setHold(!!t.hasOwnProperty("onHold")&&t.onHold),i.setScreenSharing(!!t.hasOwnProperty("screenSharing")&&t.screenSharing),e.addParticipantToList(i),e.emitParticipantsAdded([i],o.ParticipantEntryType.ADDED)}})),S.info(`[2098] [CallId: ${e.id}] Processed participants - Added and Updated`,{color:"cyan"}))}processJoinCall(e,t,i){e.mediaFlow!==o.MediaFlow.SFU&&e.localParticipant.updateConnectionState(o.ParticipantConnectionState.Connected,e.id);const n=t.mediaFlow||o.MediaFlow.P2P;e.setSessionId(t.sessionId),e.changeMediaFlow(n),e.localParticipant.updateState(o.ParticipantState.Joined,e.id),e.setState(o.CallState.Connected,i)?(e.emitParticipantStateChanged(e.localParticipant,o.ParticipantState.Joined),e.emitParticipantConnectionStateChanged(e.localParticipant,o.ParticipantConnectionState.Connected),this.processJoinAcknowledgment(e,t,n)):this.leaveCall(e,!0,"processJoinCall")}startCall(e,t,i,a){var l;const r=t.mediaFlow,s=e.participants.filter((e=>!(e.id===this.user.id&&e.clientId===this.clientId))).map((e=>e.serialize()));e.mediaFlow!==o.MediaFlow.SFU&&e.localParticipant.updateConnectionState(o.ParticipantConnectionState.Connecting,e.id);const c="true"===(null===(l=e.metadata)||void 0===l?void 0:l.videoCall),d=(t,l)=>{if(e.state==o.CallState.Idle)return t.forEach((e=>{e.stop()})),void(null==a||a({error:(0,h.checkCode)(5002,"Call was ended before media setup completed")}));e.emitAudioTrackAdded(e.localParticipant,t[0]),c&&l&&l.length>0&&(e.emitVideoTrackAdded(e.localParticipant,l[0]),e.localParticipant.setVideoTracks(l),e.localVideoTracks=l,e.setVideoDeviceId(l[0].getSettings().deviceId||null)),e.localParticipant.setAudioTracks(t),e.localAudioTracks=t,this.joinToCall({mediaFlow:r,callId:e.id,sessionId:e.sessionId,participants:i?[]:s,metadata:e.metadata},(t=>n(this,void 0,void 0,(function*(){var i;return t instanceof p.SceytCallException||t instanceof Error?(S.error(`[2137] [CallId: ${e.id}] SYNC JOIN failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`),e.setState(o.CallState.Closed,"joinCall failed"),void(null==a||a({error:(0,h.toCallException)(t)}))):t.event===o.SignalEvent.ERROR?(S.error(`[2141] [CallId: ${e.id}] SYNC JOIN failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`),void(null==a||a({error:(0,h.checkCode)(5003,(null===(i=t.error)||void 0===i?void 0:i.message)||"Unknown error")}))):void this.processJoinCall(e,t,"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})=>{d(e,t.localVideoTracks||[])})):!e.localAudioTracks||e.localVideoTracks&&e.localVideoTracks.length>0?d(e.localAudioTracks||[],e.localVideoTracks||[]):d(t.localAudioTracks||[]):this.setupMediaStream(e).then((({audioTracks:e})=>{d(e)})),e}joinCall(e,t){let i=null;try{S.info("[2159] [CallId: GLOBAL_LOGS] joinCall, start new call",{color:"blue"});const{call:n,answer:a}=this.findOrCreateCall(e);return n.setState(o.CallState.Connecting,"joinCall")?(n.localParticipant.state=o.ParticipantState.Joined,n.localParticipant.clientId=this.clientId,i=this.startCall(n,e,a,t),{success:!0,data:n}):{success:!1,error:(0,h.checkCode)(5001,`Failed to set call state from ${n.state} to connecting`)}}catch(e){return S.error(`[2173] [CallId: ${null==i?void 0:i.id}] Join call failed: ${e.message||JSON.stringify(e)}`,{color:"red"}),{success:!1,error:(0,h.toCallException)(e)}}}updateCallMetadata(e,t){e.metadata=t.metadata||0,e.createdBy=t.createdBy,e.sessionId=t.sessionId,e.id=t.id,S.info(`[2187] [CallId: ${e.id}] Updated call metadata for call ${e.id}`,{color:"light-blue"})}syncParticipants(e,t){S.info(`[2198] [CallId: ${e.id}] Syncing participants for call ${e.id}`,{color:"light-blue"}),e.participants=e.participants.filter((i=>{const n=t.find((e=>!(e.id!==i.id||e.clientId!==i.clientId&&e.clientId&&i.clientId)));return n||(S.info(`[2202] [CallId: ${e.id}] Removing participant ${i.id} who is no longer in the call`,{color:"light-blue"}),e.emitParticipantStateChanged(i,o.ParticipantState.Left),e.kickParticipantFromList(i)),!!n})),S.info(`[2216] [CallId: ${e.id}] Syncing participants for call ${e.id}`,{color:"light-blue"});for(const i of t){const t=e.participants.find((e=>!(e.id!==i.id||e.clientId!==i.clientId&&i.clientId&&e.clientId)));if(S.info(`[2219] [CallId: ${e.id}] Syncing participants for call ${e.id}`,{color:"light-blue"}),t){if(t.clientId||(t.clientId=i.clientId),t.id===e.localParticipant.id&&t.clientId===e.localParticipant.clientId){i.state===o.ParticipantState.Joined&&e.localParticipant.state>o.ParticipantState.Joined&&this.leaveCall(e,!0,"syncParticipants");continue}t.state=i.state,e.emitParticipantStateChanged(t,i.state),t.state!==o.ParticipantState.Joined?t.getFullId()!==e.localParticipant.getFullId()&&(this.closePeerConnections(e.id,t.getFullId()),e.activeSpeakerManager.removeParticipant(t)):t.id!==e.localParticipant.id&&t.clientId!==e.localParticipant.clientId&&e.state===o.CallState.Connected&&this.handleNewParticipant(e,t),t.getFullId()===e.localParticipant.getFullId()&&(e.localParticipant=t),this.syncParticipantMediaState(e,t,i),S.info(`[2254] [CallId: ${e.id}] Syncing existing participants: ${t.getFullId()} for call ${e.id}`,{color:"light-blue"})}else{const t=new a.Participant(i.id,i.clientId);t.state=i.state,e.addParticipantToList(t),this.syncParticipantMediaState(e,t,i),S.info(`[2263] [CallId: ${e.id}] Syncing no existing participants: ${t.getFullId()} for call ${e.id}`,{color:"light-blue"}),e.emitParticipantsAdded([t],o.ParticipantEntryType.ADDED),(e.mediaFlow!==o.MediaFlow.SFU&&i.state===o.ParticipantState.Joined||e.mediaFlow===o.MediaFlow.SFU&&i.connectionState===o.MediaConnectionState.Connected&&e.state===o.CallState.Connected)&&this.handleNewParticipant(e,t)}}}syncParticipantMediaState(e,t,i){if(t.getFullId()===i.id+(i.clientId?"/"+i.clientId:"")){const n=!!i.hasOwnProperty("muted")&&i.muted,a=!!i.hasOwnProperty("screenSharing")&&i.screenSharing,l=!!i.hasOwnProperty("videoEnabled")&&i.videoEnabled,r=!!i.hasOwnProperty("onHold")&&i.onHold,o=!!i.hasOwnProperty("isCallSilenced")&&i.isCallSilenced;n!==t.muted&&(S.info(`[2287] [CallId: ${e.id}] Participant ${t.getFullId()} audio state changed: ${t.muted} -> ${n}`,{color:"light-blue"}),t.setMuted(n),n?e.emitParticipantEvent(t,"Mute"):e.emitParticipantEvent(t,"Unmute")),l===t.videoEnabled||a||(S.info(`[2296] [CallId: ${e.id}] Participant ${t.getFullId()} video state changed: ${t.videoEnabled} -> ${l}`,{color:"light-blue"}),t.setVideoEnabled(l),l?e.emitParticipantEvent(t,"VideoEnabled"):e.emitParticipantEvent(t,"VideoDisabled")),a!==t.screenSharing&&(S.info(`[2307] [CallId: ${e.id}] Participant ${t.getFullId()} screen sharing state changed: ${t.screenSharing} -> ${a}`,{color:"light-blue"}),t.setScreenSharing(a),a?e.emitParticipantEvent(t,"ScreenSharingStarted"):e.emitParticipantEvent(t,"ScreenSharingStopped")),r!==t.onHold&&(S.info(`[2317] [CallId: ${e.id}] Participant ${t.getFullId()} hold state changed: ${t.onHold} -> ${r}`,{color:"light-blue"}),t.setHold(r),r?e.emitParticipantEvent(t,"Hold"):e.emitParticipantEvent(t,"Unhold")),o!==!!t.isCallSilenced&&t.getFullId()===e.localParticipant.getFullId()&&(S.info(`[2327] [CallId: ${e.id}] Participant ${t.getFullId()} ring allowed state changed: ${t.isCallSilenced} -> ${o}`,{color:"light-blue"}),e.setIsCallSilenced(o))}}handleNewParticipant(e,t){if(S.info(`[2333] [CallId: ${e.id}] Call media flow: ${e.mediaFlow}`,{color:"light-blue"}),e.mediaFlow!==o.MediaFlow.SFU){if(t.updateState(o.ParticipantState.Joined,e.id),e.emitParticipantStateChanged(t,o.ParticipantState.Joined),t.getFullId()!==e.localParticipant.getFullId()&&t.connectionState!==o.ParticipantConnectionState.Connected&&t.connectionState!==o.ParticipantConnectionState.Reconnecting){const i=t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[2341] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`,{color:"red"}):t.event!==o.SignalEvent.ERROR||S.error(`[2345] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"})};S.info(`[2370] [CallId: ${e.id}] Sending offer to participant: ${t.getFullId()}`),e.mediaFlow===o.MediaFlow.P2P&&this.isPolitePeer(t.getFullId(),e.localParticipant.getFullId())?this.sendOfferPeerToPeer(e,t,i):(this.signalingClient.clearParticipantSignals(e.id,t.getFullId()),this.signalingClient.sendSignalMessage({to:t.getFullId(),mediaFlow:e.mediaFlow,callId:e.id,event:o.SignalEvent.CONNECT,sessionId:e.sessionId},i))}}else if(t.getFullId()!==e.localParticipant.getFullId()&&t.connectionState!==o.ParticipantConnectionState.Reconnecting){const i=t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[2354] [CallId: ${e.id}] SYNC CONNECT signal sent failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`,{color:"red"}):t.event!==o.SignalEvent.ERROR||S.error(`[2358] [CallId: ${e.id}] SYNC CONNECT signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"})};this.signalingClient.clearParticipantSignals(e.id,t.getFullId()),this.signalingClient.sendSignalMessage({to:t.getFullId(),mediaFlow:e.mediaFlow,callId:e.id,event:o.SignalEvent.CONNECT,sessionId:e.sessionId},i)}}handleConnectSignal(e){if(!this.activeCalls)return;const t=this.activeCalls.find((t=>t.id===e.callId));if(t){let i=t.participants.find((t=>t.getFullId()===e.from));i&&this.sendOfferPeerToPeer(t,i,(e=>{e instanceof p.SceytCallException||e instanceof Error?S.error(`[2417] [CallId: ${t.id}] SYNC OFFER signal sent failed message: ${e.message} code: ${e instanceof p.SceytCallException?e.code:""}`,{color:"red"}):e.event!==o.SignalEvent.ERROR||S.error(`[2421] [CallId: ${t.id}] SYNC OFFER signal sent failed message: ${e.error?`${e.error.message} code: ${e.error.code}`:""}`,{color:"red"})}))}}handleMediaFlowSwitch(e){S.info(`[2375] [CallId: ${e.id}] Switching call ${e.id} from P2P to SFU`,{color:"light-blue"}),e.changeMediaFlow(o.MediaFlow.SFU);const t=new a.Participant(e.id);e.setServerParticipant(t),S.info(`[2395] [CallId: ${e.id}] Sending offer to server participant: ${t.getFullId()}`),this.sendOfferPeerToPeer(e,t,(t=>{t instanceof p.SceytCallException||t instanceof Error?S.error(`[2386] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.message} code: ${t instanceof p.SceytCallException?t.code:""}`,{color:"red"}):t.event!==o.SignalEvent.ERROR||S.error(`[2390] [CallId: ${e.id}] SYNC OFFER signal sent failed message: ${t.error?`${t.error.message} code: ${t.error.code}`:""}`,{color:"red"})})),e.participants.forEach((e=>{e.setShouldResetPeerConnection(!0)}))}}t.InternalCallHandler=C},787:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Participant=void 0;const n=i(578),a=i(758),l=i(645),r=(0,l.createLogger)("ParticipantState"),o=(0,l.createLogger)("ConnectionState");t.Participant=class{constructor(e,t){this.clientId="",this.muted=!1,this.onHold=!1,this.videoEnabled=!1,this.screenSharing=!1,this.presenter=!1,this.audioTracks=[],this.videoTracks=[],this.shouldResetPeerConnection=!1,this.state=n.ParticipantState.Idle,this.connectionState=n.ParticipantConnectionState.Idle;const i=e.split("/");this.id=i[0],this.clientId=t||i[1]||""}updateState(e,t){const i=new a.ParticipantStateMachine(this.id,t).updateState(e,this.state);return i&&(this.state=e,r.info(`[35] [CallId: ${t}] Updating state: ${e}, participantID: ${this.getFullId()}`,{color:"blue"})),i}updateConnectionState(e,t){const i=new a.ParticipantStateMachine(this.id,t).updateConnectionState(e,this.connectionState);return i&&(this.connectionState=e,o.info(`[45] [CallId: ${t}] Updating connection state: ${e}, participantID: ${this.getFullId()}`,{color:"blue"})),i}setShouldResetPeerConnection(e){this.shouldResetPeerConnection=e}setMuted(e){this.audioTracks.forEach((t=>{t.enabled=!e})),this.muted=e}setVideoEnabled(e){this.videoTracks.forEach((t=>{t.enabled=e})),this.videoEnabled=e}setScreenSharing(e){this.videoTracks.forEach((t=>{t.enabled=e})),this.screenSharing=e}setPresenter(e){this.presenter=e}setAudioTracks(e){this.audioTracks=e}setVideoTracks(e){this.videoTracks=e}setHold(e){this.onHold=e}serialize(){return{id:this.id,clientId:this.clientId}}getFullId(){return this.id+(this.clientId?"/"+this.clientId:"")}}},816:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.QueryBuilder=void 0,t.QueryBuilder=class{constructor(){this.count=10}}},185:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RecentCallQueryBuilder=void 0;const n=i(578),a=i(650),l=i(816),r=i(343),o=i(228);class s 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.build=()=>{const e=a.InternalCallHandler.getInstance();this.chatClient=e.chatClient;try{return new r.RecentCallQuery(this)}catch(e){throw(0,o.toCallException)(e)}}}}t.RecentCallQueryBuilder=s},343:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{s(n.next(e))}catch(e){l(e)}}function o(e){try{s(n.throw(e))}catch(e){l(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}s((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.RecentCallQuery=void 0;const a=i(578),l=i(645),r=i(228),o=(0,l.createLogger)("RecentCallQuery");t.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,r.checkCode)(5001,"QUERY_IN_PROGRESS");if(this.hasNext){this.loading=!0;const e=yield this.chatClient.sendCallDetailsRecord(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}:{})}:{}));this.loading=!1;const{getRecentCallsResponse:{records:t,nextToken:i}}=e;return this.hasNext=!!i,this.nextToken=i,{records:t,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}set limit(e){this.count=e}get limit(){return this.count}}},680:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.toSessionDescription=t.toSessionData=void 0;const n=i(578),a=i(645),l=i(19),r=(0,a.createLogger)("SignalingExtensions");t.toSessionData=function(e,t){const i=e.sdp.sdp||"",a=1e3*Date.now()+performance.now()%1*1e3;r.info(`[32] [CALL_TIME_TO_SESSION_DATA_START: ${a}]`,{color:"blue"});const o=l.SdpConverter.parseToSdpData(i,l.CODEC_NAME_TO_VIDEO_CODEC,t===n.MediaFlow.S2W?l.CODEC_NAME_TO_AUDIO_CODEC_S2W:l.CODEC_NAME_TO_AUDIO_CODEC),s=1e3*Date.now()+performance.now()%1*1e3;return r.info(`[35] [CALL_TIME_TO_SESSION_DATA_END: ${s}]`,{color:"blue"}),r.info(`[34] [CallId: ${e.sessionId}] toSessionData in sdp-converter: sdpData: ${JSON.stringify(o||{})}, type: ${e.sdp.type}, sessionId: ${e.sessionId}, versionId: ${e.versionId}`,{color:"blue"}),{id:e.sessionId,version:e.versionId,sdpData:o}},t.toSessionDescription=function(e,t){if(r.info(`[50] [CallId: ${e.id}] toSessionDescription in sdp-converter: sessionData: ${JSON.stringify((null==e?void 0:e.sdpData)||{})}, type: ${t}, id: ${e.id}, version: ${e.version}`,{color:"blue"}),e.sdpData){const i=l.SdpConverter.reconstructFromSDPData(e.sdpData);return r.info(`[53] [CallId: ${e.id}] toSessionDescription in sdp-converter: sdp: ${i}`,{color:"blue"}),{type:t,sdp:i}}return r.error("SessionData has neither sdpData nor sdp field"),null}},19:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdpConverter=t.CODEC_NAME_TO_AUDIO_CODEC_S2W=t.CODEC_NAME_TO_AUDIO_CODEC=t.CODEC_NAME_TO_VIDEO_CODEC=void 0;const n=i(645),a=i(228),l=i(799),r=(0,n.createLogger)("SdpConverter");t.CODEC_NAME_TO_VIDEO_CODEC=["vp8","rtx","red"],t.CODEC_NAME_TO_AUDIO_CODEC=["opus","red"],t.CODEC_NAME_TO_AUDIO_CODEC_S2W=["opus","red","pcmu","pcma"];class o{static parseToSdpData(e,i=t.CODEC_NAME_TO_VIDEO_CODEC,n=t.CODEC_NAME_TO_AUDIO_CODEC){var a,l,r;const s=[],c=e.split("\n").map((e=>e.trim())).filter((e=>e.length>0)),d=o.extractSessionId(c)||"",u=o.extractSessionVersion(c)||0,p=o.extractOriginAddress(c)||"127.0.0.1",g=(null===(a=c.find((e=>e.startsWith("s="))))||void 0===a?void 0:a.substring(2))||"-",h=(null===(l=c.find(((e,t)=>e.startsWith("c=")&&!o.inMediaSection(c,t))))||void 0===l?void 0:l.split(" ").slice(2)[0])||"",S=(null===(r=o.firstValueStartingWith(c,"a=msid-semantic:"))||void 0===r?void 0:r.trim())||"WMS",C=o.parseBundleGroup(c),v=c.findIndex((e=>e.startsWith("m="))),f=v>0?c.slice(0,v):c,I=o.firstValueStartingWith(f,"a=ice-ufrag:")||"",E=o.firstValueStartingWith(f,"a=ice-pwd:")||"",m=o.parseIceOptions(f),P=o.parseFingerprint(f),$=o.parseSetup(f),T=f.some((e=>"a=ice-lite"===e)),y=f.some((e=>"a=extmap-allow-mixed"===e));return{sessionId:d,sessionVersion:u,bundleGroup:C,iceUfrag:I,icePwd:E,iceOptions:m,fingerprint:P,setup:$,media:o.parseMediaSections(c,s,i,n),sessionName:g,originAddress:p,connectionAddress:h,msidSemantic:S,iceLite:T,extmapAllowMixed:y,stringPool:s}}static reconstructFromSDPData(e){var t,i,n,l,s,c;try{const d=[];if(d.push("v=0\r\n"),d.push(`o=- ${e.sessionId} ${e.sessionVersion} IN IP4 ${e.originAddress}\r\n`),d.push(`s=${e.sessionName}\r\n`),d.push("t=0 0\r\n"),(null===(i=null===(t=e.fingerprint)||void 0===t?void 0:t.hashValue)||void 0===i?void 0:i.length)>0&&d.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 t=e.media.map((e=>e.mid)).join(" ");d.push(`a=group:BUNDLE ${t}\r\n`)}(null===(l=null==e?void 0:e.iceOptions)||void 0===l?void 0:l.length)>0&&d.push(`a=ice-options:${e.iceOptions.join(" ")}\r\n`),(null==e?void 0:e.extmapAllowMixed)&&d.push("a=extmap-allow-mixed\r\n"),(null===(s=null==e?void 0:e.msidSemantic)||void 0===s?void 0:s.length)>0&&d.push(`a=msid-semantic: ${e.msidSemantic}\r\n`),(null==e?void 0:e.iceLite)&&d.push("a=ice-lite\r\n"),null===(c=null==e?void 0:e.media)||void 0===c||c.forEach((t=>{o.buildMediaSection(d,t,e)}));const u=d.join("");if(r.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 r.error(`[647] [CallId: GLOBAL_LOGS] Failed to reconstruct SDP: ${e.message}`,{color:"red"}),r.error(e,{color:"red"}),(0,a.toCallException)(e)}}static extractSessionId(e){const t=e.find((e=>e.startsWith("o=")));return t&&t.split(" ")[1]||null}static extractSessionVersion(e){const t=e.find((e=>e.startsWith("o=")));if(!t)return null;const i=t.split(" "),n=parseInt(i[2]||"0",10);return isNaN(n)?null:n}static extractOriginAddress(e){const t=e.find((e=>e.startsWith("o=")));return t&&t.split(" ")[5]||null}static parseBundleGroup(e){const t=e.find((e=>e.startsWith("a=group:BUNDLE ")));return t?t.substring(15).split(" ").map((e=>parseInt(e,10))).filter((e=>!isNaN(e))):[]}static parseIceOptions(e){const t=e.find((e=>e.startsWith("a=ice-options:")));return t?t.substring(14).split(" "):[]}static parseFingerprint(e){var t;const i=e.find((e=>e.startsWith("a=fingerprint:")));if(i){const e=i.substring(14).split(" ",2);if(2===e.length){let i;switch(e[0].toLowerCase()){case"sha-256":default:i=l.HashFunction.SHA256;break;case"sha-1":i=l.HashFunction.SHA1;break;case"sha-384":i=l.HashFunction.SHA384;break;case"sha-512":i=l.HashFunction.SHA512;break;case"md5":i=l.HashFunction.MD5}const n=e[1].replace(/:/g,"");return{hashFunc:i,hashValue:new Uint8Array((null===(t=n.match(/.{1,2}/g))||void 0===t?void 0:t.map((e=>parseInt(e,16))))||[])}}}return{hashFunc:l.HashFunction.SHA256,hashValue:new Uint8Array(0)}}static parseSetup(e){const t=e.find((e=>e.startsWith("a=setup:")));switch(null==t?void 0:t.substring(8).toLowerCase()){case"active":return l.DTLSSetup.ACTIVE;case"passive":return l.DTLSSetup.PASSIVE;default:return l.DTLSSetup.ACTPASS}}static firstValueStartingWith(e,t){const i=e.find((e=>e.startsWith(t)));return i?i.substring(t.length):null}static inMediaSection(e,t){return e.map(((e,t)=>({line:e,index:t}))).filter((({line:e})=>e.startsWith("m="))).map((({index:e})=>e)).some((e=>e<t))}static parseMediaSections(e,t,i,n){const a=e.map(((e,t)=>({line:e,index:t}))).filter((({line:e})=>e.startsWith("m="))).map((({index:e})=>e));return a.map(((l,r)=>{const s=r<a.length-1?a[r+1]:e.length;return o.parseMediaSection(e.slice(l,s),t,i,n)})).filter((e=>null!==e))}static parseMediaSection(e,t,i,n){var a;try{const i=e[0].substring(2).split(" ");let n;switch(i[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 r.warn(`Skipping unknown media type: ${i[0]}`),null;const s=parseInt(i[1]||"9",10)||9,c=i.slice(3).map((e=>parseInt(e,10))).filter((e=>!isNaN(e))),d=o.firstValueStartingWith(e,"a=mid:")||"",u=o.parseDirection(e),p=o.firstValueStartingWith(e,"a=msid:"),[g,h,S]=o.parseMSID(p||null),C=e.some((e=>"a=rtcp-mux"===e)),v=e.some((e=>"a=rtcp-rsize"===e)),f=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])||"",E=o.firstValueStartingWith(e,"a=rtcp:")||"",m=new Map,P=[];c.forEach((e=>{m.set(e,{codecName:{id:e,mapKey:0},fmtp:[],rtcpFeedbackIds:[]}),P.push(e)})),e.filter((e=>e.startsWith("a=rtpmap:"))).forEach((e=>{const t=e.substring(9).split(" ",2);if(2===t.length){const e=parseInt(t[0],10);if(!isNaN(e)){const i=t[1];o.dynamicCodecNames.set(e,i);const n=o.CODEC_NAME_TO_MAP_KEY.get(i)||0;if(m.has(e)){const t=m.get(e);m.set(e,{codecName:{id:e,mapKey:n},fmtp:t.fmtp,rtcpFeedbackIds:t.rtcpFeedbackIds})}}}})),e.filter((e=>e.startsWith("a=fmtp:"))).forEach((e=>{const t=e.substring(7).split(" ",2);if(2===t.length){const e=parseInt(t[0],10);if(!isNaN(e)&&m.has(e)){const i=o.parseFmtp(t[1]),n=m.get(e);m.set(e,{codecName:n.codecName,fmtp:i,rtcpFeedbackIds:n.rtcpFeedbackIds})}}})),e.filter((e=>e.startsWith("a=rtcp-fb:"))).forEach((e=>{const t=e.substring(10).split(" ");if(t.length>=2){const e=parseInt(t[0],10);if(!isNaN(e)){let i="";for(let e=1;e<t.length;e++)i+=t[e]+(e!==t.length-1?" ":"");const n=o.RTCP_FEEDBACK_STRING_TO_ID.get(i);if(void 0!==n&&m.has(e)){const t=m.get(e),i=[...t.rtcpFeedbackIds];i.includes(n)||i.push(n),m.set(e,{codecName:t.codecName,fmtp:t.fmtp,rtcpFeedbackIds:i})}}}}));const $=P.map((e=>m.get(e))).filter((e=>void 0!==e)),T=o.parseExtmaps(e),y=o.parseSsrcs(e),O=o.parseSsrcGroups(e),F=o.parseCandidates(e),w=o.firstValueStartingWith(e,"a=ice-ufrag:"),R=o.firstValueStartingWith(e,"a=ice-pwd:"),A=w?o.addToStringPool(t,w):0,b=R?o.addToStringPool(t,R):0,k=e.find((e=>e.startsWith("a=ice-options:"))),N=k?k.substring(14).split(" "):void 0,_=e.find((e=>e.startsWith("a=fingerprint:"))),M=_?o.parseFingerprint([_]):{hashFunc:l.HashFunction.SHA256,hashValue:new Uint8Array(0)},D=e.find((e=>e.startsWith("a=setup:")));return{type:n,mid:d,direction:u,msidStream:g,msidTrackLabel:h,msidTrackId:S,rtcpMux:C,rtcpRsize:v,extmaps:T,codecs:$,ssrcGroups:O,ssrcs:y,connectionAddress:I,candidates:F,endOfCandidates:f,rtcpAddress:E,iceUfragRef:A,icePwdRef:b,iceOptions:N,fingerprint:M,setup:D?o.parseSetup([D]):l.DTLSSetup.ACTPASS,port:s}}catch(e){return r.error(`[647] [CallId: GLOBAL_LOGS] Failed to parse media section: ${e.message}`,{color:"red"}),r.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 t=e.split(" ",2);if(t.length<2)return[e,"",0];const i=t[0],n=t[1],a=n.lastIndexOf("_");if(a>0){const e=n.substring(a+1),t=parseInt(e,10);if(!isNaN(t))return[i,n.substring(0,a+1),t]}return[i,n,0]}static parseFmtp(e){if(0===e.trim().length)return[];const t=[];return e.split(";").forEach((e=>{const i=e.trim();if(0!==i.length)if(i.includes("=")){const e=i.split("=",2);t.push({key:e[0].trim(),value:e[1].trim()})}else t.push({key:"value",value:i})})),t}static parseExtmaps(e){return e.filter((e=>e.startsWith("a=extmap:"))).map((e=>{const t=e.substring(9).split(" ",2);if(2!==t.length)return null;const i=t[0].split("/")[0],n=parseInt(i,10);if(isNaN(n))return null;const a=t[1];return{id:n,mapKey:o.URI_TO_EXTMAP_ID.get(a)||0}})).filter((e=>null!==e))}static parseSsrcs(e){const t=new Map;return e.filter((e=>e.startsWith("a=ssrc:"))).forEach((e=>{const i=e.substring(7).split(" ");if(i.length>=2){const e=parseInt(i[0],10);if(isNaN(e))return;const n=e,a=t.get(n)||{};if(i[1].startsWith("cname:"))a.cname=i[1].substring(6);else if(i[1].startsWith("msid:")){let e="";for(let t=1;t<i.length;t++)e+=i[t].substring(1===t?5:0)+(i.length-1!==t?" ":"");a.msid=e}t.set(n,a)}})),Array.from(t.entries()).map((([e,t])=>({id:e,cname:t.cname||"",msid:t.msid||""})))}static parseSsrcGroups(e){return e.filter((e=>e.startsWith("a=ssrc-group:"))).map((e=>{const t=e.substring(13).split(" ");return t.length>=2?{semantics:t[0],ssrcs:t.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 t=e.split(" ");if(t.length<8)return null;const i=parseInt(t[0],10);if(isNaN(i))return null;const n=parseInt(t[1],10);if(isNaN(n))return null;let a;switch(t[2].toLowerCase()){case"udp":default:a=l.IceCandidateProtocol.UDP;break;case"tcp":a=l.IceCandidateProtocol.TCP}const r=parseInt(t[3],10);if(isNaN(r))return null;const o=t[4].split("."),s=new Uint8Array(o.map((e=>parseInt(e,10)))),c=parseInt(t[5],10);if(isNaN(c))return null;let d;switch(t[7].toLowerCase()){case"host":default:d=l.IceCandidateType.HOST;break;case"srflx":d=l.IceCandidateType.SRFLX;break;case"prflx":d=l.IceCandidateType.PRFLX;break;case"relay":d=l.IceCandidateType.RELAY}let u=new Uint8Array(0),p=0,g=l.IceCandidateTcpType.ACTIVE,h=8;for(;h<t.length;){switch(t[h]){case"raddr":if(h+1<t.length){const e=t[++h];u=new Uint8Array(e.split(".").map((e=>parseInt(e,10))))}break;case"rport":h+1<t.length&&(p=parseInt(t[++h],10)||0);break;case"tcptype":if(h+1<t.length)switch(t[++h].toLowerCase()){case"active":default:g=l.IceCandidateTcpType.ACTIVE;break;case"passive":g=l.IceCandidateTcpType.PASSIVE;break;case"so":g=l.IceCandidateTcpType.SO}}h++}return{foundation:i,component:n,protocol:a,priority:r,ip:s,port:c,type:d,raddr:u,rport:p,tcptype:g}}static addToStringPool(e,t){if(0===t.length)return 0;const i=e.indexOf(t);return i>=0?i+1:(e.push(t),e.length)}static getFromStringPool(e,t){return 0===t||t>e.length?"":e[t-1]}static getCodecID(e){var t;return(null===(t=e.codecName)||void 0===t?void 0:t.id)||0}static getCodecName(e){if(!e.codecName)return null;const t=e.codecName;if(t.mapKey>0){const e=o.MAP_KEY_TO_CODEC_NAME.get(t.mapKey);if(e)return e}return o.dynamicCodecNames.get(t.id)||null}static filterVideoCodecs(e,t){if(0===t.length)return e;const i=[],n=new Set;return e.forEach((e=>{const a=o.getCodecName(e);if(!a)return;const l=a.split("/")[0];t.some((e=>e.toLowerCase()===l.toLowerCase()))&&(i.push(e),n.add(o.getCodecID(e)))})),e.forEach((e=>{const t=o.getCodecName(e);if(t&&t.toLowerCase().startsWith("rtx/")){const t=e.fmtp.find((e=>"apt"===e.key)),a=t?parseInt(t.value,10):null;null!==a&&!isNaN(a)&&n.has(a)&&i.push(e)}})),i}static buildMediaSection(e,t,i){var n,a,s,c,d,u,p,g,h,S;let C;switch(t.type){case l.MediaType.AUDIO:C="audio";break;case l.MediaType.VIDEO:C="video";break;case l.MediaType.MEDIA_TYPE_UNSPECIFIED:return void r.error("Cannot reconstruct MEDIA_TYPE_UNSPECIFIED")}const v=(null===(n=null==t?void 0:t.codecs)||void 0===n?void 0:n.map((e=>o.getCodecID(e).toString())).join(" "))||"";e.push(`m=${C} ${t.port} UDP/TLS/RTP/SAVPF ${v}\r\n`);const f=(null==t?void 0:t.connectionAddress)||(null==i?void 0:i.connectionAddress)||"0.0.0.0";e.push(`c=IN IP4 ${f}\r\n`),(null===(a=null==t?void 0:t.rtcpAddress)||void 0===a?void 0:a.length)>0&&e.push(`a=rtcp:${t.rtcpAddress}\r\n`);const I=(null==t?void 0:t.iceUfragRef)>0?o.getFromStringPool(null==i?void 0:i.stringPool,null==t?void 0:t.iceUfragRef):null==i?void 0:i.iceUfrag,E=(null==t?void 0:t.icePwdRef)>0?o.getFromStringPool(null==i?void 0:i.stringPool,null==t?void 0:t.icePwdRef):null==i?void 0:i.icePwd;I.length>0&&e.push(`a=ice-ufrag:${I}\r\n`),E.length>0&&e.push(`a=ice-pwd:${E}\r\n`);const m=(null==t?void 0:t.iceOptions)||(null==i?void 0:i.iceOptions);m.length>0&&e.push(`a=ice-options:${m.join(" ")}\r\n`);const P=(null===(c=null===(s=null==t?void 0:t.fingerprint)||void 0===s?void 0:s.hashValue)||void 0===c?void 0:c.length)>0?null==t?void 0:t.fingerprint:null==i?void 0:i.fingerprint;(null===(d=null==P?void 0:P.hashValue)||void 0===d?void 0:d.length)>0&&e.push(`a=fingerprint:${o.fingerprintToString(P)}\r\n`);const $=(null==t?void 0:t.setup)!==l.DTLSSetup.ACTPASS||(null==i?void 0:i.setup)===l.DTLSSetup.ACTPASS?t.setup:i.setup;e.push(`a=setup:${o.setupToString($)}\r\n`),e.push(`a=mid:${null==t?void 0:t.mid}\r\n`),null===(u=null==t?void 0:t.extmaps)||void 0===u||u.forEach((t=>{const i=o.EXTMAP_ID_TO_URI.get(t.mapKey)||`urn:ietf:params:rtp-hdrext:extension-${t.id}`;e.push(`a=extmap:${t.id} ${i}\r\n`)})),e.push(`a=${o.directionToString(null==t?void 0:t.direction)}\r\n`);const T=o.reconstructMSID(null==t?void 0:t.msidStream,null==t?void 0:t.msidTrackLabel,null==t?void 0:t.msidTrackId);(null==T?void 0:T.length)>0&&e.push(`a=msid:${T}\r\n`),(null==t?void 0:t.rtcpMux)&&e.push("a=rtcp-mux\r\n"),(null==t?void 0:t.rtcpRsize)&&e.push("a=rtcp-rsize\r\n"),null===(p=null==t?void 0:t.codecs)||void 0===p||p.forEach((t=>{var i,n;const a=o.getCodecID(t),l=o.getCodecName(t);if(l&&e.push(`a=rtpmap:${a} ${l}\r\n`),null===(i=null==t?void 0:t.rtcpFeedbackIds)||void 0===i||i.forEach((t=>{const i=o.RTCP_FEEDBACK_ID_TO_STRING.get(t);i&&e.push(`a=rtcp-fb:${a} ${i}\r\n`)})),(null===(n=null==t?void 0:t.fmtp)||void 0===n?void 0:n.length)>0){const i=o.reconstructFmtp(t.fmtp);e.push(`a=fmtp:${a} ${i}\r\n`)}})),null===(g=null==t?void 0:t.ssrcGroups)||void 0===g||g.forEach((t=>{const i=t.ssrcs.map((e=>(e>>>0).toString())).join(" ");e.push(`a=ssrc-group:${t.semantics} ${i}\r\n`)})),null===(h=null==t?void 0:t.ssrcs)||void 0===h||h.forEach((t=>{var i,n;const a=(t.id>>>0).toString();(null===(i=null==t?void 0:t.cname)||void 0===i?void 0:i.length)>0&&e.push(`a=ssrc:${a} cname:${t.cname}\r\n`),(null===(n=null==t?void 0:t.msid)||void 0===n?void 0:n.length)>0&&e.push(`a=ssrc:${a} msid:${t.msid}\r\n`)})),null===(S=null==t?void 0:t.candidates)||void 0===S||S.forEach((t=>{e.push(`a=candidate:${o.reconstructCandidate(t)}\r\n`)})),(null==t?void 0:t.endOfCandidates)&&e.push("a=end-of-candidates\r\n")}static reconstructMSID(e,t,i){return 0===e.length?"":0===t.length&&0===i?e:i>0&&t.length>0?`${e} ${t}${i}`:t.length>0?`${e} ${t}`:e}static reconstructFmtp(e){return e.map((e=>"value"===e.key?e.value:`${e.key}=${e.value}`)).join(";")}static fingerprintToString(e){let t;switch(e.hashFunc){case l.HashFunction.SHA256:t="sha-256";break;case l.HashFunction.SHA1:t="sha-1";break;case l.HashFunction.SHA384:t="sha-384";break;case l.HashFunction.SHA512:t="sha-512";break;case l.HashFunction.MD5:t="md5"}return`${t} ${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 t=e.protocol===l.IceCandidateProtocol.UDP?"udp":"tcp";let i;switch(e.type){case l.IceCandidateType.HOST:i="host";break;case l.IceCandidateType.SRFLX:i="srflx";break;case l.IceCandidateType.PRFLX:i="prflx";break;case l.IceCandidateType.RELAY:i="relay"}const n=[e.foundation.toString(),e.component.toString(),t,e.priority.toString(),Array.from(e.ip).map((e=>(255&e).toString())).join("."),e.port.toString(),"typ",i];if(e.raddr.length>0){n.push("raddr");const t=Array.from(e.raddr).map((e=>(255&e).toString())).join(".");n.push(t)}if(e.rport>0&&(n.push("rport"),n.push(e.rport.toString())),"tcp"===t){let t;switch(e.tcptype){case l.IceCandidateTcpType.ACTIVE:t="active";break;case l.IceCandidateTcpType.PASSIVE:t="passive";break;case l.IceCandidateTcpType.SO:t="so"}n.push("tcptype"),n.push(t)}return n.join(" ")}}t.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,t])=>[t,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,t])=>[t,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,t)=>{var i,n,a,l,r,o,s;Object.defineProperty(t,"__esModule",{value:!0}),t.IceCandidateTcpType=t.IceCandidateType=t.IceCandidateProtocol=t.MediaDirection=t.MediaType=t.DTLSSetup=t.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"}(i||(t.HashFunction=i={})),function(e){e[e.ACTIVE=0]="ACTIVE",e[e.PASSIVE=1]="PASSIVE",e[e.ACTPASS=2]="ACTPASS"}(n||(t.DTLSSetup=n={})),function(e){e[e.AUDIO=0]="AUDIO",e[e.VIDEO=1]="VIDEO",e[e.MEDIA_TYPE_UNSPECIFIED=2]="MEDIA_TYPE_UNSPECIFIED"}(a||(t.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||(t.MediaDirection=l={})),function(e){e[e.UDP=0]="UDP",e[e.TCP=1]="TCP"}(r||(t.IceCandidateProtocol=r={})),function(e){e[e.HOST=0]="HOST",e[e.SRFLX=1]="SRFLX",e[e.PRFLX=2]="PRFLX",e[e.RELAY=3]="RELAY"}(o||(t.IceCandidateType=o={})),function(e){e[e.ACTIVE=0]="ACTIVE",e[e.PASSIVE=1]="PASSIVE",e[e.SO=2]="SO"}(s||(t.IceCandidateTcpType=s={}))},828:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.QueuedSignal=void 0;const n=i(795),a=i(429);class l{constructor(e,t,i=n.SignalQueueStrategy.getSignalPriority(e),l=Date.now(),r=0,o=(0,a.v4)()){this.signal=e,this.callback=t,this.priority=i,this.timestamp=l,this.requeueCount=r,this.uniqueKey=o}get callId(){return this.signal.callId}compareTo(e){const t=e.priority-this.priority;return 0!==t?t:this.timestamp-e.timestamp}equals(e){return e instanceof l&&e.signal===this.signal}toString(){return`QueuedSignal(signal=${JSON.stringify(this.signal)}, timestamp=${this.timestamp}, priority=${this.priority}, requeueCount=${this.requeueCount}, uniqueKey=${this.uniqueKey})`}}t.QueuedSignal=l},795:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SignalQueueStrategy=t.SignalProcessingStrategy=void 0;const n=i(578),a=i(586),l=i(228);var r;!function(e){e[e.SEQUENTIAL=0]="SEQUENTIAL",e[e.IMMEDIATE=1]="IMMEDIATE"}(r||(t.SignalProcessingStrategy=r={}));class o{static getProcessingStrategy(e){return this.SEQUENTIAL_SIGNALS.has(e)?r.SEQUENTIAL:r.IMMEDIATE}static isSequentialSignal(e){return this.getProcessingStrategy(e)===r.SEQUENTIAL}static isImmediateSignal(e){return this.getProcessingStrategy(e)===r.IMMEDIATE}static getSignalPriorityValue(e,t){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: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,e)}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}}}t.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,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{s(n.next(e))}catch(e){l(e)}}function o(e){try{s(n.throw(e))}catch(e){l(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}s((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.SignalingQueue=t.SignalLevel=void 0;const a=i(795),l=(0,i(645).createLogger)("SignalingQueue");var r;!function(e){e[e.GlobalBlocking=0]="GlobalBlocking",e[e.ParticipantLevel=1]="ParticipantLevel",e[e.Immediate=2]="Immediate"}(r||(t.SignalLevel=r={})),t.SignalingQueue=class{constructor(e,t,i){this.id=e,this.isTransportConnected=t,this.sender=i,this.globalBlockingSignals=[],this.immediateSignals=[],this.participantSignals=new Map,this.processingSignalJobs=new Map,this.participantJobs=new Map,this.sentSignals=new Set}getSignalKey(e,t){return`${t}_${e.event}_${e.callId}_${e.sessionId||""}`}addSignalToQueue(e){const t=this.getSignalKey(e.signal,e.uniqueKey);if(this.sentSignals.has(t))return void l.info(`[38] [CallId: ${e.signal.callId}] Signal already sent, skipping: ${e.toString()}`);const i=a.SignalQueueStrategy.getSignalLevel(e.signal);switch(i){case r.GlobalBlocking:this.globalBlockingSignals.push(e);break;case r.ParticipantLevel:const t=e.signal.to||"";this.participantSignals.has(t)||this.participantSignals.set(t,[]),this.participantSignals.get(t).push(e);break;case r.Immediate:this.immediateSignals.push(e)}l.info(`[61] [CallId: ${e.signal.callId}] Add signal to queue ===> level: ${i}, signal: ${JSON.stringify({signal:e.signal,uniqueKey:e.uniqueKey})}`),this.invalidateToSendSignalsIfNeeded()}removeSignalFromQueue(e){const t=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.delete(t)}invalidateToSendSignalsIfNeeded(){this.isTransportConnected()?this.globalBlockingSignals.length>0?this.sendGlobalBlockingSignals():(this.sendParticipantSignals(),this.sendImmediateLevelSignals()):l.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 t=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.has(t)?l.info(`[107] [CallId: ${this.id}] Global blocking signal already sent, skipping: ${e.toString()}`):(l.info(`[111] [CallId: ${this.id}] Sending ${r.GlobalBlocking} level signal: ${e.toString()}`),yield this.sendSignal(e),this.sentSignals.add(t))}}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 t=this.getSignalKey(e.signal,e.uniqueKey);this.sentSignals.has(t)?l.info(`[145] [CallId: ${this.id}] Immediate signal already sent, skipping: ${e.toString()}`):(l.info(`[148] [CallId: ${this.id}] Sending ${r.Immediate} level signal: ${e.toString()}`),yield this.sendSignal(e),this.sentSignals.add(t))}}finally{this.processingSignalJobs.delete(r.Immediate)}}}))}sendParticipantSignals(){if(!(this.globalBlockingSignals.length>0))for(const[e,t]of this.participantSignals.entries())t.length>0&&this.sendParticipantSignal(e,t)}sendParticipantSignal(e,t){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 i=t.shift();if(!i)break;const n=this.getSignalKey(i.signal,i.uniqueKey);this.sentSignals.has(n)?l.info(`[185] [CallId: ${this.id}] Participant signal already sent, skipping: ${i.toString()}`):(l.info(`[188] [CallId: ${this.id}] Sending ${r.ParticipantLevel} level signal for identity ${e}: ${i.toString()}`),yield this.sendSignal(i),this.sentSignals.add(n))}}finally{this.participantJobs.delete(e),0===t.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=>{l.error(`[209] [CallId: ${this.id}] Error sending signal: ${e}`)}))}))}clearParticipantSignals(e){this.participantSignals.delete(e),this.participantJobs.delete(e),l.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(),l.info(`[227] [CallId: ${this.id}] Cleared all signals for queueId: ${this.id}`)}getGlobalBlockingSignals(){return this.globalBlockingSignals}}},786:function(e,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{s(n.next(e))}catch(e){l(e)}}function o(e){try{s(n.throw(e))}catch(e){l(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}s((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.Signaling=void 0;const a=i(578),l=i(645),r=i(828),o=i(586),s=i(228),c=i(65),d=i(429),u=(0,l.createLogger)("Signaling");class p{constructor(e,t){this.signalingQueues=new Map,this.chatClient=e;const i=new this.chatClient.ChannelListener;i.onSignal=e=>{t(e)},this.chatClient.addChannelListener("call_listeners",i)}calculateRetryDelay(e){return Math.min(p.BASE_DELAY_MS*Math.pow(2,e),p.MAX_DELAY_MS)}handleRetry(e,t,i,a){var l;return n(this,void 0,void 0,(function*(){if(t>=p.MAX_RETRIES)throw u.error(`[45] [CallId: ${e.signal.callId}] Max retries exceeded for signal: ${JSON.stringify(e.signal)}`,{color:"red"}),(0,s.toCallException)(i);i instanceof c.SceytCallException&&!i.isResendable&&(u.error(`[49] [CallId: ${e.signal.callId}] Signal sending failed with non-resendable exception: ${i.message}`,{color:"red"}),null===(l=e.callback)||void 0===l||l.call(e,i),a.removeSignalFromQueue(e));const n=this.calculateRetryDelay(t);u.error(`[53] [CallId: ${e.signal.callId}] Sending signal failed with error: ${i.message}, but ChatClient is connected. Retrying in ${n}ms (attempt ${t+1}/${p.MAX_RETRIES})`,{color:"red"}),yield new Promise((e=>setTimeout(e,n)));try{const t=yield this.sendSignalSuspended(e);return u.info(`[64] [CallId: ${e.signal.callId}] Retry sending signal success: ${JSON.stringify(t)}`),t}catch(i){return u.error(`[67] [CallId: ${e.signal.callId}] Retry sending signal failed: ${i instanceof Error?i.message:String(i)}`),this.handleRetry(e,t+1,i instanceof Error?i:new Error(String(i)),a)}}))}sendSignalSuspended(e){return n(this,void 0,void 0,(function*(){try{u.info(`[78] [CallId: ${e.signal.callId}] Sending signal to chat client: version: 132 ${JSON.stringify(e.signal)}`);const t=yield this.chatClient.sendSignal(e.signal,132);if(null==t?void 0:t.error)throw(0,s.toCallException)(t.error);return(0,s.handleAck)(t)}catch(e){throw(0,s.toCallException)(e)}}))}sendSignalMessage(e,t,i){u.info(`[92] [CallId: ${e.callId}] Sending signal message request: ${a.SignalEvent[e.event]} uniqueKey: ${(0,d.v4)()} ${JSON.stringify(e)}`,{color:"yellow"});const l=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}),g=i||e.callId;let h=this.signalingQueues.get(g);h||(h=new o.SignalingQueue(g,(()=>"Connected"===this.chatClient.connectionState),(e=>n(this,void 0,void 0,(function*(){var t,i,n,l,o;try{const l=yield this.sendSignalSuspended(e);if(u.info(`[115] [CallId: ${e.signal.callId||"GLOBAL_LOGS"}] Sent signal message response: ${a.SignalEvent[e.signal.event]} uniqueKey: ${e.uniqueKey} ${JSON.stringify(l)}`,{color:"magenta"}),(null==l?void 0:l.event)===a.SignalEvent.ERROR)throw(0,s.checkCode)((null===(t=null==l?void 0:l.error)||void 0===t?void 0:t.code)||0,(null===(i=null==l?void 0:l.error)||void 0===i?void 0:i.message)||"Unknown error");return null===(n=e.callback)||void 0===n||n.call(e,l),null==h||h.removeSignalFromQueue(e),l}catch(t){if(u.error(`[125] [CallId: ${e.signal.callId||"GLOBAL_LOGS"}] Signal message error: ${a.SignalEvent[e.signal.event]} uniqueKey: ${e.uniqueKey} error: ${t instanceof Error?t.message:String(t)}, resendable: ${t instanceof c.SceytCallException&&t.isResendable}`,{color:"red"}),t instanceof c.SceytCallException&&t.isResendable){const i=e.requeueCount;i<p.REQUEUE_LIMIT?null==h||h.addSignalToQueue(new r.QueuedSignal(e.signal,e.callback,e.priority,e.timestamp,i+1,(0,d.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===(l=e.callback)||void 0===l||l.call(e,t),null==h||h.removeSignalFromQueue(e))}const i=t instanceof c.SceytCallException?t:new Error(t instanceof Error?t.message:String(t));null===(o=e.callback)||void 0===o||o.call(e,i),null==h||h.removeSignalFromQueue(e)}})))),this.signalingQueues.set(g,h)),h.addSignalToQueue(new r.QueuedSignal(l,t,0,0,0,(0,d.v4)()))}clearCallSignals(e){const t=this.signalingQueues.get(e);t&&(t.clearCallSignals(),this.signalingQueues.delete(e))}clearParticipantSignals(e,t){const i=this.signalingQueues.get(e);i&&i.clearParticipantSignals(t)}cancelJoinIfPossible(e){const t=this.signalingQueues.get(e);return!!t&&(!!t.getGlobalBlockingSignals().find((e=>e.signal.event==a.SignalEvent.JOIN))&&(t.clearCallSignals(),!0))}}t.Signaling=p,p.REQUEUE_LIMIT=10,p.MAX_RETRIES=10,p.BASE_DELAY_MS=1e3,p.MAX_DELAY_MS=8e3},342:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ReceiveSignalValidator=void 0;const n=i(578),a=(0,i(645).createLogger)("ReceiveSignalValidator");class l{static canHandleSignal(e,t){const i=l.validateSignal(e,t.state,t.localParticipant);return i||a.warn(`Cannot handle signal ${e.event} in call state ${t.state} with local participant state ${t.localParticipant.state}`),i}static validateSignal(e,t,i){switch(e.event){case n.SignalEvent.JOIN:case n.SignalEvent.LEAVE:return!0;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:return t===n.CallState.Connected;case n.SignalEvent.KICK:return!0;case n.SignalEvent.INVITE:return!e.participants||!e.participants.some((e=>e.id===i.id))||t===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 t===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.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}}}t.ReceiveSignalValidator=l},771:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SendSignalValidator=void 0;const n=i(578),a=(0,i(645).createLogger)("SendSignalValidator");class l{canSendSignal(e,t){const i=l.validateSignalEvent(e.event,t.state);return i||a.warn(`Cannot send signal ${e.event} in call state ${t.state} with local participant state ${t.localParticipant.state}`),i}canSendSignalEvent(e,t){const i=l.validateSignalEvent(e,t.state);return i||a.warn(`Cannot send signal ${e} in call state ${t.state} with local participant state ${t.localParticipant.state}`),i}static validateSignalEvent(e,t){const i=t===n.CallState.Connected;switch(e){case n.SignalEvent.JOIN:return!0;case n.SignalEvent.LEAVE:return i;case n.SignalEvent.OFFER:case n.SignalEvent.ANSWER:case n.SignalEvent.CONNECT:case n.SignalEvent.KICK:case n.SignalEvent.INVITE:return t===n.CallState.Connected;case n.SignalEvent.DECLINE:return t===n.CallState.Idle;case n.SignalEvent.RINGING:return t===n.CallState.Idle||t===n.CallState.Connecting;case n.SignalEvent.INFO:case n.SignalEvent.UPDATE:return t===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 t===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:return i;case n.SignalEvent.SCREEN_SHARE_ON:case n.SignalEvent.SCREEN_SHARE_OFF:return t===n.CallState.Connected;default:return a.warn(`Unknown signal event for sending: ${e}`),!1}}}t.SendSignalValidator=l},302:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ReceiveSignalValidator=t.SendSignalValidator=void 0;var n=i(771);Object.defineProperty(t,"SendSignalValidator",{enumerable:!0,get:function(){return n.SendSignalValidator}});var a=i(342);Object.defineProperty(t,"ReceiveSignalValidator",{enumerable:!0,get:function(){return a.ReceiveSignalValidator}})},740:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.VideoTrack=void 0,t.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,t,i){var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(a,l){function r(e){try{s(n.next(e))}catch(e){l(e)}}function o(e){try{s(n.throw(e))}catch(e){l(e)}}function s(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,o)}s((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.WebRTCClient=void 0;const a=i(578),l=i(645),r=i(19),o=i(680),s=(0,l.createLogger)("WebRTCClient");t.WebRTCClient=class{constructor(e,t){this.listeners={},this.sessionId=null,this.version=null,this.iceQueueMap={},this.configuration=t,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){s.info(`[18] [CallId: ${this.callId}] setListeners in webrtcClient: listeners`,{color:"blue"}),this.listeners=e}setConfiguration(e){s.info(`[21] [CallId: ${this.callId}] setConfiguration in webrtcClient: configuration: ${e}`,{color:"blue"}),this.configuration=e}getPreferredAudioCodecs(e){const t=RTCRtpReceiver.getCapabilities("audio");return t?t.codecs.filter((t=>{const i=t.mimeType.split("/")[1].toLowerCase();return e===a.MediaFlow.S2W?r.CODEC_NAME_TO_AUDIO_CODEC_S2W.includes(i):r.CODEC_NAME_TO_AUDIO_CODEC.includes(i)})):[]}getPreferredVideoCodecs(){const e=RTCRtpSender.getCapabilities("video");if(!e)return[];const t=[];return r.CODEC_NAME_TO_VIDEO_CODEC.forEach((i=>{const n=e.codecs.find((e=>e.mimeType.split("/")[1].toLowerCase()===i.toLowerCase()));n&&t.push(n)})),t}setPreferredCodecs(e,t,i){if("video"===t){s.info(`[74] [CallId: ${this.callId}] setPreferredCodecs: video, mediaFlow: ${e}`,{color:"blue"});const t=this.getPreferredVideoCodecs(),n=[];t.forEach((e=>{n.push({mimeType:e.mimeType,clockRate:e.clockRate,sdpFmtpLine:e.sdpFmtpLine,channels:e.channels})})),i.setCodecPreferences(n)}else if("audio"===t){s.info(`[88] [CallId: ${this.callId}] setPreferredCodecs: audio, mediaFlow: ${e}`,{color:"blue"});const t=this.getPreferredAudioCodecs(e),n=[];t.forEach((e=>{n.push({mimeType:e.mimeType,clockRate:e.clockRate,sdpFmtpLine:e.sdpFmtpLine||"",channels:e.channels||void 0})})),i.setCodecPreferences(n)}}addTransceiverToPeerConnection(e,t){return n(this,void 0,void 0,(function*(){s.info(`[56] [CallId: ${this.callId}] addTransceiverToPeerConnection in webrtcClient: track: ${null==e?void 0:e.kind}`,{color:"blue"}),this.peerConnection.addTransceiver(e,{direction:"sendrecv"});const i=this.peerConnection.getTransceivers().find((t=>{var i;return(null===(i=t.receiver.track)||void 0===i?void 0:i.kind)===(null==e?void 0:e.kind)}));if(i&&"video"===(null==e?void 0:e.kind)){this.setPreferredCodecs(t,"video",i);try{const e=i.sender.getParameters();e.encodings&&e.encodings.length>0&&(e.encodings.forEach((e=>{e.maxBitrate=5e5})),yield i.sender.setParameters(e),s.info(`[57] [CallId: ${this.callId}] addTransceiverToPeerConnection: Set video max bitrate to 500 kbps`,{color:"blue"}))}catch(e){s.warn(`[58] [CallId: ${this.callId}] addTransceiverToPeerConnection: Failed to set video bitrate: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"yellow"})}}else i&&"audio"===(null==e?void 0:e.kind)&&this.setPreferredCodecs(t,"audio",i)}))}setStreamsToTransceiver(e){var t,i;return n(this,void 0,void 0,(function*(){s.info(`[61] [CallId: ${this.callId}] setStreamsToTransceiver in webrtcClient: track: ${null==e?void 0:e.kind}`,{color:"blue"});const n=this.peerConnection.getTransceivers();s.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 t,i;const n=null===(t=e.receiver.track)||void 0===t?void 0:t.kind,l=null===(i=e.sender.track)||void 0===i?void 0:i.kind;return n===a||l===a}));if(s.info(`[63] [CallId: ${this.callId}] setStreamsToTransceiver: transceiver found: ${!!l}, receiver track: ${null===(t=null==l?void 0:l.receiver.track)||void 0===t?void 0:t.kind}, sender track: ${null===(i=null==l?void 0:l.sender.track)||void 0===i?void 0:i.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 s.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 t=l.direction,i=l.sender.track,n=i?i.kind:"null";s.info(`[65] [CallId: ${this.callId}] setStreamsToTransceiver: Attached local ${a} track to transceiver, direction: ${t}, sender track: ${n}, track enabled: ${null==e?void 0:e.enabled}, track id: ${null==e?void 0:e.id}`,{color:"blue"}),i||s.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 t,i;return{mid:e.mid,receiverKind:(null===(t=e.receiver.track)||void 0===t?void 0:t.kind)||"null",senderKind:(null===(i=e.sender.track)||void 0===i?void 0:i.kind)||"null",direction:e.direction}}));s.warn(`[67] [CallId: ${this.callId}] setStreamsToTransceiver: No transceiver found for track kind: ${a}. Available transceivers: ${JSON.stringify(e)}`,{color:"yellow"})}}))}enableVideoOnPeerConnection(e,t,i=!1){return n(this,void 0,void 0,(function*(){s.info(`[27] [CallId: ${this.callId}] enableVideoOnPeerConnection in webrtcClient: enable: ${e}, kind: ${null==t?void 0:t.kind}`,{color:"blue"});const n=this.peerConnection.getTransceivers();for(let a=0;a<n.length;a++){const l=n[a];l.sender.track&&"video"===l.sender.track.kind&&(t?(t.enabled=e,yield l.sender.replaceTrack(t)):l.sender.track.enabled=e);const r=l.sender.getParameters();r.encodings&&r.encodings.length>0&&(r.encodings.forEach((e=>{e.maxBitrate=i?75e4:5e5})),yield l.sender.setParameters(r),s.info(`[184] [CallId: ${this.callId}] enableVideoOnPeerConnection: Set video max bitrate to ${i?75e4:5e5} kbps`,{color:"blue"}))}}))}enableAudioOnPeerConnection(e,t){return n(this,void 0,void 0,(function*(){s.info(`[33] [CallId: ${this.callId}] enableAudioOnPeerConnection in webrtcClient: mute: ${e}, kind: ${null==t?void 0:t.kind}`,{color:"blue"});const i=this.peerConnection.getTransceivers();for(let n=0;n<i.length;n++){const a=i[n];a.sender.track&&"audio"===a.sender.track.kind&&(t?(t.enabled=!e,yield a.sender.replaceTrack(t)):a.sender.track.enabled=!e)}}))}createOffer(e,t,i){return n(this,void 0,void 0,(function*(){try{s.info(`[36] [CallId: ${this.callId}] createOffer in webrtcClient`,{color:"blue"});const n=yield this.peerConnection.createOffer({iceRestart:!0,offerToReceiveAudio:!0,offerToReceiveVideo:!0}),a=(0,o.toSessionData)({sdp:n,sessionId:e,versionId:t},i),l=(0,o.toSessionDescription)(a,"offer");return l?(yield this.setLocalDescription(l),a):(s.error(`[76] [CallId: ${this.callId}] createOffer in webrtcClient failed to convert session data to session description`,{color:"red"}),!1)}catch(e){return s.error(`[37] [CallId: ${this.callId}] createOffer in webrtcClient failed: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),!1}}))}createAnswer(e,t,i){return n(this,void 0,void 0,(function*(){try{s.info(`[75] [CallId: ${this.callId}] createAnswer in webrtcClient`,{color:"blue"});const n=yield this.peerConnection.createAnswer(),a=(0,o.toSessionData)({sdp:n,sessionId:e,versionId:t},i),l=(0,o.toSessionDescription)(a,"answer");return l?(yield this.setLocalDescription(l),a):(s.error(`[76] [CallId: ${this.callId}] createAnswer in webrtcClient failed to convert session data to session description`,{color:"red"}),!1)}catch(e){return s.error(`[70] [CallId: ${this.callId}] createAnswer in webrtcClient failed: ${e instanceof Error?e.message:JSON.stringify(e)}`,{color:"red"}),!1}}))}setLocalDescription(e){var t;return s.info(`[44] [CallId: ${this.callId}] setLocalDescription in webrtcClient: sdp sliced 50: ${null===(t=null==e?void 0:e.sdp)||void 0===t?void 0:t.slice(0,50)}...`,{color:"blue"}),this.peerConnection.setLocalDescription(e)}setRemoteDescription(e){var t;return s.info(`[48] [CallId: ${this.callId}] setRemoteDescription in webrtcClient: sdp sliced 50: ${null===(t=e.sdp)||void 0===t?void 0:t.slice(0,50)}...`,{color:"blue"}),this.peerConnection.setRemoteDescription(e)}getLocalSdpUfrag(){var e;const t=((null===(e=this.peerConnection.localDescription)||void 0===e?void 0:e.sdp)||"").match(/a=ice-ufrag:(\S+)/);return t?t[1]:null}getRemoteSdpUfrag(){var e;const t=((null===(e=this.peerConnection.remoteDescription)||void 0===e?void 0:e.sdp)||"").match(/a=ice-ufrag:(\S+)/);return t?t[1]:null}getIceCandidateUfrag(e){const t=e.match(/ufrag\s+(\S+)/);return t?t[1]:null}isUfragEqualsSdpUfrag(e){return{equals:this.getIceCandidateUfrag(e)===this.getRemoteSdpUfrag(),ufrag:this.getIceCandidateUfrag(e),sdpUfrag:this.getRemoteSdpUfrag()}}addIceCandidate(e,t){if(s.info(`[52] [CallId: ${this.callId}] addIceCandidate in webrtcClient: candidate: ${e.candidate}`,{color:"blue"}),e.candidate){const i=this.isUfragEqualsSdpUfrag(e.candidate);if(!i.equals)return this.iceQueueMap[t]||(this.iceQueueMap[t]={}),void(i.ufrag&&(this.iceQueueMap[t][i.ufrag]||(this.iceQueueMap[t][i.ufrag]=[]),this.iceQueueMap[t][i.ufrag].push(e)))}return this.peerConnection.addIceCandidate(e)}addEventListener(e,t){this.peerConnection.addEventListener(e,t)}removeEventListener(e,t){this.peerConnection.removeEventListener(e,t)}close(){s.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,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TypedEventEmitter=void 0,t.TypedEventEmitter=class{constructor(){this.listeners=new Map}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{var i;null===(i=this.listeners.get(e))||void 0===i||i.delete(t)}}emit(e,t){var i;null===(i=this.listeners.get(e))||void 0===i||i.forEach((i=>{try{i(t)}catch(t){console.error(`Error in event handler for "${String(e)}":`,t)}}))}off(e,t){var i;t?null===(i=this.listeners.get(e))||void 0===i||i.delete(t):this.listeners.delete(e)}removeAllListeners(){this.listeners.clear()}listenerCount(e){var t,i;return null!==(i=null===(t=this.listeners.get(e))||void 0===t?void 0:t.size)&&void 0!==i?i:0}}},578:(e,t)=>{var i,n,a,l,r,o,s,c,d,u;Object.defineProperty(t,"__esModule",{value:!0}),t.CDRRequestDirection=t.CDRRequestEvent=t.CDRRequestOrder=t.ParticipantEntryType=t.MediaFlow=t.SignalEvent=t.CallState=t.MediaConnectionState=t.ParticipantConnectionState=t.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"}(i||(t.ParticipantState=i={})),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||(t.ParticipantConnectionState=n={})),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"}(a||(t.MediaConnectionState=a={})),function(e){e.Idle="idle",e.Connecting="connecting",e.Connected="connected",e.Closed="closed"}(l||(t.CallState=l={})),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"}(r||(t.SignalEvent=r={})),function(e){e[e.P2P=0]="P2P",e[e.SFU=1]="SFU",e[e.S2W=2]="S2W"}(o||(t.MediaFlow=o={})),function(e){e.ADDED="ADDED"}(s||(t.ParticipantEntryType=s={})),function(e){e[e.ASC=0]="ASC",e[e.DESC=1]="DESC"}(c||(t.CDRRequestOrder=c={})),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"}(d||(t.CDRRequestEvent=d={})),function(e){e[e.NEXT=0]="NEXT",e[e.PREVIOUS=1]="PREVIOUS"}(u||(t.CDRRequestDirection=u={}))},489:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.makeFirstById=t.getEmptyVideoTrack=void 0,t.getEmptyVideoTrack=()=>{const e=document.createElement("canvas");return e.getContext("2d"),e.width=640,e.height=480,e.captureStream().getVideoTracks()},t.makeFirstById=(e,t,i)=>{const n=new Set,a=e.filter((e=>{const t=`${e.id}${e.clientId?`/${e.clientId}`:""}`;return!n.has(t)&&(n.add(t),!0)})),l=a.findIndex((e=>e.id===t&&(e.clientId===i||!e.clientId)));if(l>-1){const[e]=a.splice(l,1);a.unshift(e)}return a}},607:function(e,t,i){var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var a=Object.getOwnPropertyDescriptor(t,i);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,a)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),a=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(t,"__esModule",{value:!0});const l=i(838);a(i(838),t),t.default=l.SceytCallClient},838:function(e,t,i){var n=this&&this.__createBinding||(Object.create?function(e,t,i,n){void 0===n&&(n=i);var a=Object.getOwnPropertyDescriptor(t,i);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,n,a)}:function(e,t,i,n){void 0===n&&(n=i),e[n]=t[i]}),a=this&&this.__exportStar||function(e,t){for(var i in e)"default"===i||Object.prototype.hasOwnProperty.call(t,i)||n(t,e,i)};Object.defineProperty(t,"__esModule",{value:!0}),t.CDRRequestDirection=t.CDRRequestEvent=t.CDRRequestOrder=t.ParticipantEntryType=t.MediaConnectionState=t.ParticipantConnectionState=t.ParticipantState=t.CallState=t.MediaFlow=t.VideoTrack=t.AudioTrack=t.Participant=t.Call=void 0,a(i(271),t);var l=i(998);Object.defineProperty(t,"Call",{enumerable:!0,get:function(){return l.Call}});var r=i(787);Object.defineProperty(t,"Participant",{enumerable:!0,get:function(){return r.Participant}});var o=i(250);Object.defineProperty(t,"AudioTrack",{enumerable:!0,get:function(){return o.AudioTrack}});var s=i(740);Object.defineProperty(t,"VideoTrack",{enumerable:!0,get:function(){return s.VideoTrack}});var c=i(578);Object.defineProperty(t,"MediaFlow",{enumerable:!0,get:function(){return c.MediaFlow}}),Object.defineProperty(t,"CallState",{enumerable:!0,get:function(){return c.CallState}}),Object.defineProperty(t,"ParticipantState",{enumerable:!0,get:function(){return c.ParticipantState}}),Object.defineProperty(t,"ParticipantConnectionState",{enumerable:!0,get:function(){return c.ParticipantConnectionState}}),Object.defineProperty(t,"MediaConnectionState",{enumerable:!0,get:function(){return c.MediaConnectionState}}),Object.defineProperty(t,"ParticipantEntryType",{enumerable:!0,get:function(){return c.ParticipantEntryType}}),Object.defineProperty(t,"CDRRequestOrder",{enumerable:!0,get:function(){return c.CDRRequestOrder}}),Object.defineProperty(t,"CDRRequestEvent",{enumerable:!0,get:function(){return c.CDRRequestEvent}}),Object.defineProperty(t,"CDRRequestDirection",{enumerable:!0,get:function(){return c.CDRRequestDirection}}),a(i(645),t)},645:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createLogger=t.removeLogListener=t.addLogListener=void 0;const i={green:"",blue:"","light-green":"","light-blue":"",yellow:"",magenta:"",cyan:"",reset:"",orange:"",red:"",white:""},n=[];t.addLogListener=e=>{n.push(e)},t.removeLogListener=e=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)},t.createLogger=(e,t="white")=>{const a=`[SceytCallClient] ${e?`[${e}]`:""}:`,l=(e,l,r,o)=>{var s;const c=null!==(s=null==o?void 0:o.color)&&void 0!==s?s:t,d={level:e,message:l,prefix:a,args:r.filter((e=>!(null==e?void 0:e.color)&&!(null==e?void 0:e.time))),color:i[c],time:(null==o?void 0:o.time)||(new Date).toISOString()};n.forEach((e=>e(d)))};return{trace:(e,t)=>{l("trace",e,[],t)},debug:(e,t)=>{l("debug",e,[],t)},info:(e,t)=>{l("info",e,[],t)},warn:(e,t)=>{l("warn",e,[],t)},error:(e,t)=>{l("error",e,[],t)}}},t.default=(0,t.createLogger)("SceytCallClient")},429:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"NIL",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(t,"parse",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(t,"stringify",{enumerable:!0,get:function(){return d.default}}),Object.defineProperty(t,"v1",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(t,"v3",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(t,"v4",{enumerable:!0,get:function(){return l.default}}),Object.defineProperty(t,"v5",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(t,"validate",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(t,"version",{enumerable:!0,get:function(){return s.default}});var n=p(i(990)),a=p(i(237)),l=p(i(355)),r=p(i(764)),o=p(i(314)),s=p(i(464)),c=p(i(435)),d=p(i(8)),u=p(i(222));function p(e){return e&&e.__esModule?e:{default:e}}},163:(e,t)=>{function i(e){return 14+(e+64>>>9<<4)+1}function n(e,t){const i=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(i>>16)<<16|65535&i}function a(e,t,i,a,l,r){return n((o=n(n(t,e),n(a,r)))<<(s=l)|o>>>32-s,i);var o,s}function l(e,t,i,n,l,r,o){return a(t&i|~t&n,e,t,l,r,o)}function r(e,t,i,n,l,r,o){return a(t&n|i&~n,e,t,l,r,o)}function o(e,t,i,n,l,r,o){return a(t^i^n,e,t,l,r,o)}function s(e,t,i,n,l,r,o){return a(i^(t|~n),e,t,l,r,o)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default=function(e){if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(let i=0;i<t.length;++i)e[i]=t.charCodeAt(i)}return function(e){const t=[],i=32*e.length,n="0123456789abcdef";for(let a=0;a<i;a+=8){const i=e[a>>5]>>>a%32&255,l=parseInt(n.charAt(i>>>4&15)+n.charAt(15&i),16);t.push(l)}return t}(function(e,t){e[t>>5]|=128<<t%32,e[i(t)-1]=t;let a=1732584193,c=-271733879,d=-1732584194,u=271733878;for(let t=0;t<e.length;t+=16){const i=a,p=c,g=d,h=u;a=l(a,c,d,u,e[t],7,-680876936),u=l(u,a,c,d,e[t+1],12,-389564586),d=l(d,u,a,c,e[t+2],17,606105819),c=l(c,d,u,a,e[t+3],22,-1044525330),a=l(a,c,d,u,e[t+4],7,-176418897),u=l(u,a,c,d,e[t+5],12,1200080426),d=l(d,u,a,c,e[t+6],17,-1473231341),c=l(c,d,u,a,e[t+7],22,-45705983),a=l(a,c,d,u,e[t+8],7,1770035416),u=l(u,a,c,d,e[t+9],12,-1958414417),d=l(d,u,a,c,e[t+10],17,-42063),c=l(c,d,u,a,e[t+11],22,-1990404162),a=l(a,c,d,u,e[t+12],7,1804603682),u=l(u,a,c,d,e[t+13],12,-40341101),d=l(d,u,a,c,e[t+14],17,-1502002290),c=l(c,d,u,a,e[t+15],22,1236535329),a=r(a,c,d,u,e[t+1],5,-165796510),u=r(u,a,c,d,e[t+6],9,-1069501632),d=r(d,u,a,c,e[t+11],14,643717713),c=r(c,d,u,a,e[t],20,-373897302),a=r(a,c,d,u,e[t+5],5,-701558691),u=r(u,a,c,d,e[t+10],9,38016083),d=r(d,u,a,c,e[t+15],14,-660478335),c=r(c,d,u,a,e[t+4],20,-405537848),a=r(a,c,d,u,e[t+9],5,568446438),u=r(u,a,c,d,e[t+14],9,-1019803690),d=r(d,u,a,c,e[t+3],14,-187363961),c=r(c,d,u,a,e[t+8],20,1163531501),a=r(a,c,d,u,e[t+13],5,-1444681467),u=r(u,a,c,d,e[t+2],9,-51403784),d=r(d,u,a,c,e[t+7],14,1735328473),c=r(c,d,u,a,e[t+12],20,-1926607734),a=o(a,c,d,u,e[t+5],4,-378558),u=o(u,a,c,d,e[t+8],11,-2022574463),d=o(d,u,a,c,e[t+11],16,1839030562),c=o(c,d,u,a,e[t+14],23,-35309556),a=o(a,c,d,u,e[t+1],4,-1530992060),u=o(u,a,c,d,e[t+4],11,1272893353),d=o(d,u,a,c,e[t+7],16,-155497632),c=o(c,d,u,a,e[t+10],23,-1094730640),a=o(a,c,d,u,e[t+13],4,681279174),u=o(u,a,c,d,e[t],11,-358537222),d=o(d,u,a,c,e[t+3],16,-722521979),c=o(c,d,u,a,e[t+6],23,76029189),a=o(a,c,d,u,e[t+9],4,-640364487),u=o(u,a,c,d,e[t+12],11,-421815835),d=o(d,u,a,c,e[t+15],16,530742520),c=o(c,d,u,a,e[t+2],23,-995338651),a=s(a,c,d,u,e[t],6,-198630844),u=s(u,a,c,d,e[t+7],10,1126891415),d=s(d,u,a,c,e[t+14],15,-1416354905),c=s(c,d,u,a,e[t+5],21,-57434055),a=s(a,c,d,u,e[t+12],6,1700485571),u=s(u,a,c,d,e[t+3],10,-1894986606),d=s(d,u,a,c,e[t+10],15,-1051523),c=s(c,d,u,a,e[t+1],21,-2054922799),a=s(a,c,d,u,e[t+8],6,1873313359),u=s(u,a,c,d,e[t+15],10,-30611744),d=s(d,u,a,c,e[t+6],15,-1560198380),c=s(c,d,u,a,e[t+13],21,1309151649),a=s(a,c,d,u,e[t+4],6,-145523070),u=s(u,a,c,d,e[t+11],10,-1120210379),d=s(d,u,a,c,e[t+2],15,718787259),c=s(c,d,u,a,e[t+9],21,-343485551),a=n(a,i),c=n(c,p),d=n(d,g),u=n(u,h)}return[a,c,d,u]}(function(e){if(0===e.length)return[];const t=8*e.length,n=new Uint32Array(i(t));for(let i=0;i<t;i+=8)n[i>>5]|=(255&e[i/8])<<i%32;return n}(e),8*e.length))}},790:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};t.default=i},314:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.default="00000000-0000-0000-0000-000000000000"},222:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,a=(n=i(435))&&n.__esModule?n:{default:n};t.default=function(e){if(!(0,a.default)(e))throw TypeError("Invalid UUID");let t;const i=new Uint8Array(16);return i[0]=(t=parseInt(e.slice(0,8),16))>>>24,i[1]=t>>>16&255,i[2]=t>>>8&255,i[3]=255&t,i[4]=(t=parseInt(e.slice(9,13),16))>>>8,i[5]=255&t,i[6]=(t=parseInt(e.slice(14,18),16))>>>8,i[7]=255&t,i[8]=(t=parseInt(e.slice(19,23),16))>>>8,i[9]=255&t,i[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,i[11]=t/4294967296&255,i[12]=t>>>24&255,i[13]=t>>>16&255,i[14]=t>>>8&255,i[15]=255&t,i}},58:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.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,t)=>{let i;Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){if(!i&&(i="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!i))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return i(n)};const n=new Uint8Array(16)},757:(e,t)=>{function i(e,t,i,n){switch(e){case 0:return t&i^~t&n;case 1:case 3:return t^i^n;case 2:return t&i^t&n^i&n}}function n(e,t){return e<<t|e>>>32-t}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default=function(e){const t=[1518500249,1859775393,2400959708,3395469782],a=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=[];for(let i=0;i<t.length;++i)e.push(t.charCodeAt(i))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);const l=e.length/4+2,r=Math.ceil(l/16),o=new Array(r);for(let t=0;t<r;++t){const i=new Uint32Array(16);for(let n=0;n<16;++n)i[n]=e[64*t+4*n]<<24|e[64*t+4*n+1]<<16|e[64*t+4*n+2]<<8|e[64*t+4*n+3];o[t]=i}o[r-1][14]=8*(e.length-1)/Math.pow(2,32),o[r-1][14]=Math.floor(o[r-1][14]),o[r-1][15]=8*(e.length-1)&4294967295;for(let e=0;e<r;++e){const l=new Uint32Array(80);for(let t=0;t<16;++t)l[t]=o[e][t];for(let e=16;e<80;++e)l[e]=n(l[e-3]^l[e-8]^l[e-14]^l[e-16],1);let r=a[0],s=a[1],c=a[2],d=a[3],u=a[4];for(let e=0;e<80;++e){const a=Math.floor(e/20),o=n(r,5)+i(a,s,c,d)+u+t[a]+l[e]>>>0;u=d,d=c,c=n(s,30)>>>0,s=r,r=o}a[0]=a[0]+r>>>0,a[1]=a[1]+s>>>0,a[2]=a[2]+c>>>0,a[3]=a[3]+d>>>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,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.unsafeStringify=r;var n,a=(n=i(435))&&n.__esModule?n:{default:n};const l=[];for(let e=0;e<256;++e)l.push((e+256).toString(16).slice(1));function r(e,t=0){return l[e[t+0]]+l[e[t+1]]+l[e[t+2]]+l[e[t+3]]+"-"+l[e[t+4]]+l[e[t+5]]+"-"+l[e[t+6]]+l[e[t+7]]+"-"+l[e[t+8]]+l[e[t+9]]+"-"+l[e[t+10]]+l[e[t+11]]+l[e[t+12]]+l[e[t+13]]+l[e[t+14]]+l[e[t+15]]}t.default=function(e,t=0){const i=r(e,t);if(!(0,a.default)(i))throw TypeError("Stringified UUID is invalid");return i}},990:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,a=(n=i(319))&&n.__esModule?n:{default:n},l=i(8);let r,o,s=0,c=0;t.default=function(e,t,i){let n=t&&i||0;const d=t||new Array(16);let u=(e=e||{}).node||r,p=void 0!==e.clockseq?e.clockseq:o;if(null==u||null==p){const t=e.random||(e.rng||a.default)();null==u&&(u=r=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==p&&(p=o=16383&(t[6]<<8|t[7]))}let g=void 0!==e.msecs?e.msecs:Date.now(),h=void 0!==e.nsecs?e.nsecs:c+1;const S=g-s+(h-c)/1e4;if(S<0&&void 0===e.clockseq&&(p=p+1&16383),(S<0||g>s)&&void 0===e.nsecs&&(h=0),h>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");s=g,c=h,o=p,g+=122192928e5;const C=(1e4*(268435455&g)+h)%4294967296;d[n++]=C>>>24&255,d[n++]=C>>>16&255,d[n++]=C>>>8&255,d[n++]=255&C;const v=g/4294967296*1e4&268435455;d[n++]=v>>>8&255,d[n++]=255&v,d[n++]=v>>>24&15|16,d[n++]=v>>>16&255,d[n++]=p>>>8|128,d[n++]=255&p;for(let e=0;e<6;++e)d[n+e]=u[e];return t||(0,l.unsafeStringify)(d)}},237:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=l(i(925)),a=l(i(163));function l(e){return e&&e.__esModule?e:{default:e}}var r=(0,n.default)("v3",48,a.default);t.default=r},925:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.URL=t.DNS=void 0,t.default=function(e,t,i){function n(e,n,r,o){var s;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let i=0;i<e.length;++i)t.push(e.charCodeAt(i));return t}(e)),"string"==typeof n&&(n=(0,l.default)(n)),16!==(null===(s=n)||void 0===s?void 0:s.length))throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+e.length);if(c.set(n),c.set(e,n.length),c=i(c),c[6]=15&c[6]|t,c[8]=63&c[8]|128,r){o=o||0;for(let e=0;e<16;++e)r[o+e]=c[e];return r}return(0,a.unsafeStringify)(c)}try{n.name=e}catch(e){}return n.DNS=r,n.URL=o,n};var n,a=i(8),l=(n=i(222))&&n.__esModule?n:{default:n};const r="6ba7b810-9dad-11d1-80b4-00c04fd430c8";t.DNS=r;const o="6ba7b811-9dad-11d1-80b4-00c04fd430c8";t.URL=o},355:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=r(i(790)),a=r(i(319)),l=i(8);function r(e){return e&&e.__esModule?e:{default:e}}t.default=function(e,t,i){if(n.default.randomUUID&&!t&&!e)return n.default.randomUUID();const r=(e=e||{}).random||(e.rng||a.default)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){i=i||0;for(let e=0;e<16;++e)t[i+e]=r[e];return t}return(0,l.unsafeStringify)(r)}},764:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=l(i(925)),a=l(i(757));function l(e){return e&&e.__esModule?e:{default:e}}var r=(0,n.default)("v5",80,a.default);t.default=r},435:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,a=(n=i(58))&&n.__esModule?n:{default:n};t.default=function(e){return"string"==typeof e&&a.default.test(e)}},464:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,a=(n=i(435))&&n.__esModule?n:{default:n};t.default=function(e){if(!(0,a.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)}}},t={};return function i(n){var a=t[n];if(void 0!==a)return a.exports;var l=t[n]={exports:{}};return e[n].call(l.exports,l,l.exports,i),l.exports}(607)})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sceyt-call",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "JavaScript Call SDK",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",