sip-connector 6.22.2 → 6.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SipConnector-Q7QLgdlo.cjs +1 -0
- package/dist/{SipConnector-Hg44qtgr.js → SipConnector-m1cOb6M0.js} +272 -218
- package/dist/SipConnector.d.ts +28 -7
- package/dist/__fixtures__/UA.mock.d.ts +6 -0
- package/dist/doMock.cjs +1 -1
- package/dist/doMock.js +344 -289
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/package.json +7 -9
- package/dist/SipConnector-4TW1xlov.cjs +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("./SipConnector-4TW1xlov.cjs"),H=require("ts-debounce"),Y=require("@krivega/cancelable-promise"),z=require("debug");require("events-constructor");const x="purgatory",P=e=>e===x,B=e=>()=>(s.logger("getRemoteStreams"),e.getRemoteStreams()),J=({kind:e,readyState:n})=>e==="video"&&n==="live",V=e=>({track:n})=>{J(n)&&e()},D=({getRemoteStreams:e,setRemoteStreams:n})=>H.debounce(()=>{const t=e();s.logger("remoteStreams",t),t&&n(t)},200),Q=e=>async t=>{const{mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,setRemoteStreams:u,onBeforeProgressCall:d,onSuccessProgressCall:E,onEnterPurgatory:f,onEnterConference:m,onFailProgressCall:y,onFinishProgressCall:h,onEndedCall:M}=t,C=D({setRemoteStreams:u,getRemoteStreams:B(e)}),T=V(C);s.logger("answerIncomingCall",t);const O=async()=>e.answerToIncomingCall({mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,ontrack:T}),A=()=>{const{remoteCallerData:S}=e;return S.incomingNumber};let _=!1,i;const l=(s.logger("subscribeEnterConference: onEnterConference",m),f??m?e.onSession("enterRoom",S=>{s.logger("enterRoom",{_room:S,isSuccessProgressCall:_}),i=S,P(i)?f&&f():m&&m({isSuccessProgressCall:_})}):()=>{}),R=S=>(s.logger("onSuccess"),_=!0,C(),E&&E({isPurgatory:P(i)}),e.onceRaceSession(["ended","failed"],()=>{l(),M&&M()}),S),b=S=>{throw s.logger("onFail"),y&&y(),l(),S},N=()=>{s.logger("onFinish"),h&&h()};if(s.logger("onBeforeProgressCall"),d){const S=A();d(S)}return O().then(R).catch(b).finally(N)},Z=e=>async t=>{const{conference:r,mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,setRemoteStreams:d,onBeforeProgressCall:E,onSuccessProgressCall:f,onEnterPurgatory:m,onEnterConference:y,onFailProgressCall:h,onFinishProgressCall:M,onEndedCall:C}=t,T=D({setRemoteStreams:d,getRemoteStreams:B(e)}),O=V(T);s.logger("callToServer",t);const A=async()=>(s.logger("startCall"),e.call({mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,number:r,ontrack:O}));let _=!1,i;const l=(s.logger("subscribeEnterConference: onEnterConference",y),m??y?e.onSession("enterRoom",S=>{s.logger("enterRoom",{_room:S,isSuccessProgressCall:_}),i=S,P(i)?m&&m():y&&y({isSuccessProgressCall:_})}):()=>{}),R=S=>(s.logger("onSuccess"),_=!0,T(),f&&f({isPurgatory:P(i)}),e.onceRaceSession(["ended","failed"],()=>{l(),C&&C()}),S),b=S=>{throw s.logger("onFail"),h&&h(),l(),S},N=()=>{s.logger("onFinish"),M&&M()};return s.logger("onBeforeProgressCall"),E&&E(r),A().then(R).catch(b).finally(N)},p=e=>{if(!Y.isCanceledError(e))throw e;return!1},ee=e=>async t=>{const{userAgent:r,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,name:d,password:E,isRegisteredUser:f,sdpSemantics:m,isDisconnectOnFail:y}=t;return s.logger("connectToServer",t),e.connect({userAgent:r,sdpSemantics:m,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,password:E,user:d,register:f}).then(()=>(s.logger("connectToServer then"),!0)).catch(async h=>(s.logger("connectToServer catch: error",h),y===!0?e.disconnect().then(()=>p(h)).catch(()=>p(h)):p(h)))},ne=e=>async()=>(s.logger("disconnectFromServer"),e.disconnect().then(()=>(s.logger("disconnectFromServer: then"),!1)).catch(n=>(s.logger("disconnectFromServer: catch",n),!1))),k=e=>{const{url:n,cause:t}=e;let r=n;return(t===s.BAD_MEDIA_DESCRIPTION||t===s.NOT_FOUND)&&(r=`${e.message.to.uri.user}@${e.message.to.uri.host}`),r};var $=(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))($||{});const te=(e=new Error)=>{var o;const{cause:n,socket:t}=e;let r="CONNECT_SERVER_FAILED";switch(n){case"Forbidden":{r="WRONG_USER_OR_PASSWORD";break}case s.BAD_MEDIA_DESCRIPTION:{r="BAD_MEDIA_ERROR";break}case s.NOT_FOUND:{r="NOT_FOUND_ERROR";break}default:t&&((o=t==null?void 0:t._ws)==null?void 0:o.readyState)===3?r="WS_CONNECTION_FAILED":k(e)&&(r="CONNECT_SERVER_FAILED_BY_LINK")}return r},re=(e=new Error)=>{const{code:n,cause:t,message:r}=e,o=k(e),c={};return r&&(c.message=r),o&&(c.link=o),n&&(c.code=n),t&&(c.cause=t),c},se=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:k,getTypeFromError:te,getValuesFromError:re},Symbol.toStringTag,{value:"Module"})),oe=({sessionId:e,remoteAddress:n,isMutedAudio:t,isMutedVideo:r,isRegistered:o,isPresentationCall:c})=>{const a=[],u=t?"0":"1",d=r?"0":"1";return a.push(`X-Vinteo-Mic-State: ${u}`,`X-Vinteo-MainCam-State: ${d}`),o||a.push("X-Vinteo-Purgatory-Call: yes"),e&&a.push(`X-Vinteo-Session: ${e}`),c&&a.push("X-Vinteo-Presentation-Call: yes"),n&&a.push(`X-Vinteo-Remote: ${n}`),a},ce=({appName:e,appVersion:n,browserName:t,browserVersion:r})=>{const o=`${e} ${n}`;return`ChromeNew - ${t?`${t} ${r}, ${o}`:o}`},ae=({isUnifiedSdpSemantic:e,appVersion:n,browserName:t,browserVersion:r,appName:o})=>e?ce({appVersion:n,browserName:t,browserVersion:r,appName:o}):"Chrome",ie=e=>async()=>{if(e.isCallActive)return s.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},ue=e=>t=>(s.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",t)),le=e=>t=>(s.logger("onUseLicense"),e.onSession("useLicense",t)),ge=e=>async({isEnabledCam:t,isEnabledMic:r})=>{if(e.isCallActive)return s.logger("sendMediaState"),e.sendMediaState({cam:t,mic:r})},Se=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(t=>{s.logger("sendRefusalToTurnOnCam: error",t)})},de=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(t=>{s.logger("sendRefusalToTurnOnMic: error",t)})},me=1e6,fe=({maxBitrate:e=me,sipConnector:n})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("startPresentation"),n.startPresentation(r,{isP2P:o,maxBitrate:e})),Ee=({sipConnector:e})=>async({isP2P:t=!1}={})=>(s.logger("stopShareSipConnector"),e.stopPresentation({isP2P:t}).catch(s.logger)),Ce=1e6,Re=({sipConnector:e,maxBitrate:n=Ce})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("updatePresentation"),e.updatePresentation(r,{isP2P:o,maxBitrate:n})),he="ERROR_NOT_RUNNING",Me=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=he,n.name="Not running",n},ye=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(Me(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),Te=e=>n=>[...n].map(r=>async()=>e(r)),_e=async({accumulatedKeys:e,sendKey:n,canRunTask:t})=>{const o=Te(n)(e);return ye(o,t)},be=e=>t=>(s.logger("onStartMainCam"),e.onSession("admin-start-main-cam",t)),ve=e=>t=>(s.logger("onStartMic"),e.onSession("admin-start-mic",t)),Ne=e=>t=>(s.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",t)),Oe=e=>t=>(s.logger("onStopMic"),e.onSession("admin-stop-mic",t)),Ae=({sipConnector:e})=>{const n=(M,C)=>({isSyncForced:T=!1})=>{if(T){M();return}C()},t=be(e),r=Ne(e),o=ve(e),c=Oe(e);let a=()=>{},u=()=>{},d=()=>{},E=()=>{};const f=({onStartMainCamForced:M,onStartMainCamNotForced:C,onStopMainCamForced:T,onStopMainCamNotForced:O,onStartMicForced:A,onStartMicNotForced:_,onStopMicForced:i,onStopMicNotForced:g})=>{const l=n(M,C);a=t(l);const R=n(T,O);u=r(R);const b=n(A,_);d=o(b);const N=n(i,g);E=c(N)},m=()=>{a(),u(),d(),E()};return{start:M=>{f(M)},stop:()=>{m()}}},Pe=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:x,createSyncMediaState:Ae,error:se,getExtraHeaders:oe,getUserAgent:ae,hasPurgatory:P,resolveAnswerIncomingCall:Q,resolveAskPermissionToEnableCam:ie,resolveCallToServer:Z,resolveConnectToServer:ee,resolveDisconnectFromServer:ne,resolveGetRemoteStreams:B,resolveOnMustStopPresentation:ue,resolveOnUseLicense:le,resolveSendMediaState:ge,resolveSendRefusalToTurnOnCam:Se,resolveSendRefusalToTurnOnMic:de,resolveStartPresentation:fe,resolveStopShareSipConnector:Ee,resolveUpdatePresentation:Re,resolveUpdateRemoteStreams:D,sendDTMFAccumulated:_e},Symbol.toStringTag,{value:"Module"})),pe=e=>[...e.keys()].map(n=>e.get(n)),Ie=(e,n)=>pe(e).find(t=>t.type===n),j=async e=>e.getStats().then(n=>{const t=Ie(n,"codec");return t==null?void 0:t.mimeType}),we=e=>e.find(n=>{var t;return((t=n==null?void 0:n.track)==null?void 0:t.kind)==="video"}),G=(e,n)=>e!==void 0&&n!==void 0&&e.toLowerCase().includes(n.toLowerCase()),Be="ERROR_NOT_RUNNING",De=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=Be,n.name="Not running",n},ke=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(De(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),Fe=new Error("Stack is empty"),I=e=>e[e.length-1],Ue=new Error("Promise is not actual"),Le=new Error("stackPromises only works with functions that returns a Promise"),xe=({noRejectIsNotActual:e=!1,noRunIsNotActual:n=!1}={})=>{const t=[],r=[],o=({task:i,index:g})=>{r.push({task:i,index:g})},c=(i,{task:g,index:l})=>{const R=r.find(({task:b,index:N})=>g===b&&l===N);if(!R)throw new Error("Task not found");if(R.promise)throw new Error("Task is already running");R.promise=i},a=({task:i,index:g})=>{const l=r.find(({task:R,index:b})=>i===R&&g===b);if(l)return l.promise},u=({task:i})=>{const g=I(r);return(g==null?void 0:g.task)===i},d=({task:i,index:g})=>(o({task:i,index:g}),async()=>{let l=a({task:i,index:g});const R=u({task:i});return!l&&n&&!R?Promise.resolve():(l||(l=i({isActual:R}),c(l,{task:i,index:g})),l)}),E=({resolve:i,reject:g})=>({results:l,isSuccessful:R})=>{const b=l.length,N=t.length;if(b===N){const S=I(l);if(R){i(S);return}g(S);return}if(e){const S=I(l);i(S);return}g(Ue)};let f=!1;const m=()=>{f=!0},y=()=>{f=!1},h=()=>f,M=async()=>(m(),ke(t,h)),C=async()=>{if(t.length===0)throw Fe;return new Promise((i,g)=>{const l=E({resolve:i,reject:g});M().then(l).catch(l)})},T=i=>{if(typeof i!="function")throw Le;const g=t.length;return t.push(d({task:i,index:g})),C},O=async i=>(T(i),C()),A=()=>{t.length=0,r.length=0},_=()=>{y(),A()};return C.add=T,C.run=O,C.stop=_,C},Ve=1e6,v=e=>e*Ve,X=v(.06),$e=v(4),je=e=>e<=64?X:e<=128?v(.12):e<=256?v(.25):e<=384?v(.32):e<=426?v(.38):e<=640?v(.5):e<=848?v(.7):e<=1280?v(1):e<=1920?v(2):$e,Ge="av1",Xe=e=>G(e,Ge),Ke=.6,K=(e,n)=>Xe(n)?e*Ke:e,We=e=>K(X,e),W=(e,n)=>{const t=je(e);return K(t,n)},q=xe(),qe=async()=>q().catch(e=>{s.logger("videoSendingBalancer: error",e)}),He=async e=>(q.add(e),qe()),F=async({sender:e,scaleResolutionDownBy:n,maxBitrate:t,onSetParameters:r})=>He(async()=>s.setEncodingsToSender(e,{scaleResolutionDownBy:n,maxBitrate:t},r)),Ye=async({sender:e,codec:n},t)=>{const o=We(n);return F({sender:e,maxBitrate:o,onSetParameters:t,scaleResolutionDownBy:200})},w=async({sender:e,track:n,codec:t},r)=>{const a=n.getSettings().width,u=W(a,t);return F({sender:e,maxBitrate:u,onSetParameters:r,scaleResolutionDownBy:1})},ze=async({sender:e,track:n,resolution:t,codec:r},o)=>{const c=n.getSettings(),a=c.width,u=c.height,[d,E]=t.split("x"),f=a/Number(d),m=u/Number(E),h=Math.max(f,m,1),M=W(Number(d),r);return F({sender:e,maxBitrate:M,onSetParameters:o,scaleResolutionDownBy:h})},Je=async({mainCam:e,resolutionMainCam:n,sender:t,track:r,codec:o},c)=>{switch(e){case s.EEventsMainCAM.PAUSE_MAIN_CAM:return Ye({sender:t,codec:o},c);case s.EEventsMainCAM.RESUME_MAIN_CAM:return w({sender:t,track:r,codec:o},c);case s.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return n!==void 0?ze({sender:t,track:r,codec:o,resolution:n},c):w({sender:t,track:r,codec:o},c);default:return w({sender:t,track:r,codec:o},c)}},U={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},L=async({mainCam:e,resolutionMainCam:n,connection:t,onSetParameters:r,ignoreForCodec:o})=>{const c=t.getSenders(),a=we(c);if(!(a!=null&&a.track))return U;const u=await j(a);return G(u,o)?U:Je({mainCam:e,resolutionMainCam:n,sender:a,codec:u,track:a.track},r)},Qe=(e,{ignoreForCodec:n,onSetParameters:t}={})=>{const r=async()=>{const{connection:d}=e;if(!d)throw new Error("connection is not exist");return L({connection:d,onSetParameters:t,ignoreForCodec:n})};let o=r;const c=async d=>(o=async()=>{const{mainCam:E,resolutionMainCam:f}=d,{connection:m}=e;if(!m)throw new Error("connection is not exist");return L({mainCam:E,resolutionMainCam:f,connection:m,onSetParameters:t,ignoreForCodec:n})},o());return{subscribe:()=>{e.onSession("main-cam-control",c)},unsubscribe:()=>{e.offSession("main-cam-control",c)},balanceByTrack:r,resetMainCamControl(){o=r},async reBalance(){return o()}}};exports.EEventsMainCAM=s.EEventsMainCAM;exports.EEventsMic=s.EEventsMic;exports.EEventsSyncMediaState=s.EEventsSyncMediaState;exports.EUseLicense=s.EUseLicense;exports.causes=s.causes;exports.constants=s.constants;exports.default=s.SipConnector;exports.disableDebug=s.disableDebug;exports.enableDebug=s.enableDebug;exports.eventNames=s.eventNames;exports.hasCanceledCallError=s.hasCanceledCallError;exports.debug=z;exports.getCodecFromSender=j;exports.resolveVideoSendingBalancer=Qe;exports.tools=Pe;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("./SipConnector-Q7QLgdlo.cjs"),H=require("ts-debounce"),Y=require("@krivega/cancelable-promise"),z=require("debug");require("events-constructor");const x="purgatory",P=e=>e===x,B=e=>()=>(s.logger("getRemoteStreams"),e.getRemoteStreams()),J=({kind:e,readyState:n})=>e==="video"&&n==="live",V=e=>({track:n})=>{J(n)&&e()},D=({getRemoteStreams:e,setRemoteStreams:n})=>H.debounce(()=>{const t=e();s.logger("remoteStreams",t),t&&n(t)},200),Q=e=>async t=>{const{mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,setRemoteStreams:u,onBeforeProgressCall:d,onSuccessProgressCall:E,onEnterPurgatory:f,onEnterConference:m,onFailProgressCall:y,onFinishProgressCall:h,onEndedCall:M}=t,C=D({setRemoteStreams:u,getRemoteStreams:B(e)}),T=V(C);s.logger("answerIncomingCall",t);const O=async()=>e.answerToIncomingCall({mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,ontrack:T}),A=()=>{const{remoteCallerData:S}=e;return S.incomingNumber};let _=!1,i;const l=(s.logger("subscribeEnterConference: onEnterConference",m),f??m?e.onSession("enterRoom",S=>{s.logger("enterRoom",{_room:S,isSuccessProgressCall:_}),i=S,P(i)?f&&f():m&&m({isSuccessProgressCall:_})}):()=>{}),R=S=>(s.logger("onSuccess"),_=!0,C(),E&&E({isPurgatory:P(i)}),e.onceRaceSession(["ended","failed"],()=>{l(),M&&M()}),S),b=S=>{throw s.logger("onFail"),y&&y(),l(),S},N=()=>{s.logger("onFinish"),h&&h()};if(s.logger("onBeforeProgressCall"),d){const S=A();d(S)}return O().then(R).catch(b).finally(N)},Z=e=>async t=>{const{conference:r,mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,setRemoteStreams:d,onBeforeProgressCall:E,onSuccessProgressCall:f,onEnterPurgatory:m,onEnterConference:y,onFailProgressCall:h,onFinishProgressCall:M,onEndedCall:C}=t,T=D({setRemoteStreams:d,getRemoteStreams:B(e)}),O=V(T);s.logger("callToServer",t);const A=async()=>(s.logger("startCall"),e.call({mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,number:r,ontrack:O}));let _=!1,i;const l=(s.logger("subscribeEnterConference: onEnterConference",y),m??y?e.onSession("enterRoom",S=>{s.logger("enterRoom",{_room:S,isSuccessProgressCall:_}),i=S,P(i)?m&&m():y&&y({isSuccessProgressCall:_})}):()=>{}),R=S=>(s.logger("onSuccess"),_=!0,T(),f&&f({isPurgatory:P(i)}),e.onceRaceSession(["ended","failed"],()=>{l(),C&&C()}),S),b=S=>{throw s.logger("onFail"),h&&h(),l(),S},N=()=>{s.logger("onFinish"),M&&M()};return s.logger("onBeforeProgressCall"),E&&E(r),A().then(R).catch(b).finally(N)},p=e=>{if(!Y.isCanceledError(e))throw e;return!1},ee=e=>async t=>{const{userAgent:r,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,name:d,password:E,isRegisteredUser:f,sdpSemantics:m,isDisconnectOnFail:y}=t;return s.logger("connectToServer",t),e.connect({userAgent:r,sdpSemantics:m,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,password:E,user:d,register:f}).then(()=>(s.logger("connectToServer then"),!0)).catch(async h=>(s.logger("connectToServer catch: error",h),y===!0?e.disconnect().then(()=>p(h)).catch(()=>p(h)):p(h)))},ne=e=>async()=>(s.logger("disconnectFromServer"),e.disconnect().then(()=>(s.logger("disconnectFromServer: then"),!1)).catch(n=>(s.logger("disconnectFromServer: catch",n),!1))),k=e=>{const{url:n,cause:t}=e;let r=n;return(t===s.BAD_MEDIA_DESCRIPTION||t===s.NOT_FOUND)&&(r=`${e.message.to.uri.user}@${e.message.to.uri.host}`),r};var $=(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))($||{});const te=(e=new Error)=>{var o;const{cause:n,socket:t}=e;let r="CONNECT_SERVER_FAILED";switch(n){case"Forbidden":{r="WRONG_USER_OR_PASSWORD";break}case s.BAD_MEDIA_DESCRIPTION:{r="BAD_MEDIA_ERROR";break}case s.NOT_FOUND:{r="NOT_FOUND_ERROR";break}default:t&&((o=t==null?void 0:t._ws)==null?void 0:o.readyState)===3?r="WS_CONNECTION_FAILED":k(e)&&(r="CONNECT_SERVER_FAILED_BY_LINK")}return r},re=(e=new Error)=>{const{code:n,cause:t,message:r}=e,o=k(e),c={};return r&&(c.message=r),o&&(c.link=o),n&&(c.code=n),t&&(c.cause=t),c},se=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:k,getTypeFromError:te,getValuesFromError:re},Symbol.toStringTag,{value:"Module"})),oe=({sessionId:e,remoteAddress:n,isMutedAudio:t,isMutedVideo:r,isRegistered:o,isPresentationCall:c})=>{const a=[],u=t?"0":"1",d=r?"0":"1";return a.push(`X-Vinteo-Mic-State: ${u}`,`X-Vinteo-MainCam-State: ${d}`),o||a.push("X-Vinteo-Purgatory-Call: yes"),e&&a.push(`X-Vinteo-Session: ${e}`),c&&a.push("X-Vinteo-Presentation-Call: yes"),n&&a.push(`X-Vinteo-Remote: ${n}`),a},ce=({appName:e,appVersion:n,browserName:t,browserVersion:r})=>{const o=`${e} ${n}`;return`ChromeNew - ${t?`${t} ${r}, ${o}`:o}`},ae=({isUnifiedSdpSemantic:e,appVersion:n,browserName:t,browserVersion:r,appName:o})=>e?ce({appVersion:n,browserName:t,browserVersion:r,appName:o}):"Chrome",ie=e=>async()=>{if(e.isCallActive)return s.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},ue=e=>t=>(s.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",t)),le=e=>t=>(s.logger("onUseLicense"),e.onSession("useLicense",t)),ge=e=>async({isEnabledCam:t,isEnabledMic:r})=>{if(e.isCallActive)return s.logger("sendMediaState"),e.sendMediaState({cam:t,mic:r})},Se=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(t=>{s.logger("sendRefusalToTurnOnCam: error",t)})},de=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(t=>{s.logger("sendRefusalToTurnOnMic: error",t)})},me=1e6,fe=({maxBitrate:e=me,sipConnector:n})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("startPresentation"),n.startPresentation(r,{isP2P:o,maxBitrate:e})),Ee=({sipConnector:e})=>async({isP2P:t=!1}={})=>(s.logger("stopShareSipConnector"),e.stopPresentation({isP2P:t}).catch(s.logger)),Ce=1e6,Re=({sipConnector:e,maxBitrate:n=Ce})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("updatePresentation"),e.updatePresentation(r,{isP2P:o,maxBitrate:n})),he="ERROR_NOT_RUNNING",Me=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=he,n.name="Not running",n},ye=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(Me(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),Te=e=>n=>[...n].map(r=>async()=>e(r)),_e=async({accumulatedKeys:e,sendKey:n,canRunTask:t})=>{const o=Te(n)(e);return ye(o,t)},be=e=>t=>(s.logger("onStartMainCam"),e.onSession("admin-start-main-cam",t)),ve=e=>t=>(s.logger("onStartMic"),e.onSession("admin-start-mic",t)),Ne=e=>t=>(s.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",t)),Oe=e=>t=>(s.logger("onStopMic"),e.onSession("admin-stop-mic",t)),Ae=({sipConnector:e})=>{const n=(M,C)=>({isSyncForced:T=!1})=>{if(T){M();return}C()},t=be(e),r=Ne(e),o=ve(e),c=Oe(e);let a=()=>{},u=()=>{},d=()=>{},E=()=>{};const f=({onStartMainCamForced:M,onStartMainCamNotForced:C,onStopMainCamForced:T,onStopMainCamNotForced:O,onStartMicForced:A,onStartMicNotForced:_,onStopMicForced:i,onStopMicNotForced:g})=>{const l=n(M,C);a=t(l);const R=n(T,O);u=r(R);const b=n(A,_);d=o(b);const N=n(i,g);E=c(N)},m=()=>{a(),u(),d(),E()};return{start:M=>{f(M)},stop:()=>{m()}}},Pe=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:x,createSyncMediaState:Ae,error:se,getExtraHeaders:oe,getUserAgent:ae,hasPurgatory:P,resolveAnswerIncomingCall:Q,resolveAskPermissionToEnableCam:ie,resolveCallToServer:Z,resolveConnectToServer:ee,resolveDisconnectFromServer:ne,resolveGetRemoteStreams:B,resolveOnMustStopPresentation:ue,resolveOnUseLicense:le,resolveSendMediaState:ge,resolveSendRefusalToTurnOnCam:Se,resolveSendRefusalToTurnOnMic:de,resolveStartPresentation:fe,resolveStopShareSipConnector:Ee,resolveUpdatePresentation:Re,resolveUpdateRemoteStreams:D,sendDTMFAccumulated:_e},Symbol.toStringTag,{value:"Module"})),pe=e=>[...e.keys()].map(n=>e.get(n)),Ie=(e,n)=>pe(e).find(t=>t.type===n),j=async e=>e.getStats().then(n=>{const t=Ie(n,"codec");return t==null?void 0:t.mimeType}),we=e=>e.find(n=>{var t;return((t=n==null?void 0:n.track)==null?void 0:t.kind)==="video"}),G=(e,n)=>e!==void 0&&n!==void 0&&e.toLowerCase().includes(n.toLowerCase()),Be="ERROR_NOT_RUNNING",De=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=Be,n.name="Not running",n},ke=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(De(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),Fe=new Error("Stack is empty"),I=e=>e[e.length-1],Ue=new Error("Promise is not actual"),Le=new Error("stackPromises only works with functions that returns a Promise"),xe=({noRejectIsNotActual:e=!1,noRunIsNotActual:n=!1}={})=>{const t=[],r=[],o=({task:i,index:g})=>{r.push({task:i,index:g})},c=(i,{task:g,index:l})=>{const R=r.find(({task:b,index:N})=>g===b&&l===N);if(!R)throw new Error("Task not found");if(R.promise)throw new Error("Task is already running");R.promise=i},a=({task:i,index:g})=>{const l=r.find(({task:R,index:b})=>i===R&&g===b);if(l)return l.promise},u=({task:i})=>{const g=I(r);return(g==null?void 0:g.task)===i},d=({task:i,index:g})=>(o({task:i,index:g}),async()=>{let l=a({task:i,index:g});const R=u({task:i});return!l&&n&&!R?Promise.resolve():(l||(l=i({isActual:R}),c(l,{task:i,index:g})),l)}),E=({resolve:i,reject:g})=>({results:l,isSuccessful:R})=>{const b=l.length,N=t.length;if(b===N){const S=I(l);if(R){i(S);return}g(S);return}if(e){const S=I(l);i(S);return}g(Ue)};let f=!1;const m=()=>{f=!0},y=()=>{f=!1},h=()=>f,M=async()=>(m(),ke(t,h)),C=async()=>{if(t.length===0)throw Fe;return new Promise((i,g)=>{const l=E({resolve:i,reject:g});M().then(l).catch(l)})},T=i=>{if(typeof i!="function")throw Le;const g=t.length;return t.push(d({task:i,index:g})),C},O=async i=>(T(i),C()),A=()=>{t.length=0,r.length=0},_=()=>{y(),A()};return C.add=T,C.run=O,C.stop=_,C},Ve=1e6,v=e=>e*Ve,X=v(.06),$e=v(4),je=e=>e<=64?X:e<=128?v(.12):e<=256?v(.25):e<=384?v(.32):e<=426?v(.38):e<=640?v(.5):e<=848?v(.7):e<=1280?v(1):e<=1920?v(2):$e,Ge="av1",Xe=e=>G(e,Ge),Ke=.6,K=(e,n)=>Xe(n)?e*Ke:e,We=e=>K(X,e),W=(e,n)=>{const t=je(e);return K(t,n)},q=xe(),qe=async()=>q().catch(e=>{s.logger("videoSendingBalancer: error",e)}),He=async e=>(q.add(e),qe()),F=async({sender:e,scaleResolutionDownBy:n,maxBitrate:t,onSetParameters:r})=>He(async()=>s.setEncodingsToSender(e,{scaleResolutionDownBy:n,maxBitrate:t},r)),Ye=async({sender:e,codec:n},t)=>{const o=We(n);return F({sender:e,maxBitrate:o,onSetParameters:t,scaleResolutionDownBy:200})},w=async({sender:e,track:n,codec:t},r)=>{const a=n.getSettings().width,u=W(a,t);return F({sender:e,maxBitrate:u,onSetParameters:r,scaleResolutionDownBy:1})},ze=async({sender:e,track:n,resolution:t,codec:r},o)=>{const c=n.getSettings(),a=c.width,u=c.height,[d,E]=t.split("x"),f=a/Number(d),m=u/Number(E),h=Math.max(f,m,1),M=W(Number(d),r);return F({sender:e,maxBitrate:M,onSetParameters:o,scaleResolutionDownBy:h})},Je=async({mainCam:e,resolutionMainCam:n,sender:t,track:r,codec:o},c)=>{switch(e){case s.EEventsMainCAM.PAUSE_MAIN_CAM:return Ye({sender:t,codec:o},c);case s.EEventsMainCAM.RESUME_MAIN_CAM:return w({sender:t,track:r,codec:o},c);case s.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return n!==void 0?ze({sender:t,track:r,codec:o,resolution:n},c):w({sender:t,track:r,codec:o},c);default:return w({sender:t,track:r,codec:o},c)}},U={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},L=async({mainCam:e,resolutionMainCam:n,connection:t,onSetParameters:r,ignoreForCodec:o})=>{const c=t.getSenders(),a=we(c);if(!(a!=null&&a.track))return U;const u=await j(a);return G(u,o)?U:Je({mainCam:e,resolutionMainCam:n,sender:a,codec:u,track:a.track},r)},Qe=(e,{ignoreForCodec:n,onSetParameters:t}={})=>{const r=async()=>{const{connection:d}=e;if(!d)throw new Error("connection is not exist");return L({connection:d,onSetParameters:t,ignoreForCodec:n})};let o=r;const c=async d=>(o=async()=>{const{mainCam:E,resolutionMainCam:f}=d,{connection:m}=e;if(!m)throw new Error("connection is not exist");return L({mainCam:E,resolutionMainCam:f,connection:m,onSetParameters:t,ignoreForCodec:n})},o());return{subscribe:()=>{e.onSession("main-cam-control",c)},unsubscribe:()=>{e.offSession("main-cam-control",c)},balanceByTrack:r,resetMainCamControl(){o=r},async reBalance(){return o()}}};exports.EEventsMainCAM=s.EEventsMainCAM;exports.EEventsMic=s.EEventsMic;exports.EEventsSyncMediaState=s.EEventsSyncMediaState;exports.EUseLicense=s.EUseLicense;exports.causes=s.causes;exports.constants=s.constants;exports.default=s.SipConnector;exports.disableDebug=s.disableDebug;exports.enableDebug=s.enableDebug;exports.eventNames=s.eventNames;exports.hasCanceledCallError=s.hasCanceledCallError;exports.debug=z;exports.getCodecFromSender=j;exports.resolveVideoSendingBalancer=Qe;exports.tools=Pe;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as c, B as V, N as $, E as P, s as q, S as nn } from "./SipConnector-
|
|
2
|
-
import { f as ln, g as Sn, i as dn, c as mn, a as fn, d as Cn, b as En, e as gn, h as Rn } from "./SipConnector-
|
|
1
|
+
import { l as c, B as V, N as $, E as P, s as q, S as nn } from "./SipConnector-m1cOb6M0.js";
|
|
2
|
+
import { f as ln, g as Sn, i as dn, c as mn, a as fn, d as Cn, b as En, e as gn, h as Rn } from "./SipConnector-m1cOb6M0.js";
|
|
3
3
|
import { debounce as J } from "ts-debounce";
|
|
4
4
|
import { isCanceledError as Q } from "@krivega/cancelable-promise";
|
|
5
5
|
import { default as yn } from "debug";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sip-connector",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.23.0",
|
|
4
4
|
"description": "Module for connect to Vinteo server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webrtc",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
],
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "vite build",
|
|
50
|
-
"commitlint": "commitlint --edit",
|
|
51
50
|
"lint": "yarn lint:js && yarn lint:ts",
|
|
52
51
|
"lint:js": "eslint src --ext ts,tsx --ignore-path .gitignore --report-unused-disable-directives --max-warnings 0",
|
|
53
52
|
"lint:ts": "tsc",
|
|
@@ -79,8 +78,8 @@
|
|
|
79
78
|
"@nabla/vite-plugin-eslint": "^2.0.2",
|
|
80
79
|
"@types/debug": "^4.1.12",
|
|
81
80
|
"@types/jest": "^29.5.12",
|
|
82
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
83
|
-
"@typescript-eslint/parser": "^6.
|
|
81
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
82
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
84
83
|
"cross-env": "^7.0.3",
|
|
85
84
|
"eslint": "^8.56.0",
|
|
86
85
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
@@ -91,14 +90,14 @@
|
|
|
91
90
|
"eslint-plugin-import": "^2.29.1",
|
|
92
91
|
"eslint-plugin-jest": "^27.6.3",
|
|
93
92
|
"eslint-plugin-prettier": "^5.1.3",
|
|
94
|
-
"eslint-plugin-unicorn": "^
|
|
93
|
+
"eslint-plugin-unicorn": "^51.0.1",
|
|
95
94
|
"husky": "^9.0.10",
|
|
96
95
|
"jest": "^29.7.0",
|
|
97
96
|
"jest-environment-jsdom": "^29.7.0",
|
|
98
97
|
"jest-extended": "^4.0.2",
|
|
99
98
|
"jest-junit": "^16.0.0",
|
|
100
|
-
"lint-staged": "^15.2.
|
|
101
|
-
"prettier": "^3.2.
|
|
99
|
+
"lint-staged": "^15.2.2",
|
|
100
|
+
"prettier": "^3.2.5",
|
|
102
101
|
"standard-version": "^9.5.0",
|
|
103
102
|
"ts-jest": "^29.1.2",
|
|
104
103
|
"ts-node": "^10.9.2",
|
|
@@ -113,8 +112,7 @@
|
|
|
113
112
|
"@krivega/jssip": "^3.22.0",
|
|
114
113
|
"debug": "^4.3.4",
|
|
115
114
|
"events-constructor": "^1.2.2",
|
|
116
|
-
"ts-debounce": "^4.0.0"
|
|
117
|
-
"webrtc-mock": "^1.0.2"
|
|
115
|
+
"ts-debounce": "^4.0.0"
|
|
118
116
|
},
|
|
119
117
|
"main:src": "src/index.ts"
|
|
120
118
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var Rt=Object.defineProperty;var It=(r,e,t)=>e in r?Rt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e,t)=>(It(r,typeof e!="symbol"?e+"":e,t),t);const T=require("@krivega/cancelable-promise"),pe=require("events-constructor"),B=require("debug"),mt="Connection Error",He="Request Timeout",ft="SIP Failure Code",Ot="Internal Error",Dt="Busy",V="Rejected",Mt="Redirected",Pt="Unavailable",qe="Not Found",pt="Address Incomplete",vt="Incompatible SDP",bt="Missing SDP",wt="Authentication Error",ke="Terminated",yt="WebRTC Error",Fe="Canceled",Ut="No Answer",Lt="Expires",Ht="No ACK",qt="Dialog Error",kt="User Denied Media Access",We="Bad Media Description",Ft="RTP Timeout",Wt=Object.freeze(Object.defineProperty({__proto__:null,ADDRESS_INCOMPLETE:pt,AUTHENTICATION_ERROR:wt,BAD_MEDIA_DESCRIPTION:We,BUSY:Dt,BYE:ke,CANCELED:Fe,CONNECTION_ERROR:mt,DIALOG_ERROR:qt,EXPIRES:Lt,INCOMPATIBLE_SDP:vt,INTERNAL_ERROR:Ot,MISSING_SDP:bt,NOT_FOUND:qe,NO_ACK:Ht,NO_ANSWER:Ut,REDIRECTED:Mt,REJECTED:V,REQUEST_TIMEOUT:He,RTP_TIMEOUT:Ft,SIP_FAILURE_CODE:ft,UNAVAILABLE:Pt,USER_DENIED_MEDIA_ACCESS:kt,WEBRTC_ERROR:yt},Symbol.toStringTag,{value:"Module"})),Y="incomingCall",x="declinedIncomingCall",G="failedIncomingCall",$="terminatedIncomingCall",L="connecting",O="connected",N="disconnected",D="newRTCSession",A="registered",X="unregistered",R="registrationFailed",Be="newMessage",J="sipEvent",z="availableSecondRemoteStream",Q="notAvailableSecondRemoteStream",K="mustStopPresentation",M="shareState",j="enterRoom",Z="useLicense",ee="peerconnection:confirmed",te="peerconnection:ontrack",P="channels",se="channels:notify",ne="ended:fromserver",ie="main-cam-control",re="admin-stop-main-cam",oe="admin-start-main-cam",ae="admin-stop-mic",ce="admin-start-mic",p="admin-force-sync-media-state",Ee="participant:added-to-list-moderators",_e="participant:removed-from-list-moderators",he="participant:move-request-to-stream",de="participation:accepting-word-request",le="participation:cancelling-word-request",ue="webcast:started",Te="webcast:stopped",Se="account:changed",Ne="account:deleted",Ce="conference:participant-token-issued",I="ended",Ve="sending",Ye="reinvite",xe="replaces",Ge="refer",$e="progress",Xe="accepted",v="confirmed",b="peerconnection",C="failed",Je="muted",ze="unmuted",ge="newDTMF",Ae="newInfo",Qe="hold",Ke="unhold",je="update",Ze="sdp",et="icecandidate",tt="getusermediafailed",st="peerconnection:createofferfailed",nt="peerconnection:createanswerfailed",it="peerconnection:setlocaldescriptionfailed",rt="peerconnection:setremotedescriptionfailed",ot="presentation:start",at="presentation:started",ct="presentation:end",Re="presentation:ended",w="presentation:failed",Bt=Object.freeze(Object.defineProperty({__proto__:null,ACCEPTED:Xe,ACCOUNT_CHANGED:Se,ACCOUNT_DELETED:Ne,ADMIN_FORCE_SYNC_MEDIA_STATE:p,ADMIN_START_MAIN_CAM:oe,ADMIN_START_MIC:ce,ADMIN_STOP_MAIN_CAM:re,ADMIN_STOP_MIC:ae,AVAILABLE_SECOND_REMOTE_STREAM_EVENT:z,CHANNELS:P,CHANNELS_NOTIFY:se,CONFERENCE_PARTICIPANT_TOKEN_ISSUED:Ce,CONFIRMED:v,CONNECTED:O,CONNECTING:L,DECLINED_INCOMING_CALL:x,DISCONNECTED:N,ENDED:I,ENDED_FROM_SERVER:ne,ENTER_ROOM:j,FAILED:C,FAILED_INCOMING_CALL:G,GET_USER_MEDIA_FAILED:tt,HOLD:Qe,ICE_CANDIDATE:et,INCOMING_CALL:Y,MAIN_CAM_CONTROL:ie,MUST_STOP_PRESENTATION_EVENT:K,MUTED:Je,NEW_DTMF:ge,NEW_INFO:Ae,NEW_MESSAGE:Be,NEW_RTC_SESSION:D,NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT:Q,PARTICIPANT_ADDED_TO_LIST_MODERATORS:Ee,PARTICIPANT_MOVE_REQUEST_TO_STREAM:he,PARTICIPANT_REMOVED_FROM_LIST_MODERATORS:_e,PARTICIPATION_ACCEPTING_WORD_REQUEST:de,PARTICIPATION_CANCELLING_WORD_REQUEST:le,PEER_CONNECTION:b,PEER_CONNECTION_CONFIRMED:ee,PEER_CONNECTION_CREATE_ANSWER_FAILED:nt,PEER_CONNECTION_CREATE_OFFER_FAILED:st,PEER_CONNECTION_ONTRACK:te,PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED:it,PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED:rt,PRESENTATION_END:ct,PRESENTATION_ENDED:Re,PRESENTATION_FAILED:w,PRESENTATION_START:ot,PRESENTATION_STARTED:at,PROGRESS:$e,REFER:Ge,REGISTERED:A,REGISTRATION_FAILED:R,REINVITE:Ye,REPLACES:xe,SDP:Ze,SENDING:Ve,SHARE_STATE:M,SIP_EVENT:J,TERMINATED_INCOMING_CALL:$,UNHOLD:Ke,UNMUTED:ze,UNREGISTERED:X,UPDATE:je,USE_LICENSE:Z,WEBCAST_STARTED:ue,WEBCAST_STOPPED:Te},Symbol.toStringTag,{value:"Module"})),Et=[Y,x,$,G,de,le,he,se,Ce,Se,Ne,ue,Te,Ee,_e],Ie=[L,O,N,D,A,X,R,Be,J],_t=[z,Q,K,M,j,Z,ee,te,P,ne,ie,oe,re,ae,ce,p],me=[I,L,Ve,Ye,xe,Ge,$e,Xe,v,b,C,Je,ze,ge,Ae,Qe,Ke,je,Ze,et,tt,st,nt,it,rt,ot,at,ct,Re,w],fe=[...Ie,...Et],Oe=[...me,..._t],Vt=Object.freeze(Object.defineProperty({__proto__:null,SESSION_EVENT_NAMES:Oe,SESSION_JSSIP_EVENT_NAMES:me,SESSION_SYNTHETICS_EVENT_NAMES:_t,UA_EVENT_NAMES:fe,UA_JSSIP_EVENT_NAMES:Ie,UA_SYNTHETICS_EVENT_NAMES:Et},Symbol.toStringTag,{value:"Module"})),Yt=r=>{const e=[];return r&&e.push(`X-Vinteo-Remote: ${r}`),e},xt="content-type",Gt="x-webrtc-enter-room",q="application/vinteo.webrtc.sharedesktop",$t="application/vinteo.webrtc.roomname",Xt="application/vinteo.webrtc.channels",Jt="application/vinteo.webrtc.mediastate",zt="application/vinteo.webrtc.refusal",ve="application/vinteo.webrtc.maincam",Qt="application/vinteo.webrtc.mic",Kt="application/vinteo.webrtc.uselic",jt="X-WEBRTC-USE-LICENSE",be="X-WEBRTC-INPUT-CHANNELS",we="X-WEBRTC-OUTPUT-CHANNELS",Zt="X-WEBRTC-MAINCAM",es="X-WEBRTC-MIC",ye="X-WEBRTC-SYNC",ts="X-WEBRTC-MAINCAM-RESOLUTION",ss="X-WEBRTC-MEDIA-STATE",ns="X-Vinteo-Media-Type",is="X-Vinteo-MainCam-State",rs="X-Vinteo-Mic-State",os="application/vinteo.webrtc.notify",as="X-VINTEO-NOTIFY",m="x-webrtc-share-state",cs=`${m}: LETMESTARTPRESENTATION`,Es=`${m}: STOPPRESENTATION`,ht="YOUCANRECEIVECONTENT",dt="CONTENTEND",_s="YOUMUSTSTOPSENDCONTENT",hs=`${m}: ${ht}`,ds=`${m}: ${dt}`,ls="X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE",us=`${ls}: LETMESTARTMAINCAM`,De="sip-connector",F=B(De),Ts=()=>{B.enable(De)},Ss=()=>{B.enable(`-${De}`)};var g=(r=>(r.PAUSE_MAIN_CAM="PAUSEMAINCAM",r.RESUME_MAIN_CAM="RESUMEMAINCAM",r.MAX_MAIN_CAM_RESOLUTION="MAXMAINCAMRESOLUTION",r.ADMIN_STOP_MAIN_CAM="ADMINSTOPMAINCAM",r.ADMIN_START_MAIN_CAM="ADMINSTARTMAINCAM",r))(g||{}),y=(r=>(r.ADMIN_STOP_MIC="ADMINSTOPMIC",r.ADMIN_START_MIC="ADMINSTARTMIC",r))(y||{}),U=(r=>(r.ADMIN_SYNC_FORCED="1",r.ADMIN_SYNC_NOT_FORCED="0",r))(U||{}),lt=(r=>(r.AUDIO="AUDIO",r.VIDEO="VIDEO",r.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION",r))(lt||{});function Ns(r){return e=>`sip:${e}@${r}`}const Cs=(r,e)=>()=>Math.floor(Math.random()*(e-r))+r,Ue=r=>r.trim().replaceAll(" ","_"),gs=Cs(1e5,99999999),k=(r,{videoMode:e,audioMode:t}={})=>{if(!r||e==="recvonly"&&t==="recvonly")return;const s=t==="recvonly"?[]:r.getAudioTracks(),n=e==="recvonly"?[]:r.getVideoTracks(),o=[...s,...n],a=new MediaStream(o);return a.getTracks=()=>[...a.getAudioTracks(),...a.getVideoTracks()],a},As=r=>r.some(t=>{const{kind:s}=t;return s==="video"}),Rs="Error decline with 603",Is=r=>r.message===Rs,ms=(r,e)=>r.find(t=>t.track&&e.getTracks().includes(t.track)),ut=1,Tt=r=>(e,t)=>t!==void 0&&e!==t||t===void 0&&e!==r,fs=Tt(ut),Os=(r,e)=>{const t=r===void 0?void 0:Math.max(r,ut);if(t!==void 0&&fs(t,e))return t},Ds=Tt(),Ms=(r,e)=>{if(Ds(r,e))return r},St=async(r,e,t)=>{const s=r.getParameters();(s.encodings===void 0||s.encodings.length===0)&&(s.encodings=[{}]);const[n]=s.encodings,o=n.scaleResolutionDownBy,a=Os(e.scaleResolutionDownBy,o);let c=!1;a!==void 0&&(s.encodings[0].scaleResolutionDownBy=a,c=!0);const E=n.maxBitrate,_=Ms(e.maxBitrate,E);return _!==void 0&&(s.encodings[0].maxBitrate=_,c=!0),c?(t&&t(s),r.setParameters(s).then(()=>({parameters:s,isChanged:c}))):{parameters:s,isChanged:c}},Ps=async(r,e,t)=>{const s=ms(r,e);if(s)return St(s,{maxBitrate:t})},ps=486,vs=487,W="local",Le="remote",bs=(r=new Error)=>{const{originator:e,cause:t}=r;return T.isCanceledError(r)?!0:typeof t=="string"?t===He||t===V||e===W&&(t===Fe||t===ke):!1},S="SipConnector",ws="channels",ys="WebcastStarted",Us="WebcastStopped",Ls="accountChanged",Hs="accountDeleted",qs="addedToListModerators",ks="removedFromListModerators",Fs="ParticipationRequestAccepted",Ws="ParticipationRequestRejected",Bs="ParticipantMovedToWebcast",Vs="ConferenceParticipantTokenIssued";class Ys{constructor({JsSIP:e}){i(this,"_isRegisterConfig",!1);i(this,"_connectionConfiguration",{});i(this,"_remoteStreams",{});i(this,"JsSIP");i(this,"_sessionEvents");i(this,"_uaEvents");i(this,"_cancelableConnect");i(this,"_cancelableCreateUa");i(this,"_cancelableDisconnect");i(this,"_cancelableSet");i(this,"_cancelableCall");i(this,"_cancelableAnswer");i(this,"_cancelableSendDTMF");i(this,"getSipServerUrl",e=>e);i(this,"promisePendingStartPresentation");i(this,"promisePendingStopPresentation");i(this,"ua");i(this,"session");i(this,"incomingSession");i(this,"_streamPresentationCurrent");i(this,"socket");i(this,"connect",async e=>(this._cancelRequests(),this._cancelableConnect.request(e)));i(this,"createUa",async e=>this._cancelableCreateUa.request(e));i(this,"set",async e=>this._cancelableSet.request(e));i(this,"call",async e=>this._cancelableCall.request(e));i(this,"disconnect",async()=>(this._cancelRequests(),this._disconnectWithoutCancelRequests()));i(this,"answerToIncomingCall",async e=>this._cancelableAnswer.request(e));i(this,"sendDTMF",async e=>this._cancelableSendDTMF.request(e));i(this,"hangUp",async()=>(this._cancelRequests(),this._hangUpWithoutCancelRequests()));i(this,"tryRegister",async()=>{if(!this.isRegisterConfig)throw new Error("Config is not registered");this._uaEvents.trigger(L,void 0);try{await this.unregister()}catch(e){F("tryRegister",e)}return this.register()});i(this,"declineToIncomingCall",async({statusCode:e=vs}={})=>new Promise((t,s)=>{if(!this.isAvailableIncomingCall){s(new Error("no incomingSession"));return}const n=this.incomingSession,o=this.remoteCallerData;this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest(),this.removeIncomingSession(),this._uaEvents.trigger(x,o),t(n.terminate({status_code:e}))}));i(this,"busyIncomingCall",async()=>this.declineToIncomingCall({statusCode:ps}));i(this,"removeIncomingSession",()=>{delete this.incomingSession});i(this,"handleNewRTCSession",({originator:e,session:t})=>{if(e===Le){this.incomingSession=t;const s=this.remoteCallerData;t.on(C,n=>{this.removeIncomingSession(),n.originator===W?this._uaEvents.trigger($,s):this._uaEvents.trigger(G,s)}),this._uaEvents.trigger(Y,s)}});i(this,"_connect",async e=>this.createUa(e).then(async()=>this._start()));i(this,"_createUa",async({displayName:e="",user:t,password:s,register:n=!1,sipServerUrl:o,sipWebSocketServerURL:a,remoteAddress:c,extraHeaders:E=[],sdpSemantics:_="plan-b",sessionTimers:h=!1,registerExpires:d=60*5,connectionRecoveryMinInterval:l=2,connectionRecoveryMaxInterval:u=6,userAgent:f})=>{if(!o)throw new Error("sipServerUrl is required");if(!a)throw new Error("sipWebSocketServerURL is required");if(n&&!t)throw new Error("user is required for authorized connection");if(n&&!s)throw new Error("password is required for authorized connection");this._connectionConfiguration={sipServerUrl:o,displayName:e,register:n,user:t,password:s},this._init({sipServerUrl:o,sipWebSocketServerURL:a});const H=n&&t?t.trim():`${gs()}`,Me={password:s,register:n,display_name:Ue(e),user_agent:f,sdp_semantics:_,sockets:[this.socket],uri:this.getSipServerUrl(H),session_timers:h,register_expires:d,connection_recovery_min_interval:l,connection_recovery_max_interval:u};this.ua&&await this._disconnectWithoutCancelRequests(),this._isRegisterConfig=!!Me.register,this.ua=new this.JsSIP.UA(Me),this._uaEvents.eachTriggers((Ct,gt)=>{const Pe=Ie.find(At=>At===gt);Pe&&this.ua&&this.ua.on(Pe,Ct)});const Nt=[...Yt(c),...E];return this.ua.registrator().setExtraHeaders(Nt),this.ua});i(this,"_start",async()=>new Promise((e,t)=>{const{ua:s}=this;if(!s){t(new Error("this.ua is not initialized"));return}const n=()=>{c(),e(s)},o=E=>{c(),t(E)},a=()=>{this.isRegisterConfig?(this.on(A,n),this.on(R,o)):this.on(O,n),this.on(N,o)},c=()=>{this.off(A,n),this.off(R,o),this.off(O,n),this.off(N,o)};a(),this.on(D,this.handleNewRTCSession),s.start()}));i(this,"_set",async({displayName:e,password:t})=>new Promise((s,n)=>{const{ua:o}=this;if(!o){n(new Error("this.ua is not initialized"));return}let a=!1,c=!1;e!==void 0&&e!==this._connectionConfiguration.displayName&&(a=o.set("display_name",Ue(e)),this._connectionConfiguration.displayName=e),t!==void 0&&t!==this._connectionConfiguration.password&&(c=o.set("password",t),this._connectionConfiguration.password=t);const E=a||c;c&&this.isRegisterConfig?this.register().then(()=>{s(E)}).catch(n):E?s(E):n(new Error("nothing changed"))}));i(this,"_disconnectWithoutCancelRequests",async()=>this._cancelableDisconnect.request());i(this,"_disconnect",async()=>{this.off(D,this.handleNewRTCSession);const e=new Promise(t=>{this.once(N,()=>{delete this.ua,t()})});return this.ua?(await this._hangUpWithoutCancelRequests(),this.ua?this.ua.stop():this._uaEvents.trigger(N,void 0)):this._uaEvents.trigger(N,void 0),e});i(this,"_call",async({number:e,mediaStream:t,extraHeaders:s=[],ontrack:n,iceServers:o,videoMode:a,audioMode:c,degradationPreference:E,offerToReceiveAudio:_=!0,offerToReceiveVideo:h=!0})=>new Promise((d,l)=>{const{ua:u}=this;if(!u){l(new Error("this.ua is not initialized"));return}this._connectionConfiguration.number=e,this._connectionConfiguration.answer=!1,this._handleCall({ontrack:n}).then(d).catch(l),this.session=u.call(this.getSipServerUrl(e),{extraHeaders:s,mediaStream:k(t,{videoMode:a,audioMode:c}),eventHandlers:this._sessionEvents.triggers,videoMode:a,audioMode:c,degradationPreference:E,pcConfig:{iceServers:o},rtcOfferConstraints:{offerToReceiveAudio:_,offerToReceiveVideo:h}})}));i(this,"_answer",async({mediaStream:e,ontrack:t,extraHeaders:s=[],iceServers:n,videoMode:o,audioMode:a,degradationPreference:c})=>new Promise((E,_)=>{if(!this.isAvailableIncomingCall){_(new Error("no incomingSession"));return}this.session=this.incomingSession,this.removeIncomingSession();const{session:h}=this;if(!h){_(new Error("No session established"));return}this._sessionEvents.eachTriggers((l,u)=>{const f=me.find(H=>H===u);f&&h.on(f,l)}),this._connectionConfiguration.answer=!0,this._connectionConfiguration.number=h.remote_identity.uri.user,this._handleCall({ontrack:t}).then(E).catch(_);const d=k(e,{videoMode:o,audioMode:a});h.answer({extraHeaders:s,videoMode:o,audioMode:a,degradationPreference:c,mediaStream:d,pcConfig:{iceServers:n}})}));i(this,"_handleCall",async({ontrack:e})=>new Promise((t,s)=>{const n=()=>{this.onSession(b,h),this.onSession(v,d)},o=()=>{this.offSession(b,h),this.offSession(v,d)},a=()=>{this.onSession(C,E),this.onSession(I,E)},c=()=>{this.offSession(C,E),this.offSession(I,E)},E=l=>{o(),c(),s(l)};let _;const h=({peerconnection:l})=>{_=l,_.ontrack=u=>{this._sessionEvents.trigger(te,_),e&&e(u)}},d=()=>{_&&this._sessionEvents.trigger(ee,_),o(),c(),t(_)};n(),a()}));i(this,"_restoreSession",()=>{this._resetPresentation(),delete this._connectionConfiguration.number,delete this.session,this._remoteStreams={}});i(this,"_sendDTMF",async e=>new Promise((t,s)=>{const{session:n}=this;if(!n){s(new Error("No session established"));return}this.onceSession(ge,({originator:o})=>{o===W&&t()}),n.sendDTMF(e,{duration:120,interToneGap:600})}));i(this,"_hangUpWithoutCancelRequests",async()=>{if(this.ua&&this.session){const{session:e}=this;this._streamPresentationCurrent&&await this.stopPresentation(),this._restoreSession(),e.isEnded()||e.terminate()}});i(this,"_handleShareState",e=>{switch(e){case ht:{this._sessionEvents.trigger(z,void 0);break}case dt:{this._sessionEvents.trigger(Q,void 0);break}case _s:{this._sessionEvents.trigger(K,void 0);break}}});i(this,"_maybeTriggerChannels",e=>{const t=e.getHeader(be),s=e.getHeader(we);if(t&&s){const n={inputChannels:t,outputChannels:s};this._sessionEvents.trigger(P,n)}});i(this,"_handleNotify",e=>{switch(e.cmd){case ws:{const t=e;this._triggerChannelsNotify(t);break}case ys:{const t=e;this._triggerWebcastStartedNotify(t);break}case Us:{const t=e;this._triggerWebcastStoppedNotify(t);break}case qs:{const t=e;this._triggerAddedToListModeratorsNotify(t);break}case ks:{const t=e;this._triggerRemovedFromListModeratorsNotify(t);break}case Fs:{const t=e;this._triggerParticipationAcceptingWordRequest(t);break}case Ws:{const t=e;this._triggerParticipationCancellingWordRequest(t);break}case Bs:{const t=e;this._triggerParticipantMoveRequestToStream(t);break}case Ls:{this._triggerAccountChangedNotify();break}case Hs:{this._triggerAccountDeletedNotify();break}case Vs:{const t=e;this._triggerConferenceParticipantTokenIssued(t);break}default:F("unknown cmd",e.cmd)}});i(this,"_triggerRemovedFromListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(_e,t)});i(this,"_triggerAddedToListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(Ee,t)});i(this,"_triggerWebcastStartedNotify",({body:{conference:e,type:t}})=>{const s={conference:e,type:t};this._uaEvents.trigger(ue,s)});i(this,"_triggerWebcastStoppedNotify",({body:{conference:e,type:t}})=>{const s={conference:e,type:t};this._uaEvents.trigger(Te,s)});i(this,"_triggerAccountChangedNotify",()=>{this._uaEvents.trigger(Se,void 0)});i(this,"_triggerAccountDeletedNotify",()=>{this._uaEvents.trigger(Ne,void 0)});i(this,"_triggerConferenceParticipantTokenIssued",({body:{conference:e,participant:t,jwt:s}})=>{const n={conference:e,participant:t,jwt:s};this._uaEvents.trigger(Ce,n)});i(this,"_triggerChannelsNotify",e=>{const t=e.input,s=e.output,n={inputChannels:t,outputChannels:s};this._uaEvents.trigger(se,n)});i(this,"_triggerParticipationAcceptingWordRequest",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(de,t)});i(this,"_triggerParticipationCancellingWordRequest",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(le,t)});i(this,"_triggerParticipantMoveRequestToStream",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(he,t)});i(this,"_triggerEnterRoom",e=>{const t=e.getHeader(Gt);this._sessionEvents.trigger(j,t)});i(this,"_triggerShareState",e=>{const t=e.getHeader(m);this._sessionEvents.trigger(M,t)});i(this,"_triggerMainCamControl",e=>{const t=e.getHeader(Zt),s=e.getHeader(ye),n=s===U.ADMIN_SYNC_FORCED;if(t===g.ADMIN_START_MAIN_CAM)this._sessionEvents.trigger(oe,{isSyncForced:n});else if(t===g.ADMIN_STOP_MAIN_CAM)this._sessionEvents.trigger(re,{isSyncForced:n});else if((t===g.RESUME_MAIN_CAM||t===g.PAUSE_MAIN_CAM)&&s)this._sessionEvents.trigger(p,{isSyncForced:n});else{const o=e.getHeader(ts);this._sessionEvents.trigger(ie,{mainCam:t,resolutionMainCam:o})}});i(this,"_triggerMicControl",e=>{const t=e.getHeader(es),n=e.getHeader(ye)===U.ADMIN_SYNC_FORCED;t===y.ADMIN_START_MIC?this._sessionEvents.trigger(ce,{isSyncForced:n}):t===y.ADMIN_STOP_MIC&&this._sessionEvents.trigger(ae,{isSyncForced:n})});i(this,"_triggerUseLicense",e=>{const t=e.getHeader(jt);this._sessionEvents.trigger(Z,t)});i(this,"_handleNewInfo",e=>{const{originator:t}=e;if(t!=="remote")return;const{request:s}=e,n=s.getHeader(xt);if(n)switch(n){case $t:{this._triggerEnterRoom(s),this._maybeTriggerChannels(s);break}case os:{this._maybeHandleNotify(s);break}case q:{this._triggerShareState(s);break}case ve:{this._triggerMainCamControl(s);break}case Qt:{this._triggerMicControl(s);break}case Kt:{this._triggerUseLicense(s);break}}});i(this,"_handleSipEvent",({request:e})=>{this._maybeHandleNotify(e)});i(this,"_maybeHandleNotify",e=>{const t=e.getHeader(as);if(t){const s=JSON.parse(t);this._handleNotify(s)}});i(this,"_handleEnded",e=>{const{originator:t}=e;t===Le&&this._sessionEvents.trigger(ne,e),this._restoreSession()});this.JsSIP=e,this._sessionEvents=new pe(Oe),this._uaEvents=new pe(fe),this._cancelableConnect=new T.CancelableRequest(this._connect,{moduleName:S,afterCancelRequest:()=>{this._cancelableCreateUa.cancelRequest(),this._cancelableDisconnect.cancelRequest()}}),this._cancelableCreateUa=new T.CancelableRequest(this._createUa,{moduleName:S}),this._cancelableDisconnect=new T.CancelableRequest(this._disconnect,{moduleName:S}),this._cancelableSet=new T.CancelableRequest(this._set,{moduleName:S}),this._cancelableCall=new T.CancelableRequest(this._call,{moduleName:S}),this._cancelableAnswer=new T.CancelableRequest(this._answer,{moduleName:S}),this._cancelableSendDTMF=new T.CancelableRequest(this._sendDTMF,{moduleName:S}),this.onSession(M,this._handleShareState),this.onSession(Ae,this._handleNewInfo),this.on(J,this._handleSipEvent),this.onSession(C,this._handleEnded),this.onSession(I,this._handleEnded)}async register(){return new Promise((e,t)=>{this.isRegisterConfig&&this.ua?(this.ua.on(A,e),this.ua.on(R,t),this.ua.register()):t(new Error("Config is not registered"))})}async unregister(){return new Promise((e,t)=>{this.isRegistered&&this.ua?(this.ua.on(X,e),this.ua.unregister()):t(new Error("ua is not registered"))})}async sendOptions(e,t,s){if(!this.ua)throw new Error("is not connected");return new Promise((n,o)=>{try{this.ua.sendOptions(e,t,{extraHeaders:s,eventHandlers:{succeeded:()=>{n()},failed:o}})}catch(a){o(a)}})}async ping(e,t){var n;if(!((n=this.ua)!=null&&n.configuration.uri))throw new Error("is not connected");const s=this.ua.configuration.uri;return this.sendOptions(s,e,t)}async replaceMediaStream(e,t){if(!this.session)throw new Error("No session established");return this.session.replaceMediaStream(e,t)}async askPermissionToEnableCam(e={}){if(!this.session)throw new Error("No session established");const t=[us];return this.session.sendInfo(ve,void 0,{noTerminateWhenError:!0,...e,extraHeaders:t}).catch(s=>{if(Is(s))throw s})}get isPendingPresentation(){return!!this.promisePendingStartPresentation||!!this.promisePendingStopPresentation}async _sendPresentation(e,t,{maxBitrate:s,degradationPreference:n,isNeedReinvite:o=!0,isP2P:a=!1}){const c=k(t);this._streamPresentationCurrent=c;const E=a?[hs]:[cs],_=e.sendInfo(q,void 0,{extraHeaders:E}).then(async()=>e.startPresentation(c,o,n)).then(async()=>{const{connection:h}=this;if(!h||s===void 0)return;const d=h.getSenders();return Ps(d,t,s)}).then(()=>t).catch(h=>{throw this._sessionEvents.trigger(w,h),h});return this.promisePendingStartPresentation=_,_.finally(()=>{this.promisePendingStartPresentation=void 0})}async startPresentation(e,{isNeedReinvite:t=!0,isP2P:s=!1,maxBitrate:n,degradationPreference:o}={}){const a=this.establishedSession;if(!a)throw new Error("No session established");if(this._streamPresentationCurrent)throw new Error("Presentation is already started");return this._sendPresentation(a,e,{isNeedReinvite:t,isP2P:s,maxBitrate:n,degradationPreference:o})}async stopPresentation({isP2P:e=!1}={}){const t=this._streamPresentationCurrent;let s=this.promisePendingStartPresentation??Promise.resolve();const n=e?[ds]:[Es],o=this.establishedSession;return o&&t&&(s=s.then(async()=>o.sendInfo(q,void 0,{extraHeaders:n})).then(async()=>o.stopPresentation(t)).catch(a=>{throw this._sessionEvents.trigger(w,a),a})),!o&&t&&this._sessionEvents.trigger(Re,t),this.promisePendingStopPresentation=s,s.finally(()=>{this._resetPresentation()})}async updatePresentation(e,{isP2P:t=!1,maxBitrate:s,degradationPreference:n}={}){const o=this.establishedSession;if(!o)throw new Error("No session established");if(!this._streamPresentationCurrent)throw new Error("Presentation has not started yet");return this.promisePendingStartPresentation&&await this.promisePendingStartPresentation,this._sendPresentation(o,e,{isP2P:t,maxBitrate:s,degradationPreference:n,isNeedReinvite:!1})}_resetPresentation(){delete this._streamPresentationCurrent,this.promisePendingStartPresentation=void 0,this.promisePendingStopPresentation=void 0}on(e,t){return this._uaEvents.on(e,t)}once(e,t){return this._uaEvents.once(e,t)}onceRace(e,t){return this._uaEvents.onceRace(e,t)}async wait(e){return this._uaEvents.wait(e)}off(e,t){this._uaEvents.off(e,t)}onSession(e,t){return this._sessionEvents.on(e,t)}onceSession(e,t){return this._sessionEvents.once(e,t)}onceRaceSession(e,t){return this._sessionEvents.onceRace(e,t)}async waitSession(e){return this._sessionEvents.wait(e)}offSession(e,t){this._sessionEvents.off(e,t)}isConfigured(){return!!this.ua}getConnectionConfiguration(){return{...this._connectionConfiguration}}getRemoteStreams(){if(!this.connection)return;const t=this.connection.getReceivers().map(({track:s})=>s);return As(t)?this._generateStreams(t):this._generateAudioStreams(t)}get connection(){var t;return(t=this.session)==null?void 0:t.connection}get remoteCallerData(){var e,t,s,n,o,a;return{displayName:(t=(e=this.incomingSession)==null?void 0:e.remote_identity)==null?void 0:t.display_name,host:(n=(s=this.incomingSession)==null?void 0:s.remote_identity)==null?void 0:n.uri.host,incomingNumber:(a=(o=this.incomingSession)==null?void 0:o.remote_identity)==null?void 0:a.uri.user,session:this.incomingSession}}get requested(){return this._cancelableConnect.requested||this._cancelableCreateUa.requested||this._cancelableCall.requested||this._cancelableAnswer.requested}get establishedSession(){return this.session&&this.session.isEstablished()?this.session:void 0}get isRegistered(){return!!this.ua&&this.ua.isRegistered()}get isRegisterConfig(){return!!this.ua&&this._isRegisterConfig}get isCallActive(){return!!(this.ua&&this.session)}get isAvailableIncomingCall(){return!!this.incomingSession}_init({sipServerUrl:e,sipWebSocketServerURL:t}){this.getSipServerUrl=Ns(e),this.socket=new this.JsSIP.WebSocketInterface(t)}_generateStream(e,t){const{id:s}=e,n=this._remoteStreams[s]||new MediaStream;return t&&n.addTrack(t),n.addTrack(e),this._remoteStreams[s]=n,n}_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,n)=>{if(s.kind==="audio")return;const o=s,a=e[n-1];let c;a&&a.kind==="audio"&&(c=a);const E=this._generateStream(o,c);t.push(E)}),t}_generateAudioStreams(e){return e.map(s=>this._generateAudioStream(s))}_cancelRequests(){this._cancelActionsRequests(),this._cancelCallRequests(),this._cancelConnectRequests()}_cancelConnectRequests(){this._cancelableConnect.cancelRequest()}_cancelCallRequests(){this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest()}_cancelActionsRequests(){this._cancelableAnswer.cancelRequest(),this._cancelableSendDTMF.cancelRequest()}async waitChannels(){return this.waitSession(P)}async waitSyncMediaState(){return this.waitSession(p)}async sendChannels({inputChannels:e,outputChannels:t}){if(!this.session)throw new Error("No session established");const s=`${be}: ${e}`,n=`${we}: ${t}`,o=[s,n];return this.session.sendInfo(Xt,void 0,{extraHeaders:o})}async sendMediaState({cam:e,mic:t},s={}){if(!this.session)throw new Error("No session established");const n=`${ss}: currentstate`,o=`${is}: ${Number(e)}`,a=`${rs}: ${Number(t)}`,c=[n,o,a];return this.session.sendInfo(Jt,void 0,{noTerminateWhenError:!0,...s,extraHeaders:c})}async _sendRefusalToTurnOn(e,t={}){if(!this.session)throw new Error("No session established");const c=[`${ns}: ${e==="mic"?0:1}`];return this.session.sendInfo(zt,void 0,{noTerminateWhenError:!0,...t,extraHeaders:c})}async sendRefusalToTurnOnMic(e={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("mic",{noTerminateWhenError:!0,...e})}async sendRefusalToTurnOnCam(e={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("cam",{noTerminateWhenError:!0,...e})}}exports.BAD_MEDIA_DESCRIPTION=We;exports.EEventsMainCAM=g;exports.EEventsMic=y;exports.EEventsSyncMediaState=U;exports.EUseLicense=lt;exports.NOT_FOUND=qe;exports.REJECTED=V;exports.SESSION_EVENT_NAMES=Oe;exports.SipConnector=Ys;exports.UA_EVENT_NAMES=fe;exports.causes=Wt;exports.constants=Bt;exports.disableDebug=Ss;exports.enableDebug=Ts;exports.eventNames=Vt;exports.hasCanceledCallError=bs;exports.logger=F;exports.setEncodingsToSender=St;
|