sip-connector 14.1.0-alpha.7 → 14.1.0-alpha.9
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/dist/@SipConnector-BOHJ000Z.cjs +1 -0
- package/dist/{@SipConnector-7Q9X7euI.js → @SipConnector-BxitfweK.js} +34 -34
- package/dist/ApiManager/constants.d.ts +1 -1
- package/dist/ApiManager/index.d.ts +1 -1
- package/dist/CallManager/index.d.ts +1 -1
- package/dist/ConnectionManager/@ConnectionManager.d.ts +2 -1
- package/dist/ConnectionManager/ConnectionFlow.d.ts +2 -1
- package/dist/SipConnector/@SipConnector.d.ts +2 -2
- package/dist/doMock.cjs +1 -1
- package/dist/doMock.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -2
- package/dist/types.d.ts +0 -1
- package/package.json +1 -1
- package/dist/@SipConnector-C09fG-9w.cjs +0 -1
- package/dist/headers.d.ts +0 -37
- /package/dist/{getExtraHeadersRemoteAddress.d.ts → ConnectionManager/getExtraHeadersRemoteAddress.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const f=require("events-constructor");require("@krivega/cancelable-promise");const k=require("debug"),W=require("repeated-calls"),G=require("xstate");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||{}),v=(n=>(n.LOCAL="local",n.REMOTE="remote",n.SYSTEM="system",n))(v||{});const B=["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"],Z=["peerconnection:confirmed","peerconnection:ontrack","ended:fromserver"],q=[...B,...Z];function ee(n){return e=>`sip:${e}@${n}`}const te=(n,e)=>()=>Math.floor(Math.random()*(e-n))+n,x=n=>n.trim().replaceAll(" ","_"),ne=te(1e5,99999999),se=n=>n.some(t=>{const{kind:s}=t;return s==="video"}),ie=(n,e)=>{n.getVideoTracks().forEach(s=>{"contentHint"in s&&s.contentHint!==e&&(s.contentHint=e)})},y=(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"&&ie(o,s),o};class re{isPendingCall=!1;isPendingAnswer=!1;rtcSession;remoteStreams={};events;callConfiguration={};constructor(e){this.events=e}}var V=(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))(V||{});class ae{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 oe extends re{remoteStreamsManager=new ae;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:d,offerToReceiveAudio:E=!0,offerToReceiveVideo:l=!0,sendEncodings:S,onAddedTransceiver:I})=>(this.isPendingCall=!0,new Promise((C,P)=>{this.callConfiguration.number=s,this.callConfiguration.answer=!1,this.handleCall({ontrack:a}).then(C).catch(b=>{P(b)}),this.rtcSession=e.call(t(s),{extraHeaders:r,mediaStream:y(i,{directionVideo:c,directionAudio:g,contentHint:d}),directionVideo:c,directionAudio:g,pcConfig:{iceServers:o},rtcOfferConstraints:{offerToReceiveAudio:E,offerToReceiveVideo:l},sendEncodings:S,onAddedTransceiver:I}),this.subscribeToSessionEvents(this.rtcSession)}).finally(()=>{this.isPendingCall=!1}));async endCall(){const{rtcSession:e}=this;if(e&&!e.isEnded())return e.terminateAsync({cause:V.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:d,sendEncodings:E,onAddedTransceiver:l})=>(this.isPendingAnswer=!0,new Promise((S,I)=>{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(b=>{I(b)});const P=y(t,{directionVideo:a,directionAudio:o,contentHint:d});C.answer({extraHeaders:i,directionVideo:a,directionAudio:o,mediaStream:P,pcConfig:{iceServers:r},rtcOfferConstraints:{offerToReceiveAudio:c,offerToReceiveVideo:g},sendEncodings:E,onAddedTransceiver:l})}catch(C){I(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 se(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=y(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,d),this.events.on(N.CONFIRMED,E)},r=()=>{this.events.off(N.PEER_CONNECTION,d),this.events.off(N.CONFIRMED,E)},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=l=>{r(),o(),s(l)};let g;const d=({peerconnection:l})=>{g=l;const S=I=>{this.events.trigger(N.PEER_CONNECTION_ONTRACK,l),e&&e(I)};l.ontrack=S,this.disposers.add(()=>{l.ontrack=null})},E=()=>{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=B.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===v.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 ce{events;strategy;constructor(e){this.events=new f(q),this.strategy=e??new oe(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 H="sip-connector",p=k(H),ge=()=>{k.enable(H)},Te=()=>{k.enable(`-${H}`)},he="Error decline with 603",de=1006,le=n=>typeof n=="object"&&n!==null&&"code"in n&&n.code===de,Ee=n=>n.message===he;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||{}),U=(n=>(n.AVAILABLE_SECOND_REMOTE_STREAM="YOUCANRECEIVECONTENT",n.NOT_AVAILABLE_SECOND_REMOTE_STREAM="CONTENTEND",n.MUST_STOP_PRESENTATION="YOUMUSTSTOPSENDCONTENT",n))(U||{}),w=(n=>(n.SPECTATOR="SPECTATOR",n.PARTICIPANT="PARTICIPANT",n))(w||{}),M=(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))(M||{}),_=(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))(_||{}),m=(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))(m||{}),L=(n=>(n.ADMIN_STOP_MIC="ADMINSTOPMIC",n.ADMIN_START_MIC="ADMINSTARTMIC",n))(L||{}),F=(n=>(n.ADMIN_SYNC_FORCED="1",n.ADMIN_SYNC_NOT_FORCED="0",n))(F||{}),Y=(n=>(n.AUDIO="AUDIO",n.VIDEO="VIDEO",n.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION",n))(Y||{}),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.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","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 A=(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))(A||{});class Se{events;connectionManager;callManager;constructor({connectionManager:e,callManager:t}){this.connectionManager=e,this.callManager=t,this.events=new f(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)=>{const i=this.callManager.getEstablishedRTCSession();if(!i){s(new Error("No rtcSession established"));return}this.callManager.once("newDTMF",({originator:r})=>{r===v.LOCAL&&t()}),i.sendDTMF(e,{duration:120,interToneGap:600})})}async sendChannels({inputChannels:e,outputChannels:t}){const s=this.callManager.getEstablishedRTCSession();if(!s)throw new Error("No rtcSession established");const i=`${h.INPUT_CHANNELS}: ${e}`,r=`${h.OUTPUT_CHANNELS}: ${t}`,a=[i,r];return s.sendInfo(_.CHANNELS,void 0,{extraHeaders:a})}async sendMediaState({cam:e,mic:t},s={}){const i=this.callManager.getEstablishedRTCSession();if(!i)throw new Error("No rtcSession established");const 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(_.MEDIA_STATE,void 0,{noTerminateWhenError:!0,...s,extraHeaders:c})}async sendRefusalToTurnOn(e,t={}){const s=this.callManager.getEstablishedRTCSession();if(!s)throw new Error("No rtcSession established");const a=e==="mic"?0:1,c=[`${h.MEDIA_TYPE}: ${a}`];return s.sendInfo(_.REFUSAL,void 0,{noTerminateWhenError:!0,...t,extraHeaders:c})}async sendRefusalToTurnOnMic(e={}){if(!this.callManager.getEstablishedRTCSession())throw new Error("No rtcSession established");return this.sendRefusalToTurnOn("mic",{noTerminateWhenError:!0,...e})}async sendRefusalToTurnOnCam(e={}){if(!this.callManager.getEstablishedRTCSession())throw new Error("No rtcSession established");return this.sendRefusalToTurnOn("cam",{noTerminateWhenError:!0,...e})}async sendMustStopPresentationP2P(){const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");await e.sendInfo(_.SHARE_STATE,void 0,{extraHeaders:[h.MUST_STOP_PRESENTATION_P2P]})}async sendStoppedPresentationP2P(){const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");await e.sendInfo(_.SHARE_STATE,void 0,{extraHeaders:[h.STOP_PRESENTATION_P2P]})}async sendStoppedPresentation(){const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");await e.sendInfo(_.SHARE_STATE,void 0,{extraHeaders:[h.STOP_PRESENTATION]})}async askPermissionToStartPresentationP2P(){const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");await e.sendInfo(_.SHARE_STATE,void 0,{extraHeaders:[h.START_PRESENTATION_P2P]})}async askPermissionToStartPresentation(){const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");await e.sendInfo(_.SHARE_STATE,void 0,{extraHeaders:[h.START_PRESENTATION]})}async askPermissionToEnableCam(e={}){const t=this.callManager.getEstablishedRTCSession();if(!t)throw new Error("No rtcSession established");const s=[h.ENABLE_MAIN_CAM];return t.sendInfo(_.MAIN_CAM,void 0,{noTerminateWhenError:!0,...e,extraHeaders:s}).catch(i=>{if(Ee(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)}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){p("error parse notify",t)}};handleNotify=e=>{switch(e.cmd){case A.CHANNELS:{const t=e;this.triggerChannelsNotify(t);break}case A.WEBCAST_STARTED:{const t=e;this.triggerWebcastStartedNotify(t);break}case A.WEBCAST_STOPPED:{const t=e;this.triggerWebcastStoppedNotify(t);break}case A.ADDED_TO_LIST_MODERATORS:{const t=e;this.triggerAddedToListModeratorsNotify(t);break}case A.REMOVED_FROM_LIST_MODERATORS:{const t=e;this.triggerRemovedFromListModeratorsNotify(t);break}case A.ACCEPTING_WORD_REQUEST:{const t=e;this.triggerParticipationAcceptingWordRequest(t);break}case A.CANCELLING_WORD_REQUEST:{const t=e;this.triggerParticipationCancellingWordRequest(t);break}case A.MOVE_REQUEST_TO_STREAM:{const t=e;this.triggerParticipantMoveRequestToStream(t);break}case A.ACCOUNT_CHANGED:{this.triggerAccountChangedNotify();break}case A.ACCOUNT_DELETED:{this.triggerAccountDeletedNotify();break}case A.CONFERENCE_PARTICIPANT_TOKEN_ISSUED:{const t=e;this.triggerConferenceParticipantTokenIssued(t);break}default:p("unknown cmd",e)}};handleNewInfo=e=>{const{originator:t}=e;if(t!==v.REMOTE)return;const{request:s}=e,i=s.getHeader(h.CONTENT_TYPE);if(i!==void 0)switch(i){case M.ENTER_ROOM:{this.triggerEnterRoom(s),this.maybeTriggerChannels(s);break}case M.NOTIFY:{this.maybeHandleNotify(s);break}case M.SHARE_STATE:{this.triggerShareState(s);break}case M.MAIN_CAM:{this.triggerMainCamControl(s);break}case M.MIC:{this.triggerMicControl(s);break}case M.USE_LICENSE:{this.triggerUseLicense(s);break}case M.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 U.AVAILABLE_SECOND_REMOTE_STREAM:{this.events.trigger(T.AVAILABLE_SECOND_REMOTE_STREAM,void 0);break}case U.NOT_AVAILABLE_SECOND_REMOTE_STREAM:{this.events.trigger(T.NOT_AVAILABLE_SECOND_REMOTE_STREAM,void 0);break}case U.MUST_STOP_PRESENTATION:{this.events.trigger(T.MUST_STOP_PRESENTATION,void 0);break}}};maybeTriggerParticipantMoveRequest=e=>{const t=e.getHeader(h.CONTENT_PARTICIPANT_STATE);t===w.SPECTATOR&&this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS,void 0),t===w.PARTICIPANT&&this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS,void 0)};triggerMainCamControl=e=>{const t=e.getHeader(h.MAIN_CAM),s=e.getHeader(h.MEDIA_SYNC),i=s===F.ADMIN_SYNC_FORCED;if(t===m.ADMIN_START_MAIN_CAM){this.events.trigger(T.ADMIN_START_MAIN_CAM,{isSyncForced:i});return}if(t===m.ADMIN_STOP_MAIN_CAM){this.events.trigger(T.ADMIN_STOP_MAIN_CAM,{isSyncForced:i});return}(t===m.RESUME_MAIN_CAM||t===m.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)===F.ADMIN_SYNC_FORCED;t===L.ADMIN_START_MIC?this.events.trigger(T.ADMIN_START_MIC,{isSyncForced:i}):t===L.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 R=(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))(R||{});const Q=["presentation:start","presentation:started","presentation:end","presentation:ended","presentation:failed"],Ce=1,Ne=n=>W.hasCanceledError(n);class ue{events;promisePendingStartPresentation;promisePendingStopPresentation;streamPresentationCurrent;cancelableSendPresentationWithRepeatedCalls;callManager;constructor({callManager:e}){this.callManager=e,this.events=new f(Q),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(R.FAILED_PRESENTATION,r),r}):t&&this.events.trigger(R.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(R.START_PRESENTATION,e)}),this.callManager.on("presentation:started",e=>{this.events.trigger(R.STARTED_PRESENTATION,e)}),this.callManager.on("presentation:end",e=>{this.events.trigger(R.END_PRESENTATION,e)}),this.callManager.on("presentation:ended",e=>{this.events.trigger(R.ENDED_PRESENTATION,e)}),this.callManager.on("presentation:failed",e=>{this.events.trigger(R.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:Ce}}){const a=async()=>this.sendPresentation(e,t,s,i),o=()=>!!this.streamPresentationCurrent;return this.cancelableSendPresentationWithRepeatedCalls=W.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=y(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(d=>{throw this.removeStreamPresentationCurrent(),this.events.trigger(R.FAILED_PRESENTATION,d),d});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 Ae{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 u=(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))(u||{});const X=["connecting","connected","disconnected","newRTCSession","registered","unregistered","registrationFailed","newMessage","sipEvent"],J=[...X],_e=3;class Ie{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",x(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(u.DISCONNECTED,()=>{s()})}),t=this.getUa();return t?t.stop():this.events.trigger(u.DISCONNECTED,void 0),e.finally(()=>{this.setUa(void 0),this.stateMachine.reset()})};cancelRequests(){this.cancelConnectWithRepeatedCalls()}connectWithDuplicatedCalls=async(e,{callLimit:t=_e}={})=>{const s=async()=>this.connectInner(e),i=r=>{const c=this.getUa()?.isConnected()===!0&&this.hasEqualConnectionConfiguration(e),g=r!=null&&!le(r);return c||g};return this.stateMachine.startConnect(),this.cancelableConnectWithRepeatedCalls=W.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:d,displayName:E="",register:l=!1,extraHeaders:S=[]})=>{this.stateMachine.startInitUa(),this.setConnectionConfiguration({sipServerUrl:s,displayName:E,register:l,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:E,register:l,sessionTimers:a,registerExpires:o,connectionRecoveryMinInterval:c,connectionRecoveryMaxInterval:g,userAgent:d,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 E=u.CONNECTED,l=[u.DISCONNECTED];return this.events.on(E,c),l.forEach(S=>{this.events.on(S,g)}),()=>{this.events.off(E,c),l.forEach(S=>{this.events.off(S,g)})}})(()=>{i?.(),e(s)},c=>{i?.(),t(c)}),s.start()});cancelConnectWithRepeatedCalls(){this.cancelableConnectWithRepeatedCalls?.cancel()}}var K=(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))(K||{});const Re=G.setup({types:{context:{},events:{}},actions:{logTransition:(n,e)=>{p(`State transition: ${e.from} -> ${e.to} (${e.event})`)},logStateChange:(n,e)=>{p("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 Me{actor;stateChangeListeners=new Set;events;unsubscribeFromEvents;actorSubscription;constructor(e){this.events=e,this.actor=G.createActor(Re),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(K).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)){p(`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 pe{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(u.REGISTERED,t),e.on(u.REGISTRATION_FAILED,s),e.register()})}async unregister(){const e=this.getUaProtected();return new Promise(t=>{e.on(u.UNREGISTERED,t),e.unregister()})}async tryRegister(){try{await this.unregister()}catch(e){p("tryRegister",e)}return this.register()}subscribeToStartEvents(e,t){const s=u.REGISTERED,i=[u.REGISTRATION_FAILED,u.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 Pe{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}),d=this.uaFactory.createUA({...g,remoteAddress:r,extraHeaders:a}),E=()=>{const S=new Error("Telephony is not available");c(S)};d.once(u.DISCONNECTED,E);const l=()=>{d.removeAllListeners(),d.once(u.DISCONNECTED,()=>{o()}),d.stop()};d.once(u.CONNECTED,l),d.start()})}}const me=n=>{const e=[];return n!==void 0&&n!==""&&e.push(`X-Vinteo-Remote: ${n}`),e};class O{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():`${ne()}`}static buildExtraHeaders(e,t){const s=e!==void 0&&e!==""?me(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:d=6,userAgent:E}){O.validateConfiguration({register:a,password:t,user:e,sipServerUrl:r,sipWebSocketServerURL:s});const l=O.resolveAuthorizationUser(a,e),S=ee(r),I=S(l),C=new this.JsSIP.WebSocketInterface(s);return{configuration:{password:t,register:a,uri:I,display_name:x(i),user_agent:E,sdpSemantics:"unified-plan",sockets:[C],session_timers:o,register_expires:c,connection_recovery_min_interval:g,connection_recovery_max_interval:d},helpers:{socket:C,getSipServerUrl:S}}}createUA({remoteAddress:e,extraHeaders:t,...s}){const i=new this.JsSIP.UA(s),r=O.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=X.find(g=>g===o);c&&r.on(c,a)}),{ua:r,helpers:i}}}class Oe{events;ua;socket;uaFactory;registrationManager;stateMachine;connectionFlow;sipOperations;configurationManager;JsSIP;constructor({JsSIP:e}){this.JsSIP=e,this.events=new f(J),this.uaFactory=new O(e),this.registrationManager=new pe({events:this.events,getUaProtected:this.getUaProtected}),this.stateMachine=new Me(this.events),this.configurationManager=new Ae({getUa:this.getUa}),this.sipOperations=new Pe({uaFactory:this.uaFactory,getUaProtected:this.getUaProtected}),this.connectionFlow=new Ie({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 O.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 D=(n=>(n.INCOMING_CALL="incomingCall",n.DECLINED_INCOMING_CALL="declinedIncomingCall",n.TERMINATED_INCOMING_CALL="terminatedIncomingCall",n.FAILED_INCOMING_CALL="failedIncomingCall",n))(D||{}),$=(n=>(n.LOCAL="local",n.REMOTE="remote",n.SYSTEM="system",n))($||{});const j=["incomingCall","declinedIncomingCall","terminatedIncomingCall","failedIncomingCall"],fe=486,De=487;class ve{events;incomingRTCSession;connectionManager;constructor(e){this.connectionManager=e,this.events=new f(j),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=De}={}){return new Promise((t,s)=>{try{const i=this.getIncomingRTCSession(),r=this.remoteCallerData;this.removeIncomingSession(),this.events.trigger(D.DECLINED_INCOMING_CALL,r),i.terminate({status_code:e}),t()}catch(i){s(i)}})}async busyIncomingCall(){return this.declineToIncomingCall({statusCode:fe})}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===$.REMOTE&&this.setIncomingSession(t)};setIncomingSession(e){this.incomingRTCSession=e;const t=this.remoteCallerData;e.on("failed",s=>{this.removeIncomingSession(),s.originator===$.LOCAL?this.events.trigger(D.TERMINATED_INCOMING_CALL,t):this.events.trigger(D.FAILED_INCOMING_CALL,t)}),this.events.trigger(D.INCOMING_CALL,t)}removeIncomingSession(){delete this.incomingRTCSession}}const ye=J.map(n=>`connection:${n}`),Ue=q.map(n=>`call:${n}`),be=z.map(n=>`api:${n}`),we=j.map(n=>`incoming-call:${n}`),Le=Q.map(n=>`presentation:${n}`),Fe=[...ye,...Ue,...be,...we,...Le];class $e{events;connectionManager;callManager;apiManager;incomingCallManager;presentationManager;constructor({JsSIP:e}){this.events=new f(Fe),this.connectionManager=new Oe({JsSIP:e}),this.callManager=new ce,this.apiManager=new Se({connectionManager:this.connectionManager,callManager:this.callManager}),this.incomingCallManager=new ve(this.connectionManager),this.presentationManager=new ue({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()=>{t===!0?await this.apiManager.sendMustStopPresentationP2P():await 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)})})}}exports.ECallCause=V;exports.EEventsMainCAM=m;exports.EUseLicense=Y;exports.Originator=v;exports.SipConnector=$e;exports.disableDebug=Te;exports.enableDebug=ge;exports.hasCanceledStartPresentationError=Ne;exports.logger=p;
|
|
@@ -127,9 +127,9 @@ class ce extends ae {
|
|
|
127
127
|
directionVideo: c,
|
|
128
128
|
directionAudio: g,
|
|
129
129
|
contentHint: d,
|
|
130
|
-
offerToReceiveAudio:
|
|
130
|
+
offerToReceiveAudio: E = !0,
|
|
131
131
|
offerToReceiveVideo: l = !0,
|
|
132
|
-
sendEncodings:
|
|
132
|
+
sendEncodings: S,
|
|
133
133
|
onAddedTransceiver: I
|
|
134
134
|
}) => (this.isPendingCall = !0, new Promise((C, p) => {
|
|
135
135
|
this.callConfiguration.number = s, this.callConfiguration.answer = !1, this.handleCall({ ontrack: a }).then(C).catch((b) => {
|
|
@@ -147,10 +147,10 @@ class ce extends ae {
|
|
|
147
147
|
iceServers: o
|
|
148
148
|
},
|
|
149
149
|
rtcOfferConstraints: {
|
|
150
|
-
offerToReceiveAudio:
|
|
150
|
+
offerToReceiveAudio: E,
|
|
151
151
|
offerToReceiveVideo: l
|
|
152
152
|
},
|
|
153
|
-
sendEncodings:
|
|
153
|
+
sendEncodings: S,
|
|
154
154
|
onAddedTransceiver: I
|
|
155
155
|
}), this.subscribeToSessionEvents(this.rtcSession);
|
|
156
156
|
}).finally(() => {
|
|
@@ -176,12 +176,12 @@ class ce extends ae {
|
|
|
176
176
|
offerToReceiveAudio: c,
|
|
177
177
|
offerToReceiveVideo: g,
|
|
178
178
|
contentHint: d,
|
|
179
|
-
sendEncodings:
|
|
179
|
+
sendEncodings: E,
|
|
180
180
|
onAddedTransceiver: l
|
|
181
|
-
}) => (this.isPendingAnswer = !0, new Promise((
|
|
181
|
+
}) => (this.isPendingAnswer = !0, new Promise((S, I) => {
|
|
182
182
|
try {
|
|
183
183
|
const C = e();
|
|
184
|
-
this.rtcSession = C, this.subscribeToSessionEvents(C), this.callConfiguration.answer = !0, this.callConfiguration.number = C.remote_identity.uri.user, this.handleCall({ ontrack: s }).then(
|
|
184
|
+
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((b) => {
|
|
185
185
|
I(b);
|
|
186
186
|
});
|
|
187
187
|
const p = v(t, {
|
|
@@ -201,7 +201,7 @@ class ce extends ae {
|
|
|
201
201
|
offerToReceiveAudio: c,
|
|
202
202
|
offerToReceiveVideo: g
|
|
203
203
|
},
|
|
204
|
-
sendEncodings:
|
|
204
|
+
sendEncodings: E,
|
|
205
205
|
onAddedTransceiver: l
|
|
206
206
|
});
|
|
207
207
|
} catch (C) {
|
|
@@ -234,9 +234,9 @@ class ce extends ae {
|
|
|
234
234
|
ontrack: e
|
|
235
235
|
}) => new Promise((t, s) => {
|
|
236
236
|
const i = () => {
|
|
237
|
-
this.events.on(N.PEER_CONNECTION, d), this.events.on(N.CONFIRMED,
|
|
237
|
+
this.events.on(N.PEER_CONNECTION, d), this.events.on(N.CONFIRMED, E);
|
|
238
238
|
}, r = () => {
|
|
239
|
-
this.events.off(N.PEER_CONNECTION, d), this.events.off(N.CONFIRMED,
|
|
239
|
+
this.events.off(N.PEER_CONNECTION, d), this.events.off(N.CONFIRMED, E);
|
|
240
240
|
}, a = () => {
|
|
241
241
|
this.events.on(N.FAILED, c), this.events.on(N.ENDED, c);
|
|
242
242
|
}, o = () => {
|
|
@@ -247,13 +247,13 @@ class ce extends ae {
|
|
|
247
247
|
let g;
|
|
248
248
|
const d = ({ peerconnection: l }) => {
|
|
249
249
|
g = l;
|
|
250
|
-
const
|
|
250
|
+
const S = (I) => {
|
|
251
251
|
this.events.trigger(N.PEER_CONNECTION_ONTRACK, l), e && e(I);
|
|
252
252
|
};
|
|
253
|
-
l.
|
|
254
|
-
l.
|
|
253
|
+
l.ontrack = S, this.disposers.add(() => {
|
|
254
|
+
l.ontrack = null;
|
|
255
255
|
});
|
|
256
|
-
},
|
|
256
|
+
}, E = () => {
|
|
257
257
|
g !== void 0 && this.events.trigger(N.PEER_CONNECTION_CONFIRMED, g), r(), o(), t(g);
|
|
258
258
|
};
|
|
259
259
|
i(), a();
|
|
@@ -332,7 +332,7 @@ const W = "sip-connector", P = k(W), He = () => {
|
|
|
332
332
|
}, Ge = () => {
|
|
333
333
|
k.enable(`-${W}`);
|
|
334
334
|
}, Te = "Error decline with 603", he = 1006, de = (n) => typeof n == "object" && n !== null && "code" in n && n.code === he, le = (n) => n.message === Te;
|
|
335
|
-
var h = /* @__PURE__ */ ((n) => (n.
|
|
335
|
+
var h = /* @__PURE__ */ ((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 || {}), y = /* @__PURE__ */ ((n) => (n.AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT", n.NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND", n.MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT", n))(y || {}), w = /* @__PURE__ */ ((n) => (n.SPECTATOR = "SPECTATOR", n.PARTICIPANT = "PARTICIPANT", n))(w || {}), M = /* @__PURE__ */ ((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))(M || {}), _ = /* @__PURE__ */ ((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))(_ || {}), f = /* @__PURE__ */ ((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 || {}), L = /* @__PURE__ */ ((n) => (n.ADMIN_STOP_MIC = "ADMINSTOPMIC", n.ADMIN_START_MIC = "ADMINSTARTMIC", n))(L || {}), F = /* @__PURE__ */ ((n) => (n.ADMIN_SYNC_FORCED = "1", n.ADMIN_SYNC_NOT_FORCED = "0", n))(F || {}), Ee = /* @__PURE__ */ ((n) => (n.AUDIO = "AUDIO", n.VIDEO = "VIDEO", n.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", n))(Ee || {}), T = /* @__PURE__ */ ((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.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 || {});
|
|
336
336
|
const q = [
|
|
337
337
|
"participation:accepting-word-request",
|
|
338
338
|
"participation:cancelling-word-request",
|
|
@@ -595,7 +595,7 @@ class Se {
|
|
|
595
595
|
const { originator: t } = e;
|
|
596
596
|
if (t !== U.REMOTE)
|
|
597
597
|
return;
|
|
598
|
-
const { request: s } = e, i = s.getHeader(h.
|
|
598
|
+
const { request: s } = e, i = s.getHeader(h.CONTENT_TYPE);
|
|
599
599
|
if (i !== void 0)
|
|
600
600
|
switch (i) {
|
|
601
601
|
case M.ENTER_ROOM: {
|
|
@@ -1111,13 +1111,13 @@ class _e {
|
|
|
1111
1111
|
connectionRecoveryMinInterval: c,
|
|
1112
1112
|
connectionRecoveryMaxInterval: g,
|
|
1113
1113
|
userAgent: d,
|
|
1114
|
-
displayName:
|
|
1114
|
+
displayName: E = "",
|
|
1115
1115
|
register: l = !1,
|
|
1116
|
-
extraHeaders:
|
|
1116
|
+
extraHeaders: S = []
|
|
1117
1117
|
}) => {
|
|
1118
1118
|
this.stateMachine.startInitUa(), this.setConnectionConfiguration({
|
|
1119
1119
|
sipServerUrl: s,
|
|
1120
|
-
displayName:
|
|
1120
|
+
displayName: E,
|
|
1121
1121
|
register: l,
|
|
1122
1122
|
user: e,
|
|
1123
1123
|
password: t
|
|
@@ -1128,7 +1128,7 @@ class _e {
|
|
|
1128
1128
|
password: t,
|
|
1129
1129
|
sipServerUrl: s,
|
|
1130
1130
|
sipWebSocketServerURL: i,
|
|
1131
|
-
displayName:
|
|
1131
|
+
displayName: E,
|
|
1132
1132
|
register: l,
|
|
1133
1133
|
sessionTimers: a,
|
|
1134
1134
|
registerExpires: o,
|
|
@@ -1136,7 +1136,7 @@ class _e {
|
|
|
1136
1136
|
connectionRecoveryMaxInterval: g,
|
|
1137
1137
|
userAgent: d,
|
|
1138
1138
|
remoteAddress: r,
|
|
1139
|
-
extraHeaders:
|
|
1139
|
+
extraHeaders: S
|
|
1140
1140
|
},
|
|
1141
1141
|
this.events
|
|
1142
1142
|
);
|
|
@@ -1152,12 +1152,12 @@ class _e {
|
|
|
1152
1152
|
i = ((c, g) => {
|
|
1153
1153
|
if (this.getConnectionConfiguration().register === !0)
|
|
1154
1154
|
return this.registrationManager.subscribeToStartEvents(c, g);
|
|
1155
|
-
const
|
|
1156
|
-
return this.events.on(
|
|
1157
|
-
this.events.on(
|
|
1155
|
+
const E = u.CONNECTED, l = [u.DISCONNECTED];
|
|
1156
|
+
return this.events.on(E, c), l.forEach((S) => {
|
|
1157
|
+
this.events.on(S, g);
|
|
1158
1158
|
}), () => {
|
|
1159
|
-
this.events.off(
|
|
1160
|
-
this.events.off(
|
|
1159
|
+
this.events.off(E, c), l.forEach((S) => {
|
|
1160
|
+
this.events.off(S, g);
|
|
1161
1161
|
});
|
|
1162
1162
|
};
|
|
1163
1163
|
})(() => {
|
|
@@ -1735,11 +1735,11 @@ class pe {
|
|
|
1735
1735
|
displayName: t,
|
|
1736
1736
|
userAgent: e,
|
|
1737
1737
|
sipServerUrl: s
|
|
1738
|
-
}), d = this.uaFactory.createUA({ ...g, remoteAddress: r, extraHeaders: a }),
|
|
1739
|
-
const
|
|
1740
|
-
c(
|
|
1738
|
+
}), d = this.uaFactory.createUA({ ...g, remoteAddress: r, extraHeaders: a }), E = () => {
|
|
1739
|
+
const S = new Error("Telephony is not available");
|
|
1740
|
+
c(S);
|
|
1741
1741
|
};
|
|
1742
|
-
d.once(u.DISCONNECTED,
|
|
1742
|
+
d.once(u.DISCONNECTED, E);
|
|
1743
1743
|
const l = () => {
|
|
1744
1744
|
d.removeAllListeners(), d.once(u.DISCONNECTED, () => {
|
|
1745
1745
|
o();
|
|
@@ -1796,7 +1796,7 @@ class m {
|
|
|
1796
1796
|
// 5 minutes in sec
|
|
1797
1797
|
connectionRecoveryMinInterval: g = 2,
|
|
1798
1798
|
connectionRecoveryMaxInterval: d = 6,
|
|
1799
|
-
userAgent:
|
|
1799
|
+
userAgent: E
|
|
1800
1800
|
}) {
|
|
1801
1801
|
m.validateConfiguration({
|
|
1802
1802
|
register: a,
|
|
@@ -1805,14 +1805,14 @@ class m {
|
|
|
1805
1805
|
sipServerUrl: r,
|
|
1806
1806
|
sipWebSocketServerURL: s
|
|
1807
1807
|
});
|
|
1808
|
-
const l = m.resolveAuthorizationUser(a, e),
|
|
1808
|
+
const l = m.resolveAuthorizationUser(a, e), S = te(r), I = S(l), C = new this.JsSIP.WebSocketInterface(s);
|
|
1809
1809
|
return {
|
|
1810
1810
|
configuration: {
|
|
1811
1811
|
password: t,
|
|
1812
1812
|
register: a,
|
|
1813
1813
|
uri: I,
|
|
1814
1814
|
display_name: B(i),
|
|
1815
|
-
user_agent:
|
|
1815
|
+
user_agent: E,
|
|
1816
1816
|
sdpSemantics: "unified-plan",
|
|
1817
1817
|
sockets: [C],
|
|
1818
1818
|
session_timers: o,
|
|
@@ -1822,7 +1822,7 @@ class m {
|
|
|
1822
1822
|
},
|
|
1823
1823
|
helpers: {
|
|
1824
1824
|
socket: C,
|
|
1825
|
-
getSipServerUrl:
|
|
1825
|
+
getSipServerUrl: S
|
|
1826
1826
|
}
|
|
1827
1827
|
};
|
|
1828
1828
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { default as ApiManager } from './@ApiManager';
|
|
2
|
-
export { EEventsMainCAM, EEventsMic, EEventsSyncMediaState, EUseLicense } from './constants';
|
|
2
|
+
export { EContentTypeReceived, EContentTypeSent, EEventsMainCAM, EEventsMic, EEventsSyncMediaState, EHeader, EShareState, EUseLicense, } from './constants';
|
|
3
3
|
export type { TEvent as TApiEvent } from './eventNames';
|
|
@@ -4,4 +4,4 @@ export { EEvent as ECallEvent, Originator } from './eventNames';
|
|
|
4
4
|
export type { TEvent as TCallEvent, TEvents as TCallEvents } from './eventNames';
|
|
5
5
|
export { default as hasCanceledCallError } from './hasCanceledCallError';
|
|
6
6
|
export { MCUCallStrategy } from './MCUCallStrategy';
|
|
7
|
-
export type { TCustomError } from './types';
|
|
7
|
+
export type { TCustomError, TGetServerUrl } from './types';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RegisteredEvent, UA, UnRegisteredEvent, WebSocketInterface } from '@krivega/jssip';
|
|
2
2
|
import { default as Events } from 'events-constructor';
|
|
3
|
-
import { TGetServerUrl
|
|
3
|
+
import { TGetServerUrl } from '../CallManager';
|
|
4
|
+
import { TJsSIP } from '../types';
|
|
4
5
|
import { TConnect, TSet } from './ConnectionFlow';
|
|
5
6
|
import { TEvent, EVENT_NAMES } from './eventNames';
|
|
6
7
|
import { TParametersCheckTelephony, default as SipOperations } from './SipOperations';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UA, WebSocketInterface } from '@krivega/jssip';
|
|
2
2
|
import { default as Events } from 'events-constructor';
|
|
3
|
-
import { TGetServerUrl
|
|
3
|
+
import { TGetServerUrl } from '../CallManager';
|
|
4
|
+
import { TJsSIP } from '../types';
|
|
4
5
|
import { default as ConnectionStateMachine } from './ConnectionStateMachine';
|
|
5
6
|
import { EVENT_NAMES } from './eventNames';
|
|
6
7
|
import { default as RegistrationManager } from './RegistrationManager';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { default as Events } from 'events-constructor';
|
|
2
2
|
import { ApiManager } from '../ApiManager';
|
|
3
|
-
import { CallManager } from '../CallManager';
|
|
3
|
+
import { TGetServerUrl, CallManager } from '../CallManager';
|
|
4
4
|
import { ConnectionManager } from '../ConnectionManager';
|
|
5
5
|
import { IncomingCallManager } from '../IncomingCallManager';
|
|
6
6
|
import { PresentationManager } from '../PresentationManager';
|
|
7
7
|
import { TContentHint, TOnAddedTransceiver } from '../PresentationManager/types';
|
|
8
|
-
import {
|
|
8
|
+
import { TJsSIP } from '../types';
|
|
9
9
|
import { TEvent, EVENT_NAMES } from './eventNames';
|
|
10
10
|
declare class SipConnector {
|
|
11
11
|
readonly events: Events<typeof EVENT_NAMES>;
|
package/dist/doMock.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("./@SipConnector-C09fG-9w.cjs"),W=require("@krivega/jssip/lib/NameAddrHeader"),b=require("@krivega/jssip/lib/URI"),V=require("node:events"),k=require("@krivega/jssip/lib/SIPMessage"),c=require("@krivega/jssip"),R=require("webrtc-mock"),O=require("events-constructor");class S extends k.IncomingRequest{headers;constructor(e){super(),this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)??""}}const U="incomingCall",H="declinedIncomingCall",q="failedIncomingCall",G="terminatedIncomingCall",P="connecting",x="connected",z="disconnected",j="newRTCSession",Y="registered",B="unregistered",K="registrationFailed",J="newMessage",Q="sipEvent",$="availableSecondRemoteStream",X="notAvailableSecondRemoteStream",Z="mustStopPresentation",ee="shareState",te="enterRoom",re="useLicense",ne="peerconnection:confirmed",oe="peerconnection:ontrack",ie="channels",se="channels:notify",ae="ended:fromserver",ce="main-cam-control",de="admin-stop-main-cam",Ee="admin-start-main-cam",he="admin-stop-mic",ue="admin-start-mic",me="admin-force-sync-media-state",le="participant:added-to-list-moderators",pe="participant:removed-from-list-moderators",ge="participant:move-request-to-stream",_e="participant:move-request-to-spectators",Te="participant:move-request-to-participants",Ie="participation:accepting-word-request",Se="participation:cancelling-word-request",Ne="webcast:started",we="webcast:stopped",Ce="account:changed",Re="account:deleted",fe="conference:participant-token-issued",Ae="ended",Me="sending",Oe="reinvite",Pe="replaces",De="refer",ve="progress",ye="accepted",Le="confirmed",Fe="peerconnection",We="failed",be="muted",Ve="unmuted",ke="newDTMF",Ue="newInfo",He="hold",qe="unhold",Ge="update",xe="sdp",ze="icecandidate",je="getusermediafailed",Ye="peerconnection:createofferfailed",Be="peerconnection:createanswerfailed",Ke="peerconnection:setlocaldescriptionfailed",Je="peerconnection:setremotedescriptionfailed",Qe="presentation:start",$e="presentation:started",Xe="presentation:end",Ze="presentation:ended",et="presentation:failed",tt=[U,H,G,q,Ie,Se,ge,se,fe,Ce,Re,Ne,we,le,pe],D=[P,x,z,j,Y,B,K,J,Q],rt=[$,X,Z,ee,te,re,ne,oe,ie,ae,ce,Ee,de,he,ue,me,_e,Te],nt=[Ae,P,Me,Oe,Pe,De,ve,ye,Le,Fe,We,be,Ve,ke,Ue,He,qe,Ge,xe,ze,je,Ye,Be,Ke,Je,Qe,$e,Xe,Ze,et];[...D,...tt];const ot=[...nt,...rt];class it{originator;connection;events;remote_identity;mutedOptions={audio:!1,video:!1};constructor({originator:e="local",eventHandlers:t,remoteIdentity:r}){this.originator=e,this.events=new O(ot),this.initEvents(t),this.remote_identity=r}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}set data(e){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(e){throw new Error("Method not implemented.")}terminate(e){throw new Error("Method not implemented.")}async sendInfo(e,t,r){throw new Error("Method not implemented.")}hold(e,t){throw new Error("Method not implemented.")}unhold(e,t){throw new Error("Method not implemented.")}async renegotiate(e,t){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(e){throw new Error("Method not implemented.")}unmute(e){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(e,t){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(e,t){throw new Error("Method not implemented.")}addListener(e,t){throw new Error("Method not implemented.")}once(e,t){throw new Error("Method not implemented.")}removeListener(e,t){throw new Error("Method not implemented.")}off(e,t){return this.events.off(e,t),this}removeAllListeners(e){return console.warn("Method not implemented. Event:",e),this}setMaxListeners(e){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(e){throw new Error("Method not implemented.")}rawListeners(e){throw new Error("Method not implemented.")}emit(e,...t){throw new Error("Method not implemented.")}listenerCount(e){throw new Error("Method not implemented.")}prependListener(e,t){throw new Error("Method not implemented.")}prependOnceListener(e,t){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(e){e&&Object.entries(e).forEach(([t,r])=>this.on(t,r))}on(e,t){return this.events.on(e,t),this}trigger(e,t){this.events.trigger(e,t)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(e){return this.trigger("presentation:start",e),this.trigger("presentation:started",e),e}async stopPresentation(e){return this.trigger("presentation:end",e),this.trigger("presentation:ended",e),e}isEstablished(){return!0}}class st{dtmf=null;track=null;transport=null;transform=null;parameters={encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}};parametersGets;constructor({track:e}={}){this.track=e??null}async getStats(){throw new Error("Method not implemented.")}async replaceTrack(e){this.track=e??null}async setParameters(e){if(e!==this.parametersGets)throw new Error("Failed to execute 'setParameters' on 'RTCRtpSender': Read-only field modified in setParameters().");const{transactionId:t}=this.parameters;this.parameters={...this.parameters,...e,transactionId:`${Number(t)+1}`}}getParameters(){return this.parametersGets={...this.parameters},this.parametersGets}setStreams(){throw new Error("Method not implemented.")}}class at{senders=[];receivers=[];canTrickleIceCandidates;connectionState;currentLocalDescription;currentRemoteDescription;iceConnectionState;iceGatheringState;idpErrorInfo;idpLoginUrl;localDescription;onconnectionstatechange;ondatachannel;onicecandidate;onicecandidateerror=null;oniceconnectionstatechange;onicegatheringstatechange;onnegotiationneeded;onsignalingstatechange;ontrack;peerIdentity=void 0;pendingLocalDescription;pendingRemoteDescription;remoteDescription;sctp=null;signalingState;constructor(e,t){this.receivers=t.map(r=>({track:r}))}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(e){throw new Error("Method not implemented.")}addTransceiver(e,t){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(e,t){throw new Error("Method not implemented.")}createDataChannel(e,t){throw new Error("Method not implemented.")}async createOffer(e,t,r){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(e){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(e){throw new Error("Method not implemented.")}setConfiguration(e){throw new Error("Method not implemented.")}async setLocalDescription(e){throw new Error("Method not implemented.")}async setRemoteDescription(e){throw new Error("Method not implemented.")}addEventListener(e,t,r){console.warn("Method not implemented. Type:",e)}removeEventListener(e,t,r){console.warn("Method not implemented. Type:",e)}dispatchEvent(e){throw new Error("Method not implemented.")}getReceivers=()=>this.receivers;getSenders=()=>this.senders;addTrack=e=>{const t=new st({track:e});return this.senders.push(t),t}}function ct(n){const e=n.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const g=400,v="777",dt=n=>n.getVideoTracks().length>0;class i extends it{static presentationError;static startPresentationError;static countStartPresentationError=Number.POSITIVE_INFINITY;static countStartsPresentation=0;url;status_code;answer=jest.fn(({mediaStream:e})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(e),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},g)});replaceMediaStream=jest.fn(async e=>{});isEndedInner=!1;constructor({url:e="",mediaStream:t,eventHandlers:r,originator:s,remoteIdentity:a=new c.NameAddrHeader(new c.URI("sip","caller1","test1.com",5060),"Test Caller 1")}){super({originator:s,eventHandlers:r,remoteIdentity:a}),this.url=e,this.initPeerconnection(t)}static setPresentationError(e){this.presentationError=e}static resetPresentationError(){this.presentationError=void 0}static setStartPresentationError(e,{count:t=Number.POSITIVE_INFINITY}={}){this.startPresentationError=e,this.countStartPresentationError=t}static resetStartPresentationError(){this.startPresentationError=void 0,this.countStartPresentationError=Number.POSITIVE_INFINITY,this.countStartsPresentation=0}startPresentation=async e=>{if(i.countStartsPresentation+=1,i.presentationError)throw this.trigger("presentation:start",e),this.trigger("presentation:failed",e),i.presentationError;if(i.startPresentationError&&i.countStartsPresentation<i.countStartPresentationError)throw this.trigger("presentation:start",e),this.trigger("presentation:failed",e),i.startPresentationError;return super.startPresentation(e)};stopPresentation=async e=>{if(i.presentationError)throw this.trigger("presentation:end",e),this.trigger("presentation:failed",e),i.presentationError;return super.stopPresentation(e)};initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const t=R.createAudioMediaStreamTrackMock();t.id="mainaudio1";const r=[t];if(dt(e)){const a=R.createVideoMediaStreamTrackMock();a.id="mainvideo1",r.push(a)}this.connection=new at(void 0,r),this.addStream(e),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},g)}connect(e){const t=ct(e);setTimeout(()=>{this.url.includes(v)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:"Rejected"}):(this.trigger("connecting"),setTimeout(()=>{this.newInfo({originator:M.Originator.REMOTE,request:{getHeader:r=>r==="content-type"?"application/vinteo.webrtc.roomname":r==="x-webrtc-enter-room"?t:r==="x-webrtc-participant-name"?"Test Caller 1":""}})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},g)}terminate({status_code:e,cause:t}={}){return this.status_code=e,this.trigger("ended",{status_code:e,cause:t,originator:"local"}),this.isEndedInner=!1,this}async terminateAsync({status_code:e,cause:t}={}){this.terminate({status_code:e,cause:t})}terminateRemote({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e,originator:"remote"}),this}addStream(e,t="getTracks"){e[t]().forEach(r=>this.connection.addTrack(r))}forEachSenders(e){const t=this.connection.getSenders();for(const r of t)e(r);return t}toggleMuteAudio(e){this.forEachSenders(({track:t})=>{t&&t.kind==="audio"&&(t.enabled=!e)})}toggleMuteVideo(e){this.forEachSenders(({track:t})=>{t&&t.kind==="video"&&(t.enabled=!e)})}mute(e){e.audio&&(this.mutedOptions.audio=!0,this.toggleMuteAudio(this.mutedOptions.audio)),e.video&&(this.mutedOptions.video=!0,this.toggleMuteVideo(this.mutedOptions.video)),this.onmute(e)}unmute(e){e.audio&&(this.mutedOptions.audio=!1),e.video&&(this.mutedOptions.video=!1),this.trigger("unmuted",e)}isMuted(){return this.mutedOptions}onmute({audio:e,video:t}){this.trigger("muted",{audio:e,video:t})}async sendInfo(){}isEnded(){return this.isEndedInner}newInfo(e){this.trigger("newInfo",e)}}class Et{extraHeaders=[];setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",T="PASSWORD_CORRECT_2",y="NAME_INCORRECT",h=400,_={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},f={status_code:200,reason_phrase:"OK"},A={status_code:401,reason_phrase:"Unauthorized"};class o{static isAvailableTelephony=!0;static startError;static countStartError=Number.POSITIVE_INFINITY;static countStarts=0;events;registratorInner;call=jest.fn((e,t)=>{const{mediaStream:r,eventHandlers:s}=t;return this.session=new i({url:e,mediaStream:r,eventHandlers:s,originator:"local"}),this.session.connect(e),this.session});sendOptions=jest.fn((e,t,r)=>{console.log("sendOptions",e,t,r)});start=jest.fn(()=>{if(o.countStarts+=1,o.startError&&o.countStarts<o.countStartError){this.trigger("disconnected",o.startError);return}this.register()});stop=jest.fn(()=>{this.startedTimeout&&clearTimeout(this.startedTimeout),this.stopedTimeout&&clearTimeout(this.stopedTimeout),this.unregister(),this.isStarted()?this.stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:!0,socket:_})},h):this.trigger("disconnected",{error:!0,socket:_})});removeAllListeners=jest.fn(()=>(this.events.removeEventHandlers(),this));once=jest.fn((e,t)=>(this.events.once(e,t),this));startedTimeout;stopedTimeout;session;isRegisteredInner;isConnectedInner;configuration;constructor(e){this.events=new O(D);const[t,r]=e.uri.split(":"),[s,a]=r.split("@"),p={...e,uri:new c.URI(t,s,a)};this.configuration=p,this.registratorInner=new Et}static setStartError(e,{count:t=Number.POSITIVE_INFINITY}={}){o.startError=e,o.countStartError=t}static resetStartError(){o.startError=void 0,o.countStartError=Number.POSITIVE_INFINITY,o.countStarts=0}static setAvailableTelephony(){o.isAvailableTelephony=!0}static setNotAvailableTelephony(){o.isAvailableTelephony=!1}static reset(){o.resetStartError(),o.setAvailableTelephony()}on(e,t){return this.events.on(e,t),this}off(e,t){return this.events.off(e,t),this}trigger(e,t){this.events.trigger(e,t)}terminateSessions(){this.session?.terminate()}set(e,t){return this.configuration[e]=t,!0}register(){this.startedTimeout&&clearTimeout(this.startedTimeout);const{password:e,register:t,uri:r}=this.configuration;t===!0&&r.user.includes(y)?(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:A,cause:c.C.causes.REJECTED})},h)):!this.isRegistered()&&t===!0&&(e===d||e===T)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:f})},h)):t===!0&&e!==d&&e!==T&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:A,cause:c.C.causes.REJECTED})},h)),o.isAvailableTelephony?(this.trigger("connected",{socket:_}),this.isConnectedInner=!0):this.stop()}unregister(){this.isRegisteredInner=!1,this.isConnectedInner=!1,this.trigger("unregistered",{response:f})}isRegistered(){return this.isRegisteredInner===!0}isConnected(){return this.isConnectedInner===!0}isStarted(){return this.configuration.register===!0&&this.isRegisteredInner===!0||this.configuration.register!==!0&&this.isConnectedInner===!0}newSipEvent(e){this.trigger("sipEvent",e)}registrator(){return this.registratorInner}}class ht{url;constructor(e){this.url=e}}class ut extends V.EventEmitter{contentType;body;constructor(e,t){super(),this.contentType=e,this.body=t}}const I="remote",mt=(n,e)=>{const t=new S(e),r={originator:I,request:t,info:new ut("","")};n.newInfo(r)},lt=(n,e)=>{const r={event:"sipEvent",request:new S(e)};n.newSipEvent(r)},pt=(n,{incomingNumber:e="1234",displayName:t,host:r})=>{const s=new i({originator:I,eventHandlers:{}}),a=new b("sip",e,r);s.remote_identity=new W(a,t);const p=new S([]);n.trigger("newRTCSession",{originator:I,session:s,request:p})},gt=(n,e)=>{e?n.trigger("failed",e):n.trigger("failed",n)},N={triggerNewInfo:mt,triggerNewSipEvent:lt,triggerIncomingSession:pt,triggerFailIncomingSession:gt,WebSocketInterface:ht,UA:o,C:{INVITE:"INVITE"}},u="user",E="displayName",m="SIP_SERVER_URL",w="SIP_WEB_SOCKET_SERVER_URL",_t=new N.WebSocketInterface(w),C={userAgent:"Chrome",sipServerUrl:m,sipWebSocketServerURL:w},Tt={...C},L={...C,user:u,password:d,register:!0},It={...L,displayName:E},St={...C,displayName:E,register:!1},l={session_timers:!1,sockets:[_t],user_agent:"Chrome",sdpSemantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},Nt={...l,password:d,uri:new c.URI("sip",u,m),display_name:"",register:!0},wt={...l,password:d,uri:new c.URI("sip",u,m),display_name:E,register:!0},Ct={...l,display_name:E,register:!1},Rt={...l,display_name:"",register:!1},F="10.10.10.10",ft=[`X-Vinteo-Remote: ${F}`],At=()=>new M.SipConnector({JsSIP:N});exports.FAILED_CONFERENCE_NUMBER=v;exports.JsSIP=N;exports.NAME_INCORRECT=y;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=T;exports.SIP_SERVER_URL=m;exports.SIP_WEB_SOCKET_SERVER_URL=w;exports.dataForConnectionWithAuthorization=L;exports.dataForConnectionWithAuthorizationWithDisplayName=It;exports.dataForConnectionWithoutAuthorization=St;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=Tt;exports.displayName=E;exports.doMockSipConnector=At;exports.extraHeadersRemoteAddress=ft;exports.remoteAddress=F;exports.uaConfigurationWithAuthorization=Nt;exports.uaConfigurationWithAuthorizationWithDisplayName=wt;exports.uaConfigurationWithoutAuthorization=Ct;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=Rt;exports.user=u;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("./@SipConnector-BOHJ000Z.cjs"),W=require("@krivega/jssip/lib/NameAddrHeader"),b=require("@krivega/jssip/lib/URI"),V=require("node:events"),k=require("@krivega/jssip/lib/SIPMessage"),c=require("@krivega/jssip"),R=require("webrtc-mock"),O=require("events-constructor");class S extends k.IncomingRequest{headers;constructor(e){super(),this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)??""}}const U="incomingCall",H="declinedIncomingCall",q="failedIncomingCall",G="terminatedIncomingCall",P="connecting",x="connected",z="disconnected",j="newRTCSession",Y="registered",B="unregistered",K="registrationFailed",J="newMessage",Q="sipEvent",$="availableSecondRemoteStream",X="notAvailableSecondRemoteStream",Z="mustStopPresentation",ee="shareState",te="enterRoom",re="useLicense",ne="peerconnection:confirmed",oe="peerconnection:ontrack",ie="channels",se="channels:notify",ae="ended:fromserver",ce="main-cam-control",de="admin-stop-main-cam",Ee="admin-start-main-cam",he="admin-stop-mic",ue="admin-start-mic",me="admin-force-sync-media-state",le="participant:added-to-list-moderators",pe="participant:removed-from-list-moderators",ge="participant:move-request-to-stream",_e="participant:move-request-to-spectators",Te="participant:move-request-to-participants",Ie="participation:accepting-word-request",Se="participation:cancelling-word-request",Ne="webcast:started",we="webcast:stopped",Ce="account:changed",Re="account:deleted",fe="conference:participant-token-issued",Ae="ended",Me="sending",Oe="reinvite",Pe="replaces",De="refer",ve="progress",ye="accepted",Le="confirmed",Fe="peerconnection",We="failed",be="muted",Ve="unmuted",ke="newDTMF",Ue="newInfo",He="hold",qe="unhold",Ge="update",xe="sdp",ze="icecandidate",je="getusermediafailed",Ye="peerconnection:createofferfailed",Be="peerconnection:createanswerfailed",Ke="peerconnection:setlocaldescriptionfailed",Je="peerconnection:setremotedescriptionfailed",Qe="presentation:start",$e="presentation:started",Xe="presentation:end",Ze="presentation:ended",et="presentation:failed",tt=[U,H,G,q,Ie,Se,ge,se,fe,Ce,Re,Ne,we,le,pe],D=[P,x,z,j,Y,B,K,J,Q],rt=[$,X,Z,ee,te,re,ne,oe,ie,ae,ce,Ee,de,he,ue,me,_e,Te],nt=[Ae,P,Me,Oe,Pe,De,ve,ye,Le,Fe,We,be,Ve,ke,Ue,He,qe,Ge,xe,ze,je,Ye,Be,Ke,Je,Qe,$e,Xe,Ze,et];[...D,...tt];const ot=[...nt,...rt];class it{originator;connection;events;remote_identity;mutedOptions={audio:!1,video:!1};constructor({originator:e="local",eventHandlers:t,remoteIdentity:r}){this.originator=e,this.events=new O(ot),this.initEvents(t),this.remote_identity=r}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}set data(e){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(e){throw new Error("Method not implemented.")}terminate(e){throw new Error("Method not implemented.")}async sendInfo(e,t,r){throw new Error("Method not implemented.")}hold(e,t){throw new Error("Method not implemented.")}unhold(e,t){throw new Error("Method not implemented.")}async renegotiate(e,t){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(e){throw new Error("Method not implemented.")}unmute(e){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(e,t){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(e,t){throw new Error("Method not implemented.")}addListener(e,t){throw new Error("Method not implemented.")}once(e,t){throw new Error("Method not implemented.")}removeListener(e,t){throw new Error("Method not implemented.")}off(e,t){return this.events.off(e,t),this}removeAllListeners(e){return console.warn("Method not implemented. Event:",e),this}setMaxListeners(e){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(e){throw new Error("Method not implemented.")}rawListeners(e){throw new Error("Method not implemented.")}emit(e,...t){throw new Error("Method not implemented.")}listenerCount(e){throw new Error("Method not implemented.")}prependListener(e,t){throw new Error("Method not implemented.")}prependOnceListener(e,t){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(e){e&&Object.entries(e).forEach(([t,r])=>this.on(t,r))}on(e,t){return this.events.on(e,t),this}trigger(e,t){this.events.trigger(e,t)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(e){return this.trigger("presentation:start",e),this.trigger("presentation:started",e),e}async stopPresentation(e){return this.trigger("presentation:end",e),this.trigger("presentation:ended",e),e}isEstablished(){return!0}}class st{dtmf=null;track=null;transport=null;transform=null;parameters={encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}};parametersGets;constructor({track:e}={}){this.track=e??null}async getStats(){throw new Error("Method not implemented.")}async replaceTrack(e){this.track=e??null}async setParameters(e){if(e!==this.parametersGets)throw new Error("Failed to execute 'setParameters' on 'RTCRtpSender': Read-only field modified in setParameters().");const{transactionId:t}=this.parameters;this.parameters={...this.parameters,...e,transactionId:`${Number(t)+1}`}}getParameters(){return this.parametersGets={...this.parameters},this.parametersGets}setStreams(){throw new Error("Method not implemented.")}}class at{senders=[];receivers=[];canTrickleIceCandidates;connectionState;currentLocalDescription;currentRemoteDescription;iceConnectionState;iceGatheringState;idpErrorInfo;idpLoginUrl;localDescription;onconnectionstatechange;ondatachannel;onicecandidate;onicecandidateerror=null;oniceconnectionstatechange;onicegatheringstatechange;onnegotiationneeded;onsignalingstatechange;ontrack;peerIdentity=void 0;pendingLocalDescription;pendingRemoteDescription;remoteDescription;sctp=null;signalingState;constructor(e,t){this.receivers=t.map(r=>({track:r}))}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(e){throw new Error("Method not implemented.")}addTransceiver(e,t){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(e,t){throw new Error("Method not implemented.")}createDataChannel(e,t){throw new Error("Method not implemented.")}async createOffer(e,t,r){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(e){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(e){throw new Error("Method not implemented.")}setConfiguration(e){throw new Error("Method not implemented.")}async setLocalDescription(e){throw new Error("Method not implemented.")}async setRemoteDescription(e){throw new Error("Method not implemented.")}addEventListener(e,t,r){console.warn("Method not implemented. Type:",e)}removeEventListener(e,t,r){console.warn("Method not implemented. Type:",e)}dispatchEvent(e){throw new Error("Method not implemented.")}getReceivers=()=>this.receivers;getSenders=()=>this.senders;addTrack=e=>{const t=new st({track:e});return this.senders.push(t),t}}function ct(n){const e=n.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const g=400,v="777",dt=n=>n.getVideoTracks().length>0;class i extends it{static presentationError;static startPresentationError;static countStartPresentationError=Number.POSITIVE_INFINITY;static countStartsPresentation=0;url;status_code;answer=jest.fn(({mediaStream:e})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(e),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},g)});replaceMediaStream=jest.fn(async e=>{});isEndedInner=!1;constructor({url:e="",mediaStream:t,eventHandlers:r,originator:s,remoteIdentity:a=new c.NameAddrHeader(new c.URI("sip","caller1","test1.com",5060),"Test Caller 1")}){super({originator:s,eventHandlers:r,remoteIdentity:a}),this.url=e,this.initPeerconnection(t)}static setPresentationError(e){this.presentationError=e}static resetPresentationError(){this.presentationError=void 0}static setStartPresentationError(e,{count:t=Number.POSITIVE_INFINITY}={}){this.startPresentationError=e,this.countStartPresentationError=t}static resetStartPresentationError(){this.startPresentationError=void 0,this.countStartPresentationError=Number.POSITIVE_INFINITY,this.countStartsPresentation=0}startPresentation=async e=>{if(i.countStartsPresentation+=1,i.presentationError)throw this.trigger("presentation:start",e),this.trigger("presentation:failed",e),i.presentationError;if(i.startPresentationError&&i.countStartsPresentation<i.countStartPresentationError)throw this.trigger("presentation:start",e),this.trigger("presentation:failed",e),i.startPresentationError;return super.startPresentation(e)};stopPresentation=async e=>{if(i.presentationError)throw this.trigger("presentation:end",e),this.trigger("presentation:failed",e),i.presentationError;return super.stopPresentation(e)};initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const t=R.createAudioMediaStreamTrackMock();t.id="mainaudio1";const r=[t];if(dt(e)){const a=R.createVideoMediaStreamTrackMock();a.id="mainvideo1",r.push(a)}this.connection=new at(void 0,r),this.addStream(e),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},g)}connect(e){const t=ct(e);setTimeout(()=>{this.url.includes(v)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:"Rejected"}):(this.trigger("connecting"),setTimeout(()=>{this.newInfo({originator:M.Originator.REMOTE,request:{getHeader:r=>r==="content-type"?"application/vinteo.webrtc.roomname":r==="x-webrtc-enter-room"?t:r==="x-webrtc-participant-name"?"Test Caller 1":""}})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},g)}terminate({status_code:e,cause:t}={}){return this.status_code=e,this.trigger("ended",{status_code:e,cause:t,originator:"local"}),this.isEndedInner=!1,this}async terminateAsync({status_code:e,cause:t}={}){this.terminate({status_code:e,cause:t})}terminateRemote({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e,originator:"remote"}),this}addStream(e,t="getTracks"){e[t]().forEach(r=>this.connection.addTrack(r))}forEachSenders(e){const t=this.connection.getSenders();for(const r of t)e(r);return t}toggleMuteAudio(e){this.forEachSenders(({track:t})=>{t&&t.kind==="audio"&&(t.enabled=!e)})}toggleMuteVideo(e){this.forEachSenders(({track:t})=>{t&&t.kind==="video"&&(t.enabled=!e)})}mute(e){e.audio&&(this.mutedOptions.audio=!0,this.toggleMuteAudio(this.mutedOptions.audio)),e.video&&(this.mutedOptions.video=!0,this.toggleMuteVideo(this.mutedOptions.video)),this.onmute(e)}unmute(e){e.audio&&(this.mutedOptions.audio=!1),e.video&&(this.mutedOptions.video=!1),this.trigger("unmuted",e)}isMuted(){return this.mutedOptions}onmute({audio:e,video:t}){this.trigger("muted",{audio:e,video:t})}async sendInfo(){}isEnded(){return this.isEndedInner}newInfo(e){this.trigger("newInfo",e)}}class Et{extraHeaders=[];setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",T="PASSWORD_CORRECT_2",y="NAME_INCORRECT",h=400,_={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},f={status_code:200,reason_phrase:"OK"},A={status_code:401,reason_phrase:"Unauthorized"};class o{static isAvailableTelephony=!0;static startError;static countStartError=Number.POSITIVE_INFINITY;static countStarts=0;events;registratorInner;call=jest.fn((e,t)=>{const{mediaStream:r,eventHandlers:s}=t;return this.session=new i({url:e,mediaStream:r,eventHandlers:s,originator:"local"}),this.session.connect(e),this.session});sendOptions=jest.fn((e,t,r)=>{console.log("sendOptions",e,t,r)});start=jest.fn(()=>{if(o.countStarts+=1,o.startError&&o.countStarts<o.countStartError){this.trigger("disconnected",o.startError);return}this.register()});stop=jest.fn(()=>{this.startedTimeout&&clearTimeout(this.startedTimeout),this.stopedTimeout&&clearTimeout(this.stopedTimeout),this.unregister(),this.isStarted()?this.stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:!0,socket:_})},h):this.trigger("disconnected",{error:!0,socket:_})});removeAllListeners=jest.fn(()=>(this.events.removeEventHandlers(),this));once=jest.fn((e,t)=>(this.events.once(e,t),this));startedTimeout;stopedTimeout;session;isRegisteredInner;isConnectedInner;configuration;constructor(e){this.events=new O(D);const[t,r]=e.uri.split(":"),[s,a]=r.split("@"),p={...e,uri:new c.URI(t,s,a)};this.configuration=p,this.registratorInner=new Et}static setStartError(e,{count:t=Number.POSITIVE_INFINITY}={}){o.startError=e,o.countStartError=t}static resetStartError(){o.startError=void 0,o.countStartError=Number.POSITIVE_INFINITY,o.countStarts=0}static setAvailableTelephony(){o.isAvailableTelephony=!0}static setNotAvailableTelephony(){o.isAvailableTelephony=!1}static reset(){o.resetStartError(),o.setAvailableTelephony()}on(e,t){return this.events.on(e,t),this}off(e,t){return this.events.off(e,t),this}trigger(e,t){this.events.trigger(e,t)}terminateSessions(){this.session?.terminate()}set(e,t){return this.configuration[e]=t,!0}register(){this.startedTimeout&&clearTimeout(this.startedTimeout);const{password:e,register:t,uri:r}=this.configuration;t===!0&&r.user.includes(y)?(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:A,cause:c.C.causes.REJECTED})},h)):!this.isRegistered()&&t===!0&&(e===d||e===T)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:f})},h)):t===!0&&e!==d&&e!==T&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:A,cause:c.C.causes.REJECTED})},h)),o.isAvailableTelephony?(this.trigger("connected",{socket:_}),this.isConnectedInner=!0):this.stop()}unregister(){this.isRegisteredInner=!1,this.isConnectedInner=!1,this.trigger("unregistered",{response:f})}isRegistered(){return this.isRegisteredInner===!0}isConnected(){return this.isConnectedInner===!0}isStarted(){return this.configuration.register===!0&&this.isRegisteredInner===!0||this.configuration.register!==!0&&this.isConnectedInner===!0}newSipEvent(e){this.trigger("sipEvent",e)}registrator(){return this.registratorInner}}class ht{url;constructor(e){this.url=e}}class ut extends V.EventEmitter{contentType;body;constructor(e,t){super(),this.contentType=e,this.body=t}}const I="remote",mt=(n,e)=>{const t=new S(e),r={originator:I,request:t,info:new ut("","")};n.newInfo(r)},lt=(n,e)=>{const r={event:"sipEvent",request:new S(e)};n.newSipEvent(r)},pt=(n,{incomingNumber:e="1234",displayName:t,host:r})=>{const s=new i({originator:I,eventHandlers:{}}),a=new b("sip",e,r);s.remote_identity=new W(a,t);const p=new S([]);n.trigger("newRTCSession",{originator:I,session:s,request:p})},gt=(n,e)=>{e?n.trigger("failed",e):n.trigger("failed",n)},N={triggerNewInfo:mt,triggerNewSipEvent:lt,triggerIncomingSession:pt,triggerFailIncomingSession:gt,WebSocketInterface:ht,UA:o,C:{INVITE:"INVITE"}},u="user",E="displayName",m="SIP_SERVER_URL",w="SIP_WEB_SOCKET_SERVER_URL",_t=new N.WebSocketInterface(w),C={userAgent:"Chrome",sipServerUrl:m,sipWebSocketServerURL:w},Tt={...C},L={...C,user:u,password:d,register:!0},It={...L,displayName:E},St={...C,displayName:E,register:!1},l={session_timers:!1,sockets:[_t],user_agent:"Chrome",sdpSemantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},Nt={...l,password:d,uri:new c.URI("sip",u,m),display_name:"",register:!0},wt={...l,password:d,uri:new c.URI("sip",u,m),display_name:E,register:!0},Ct={...l,display_name:E,register:!1},Rt={...l,display_name:"",register:!1},F="10.10.10.10",ft=[`X-Vinteo-Remote: ${F}`],At=()=>new M.SipConnector({JsSIP:N});exports.FAILED_CONFERENCE_NUMBER=v;exports.JsSIP=N;exports.NAME_INCORRECT=y;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=T;exports.SIP_SERVER_URL=m;exports.SIP_WEB_SOCKET_SERVER_URL=w;exports.dataForConnectionWithAuthorization=L;exports.dataForConnectionWithAuthorizationWithDisplayName=It;exports.dataForConnectionWithoutAuthorization=St;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=Tt;exports.displayName=E;exports.doMockSipConnector=At;exports.extraHeadersRemoteAddress=ft;exports.remoteAddress=F;exports.uaConfigurationWithAuthorization=Nt;exports.uaConfigurationWithAuthorizationWithDisplayName=wt;exports.uaConfigurationWithoutAuthorization=Ct;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=Rt;exports.user=u;
|
package/dist/doMock.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("events-constructor");const i=require("./@SipConnector-C09fG-9w.cjs"),W=require("@krivega/cancelable-promise"),ce=require("repeated-calls"),ae=require("ts-debounce"),_=require("debug"),le=require("sequent-promises"),ue=require("stack-promises"),de=e=>e instanceof Object&&("originator"in e||"cause"in e),ge=e=>{if(W.isCanceledError(e))return!0;if(!de(e))return!1;const{originator:n,cause:t}=e;return typeof t=="string"?t===i.ECallCause.REQUEST_TIMEOUT||t===i.ECallCause.REJECTED||n===i.Originator.LOCAL&&(t===i.ECallCause.CANCELED||t===i.ECallCause.BYE):!1},fe=(e,n)=>(e.degradationPreference=n.degradationPreference,e),Ce=(e,n)=>{e.encodings??=[];for(let t=e.encodings.length;t<n;t+=1)e.encodings.push({});return e},G=e=>(n,t)=>t!==void 0&&n!==t||t===void 0&&n!==e,he=G(),Se=(e,n)=>{if(he(e,n))return e},me=(e,n)=>{const t=e.maxBitrate,o=Se(n,t);return o!==void 0&&(e.maxBitrate=o),e},K=1,Re=G(K),ye=(e,n)=>{const t=e===void 0?void 0:Math.max(e,K);if(t!==void 0&&Re(t,n))return t},pe=(e,n)=>{const t=e.scaleResolutionDownBy,o=ye(n,t);return o!==void 0&&(e.scaleResolutionDownBy=o),e},Ee=(e,n)=>{const t=n.encodings?.length??0;return Ce(e,t),e.encodings.forEach((o,r)=>{const s=(n?.encodings??[])[r],c=s?.maxBitrate,a=s?.scaleResolutionDownBy;me(o,c),pe(o,a)}),e},Te=(e,n)=>{if(e.codecs?.length!==n.codecs?.length)return!0;for(let t=0;t<(e.codecs?.length??0);t++)if(JSON.stringify(e.codecs[t])!==JSON.stringify(n.codecs[t]))return!0;if(e.headerExtensions?.length!==n.headerExtensions?.length)return!0;for(let t=0;t<(e.headerExtensions?.length??0);t++)if(JSON.stringify(e.headerExtensions[t])!==JSON.stringify(n.headerExtensions[t]))return!0;if(e.encodings?.length!==n.encodings?.length)return!0;for(let t=0;t<(e.encodings.length??0);t++)if(JSON.stringify(e.encodings[t])!==JSON.stringify(n.encodings[t]))return!0;return e.rtcp?.cname!==n.rtcp?.cname||e.rtcp?.reducedSize!==n.rtcp?.reducedSize||e.degradationPreference!==n.degradationPreference},q=async(e,n)=>{const t=e.getParameters(),o=JSON.parse(JSON.stringify(t));Ee(t,n),fe(t,n);const r=Te(o,t);return r&&await e.setParameters(t),{parameters:t,isChanged:r}},Me=e=>e.getVideoTracks()[0],ve=1e6,m=e=>e*ve,Y=m(.06),be=m(4),_e=e=>e<=64?Y:e<=128?m(.12):e<=256?m(.25):e<=384?m(.32):e<=426?m(.38):e<=640?m(.5):e<=848?m(.7):e<=1280?m(1):e<=1920?m(2):be,z=(e,n)=>e!==void 0&&n!==void 0&&e.toLowerCase().includes(n.toLowerCase()),Ae="av1",Oe=e=>z(e,Ae),Ne=.6,Q=(e,n)=>Oe(n)?e*Ne:e,Be=e=>Q(Y,e),Z=(e,n)=>{const t=_e(e);return Q(t,n)},H=1,ee=({videoTrack:e,targetSize:n,codec:t})=>{const o=e.getSettings(),r=o.width,s=o.height,c=r===void 0?H:r/n.width,a=s===void 0?H:s/n.height,l=Math.max(c,a,H),d=Z(n.width,t);return{scaleResolutionDownBy:l,maxBitrate:d}},w=({mediaStream:e,simulcastEncodings:n,sendEncodings:t})=>{if(n&&n.length>0){const o=t??[],r=Me(e);if(r===void 0)throw new Error("No video track");return n.forEach((s,c)=>{const a=o[c]??{};a.active=!0,s.rid!==void 0&&(a.rid=s.rid),s.scalabilityMode!==void 0&&(a.scalabilityMode=s.scalabilityMode);const{maxBitrate:l,scaleResolutionDownBy:d}=ee({videoTrack:r,targetSize:{width:s.width,height:s.height}});a.maxBitrate=l,a.scaleResolutionDownBy=d,o[c]=a}),o}return t},ne="purgatory",P=e=>e===ne,we=(e,n)=>e.filter(o=>n.some(r=>r.clockRate===o.clockRate&&r.mimeType===o.mimeType&&r.channels===o.channels&&r.sdpFmtpLine===o.sdpFmtpLine)),De=e=>{const n=RTCRtpSender.getCapabilities(e),t=RTCRtpReceiver.getCapabilities(e),o=n===null?[]:n.codecs,r=t===null?[]:t.codecs;return we(o,r)},Pe=(e,n)=>n===void 0||n.length===0?e:e.sort((t,o)=>{const r=n.indexOf(t.mimeType),s=n.indexOf(o.mimeType),c=r===-1?Number.MAX_VALUE:r,a=s===-1?Number.MAX_VALUE:s;return c-a}),Ie=(e,n)=>n===void 0||n.length===0?e:e.filter(t=>!n.includes(t.mimeType)),D=(e,{preferredMimeTypesVideoCodecs:n,excludeMimeTypesVideoCodecs:t})=>async o=>{try{if(typeof o.setCodecPreferences=="function"&&o.sender.track?.kind==="video"&&(n!==void 0&&n.length>0||t!==void 0&&t.length>0)){const r=De("video"),s=Ie(r,t),c=Pe(s,n);o.setCodecPreferences(c)}Object.keys(e).length>0&&await q(o.sender,e)}catch(r){i.logger("updateTransceiver error",r)}},$=e=>{if(!W.isCanceledError(e)&&!ce.hasCanceledError(e))throw e;return{isSuccessful:!1}},xe=({kind:e,readyState:n})=>e==="video"&&n==="live",Fe=new Set(["on","once","onceRace","wait","off","sendDTMF","hangUp","declineToIncomingCall","sendChannels","checkTelephony","waitChannels","ping","connection","isConfigured","isRegistered"]);class ke{on;once;onceRace;wait;off;sendDTMF;hangUp;declineToIncomingCall;sendChannels;checkTelephony;waitChannels;ping;connection;isConfigured;isRegistered;sipConnector;preferredMimeTypesVideoCodecs;excludeMimeTypesVideoCodecs;constructor(n,{preferredMimeTypesVideoCodecs:t,excludeMimeTypesVideoCodecs:o}={}){return this.preferredMimeTypesVideoCodecs=t,this.excludeMimeTypesVideoCodecs=o,this.sipConnector=n,new Proxy(this,{get:(r,s,c)=>{if(typeof s=="string"&&Fe.has(s)&&s in this.sipConnector){const l=Reflect.get(this.sipConnector,s,this.sipConnector);return typeof l=="function"?l.bind(this.sipConnector):l}const a=Reflect.get(r,s,c);return typeof a=="function"?a.bind(r):a}})}connectToServer=async n=>{const{userAgent:t,sipWebSocketServerURL:o,sipServerUrl:r,remoteAddress:s,displayName:c,name:a,password:l,isRegisteredUser:d,isDisconnectOnFail:f}=n;return i.logger("connectToServer",n),this.sipConnector.connect({userAgent:t,sipWebSocketServerURL:o,sipServerUrl:r,remoteAddress:s,displayName:c,password:l,user:a,register:d}).then(g=>(i.logger("connectToServer then"),{ua:g,isSuccessful:!0})).catch(async g=>(i.logger("connectToServer catch: error",g),f===!0?this.sipConnector.disconnect().then(()=>$(g)).catch(()=>$(g)):$(g)))};callToServer=async n=>{const{conference:t,mediaStream:o,extraHeaders:r,iceServers:s,contentHint:c,simulcastEncodings:a,degradationPreference:l,sendEncodings:d,offerToReceiveAudio:f,offerToReceiveVideo:g,directionVideo:I,directionAudio:x,setRemoteStreams:C,onBeforeProgressCall:R,onSuccessProgressCall:h,onEnterPurgatory:S,onEnterConference:y,onFailProgressCall:p,onFinishProgressCall:E,onEndedCall:T}=n,b=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:C}),A=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{b().catch(_)}}),O=D({degradationPreference:l},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});i.logger("callToServer",n);const N=async()=>(i.logger("startCall"),this.sipConnector.call({mediaStream:o,extraHeaders:r,iceServers:s,contentHint:c,offerToReceiveAudio:f,offerToReceiveVideo:g,directionVideo:I,directionAudio:x,sendEncodings:w({mediaStream:o,simulcastEncodings:a,sendEncodings:d}),number:t,onAddedTransceiver:O,ontrack:A}));let M=!1,v;const B=(i.logger("subscribeEnterConference: onEnterConference",y),S??y?this.sipConnector.on("api:enterRoom",({room:u})=>{i.logger("enterRoom",{_room:u,isSuccessProgressCall:M}),v=u,P(v)?S&&S():y&&y({isSuccessProgressCall:M})}):()=>{}),U=u=>(i.logger("onSuccess"),M=!0,b().catch(_),h&&h({isPurgatory:P(v)}),this.sipConnector.onceRace(["call:ended","call:failed"],()=>{B(),T&&T()}),u),V=u=>{throw i.logger("onFail"),p&&p(),B(),u},L=()=>{i.logger("onFinish"),E&&E()};return i.logger("onBeforeProgressCall"),R&&R(t),N().then(U).catch(u=>V(u)).finally(L)};disconnectFromServer=async()=>this.sipConnector.disconnect().then(()=>(i.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(n=>(i.logger("disconnectFromServer: catch",n),{isSuccessful:!1}));answerToIncomingCall=async n=>{const{mediaStream:t,extraHeaders:o,iceServers:r,contentHint:s,simulcastEncodings:c,degradationPreference:a,sendEncodings:l,offerToReceiveAudio:d,offerToReceiveVideo:f,directionVideo:g,directionAudio:I,setRemoteStreams:x,onBeforeProgressCall:C,onSuccessProgressCall:R,onEnterPurgatory:h,onEnterConference:S,onFailProgressCall:y,onFinishProgressCall:p,onEndedCall:E}=n,T=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:x}),b=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{T().catch(_)}}),A=D({degradationPreference:a},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});i.logger("answerToIncomingCall",n);const O=async()=>this.sipConnector.answerToIncomingCall({mediaStream:t,extraHeaders:o,iceServers:r,contentHint:s,offerToReceiveAudio:d,offerToReceiveVideo:f,directionVideo:g,directionAudio:I,sendEncodings:w({mediaStream:t,simulcastEncodings:c,sendEncodings:l}),onAddedTransceiver:A,ontrack:b}),N=()=>{const{remoteCallerData:u}=this.sipConnector;return u.incomingNumber};let M=!1,v;const B=(i.logger("subscribeEnterConference: onEnterConference",S),h??S?this.sipConnector.on("api:enterRoom",u=>{i.logger("enterRoom",{_room:u,isSuccessProgressCall:M}),v=u,P(v)?h&&h():S&&S({isSuccessProgressCall:M})}):()=>{}),U=u=>(i.logger("onSuccess"),M=!0,T().catch(_),R&&R({isPurgatory:P(v)}),this.sipConnector.onceRace(["call:ended","call:failed"],()=>{B(),E&&E()}),u),V=u=>{throw i.logger("onFail"),y&&y(),B(),u},L=()=>{i.logger("onFinish"),p&&p()};if(i.logger("onBeforeProgressCall"),C){const u=N();C(u)}return O().then(U).catch(u=>V(u)).finally(L)};updatePresentation=async({mediaStream:n,isP2P:t,maxBitrate:o,contentHint:r,simulcastEncodings:s,degradationPreference:c,sendEncodings:a,preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:d})=>{const f=D({degradationPreference:c},{preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:d});return i.logger("updatePresentation"),this.sipConnector.updatePresentation(n,{isP2P:t,maxBitrate:o,contentHint:r,sendEncodings:w({mediaStream:n,simulcastEncodings:s,sendEncodings:a}),onAddedTransceiver:f})};startPresentation=async({mediaStream:n,isP2P:t,maxBitrate:o,contentHint:r,simulcastEncodings:s,degradationPreference:c,sendEncodings:a,preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:d,callLimit:f})=>{const g=D({degradationPreference:c},{preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:d});return i.logger("startPresentation"),this.sipConnector.startPresentation(n,{isP2P:t,maxBitrate:o,contentHint:r,callLimit:f,sendEncodings:w({mediaStream:n,simulcastEncodings:s,sendEncodings:a}),onAddedTransceiver:g})};stopShareSipConnector=async({isP2P:n=!1}={})=>(i.logger("stopShareSipConnector"),this.sipConnector.stopPresentation({isP2P:n}).catch(t=>{i.logger(t)}));sendRefusalToTurnOnMic=async()=>{i.logger("sendRefusalToTurnOnMic"),await this.sipConnector.sendRefusalToTurnOnMic().catch(n=>{i.logger("sendRefusalToTurnOnMic: error",n)})};sendRefusalToTurnOnCam=async()=>{i.logger("sendRefusalToTurnOnCam"),await this.sipConnector.sendRefusalToTurnOnCam().catch(n=>{i.logger("sendRefusalToTurnOnCam: error",n)})};sendMediaState=async({isEnabledCam:n,isEnabledMic:t})=>{i.logger("sendMediaState"),await this.sipConnector.sendMediaState({cam:n,mic:t})};replaceMediaStream=async(n,{deleteExisting:t,addMissing:o,forceRenegotiation:r,contentHint:s,simulcastEncodings:c,degradationPreference:a,sendEncodings:l}={})=>{const d=D({degradationPreference:a},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});return i.logger("replaceMediaStream"),this.sipConnector.replaceMediaStream(n,{deleteExisting:t,addMissing:o,forceRenegotiation:r,contentHint:s,sendEncodings:w({mediaStream:n,simulcastEncodings:c,sendEncodings:l}),onAddedTransceiver:d})};askPermissionToEnableCam=async()=>{i.logger("askPermissionToEnableCam"),await this.sipConnector.askPermissionToEnableCam()};resolveHandleReadyRemoteStreamsDebounced=({onReadyRemoteStreams:n})=>ae.debounce(()=>{const t=this.sipConnector.getRemoteStreams();i.logger("remoteStreams",t),t&&n(t)},200);resolveHandleReadyRemoteStreams=({onReadyRemoteStreams:n})=>({track:t})=>{xe(t)&&n()};getRemoteStreams=()=>(i.logger("getRemoteStreams"),this.sipConnector.getRemoteStreams());onUseLicense=n=>(i.logger("onUseLicense"),this.sipConnector.on("api:useLicense",n));onMustStopPresentation=n=>(i.logger("onMustStopPresentation"),this.sipConnector.on("api:mustStopPresentation",n));onMoveToSpectators=n=>(i.logger("onMoveToSpectators"),this.sipConnector.on("api:participant:move-request-to-spectators",n));onMoveToParticipants=n=>(i.logger("onMoveToParticipants"),this.sipConnector.on("api:participant:move-request-to-participants",n))}const k=e=>{const{url:n,cause:t}=e;let o=n;return(t===i.ECallCause.BAD_MEDIA_DESCRIPTION||t===i.ECallCause.NOT_FOUND)&&(o=`${e.message.to.uri.user}@${e.message.to.uri.host}`),o};var te=(e=>(e.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",e.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",e.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",e.NOT_FOUND_ERROR="NOT_FOUND_ERROR",e.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",e.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",e))(te||{});const Ue=new Error("Unknown error"),Ve=(e=Ue)=>{const{cause:n,socket:t}=e;let o="CONNECT_SERVER_FAILED";switch(n){case"Forbidden":{o="WRONG_USER_OR_PASSWORD";break}case i.ECallCause.BAD_MEDIA_DESCRIPTION:{o="BAD_MEDIA_ERROR";break}case i.ECallCause.NOT_FOUND:{o="NOT_FOUND_ERROR";break}default:t!==void 0&&t._ws?.readyState===3?o="WS_CONNECTION_FAILED":k(e)!==void 0&&k(e)!==""&&(o="CONNECT_SERVER_FAILED_BY_LINK")}return o},Le=e=>{let n="";try{n=JSON.stringify(e)}catch(t){i.logger("failed to stringify message",t)}return n},He=new Error("Unknown error"),$e=(e=He)=>{const{code:n,cause:t,message:o}=e,r=k(e),s={code:"",cause:"",message:""};return typeof o=="object"&&o!==null?s.message=Le(o):o&&(s.message=String(o)),r!==void 0&&r!==""&&(s.link=r),n!==void 0&&n!==""&&(s.code=n),t!==void 0&&t!==""&&(s.cause=t),s},qe=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:te,getLinkError:k,getTypeFromError:Ve,getValuesFromError:$e},Symbol.toStringTag,{value:"Module"})),Je=({sessionId:e,remoteAddress:n,isMutedAudio:t,isMutedVideo:o,isRegistered:r,isPresentationCall:s})=>{const c=[],a=t?"0":"1",l=o?"0":"1";return c.push(`X-Vinteo-Mic-State: ${a}`,`X-Vinteo-MainCam-State: ${l}`),(r===!1||r===void 0)&&c.push("X-Vinteo-Purgatory-Call: yes"),e!==void 0&&e!==""&&c.push(`X-Vinteo-Session: ${e}`),s===!0&&c.push("X-Vinteo-Presentation-Call: yes"),n!==void 0&&n!==""&&c.push(`X-Vinteo-Remote: ${n}`),c},Xe="[@*!|]",je="_",We=e=>{let n=e;return n=n.replaceAll(new RegExp(Xe,"g"),je),n},Ge=({appName:e,appVersion:n,browserName:t,browserVersion:o})=>{const s=`${We(e)} ${n}`;return`ChromeNew - ${t===void 0?s:`${t} ${o}, ${s}`}`},Ke=({isUnifiedSdpSemantic:e,appVersion:n,browserName:t,browserVersion:o,appName:r})=>e?Ge({appVersion:n,browserName:t,browserVersion:o,appName:r}):"Chrome",Ye=e=>n=>[...n].map(o=>async()=>e(o)),ze=async({accumulatedKeys:e,sendKey:n,canRunTask:t})=>{const r=Ye(n)(e);return le.sequentPromises(r,t)},Qe=e=>t=>(i.logger("onStartMainCam"),e.on("api:admin-start-main-cam",t)),Ze=e=>t=>(i.logger("onStartMic"),e.on("api:admin-start-mic",t)),en=e=>t=>(i.logger("onStopMainCam"),e.on("api:admin-stop-main-cam",t)),nn=e=>t=>(i.logger("onStopMic"),e.on("api:admin-stop-mic",t)),tn=({sipConnector:e})=>{const n=(C,R)=>({isSyncForced:h})=>{if(h===!0){C();return}R()},t=Qe(e),o=en(e),r=Ze(e),s=nn(e);let c,a,l,d;const f=({onStartMainCamForced:C,onStartMainCamNotForced:R,onStopMainCamForced:h,onStopMainCamNotForced:S,onStartMicForced:y,onStartMicNotForced:p,onStopMicForced:E,onStopMicNotForced:T})=>{const b=n(C,R);c=t(b);const A=n(h,S);a=o(A);const O=n(y,p);l=r(O);const N=n(E,T);d=s(N)},g=()=>{c?.(),a?.(),l?.(),d?.()};return{start:C=>{f(C)},stop:()=>{g()}}},on=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:ne,createSyncMediaState:tn,error:qe,getExtraHeaders:Je,getUserAgent:Ke,hasPurgatory:P,sendDtmfAccumulated:ze},Symbol.toStringTag,{value:"Module"}));var oe=(e=>(e.VP8="video/VP8",e.VP9="video/VP9",e.H264="video/H264",e.AV1="video/AV1",e.rtx="video/rtx",e.red="video/red",e.flexfec03="video/flexfec-03",e))(oe||{});const rn=e=>[...e.keys()].map(n=>e.get(n)),sn=(e,n)=>rn(e).find(t=>t?.type===n),re=async e=>e.getStats().then(n=>sn(n,"codec")?.mimeType),cn=e=>e.find(n=>n.track?.kind==="video"),an=async(e,n,t)=>{const{isChanged:o,parameters:r}=await q(e,{encodings:[{scaleResolutionDownBy:n.scaleResolutionDownBy,maxBitrate:n.maxBitrate}]});return o&&t&&t(r),{isChanged:o,parameters:r}},se=ue.createStackPromises(),ln=async()=>se().catch(e=>{i.logger("videoSendingBalancer: error",e)}),un=async e=>(se.add(e),ln()),J=async({sender:e,scaleResolutionDownBy:n,maxBitrate:t,onSetParameters:o})=>un(async()=>an(e,{scaleResolutionDownBy:n,maxBitrate:t},o)),dn=async({sender:e,codec:n},t)=>{const r=Be(n);return J({sender:e,maxBitrate:r,onSetParameters:t,scaleResolutionDownBy:200})},F=async({sender:e,videoTrack:n,codec:t},o)=>{const c=n.getSettings().width,a=Z(c??0,t);return J({sender:e,maxBitrate:a,onSetParameters:o,scaleResolutionDownBy:1})},gn=async({sender:e,videoTrack:n,resolution:t,codec:o},r)=>{const[s,c]=t.split("x"),{maxBitrate:a,scaleResolutionDownBy:l}=ee({videoTrack:n,codec:o,targetSize:{width:Number(s),height:Number(c)}});return J({sender:e,maxBitrate:a,onSetParameters:r,scaleResolutionDownBy:l})},fn=async({mainCam:e,resolutionMainCam:n,sender:t,videoTrack:o,codec:r},s)=>{switch(e){case i.EEventsMainCAM.PAUSE_MAIN_CAM:return dn({sender:t,codec:r},s);case i.EEventsMainCAM.RESUME_MAIN_CAM:return F({sender:t,videoTrack:o,codec:r},s);case i.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return n!==void 0?gn({sender:t,videoTrack:o,codec:r,resolution:n},s):F({sender:t,videoTrack:o,codec:r},s);case i.EEventsMainCAM.ADMIN_STOP_MAIN_CAM:case i.EEventsMainCAM.ADMIN_START_MAIN_CAM:case void 0:return F({sender:t,videoTrack:o,codec:r},s);default:return F({sender:t,videoTrack:o,codec:r},s)}},X={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},j=async({mainCam:e,resolutionMainCam:n,connection:t,onSetParameters:o,ignoreForCodec:r})=>{const s=t.getSenders(),c=cn(s);if(!c?.track)return X;const a=await re(c);return z(a,r)?X:fn({mainCam:e,resolutionMainCam:n,sender:c,codec:a,videoTrack:c.track},o)},Cn=(e,{ignoreForCodec:n,onSetParameters:t}={})=>{const o=async()=>{const{connection:l}=e;if(!l)throw new Error("connection is not exist");return j({connection:l,onSetParameters:t,ignoreForCodec:n})};let r=o;const s=l=>{r=async()=>{const{mainCam:d,resolutionMainCam:f}=l,{connection:g}=e;if(!g)throw new Error("connection is not exist");return j({mainCam:d,resolutionMainCam:f,connection:g,onSetParameters:t,ignoreForCodec:n})},r().catch(_)};return{subscribe:()=>{e.on("api:main-cam-control",s)},unsubscribe:()=>{e.off("api:main-cam-control",s)},balanceByTrack:o,resetMainCamControl(){r=o},async reBalance(){return r()}}};exports.ECallCause=i.ECallCause;exports.EUseLicense=i.EUseLicense;exports.SipConnector=i.SipConnector;exports.disableDebug=i.disableDebug;exports.enableDebug=i.enableDebug;exports.hasCanceledStartPresentationError=i.hasCanceledStartPresentationError;exports.debug=_;exports.EMimeTypesVideoCodecs=oe;exports.SipConnectorFacade=ke;exports.getCodecFromSender=re;exports.hasCanceledCallError=ge;exports.resolveVideoSendingBalancer=Cn;exports.setParametersToSender=q;exports.tools=on;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("events-constructor");const i=require("./@SipConnector-BOHJ000Z.cjs"),W=require("@krivega/cancelable-promise"),ce=require("repeated-calls"),ae=require("ts-debounce"),_=require("debug"),le=require("sequent-promises"),ue=require("stack-promises"),de=e=>e instanceof Object&&("originator"in e||"cause"in e),ge=e=>{if(W.isCanceledError(e))return!0;if(!de(e))return!1;const{originator:n,cause:t}=e;return typeof t=="string"?t===i.ECallCause.REQUEST_TIMEOUT||t===i.ECallCause.REJECTED||n===i.Originator.LOCAL&&(t===i.ECallCause.CANCELED||t===i.ECallCause.BYE):!1},fe=(e,n)=>(e.degradationPreference=n.degradationPreference,e),Ce=(e,n)=>{e.encodings??=[];for(let t=e.encodings.length;t<n;t+=1)e.encodings.push({});return e},G=e=>(n,t)=>t!==void 0&&n!==t||t===void 0&&n!==e,he=G(),Se=(e,n)=>{if(he(e,n))return e},me=(e,n)=>{const t=e.maxBitrate,o=Se(n,t);return o!==void 0&&(e.maxBitrate=o),e},K=1,Re=G(K),ye=(e,n)=>{const t=e===void 0?void 0:Math.max(e,K);if(t!==void 0&&Re(t,n))return t},pe=(e,n)=>{const t=e.scaleResolutionDownBy,o=ye(n,t);return o!==void 0&&(e.scaleResolutionDownBy=o),e},Ee=(e,n)=>{const t=n.encodings?.length??0;return Ce(e,t),e.encodings.forEach((o,r)=>{const s=(n?.encodings??[])[r],c=s?.maxBitrate,a=s?.scaleResolutionDownBy;me(o,c),pe(o,a)}),e},Te=(e,n)=>{if(e.codecs?.length!==n.codecs?.length)return!0;for(let t=0;t<(e.codecs?.length??0);t++)if(JSON.stringify(e.codecs[t])!==JSON.stringify(n.codecs[t]))return!0;if(e.headerExtensions?.length!==n.headerExtensions?.length)return!0;for(let t=0;t<(e.headerExtensions?.length??0);t++)if(JSON.stringify(e.headerExtensions[t])!==JSON.stringify(n.headerExtensions[t]))return!0;if(e.encodings?.length!==n.encodings?.length)return!0;for(let t=0;t<(e.encodings.length??0);t++)if(JSON.stringify(e.encodings[t])!==JSON.stringify(n.encodings[t]))return!0;return e.rtcp?.cname!==n.rtcp?.cname||e.rtcp?.reducedSize!==n.rtcp?.reducedSize||e.degradationPreference!==n.degradationPreference},q=async(e,n)=>{const t=e.getParameters(),o=JSON.parse(JSON.stringify(t));Ee(t,n),fe(t,n);const r=Te(o,t);return r&&await e.setParameters(t),{parameters:t,isChanged:r}},Me=e=>e.getVideoTracks()[0],ve=1e6,m=e=>e*ve,Y=m(.06),be=m(4),_e=e=>e<=64?Y:e<=128?m(.12):e<=256?m(.25):e<=384?m(.32):e<=426?m(.38):e<=640?m(.5):e<=848?m(.7):e<=1280?m(1):e<=1920?m(2):be,z=(e,n)=>e!==void 0&&n!==void 0&&e.toLowerCase().includes(n.toLowerCase()),Ae="av1",Oe=e=>z(e,Ae),Ne=.6,Q=(e,n)=>Oe(n)?e*Ne:e,Be=e=>Q(Y,e),Z=(e,n)=>{const t=_e(e);return Q(t,n)},H=1,ee=({videoTrack:e,targetSize:n,codec:t})=>{const o=e.getSettings(),r=o.width,s=o.height,c=r===void 0?H:r/n.width,a=s===void 0?H:s/n.height,l=Math.max(c,a,H),d=Z(n.width,t);return{scaleResolutionDownBy:l,maxBitrate:d}},w=({mediaStream:e,simulcastEncodings:n,sendEncodings:t})=>{if(n&&n.length>0){const o=t??[],r=Me(e);if(r===void 0)throw new Error("No video track");return n.forEach((s,c)=>{const a=o[c]??{};a.active=!0,s.rid!==void 0&&(a.rid=s.rid),s.scalabilityMode!==void 0&&(a.scalabilityMode=s.scalabilityMode);const{maxBitrate:l,scaleResolutionDownBy:d}=ee({videoTrack:r,targetSize:{width:s.width,height:s.height}});a.maxBitrate=l,a.scaleResolutionDownBy=d,o[c]=a}),o}return t},ne="purgatory",P=e=>e===ne,we=(e,n)=>e.filter(o=>n.some(r=>r.clockRate===o.clockRate&&r.mimeType===o.mimeType&&r.channels===o.channels&&r.sdpFmtpLine===o.sdpFmtpLine)),De=e=>{const n=RTCRtpSender.getCapabilities(e),t=RTCRtpReceiver.getCapabilities(e),o=n===null?[]:n.codecs,r=t===null?[]:t.codecs;return we(o,r)},Pe=(e,n)=>n===void 0||n.length===0?e:e.sort((t,o)=>{const r=n.indexOf(t.mimeType),s=n.indexOf(o.mimeType),c=r===-1?Number.MAX_VALUE:r,a=s===-1?Number.MAX_VALUE:s;return c-a}),Ie=(e,n)=>n===void 0||n.length===0?e:e.filter(t=>!n.includes(t.mimeType)),D=(e,{preferredMimeTypesVideoCodecs:n,excludeMimeTypesVideoCodecs:t})=>async o=>{try{if(typeof o.setCodecPreferences=="function"&&o.sender.track?.kind==="video"&&(n!==void 0&&n.length>0||t!==void 0&&t.length>0)){const r=De("video"),s=Ie(r,t),c=Pe(s,n);o.setCodecPreferences(c)}Object.keys(e).length>0&&await q(o.sender,e)}catch(r){i.logger("updateTransceiver error",r)}},$=e=>{if(!W.isCanceledError(e)&&!ce.hasCanceledError(e))throw e;return{isSuccessful:!1}},xe=({kind:e,readyState:n})=>e==="video"&&n==="live",Fe=new Set(["on","once","onceRace","wait","off","sendDTMF","hangUp","declineToIncomingCall","sendChannels","checkTelephony","waitChannels","ping","connection","isConfigured","isRegistered"]);class ke{on;once;onceRace;wait;off;sendDTMF;hangUp;declineToIncomingCall;sendChannels;checkTelephony;waitChannels;ping;connection;isConfigured;isRegistered;sipConnector;preferredMimeTypesVideoCodecs;excludeMimeTypesVideoCodecs;constructor(n,{preferredMimeTypesVideoCodecs:t,excludeMimeTypesVideoCodecs:o}={}){return this.preferredMimeTypesVideoCodecs=t,this.excludeMimeTypesVideoCodecs=o,this.sipConnector=n,new Proxy(this,{get:(r,s,c)=>{if(typeof s=="string"&&Fe.has(s)&&s in this.sipConnector){const l=Reflect.get(this.sipConnector,s,this.sipConnector);return typeof l=="function"?l.bind(this.sipConnector):l}const a=Reflect.get(r,s,c);return typeof a=="function"?a.bind(r):a}})}connectToServer=async n=>{const{userAgent:t,sipWebSocketServerURL:o,sipServerUrl:r,remoteAddress:s,displayName:c,name:a,password:l,isRegisteredUser:d,isDisconnectOnFail:f}=n;return i.logger("connectToServer",n),this.sipConnector.connect({userAgent:t,sipWebSocketServerURL:o,sipServerUrl:r,remoteAddress:s,displayName:c,password:l,user:a,register:d}).then(g=>(i.logger("connectToServer then"),{ua:g,isSuccessful:!0})).catch(async g=>(i.logger("connectToServer catch: error",g),f===!0?this.sipConnector.disconnect().then(()=>$(g)).catch(()=>$(g)):$(g)))};callToServer=async n=>{const{conference:t,mediaStream:o,extraHeaders:r,iceServers:s,contentHint:c,simulcastEncodings:a,degradationPreference:l,sendEncodings:d,offerToReceiveAudio:f,offerToReceiveVideo:g,directionVideo:I,directionAudio:x,setRemoteStreams:C,onBeforeProgressCall:R,onSuccessProgressCall:h,onEnterPurgatory:S,onEnterConference:y,onFailProgressCall:p,onFinishProgressCall:E,onEndedCall:T}=n,b=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:C}),A=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{b().catch(_)}}),O=D({degradationPreference:l},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});i.logger("callToServer",n);const N=async()=>(i.logger("startCall"),this.sipConnector.call({mediaStream:o,extraHeaders:r,iceServers:s,contentHint:c,offerToReceiveAudio:f,offerToReceiveVideo:g,directionVideo:I,directionAudio:x,sendEncodings:w({mediaStream:o,simulcastEncodings:a,sendEncodings:d}),number:t,onAddedTransceiver:O,ontrack:A}));let M=!1,v;const B=(i.logger("subscribeEnterConference: onEnterConference",y),S??y?this.sipConnector.on("api:enterRoom",({room:u})=>{i.logger("enterRoom",{_room:u,isSuccessProgressCall:M}),v=u,P(v)?S&&S():y&&y({isSuccessProgressCall:M})}):()=>{}),U=u=>(i.logger("onSuccess"),M=!0,b().catch(_),h&&h({isPurgatory:P(v)}),this.sipConnector.onceRace(["call:ended","call:failed"],()=>{B(),T&&T()}),u),V=u=>{throw i.logger("onFail"),p&&p(),B(),u},L=()=>{i.logger("onFinish"),E&&E()};return i.logger("onBeforeProgressCall"),R&&R(t),N().then(U).catch(u=>V(u)).finally(L)};disconnectFromServer=async()=>this.sipConnector.disconnect().then(()=>(i.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(n=>(i.logger("disconnectFromServer: catch",n),{isSuccessful:!1}));answerToIncomingCall=async n=>{const{mediaStream:t,extraHeaders:o,iceServers:r,contentHint:s,simulcastEncodings:c,degradationPreference:a,sendEncodings:l,offerToReceiveAudio:d,offerToReceiveVideo:f,directionVideo:g,directionAudio:I,setRemoteStreams:x,onBeforeProgressCall:C,onSuccessProgressCall:R,onEnterPurgatory:h,onEnterConference:S,onFailProgressCall:y,onFinishProgressCall:p,onEndedCall:E}=n,T=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:x}),b=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{T().catch(_)}}),A=D({degradationPreference:a},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});i.logger("answerToIncomingCall",n);const O=async()=>this.sipConnector.answerToIncomingCall({mediaStream:t,extraHeaders:o,iceServers:r,contentHint:s,offerToReceiveAudio:d,offerToReceiveVideo:f,directionVideo:g,directionAudio:I,sendEncodings:w({mediaStream:t,simulcastEncodings:c,sendEncodings:l}),onAddedTransceiver:A,ontrack:b}),N=()=>{const{remoteCallerData:u}=this.sipConnector;return u.incomingNumber};let M=!1,v;const B=(i.logger("subscribeEnterConference: onEnterConference",S),h??S?this.sipConnector.on("api:enterRoom",u=>{i.logger("enterRoom",{_room:u,isSuccessProgressCall:M}),v=u,P(v)?h&&h():S&&S({isSuccessProgressCall:M})}):()=>{}),U=u=>(i.logger("onSuccess"),M=!0,T().catch(_),R&&R({isPurgatory:P(v)}),this.sipConnector.onceRace(["call:ended","call:failed"],()=>{B(),E&&E()}),u),V=u=>{throw i.logger("onFail"),y&&y(),B(),u},L=()=>{i.logger("onFinish"),p&&p()};if(i.logger("onBeforeProgressCall"),C){const u=N();C(u)}return O().then(U).catch(u=>V(u)).finally(L)};updatePresentation=async({mediaStream:n,isP2P:t,maxBitrate:o,contentHint:r,simulcastEncodings:s,degradationPreference:c,sendEncodings:a,preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:d})=>{const f=D({degradationPreference:c},{preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:d});return i.logger("updatePresentation"),this.sipConnector.updatePresentation(n,{isP2P:t,maxBitrate:o,contentHint:r,sendEncodings:w({mediaStream:n,simulcastEncodings:s,sendEncodings:a}),onAddedTransceiver:f})};startPresentation=async({mediaStream:n,isP2P:t,maxBitrate:o,contentHint:r,simulcastEncodings:s,degradationPreference:c,sendEncodings:a,preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:d,callLimit:f})=>{const g=D({degradationPreference:c},{preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:d});return i.logger("startPresentation"),this.sipConnector.startPresentation(n,{isP2P:t,maxBitrate:o,contentHint:r,callLimit:f,sendEncodings:w({mediaStream:n,simulcastEncodings:s,sendEncodings:a}),onAddedTransceiver:g})};stopShareSipConnector=async({isP2P:n=!1}={})=>(i.logger("stopShareSipConnector"),this.sipConnector.stopPresentation({isP2P:n}).catch(t=>{i.logger(t)}));sendRefusalToTurnOnMic=async()=>{i.logger("sendRefusalToTurnOnMic"),await this.sipConnector.sendRefusalToTurnOnMic().catch(n=>{i.logger("sendRefusalToTurnOnMic: error",n)})};sendRefusalToTurnOnCam=async()=>{i.logger("sendRefusalToTurnOnCam"),await this.sipConnector.sendRefusalToTurnOnCam().catch(n=>{i.logger("sendRefusalToTurnOnCam: error",n)})};sendMediaState=async({isEnabledCam:n,isEnabledMic:t})=>{i.logger("sendMediaState"),await this.sipConnector.sendMediaState({cam:n,mic:t})};replaceMediaStream=async(n,{deleteExisting:t,addMissing:o,forceRenegotiation:r,contentHint:s,simulcastEncodings:c,degradationPreference:a,sendEncodings:l}={})=>{const d=D({degradationPreference:a},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});return i.logger("replaceMediaStream"),this.sipConnector.replaceMediaStream(n,{deleteExisting:t,addMissing:o,forceRenegotiation:r,contentHint:s,sendEncodings:w({mediaStream:n,simulcastEncodings:c,sendEncodings:l}),onAddedTransceiver:d})};askPermissionToEnableCam=async()=>{i.logger("askPermissionToEnableCam"),await this.sipConnector.askPermissionToEnableCam()};resolveHandleReadyRemoteStreamsDebounced=({onReadyRemoteStreams:n})=>ae.debounce(()=>{const t=this.sipConnector.getRemoteStreams();i.logger("remoteStreams",t),t&&n(t)},200);resolveHandleReadyRemoteStreams=({onReadyRemoteStreams:n})=>({track:t})=>{xe(t)&&n()};getRemoteStreams=()=>(i.logger("getRemoteStreams"),this.sipConnector.getRemoteStreams());onUseLicense=n=>(i.logger("onUseLicense"),this.sipConnector.on("api:useLicense",n));onMustStopPresentation=n=>(i.logger("onMustStopPresentation"),this.sipConnector.on("api:mustStopPresentation",n));onMoveToSpectators=n=>(i.logger("onMoveToSpectators"),this.sipConnector.on("api:participant:move-request-to-spectators",n));onMoveToParticipants=n=>(i.logger("onMoveToParticipants"),this.sipConnector.on("api:participant:move-request-to-participants",n))}const k=e=>{const{url:n,cause:t}=e;let o=n;return(t===i.ECallCause.BAD_MEDIA_DESCRIPTION||t===i.ECallCause.NOT_FOUND)&&(o=`${e.message.to.uri.user}@${e.message.to.uri.host}`),o};var te=(e=>(e.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",e.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",e.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",e.NOT_FOUND_ERROR="NOT_FOUND_ERROR",e.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",e.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",e))(te||{});const Ue=new Error("Unknown error"),Ve=(e=Ue)=>{const{cause:n,socket:t}=e;let o="CONNECT_SERVER_FAILED";switch(n){case"Forbidden":{o="WRONG_USER_OR_PASSWORD";break}case i.ECallCause.BAD_MEDIA_DESCRIPTION:{o="BAD_MEDIA_ERROR";break}case i.ECallCause.NOT_FOUND:{o="NOT_FOUND_ERROR";break}default:t!==void 0&&t._ws?.readyState===3?o="WS_CONNECTION_FAILED":k(e)!==void 0&&k(e)!==""&&(o="CONNECT_SERVER_FAILED_BY_LINK")}return o},Le=e=>{let n="";try{n=JSON.stringify(e)}catch(t){i.logger("failed to stringify message",t)}return n},He=new Error("Unknown error"),$e=(e=He)=>{const{code:n,cause:t,message:o}=e,r=k(e),s={code:"",cause:"",message:""};return typeof o=="object"&&o!==null?s.message=Le(o):o&&(s.message=String(o)),r!==void 0&&r!==""&&(s.link=r),n!==void 0&&n!==""&&(s.code=n),t!==void 0&&t!==""&&(s.cause=t),s},qe=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:te,getLinkError:k,getTypeFromError:Ve,getValuesFromError:$e},Symbol.toStringTag,{value:"Module"})),Je=({sessionId:e,remoteAddress:n,isMutedAudio:t,isMutedVideo:o,isRegistered:r,isPresentationCall:s})=>{const c=[],a=t?"0":"1",l=o?"0":"1";return c.push(`X-Vinteo-Mic-State: ${a}`,`X-Vinteo-MainCam-State: ${l}`),(r===!1||r===void 0)&&c.push("X-Vinteo-Purgatory-Call: yes"),e!==void 0&&e!==""&&c.push(`X-Vinteo-Session: ${e}`),s===!0&&c.push("X-Vinteo-Presentation-Call: yes"),n!==void 0&&n!==""&&c.push(`X-Vinteo-Remote: ${n}`),c},Xe="[@*!|]",je="_",We=e=>{let n=e;return n=n.replaceAll(new RegExp(Xe,"g"),je),n},Ge=({appName:e,appVersion:n,browserName:t,browserVersion:o})=>{const s=`${We(e)} ${n}`;return`ChromeNew - ${t===void 0?s:`${t} ${o}, ${s}`}`},Ke=({isUnifiedSdpSemantic:e,appVersion:n,browserName:t,browserVersion:o,appName:r})=>e?Ge({appVersion:n,browserName:t,browserVersion:o,appName:r}):"Chrome",Ye=e=>n=>[...n].map(o=>async()=>e(o)),ze=async({accumulatedKeys:e,sendKey:n,canRunTask:t})=>{const r=Ye(n)(e);return le.sequentPromises(r,t)},Qe=e=>t=>(i.logger("onStartMainCam"),e.on("api:admin-start-main-cam",t)),Ze=e=>t=>(i.logger("onStartMic"),e.on("api:admin-start-mic",t)),en=e=>t=>(i.logger("onStopMainCam"),e.on("api:admin-stop-main-cam",t)),nn=e=>t=>(i.logger("onStopMic"),e.on("api:admin-stop-mic",t)),tn=({sipConnector:e})=>{const n=(C,R)=>({isSyncForced:h})=>{if(h===!0){C();return}R()},t=Qe(e),o=en(e),r=Ze(e),s=nn(e);let c,a,l,d;const f=({onStartMainCamForced:C,onStartMainCamNotForced:R,onStopMainCamForced:h,onStopMainCamNotForced:S,onStartMicForced:y,onStartMicNotForced:p,onStopMicForced:E,onStopMicNotForced:T})=>{const b=n(C,R);c=t(b);const A=n(h,S);a=o(A);const O=n(y,p);l=r(O);const N=n(E,T);d=s(N)},g=()=>{c?.(),a?.(),l?.(),d?.()};return{start:C=>{f(C)},stop:()=>{g()}}},on=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:ne,createSyncMediaState:tn,error:qe,getExtraHeaders:Je,getUserAgent:Ke,hasPurgatory:P,sendDtmfAccumulated:ze},Symbol.toStringTag,{value:"Module"}));var oe=(e=>(e.VP8="video/VP8",e.VP9="video/VP9",e.H264="video/H264",e.AV1="video/AV1",e.rtx="video/rtx",e.red="video/red",e.flexfec03="video/flexfec-03",e))(oe||{});const rn=e=>[...e.keys()].map(n=>e.get(n)),sn=(e,n)=>rn(e).find(t=>t?.type===n),re=async e=>e.getStats().then(n=>sn(n,"codec")?.mimeType),cn=e=>e.find(n=>n.track?.kind==="video"),an=async(e,n,t)=>{const{isChanged:o,parameters:r}=await q(e,{encodings:[{scaleResolutionDownBy:n.scaleResolutionDownBy,maxBitrate:n.maxBitrate}]});return o&&t&&t(r),{isChanged:o,parameters:r}},se=ue.createStackPromises(),ln=async()=>se().catch(e=>{i.logger("videoSendingBalancer: error",e)}),un=async e=>(se.add(e),ln()),J=async({sender:e,scaleResolutionDownBy:n,maxBitrate:t,onSetParameters:o})=>un(async()=>an(e,{scaleResolutionDownBy:n,maxBitrate:t},o)),dn=async({sender:e,codec:n},t)=>{const r=Be(n);return J({sender:e,maxBitrate:r,onSetParameters:t,scaleResolutionDownBy:200})},F=async({sender:e,videoTrack:n,codec:t},o)=>{const c=n.getSettings().width,a=Z(c??0,t);return J({sender:e,maxBitrate:a,onSetParameters:o,scaleResolutionDownBy:1})},gn=async({sender:e,videoTrack:n,resolution:t,codec:o},r)=>{const[s,c]=t.split("x"),{maxBitrate:a,scaleResolutionDownBy:l}=ee({videoTrack:n,codec:o,targetSize:{width:Number(s),height:Number(c)}});return J({sender:e,maxBitrate:a,onSetParameters:r,scaleResolutionDownBy:l})},fn=async({mainCam:e,resolutionMainCam:n,sender:t,videoTrack:o,codec:r},s)=>{switch(e){case i.EEventsMainCAM.PAUSE_MAIN_CAM:return dn({sender:t,codec:r},s);case i.EEventsMainCAM.RESUME_MAIN_CAM:return F({sender:t,videoTrack:o,codec:r},s);case i.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return n!==void 0?gn({sender:t,videoTrack:o,codec:r,resolution:n},s):F({sender:t,videoTrack:o,codec:r},s);case i.EEventsMainCAM.ADMIN_STOP_MAIN_CAM:case i.EEventsMainCAM.ADMIN_START_MAIN_CAM:case void 0:return F({sender:t,videoTrack:o,codec:r},s);default:return F({sender:t,videoTrack:o,codec:r},s)}},X={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},j=async({mainCam:e,resolutionMainCam:n,connection:t,onSetParameters:o,ignoreForCodec:r})=>{const s=t.getSenders(),c=cn(s);if(!c?.track)return X;const a=await re(c);return z(a,r)?X:fn({mainCam:e,resolutionMainCam:n,sender:c,codec:a,videoTrack:c.track},o)},Cn=(e,{ignoreForCodec:n,onSetParameters:t}={})=>{const o=async()=>{const{connection:l}=e;if(!l)throw new Error("connection is not exist");return j({connection:l,onSetParameters:t,ignoreForCodec:n})};let r=o;const s=l=>{r=async()=>{const{mainCam:d,resolutionMainCam:f}=l,{connection:g}=e;if(!g)throw new Error("connection is not exist");return j({mainCam:d,resolutionMainCam:f,connection:g,onSetParameters:t,ignoreForCodec:n})},r().catch(_)};return{subscribe:()=>{e.on("api:main-cam-control",s)},unsubscribe:()=>{e.off("api:main-cam-control",s)},balanceByTrack:o,resetMainCamControl(){r=o},async reBalance(){return r()}}};exports.ECallCause=i.ECallCause;exports.EUseLicense=i.EUseLicense;exports.SipConnector=i.SipConnector;exports.disableDebug=i.disableDebug;exports.enableDebug=i.enableDebug;exports.hasCanceledStartPresentationError=i.hasCanceledStartPresentationError;exports.debug=_;exports.EMimeTypesVideoCodecs=oe;exports.SipConnectorFacade=ke;exports.getCodecFromSender=re;exports.hasCanceledCallError=ge;exports.resolveVideoSendingBalancer=Cn;exports.setParametersToSender=q;exports.tools=on;
|
package/dist/index.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ export { SipConnector } from './SipConnector';
|
|
|
9
9
|
export { SipConnectorFacade } from './SipConnectorFacade';
|
|
10
10
|
export * as tools from './tools';
|
|
11
11
|
export { EMimeTypesVideoCodecs } from './types';
|
|
12
|
+
export type { TJsSIP } from './types';
|
|
12
13
|
export { default as getCodecFromSender } from './utils/getCodecFromSender';
|
|
13
14
|
export { default as resolveVideoSendingBalancer } from './videoSendingBalancer';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "events-constructor";
|
|
2
|
-
import { E as y, O as ce, l as c, a as w } from "./@SipConnector-
|
|
3
|
-
import { b as On, S as Nn, d as Bn, e as wn, h as Dn } from "./@SipConnector-
|
|
2
|
+
import { E as y, O as ce, l as c, a as w } from "./@SipConnector-BxitfweK.js";
|
|
3
|
+
import { b as On, S as Nn, d as Bn, e as wn, h as Dn } from "./@SipConnector-BxitfweK.js";
|
|
4
4
|
import { isCanceledError as K } from "@krivega/cancelable-promise";
|
|
5
5
|
import { hasCanceledError as ae } from "repeated-calls";
|
|
6
6
|
import { debounce as ue } from "ts-debounce";
|
package/dist/types.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ export type TJsSIP = {
|
|
|
3
3
|
UA: typeof UA;
|
|
4
4
|
WebSocketInterface: typeof WebSocketInterface;
|
|
5
5
|
};
|
|
6
|
-
export type TGetServerUrl = (id: string) => string;
|
|
7
6
|
export type TRtpSendParameters = Partial<Omit<RTCRtpSendParameters, 'transactionId'>>;
|
|
8
7
|
export type TSize = {
|
|
9
8
|
width: number;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const f=require("events-constructor");require("@krivega/cancelable-promise");const k=require("debug"),W=require("repeated-calls"),G=require("xstate");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||{}),v=(n=>(n.LOCAL="local",n.REMOTE="remote",n.SYSTEM="system",n))(v||{});const B=["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"],Z=["peerconnection:confirmed","peerconnection:ontrack","ended:fromserver"],q=[...B,...Z];function ee(n){return e=>`sip:${e}@${n}`}const te=(n,e)=>()=>Math.floor(Math.random()*(e-n))+n,x=n=>n.trim().replaceAll(" ","_"),ne=te(1e5,99999999),se=n=>n.some(t=>{const{kind:s}=t;return s==="video"}),ie=(n,e)=>{n.getVideoTracks().forEach(s=>{"contentHint"in s&&s.contentHint!==e&&(s.contentHint=e)})},y=(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"&&ie(o,s),o};class re{isPendingCall=!1;isPendingAnswer=!1;rtcSession;remoteStreams={};events;callConfiguration={};constructor(e){this.events=e}}var V=(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))(V||{});class ae{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 oe extends re{remoteStreamsManager=new ae;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:d,offerToReceiveAudio:S=!0,offerToReceiveVideo:l=!0,sendEncodings:E,onAddedTransceiver:I})=>(this.isPendingCall=!0,new Promise((C,P)=>{this.callConfiguration.number=s,this.callConfiguration.answer=!1,this.handleCall({ontrack:a}).then(C).catch(b=>{P(b)}),this.rtcSession=e.call(t(s),{extraHeaders:r,mediaStream:y(i,{directionVideo:c,directionAudio:g,contentHint:d}),directionVideo:c,directionAudio:g,pcConfig:{iceServers:o},rtcOfferConstraints:{offerToReceiveAudio:S,offerToReceiveVideo:l},sendEncodings:E,onAddedTransceiver:I}),this.subscribeToSessionEvents(this.rtcSession)}).finally(()=>{this.isPendingCall=!1}));async endCall(){const{rtcSession:e}=this;if(e&&!e.isEnded())return e.terminateAsync({cause:V.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:d,sendEncodings:S,onAddedTransceiver:l})=>(this.isPendingAnswer=!0,new Promise((E,I)=>{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(E).catch(b=>{I(b)});const P=y(t,{directionVideo:a,directionAudio:o,contentHint:d});C.answer({extraHeaders:i,directionVideo:a,directionAudio:o,mediaStream:P,pcConfig:{iceServers:r},rtcOfferConstraints:{offerToReceiveAudio:c,offerToReceiveVideo:g},sendEncodings:S,onAddedTransceiver:l})}catch(C){I(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 se(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=y(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,d),this.events.on(N.CONFIRMED,S)},r=()=>{this.events.off(N.PEER_CONNECTION,d),this.events.off(N.CONFIRMED,S)},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=l=>{r(),o(),s(l)};let g;const d=({peerconnection:l})=>{g=l;const E=I=>{this.events.trigger(N.PEER_CONNECTION_ONTRACK,l),e&&e(I)};l.addEventListener("track",E),this.disposers.add(()=>{l.removeEventListener("track",E)})},S=()=>{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=B.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===v.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 ce{events;strategy;constructor(e){this.events=new f(q),this.strategy=e??new oe(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 H="sip-connector",p=k(H),ge=()=>{k.enable(H)},Te=()=>{k.enable(`-${H}`)},he="Error decline with 603",de=1006,le=n=>typeof n=="object"&&n!==null&&"code"in n&&n.code===de,Ee=n=>n.message===he;var h=(n=>(n.CONTENT_TYPE_NAME="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||{}),U=(n=>(n.AVAILABLE_SECOND_REMOTE_STREAM="YOUCANRECEIVECONTENT",n.NOT_AVAILABLE_SECOND_REMOTE_STREAM="CONTENTEND",n.MUST_STOP_PRESENTATION="YOUMUSTSTOPSENDCONTENT",n))(U||{}),w=(n=>(n.SPECTATOR="SPECTATOR",n.PARTICIPANT="PARTICIPANT",n))(w||{}),M=(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))(M||{}),_=(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))(_||{}),m=(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))(m||{}),L=(n=>(n.ADMIN_STOP_MIC="ADMINSTOPMIC",n.ADMIN_START_MIC="ADMINSTARTMIC",n))(L||{}),F=(n=>(n.ADMIN_SYNC_FORCED="1",n.ADMIN_SYNC_NOT_FORCED="0",n))(F||{}),Y=(n=>(n.AUDIO="AUDIO",n.VIDEO="VIDEO",n.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION",n))(Y||{}),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.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","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 A=(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))(A||{});class Se{events;connectionManager;callManager;constructor({connectionManager:e,callManager:t}){this.connectionManager=e,this.callManager=t,this.events=new f(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)=>{const i=this.callManager.getEstablishedRTCSession();if(!i){s(new Error("No rtcSession established"));return}this.callManager.once("newDTMF",({originator:r})=>{r===v.LOCAL&&t()}),i.sendDTMF(e,{duration:120,interToneGap:600})})}async sendChannels({inputChannels:e,outputChannels:t}){const s=this.callManager.getEstablishedRTCSession();if(!s)throw new Error("No rtcSession established");const i=`${h.INPUT_CHANNELS}: ${e}`,r=`${h.OUTPUT_CHANNELS}: ${t}`,a=[i,r];return s.sendInfo(_.CHANNELS,void 0,{extraHeaders:a})}async sendMediaState({cam:e,mic:t},s={}){const i=this.callManager.getEstablishedRTCSession();if(!i)throw new Error("No rtcSession established");const 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(_.MEDIA_STATE,void 0,{noTerminateWhenError:!0,...s,extraHeaders:c})}async sendRefusalToTurnOn(e,t={}){const s=this.callManager.getEstablishedRTCSession();if(!s)throw new Error("No rtcSession established");const a=e==="mic"?0:1,c=[`${h.MEDIA_TYPE}: ${a}`];return s.sendInfo(_.REFUSAL,void 0,{noTerminateWhenError:!0,...t,extraHeaders:c})}async sendRefusalToTurnOnMic(e={}){if(!this.callManager.getEstablishedRTCSession())throw new Error("No rtcSession established");return this.sendRefusalToTurnOn("mic",{noTerminateWhenError:!0,...e})}async sendRefusalToTurnOnCam(e={}){if(!this.callManager.getEstablishedRTCSession())throw new Error("No rtcSession established");return this.sendRefusalToTurnOn("cam",{noTerminateWhenError:!0,...e})}async sendMustStopPresentationP2P(){const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");await e.sendInfo(_.SHARE_STATE,void 0,{extraHeaders:[h.MUST_STOP_PRESENTATION_P2P]})}async sendStoppedPresentationP2P(){const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");await e.sendInfo(_.SHARE_STATE,void 0,{extraHeaders:[h.STOP_PRESENTATION_P2P]})}async sendStoppedPresentation(){const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");await e.sendInfo(_.SHARE_STATE,void 0,{extraHeaders:[h.STOP_PRESENTATION]})}async askPermissionToStartPresentationP2P(){const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");await e.sendInfo(_.SHARE_STATE,void 0,{extraHeaders:[h.START_PRESENTATION_P2P]})}async askPermissionToStartPresentation(){const e=this.callManager.getEstablishedRTCSession();if(!e)throw new Error("No rtcSession established");await e.sendInfo(_.SHARE_STATE,void 0,{extraHeaders:[h.START_PRESENTATION]})}async askPermissionToEnableCam(e={}){const t=this.callManager.getEstablishedRTCSession();if(!t)throw new Error("No rtcSession established");const s=[h.ENABLE_MAIN_CAM];return t.sendInfo(_.MAIN_CAM,void 0,{noTerminateWhenError:!0,...e,extraHeaders:s}).catch(i=>{if(Ee(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)}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){p("error parse notify",t)}};handleNotify=e=>{switch(e.cmd){case A.CHANNELS:{const t=e;this.triggerChannelsNotify(t);break}case A.WEBCAST_STARTED:{const t=e;this.triggerWebcastStartedNotify(t);break}case A.WEBCAST_STOPPED:{const t=e;this.triggerWebcastStoppedNotify(t);break}case A.ADDED_TO_LIST_MODERATORS:{const t=e;this.triggerAddedToListModeratorsNotify(t);break}case A.REMOVED_FROM_LIST_MODERATORS:{const t=e;this.triggerRemovedFromListModeratorsNotify(t);break}case A.ACCEPTING_WORD_REQUEST:{const t=e;this.triggerParticipationAcceptingWordRequest(t);break}case A.CANCELLING_WORD_REQUEST:{const t=e;this.triggerParticipationCancellingWordRequest(t);break}case A.MOVE_REQUEST_TO_STREAM:{const t=e;this.triggerParticipantMoveRequestToStream(t);break}case A.ACCOUNT_CHANGED:{this.triggerAccountChangedNotify();break}case A.ACCOUNT_DELETED:{this.triggerAccountDeletedNotify();break}case A.CONFERENCE_PARTICIPANT_TOKEN_ISSUED:{const t=e;this.triggerConferenceParticipantTokenIssued(t);break}default:p("unknown cmd",e)}};handleNewInfo=e=>{const{originator:t}=e;if(t!==v.REMOTE)return;const{request:s}=e,i=s.getHeader(h.CONTENT_TYPE_NAME);if(i!==void 0)switch(i){case M.ENTER_ROOM:{this.triggerEnterRoom(s),this.maybeTriggerChannels(s);break}case M.NOTIFY:{this.maybeHandleNotify(s);break}case M.SHARE_STATE:{this.triggerShareState(s);break}case M.MAIN_CAM:{this.triggerMainCamControl(s);break}case M.MIC:{this.triggerMicControl(s);break}case M.USE_LICENSE:{this.triggerUseLicense(s);break}case M.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 U.AVAILABLE_SECOND_REMOTE_STREAM:{this.events.trigger(T.AVAILABLE_SECOND_REMOTE_STREAM,void 0);break}case U.NOT_AVAILABLE_SECOND_REMOTE_STREAM:{this.events.trigger(T.NOT_AVAILABLE_SECOND_REMOTE_STREAM,void 0);break}case U.MUST_STOP_PRESENTATION:{this.events.trigger(T.MUST_STOP_PRESENTATION,void 0);break}}};maybeTriggerParticipantMoveRequest=e=>{const t=e.getHeader(h.CONTENT_PARTICIPANT_STATE);t===w.SPECTATOR&&this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS,void 0),t===w.PARTICIPANT&&this.events.trigger(T.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS,void 0)};triggerMainCamControl=e=>{const t=e.getHeader(h.MAIN_CAM),s=e.getHeader(h.MEDIA_SYNC),i=s===F.ADMIN_SYNC_FORCED;if(t===m.ADMIN_START_MAIN_CAM){this.events.trigger(T.ADMIN_START_MAIN_CAM,{isSyncForced:i});return}if(t===m.ADMIN_STOP_MAIN_CAM){this.events.trigger(T.ADMIN_STOP_MAIN_CAM,{isSyncForced:i});return}(t===m.RESUME_MAIN_CAM||t===m.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)===F.ADMIN_SYNC_FORCED;t===L.ADMIN_START_MIC?this.events.trigger(T.ADMIN_START_MIC,{isSyncForced:i}):t===L.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 R=(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))(R||{});const Q=["presentation:start","presentation:started","presentation:end","presentation:ended","presentation:failed"],Ce=1,Ne=n=>W.hasCanceledError(n);class ue{events;promisePendingStartPresentation;promisePendingStopPresentation;streamPresentationCurrent;cancelableSendPresentationWithRepeatedCalls;callManager;constructor({callManager:e}){this.callManager=e,this.events=new f(Q),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(R.FAILED_PRESENTATION,r),r}):t&&this.events.trigger(R.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(R.START_PRESENTATION,e)}),this.callManager.on("presentation:started",e=>{this.events.trigger(R.STARTED_PRESENTATION,e)}),this.callManager.on("presentation:end",e=>{this.events.trigger(R.END_PRESENTATION,e)}),this.callManager.on("presentation:ended",e=>{this.events.trigger(R.ENDED_PRESENTATION,e)}),this.callManager.on("presentation:failed",e=>{this.events.trigger(R.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:Ce}}){const a=async()=>this.sendPresentation(e,t,s,i),o=()=>!!this.streamPresentationCurrent;return this.cancelableSendPresentationWithRepeatedCalls=W.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=y(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(d=>{throw this.removeStreamPresentationCurrent(),this.events.trigger(R.FAILED_PRESENTATION,d),d});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 Ae{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 u=(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))(u||{});const X=["connecting","connected","disconnected","newRTCSession","registered","unregistered","registrationFailed","newMessage","sipEvent"],J=[...X],_e=3;class Ie{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",x(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(u.DISCONNECTED,()=>{s()})}),t=this.getUa();return t?t.stop():this.events.trigger(u.DISCONNECTED,void 0),e.finally(()=>{this.setUa(void 0),this.stateMachine.reset()})};cancelRequests(){this.cancelConnectWithRepeatedCalls()}connectWithDuplicatedCalls=async(e,{callLimit:t=_e}={})=>{const s=async()=>this.connectInner(e),i=r=>{const c=this.getUa()?.isConnected()===!0&&this.hasEqualConnectionConfiguration(e),g=r!=null&&!le(r);return c||g};return this.stateMachine.startConnect(),this.cancelableConnectWithRepeatedCalls=W.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:d,displayName:S="",register:l=!1,extraHeaders:E=[]})=>{this.stateMachine.startInitUa(),this.setConnectionConfiguration({sipServerUrl:s,displayName:S,register:l,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:S,register:l,sessionTimers:a,registerExpires:o,connectionRecoveryMinInterval:c,connectionRecoveryMaxInterval:g,userAgent:d,remoteAddress:r,extraHeaders:E},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 S=u.CONNECTED,l=[u.DISCONNECTED];return this.events.on(S,c),l.forEach(E=>{this.events.on(E,g)}),()=>{this.events.off(S,c),l.forEach(E=>{this.events.off(E,g)})}})(()=>{i?.(),e(s)},c=>{i?.(),t(c)}),s.start()});cancelConnectWithRepeatedCalls(){this.cancelableConnectWithRepeatedCalls?.cancel()}}var K=(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))(K||{});const Re=G.setup({types:{context:{},events:{}},actions:{logTransition:(n,e)=>{p(`State transition: ${e.from} -> ${e.to} (${e.event})`)},logStateChange:(n,e)=>{p("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 Me{actor;stateChangeListeners=new Set;events;unsubscribeFromEvents;actorSubscription;constructor(e){this.events=e,this.actor=G.createActor(Re),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(K).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)){p(`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 pe{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(u.REGISTERED,t),e.on(u.REGISTRATION_FAILED,s),e.register()})}async unregister(){const e=this.getUaProtected();return new Promise(t=>{e.on(u.UNREGISTERED,t),e.unregister()})}async tryRegister(){try{await this.unregister()}catch(e){p("tryRegister",e)}return this.register()}subscribeToStartEvents(e,t){const s=u.REGISTERED,i=[u.REGISTRATION_FAILED,u.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 Pe{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}),d=this.uaFactory.createUA({...g,remoteAddress:r,extraHeaders:a}),S=()=>{const E=new Error("Telephony is not available");c(E)};d.once(u.DISCONNECTED,S);const l=()=>{d.removeAllListeners(),d.once(u.DISCONNECTED,()=>{o()}),d.stop()};d.once(u.CONNECTED,l),d.start()})}}const me=n=>{const e=[];return n!==void 0&&n!==""&&e.push(`X-Vinteo-Remote: ${n}`),e};class O{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():`${ne()}`}static buildExtraHeaders(e,t){const s=e!==void 0&&e!==""?me(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:d=6,userAgent:S}){O.validateConfiguration({register:a,password:t,user:e,sipServerUrl:r,sipWebSocketServerURL:s});const l=O.resolveAuthorizationUser(a,e),E=ee(r),I=E(l),C=new this.JsSIP.WebSocketInterface(s);return{configuration:{password:t,register:a,uri:I,display_name:x(i),user_agent:S,sdpSemantics:"unified-plan",sockets:[C],session_timers:o,register_expires:c,connection_recovery_min_interval:g,connection_recovery_max_interval:d},helpers:{socket:C,getSipServerUrl:E}}}createUA({remoteAddress:e,extraHeaders:t,...s}){const i=new this.JsSIP.UA(s),r=O.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=X.find(g=>g===o);c&&r.on(c,a)}),{ua:r,helpers:i}}}class Oe{events;ua;socket;uaFactory;registrationManager;stateMachine;connectionFlow;sipOperations;configurationManager;JsSIP;constructor({JsSIP:e}){this.JsSIP=e,this.events=new f(J),this.uaFactory=new O(e),this.registrationManager=new pe({events:this.events,getUaProtected:this.getUaProtected}),this.stateMachine=new Me(this.events),this.configurationManager=new Ae({getUa:this.getUa}),this.sipOperations=new Pe({uaFactory:this.uaFactory,getUaProtected:this.getUaProtected}),this.connectionFlow=new Ie({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 O.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 D=(n=>(n.INCOMING_CALL="incomingCall",n.DECLINED_INCOMING_CALL="declinedIncomingCall",n.TERMINATED_INCOMING_CALL="terminatedIncomingCall",n.FAILED_INCOMING_CALL="failedIncomingCall",n))(D||{}),$=(n=>(n.LOCAL="local",n.REMOTE="remote",n.SYSTEM="system",n))($||{});const j=["incomingCall","declinedIncomingCall","terminatedIncomingCall","failedIncomingCall"],fe=486,De=487;class ve{events;incomingRTCSession;connectionManager;constructor(e){this.connectionManager=e,this.events=new f(j),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=De}={}){return new Promise((t,s)=>{try{const i=this.getIncomingRTCSession(),r=this.remoteCallerData;this.removeIncomingSession(),this.events.trigger(D.DECLINED_INCOMING_CALL,r),i.terminate({status_code:e}),t()}catch(i){s(i)}})}async busyIncomingCall(){return this.declineToIncomingCall({statusCode:fe})}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===$.REMOTE&&this.setIncomingSession(t)};setIncomingSession(e){this.incomingRTCSession=e;const t=this.remoteCallerData;e.on("failed",s=>{this.removeIncomingSession(),s.originator===$.LOCAL?this.events.trigger(D.TERMINATED_INCOMING_CALL,t):this.events.trigger(D.FAILED_INCOMING_CALL,t)}),this.events.trigger(D.INCOMING_CALL,t)}removeIncomingSession(){delete this.incomingRTCSession}}const ye=J.map(n=>`connection:${n}`),Ue=q.map(n=>`call:${n}`),be=z.map(n=>`api:${n}`),we=j.map(n=>`incoming-call:${n}`),Le=Q.map(n=>`presentation:${n}`),Fe=[...ye,...Ue,...be,...we,...Le];class $e{events;connectionManager;callManager;apiManager;incomingCallManager;presentationManager;constructor({JsSIP:e}){this.events=new f(Fe),this.connectionManager=new Oe({JsSIP:e}),this.callManager=new ce,this.apiManager=new Se({connectionManager:this.connectionManager,callManager:this.callManager}),this.incomingCallManager=new ve(this.connectionManager),this.presentationManager=new ue({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()=>{t===!0?await this.apiManager.sendMustStopPresentationP2P():await 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)})})}}exports.ECallCause=V;exports.EEventsMainCAM=m;exports.EUseLicense=Y;exports.Originator=v;exports.SipConnector=$e;exports.disableDebug=Te;exports.enableDebug=ge;exports.hasCanceledStartPresentationError=Ne;exports.logger=p;
|
package/dist/headers.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export declare const HEADER_CONTENT_TYPE_NAME = "content-type";
|
|
2
|
-
export declare const HEADER_CONTENT_ENTER_ROOM = "x-webrtc-enter-room";
|
|
3
|
-
export declare const CONTENT_TYPE_SHARE_STATE = "application/vinteo.webrtc.sharedesktop";
|
|
4
|
-
export declare const CONTENT_TYPE_ENTER_ROOM = "application/vinteo.webrtc.roomname";
|
|
5
|
-
export declare const CONTENT_TYPE_CHANNELS = "application/vinteo.webrtc.channels";
|
|
6
|
-
export declare const CONTENT_TYPE_MEDIA_STATE = "application/vinteo.webrtc.mediastate";
|
|
7
|
-
export declare const CONTENT_TYPE_REFUSAL = "application/vinteo.webrtc.refusal";
|
|
8
|
-
export declare const CONTENT_TYPE_MAIN_CAM = "application/vinteo.webrtc.maincam";
|
|
9
|
-
export declare const CONTENT_TYPE_MIC = "application/vinteo.webrtc.mic";
|
|
10
|
-
export declare const CONTENT_TYPE_USE_LICENSE = "application/vinteo.webrtc.uselic";
|
|
11
|
-
export declare const HEADER_CONTENT_USE_LICENSE = "X-WEBRTC-USE-LICENSE";
|
|
12
|
-
export declare const HEADER_PARTICIPANT_NAME = "X-WEBRTC-PARTICIPANT-NAME";
|
|
13
|
-
export declare const HEADER_INPUT_CHANNELS = "X-WEBRTC-INPUT-CHANNELS";
|
|
14
|
-
export declare const HEADER_OUTPUT_CHANNELS = "X-WEBRTC-OUTPUT-CHANNELS";
|
|
15
|
-
export declare const HEADER_MAIN_CAM = "X-WEBRTC-MAINCAM";
|
|
16
|
-
export declare const HEADER_MIC = "X-WEBRTC-MIC";
|
|
17
|
-
export declare const HEADER_MEDIA_SYNC = "X-WEBRTC-SYNC";
|
|
18
|
-
export declare const HEADER_MAIN_CAM_RESOLUTION = "X-WEBRTC-MAINCAM-RESOLUTION";
|
|
19
|
-
export declare const HEADER_MEDIA_STATE = "X-WEBRTC-MEDIA-STATE";
|
|
20
|
-
export declare const HEADER_MEDIA_TYPE = "X-Vinteo-Media-Type";
|
|
21
|
-
export declare const HEADER_MAIN_CAM_STATE = "X-Vinteo-MainCam-State";
|
|
22
|
-
export declare const HEADER_MIC_STATE = "X-Vinteo-Mic-State";
|
|
23
|
-
export declare const CONTENT_TYPE_PARTICIPANT_STATE = "application/vinteo.webrtc.partstate";
|
|
24
|
-
export declare const HEADER_CONTENT_PARTICIPANT_STATE = "X-WEBRTC-PARTSTATE";
|
|
25
|
-
export declare const CONTENT_TYPE_NOTIFY = "application/vinteo.webrtc.notify";
|
|
26
|
-
export declare const HEADER_NOTIFY = "X-VINTEO-NOTIFY";
|
|
27
|
-
export declare const HEADER_CONTENT_SHARE_STATE = "x-webrtc-share-state";
|
|
28
|
-
export declare const HEADER_START_PRESENTATION = "x-webrtc-share-state: LETMESTARTPRESENTATION";
|
|
29
|
-
export declare const HEADER_STOP_PRESENTATION = "x-webrtc-share-state: STOPPRESENTATION";
|
|
30
|
-
export declare const AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT";
|
|
31
|
-
export declare const NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND";
|
|
32
|
-
export declare const MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT";
|
|
33
|
-
export declare const HEADER_MUST_STOP_PRESENTATION_P2P = "x-webrtc-share-state: YOUMUSTSTOPSENDCONTENT";
|
|
34
|
-
export declare const HEADER_START_PRESENTATION_P2P = "x-webrtc-share-state: YOUCANRECEIVECONTENT";
|
|
35
|
-
export declare const HEADER_STOP_PRESENTATION_P2P = "x-webrtc-share-state: CONTENTEND";
|
|
36
|
-
export declare const HEADER_CONTENT_ENABLE_MEDIA_DEVICE = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE";
|
|
37
|
-
export declare const HEADER_ENABLE_MAIN_CAM = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE: LETMESTARTMAINCAM";
|
|
File without changes
|