sip-connector 15.0.0 → 15.2.0
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.
- package/README.md +160 -11
- package/dist/{@SipConnector-DbvV1Leg.js → @SipConnector-BEZk1hmx.js} +511 -229
- package/dist/@SipConnector-hpySQIBa.cjs +1 -0
- package/dist/ApiManager/__tests-utils__/helpers.d.ts +9 -0
- package/dist/ApiManager/constants.d.ts +2 -1
- package/dist/ApiManager/eventNames.d.ts +2 -1
- package/dist/CallManager/MCUCallStrategy.d.ts +1 -1
- package/dist/ConnectionManager/@ConnectionManager.d.ts +3 -3
- package/dist/ConnectionManager/getExtraHeadersRemoteAddress.d.ts +2 -2
- package/dist/IncomingCallManager/@IncomingCallManager.d.ts +2 -2
- package/dist/SipConnector/@SipConnector.d.ts +4 -2
- package/dist/SipConnector/eventNames.d.ts +1 -1
- package/dist/SipConnectorFacade/SipConnectorFacade.d.ts +15 -1
- package/dist/StatsManager/@StatsManager.d.ts +19 -0
- package/dist/StatsManager/eventNames.d.ts +2 -0
- package/dist/StatsManager/index.d.ts +2 -0
- package/dist/StatsPeerConnection/StatsPeerConnection.d.ts +20 -0
- package/dist/StatsPeerConnection/__fixtures__/callStaticsState.d.ts +3923 -0
- package/dist/StatsPeerConnection/constants.d.ts +14 -0
- package/dist/StatsPeerConnection/eventNames.d.ts +10 -0
- package/dist/StatsPeerConnection/index.d.ts +4 -0
- package/dist/StatsPeerConnection/parseStatsReports.d.ts +14 -0
- package/dist/StatsPeerConnection/requestAllStatistics.d.ts +11 -0
- package/dist/StatsPeerConnection/typings.d.ts +194 -0
- package/dist/StatsPeerConnection/utils/hasAvailableStats.d.ts +2 -0
- package/dist/StatsPeerConnection/utils/index.d.ts +3 -0
- package/dist/StatsPeerConnection/utils/now.d.ts +2 -0
- package/dist/StatsPeerConnection/utils/statsReportToObject.d.ts +4 -0
- package/dist/VideoSendingBalancer/CodecProvider.d.ts +7 -0
- package/dist/VideoSendingBalancer/ParametersSetterWithQueue.d.ts +12 -0
- package/dist/VideoSendingBalancer/SenderBalancer.d.ts +52 -0
- package/dist/VideoSendingBalancer/SenderFinder.d.ts +7 -0
- package/dist/VideoSendingBalancer/TaskQueue.d.ts +20 -0
- package/dist/VideoSendingBalancer/VideoSendingBalancer.d.ts +44 -0
- package/dist/VideoSendingBalancer/VideoSendingEventHandler.d.ts +25 -0
- package/dist/VideoSendingBalancer/calcBitrate/calcMaxBitrateByWidth.d.ts +4 -0
- package/dist/VideoSendingBalancer/calcBitrate/calcMaxBitrateByWidthAndCodec.d.ts +4 -0
- package/dist/VideoSendingBalancer/calcBitrate/index.d.ts +1 -0
- package/dist/VideoSendingBalancer/calcResolution/calcScaleResolutionDownBy.d.ts +6 -0
- package/dist/VideoSendingBalancer/calcResolution/index.d.ts +1 -0
- package/dist/VideoSendingBalancer/index.d.ts +3 -0
- package/dist/VideoSendingBalancer/types.d.ts +36 -0
- package/dist/__fixtures__/BaseSession.mock.d.ts +1 -1
- package/dist/__fixtures__/RTCPeerConnectionMock.d.ts +2 -2
- package/dist/__fixtures__/RTCRtpSenderMock.d.ts +1 -0
- package/dist/__fixtures__/RTCSessionMock.d.ts +2 -2
- package/dist/__fixtures__/UA.mock.d.ts +2 -2
- package/dist/__fixtures__/eventNames.d.ts +1 -1
- package/dist/__fixtures__/jssip.mock.d.ts +1 -1
- package/dist/doMock.cjs +1 -1
- package/dist/doMock.js +21 -22
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +697 -562
- package/dist/tools/createUaParser/createUaParser.d.ts +4 -0
- package/dist/tools/createUaParser/index.d.ts +1 -0
- package/dist/tools/createUaParser/isElectronEnvironment.d.ts +2 -0
- package/dist/tools/error/index.d.ts +1 -1
- package/dist/tools/index.d.ts +5 -1
- package/dist/{setParametersToSender → tools/setParametersToSender}/configureDegradationPreference.d.ts +1 -1
- package/dist/{setParametersToSender → tools/setParametersToSender}/configureEncodings.d.ts +1 -1
- package/dist/tools/setParametersToSender/index.d.ts +3 -0
- package/dist/tools/setParametersToSender/setEncodingsToSender.d.ts +6 -0
- package/dist/tools/setParametersToSender/setMaxBitrateToSender.d.ts +2 -0
- package/dist/tools/setParametersToSender/setParametersToSender.d.ts +4 -0
- package/dist/tools/setParametersToSender/types.d.ts +5 -0
- package/dist/tools/syncMediaState/createSyncMediaState.d.ts +18 -0
- package/dist/tools/syncMediaState/index.d.ts +1 -18
- package/dist/utils/utils.d.ts +4 -0
- package/package.json +12 -18
- package/dist/@SipConnector-CZo7A8_q.cjs +0 -1
- package/dist/setParametersToSender/index.d.ts +0 -1
- package/dist/setParametersToSender/setParametersToSender.d.ts +0 -7
- package/dist/videoSendingBalancer/balance.d.ts +0 -10
- package/dist/videoSendingBalancer/getMaxBitrateByWidth.d.ts +0 -4
- package/dist/videoSendingBalancer/getMaxBitrateByWidthAndCodec.d.ts +0 -4
- package/dist/videoSendingBalancer/index.d.ts +0 -13
- package/dist/videoSendingBalancer/processSender.d.ts +0 -10
- package/dist/videoSendingBalancer/scaleBitrate.d.ts +0 -2
- package/dist/videoSendingBalancer/setEncodingsToSender.d.ts +0 -10
- /package/dist/{videoSendingBalancer → VideoSendingBalancer/calcBitrate}/hasAv1Codec.d.ts +0 -0
- /package/dist/{videoSendingBalancer → VideoSendingBalancer/calcBitrate}/scaleBitrateByCodec.d.ts +0 -0
- /package/dist/{videoSendingBalancer → tools}/scaleResolutionAndBitrate.d.ts +0 -0
- /package/dist/{setParametersToSender → tools/setParametersToSender}/configureEmptyEncodings.d.ts +0 -0
- /package/dist/{setParametersToSender → tools/setParametersToSender}/configureMaxBitrate.d.ts +0 -0
- /package/dist/{setParametersToSender → tools/setParametersToSender}/configureScaleResolutionDownBy.d.ts +0 -0
- /package/dist/{setParametersToSender → tools/setParametersToSender}/hasChangedRTCRtpSendParameters.d.ts +0 -0
- /package/dist/{setParametersToSender → tools/setParametersToSender}/resolveHasNeedToUpdateItemEncoding.d.ts +0 -0
- /package/dist/{videoSendingBalancer → utils}/hasIncludesString.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const m=require("events-constructor"),ge=require("@krivega/cancelable-promise"),q=require("debug"),B=require("repeated-calls"),Q=require("xstate"),de=require("@krivega/timeout-requester");require("ua-parser-js");require("sequent-promises");var N=(n=>(n.PEER_CONNECTION="peerconnection",n.CONNECTING="connecting",n.SENDING="sending",n.PROGRESS="progress",n.ACCEPTED="accepted",n.CONFIRMED="confirmed",n.ENDED="ended",n.FAILED="failed",n.NEW_DTMF="newDTMF",n.NEW_INFO="newInfo",n.HOLD="hold",n.UNHOLD="unhold",n.MUTED="muted",n.UNMUTED="unmuted",n.REINVITE="reinvite",n.UPDATE="update",n.REFER="refer",n.REPLACES="replaces",n.SDP="sdp",n.ICE_CANDIDATE="icecandidate",n.GET_USER_MEDIA_FAILED="getusermediafailed",n.PEER_CONNECTION_CREATE_OFFER_FAILED="peerconnection:createofferfailed",n.PEER_CONNECTION_CREATE_ANSWER_FAILED="peerconnection:createanswerfailed",n.PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED="peerconnection:setlocaldescriptionfailed",n.PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED="peerconnection:setremotedescriptionfailed",n.START_PRESENTATION="presentation:start",n.STARTED_PRESENTATION="presentation:started",n.END_PRESENTATION="presentation:end",n.ENDED_PRESENTATION="presentation:ended",n.FAILED_PRESENTATION="presentation:failed",n.PEER_CONNECTION_CONFIRMED="peerconnection:confirmed",n.PEER_CONNECTION_ONTRACK="peerconnection:ontrack",n.ENDED_FROM_SERVER="ended:fromserver",n))(N||{}),w=(n=>(n.LOCAL="local",n.REMOTE="remote",n.SYSTEM="system",n))(w||{});const X=["peerconnection","connecting","sending","progress","accepted","confirmed","ended","failed","newInfo","newDTMF","presentation:start","presentation:started","presentation:end","presentation:ended","presentation:failed","reinvite","update","refer","replaces","sdp","icecandidate","getusermediafailed","peerconnection:createofferfailed","peerconnection:createanswerfailed","peerconnection:setlocaldescriptionfailed","peerconnection:setremotedescriptionfailed"],Te=["peerconnection:confirmed","peerconnection:ontrack","ended:fromserver"],J=[...X,...Te],he=(n,e)=>{n.getVideoTracks().forEach(s=>{"contentHint"in s&&s.contentHint!==e&&(s.contentHint=e)})},b=(n,{directionVideo:e,directionAudio:t,contentHint:s}={})=>{if(!n||e==="recvonly"&&t==="recvonly")return;const i=t==="recvonly"?[]:n.getAudioTracks(),r=e==="recvonly"?[]:n.getVideoTracks(),a=[...i,...r],o=new MediaStream(a);return o.getTracks=()=>[...o.getAudioTracks(),...o.getVideoTracks()],s&&s!=="none"&&he(o,s),o};function Ee(n){return e=>`sip:${e}@${n}`}const le=(n,e)=>()=>Math.floor(Math.random()*(e-n))+n,j=n=>n.trim().replaceAll(" ","_"),Se=le(1e5,99999999),ue=n=>n.some(t=>{const{kind:s}=t;return s==="video"});class Ce{isPendingCall=!1;isPendingAnswer=!1;rtcSession;remoteStreams={};events;callConfiguration={};constructor(e){this.events=e}}var H=(n=>(n.BYE="Terminated",n.WEBRTC_ERROR="WebRTC Error",n.CANCELED="Canceled",n.REQUEST_TIMEOUT="Request Timeout",n.REJECTED="Rejected",n.REDIRECTED="Redirected",n.UNAVAILABLE="Unavailable",n.NOT_FOUND="Not Found",n.ADDRESS_INCOMPLETE="Address Incomplete",n.INCOMPATIBLE_SDP="Incompatible SDP",n.BAD_MEDIA_DESCRIPTION="Bad Media Description",n))(H||{});class Ne{remoteStreams={};reset(){this.remoteStreams={}}generateStream(e,t){const{id:s}=e,i=this.remoteStreams[s]??new MediaStream;return t&&i.addTrack(t),i.addTrack(e),this.remoteStreams[s]=i,i}generateAudioStream(e){const{id:t}=e,s=this.remoteStreams[t]??new MediaStream;return s.addTrack(e),this.remoteStreams[t]=s,s}generateStreams(e){const t=[];return e.forEach((s,i)=>{if(s.kind==="audio")return;const r=s,a=e[i-1];let o;a?.kind==="audio"&&(o=a);const c=this.generateStream(r,o);t.push(c)}),t}generateAudioStreams(e){return e.map(t=>this.generateAudioStream(t))}}class Ae extends Ce{remoteStreamsManager=new Ne;disposers=new Set;constructor(e){super(e),e.on(N.FAILED,this.handleEnded),e.on(N.ENDED,this.handleEnded)}get requested(){return this.isPendingCall||this.isPendingAnswer}get connection(){return this.rtcSession?.connection}get isCallActive(){return this.rtcSession?.isEstablished()===!0}get establishedRTCSession(){return this.rtcSession?.isEstablished()===!0?this.rtcSession:void 0}startCall=async(e,t,{number:s,mediaStream:i,extraHeaders:r=[],ontrack:a,iceServers:o,directionVideo:c,directionAudio:g,contentHint:E,offerToReceiveAudio:u=!0,offerToReceiveVideo:d=!0,sendEncodings:S,onAddedTransceiver:_})=>(this.isPendingCall=!0,new Promise((C,p)=>{this.callConfiguration.number=s,this.callConfiguration.answer=!1,this.handleCall({ontrack:a}).then(C).catch(v=>{p(v)}),this.rtcSession=e.call(t(s),{extraHeaders:r,mediaStream:b(i,{directionVideo:c,directionAudio:g,contentHint:E}),eventHandlers:this.events.triggers,directionVideo:c,directionAudio:g,pcConfig:{iceServers:o},rtcOfferConstraints:{offerToReceiveAudio:u,offerToReceiveVideo:d},sendEncodings:S,onAddedTransceiver:_})}).finally(()=>{this.isPendingCall=!1}));async endCall(){const{rtcSession:e}=this;if(e&&!e.isEnded())return e.terminateAsync({cause:H.CANCELED}).finally(()=>{this.reset()});this.reset()}answerToIncomingCall=async(e,{mediaStream:t,ontrack:s,extraHeaders:i=[],iceServers:r,directionVideo:a,directionAudio:o,offerToReceiveAudio:c,offerToReceiveVideo:g,contentHint:E,sendEncodings:u,onAddedTransceiver:d})=>(this.isPendingAnswer=!0,new Promise((S,_)=>{try{const C=e();this.rtcSession=C,this.subscribeToSessionEvents(C),this.callConfiguration.answer=!0,this.callConfiguration.number=C.remote_identity.uri.user,this.handleCall({ontrack:s}).then(S).catch(v=>{_(v)});const p=b(t,{directionVideo:a,directionAudio:o,contentHint:E});C.answer({extraHeaders:i,directionVideo:a,directionAudio:o,mediaStream:p,pcConfig:{iceServers:r},rtcOfferConstraints:{offerToReceiveAudio:c,offerToReceiveVideo:g},sendEncodings:u,onAddedTransceiver:d})}catch(C){_(C)}}).finally(()=>{this.isPendingAnswer=!1}));getEstablishedRTCSession(){return this.rtcSession?.isEstablished()===!0?this.rtcSession:void 0}getCallConfiguration(){return{...this.callConfiguration}}getRemoteStreams(){if(!this.connection)return;const t=this.connection.getReceivers().map(({track:s})=>s);return ue(t)?this.remoteStreamsManager.generateStreams(t):this.remoteStreamsManager.generateAudioStreams(t)}async replaceMediaStream(e,t){if(!this.rtcSession)throw new Error("No rtcSession established");const{contentHint:s}=t??{},i=b(e,{contentHint:s});if(i===void 0)throw new Error("No preparedMediaStream");return this.rtcSession.replaceMediaStream(i,t)}handleCall=async({ontrack:e})=>new Promise((t,s)=>{const i=()=>{this.events.on(N.PEER_CONNECTION,E),this.events.on(N.CONFIRMED,u)},r=()=>{this.events.off(N.PEER_CONNECTION,E),this.events.off(N.CONFIRMED,u)},a=()=>{this.events.on(N.FAILED,c),this.events.on(N.ENDED,c)},o=()=>{this.events.off(N.FAILED,c),this.events.off(N.ENDED,c)},c=d=>{r(),o(),s(d)};let g;const E=({peerconnection:d})=>{g=d;const S=_=>{this.events.trigger(N.PEER_CONNECTION_ONTRACK,d),e&&e(_)};d.addEventListener("track",S),this.disposers.add(()=>{d.removeEventListener("track",S)})},u=()=>{g!==void 0&&this.events.trigger(N.PEER_CONNECTION_CONFIRMED,g),r(),o(),t(g)};i(),a()});subscribeToSessionEvents(e){this.events.eachTriggers((t,s)=>{const i=X.find(r=>r===s);i&&(e.on(i,t),this.disposers.add(()=>{e.off(i,t)}))})}unsubscribeFromSessionEvents(){this.disposers.forEach(e=>{e()}),this.disposers.clear()}handleEnded=e=>{const{originator:t}=e;t===w.REMOTE&&this.events.trigger(N.ENDED_FROM_SERVER,e),this.reset()};reset=()=>{delete this.rtcSession,this.remoteStreamsManager.reset(),this.unsubscribeFromSessionEvents(),this.callConfiguration.number=void 0,this.callConfiguration.answer=!1}}class Re{events;strategy;constructor(e){this.events=new m.Events(J),this.strategy=e??new Ae(this.events)}get requested(){return this.strategy.requested}get connection(){return this.strategy.connection}get establishedRTCSession(){return this.strategy.establishedRTCSession}get isCallActive(){return this.strategy.isCallActive}on(e,t){return this.events.on(e,t)}once(e,t){return this.events.once(e,t)}onceRace(e,t){return this.events.onceRace(e,t)}async wait(e){return this.events.wait(e)}off(e,t){this.events.off(e,t)}setStrategy(e){this.strategy=e}startCall=async(...e)=>this.strategy.startCall(...e);endCall=async()=>this.strategy.endCall();answerToIncomingCall=async(...e)=>this.strategy.answerToIncomingCall(...e);getEstablishedRTCSession=()=>this.strategy.getEstablishedRTCSession();getCallConfiguration=()=>this.strategy.getCallConfiguration();getRemoteStreams=()=>this.strategy.getRemoteStreams();replaceMediaStream=async(...e)=>this.strategy.replaceMediaStream(...e)}const G="sip-connector",O=q(G),_e=()=>{q.enable(G)},Ie=()=>{q.enable(`-${G}`)},Me="Error decline with 603",pe=1006,Pe=n=>typeof n=="object"&&n!==null&&"code"in n&&n.code===pe,Oe=n=>n.message===Me;var h=(n=>(n.CONTENT_TYPE="content-type",n.CONTENT_ENTER_ROOM="x-webrtc-enter-room",n.CONTENT_USE_LICENSE="X-WEBRTC-USE-LICENSE",n.PARTICIPANT_NAME="X-WEBRTC-PARTICIPANT-NAME",n.INPUT_CHANNELS="X-WEBRTC-INPUT-CHANNELS",n.OUTPUT_CHANNELS="X-WEBRTC-OUTPUT-CHANNELS",n.MAIN_CAM="X-WEBRTC-MAINCAM",n.MIC="X-WEBRTC-MIC",n.MEDIA_SYNC="X-WEBRTC-SYNC",n.MAIN_CAM_RESOLUTION="X-WEBRTC-MAINCAM-RESOLUTION",n.MEDIA_STATE="X-WEBRTC-MEDIA-STATE",n.MEDIA_TYPE="X-Vinteo-Media-Type",n.MAIN_CAM_STATE="X-Vinteo-MainCam-State",n.MIC_STATE="X-Vinteo-Mic-State",n.CONTENT_PARTICIPANT_STATE="X-WEBRTC-PARTSTATE",n.NOTIFY="X-VINTEO-NOTIFY",n.CONTENT_ENABLE_MEDIA_DEVICE="X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE",n.CONTENT_SHARE_STATE="x-webrtc-share-state",n.MUST_STOP_PRESENTATION_P2P="x-webrtc-share-state: YOUMUSTSTOPSENDCONTENT",n.START_PRESENTATION_P2P="x-webrtc-share-state: YOUCANRECEIVECONTENT",n.STOP_PRESENTATION_P2P="x-webrtc-share-state: CONTENTEND",n.STOP_PRESENTATION="x-webrtc-share-state: STOPPRESENTATION",n.START_PRESENTATION="x-webrtc-share-state: LETMESTARTPRESENTATION",n.ENABLE_MAIN_CAM="X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE: LETMESTARTMAINCAM",n))(h||{}),F=(n=>(n.AVAILABLE_SECOND_REMOTE_STREAM="YOUCANRECEIVECONTENT",n.NOT_AVAILABLE_SECOND_REMOTE_STREAM="CONTENTEND",n.MUST_STOP_PRESENTATION="YOUMUSTSTOPSENDCONTENT",n))(F||{}),$=(n=>(n.SPECTATOR="SPECTATOR",n.PARTICIPANT="PARTICIPANT",n.SPECTATOR_OVER_SFU="SPECTATOROVERSFU",n))($||{}),P=(n=>(n.ENTER_ROOM="application/vinteo.webrtc.roomname",n.MIC="application/vinteo.webrtc.mic",n.USE_LICENSE="application/vinteo.webrtc.uselic",n.PARTICIPANT_STATE="application/vinteo.webrtc.partstate",n.NOTIFY="application/vinteo.webrtc.notify",n.SHARE_STATE="application/vinteo.webrtc.sharedesktop",n.MAIN_CAM="application/vinteo.webrtc.maincam",n))(P||{}),I=(n=>(n.CHANNELS="application/vinteo.webrtc.channels",n.MEDIA_STATE="application/vinteo.webrtc.mediastate",n.REFUSAL="application/vinteo.webrtc.refusal",n.SHARE_STATE="application/vinteo.webrtc.sharedesktop",n.MAIN_CAM="application/vinteo.webrtc.maincam",n))(I||{}),f=(n=>(n.PAUSE_MAIN_CAM="PAUSEMAINCAM",n.RESUME_MAIN_CAM="RESUMEMAINCAM",n.MAX_MAIN_CAM_RESOLUTION="MAXMAINCAMRESOLUTION",n.ADMIN_STOP_MAIN_CAM="ADMINSTOPMAINCAM",n.ADMIN_START_MAIN_CAM="ADMINSTARTMAINCAM",n))(f||{}),k=(n=>(n.ADMIN_STOP_MIC="ADMINSTOPMIC",n.ADMIN_START_MIC="ADMINSTARTMIC",n))(k||{}),W=(n=>(n.ADMIN_SYNC_FORCED="1",n.ADMIN_SYNC_NOT_FORCED="0",n))(W||{}),K=(n=>(n.AUDIO="AUDIO",n.VIDEO="VIDEO",n.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION",n))(K||{}),T=(n=>(n.CHANNELS_NOTIFY="channels:notify",n.PARTICIPANT_ADDED_TO_LIST_MODERATORS="participant:added-to-list-moderators",n.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS="participant:removed-from-list-moderators",n.PARTICIPANT_MOVE_REQUEST_TO_STREAM="participant:move-request-to-stream",n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS="participant:move-request-to-spectators",n.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS="participant:move-request-to-participants",n.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_OVER_SFU="participant:move-request-to-spectators-over-sfu",n.PARTICIPATION_ACCEPTING_WORD_REQUEST="participation:accepting-word-request",n.PARTICIPATION_CANCELLING_WORD_REQUEST="participation:cancelling-word-request",n.WEBCAST_STARTED="webcast:started",n.WEBCAST_STOPPED="webcast:stopped",n.ACCOUNT_CHANGED="account:changed",n.ACCOUNT_DELETED="account:deleted",n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED="conference:participant-token-issued",n.CHANNELS="channels",n.ENTER_ROOM="enterRoom",n.SHARE_STATE="shareState",n.MAIN_CAM_CONTROL="main-cam-control",n.USE_LICENSE="useLicense",n.ADMIN_START_MAIN_CAM="admin-start-main-cam",n.ADMIN_STOP_MAIN_CAM="admin-stop-main-cam",n.ADMIN_START_MIC="admin-start-mic",n.ADMIN_STOP_MIC="admin-stop-mic",n.ADMIN_FORCE_SYNC_MEDIA_STATE="admin-force-sync-media-state",n.AVAILABLE_SECOND_REMOTE_STREAM="availableSecondRemoteStream",n.NOT_AVAILABLE_SECOND_REMOTE_STREAM="notAvailableSecondRemoteStream",n.MUST_STOP_PRESENTATION="mustStopPresentation",n.NEW_DTMF="newDTMF",n))(T||{});const Z=["participation:accepting-word-request","participation:cancelling-word-request","participant:move-request-to-stream","channels:notify","conference:participant-token-issued","account:changed","account:deleted","webcast:started","webcast:stopped","participant:added-to-list-moderators","participant:removed-from-list-moderators","participant:move-request-to-spectators","participant:move-request-to-participants","participant:move-request-to-spectators-over-sfu","channels","enterRoom","shareState","main-cam-control","useLicense","admin-start-main-cam","admin-stop-main-cam","admin-start-mic","admin-stop-mic","admin-force-sync-media-state","availableSecondRemoteStream","notAvailableSecondRemoteStream","mustStopPresentation","newDTMF"];var R=(n=>(n.CHANNELS="channels",n.WEBCAST_STARTED="WebcastStarted",n.WEBCAST_STOPPED="WebcastStopped",n.ACCOUNT_CHANGED="accountChanged",n.ACCOUNT_DELETED="accountDeleted",n.ADDED_TO_LIST_MODERATORS="addedToListModerators",n.REMOVED_FROM_LIST_MODERATORS="removedFromListModerators",n.ACCEPTING_WORD_REQUEST="ParticipationRequestAccepted",n.CANCELLING_WORD_REQUEST="ParticipationRequestRejected",n.MOVE_REQUEST_TO_STREAM="ParticipantMovedToWebcast",n.CONFERENCE_PARTICIPANT_TOKEN_ISSUED="ConferenceParticipantTokenIssued",n))(R||{});class me{events;connectionManager;callManager;constructor({connectionManager:e,callManager:t}){this.connectionManager=e,this.callManager=t,this.events=new m.Events(Z),this.subscribe()}async waitChannels(){return this.wait(T.CHANNELS)}async waitSyncMediaState(){return this.wait(T.ADMIN_FORCE_SYNC_MEDIA_STATE)}async sendDTMF(e){return new Promise((t,s)=>{let i;try{i=this.getEstablishedRTCSessionProtected()}catch(r){s(r)}i&&(this.callManager.once("newDTMF",({originator:r})=>{r===w.LOCAL&&t()}),i.sendDTMF(e,{duration:120,interToneGap:600}))})}async sendChannels({inputChannels:e,outputChannels:t}){const s=this.getEstablishedRTCSessionProtected(),i=`${h.INPUT_CHANNELS}: ${e}`,r=`${h.OUTPUT_CHANNELS}: ${t}`,a=[i,r];return s.sendInfo(I.CHANNELS,void 0,{extraHeaders:a})}async sendMediaState({cam:e,mic:t},s={}){const i=this.getEstablishedRTCSessionProtected(),r=`${h.MEDIA_STATE}: currentstate`,a=`${h.MAIN_CAM_STATE}: ${Number(e)}`,o=`${h.MIC_STATE}: ${Number(t)}`,c=[r,a,o];return i.sendInfo(I.MEDIA_STATE,void 0,{noTerminateWhenError:!0,...s,extraHeaders:c})}async sendRefusalToTurnOn(e,t={}){const s=this.getEstablishedRTCSessionProtected(),a=e==="mic"?0:1,c=[`${h.MEDIA_TYPE}: ${a}`];return s.sendInfo(I.REFUSAL,void 0,{noTerminateWhenError:!0,...t,extraHeaders:c})}async sendRefusalToTurnOnMic(e={}){return this.sendRefusalToTurnOn("mic",{noTerminateWhenError:!0,...e})}async sendRefusalToTurnOnCam(e={}){return this.sendRefusalToTurnOn("cam",{noTerminateWhenError:!0,...e})}async sendMustStopPresentationP2P(){await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE,void 0,{extraHeaders:[h.MUST_STOP_PRESENTATION_P2P]})}async sendStoppedPresentationP2P(){await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE,void 0,{extraHeaders:[h.STOP_PRESENTATION_P2P]})}async sendStoppedPresentation(){await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE,void 0,{extraHeaders:[h.STOP_PRESENTATION]})}async askPermissionToStartPresentationP2P(){await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE,void 0,{extraHeaders:[h.START_PRESENTATION_P2P]})}async askPermissionToStartPresentation(){await this.getEstablishedRTCSessionProtected().sendInfo(I.SHARE_STATE,void 0,{extraHeaders:[h.START_PRESENTATION]})}async askPermissionToEnableCam(e={}){const t=this.getEstablishedRTCSessionProtected(),s=[h.ENABLE_MAIN_CAM];return t.sendInfo(I.MAIN_CAM,void 0,{noTerminateWhenError:!0,...e,extraHeaders:s}).catch(i=>{if(Oe(i))throw i})}on(e,t){return this.events.on(e,t)}once(e,t){return this.events.once(e,t)}onceRace(e,t){return this.events.onceRace(e,t)}async wait(e){return this.events.wait(e)}off(e,t){this.events.off(e,t)}getEstablishedRTCSessionProtected=()=>{const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");return e};subscribe(){this.connectionManager.on("sipEvent",this.handleSipEvent),this.callManager.on("newInfo",this.handleNewInfo),this.callManager.on("newDTMF",e=>{this.events.trigger("newDTMF",e)})}handleSipEvent=({request:e})=>{this.maybeHandleNotify(e)};maybeHandleNotify=e=>{try{const t=e.getHeader(h.NOTIFY);if(t){const s=JSON.parse(t);this.handleNotify(s)}}catch(t){O("error parse notify",t)}};handleNotify=e=>{switch(e.cmd){case R.CHANNELS:{const t=e;this.triggerChannelsNotify(t);break}case R.WEBCAST_STARTED:{const t=e;this.triggerWebcastStartedNotify(t);break}case R.WEBCAST_STOPPED:{const t=e;this.triggerWebcastStoppedNotify(t);break}case R.ADDED_TO_LIST_MODERATORS:{const t=e;this.triggerAddedToListModeratorsNotify(t);break}case R.REMOVED_FROM_LIST_MODERATORS:{const t=e;this.triggerRemovedFromListModeratorsNotify(t);break}case R.ACCEPTING_WORD_REQUEST:{const t=e;this.triggerParticipationAcceptingWordRequest(t);break}case R.CANCELLING_WORD_REQUEST:{const t=e;this.triggerParticipationCancellingWordRequest(t);break}case R.MOVE_REQUEST_TO_STREAM:{const t=e;this.triggerParticipantMoveRequestToStream(t);break}case R.ACCOUNT_CHANGED:{this.triggerAccountChangedNotify();break}case R.ACCOUNT_DELETED:{this.triggerAccountDeletedNotify();break}case R.CONFERENCE_PARTICIPANT_TOKEN_ISSUED:{const t=e;this.triggerConferenceParticipantTokenIssued(t);break}default:O("unknown cmd",e)}};handleNewInfo=e=>{const{originator:t}=e;if(t!==w.REMOTE)return;const{request:s}=e,i=s.getHeader(h.CONTENT_TYPE);if(i!==void 0)switch(i){case P.ENTER_ROOM:{this.triggerEnterRoom(s),this.maybeTriggerChannels(s);break}case P.NOTIFY:{this.maybeHandleNotify(s);break}case P.SHARE_STATE:{this.triggerShareState(s);break}case P.MAIN_CAM:{this.triggerMainCamControl(s);break}case P.MIC:{this.triggerMicControl(s);break}case P.USE_LICENSE:{this.triggerUseLicense(s);break}case P.PARTICIPANT_STATE:{this.maybeTriggerParticipantMoveRequest(s);break}}};triggerChannelsNotify=e=>{const t=e.input,s=e.output,i={inputChannels:t,outputChannels:s};this.events.trigger(T.CHANNELS_NOTIFY,i)};triggerWebcastStartedNotify=({body:{conference:e,type:t}})=>{const s={conference:e,type:t};this.events.trigger(T.WEBCAST_STARTED,s)};triggerWebcastStoppedNotify=({body:{conference:e,type:t}})=>{const s={conference:e,type:t};this.events.trigger(T.WEBCAST_STOPPED,s)};triggerAddedToListModeratorsNotify=({conference:e})=>{const t={conference:e};this.events.trigger(T.PARTICIPANT_ADDED_TO_LIST_MODERATORS,t)};triggerRemovedFromListModeratorsNotify=({conference:e})=>{const t={conference:e};this.events.trigger(T.PARTICIPANT_REMOVED_FROM_LIST_MODERATORS,t)};triggerParticipationAcceptingWordRequest=({body:{conference:e}})=>{const t={conference:e};this.events.trigger(T.PARTICIPATION_ACCEPTING_WORD_REQUEST,t)};triggerParticipationCancellingWordRequest=({body:{conference:e}})=>{const t={conference:e};this.events.trigger(T.PARTICIPATION_CANCELLING_WORD_REQUEST,t)};triggerParticipantMoveRequestToStream=({body:{conference:e}})=>{const t={conference:e};this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_STREAM,t)};triggerAccountChangedNotify=()=>{this.events.trigger(T.ACCOUNT_CHANGED,void 0)};triggerAccountDeletedNotify=()=>{this.events.trigger(T.ACCOUNT_DELETED,void 0)};triggerConferenceParticipantTokenIssued=({body:{conference:e,participant:t,jwt:s}})=>{const i={conference:e,participant:t,jwt:s};this.events.trigger(T.CONFERENCE_PARTICIPANT_TOKEN_ISSUED,i)};maybeTriggerChannels=e=>{const t=e.getHeader(h.INPUT_CHANNELS),s=e.getHeader(h.OUTPUT_CHANNELS);if(t&&s){const i={inputChannels:t,outputChannels:s};this.events.trigger(T.CHANNELS,i)}};triggerEnterRoom=e=>{const t=e.getHeader(h.CONTENT_ENTER_ROOM),s=e.getHeader(h.PARTICIPANT_NAME);this.events.trigger(T.ENTER_ROOM,{room:t,participantName:s})};triggerShareState=e=>{const t=e.getHeader(h.CONTENT_SHARE_STATE);if(t!==void 0)switch(t){case F.AVAILABLE_SECOND_REMOTE_STREAM:{this.events.trigger(T.AVAILABLE_SECOND_REMOTE_STREAM,void 0);break}case F.NOT_AVAILABLE_SECOND_REMOTE_STREAM:{this.events.trigger(T.NOT_AVAILABLE_SECOND_REMOTE_STREAM,void 0);break}case F.MUST_STOP_PRESENTATION:{this.events.trigger(T.MUST_STOP_PRESENTATION,void 0);break}}};maybeTriggerParticipantMoveRequest=e=>{const t=e.getHeader(h.CONTENT_PARTICIPANT_STATE);t===$.SPECTATOR&&this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS,void 0),t===$.PARTICIPANT&&this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS,void 0),t===$.SPECTATOR_OVER_SFU&&this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_OVER_SFU,void 0)};triggerMainCamControl=e=>{const t=e.getHeader(h.MAIN_CAM),s=e.getHeader(h.MEDIA_SYNC),i=s===W.ADMIN_SYNC_FORCED;if(t===f.ADMIN_START_MAIN_CAM){this.events.trigger(T.ADMIN_START_MAIN_CAM,{isSyncForced:i});return}if(t===f.ADMIN_STOP_MAIN_CAM){this.events.trigger(T.ADMIN_STOP_MAIN_CAM,{isSyncForced:i});return}(t===f.RESUME_MAIN_CAM||t===f.PAUSE_MAIN_CAM)&&s!==void 0&&this.events.trigger(T.ADMIN_FORCE_SYNC_MEDIA_STATE,{isSyncForced:i});const r=e.getHeader(h.MAIN_CAM_RESOLUTION);this.events.trigger(T.MAIN_CAM_CONTROL,{mainCam:t,resolutionMainCam:r})};triggerMicControl=e=>{const t=e.getHeader(h.MIC),i=e.getHeader(h.MEDIA_SYNC)===W.ADMIN_SYNC_FORCED;t===k.ADMIN_START_MIC?this.events.trigger(T.ADMIN_START_MIC,{isSyncForced:i}):t===k.ADMIN_STOP_MIC&&this.events.trigger(T.ADMIN_STOP_MIC,{isSyncForced:i})};triggerUseLicense=e=>{const t=e.getHeader(h.CONTENT_USE_LICENSE);this.events.trigger(T.USE_LICENSE,t)}}var M=(n=>(n.START_PRESENTATION="presentation:start",n.STARTED_PRESENTATION="presentation:started",n.END_PRESENTATION="presentation:end",n.ENDED_PRESENTATION="presentation:ended",n.FAILED_PRESENTATION="presentation:failed",n))(M||{});const ee=["presentation:start","presentation:started","presentation:end","presentation:ended","presentation:failed"],fe=1,De=n=>B.hasCanceledError(n);class ve{events;promisePendingStartPresentation;promisePendingStopPresentation;streamPresentationCurrent;cancelableSendPresentationWithRepeatedCalls;callManager;constructor({callManager:e}){this.callManager=e,this.events=new m.Events(ee),this.subscribe()}get isPendingPresentation(){return!!this.promisePendingStartPresentation||!!this.promisePendingStopPresentation}async startPresentation(e,t,{isNeedReinvite:s,maxBitrate:i,contentHint:r,sendEncodings:a,onAddedTransceiver:o}={},c){const g=this.getRtcSessionProtected();if(this.streamPresentationCurrent)throw new Error("Presentation is already started");return this.sendPresentationWithDuplicatedCalls(e,{rtcSession:g,stream:t,presentationOptions:{isNeedReinvite:s,maxBitrate:i,contentHint:r,sendEncodings:a,onAddedTransceiver:o},options:c})}async stopPresentation(e){this.cancelSendPresentationWithRepeatedCalls();const t=this.streamPresentationCurrent;let s=this.promisePendingStartPresentation??Promise.resolve(void 0);const i=this.callManager.getEstablishedRTCSession();return i&&t?s=e().then(async()=>i.stopPresentation(t)).catch(r=>{throw this.events.trigger(M.FAILED_PRESENTATION,r),r}):t&&this.events.trigger(M.ENDED_PRESENTATION,t),this.promisePendingStopPresentation=s,s.finally(()=>{this.resetPresentation()})}async updatePresentation(e,t,{contentHint:s,sendEncodings:i,onAddedTransceiver:r}={}){const a=this.getRtcSessionProtected();if(!this.streamPresentationCurrent)throw new Error("Presentation has not started yet");return this.promisePendingStartPresentation&&await this.promisePendingStartPresentation,this.sendPresentation(e,a,t,{contentHint:s,isNeedReinvite:!1,sendEncodings:i,onAddedTransceiver:r})}cancelSendPresentationWithRepeatedCalls(){this.cancelableSendPresentationWithRepeatedCalls?.cancel()}on(e,t){return this.events.on(e,t)}once(e,t){return this.events.once(e,t)}onceRace(e,t){return this.events.onceRace(e,t)}async wait(e){return this.events.wait(e)}off(e,t){this.events.off(e,t)}subscribe(){this.callManager.on("presentation:start",e=>{this.events.trigger(M.START_PRESENTATION,e)}),this.callManager.on("presentation:started",e=>{this.events.trigger(M.STARTED_PRESENTATION,e)}),this.callManager.on("presentation:end",e=>{this.events.trigger(M.END_PRESENTATION,e)}),this.callManager.on("presentation:ended",e=>{this.events.trigger(M.ENDED_PRESENTATION,e)}),this.callManager.on("presentation:failed",e=>{this.events.trigger(M.FAILED_PRESENTATION,e)}),this.callManager.on("failed",this.handleEnded),this.callManager.on("ended",this.handleEnded)}async sendPresentationWithDuplicatedCalls(e,{rtcSession:t,stream:s,presentationOptions:i,options:r={callLimit:fe}}){const a=async()=>this.sendPresentation(e,t,s,i),o=()=>!!this.streamPresentationCurrent;return this.cancelableSendPresentationWithRepeatedCalls=B.repeatedCallsAsync({targetFunction:a,isComplete:o,isRejectAsValid:!0,...r}),this.cancelableSendPresentationWithRepeatedCalls.then(c=>c)}async sendPresentation(e,t,s,{isNeedReinvite:i=!0,contentHint:r="detail",sendEncodings:a,onAddedTransceiver:o}){const c=b(s,{contentHint:r});if(c===void 0)throw new Error("No streamPresentationTarget");this.streamPresentationCurrent=c;const g=e().then(async()=>t.startPresentation(c,i,{sendEncodings:a,onAddedTransceiver:o})).then(()=>s).catch(E=>{throw this.removeStreamPresentationCurrent(),this.events.trigger(M.FAILED_PRESENTATION,E),E});return this.promisePendingStartPresentation=g,g.finally(()=>{this.promisePendingStartPresentation=void 0})}getRtcSessionProtected=()=>{const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");return e};handleEnded=()=>{this.reset()};reset(){this.cancelSendPresentationWithRepeatedCalls(),this.resetPresentation()}resetPresentation(){this.removeStreamPresentationCurrent(),this.promisePendingStartPresentation=void 0,this.promisePendingStopPresentation=void 0}removeStreamPresentationCurrent(){delete this.streamPresentationCurrent}}class ye{data={};getUa;constructor(e){this.getUa=e.getUa}isConfigured(){return this.getUa()!==void 0}get(){return{...this.data}}set(e){this.data={...e}}update(e,t){this.data[e]=t}clear(){this.data={}}isRegister(){return this.data.register===!0}getSipServerUrl(){return this.data.sipServerUrl}getDisplayName(){return this.data.displayName}getUser(){return this.data.user}getPassword(){return this.data.password}isRegisterEnabled(){return this.data.register===!0}}var A=(n=>(n.CONNECTING="connecting",n.CONNECTED="connected",n.DISCONNECTED="disconnected",n.NEW_RTC_SESSION="newRTCSession",n.REGISTERED="registered",n.UNREGISTERED="unregistered",n.REGISTRATION_FAILED="registrationFailed",n.NEW_MESSAGE="newMessage",n.SIP_EVENT="sipEvent",n))(A||{});const te=["connecting","connected","disconnected","newRTCSession","registered","unregistered","registrationFailed","newMessage","sipEvent"],ne=[...te],Ue=3;class be{cancelableConnectWithRepeatedCalls;JsSIP;events;uaFactory;stateMachine;registrationManager;getUa;setUa;getConnectionConfiguration;setConnectionConfiguration;updateConnectionConfiguration;setSipServerUrl;setSocket;constructor(e){this.JsSIP=e.JsSIP,this.events=e.events,this.uaFactory=e.uaFactory,this.stateMachine=e.stateMachine,this.registrationManager=e.registrationManager,this.getUa=e.getUa,this.setUa=e.setUa,this.getConnectionConfiguration=e.getConnectionConfiguration,this.setConnectionConfiguration=e.setConnectionConfiguration,this.updateConnectionConfiguration=e.updateConnectionConfiguration,this.setSipServerUrl=e.setSipServerUrl,this.setSocket=e.setSocket}connect=async(e,t)=>(this.cancelRequests(),this.connectWithDuplicatedCalls(e,t));set=async({displayName:e})=>new Promise((t,s)=>{const i=this.getUa();if(!i){s(new Error("this.ua is not initialized"));return}let r=!1;const a=this.getConnectionConfiguration();e!==void 0&&e!==a.displayName&&(r=i.set("display_name",j(e)),this.updateConnectionConfiguration("displayName",e));const o=r;o?t(o):s(new Error("nothing changed"))});disconnect=async()=>{const e=new Promise(s=>{this.events.once(A.DISCONNECTED,()=>{s()})}),t=this.getUa();return t?t.stop():this.events.trigger(A.DISCONNECTED,void 0),e.finally(()=>{this.setUa(void 0),this.stateMachine.reset()})};cancelRequests(){this.cancelConnectWithRepeatedCalls()}connectWithDuplicatedCalls=async(e,{callLimit:t=Ue}={})=>{const s=async()=>this.connectInner(e),i=r=>{const c=this.getUa()?.isConnected()===!0&&this.hasEqualConnectionConfiguration(e),g=r!=null&&!Pe(r);return c||g};return this.stateMachine.startConnect(),this.cancelableConnectWithRepeatedCalls=B.repeatedCallsAsync({targetFunction:s,isComplete:i,callLimit:t,isRejectAsValid:!0,isCheckBeforeCall:!1}),this.cancelableConnectWithRepeatedCalls.then(r=>{if(r instanceof this.JsSIP.UA)return r;throw r})};hasEqualConnectionConfiguration(e){const{configuration:t}=this.uaFactory.createConfiguration(e),i=this.getUa()?.configuration;return i?i.password===t.password&&i.register===t.register&&i.uri.toString()===t.uri&&i.display_name===t.display_name&&i.user_agent===t.user_agent&&i.sockets===t.sockets&&i.session_timers===t.session_timers&&i.register_expires===t.register_expires&&i.connection_recovery_min_interval===t.connection_recovery_min_interval&&i.connection_recovery_max_interval===t.connection_recovery_max_interval:!1}connectInner=async e=>this.initUa(e).then(async()=>this.start());initUa=async({user:e,password:t,sipServerUrl:s,sipWebSocketServerURL:i,remoteAddress:r,sessionTimers:a,registerExpires:o,connectionRecoveryMinInterval:c,connectionRecoveryMaxInterval:g,userAgent:E,displayName:u="",register:d=!1,extraHeaders:S=[]})=>{this.stateMachine.startInitUa(),this.setConnectionConfiguration({sipServerUrl:s,displayName:u,register:d,user:e,password:t}),this.getUa()&&await this.disconnect();const{ua:C,helpers:p}=this.uaFactory.createUAWithConfiguration({user:e,password:t,sipServerUrl:s,sipWebSocketServerURL:i,displayName:u,register:d,sessionTimers:a,registerExpires:o,connectionRecoveryMinInterval:c,connectionRecoveryMaxInterval:g,userAgent:E,remoteAddress:r,extraHeaders:S},this.events);return this.setUa(C),this.setSipServerUrl(p.getSipServerUrl),this.setSocket(p.socket),C};start=async()=>new Promise((e,t)=>{const s=this.getUa();if(!s){t(new Error("this.ua is not initialized"));return}let i;i=((c,g)=>{if(this.getConnectionConfiguration().register===!0)return this.registrationManager.subscribeToStartEvents(c,g);const u=A.CONNECTED,d=[A.DISCONNECTED];return this.events.on(u,c),d.forEach(S=>{this.events.on(S,g)}),()=>{this.events.off(u,c),d.forEach(S=>{this.events.off(S,g)})}})(()=>{i?.(),e(s)},c=>{i?.(),t(c)}),s.start()});cancelConnectWithRepeatedCalls(){this.cancelableConnectWithRepeatedCalls?.cancel()}}var se=(n=>(n.START_CONNECT="START_CONNECT",n.START_INIT_UA="START_INIT_UA",n.UA_CONNECTED="UA_CONNECTED",n.UA_REGISTERED="UA_REGISTERED",n.UA_UNREGISTERED="UA_UNREGISTERED",n.UA_DISCONNECTED="UA_DISCONNECTED",n.CONNECTION_FAILED="CONNECTION_FAILED",n.RESET="RESET",n))(se||{});const we=Q.setup({types:{context:{},events:{}},actions:{logTransition:(n,e)=>{O(`State transition: ${e.from} -> ${e.to} (${e.event})`)},logStateChange:(n,e)=>{O("ConnectionStateMachine state changed",e.state)}}}).createMachine({id:"connection",initial:"idle",context:{},states:{idle:{entry:{type:"logStateChange",params:{state:"idle"}},on:{START_CONNECT:{target:"connecting",actions:{type:"logTransition",params:{from:"idle",to:"connecting",event:"START_CONNECT"}}}}},connecting:{entry:{type:"logStateChange",params:{state:"connecting"}},on:{START_INIT_UA:{target:"initializing",actions:{type:"logTransition",params:{from:"connecting",to:"initializing",event:"START_INIT_UA"}}},UA_DISCONNECTED:{target:"disconnected",actions:{type:"logTransition",params:{from:"connecting",to:"disconnected",event:"UA_DISCONNECTED"}}},CONNECTION_FAILED:{target:"failed",actions:{type:"logTransition",params:{from:"connecting",to:"failed",event:"CONNECTION_FAILED"}}}}},initializing:{entry:{type:"logStateChange",params:{state:"initializing"}},on:{UA_CONNECTED:{target:"connected",actions:{type:"logTransition",params:{from:"initializing",to:"connected",event:"UA_CONNECTED"}}},UA_REGISTERED:{target:"registered",actions:{type:"logTransition",params:{from:"initializing",to:"registered",event:"UA_REGISTERED"}}},UA_DISCONNECTED:{target:"disconnected",actions:{type:"logTransition",params:{from:"initializing",to:"disconnected",event:"UA_DISCONNECTED"}}},CONNECTION_FAILED:{target:"failed",actions:{type:"logTransition",params:{from:"initializing",to:"failed",event:"CONNECTION_FAILED"}}}}},connected:{entry:{type:"logStateChange",params:{state:"connected"}},on:{UA_REGISTERED:{target:"registered",actions:{type:"logTransition",params:{from:"connected",to:"registered",event:"UA_REGISTERED"}}},UA_DISCONNECTED:{target:"disconnected",actions:{type:"logTransition",params:{from:"connected",to:"disconnected",event:"UA_DISCONNECTED"}}},CONNECTION_FAILED:{target:"failed",actions:{type:"logTransition",params:{from:"connected",to:"failed",event:"CONNECTION_FAILED"}}}}},registered:{entry:{type:"logStateChange",params:{state:"registered"}},on:{UA_UNREGISTERED:{target:"connected",actions:{type:"logTransition",params:{from:"registered",to:"connected",event:"UA_UNREGISTERED"}}},UA_DISCONNECTED:{target:"disconnected",actions:{type:"logTransition",params:{from:"registered",to:"disconnected",event:"UA_DISCONNECTED"}}},CONNECTION_FAILED:{target:"failed",actions:{type:"logTransition",params:{from:"registered",to:"failed",event:"CONNECTION_FAILED"}}}}},disconnected:{entry:{type:"logStateChange",params:{state:"disconnected"}},on:{RESET:{target:"idle",actions:{type:"logTransition",params:{from:"disconnected",to:"idle",event:"RESET"}}},START_CONNECT:{target:"connecting",actions:{type:"logTransition",params:{from:"disconnected",to:"connecting",event:"START_CONNECT"}}}}},failed:{entry:{type:"logStateChange",params:{state:"failed"}},on:{RESET:{target:"idle",actions:{type:"logTransition",params:{from:"failed",to:"idle",event:"RESET"}}},START_CONNECT:{target:"connecting",actions:{type:"logTransition",params:{from:"failed",to:"connecting",event:"START_CONNECT"}}}}}}});class Le{actor;stateChangeListeners=new Set;events;unsubscribeFromEvents;actorSubscription;constructor(e){this.events=e,this.actor=Q.createActor(we),this.actorSubscription=this.actor.subscribe(t=>{const s=t.value;this.stateChangeListeners.forEach(i=>{i(s)})}),this.actor.start(),this.subscribeToEvents()}get state(){return this.actor.getSnapshot().value}get isIdle(){return this.hasState("idle")}get isConnecting(){return this.hasState("connecting")}get isInitializing(){return this.hasState("initializing")}get isConnected(){return this.hasState("connected")}get isRegistered(){return this.hasState("registered")}get isDisconnected(){return this.hasState("disconnected")}get isFailed(){return this.hasState("failed")}get isPending(){return this.isConnecting||this.isInitializing}get isPendingConnect(){return this.isConnecting}get isPendingInitUa(){return this.isInitializing}get isActiveConnection(){return this.isConnected||this.isRegistered}startConnect(){this.toStartConnect()}startInitUa(){this.toStartInitUa()}reset(){this.toIdle()}destroy(){this.unsubscribeFromEvents?.(),this.actorSubscription?.unsubscribe(),this.actor.stop()}onStateChange(e){return this.stateChangeListeners.add(e),()=>{this.stateChangeListeners.delete(e)}}canTransition(e){return this.actor.getSnapshot().can({type:e})}getValidEvents(){return Object.values(se).filter(e=>this.canTransition(e))}hasState(e){return this.actor.getSnapshot().matches(e)}sendEvent(e){const t=this.actor.getSnapshot(),s={type:e};if(!t.can(s)){O(`Invalid transition: ${s.type} from ${this.state}. Event cannot be processed in current state.`);return}this.actor.send(s)}toStartConnect=()=>{this.sendEvent("START_CONNECT")};toStartInitUa=()=>{this.sendEvent("START_INIT_UA")};toConnected=()=>{this.sendEvent("UA_CONNECTED")};toRegistered=()=>{this.sendEvent("UA_REGISTERED")};toUnregistered=()=>{this.sendEvent("UA_UNREGISTERED")};toDisconnected=()=>{this.sendEvent("UA_DISCONNECTED")};toFailed=()=>{this.sendEvent("CONNECTION_FAILED")};toIdle=()=>{this.sendEvent("RESET")};subscribeToEvents(){this.events.on("connected",this.toConnected),this.events.on("registered",this.toRegistered),this.events.on("unregistered",this.toUnregistered),this.events.on("disconnected",this.toDisconnected),this.events.on("registrationFailed",this.toFailed),this.unsubscribeFromEvents=()=>{this.events.off("connected",this.toConnected),this.events.off("registered",this.toRegistered),this.events.off("unregistered",this.toUnregistered),this.events.off("disconnected",this.toDisconnected),this.events.off("registrationFailed",this.toFailed)}}}class Fe{events;getUaProtected;constructor(e){this.events=e.events,this.getUaProtected=e.getUaProtected}async register(){const e=this.getUaProtected();return new Promise((t,s)=>{e.on(A.REGISTERED,t),e.on(A.REGISTRATION_FAILED,s),e.register()})}async unregister(){const e=this.getUaProtected();return new Promise(t=>{e.on(A.UNREGISTERED,t),e.unregister()})}async tryRegister(){try{await this.unregister()}catch(e){O("tryRegister",e)}return this.register()}subscribeToStartEvents(e,t){const s=A.REGISTERED,i=[A.REGISTRATION_FAILED,A.DISCONNECTED];return this.events.on(s,e),i.forEach(r=>{this.events.on(r,t)}),()=>{this.events.off(s,e),i.forEach(r=>{this.events.off(r,t)})}}}class $e{uaFactory;getUaProtected;constructor(e){this.uaFactory=e.uaFactory,this.getUaProtected=e.getUaProtected}async sendOptions(e,t,s){const i=this.getUaProtected();return new Promise((r,a)=>{try{i.sendOptions(e,t,{extraHeaders:s,eventHandlers:{succeeded:()=>{r()},failed:a}})}catch(o){a(o)}})}async ping(e,t){const i=this.getUaProtected().configuration.uri;return this.sendOptions(i,e,t)}async checkTelephony({userAgent:e,displayName:t,sipServerUrl:s,sipWebSocketServerURL:i,remoteAddress:r,extraHeaders:a}){return new Promise((o,c)=>{const{configuration:g}=this.uaFactory.createConfiguration({sipWebSocketServerURL:i,displayName:t,userAgent:e,sipServerUrl:s}),E=this.uaFactory.createUA({...g,remoteAddress:r,extraHeaders:a}),u=()=>{const S=new Error("Telephony is not available");c(S)};E.once(A.DISCONNECTED,u);const d=()=>{E.removeAllListeners(),E.once(A.DISCONNECTED,()=>{o()}),E.stop()};E.once(A.CONNECTED,d),E.start()})}}const ke=n=>{const e=[];return n!==void 0&&n!==""&&e.push(`X-Vinteo-Remote: ${n}`),e};class D{JsSIP;constructor(e){this.JsSIP=e}static isRegisteredUA(e){return!!e&&e.isRegistered()}static validateConfiguration({register:e,password:t,user:s,sipServerUrl:i,sipWebSocketServerURL:r}){if(!i)throw new Error("sipServerUrl is required");if(!r)throw new Error("sipWebSocketServerURL is required");if(e&&(t===void 0||t===""))throw new Error("password is required for authorized connection");if(e&&(s===void 0||s===""))throw new Error("user is required for authorized connection")}static resolveAuthorizationUser(e,t){return e&&t!==void 0&&t.trim()!==""?t.trim():`${Se()}`}static buildExtraHeaders(e,t){const s=e!==void 0&&e!==""?ke(e):[];return t===void 0?s:[...s,...t]}createConfiguration({user:e,password:t,sipWebSocketServerURL:s,displayName:i="",sipServerUrl:r,register:a=!1,sessionTimers:o=!1,registerExpires:c=300,connectionRecoveryMinInterval:g=2,connectionRecoveryMaxInterval:E=6,userAgent:u}){D.validateConfiguration({register:a,password:t,user:e,sipServerUrl:r,sipWebSocketServerURL:s});const d=D.resolveAuthorizationUser(a,e),S=Ee(r),_=S(d),C=new this.JsSIP.WebSocketInterface(s);return{configuration:{password:t,register:a,uri:_,display_name:j(i),user_agent:u,sdpSemantics:"unified-plan",sockets:[C],session_timers:o,register_expires:c,connection_recovery_min_interval:g,connection_recovery_max_interval:E},helpers:{socket:C,getSipServerUrl:S}}}createUA({remoteAddress:e,extraHeaders:t,...s}){const i=new this.JsSIP.UA(s),r=D.buildExtraHeaders(e,t);return r.length>0&&i.registrator().setExtraHeaders(r),i}createUAWithConfiguration(e,t){const{configuration:s,helpers:i}=this.createConfiguration(e),r=this.createUA({...s,remoteAddress:e.remoteAddress,extraHeaders:e.extraHeaders});return t.eachTriggers((a,o)=>{const c=te.find(g=>g===o);c&&r.on(c,a)}),{ua:r,helpers:i}}}class We{events;ua;socket;uaFactory;registrationManager;stateMachine;connectionFlow;sipOperations;configurationManager;JsSIP;constructor({JsSIP:e}){this.JsSIP=e,this.events=new m.Events(ne),this.uaFactory=new D(e),this.registrationManager=new Fe({events:this.events,getUaProtected:this.getUaProtected}),this.stateMachine=new Le(this.events),this.configurationManager=new ye({getUa:this.getUa}),this.sipOperations=new $e({uaFactory:this.uaFactory,getUaProtected:this.getUaProtected}),this.connectionFlow=new be({JsSIP:this.JsSIP,events:this.events,uaFactory:this.uaFactory,stateMachine:this.stateMachine,registrationManager:this.registrationManager,getUa:this.getUa,getConnectionConfiguration:this.getConnectionConfiguration,setConnectionConfiguration:t=>{this.configurationManager.set(t)},updateConnectionConfiguration:(t,s)=>{this.configurationManager.update(t,s)},setUa:t=>{this.ua=t},setSipServerUrl:t=>{this.getSipServerUrl=t},setSocket:t=>{this.socket=t}})}get requested(){return this.stateMachine.isPending}get isPendingConnect(){return this.stateMachine.isPendingConnect}get isPendingInitUa(){return this.stateMachine.isPendingInitUa}get connectionState(){return this.stateMachine.state}get isRegistered(){return D.isRegisteredUA(this.ua)}get isRegisterConfig(){return this.configurationManager.isRegister()}connect=async(e,t)=>this.connectionFlow.connect(e,t);set=async({displayName:e})=>this.connectionFlow.set({displayName:e});disconnect=async()=>this.connectionFlow.disconnect();async register(){return this.registrationManager.register()}async unregister(){return this.registrationManager.unregister()}tryRegister=async()=>this.registrationManager.tryRegister();sendOptions=async(e,t,s)=>this.sipOperations.sendOptions(e,t,s);ping=async(e,t)=>this.sipOperations.ping(e,t);checkTelephony=async e=>this.sipOperations.checkTelephony(e);on(e,t){return this.events.on(e,t)}once(e,t){return this.events.once(e,t)}onceRace(e,t){return this.events.onceRace(e,t)}async wait(e){return this.events.wait(e)}off(e,t){this.events.off(e,t)}isConfigured(){return this.configurationManager.isConfigured()}getConnectionConfiguration=()=>this.configurationManager.get();destroy(){this.stateMachine.destroy()}getSipServerUrl=e=>e;getUaProtected=()=>{if(!this.ua)throw new Error("UA not initialized");return this.ua};getUa=()=>this.ua}var U=(n=>(n.INCOMING_CALL="incomingCall",n.DECLINED_INCOMING_CALL="declinedIncomingCall",n.TERMINATED_INCOMING_CALL="terminatedIncomingCall",n.FAILED_INCOMING_CALL="failedIncomingCall",n))(U||{}),V=(n=>(n.LOCAL="local",n.REMOTE="remote",n.SYSTEM="system",n))(V||{});const ie=["incomingCall","declinedIncomingCall","terminatedIncomingCall","failedIncomingCall"],Ve=486,qe=487;class Be{events;incomingRTCSession;connectionManager;constructor(e){this.connectionManager=e,this.events=new m.Events(ie),this.start()}get remoteCallerData(){return{displayName:this.incomingRTCSession?.remote_identity.display_name,host:this.incomingRTCSession?.remote_identity.uri.host,incomingNumber:this.incomingRTCSession?.remote_identity.uri.user,rtcSession:this.incomingRTCSession}}get isAvailableIncomingCall(){return!!this.incomingRTCSession}start(){this.subscribe()}stop(){this.unsubscribe(),this.removeIncomingSession()}getIncomingRTCSession=()=>{const{incomingRTCSession:e}=this;if(!e)throw new Error("No incomingRTCSession");return e};extractIncomingRTCSession=()=>{const e=this.getIncomingRTCSession();return this.removeIncomingSession(),e};async declineToIncomingCall({statusCode:e=qe}={}){return new Promise((t,s)=>{try{const i=this.getIncomingRTCSession(),r=this.remoteCallerData;this.removeIncomingSession(),this.events.trigger(U.DECLINED_INCOMING_CALL,r),i.terminate({status_code:e}),t()}catch(i){s(i)}})}async busyIncomingCall(){return this.declineToIncomingCall({statusCode:Ve})}on(e,t){return this.events.on(e,t)}once(e,t){return this.events.once(e,t)}onceRace(e,t){return this.events.onceRace(e,t)}async wait(e){return this.events.wait(e)}off(e,t){this.events.off(e,t)}subscribe(){this.connectionManager.on("newRTCSession",this.handleNewRTCSession)}unsubscribe(){this.connectionManager.off("newRTCSession",this.handleNewRTCSession)}handleNewRTCSession=({originator:e,session:t})=>{e===V.REMOTE&&this.setIncomingSession(t)};setIncomingSession(e){this.incomingRTCSession=e;const t=this.remoteCallerData;e.on("failed",s=>{this.removeIncomingSession(),s.originator===V.LOCAL?this.events.trigger(U.TERMINATED_INCOMING_CALL,t):this.events.trigger(U.FAILED_INCOMING_CALL,t)}),this.events.trigger(U.INCOMING_CALL,t)}removeIncomingSession(){delete this.incomingRTCSession}}const y=1e3;var l=(n=>(n.INBOUND_RTP="inbound-rtp",n.REMOTE_OUTBOUND_RTP="remote-outbound-rtp",n.MEDIA_SOURCE="media-source",n.OUTBOUND_RTP="outbound-rtp",n.REMOTE_INBOUND_RTP="remote-inbound-rtp",n.CODEC="codec",n.CANDIDATE_PAIR="candidate-pair",n.CERTIFICATE="certificate",n.TRANSPORT="transport",n.LOCAL_CANDIDATE="local-candidate",n.REMOTE_CANDIDATE="remote-candidate",n))(l||{});const re=["collected"],x=()=>"performance"in window?performance.now():Date.now(),L=n=>[...n.keys()].reduce((e,t)=>{const s=n.get(t);return s===void 0?e:{...e,[s.type]:s}},{}),He=n=>{if(!n)return{outboundRtp:void 0,codec:void 0,mediaSource:void 0,remoteInboundRtp:void 0};const e=L(n);return{outboundRtp:e[l.OUTBOUND_RTP],codec:e[l.CODEC],mediaSource:e[l.MEDIA_SOURCE],remoteInboundRtp:e[l.REMOTE_INBOUND_RTP]}},Y=n=>{if(!n)return{outboundRtp:void 0,codec:void 0,mediaSource:void 0,remoteInboundRtp:void 0};const e=L(n);return{outboundRtp:e[l.OUTBOUND_RTP],codec:e[l.CODEC],mediaSource:e[l.MEDIA_SOURCE],remoteInboundRtp:e[l.REMOTE_INBOUND_RTP]}},z=({videoReceiversStats:n,synchronizationSourcesVideo:e})=>{if(!n)return{inboundRtp:void 0,codec:void 0,synchronizationSources:e};const t=L(n);return{inboundRtp:t[l.INBOUND_RTP],codec:t[l.CODEC],synchronizationSources:e}},Ge=({audioReceiverStats:n,synchronizationSourcesAudio:e})=>{if(!n)return{inboundRtp:void 0,codec:void 0,remoteOutboundRtp:void 0,synchronizationSources:e};const t=L(n);return{inboundRtp:t[l.INBOUND_RTP],codec:t[l.CODEC],remoteOutboundRtp:t[l.REMOTE_OUTBOUND_RTP],synchronizationSources:e}},ae=n=>{if(!n)return{candidatePair:void 0,certificate:void 0,localCandidate:void 0,remoteCandidate:void 0,transport:void 0};const e=L(n);return{candidatePair:e[l.CANDIDATE_PAIR],certificate:e[l.CERTIFICATE],localCandidate:e[l.LOCAL_CANDIDATE],remoteCandidate:e[l.REMOTE_CANDIDATE],transport:e[l.TRANSPORT]}},xe=({audioSenderStats:n,videoSenderFirstStats:e,videoSenderSecondStats:t})=>({video:Y(e),secondVideo:Y(t),audio:He(n),additional:ae(n??e??t)}),Ye=({audioReceiverStats:n,videoReceiverFirstStats:e,videoReceiverSecondStats:t,synchronizationSources:s})=>({video:z({videoReceiversStats:e,synchronizationSourcesVideo:s.video}),secondVideo:z({videoReceiversStats:t,synchronizationSourcesVideo:s.video}),audio:Ge({audioReceiverStats:n,synchronizationSourcesAudio:s.audio}),additional:ae(n??e??t)}),ze=({audioSenderStats:n,videoSenderFirstStats:e,videoSenderSecondStats:t,audioReceiverStats:s,videoReceiverFirstStats:i,videoReceiverSecondStats:r,synchronizationSources:a})=>{const o=xe({audioSenderStats:n,videoSenderFirstStats:e,videoSenderSecondStats:t}),c=Ye({audioReceiverStats:s,videoReceiverFirstStats:i,videoReceiverSecondStats:r,synchronizationSources:a});return{outbound:o,inbound:c}},Qe=async n=>{const e="audio",t="video",s=n.getSenders(),i=s.find(d=>d.track?.kind===e),r=s.filter(d=>d.track?.kind===t),a=n.getReceivers(),o=a.find(d=>d.track.kind===e),c=a.filter(d=>d.track.kind===t),g={trackIdentifier:o?.track.id,item:o?.getSynchronizationSources()[0]},E={trackIdentifier:c[0]?.track.id,item:c[0]?.getSynchronizationSources()[0]},u={audio:g,video:E};return Promise.all([i?.getStats(),r[0]?.getStats(),r[1]?.getStats(),o?.getStats(),c[0]?.getStats(),c[1]?.getStats()]).then(d=>{const[S,_,C,p,v,ce]=d;return{synchronizationSources:u,audioSenderStats:S,videoSenderFirstStats:_,videoSenderSecondStats:C,audioReceiverStats:p,videoReceiverFirstStats:v,videoReceiverSecondStats:ce}})},Xe=n=>{O(String(n))};class oe{events;setTimeoutRequest;requesterAllStatistics=new ge.CancelableRequest(Qe);constructor(){this.events=new m.TypedEvents(re),this.setTimeoutRequest=new de.SetTimeoutRequest}get requested(){return this.setTimeoutRequest.requested}start(e,{interval:t=y,onError:s=Xe}={}){const i=this.resolveCollectStatistics(e,{onError:s});this.stop(),this.setTimeoutRequest.request(i,t)}stop(){this.setTimeoutRequest.cancelRequest(),this.requesterAllStatistics.cancelRequest()}on(e,t){return this.events.on(e,t)}once(e,t){return this.events.once(e,t)}onceRace(e,t){return this.events.onceRace(e,t)}async wait(e){return this.events.wait(e)}off(e,t){this.events.off(e,t)}resolveCollectStatistics=(e,{onError:t})=>()=>{const s=x();this.requesterAllStatistics.request(e).then(i=>{this.events.trigger("collected",ze(i));const a=x()-s;let o=y;a>48?o=y*4:a>32?o=y*3:a>16&&(o=y*2),this.start(e,{onError:t,interval:o})}).catch(i=>{t&&t(i)})}}class Je{statsPeerConnection;callManager;constructor({callManager:e}){this.callManager=e,this.statsPeerConnection=new oe,this.subscribe()}get events(){return this.statsPeerConnection.events}on(e,t){return this.statsPeerConnection.on(e,t)}once(e,t){return this.statsPeerConnection.once(e,t)}onceRace(e,t){return this.statsPeerConnection.onceRace(e,t)}async wait(e){return this.statsPeerConnection.wait(e)}off(e,t){this.statsPeerConnection.off(e,t)}subscribe(){this.callManager.on("peerconnection:confirmed",this.handleStarted),this.callManager.on("failed",this.handleEnded),this.callManager.on("ended",this.handleEnded)}handleStarted=e=>{this.statsPeerConnection.start(e)};handleEnded=()=>{this.statsPeerConnection.stop()}}const je=ne.map(n=>`connection:${n}`),Ke=J.map(n=>`call:${n}`),Ze=Z.map(n=>`api:${n}`),et=ie.map(n=>`incoming-call:${n}`),tt=ee.map(n=>`presentation:${n}`),nt=re.map(n=>`stats:${n}`),st=[...je,...Ke,...Ze,...et,...tt,...nt];class it{events;connectionManager;callManager;apiManager;incomingCallManager;presentationManager;statsManager;constructor({JsSIP:e}){this.events=new m.Events(st),this.connectionManager=new We({JsSIP:e}),this.callManager=new Re,this.apiManager=new me({connectionManager:this.connectionManager,callManager:this.callManager}),this.incomingCallManager=new Be(this.connectionManager),this.presentationManager=new ve({callManager:this.callManager}),this.statsManager=new Je({callManager:this.callManager}),this.subscribe()}get requestedConnection(){return this.connectionManager.requested}get isPendingConnect(){return this.connectionManager.isPendingConnect}get isPendingInitUa(){return this.connectionManager.isPendingInitUa}get connectionState(){return this.connectionManager.connectionState}get isRegistered(){return this.connectionManager.isRegistered}get isRegisterConfig(){return this.connectionManager.isRegisterConfig}get socket(){return this.connectionManager.socket}get requestedCall(){return this.callManager.requested}get connection(){return this.callManager.connection}get establishedRTCSession(){return this.callManager.establishedRTCSession}get isCallActive(){return this.callManager.isCallActive}get remoteCallerData(){return this.incomingCallManager.remoteCallerData}get isAvailableIncomingCall(){return this.incomingCallManager.isAvailableIncomingCall}on(e,t){return this.events.on(e,t)}once(e,t){return this.events.once(e,t)}onceRace(e,t){return this.events.onceRace(e,t)}async wait(e){return this.events.wait(e)}off(e,t){this.events.off(e,t)}connect=async(...e)=>this.connectionManager.connect(...e);set=async(...e)=>this.connectionManager.set(...e);disconnect=async()=>this.connectionManager.disconnect();register=async()=>this.connectionManager.register();unregister=async()=>this.connectionManager.unregister();tryRegister=async()=>this.connectionManager.tryRegister();sendOptions=async(e,t,s)=>this.connectionManager.sendOptions(e,t,s);ping=async(e,t)=>this.connectionManager.ping(e,t);checkTelephony=async e=>this.connectionManager.checkTelephony(e);isConfigured=()=>this.connectionManager.isConfigured();getConnectionConfiguration=()=>this.connectionManager.getConnectionConfiguration();getSipServerUrl=e=>this.connectionManager.getSipServerUrl(e);call=async e=>this.callManager.startCall(this.connectionManager.getUaProtected(),this.getSipServerUrl,e);hangUp=async()=>this.callManager.endCall();answerToIncomingCall=async e=>this.callManager.answerToIncomingCall(this.incomingCallManager.extractIncomingRTCSession,e);declineToIncomingCall=async(...e)=>this.incomingCallManager.declineToIncomingCall(...e);getEstablishedRTCSession=()=>this.callManager.getEstablishedRTCSession();getCallConfiguration=()=>this.callManager.getCallConfiguration();getRemoteStreams=()=>this.callManager.getRemoteStreams();replaceMediaStream=async(...e)=>this.callManager.replaceMediaStream(...e);async startPresentation(e,t={}){const{isP2P:s,callLimit:i,...r}=t;return this.presentationManager.startPresentation(async()=>{s===!0?(await this.apiManager.sendMustStopPresentationP2P(),await this.apiManager.askPermissionToStartPresentationP2P()):await this.apiManager.askPermissionToStartPresentation()},e,r,i===void 0?void 0:{callLimit:i})}async stopPresentation(e={}){const{isP2P:t}=e;return this.presentationManager.stopPresentation(async()=>{await(t===!0?this.apiManager.sendMustStopPresentationP2P():this.apiManager.sendStoppedPresentation())})}async updatePresentation(e,t={}){const{isP2P:s,...i}=t;return this.presentationManager.updatePresentation(async()=>{s===!0?(await this.apiManager.sendMustStopPresentationP2P(),await this.apiManager.askPermissionToStartPresentationP2P()):await this.apiManager.askPermissionToStartPresentation()},e,i)}async waitChannels(...e){return this.apiManager.waitChannels(...e)}async waitSyncMediaState(...e){return this.apiManager.waitSyncMediaState(...e)}async sendDTMF(...e){return this.apiManager.sendDTMF(...e)}async sendChannels(...e){return this.apiManager.sendChannels(...e)}async sendMediaState(...e){return this.apiManager.sendMediaState(...e)}async sendRefusalToTurnOn(...e){return this.apiManager.sendRefusalToTurnOn(...e)}async sendRefusalToTurnOnMic(...e){return this.apiManager.sendRefusalToTurnOnMic(...e)}async sendRefusalToTurnOnCam(...e){return this.apiManager.sendRefusalToTurnOnCam(...e)}async sendMustStopPresentationP2P(...e){return this.apiManager.sendMustStopPresentationP2P(...e)}async sendStoppedPresentationP2P(...e){return this.apiManager.sendStoppedPresentationP2P(...e)}async sendStoppedPresentation(...e){return this.apiManager.sendStoppedPresentation(...e)}async askPermissionToStartPresentationP2P(...e){return this.apiManager.askPermissionToStartPresentationP2P(...e)}async askPermissionToStartPresentation(...e){return this.apiManager.askPermissionToStartPresentation(...e)}async askPermissionToEnableCam(...e){return this.apiManager.askPermissionToEnableCam(...e)}subscribe(){this.connectionManager.events.eachTriggers((e,t)=>{this.connectionManager.on(t,s=>{this.events.trigger(`connection:${t}`,s)})}),this.callManager.events.eachTriggers((e,t)=>{this.callManager.on(t,s=>{this.events.trigger(`call:${t}`,s)})}),this.apiManager.events.eachTriggers((e,t)=>{this.apiManager.on(t,s=>{this.events.trigger(`api:${t}`,s)})}),this.incomingCallManager.events.eachTriggers((e,t)=>{this.incomingCallManager.on(t,s=>{this.events.trigger(`incoming-call:${t}`,s)})}),this.presentationManager.events.eachTriggers((e,t)=>{this.presentationManager.on(t,s=>{this.events.trigger(`presentation:${t}`,s)})}),this.statsManager.events.eachTriggers((e,t)=>{this.statsManager.on(t,s=>{this.events.trigger(`stats:${t}`,s)})})}}exports.ECallCause=H;exports.EEventsMainCAM=f;exports.EStatsTypes=l;exports.EUseLicense=K;exports.Originator=w;exports.SipConnector=it;exports.StatsPeerConnection=oe;exports.disableDebug=Ie;exports.enableDebug=_e;exports.hasCanceledStartPresentationError=De;exports.logger=O;exports.prepareMediaStream=b;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class MockRequest {
|
|
2
|
+
private headers;
|
|
3
|
+
static createInfoEvent(originator: string, request: MockRequest): {
|
|
4
|
+
readonly originator: string;
|
|
5
|
+
readonly request: MockRequest;
|
|
6
|
+
};
|
|
7
|
+
setHeader(name: string, value: string): void;
|
|
8
|
+
getHeader(name: string): string | undefined;
|
|
9
|
+
}
|
|
@@ -31,7 +31,8 @@ export declare enum EShareState {
|
|
|
31
31
|
}
|
|
32
32
|
export declare enum EParticipantType {
|
|
33
33
|
SPECTATOR = "SPECTATOR",
|
|
34
|
-
PARTICIPANT = "PARTICIPANT"
|
|
34
|
+
PARTICIPANT = "PARTICIPANT",
|
|
35
|
+
SPECTATOR_OVER_SFU = "SPECTATOROVERSFU"
|
|
35
36
|
}
|
|
36
37
|
export declare enum EContentTypeReceived {
|
|
37
38
|
ENTER_ROOM = "application/vinteo.webrtc.roomname",
|
|
@@ -6,6 +6,7 @@ export declare enum EEvent {
|
|
|
6
6
|
PARTICIPANT_MOVE_REQUEST_TO_STREAM = "participant:move-request-to-stream",
|
|
7
7
|
PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS = "participant:move-request-to-spectators",
|
|
8
8
|
PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS = "participant:move-request-to-participants",
|
|
9
|
+
PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS_OVER_SFU = "participant:move-request-to-spectators-over-sfu",
|
|
9
10
|
PARTICIPATION_ACCEPTING_WORD_REQUEST = "participation:accepting-word-request",
|
|
10
11
|
PARTICIPATION_CANCELLING_WORD_REQUEST = "participation:cancelling-word-request",
|
|
11
12
|
WEBCAST_STARTED = "webcast:started",
|
|
@@ -28,6 +29,6 @@ export declare enum EEvent {
|
|
|
28
29
|
MUST_STOP_PRESENTATION = "mustStopPresentation",
|
|
29
30
|
NEW_DTMF = "newDTMF"
|
|
30
31
|
}
|
|
31
|
-
export declare const EVENT_NAMES: readonly ["participation:accepting-word-request", "participation:cancelling-word-request", "participant:move-request-to-stream", "channels:notify", "conference:participant-token-issued", "account:changed", "account:deleted", "webcast:started", "webcast:stopped", "participant:added-to-list-moderators", "participant:removed-from-list-moderators", "participant:move-request-to-spectators", "participant:move-request-to-participants", "channels", "enterRoom", "shareState", "main-cam-control", "useLicense", "admin-start-main-cam", "admin-stop-main-cam", "admin-start-mic", "admin-stop-mic", "admin-force-sync-media-state", "availableSecondRemoteStream", "notAvailableSecondRemoteStream", "mustStopPresentation", "newDTMF"];
|
|
32
|
+
export declare const EVENT_NAMES: readonly ["participation:accepting-word-request", "participation:cancelling-word-request", "participant:move-request-to-stream", "channels:notify", "conference:participant-token-issued", "account:changed", "account:deleted", "webcast:started", "webcast:stopped", "participant:added-to-list-moderators", "participant:removed-from-list-moderators", "participant:move-request-to-spectators", "participant:move-request-to-participants", "participant:move-request-to-spectators-over-sfu", "channels", "enterRoom", "shareState", "main-cam-control", "useLicense", "admin-start-main-cam", "admin-stop-main-cam", "admin-start-mic", "admin-stop-mic", "admin-force-sync-media-state", "availableSecondRemoteStream", "notAvailableSecondRemoteStream", "mustStopPresentation", "newDTMF"];
|
|
32
33
|
export type TEvent = (typeof EVENT_NAMES)[number];
|
|
33
34
|
export type TEvents = Events<typeof EVENT_NAMES>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RTCSession } from '@krivega/jssip';
|
|
2
1
|
import { AbstractCallStrategy } from './AbstractCallStrategy';
|
|
2
|
+
import { RTCSession } from '@krivega/jssip';
|
|
3
3
|
import { TEvents } from './eventNames';
|
|
4
4
|
import { ICallStrategy, TOntrack } from './types';
|
|
5
5
|
export declare class MCUCallStrategy extends AbstractCallStrategy {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { RegisteredEvent, UA, UnRegisteredEvent, WebSocketInterface } from '@krivega/jssip';
|
|
2
1
|
import { Events } from 'events-constructor';
|
|
2
|
+
import { EVENT_NAMES, TEvent } from './eventNames';
|
|
3
|
+
import { default as SipOperations, TParametersCheckTelephony } from './SipOperations';
|
|
4
|
+
import { RegisteredEvent, UA, UnRegisteredEvent, WebSocketInterface } from '@krivega/jssip';
|
|
3
5
|
import { TGetServerUrl } from '../CallManager';
|
|
4
6
|
import { TJsSIP } from '../types';
|
|
5
7
|
import { TConnect, TSet } from './ConnectionFlow';
|
|
6
|
-
import { TEvent, EVENT_NAMES } from './eventNames';
|
|
7
|
-
import { TParametersCheckTelephony, default as SipOperations } from './SipOperations';
|
|
8
8
|
export default class ConnectionManager {
|
|
9
9
|
readonly events: Events<typeof EVENT_NAMES>;
|
|
10
10
|
ua?: UA;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
1
|
+
declare const getExtraHeadersRemoteAddress: (remoteAddress?: string) => string[];
|
|
2
|
+
export default getExtraHeadersRemoteAddress;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RTCSession } from '@krivega/jssip';
|
|
2
1
|
import { Events } from 'events-constructor';
|
|
2
|
+
import { EVENT_NAMES, TEvent } from './eventNames';
|
|
3
|
+
import { RTCSession } from '@krivega/jssip';
|
|
3
4
|
import { ConnectionManager } from '../ConnectionManager';
|
|
4
|
-
import { TEvent, EVENT_NAMES } from './eventNames';
|
|
5
5
|
type TRemoteCallerData = {
|
|
6
6
|
displayName?: string;
|
|
7
7
|
host?: string;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Events } from 'events-constructor';
|
|
2
2
|
import { ApiManager } from '../ApiManager';
|
|
3
|
-
import {
|
|
3
|
+
import { CallManager, TGetServerUrl } from '../CallManager';
|
|
4
4
|
import { ConnectionManager } from '../ConnectionManager';
|
|
5
5
|
import { IncomingCallManager } from '../IncomingCallManager';
|
|
6
6
|
import { PresentationManager } from '../PresentationManager';
|
|
7
|
+
import { StatsManager } from '../StatsManager';
|
|
8
|
+
import { EVENT_NAMES, TEvent } from './eventNames';
|
|
7
9
|
import { TContentHint, TOnAddedTransceiver } from '../PresentationManager/types';
|
|
8
10
|
import { TJsSIP } from '../types';
|
|
9
|
-
import { TEvent, EVENT_NAMES } from './eventNames';
|
|
10
11
|
declare class SipConnector {
|
|
11
12
|
readonly events: Events<typeof EVENT_NAMES>;
|
|
12
13
|
readonly connectionManager: ConnectionManager;
|
|
@@ -14,6 +15,7 @@ declare class SipConnector {
|
|
|
14
15
|
readonly apiManager: ApiManager;
|
|
15
16
|
readonly incomingCallManager: IncomingCallManager;
|
|
16
17
|
readonly presentationManager: PresentationManager;
|
|
18
|
+
readonly statsManager: StatsManager;
|
|
17
19
|
constructor({ JsSIP }: {
|
|
18
20
|
JsSIP: TJsSIP;
|
|
19
21
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Events } from 'events-constructor';
|
|
2
|
-
export declare const EVENT_NAMES: readonly ("connection:connecting" | "connection:connected" | "connection:disconnected" | "connection:newRTCSession" | "connection:registered" | "connection:unregistered" | "connection:registrationFailed" | "connection:newMessage" | "connection:sipEvent" | "call:peerconnection" | "call:connecting" | "call:sending" | "call:progress" | "call:accepted" | "call:confirmed" | "call:ended" | "call:failed" | "call:newDTMF" | "call:newInfo" | "call:reinvite" | "call:update" | "call:refer" | "call:replaces" | "call:sdp" | "call:icecandidate" | "call:getusermediafailed" | "call:peerconnection:createofferfailed" | "call:peerconnection:createanswerfailed" | "call:peerconnection:setlocaldescriptionfailed" | "call:peerconnection:setremotedescriptionfailed" | "call:presentation:start" | "call:presentation:started" | "call:presentation:end" | "call:presentation:ended" | "call:presentation:failed" | "call:peerconnection:confirmed" | "call:peerconnection:ontrack" | "call:ended:fromserver" | "api:newDTMF" | "api:channels:notify" | "api:participant:added-to-list-moderators" | "api:participant:removed-from-list-moderators" | "api:participant:move-request-to-stream" | "api:participant:move-request-to-spectators" | "api:participant:move-request-to-participants" | "api:participation:accepting-word-request" | "api:participation:cancelling-word-request" | "api:webcast:started" | "api:webcast:stopped" | "api:account:changed" | "api:account:deleted" | "api:conference:participant-token-issued" | "api:channels" | "api:enterRoom" | "api:shareState" | "api:main-cam-control" | "api:useLicense" | "api:admin-start-main-cam" | "api:admin-stop-main-cam" | "api:admin-start-mic" | "api:admin-stop-mic" | "api:admin-force-sync-media-state" | "api:availableSecondRemoteStream" | "api:notAvailableSecondRemoteStream" | "api:mustStopPresentation" | "incoming-call:incomingCall" | "incoming-call:declinedIncomingCall" | "incoming-call:terminatedIncomingCall" | "incoming-call:failedIncomingCall" | "presentation:presentation:start" | "presentation:presentation:started" | "presentation:presentation:end" | "presentation:presentation:ended" | "presentation:presentation:failed")[];
|
|
2
|
+
export declare const EVENT_NAMES: readonly ("connection:connecting" | "connection:connected" | "connection:disconnected" | "connection:newRTCSession" | "connection:registered" | "connection:unregistered" | "connection:registrationFailed" | "connection:newMessage" | "connection:sipEvent" | "call:peerconnection" | "call:connecting" | "call:sending" | "call:progress" | "call:accepted" | "call:confirmed" | "call:ended" | "call:failed" | "call:newDTMF" | "call:newInfo" | "call:reinvite" | "call:update" | "call:refer" | "call:replaces" | "call:sdp" | "call:icecandidate" | "call:getusermediafailed" | "call:peerconnection:createofferfailed" | "call:peerconnection:createanswerfailed" | "call:peerconnection:setlocaldescriptionfailed" | "call:peerconnection:setremotedescriptionfailed" | "call:presentation:start" | "call:presentation:started" | "call:presentation:end" | "call:presentation:ended" | "call:presentation:failed" | "call:peerconnection:confirmed" | "call:peerconnection:ontrack" | "call:ended:fromserver" | "api:newDTMF" | "api:channels:notify" | "api:participant:added-to-list-moderators" | "api:participant:removed-from-list-moderators" | "api:participant:move-request-to-stream" | "api:participant:move-request-to-spectators" | "api:participant:move-request-to-participants" | "api:participant:move-request-to-spectators-over-sfu" | "api:participation:accepting-word-request" | "api:participation:cancelling-word-request" | "api:webcast:started" | "api:webcast:stopped" | "api:account:changed" | "api:account:deleted" | "api:conference:participant-token-issued" | "api:channels" | "api:enterRoom" | "api:shareState" | "api:main-cam-control" | "api:useLicense" | "api:admin-start-main-cam" | "api:admin-stop-main-cam" | "api:admin-start-mic" | "api:admin-stop-mic" | "api:admin-force-sync-media-state" | "api:availableSecondRemoteStream" | "api:notAvailableSecondRemoteStream" | "api:mustStopPresentation" | "incoming-call:incomingCall" | "incoming-call:declinedIncomingCall" | "incoming-call:terminatedIncomingCall" | "incoming-call:failedIncomingCall" | "presentation:presentation:start" | "presentation:presentation:started" | "presentation:presentation:end" | "presentation:presentation:ended" | "presentation:presentation:failed" | "stats:collected")[];
|
|
3
3
|
export type TEvent = (typeof EVENT_NAMES)[number];
|
|
4
4
|
export type TEvents = Events<typeof EVENT_NAMES>;
|
|
@@ -2,7 +2,19 @@ import { UA } from '@krivega/jssip';
|
|
|
2
2
|
import { EUseLicense } from '../ApiManager';
|
|
3
3
|
import { TContentHint } from '../PresentationManager';
|
|
4
4
|
import { SipConnector } from '../SipConnector';
|
|
5
|
+
import { TEventMap as TStatsEventMap } from '../StatsManager';
|
|
5
6
|
import { TSimulcastEncoding } from '../types';
|
|
7
|
+
type TEnterRoomHandlers = {
|
|
8
|
+
onEnterPurgatory?: () => void;
|
|
9
|
+
onEnterConference?: (parameters_: {
|
|
10
|
+
isSuccessProgressCall: boolean;
|
|
11
|
+
}) => void;
|
|
12
|
+
};
|
|
13
|
+
export declare const TEST_HOOKS: {
|
|
14
|
+
handleEnterRoomEvent: (room: string, isSuccessProgressCall: boolean, { onEnterPurgatory, onEnterConference }: TEnterRoomHandlers) => void;
|
|
15
|
+
handleOnceRaceEvent: (unsubscribeEnterConference: () => void, onEndedCall?: () => void) => void;
|
|
16
|
+
handleFailProgressEvent: (onFailProgressCall: (() => void) | undefined, unsubscribeEnterConference: () => void, error: Error) => never;
|
|
17
|
+
};
|
|
6
18
|
interface IProxyMethods {
|
|
7
19
|
on: SipConnector['on'];
|
|
8
20
|
once: SipConnector['once'];
|
|
@@ -143,7 +155,7 @@ declare class SipConnectorFacade implements IProxyMethods {
|
|
|
143
155
|
isEnabledCam: boolean;
|
|
144
156
|
isEnabledMic: boolean;
|
|
145
157
|
}) => Promise<void>;
|
|
146
|
-
replaceMediaStream: (mediaStream: MediaStream, { deleteExisting, addMissing, forceRenegotiation, contentHint, simulcastEncodings, degradationPreference, sendEncodings, }
|
|
158
|
+
replaceMediaStream: (mediaStream: MediaStream, { deleteExisting, addMissing, forceRenegotiation, contentHint, simulcastEncodings, degradationPreference, sendEncodings, }: {
|
|
147
159
|
deleteExisting?: boolean;
|
|
148
160
|
addMissing?: boolean;
|
|
149
161
|
forceRenegotiation?: boolean;
|
|
@@ -169,5 +181,7 @@ declare class SipConnectorFacade implements IProxyMethods {
|
|
|
169
181
|
onMustStopPresentation: (handler: () => void) => (() => void);
|
|
170
182
|
onMoveToSpectators: (handler: () => void) => (() => void);
|
|
171
183
|
onMoveToParticipants: (handler: () => void) => (() => void);
|
|
184
|
+
onStats: (handler: (data: TStatsEventMap["collected"]) => void) => (() => void);
|
|
185
|
+
offStats: (handler: (data: TStatsEventMap["collected"]) => void) => void;
|
|
172
186
|
}
|
|
173
187
|
export default SipConnectorFacade;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { StatsPeerConnection, TEventMap } from '../StatsPeerConnection';
|
|
2
|
+
import { CallManager } from '../CallManager';
|
|
3
|
+
declare class StatsManager {
|
|
4
|
+
readonly statsPeerConnection: StatsPeerConnection;
|
|
5
|
+
private readonly callManager;
|
|
6
|
+
constructor({ callManager }: {
|
|
7
|
+
callManager: CallManager;
|
|
8
|
+
});
|
|
9
|
+
get events(): import('../StatsPeerConnection/eventNames').TEvents;
|
|
10
|
+
on<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): () => void;
|
|
11
|
+
once<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): () => void;
|
|
12
|
+
onceRace<T extends keyof TEventMap>(eventNames: T[], handler: (data: TEventMap[T], eventName: string) => void): () => void;
|
|
13
|
+
wait<T extends keyof TEventMap>(eventName: T): Promise<TEventMap[T]>;
|
|
14
|
+
off<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): void;
|
|
15
|
+
private subscribe;
|
|
16
|
+
private readonly handleStarted;
|
|
17
|
+
private readonly handleEnded;
|
|
18
|
+
}
|
|
19
|
+
export default StatsManager;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TEventMap, TEvents } from './eventNames';
|
|
2
|
+
declare class StatsPeerConnection {
|
|
3
|
+
readonly events: TEvents;
|
|
4
|
+
private readonly setTimeoutRequest;
|
|
5
|
+
private readonly requesterAllStatistics;
|
|
6
|
+
constructor();
|
|
7
|
+
get requested(): boolean;
|
|
8
|
+
start(peerConnection: RTCPeerConnection, { interval, onError, }?: {
|
|
9
|
+
onError?: (error: unknown) => void;
|
|
10
|
+
interval?: number;
|
|
11
|
+
}): void;
|
|
12
|
+
stop(): void;
|
|
13
|
+
on<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): () => void;
|
|
14
|
+
once<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): () => void;
|
|
15
|
+
onceRace<T extends keyof TEventMap>(eventNames: T[], handler: (data: TEventMap[T], eventName: string) => void): () => void;
|
|
16
|
+
wait<T extends keyof TEventMap>(eventName: T): Promise<TEventMap[T]>;
|
|
17
|
+
off<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): void;
|
|
18
|
+
private readonly resolveCollectStatistics;
|
|
19
|
+
}
|
|
20
|
+
export default StatsPeerConnection;
|