sip-connector 13.2.0 → 13.3.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.
@@ -15,11 +15,13 @@ interface IProxyMethods {
15
15
  sendDTMF: SipConnector['sendDTMF'];
16
16
  hangUp: SipConnector['hangUp'];
17
17
  declineToIncomingCall: SipConnector['declineToIncomingCall'];
18
- isConfigured: SipConnector['isConfigured'];
19
18
  sendChannels: SipConnector['sendChannels'];
20
19
  checkTelephony: SipConnector['checkTelephony'];
21
20
  waitChannels: SipConnector['waitChannels'];
21
+ ping: SipConnector['ping'];
22
22
  connection: SipConnector['connection'];
23
+ isConfigured: SipConnector['isConfigured'];
24
+ isRegistered: SipConnector['isRegistered'];
23
25
  }
24
26
  declare class SipConnectorFacade implements IProxyMethods {
25
27
  readonly sipConnector: SipConnector;
@@ -38,11 +40,13 @@ declare class SipConnectorFacade implements IProxyMethods {
38
40
  sendDTMF: IProxyMethods['sendDTMF'];
39
41
  hangUp: IProxyMethods['hangUp'];
40
42
  declineToIncomingCall: IProxyMethods['declineToIncomingCall'];
41
- isConfigured: IProxyMethods['isConfigured'];
42
43
  sendChannels: IProxyMethods['sendChannels'];
43
44
  checkTelephony: IProxyMethods['checkTelephony'];
44
45
  waitChannels: IProxyMethods['waitChannels'];
46
+ ping: IProxyMethods['ping'];
45
47
  connection: IProxyMethods['connection'];
48
+ isConfigured: IProxyMethods['isConfigured'];
49
+ isRegistered: IProxyMethods['isRegistered'];
46
50
  constructor(sipConnector: SipConnector, { preferredMimeTypesVideoCodecs, excludeMimeTypesVideoCodecs, }?: {
47
51
  preferredMimeTypesVideoCodecs?: string[];
48
52
  excludeMimeTypesVideoCodecs?: string[];
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var ne=Object.defineProperty;var te=(n,e,t)=>e in n?ne(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var u=(n,e,t)=>te(n,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("./SipConnector-CE4F15z6.cjs"),se=require("sequent-promises"),oe=require("stack-promises"),re=require("@krivega/cancelable-promise"),ie=require("repeated-calls"),ce=require("ts-debounce"),ae=require("debug"),$=n=>{const{url:e,cause:t}=n;let s=e;return(t===o.BAD_MEDIA_DESCRIPTION||t===o.NOT_FOUND)&&(s=`${n.message.to.uri.user}@${n.message.to.uri.host}`),s};var j=(n=>(n.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",n.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",n.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",n.NOT_FOUND_ERROR="NOT_FOUND_ERROR",n.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",n.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",n))(j||{});const ue=(n=new Error)=>{var r;const{cause:e,socket:t}=n;let s="CONNECT_SERVER_FAILED";switch(e){case"Forbidden":{s="WRONG_USER_OR_PASSWORD";break}case o.BAD_MEDIA_DESCRIPTION:{s="BAD_MEDIA_ERROR";break}case o.NOT_FOUND:{s="NOT_FOUND_ERROR";break}default:t&&((r=t==null?void 0:t._ws)==null?void 0:r.readyState)===3?s="WS_CONNECTION_FAILED":$(n)&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},le=n=>{let e="";try{e=JSON.stringify(n)}catch(t){o.logger("failed to stringify message",t)}return e},de=(n=new Error)=>{const{code:e,cause:t,message:s}=n,r=$(n),i={code:"",cause:"",message:""};return typeof s=="object"&&s!==null?i.message=le(s):s&&(i.message=String(s)),r&&(i.link=r),e&&(i.code=e),t&&(i.cause=t),i},ge=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:j,getLinkError:$,getTypeFromError:ue,getValuesFromError:de},Symbol.toStringTag,{value:"Module"})),Se=({sessionId:n,remoteAddress:e,isMutedAudio:t,isMutedVideo:s,isRegistered:r,isPresentationCall:i})=>{const c=[],a=t?"0":"1",l=s?"0":"1";return c.push(`X-Vinteo-Mic-State: ${a}`,`X-Vinteo-MainCam-State: ${l}`),r||c.push("X-Vinteo-Purgatory-Call: yes"),n&&c.push(`X-Vinteo-Session: ${n}`),i&&c.push("X-Vinteo-Presentation-Call: yes"),e&&c.push(`X-Vinteo-Remote: ${e}`),c},Ce="[@*!|]",fe="_",me=n=>{let e=n;return e=e.replaceAll(new RegExp(Ce,"g"),fe),e},he=({appName:n,appVersion:e,browserName:t,browserVersion:s})=>{const i=`${me(n)} ${e}`;return`ChromeNew - ${t?`${t} ${s}, ${i}`:i}`},Re=({isUnifiedSdpSemantic:n,appVersion:e,browserName:t,browserVersion:s,appName:r})=>n?he({appVersion:e,browserName:t,browserVersion:s,appName:r}):"Chrome",W="purgatory",w=n=>n===W,pe=n=>e=>[...e].map(s=>async()=>n(s)),Ee=async({accumulatedKeys:n,sendKey:e,canRunTask:t})=>{const r=pe(e)(n);return se.sequentPromises(r,t)},ye=n=>t=>(o.logger("onStartMainCam"),n.onSession("admin-start-main-cam",t)),Te=n=>t=>(o.logger("onStartMic"),n.onSession("admin-start-mic",t)),Me=n=>t=>(o.logger("onStopMainCam"),n.onSession("admin-stop-main-cam",t)),be=n=>t=>(o.logger("onStopMic"),n.onSession("admin-stop-mic",t)),Ae=({sipConnector:n})=>{const e=(f,p)=>({isSyncForced:m=!1})=>{if(m){f();return}p()},t=ye(n),s=Me(n),r=Te(n),i=be(n);let c=()=>{},a=()=>{},l=()=>{},g=()=>{};const C=({onStartMainCamForced:f,onStartMainCamNotForced:p,onStopMainCamForced:m,onStopMainCamNotForced:h,onStartMicForced:E,onStartMicNotForced:y,onStopMicForced:T,onStopMicNotForced:M})=>{const _=e(f,p);c=t(_);const v=e(m,h);a=s(v);const O=e(E,y);l=r(O);const N=e(T,M);g=i(N)},S=()=>{c(),a(),l(),g()};return{start:f=>{C(f)},stop:()=>{S()}}},_e=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:W,createSyncMediaState:Ae,error:ge,getExtraHeaders:Se,getUserAgent:Re,hasPurgatory:w,sendDTMFAccumulated:Ee},Symbol.toStringTag,{value:"Module"})),ve=n=>[...n.keys()].map(e=>n.get(e)),Oe=(n,e)=>ve(n).find(t=>t.type===e),G=async n=>n.getStats().then(e=>{const t=Oe(e,"codec");return t==null?void 0:t.mimeType}),Ne=n=>n.find(e=>{var t;return((t=e==null?void 0:e.track)==null?void 0:t.kind)==="video"}),K=(n,e)=>n!==void 0&&e!==void 0&&n.toLowerCase().includes(e.toLowerCase()),Pe=1e6,R=n=>n*Pe,Y=R(.06),Be=R(4),De=n=>n<=64?Y:n<=128?R(.12):n<=256?R(.25):n<=384?R(.32):n<=426?R(.38):n<=640?R(.5):n<=848?R(.7):n<=1280?R(1):n<=1920?R(2):Be,we="av1",Ie=n=>K(n,we),Fe=.6,z=(n,e)=>Ie(e)?n*Fe:n,ke=n=>z(Y,n),Q=(n,e)=>{const t=De(n);return z(t,e)},Ue=1,J=({videoTrack:n,targetSize:e,codec:t})=>{const s=n.getSettings(),r=s.width,i=s.height,c=r/e.width,a=i/e.height,l=Math.max(c,a,Ue),g=Q(e.width,t);return{scaleResolutionDownBy:l,maxBitrate:g}},Z=oe.createStackPromises(),Ve=async()=>Z().catch(n=>{o.logger("videoSendingBalancer: error",n)}),Le=async n=>(Z.add(n),Ve()),q=async({sender:n,scaleResolutionDownBy:e,maxBitrate:t,onSetParameters:s})=>Le(async()=>o.setEncodingsToSender(n,{scaleResolutionDownBy:e,maxBitrate:t},s)),xe=async({sender:n,codec:e},t)=>{const r=ke(e);return q({sender:n,maxBitrate:r,onSetParameters:t,scaleResolutionDownBy:200})},L=async({sender:n,videoTrack:e,codec:t},s)=>{const c=e.getSettings().width,a=Q(c,t);return q({sender:n,maxBitrate:a,onSetParameters:s,scaleResolutionDownBy:1})},$e=async({sender:n,videoTrack:e,resolution:t,codec:s},r)=>{const[i,c]=t.split("x"),{maxBitrate:a,scaleResolutionDownBy:l}=J({videoTrack:e,codec:s,targetSize:{width:Number(i),height:Number(c)}});return q({sender:n,maxBitrate:a,onSetParameters:r,scaleResolutionDownBy:l})},qe=async({mainCam:n,resolutionMainCam:e,sender:t,videoTrack:s,codec:r},i)=>{switch(n){case o.EEventsMainCAM.PAUSE_MAIN_CAM:return xe({sender:t,codec:r},i);case o.EEventsMainCAM.RESUME_MAIN_CAM:return L({sender:t,videoTrack:s,codec:r},i);case o.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return e!==void 0?$e({sender:t,videoTrack:s,codec:r,resolution:e},i):L({sender:t,videoTrack:s,codec:r},i);default:return L({sender:t,videoTrack:s,codec:r},i)}},H={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},X=async({mainCam:n,resolutionMainCam:e,connection:t,onSetParameters:s,ignoreForCodec:r})=>{const i=t.getSenders(),c=Ne(i);if(!(c!=null&&c.track))return H;const a=await G(c);return K(a,r)?H:qe({mainCam:n,resolutionMainCam:e,sender:c,codec:a,videoTrack:c.track},s)},He=(n,{ignoreForCodec:e,onSetParameters:t}={})=>{const s=async()=>{const{connection:l}=n;if(!l)throw new Error("connection is not exist");return X({connection:l,onSetParameters:t,ignoreForCodec:e})};let r=s;const i=async l=>(r=async()=>{const{mainCam:g,resolutionMainCam:C}=l,{connection:S}=n;if(!S)throw new Error("connection is not exist");return X({mainCam:g,resolutionMainCam:C,connection:S,onSetParameters:t,ignoreForCodec:e})},r());return{subscribe:()=>{n.onSession("main-cam-control",i)},unsubscribe:()=>{n.offSession("main-cam-control",i)},balanceByTrack:s,resetMainCamControl(){r=s},async reBalance(){return r()}}},Xe=n=>n.getVideoTracks()[0],B=({mediaStream:n,simulcastEncodings:e,sendEncodings:t})=>{if(e&&e.length>0){const s=t??[],r=Xe(n);return e.forEach((i,c)=>{const a=s[c]??{};a.active=!0,i.rid!==void 0&&(a.rid=i.rid),i.scalabilityMode!==void 0&&(a.scalabilityMode=i.scalabilityMode);const{maxBitrate:l,scaleResolutionDownBy:g}=J({videoTrack:r,targetSize:{width:i.width,height:i.height}});a.maxBitrate=l,a.scaleResolutionDownBy=g,s[c]=a}),s}return t},je=(n,e)=>[...n,...e].filter((r,i,c)=>i===c.findIndex(a=>a.clockRate===r.clockRate&&a.mimeType===r.mimeType&&a.channels===r.channels&&a.sdpFmtpLine===r.sdpFmtpLine)),We=n=>{const e=RTCRtpSender.getCapabilities(n),t=RTCRtpReceiver.getCapabilities(n),s=e===null?[]:e.codecs,r=t===null?[]:t.codecs;return je(s,r)},Ge=(n,e)=>e===void 0||e.length===0?n:n.sort((t,s)=>{const r=e.indexOf(t.mimeType),i=e.indexOf(s.mimeType),c=r===-1?Number.MAX_VALUE:r,a=i===-1?Number.MAX_VALUE:i;return c-a}),Ke=(n,e)=>e===void 0||e.length===0?n:n.filter(t=>!e.includes(t.mimeType)),D=(n,{preferredMimeTypesVideoCodecs:e,excludeMimeTypesVideoCodecs:t})=>async s=>{var r;if(typeof s.setCodecPreferences=="function"&&((r=s.sender.track)==null?void 0:r.kind)==="video"&&(e!==void 0&&(e==null?void 0:e.length)>0||t!==void 0&&(t==null?void 0:t.length)>0)){const i=We("video"),c=Ke(i,t),a=Ge(c,e);s.setCodecPreferences(a)}Object.keys(n).length>0&&await o.setParametersToSender(s.sender,n)},x=n=>{if(!re.isCanceledError(n)&&!ie.hasCanceledError(n))throw n;return{isSuccessful:!1}},Ye=({kind:n,readyState:e})=>n==="video"&&e==="live",ze=new Set(["on","once","onceRace","wait","off","onSession","onceSession","onceRaceSession","waitSession","offSession","sendDTMF","hangUp","declineToIncomingCall","isConfigured","sendChannels","checkTelephony","waitChannels","connection"]);class Qe{constructor(e,{preferredMimeTypesVideoCodecs:t,excludeMimeTypesVideoCodecs:s}={}){u(this,"sipConnector");u(this,"preferredMimeTypesVideoCodecs");u(this,"excludeMimeTypesVideoCodecs");u(this,"on");u(this,"once");u(this,"onceRace");u(this,"wait");u(this,"off");u(this,"onSession");u(this,"onceSession");u(this,"onceRaceSession");u(this,"waitSession");u(this,"offSession");u(this,"sendDTMF");u(this,"hangUp");u(this,"declineToIncomingCall");u(this,"isConfigured");u(this,"sendChannels");u(this,"checkTelephony");u(this,"waitChannels");u(this,"connection");u(this,"connectToServer",async e=>{const{userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,name:a,password:l,isRegisteredUser:g,isDisconnectOnFail:C}=e;return o.logger("connectToServer",e),this.sipConnector.connect({userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,password:l,user:a,register:g}).then(S=>(o.logger("connectToServer then"),{ua:S,isSuccessful:!0})).catch(async S=>(o.logger("connectToServer catch: error",S),C===!0?this.sipConnector.disconnect().then(()=>x(S)).catch(()=>x(S)):x(S)))});u(this,"callToServer",async e=>{const{conference:t,mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,simulcastEncodings:a,degradationPreference:l,sendEncodings:g,offerToReceiveAudio:C,offerToReceiveVideo:S,directionVideo:I,directionAudio:F,setRemoteStreams:f,onBeforeProgressCall:p,onSuccessProgressCall:m,onEnterPurgatory:h,onEnterConference:E,onFailProgressCall:y,onFinishProgressCall:T,onEndedCall:M}=e,_=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:f}),v=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:_}),O=D({degradationPreference:l},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("callToServer",e);const N=async()=>(o.logger("startCall"),this.sipConnector.call({mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,offerToReceiveAudio:C,offerToReceiveVideo:S,directionVideo:I,directionAudio:F,sendEncodings:B({mediaStream:s,simulcastEncodings:a,sendEncodings:g}),number:t,onAddedTransceiver:O,ontrack:v}));let b=!1,A;const P=(o.logger("subscribeEnterConference: onEnterConference",E),h??E?this.sipConnector.onSession("enterRoom",({room:d})=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:b}),A=d,w(A)?h&&h():E&&E({isSuccessProgressCall:b})}):()=>{}),k=d=>(o.logger("onSuccess"),b=!0,_(),m&&m({isPurgatory:w(A)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),M&&M()}),d),U=d=>{throw o.logger("onFail"),y&&y(),P(),d},V=()=>{o.logger("onFinish"),T&&T()};return o.logger("onBeforeProgressCall"),p&&p(t),N().then(k).catch(d=>U(d)).finally(V)});u(this,"disconnectFromServer",async()=>this.sipConnector.disconnect().then(()=>(o.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(e=>(o.logger("disconnectFromServer: catch",e),{isSuccessful:!1})));u(this,"answerIncomingCall",async e=>{const{mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,simulcastEncodings:c,degradationPreference:a,sendEncodings:l,offerToReceiveAudio:g,offerToReceiveVideo:C,directionVideo:S,directionAudio:I,setRemoteStreams:F,onBeforeProgressCall:f,onSuccessProgressCall:p,onEnterPurgatory:m,onEnterConference:h,onFailProgressCall:E,onFinishProgressCall:y,onEndedCall:T}=e,M=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:F}),_=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:M}),v=D({degradationPreference:a},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("answerIncomingCall",e);const O=async()=>this.sipConnector.answerToIncomingCall({mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,offerToReceiveAudio:g,offerToReceiveVideo:C,directionVideo:S,directionAudio:I,sendEncodings:B({mediaStream:t,simulcastEncodings:c,sendEncodings:l}),onAddedTransceiver:v,ontrack:_}),N=()=>{const{remoteCallerData:d}=this.sipConnector;return d.incomingNumber};let b=!1,A;const P=(o.logger("subscribeEnterConference: onEnterConference",h),m??h?this.sipConnector.onSession("enterRoom",d=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:b}),A=d,w(A)?m&&m():h&&h({isSuccessProgressCall:b})}):()=>{}),k=d=>(o.logger("onSuccess"),b=!0,M(),p&&p({isPurgatory:w(A)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),T&&T()}),d),U=d=>{throw o.logger("onFail"),E&&E(),P(),d},V=()=>{o.logger("onFinish"),y&&y()};if(o.logger("onBeforeProgressCall"),f){const d=N();f(d)}return O().then(k).catch(d=>U(d)).finally(V)});u(this,"updatePresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:a,preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:g})=>{const C=D({degradationPreference:c},{preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:g});return o.logger("updatePresentation"),this.sipConnector.updatePresentation(e,{isP2P:t,maxBitrate:s,contentHint:r,sendEncodings:B({mediaStream:e,simulcastEncodings:i,sendEncodings:a}),onAddedTransceiver:C})});u(this,"startPresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:a,preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:g},C)=>{const S=D({degradationPreference:c},{preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:g});return o.logger("startPresentation"),this.sipConnector.startPresentation(e,{isP2P:t,maxBitrate:s,contentHint:r,sendEncodings:B({mediaStream:e,simulcastEncodings:i,sendEncodings:a}),onAddedTransceiver:S},C)});u(this,"stopShareSipConnector",async({isP2P:e=!1}={})=>(o.logger("stopShareSipConnector"),this.sipConnector.stopPresentation({isP2P:e}).catch(t=>{o.logger(t)})));u(this,"sendRefusalToTurnOnMic",async()=>{if(this.sipConnector.isCallActive)return o.logger("sendRefusalToTurnOnMic"),this.sipConnector.sendRefusalToTurnOnMic().catch(e=>{o.logger("sendRefusalToTurnOnMic: error",e)})});u(this,"sendRefusalToTurnOnCam",async()=>{if(this.sipConnector.isCallActive)return o.logger("sendRefusalToTurnOnCam"),this.sipConnector.sendRefusalToTurnOnCam().catch(e=>{o.logger("sendRefusalToTurnOnCam: error",e)})});u(this,"sendMediaState",async({isEnabledCam:e,isEnabledMic:t})=>{if(this.sipConnector.isCallActive)return o.logger("sendMediaState"),this.sipConnector.sendMediaState({cam:e,mic:t})});u(this,"replaceMediaStream",async(e,{deleteExisting:t,addMissing:s,forceRenegotiation:r,contentHint:i,simulcastEncodings:c,degradationPreference:a,sendEncodings:l}={})=>{const g=D({degradationPreference:a},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});return o.logger("replaceMediaStream"),this.sipConnector.replaceMediaStream(e,{deleteExisting:t,addMissing:s,forceRenegotiation:r,contentHint:i,sendEncodings:B({mediaStream:e,simulcastEncodings:c,sendEncodings:l}),onAddedTransceiver:g})});u(this,"askPermissionToEnableCam",async()=>{if(this.sipConnector.isCallActive)return o.logger("askPermissionToEnableCam"),this.sipConnector.askPermissionToEnableCam()});u(this,"resolveHandleReadyRemoteStreamsDebounced",({onReadyRemoteStreams:e})=>ce.debounce(()=>{const t=this.sipConnector.getRemoteStreams();o.logger("remoteStreams",t),t&&e(t)},200));u(this,"resolveHandleReadyRemoteStreams",({onReadyRemoteStreams:e})=>({track:t})=>{Ye(t)&&e()});u(this,"getRemoteStreams",()=>(o.logger("getRemoteStreams"),this.sipConnector.getRemoteStreams()));u(this,"onUseLicense",e=>(o.logger("onUseLicense"),this.sipConnector.onSession("useLicense",e)));u(this,"onMustStopPresentation",e=>(o.logger("onMustStopPresentation"),this.sipConnector.onSession("mustStopPresentation",e)));u(this,"onMoveToSpectators",e=>(o.logger("onMoveToSpectators"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS,e)));u(this,"onMoveToParticipants",e=>(o.logger("onMoveToParticipants"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS,e)));return this.preferredMimeTypesVideoCodecs=t,this.excludeMimeTypesVideoCodecs=s,this.sipConnector=e,new Proxy(this,{get:(r,i,c)=>{if(typeof i=="string"&&ze.has(i)&&i in this.sipConnector){const l=Reflect.get(this.sipConnector,i,this.sipConnector);return typeof l=="function"?l.bind(this.sipConnector):l}const a=Reflect.get(r,i,c);return typeof a=="function"?a.bind(r):a}})}}exports.EEventsMainCAM=o.EEventsMainCAM;exports.EEventsMic=o.EEventsMic;exports.EEventsSyncMediaState=o.EEventsSyncMediaState;exports.EMimeTypesVideoCodecs=o.EMimeTypesVideoCodecs;exports.EUseLicense=o.EUseLicense;exports.causes=o.causes;exports.constants=o.constants;exports.default=o.SipConnector;exports.disableDebug=o.disableDebug;exports.enableDebug=o.enableDebug;exports.eventNames=o.eventNames;exports.hasCanceledCallError=o.hasCanceledCallError;exports.setParametersToSender=o.setParametersToSender;exports.debug=ae;exports.SipConnectorFacade=Qe;exports.getCodecFromSender=G;exports.resolveVideoSendingBalancer=He;exports.tools=_e;
1
+ "use strict";var ne=Object.defineProperty;var te=(n,e,t)=>e in n?ne(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var u=(n,e,t)=>te(n,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("./SipConnector-CE4F15z6.cjs"),se=require("sequent-promises"),oe=require("stack-promises"),re=require("@krivega/cancelable-promise"),ie=require("repeated-calls"),ce=require("ts-debounce"),ae=require("debug"),$=n=>{const{url:e,cause:t}=n;let s=e;return(t===o.BAD_MEDIA_DESCRIPTION||t===o.NOT_FOUND)&&(s=`${n.message.to.uri.user}@${n.message.to.uri.host}`),s};var j=(n=>(n.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",n.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",n.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",n.NOT_FOUND_ERROR="NOT_FOUND_ERROR",n.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",n.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",n))(j||{});const ue=(n=new Error)=>{var r;const{cause:e,socket:t}=n;let s="CONNECT_SERVER_FAILED";switch(e){case"Forbidden":{s="WRONG_USER_OR_PASSWORD";break}case o.BAD_MEDIA_DESCRIPTION:{s="BAD_MEDIA_ERROR";break}case o.NOT_FOUND:{s="NOT_FOUND_ERROR";break}default:t&&((r=t==null?void 0:t._ws)==null?void 0:r.readyState)===3?s="WS_CONNECTION_FAILED":$(n)&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},le=n=>{let e="";try{e=JSON.stringify(n)}catch(t){o.logger("failed to stringify message",t)}return e},de=(n=new Error)=>{const{code:e,cause:t,message:s}=n,r=$(n),i={code:"",cause:"",message:""};return typeof s=="object"&&s!==null?i.message=le(s):s&&(i.message=String(s)),r&&(i.link=r),e&&(i.code=e),t&&(i.cause=t),i},ge=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:j,getLinkError:$,getTypeFromError:ue,getValuesFromError:de},Symbol.toStringTag,{value:"Module"})),Se=({sessionId:n,remoteAddress:e,isMutedAudio:t,isMutedVideo:s,isRegistered:r,isPresentationCall:i})=>{const c=[],a=t?"0":"1",l=s?"0":"1";return c.push(`X-Vinteo-Mic-State: ${a}`,`X-Vinteo-MainCam-State: ${l}`),r||c.push("X-Vinteo-Purgatory-Call: yes"),n&&c.push(`X-Vinteo-Session: ${n}`),i&&c.push("X-Vinteo-Presentation-Call: yes"),e&&c.push(`X-Vinteo-Remote: ${e}`),c},Ce="[@*!|]",fe="_",me=n=>{let e=n;return e=e.replaceAll(new RegExp(Ce,"g"),fe),e},he=({appName:n,appVersion:e,browserName:t,browserVersion:s})=>{const i=`${me(n)} ${e}`;return`ChromeNew - ${t?`${t} ${s}, ${i}`:i}`},Re=({isUnifiedSdpSemantic:n,appVersion:e,browserName:t,browserVersion:s,appName:r})=>n?he({appVersion:e,browserName:t,browserVersion:s,appName:r}):"Chrome",W="purgatory",w=n=>n===W,pe=n=>e=>[...e].map(s=>async()=>n(s)),Ee=async({accumulatedKeys:n,sendKey:e,canRunTask:t})=>{const r=pe(e)(n);return se.sequentPromises(r,t)},ye=n=>t=>(o.logger("onStartMainCam"),n.onSession("admin-start-main-cam",t)),Te=n=>t=>(o.logger("onStartMic"),n.onSession("admin-start-mic",t)),Me=n=>t=>(o.logger("onStopMainCam"),n.onSession("admin-stop-main-cam",t)),be=n=>t=>(o.logger("onStopMic"),n.onSession("admin-stop-mic",t)),Ae=({sipConnector:n})=>{const e=(f,p)=>({isSyncForced:m=!1})=>{if(m){f();return}p()},t=ye(n),s=Me(n),r=Te(n),i=be(n);let c=()=>{},a=()=>{},l=()=>{},g=()=>{};const C=({onStartMainCamForced:f,onStartMainCamNotForced:p,onStopMainCamForced:m,onStopMainCamNotForced:h,onStartMicForced:E,onStartMicNotForced:y,onStopMicForced:T,onStopMicNotForced:M})=>{const _=e(f,p);c=t(_);const v=e(m,h);a=s(v);const O=e(E,y);l=r(O);const N=e(T,M);g=i(N)},S=()=>{c(),a(),l(),g()};return{start:f=>{C(f)},stop:()=>{S()}}},_e=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:W,createSyncMediaState:Ae,error:ge,getExtraHeaders:Se,getUserAgent:Re,hasPurgatory:w,sendDTMFAccumulated:Ee},Symbol.toStringTag,{value:"Module"})),ve=n=>[...n.keys()].map(e=>n.get(e)),Oe=(n,e)=>ve(n).find(t=>t.type===e),G=async n=>n.getStats().then(e=>{const t=Oe(e,"codec");return t==null?void 0:t.mimeType}),Ne=n=>n.find(e=>{var t;return((t=e==null?void 0:e.track)==null?void 0:t.kind)==="video"}),K=(n,e)=>n!==void 0&&e!==void 0&&n.toLowerCase().includes(e.toLowerCase()),Pe=1e6,R=n=>n*Pe,Y=R(.06),Be=R(4),De=n=>n<=64?Y:n<=128?R(.12):n<=256?R(.25):n<=384?R(.32):n<=426?R(.38):n<=640?R(.5):n<=848?R(.7):n<=1280?R(1):n<=1920?R(2):Be,we="av1",Ie=n=>K(n,we),Fe=.6,z=(n,e)=>Ie(e)?n*Fe:n,ke=n=>z(Y,n),Q=(n,e)=>{const t=De(n);return z(t,e)},Ue=1,J=({videoTrack:n,targetSize:e,codec:t})=>{const s=n.getSettings(),r=s.width,i=s.height,c=r/e.width,a=i/e.height,l=Math.max(c,a,Ue),g=Q(e.width,t);return{scaleResolutionDownBy:l,maxBitrate:g}},Z=oe.createStackPromises(),Ve=async()=>Z().catch(n=>{o.logger("videoSendingBalancer: error",n)}),Le=async n=>(Z.add(n),Ve()),q=async({sender:n,scaleResolutionDownBy:e,maxBitrate:t,onSetParameters:s})=>Le(async()=>o.setEncodingsToSender(n,{scaleResolutionDownBy:e,maxBitrate:t},s)),xe=async({sender:n,codec:e},t)=>{const r=ke(e);return q({sender:n,maxBitrate:r,onSetParameters:t,scaleResolutionDownBy:200})},L=async({sender:n,videoTrack:e,codec:t},s)=>{const c=e.getSettings().width,a=Q(c,t);return q({sender:n,maxBitrate:a,onSetParameters:s,scaleResolutionDownBy:1})},$e=async({sender:n,videoTrack:e,resolution:t,codec:s},r)=>{const[i,c]=t.split("x"),{maxBitrate:a,scaleResolutionDownBy:l}=J({videoTrack:e,codec:s,targetSize:{width:Number(i),height:Number(c)}});return q({sender:n,maxBitrate:a,onSetParameters:r,scaleResolutionDownBy:l})},qe=async({mainCam:n,resolutionMainCam:e,sender:t,videoTrack:s,codec:r},i)=>{switch(n){case o.EEventsMainCAM.PAUSE_MAIN_CAM:return xe({sender:t,codec:r},i);case o.EEventsMainCAM.RESUME_MAIN_CAM:return L({sender:t,videoTrack:s,codec:r},i);case o.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return e!==void 0?$e({sender:t,videoTrack:s,codec:r,resolution:e},i):L({sender:t,videoTrack:s,codec:r},i);default:return L({sender:t,videoTrack:s,codec:r},i)}},H={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},X=async({mainCam:n,resolutionMainCam:e,connection:t,onSetParameters:s,ignoreForCodec:r})=>{const i=t.getSenders(),c=Ne(i);if(!(c!=null&&c.track))return H;const a=await G(c);return K(a,r)?H:qe({mainCam:n,resolutionMainCam:e,sender:c,codec:a,videoTrack:c.track},s)},He=(n,{ignoreForCodec:e,onSetParameters:t}={})=>{const s=async()=>{const{connection:l}=n;if(!l)throw new Error("connection is not exist");return X({connection:l,onSetParameters:t,ignoreForCodec:e})};let r=s;const i=async l=>(r=async()=>{const{mainCam:g,resolutionMainCam:C}=l,{connection:S}=n;if(!S)throw new Error("connection is not exist");return X({mainCam:g,resolutionMainCam:C,connection:S,onSetParameters:t,ignoreForCodec:e})},r());return{subscribe:()=>{n.onSession("main-cam-control",i)},unsubscribe:()=>{n.offSession("main-cam-control",i)},balanceByTrack:s,resetMainCamControl(){r=s},async reBalance(){return r()}}},Xe=n=>n.getVideoTracks()[0],B=({mediaStream:n,simulcastEncodings:e,sendEncodings:t})=>{if(e&&e.length>0){const s=t??[],r=Xe(n);return e.forEach((i,c)=>{const a=s[c]??{};a.active=!0,i.rid!==void 0&&(a.rid=i.rid),i.scalabilityMode!==void 0&&(a.scalabilityMode=i.scalabilityMode);const{maxBitrate:l,scaleResolutionDownBy:g}=J({videoTrack:r,targetSize:{width:i.width,height:i.height}});a.maxBitrate=l,a.scaleResolutionDownBy=g,s[c]=a}),s}return t},je=(n,e)=>[...n,...e].filter((r,i,c)=>i===c.findIndex(a=>a.clockRate===r.clockRate&&a.mimeType===r.mimeType&&a.channels===r.channels&&a.sdpFmtpLine===r.sdpFmtpLine)),We=n=>{const e=RTCRtpSender.getCapabilities(n),t=RTCRtpReceiver.getCapabilities(n),s=e===null?[]:e.codecs,r=t===null?[]:t.codecs;return je(s,r)},Ge=(n,e)=>e===void 0||e.length===0?n:n.sort((t,s)=>{const r=e.indexOf(t.mimeType),i=e.indexOf(s.mimeType),c=r===-1?Number.MAX_VALUE:r,a=i===-1?Number.MAX_VALUE:i;return c-a}),Ke=(n,e)=>e===void 0||e.length===0?n:n.filter(t=>!e.includes(t.mimeType)),D=(n,{preferredMimeTypesVideoCodecs:e,excludeMimeTypesVideoCodecs:t})=>async s=>{var r;if(typeof s.setCodecPreferences=="function"&&((r=s.sender.track)==null?void 0:r.kind)==="video"&&(e!==void 0&&(e==null?void 0:e.length)>0||t!==void 0&&(t==null?void 0:t.length)>0)){const i=We("video"),c=Ke(i,t),a=Ge(c,e);s.setCodecPreferences(a)}Object.keys(n).length>0&&await o.setParametersToSender(s.sender,n)},x=n=>{if(!re.isCanceledError(n)&&!ie.hasCanceledError(n))throw n;return{isSuccessful:!1}},Ye=({kind:n,readyState:e})=>n==="video"&&e==="live",ze=new Set(["on","once","onceRace","wait","off","onSession","onceSession","onceRaceSession","waitSession","offSession","sendDTMF","hangUp","declineToIncomingCall","sendChannels","checkTelephony","waitChannels","ping","connection","isConfigured","isRegistered"]);class Qe{constructor(e,{preferredMimeTypesVideoCodecs:t,excludeMimeTypesVideoCodecs:s}={}){u(this,"sipConnector");u(this,"preferredMimeTypesVideoCodecs");u(this,"excludeMimeTypesVideoCodecs");u(this,"on");u(this,"once");u(this,"onceRace");u(this,"wait");u(this,"off");u(this,"onSession");u(this,"onceSession");u(this,"onceRaceSession");u(this,"waitSession");u(this,"offSession");u(this,"sendDTMF");u(this,"hangUp");u(this,"declineToIncomingCall");u(this,"sendChannels");u(this,"checkTelephony");u(this,"waitChannels");u(this,"ping");u(this,"connection");u(this,"isConfigured");u(this,"isRegistered");u(this,"connectToServer",async e=>{const{userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,name:a,password:l,isRegisteredUser:g,isDisconnectOnFail:C}=e;return o.logger("connectToServer",e),this.sipConnector.connect({userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,password:l,user:a,register:g}).then(S=>(o.logger("connectToServer then"),{ua:S,isSuccessful:!0})).catch(async S=>(o.logger("connectToServer catch: error",S),C===!0?this.sipConnector.disconnect().then(()=>x(S)).catch(()=>x(S)):x(S)))});u(this,"callToServer",async e=>{const{conference:t,mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,simulcastEncodings:a,degradationPreference:l,sendEncodings:g,offerToReceiveAudio:C,offerToReceiveVideo:S,directionVideo:I,directionAudio:F,setRemoteStreams:f,onBeforeProgressCall:p,onSuccessProgressCall:m,onEnterPurgatory:h,onEnterConference:E,onFailProgressCall:y,onFinishProgressCall:T,onEndedCall:M}=e,_=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:f}),v=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:_}),O=D({degradationPreference:l},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("callToServer",e);const N=async()=>(o.logger("startCall"),this.sipConnector.call({mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,offerToReceiveAudio:C,offerToReceiveVideo:S,directionVideo:I,directionAudio:F,sendEncodings:B({mediaStream:s,simulcastEncodings:a,sendEncodings:g}),number:t,onAddedTransceiver:O,ontrack:v}));let b=!1,A;const P=(o.logger("subscribeEnterConference: onEnterConference",E),h??E?this.sipConnector.onSession("enterRoom",({room:d})=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:b}),A=d,w(A)?h&&h():E&&E({isSuccessProgressCall:b})}):()=>{}),k=d=>(o.logger("onSuccess"),b=!0,_(),m&&m({isPurgatory:w(A)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),M&&M()}),d),U=d=>{throw o.logger("onFail"),y&&y(),P(),d},V=()=>{o.logger("onFinish"),T&&T()};return o.logger("onBeforeProgressCall"),p&&p(t),N().then(k).catch(d=>U(d)).finally(V)});u(this,"disconnectFromServer",async()=>this.sipConnector.disconnect().then(()=>(o.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(e=>(o.logger("disconnectFromServer: catch",e),{isSuccessful:!1})));u(this,"answerIncomingCall",async e=>{const{mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,simulcastEncodings:c,degradationPreference:a,sendEncodings:l,offerToReceiveAudio:g,offerToReceiveVideo:C,directionVideo:S,directionAudio:I,setRemoteStreams:F,onBeforeProgressCall:f,onSuccessProgressCall:p,onEnterPurgatory:m,onEnterConference:h,onFailProgressCall:E,onFinishProgressCall:y,onEndedCall:T}=e,M=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:F}),_=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:M}),v=D({degradationPreference:a},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("answerIncomingCall",e);const O=async()=>this.sipConnector.answerToIncomingCall({mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,offerToReceiveAudio:g,offerToReceiveVideo:C,directionVideo:S,directionAudio:I,sendEncodings:B({mediaStream:t,simulcastEncodings:c,sendEncodings:l}),onAddedTransceiver:v,ontrack:_}),N=()=>{const{remoteCallerData:d}=this.sipConnector;return d.incomingNumber};let b=!1,A;const P=(o.logger("subscribeEnterConference: onEnterConference",h),m??h?this.sipConnector.onSession("enterRoom",d=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:b}),A=d,w(A)?m&&m():h&&h({isSuccessProgressCall:b})}):()=>{}),k=d=>(o.logger("onSuccess"),b=!0,M(),p&&p({isPurgatory:w(A)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),T&&T()}),d),U=d=>{throw o.logger("onFail"),E&&E(),P(),d},V=()=>{o.logger("onFinish"),y&&y()};if(o.logger("onBeforeProgressCall"),f){const d=N();f(d)}return O().then(k).catch(d=>U(d)).finally(V)});u(this,"updatePresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:a,preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:g})=>{const C=D({degradationPreference:c},{preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:g});return o.logger("updatePresentation"),this.sipConnector.updatePresentation(e,{isP2P:t,maxBitrate:s,contentHint:r,sendEncodings:B({mediaStream:e,simulcastEncodings:i,sendEncodings:a}),onAddedTransceiver:C})});u(this,"startPresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:a,preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:g},C)=>{const S=D({degradationPreference:c},{preferredMimeTypesVideoCodecs:l,excludeMimeTypesVideoCodecs:g});return o.logger("startPresentation"),this.sipConnector.startPresentation(e,{isP2P:t,maxBitrate:s,contentHint:r,sendEncodings:B({mediaStream:e,simulcastEncodings:i,sendEncodings:a}),onAddedTransceiver:S},C)});u(this,"stopShareSipConnector",async({isP2P:e=!1}={})=>(o.logger("stopShareSipConnector"),this.sipConnector.stopPresentation({isP2P:e}).catch(t=>{o.logger(t)})));u(this,"sendRefusalToTurnOnMic",async()=>{if(this.sipConnector.isCallActive)return o.logger("sendRefusalToTurnOnMic"),this.sipConnector.sendRefusalToTurnOnMic().catch(e=>{o.logger("sendRefusalToTurnOnMic: error",e)})});u(this,"sendRefusalToTurnOnCam",async()=>{if(this.sipConnector.isCallActive)return o.logger("sendRefusalToTurnOnCam"),this.sipConnector.sendRefusalToTurnOnCam().catch(e=>{o.logger("sendRefusalToTurnOnCam: error",e)})});u(this,"sendMediaState",async({isEnabledCam:e,isEnabledMic:t})=>{if(this.sipConnector.isCallActive)return o.logger("sendMediaState"),this.sipConnector.sendMediaState({cam:e,mic:t})});u(this,"replaceMediaStream",async(e,{deleteExisting:t,addMissing:s,forceRenegotiation:r,contentHint:i,simulcastEncodings:c,degradationPreference:a,sendEncodings:l}={})=>{const g=D({degradationPreference:a},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});return o.logger("replaceMediaStream"),this.sipConnector.replaceMediaStream(e,{deleteExisting:t,addMissing:s,forceRenegotiation:r,contentHint:i,sendEncodings:B({mediaStream:e,simulcastEncodings:c,sendEncodings:l}),onAddedTransceiver:g})});u(this,"askPermissionToEnableCam",async()=>{if(this.sipConnector.isCallActive)return o.logger("askPermissionToEnableCam"),this.sipConnector.askPermissionToEnableCam()});u(this,"resolveHandleReadyRemoteStreamsDebounced",({onReadyRemoteStreams:e})=>ce.debounce(()=>{const t=this.sipConnector.getRemoteStreams();o.logger("remoteStreams",t),t&&e(t)},200));u(this,"resolveHandleReadyRemoteStreams",({onReadyRemoteStreams:e})=>({track:t})=>{Ye(t)&&e()});u(this,"getRemoteStreams",()=>(o.logger("getRemoteStreams"),this.sipConnector.getRemoteStreams()));u(this,"onUseLicense",e=>(o.logger("onUseLicense"),this.sipConnector.onSession("useLicense",e)));u(this,"onMustStopPresentation",e=>(o.logger("onMustStopPresentation"),this.sipConnector.onSession("mustStopPresentation",e)));u(this,"onMoveToSpectators",e=>(o.logger("onMoveToSpectators"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS,e)));u(this,"onMoveToParticipants",e=>(o.logger("onMoveToParticipants"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS,e)));return this.preferredMimeTypesVideoCodecs=t,this.excludeMimeTypesVideoCodecs=s,this.sipConnector=e,new Proxy(this,{get:(r,i,c)=>{if(typeof i=="string"&&ze.has(i)&&i in this.sipConnector){const l=Reflect.get(this.sipConnector,i,this.sipConnector);return typeof l=="function"?l.bind(this.sipConnector):l}const a=Reflect.get(r,i,c);return typeof a=="function"?a.bind(r):a}})}}exports.EEventsMainCAM=o.EEventsMainCAM;exports.EEventsMic=o.EEventsMic;exports.EEventsSyncMediaState=o.EEventsSyncMediaState;exports.EMimeTypesVideoCodecs=o.EMimeTypesVideoCodecs;exports.EUseLicense=o.EUseLicense;exports.causes=o.causes;exports.constants=o.constants;exports.default=o.SipConnector;exports.disableDebug=o.disableDebug;exports.enableDebug=o.enableDebug;exports.eventNames=o.eventNames;exports.hasCanceledCallError=o.hasCanceledCallError;exports.setParametersToSender=o.setParametersToSender;exports.debug=ae;exports.SipConnectorFacade=Qe;exports.getCodecFromSender=G;exports.resolveVideoSendingBalancer=He;exports.tools=_e;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var se = Object.defineProperty;
2
2
  var oe = (n, e, t) => e in n ? se(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var u = (n, e, t) => oe(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { B as G, N as K, l as a, E as x, s as re, a as ie, P as ce, b as ae, S as sn } from "./SipConnector-B4xLnl6L.js";
3
+ var a = (n, e, t) => oe(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { B as G, N as K, l as u, E as x, s as re, a as ie, P as ce, b as ae, S as sn } from "./SipConnector-B4xLnl6L.js";
5
5
  import { i as mn, j as hn, m as Rn, k as gn, c as pn, d as yn, f as En, g as Tn, e as bn, h as Mn } from "./SipConnector-B4xLnl6L.js";
6
6
  import { sequentPromises as ue } from "sequent-promises";
7
7
  import { createStackPromises as le } from "stack-promises";
@@ -41,7 +41,7 @@ const Ce = (n = new Error()) => {
41
41
  try {
42
42
  e = JSON.stringify(n);
43
43
  } catch (t) {
44
- a("failed to stringify message", t);
44
+ u("failed to stringify message", t);
45
45
  }
46
46
  return e;
47
47
  }, he = (n = new Error()) => {
@@ -87,7 +87,7 @@ const Ce = (n = new Error()) => {
87
87
  }) => {
88
88
  const o = Me(e)(n);
89
89
  return ue(o, t);
90
- }, _e = (n) => (t) => (a("onStartMainCam"), n.onSession("admin-start-main-cam", t)), ve = (n) => (t) => (a("onStartMic"), n.onSession("admin-start-mic", t)), Oe = (n) => (t) => (a("onStopMainCam"), n.onSession("admin-stop-main-cam", t)), Ne = (n) => (t) => (a("onStopMic"), n.onSession("admin-stop-mic", t)), we = ({ sipConnector: n }) => {
90
+ }, _e = (n) => (t) => (u("onStartMainCam"), n.onSession("admin-start-main-cam", t)), ve = (n) => (t) => (u("onStartMic"), n.onSession("admin-start-mic", t)), Oe = (n) => (t) => (u("onStopMainCam"), n.onSession("admin-stop-main-cam", t)), Ne = (n) => (t) => (u("onStopMic"), n.onSession("admin-stop-mic", t)), we = ({ sipConnector: n }) => {
91
91
  const e = (m, p) => ({ isSyncForced: h = !1 }) => {
92
92
  if (h) {
93
93
  m();
@@ -161,7 +161,7 @@ const Ce = (n = new Error()) => {
161
161
  const s = n.getSettings(), o = s.width, r = s.height, i = o / e.width, c = r / e.height, l = Math.max(i, c, He), S = Z(e.width, t);
162
162
  return { scaleResolutionDownBy: l, maxBitrate: S };
163
163
  }, ne = le(), Xe = async () => ne().catch((n) => {
164
- a("videoSendingBalancer: error", n);
164
+ u("videoSendingBalancer: error", n);
165
165
  }), je = async (n) => (ne.add(n), Xe()), X = async ({
166
166
  sender: n,
167
167
  scaleResolutionDownBy: e,
@@ -354,57 +354,63 @@ const Ce = (n = new Error()) => {
354
354
  "sendDTMF",
355
355
  "hangUp",
356
356
  "declineToIncomingCall",
357
- "isConfigured",
358
357
  "sendChannels",
359
358
  "checkTelephony",
360
359
  "waitChannels",
361
- "connection"
360
+ "ping",
361
+ "connection",
362
+ "isConfigured",
363
+ "isRegistered"
362
364
  ]);
363
365
  class Sn {
364
366
  constructor(e, {
365
367
  preferredMimeTypesVideoCodecs: t,
366
368
  excludeMimeTypesVideoCodecs: s
367
369
  } = {}) {
368
- u(this, "sipConnector");
369
- u(this, "preferredMimeTypesVideoCodecs");
370
- u(this, "excludeMimeTypesVideoCodecs");
370
+ a(this, "sipConnector");
371
+ a(this, "preferredMimeTypesVideoCodecs");
372
+ a(this, "excludeMimeTypesVideoCodecs");
371
373
  // @ts-expect-error: proxy method
372
- u(this, "on");
374
+ a(this, "on");
373
375
  // @ts-expect-error: proxy method
374
- u(this, "once");
376
+ a(this, "once");
375
377
  // @ts-expect-error: proxy method
376
- u(this, "onceRace");
378
+ a(this, "onceRace");
377
379
  // @ts-expect-error: proxy method
378
- u(this, "wait");
380
+ a(this, "wait");
379
381
  // @ts-expect-error: proxy method
380
- u(this, "off");
382
+ a(this, "off");
381
383
  // @ts-expect-error: proxy method
382
- u(this, "onSession");
384
+ a(this, "onSession");
383
385
  // @ts-expect-error: proxy method
384
- u(this, "onceSession");
386
+ a(this, "onceSession");
385
387
  // @ts-expect-error: proxy method
386
- u(this, "onceRaceSession");
388
+ a(this, "onceRaceSession");
387
389
  // @ts-expect-error: proxy method
388
- u(this, "waitSession");
390
+ a(this, "waitSession");
389
391
  // @ts-expect-error: proxy method
390
- u(this, "offSession");
392
+ a(this, "offSession");
391
393
  // @ts-expect-error: proxy method
392
- u(this, "sendDTMF");
394
+ a(this, "sendDTMF");
393
395
  // @ts-expect-error: proxy method
394
- u(this, "hangUp");
396
+ a(this, "hangUp");
395
397
  // @ts-expect-error: proxy method
396
- u(this, "declineToIncomingCall");
398
+ a(this, "declineToIncomingCall");
397
399
  // @ts-expect-error: proxy method
398
- u(this, "isConfigured");
400
+ a(this, "sendChannels");
399
401
  // @ts-expect-error: proxy method
400
- u(this, "sendChannels");
402
+ a(this, "checkTelephony");
401
403
  // @ts-expect-error: proxy method
402
- u(this, "checkTelephony");
404
+ a(this, "waitChannels");
403
405
  // @ts-expect-error: proxy method
404
- u(this, "waitChannels");
406
+ a(this, "ping");
405
407
  // proxy method
406
- u(this, "connection");
407
- u(this, "connectToServer", async (e) => {
408
+ a(this, "connection");
409
+ // @ts-expect-error: proxy method
410
+ a(this, "isConfigured");
411
+ // @ts-expect-error: proxy method
412
+ a(this, "isRegistered");
413
+ a(this, "connectToServer", async (e) => {
408
414
  const {
409
415
  userAgent: t,
410
416
  sipWebSocketServerURL: s,
@@ -416,7 +422,7 @@ class Sn {
416
422
  isRegisteredUser: S,
417
423
  isDisconnectOnFail: C
418
424
  } = e;
419
- return a("connectToServer", e), this.sipConnector.connect({
425
+ return u("connectToServer", e), this.sipConnector.connect({
420
426
  userAgent: t,
421
427
  sipWebSocketServerURL: s,
422
428
  sipServerUrl: o,
@@ -425,9 +431,9 @@ class Sn {
425
431
  password: l,
426
432
  user: c,
427
433
  register: S
428
- }).then((f) => (a("connectToServer then"), { ua: f, isSuccessful: !0 })).catch(async (f) => (a("connectToServer catch: error", f), C === !0 ? this.sipConnector.disconnect().then(() => $(f)).catch(() => $(f)) : $(f)));
434
+ }).then((f) => (u("connectToServer then"), { ua: f, isSuccessful: !0 })).catch(async (f) => (u("connectToServer catch: error", f), C === !0 ? this.sipConnector.disconnect().then(() => $(f)).catch(() => $(f)) : $(f)));
429
435
  });
430
- u(this, "callToServer", async (e) => {
436
+ a(this, "callToServer", async (e) => {
431
437
  const {
432
438
  conference: t,
433
439
  mediaStream: s,
@@ -462,8 +468,8 @@ class Sn {
462
468
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
463
469
  }
464
470
  );
465
- a("callToServer", e);
466
- const N = async () => (a("startCall"), this.sipConnector.call({
471
+ u("callToServer", e);
472
+ const N = async () => (u("startCall"), this.sipConnector.call({
467
473
  mediaStream: s,
468
474
  extraHeaders: o,
469
475
  iceServers: r,
@@ -482,20 +488,20 @@ class Sn {
482
488
  ontrack: v
483
489
  }));
484
490
  let M = !1, A;
485
- const w = (a("subscribeEnterConference: onEnterConference", y), R ?? y ? this.sipConnector.onSession("enterRoom", ({ room: d }) => {
486
- a("enterRoom", { _room: d, isSuccessProgressCall: M }), A = d, D(A) ? R && R() : y && y({ isSuccessProgressCall: M });
491
+ const w = (u("subscribeEnterConference: onEnterConference", y), R ?? y ? this.sipConnector.onSession("enterRoom", ({ room: d }) => {
492
+ u("enterRoom", { _room: d, isSuccessProgressCall: M }), A = d, D(A) ? R && R() : y && y({ isSuccessProgressCall: M });
487
493
  }) : () => {
488
- }), k = (d) => (a("onSuccess"), M = !0, _(), h && h({ isPurgatory: D(A) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
494
+ }), k = (d) => (u("onSuccess"), M = !0, _(), h && h({ isPurgatory: D(A) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
489
495
  w(), b && b();
490
496
  }), d), U = (d) => {
491
- throw a("onFail"), E && E(), w(), d;
497
+ throw u("onFail"), E && E(), w(), d;
492
498
  }, V = () => {
493
- a("onFinish"), T && T();
499
+ u("onFinish"), T && T();
494
500
  };
495
- return a("onBeforeProgressCall"), p && p(t), N().then(k).catch((d) => U(d)).finally(V);
501
+ return u("onBeforeProgressCall"), p && p(t), N().then(k).catch((d) => U(d)).finally(V);
496
502
  });
497
- u(this, "disconnectFromServer", async () => this.sipConnector.disconnect().then(() => (a("disconnectFromServer: then"), { isSuccessful: !0 })).catch((e) => (a("disconnectFromServer: catch", e), { isSuccessful: !1 })));
498
- u(this, "answerIncomingCall", async (e) => {
503
+ a(this, "disconnectFromServer", async () => this.sipConnector.disconnect().then(() => (u("disconnectFromServer: then"), { isSuccessful: !0 })).catch((e) => (u("disconnectFromServer: catch", e), { isSuccessful: !1 })));
504
+ a(this, "answerIncomingCall", async (e) => {
499
505
  const {
500
506
  mediaStream: t,
501
507
  extraHeaders: s,
@@ -529,7 +535,7 @@ class Sn {
529
535
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
530
536
  }
531
537
  );
532
- a("answerIncomingCall", e);
538
+ u("answerIncomingCall", e);
533
539
  const O = async () => this.sipConnector.answerToIncomingCall({
534
540
  mediaStream: t,
535
541
  extraHeaders: s,
@@ -551,23 +557,23 @@ class Sn {
551
557
  return d.incomingNumber;
552
558
  };
553
559
  let M = !1, A;
554
- const w = (a("subscribeEnterConference: onEnterConference", R), h ?? R ? this.sipConnector.onSession("enterRoom", (d) => {
555
- a("enterRoom", { _room: d, isSuccessProgressCall: M }), A = d, D(A) ? h && h() : R && R({ isSuccessProgressCall: M });
560
+ const w = (u("subscribeEnterConference: onEnterConference", R), h ?? R ? this.sipConnector.onSession("enterRoom", (d) => {
561
+ u("enterRoom", { _room: d, isSuccessProgressCall: M }), A = d, D(A) ? h && h() : R && R({ isSuccessProgressCall: M });
556
562
  }) : () => {
557
- }), k = (d) => (a("onSuccess"), M = !0, b(), p && p({ isPurgatory: D(A) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
563
+ }), k = (d) => (u("onSuccess"), M = !0, b(), p && p({ isPurgatory: D(A) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
558
564
  w(), T && T();
559
565
  }), d), U = (d) => {
560
- throw a("onFail"), y && y(), w(), d;
566
+ throw u("onFail"), y && y(), w(), d;
561
567
  }, V = () => {
562
- a("onFinish"), E && E();
568
+ u("onFinish"), E && E();
563
569
  };
564
- if (a("onBeforeProgressCall"), m) {
570
+ if (u("onBeforeProgressCall"), m) {
565
571
  const d = N();
566
572
  m(d);
567
573
  }
568
574
  return O().then(k).catch((d) => U(d)).finally(V);
569
575
  });
570
- u(this, "updatePresentation", async ({
576
+ a(this, "updatePresentation", async ({
571
577
  mediaStream: e,
572
578
  isP2P: t,
573
579
  maxBitrate: s,
@@ -587,7 +593,7 @@ class Sn {
587
593
  excludeMimeTypesVideoCodecs: S
588
594
  }
589
595
  );
590
- return a("updatePresentation"), this.sipConnector.updatePresentation(e, {
596
+ return u("updatePresentation"), this.sipConnector.updatePresentation(e, {
591
597
  isP2P: t,
592
598
  maxBitrate: s,
593
599
  contentHint: o,
@@ -599,7 +605,7 @@ class Sn {
599
605
  onAddedTransceiver: C
600
606
  });
601
607
  });
602
- u(this, "startPresentation", async ({
608
+ a(this, "startPresentation", async ({
603
609
  mediaStream: e,
604
610
  isP2P: t,
605
611
  maxBitrate: s,
@@ -619,7 +625,7 @@ class Sn {
619
625
  excludeMimeTypesVideoCodecs: S
620
626
  }
621
627
  );
622
- return a("startPresentation"), this.sipConnector.startPresentation(
628
+ return u("startPresentation"), this.sipConnector.startPresentation(
623
629
  e,
624
630
  {
625
631
  isP2P: t,
@@ -635,31 +641,31 @@ class Sn {
635
641
  C
636
642
  );
637
643
  });
638
- u(this, "stopShareSipConnector", async ({ isP2P: e = !1 } = {}) => (a("stopShareSipConnector"), this.sipConnector.stopPresentation({
644
+ a(this, "stopShareSipConnector", async ({ isP2P: e = !1 } = {}) => (u("stopShareSipConnector"), this.sipConnector.stopPresentation({
639
645
  isP2P: e
640
646
  }).catch((t) => {
641
- a(t);
647
+ u(t);
642
648
  })));
643
- u(this, "sendRefusalToTurnOnMic", async () => {
649
+ a(this, "sendRefusalToTurnOnMic", async () => {
644
650
  if (this.sipConnector.isCallActive)
645
- return a("sendRefusalToTurnOnMic"), this.sipConnector.sendRefusalToTurnOnMic().catch((e) => {
646
- a("sendRefusalToTurnOnMic: error", e);
651
+ return u("sendRefusalToTurnOnMic"), this.sipConnector.sendRefusalToTurnOnMic().catch((e) => {
652
+ u("sendRefusalToTurnOnMic: error", e);
647
653
  });
648
654
  });
649
- u(this, "sendRefusalToTurnOnCam", async () => {
655
+ a(this, "sendRefusalToTurnOnCam", async () => {
650
656
  if (this.sipConnector.isCallActive)
651
- return a("sendRefusalToTurnOnCam"), this.sipConnector.sendRefusalToTurnOnCam().catch((e) => {
652
- a("sendRefusalToTurnOnCam: error", e);
657
+ return u("sendRefusalToTurnOnCam"), this.sipConnector.sendRefusalToTurnOnCam().catch((e) => {
658
+ u("sendRefusalToTurnOnCam: error", e);
653
659
  });
654
660
  });
655
- u(this, "sendMediaState", async ({
661
+ a(this, "sendMediaState", async ({
656
662
  isEnabledCam: e,
657
663
  isEnabledMic: t
658
664
  }) => {
659
665
  if (this.sipConnector.isCallActive)
660
- return a("sendMediaState"), this.sipConnector.sendMediaState({ cam: e, mic: t });
666
+ return u("sendMediaState"), this.sipConnector.sendMediaState({ cam: e, mic: t });
661
667
  });
662
- u(this, "replaceMediaStream", async (e, {
668
+ a(this, "replaceMediaStream", async (e, {
663
669
  deleteExisting: t,
664
670
  addMissing: s,
665
671
  forceRenegotiation: o,
@@ -677,7 +683,7 @@ class Sn {
677
683
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
678
684
  }
679
685
  );
680
- return a("replaceMediaStream"), this.sipConnector.replaceMediaStream(e, {
686
+ return u("replaceMediaStream"), this.sipConnector.replaceMediaStream(e, {
681
687
  deleteExisting: t,
682
688
  addMissing: s,
683
689
  forceRenegotiation: o,
@@ -690,26 +696,26 @@ class Sn {
690
696
  onAddedTransceiver: S
691
697
  });
692
698
  });
693
- u(this, "askPermissionToEnableCam", async () => {
699
+ a(this, "askPermissionToEnableCam", async () => {
694
700
  if (this.sipConnector.isCallActive)
695
- return a("askPermissionToEnableCam"), this.sipConnector.askPermissionToEnableCam();
701
+ return u("askPermissionToEnableCam"), this.sipConnector.askPermissionToEnableCam();
696
702
  });
697
- u(this, "resolveHandleReadyRemoteStreamsDebounced", ({
703
+ a(this, "resolveHandleReadyRemoteStreamsDebounced", ({
698
704
  onReadyRemoteStreams: e
699
705
  }) => fe(() => {
700
706
  const t = this.sipConnector.getRemoteStreams();
701
- a("remoteStreams", t), t && e(t);
707
+ u("remoteStreams", t), t && e(t);
702
708
  }, 200));
703
- u(this, "resolveHandleReadyRemoteStreams", ({
709
+ a(this, "resolveHandleReadyRemoteStreams", ({
704
710
  onReadyRemoteStreams: e
705
711
  }) => ({ track: t }) => {
706
712
  Ze(t) && e();
707
713
  });
708
- u(this, "getRemoteStreams", () => (a("getRemoteStreams"), this.sipConnector.getRemoteStreams()));
709
- u(this, "onUseLicense", (e) => (a("onUseLicense"), this.sipConnector.onSession("useLicense", e)));
710
- u(this, "onMustStopPresentation", (e) => (a("onMustStopPresentation"), this.sipConnector.onSession("mustStopPresentation", e)));
711
- u(this, "onMoveToSpectators", (e) => (a("onMoveToSpectators"), this.sipConnector.onSession(ce, e)));
712
- u(this, "onMoveToParticipants", (e) => (a("onMoveToParticipants"), this.sipConnector.onSession(ae, e)));
714
+ a(this, "getRemoteStreams", () => (u("getRemoteStreams"), this.sipConnector.getRemoteStreams()));
715
+ a(this, "onUseLicense", (e) => (u("onUseLicense"), this.sipConnector.onSession("useLicense", e)));
716
+ a(this, "onMustStopPresentation", (e) => (u("onMustStopPresentation"), this.sipConnector.onSession("mustStopPresentation", e)));
717
+ a(this, "onMoveToSpectators", (e) => (u("onMoveToSpectators"), this.sipConnector.onSession(ce, e)));
718
+ a(this, "onMoveToParticipants", (e) => (u("onMoveToParticipants"), this.sipConnector.onSession(ae, e)));
713
719
  return this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.sipConnector = e, new Proxy(this, {
714
720
  get: (o, r, i) => {
715
721
  if (typeof r == "string" && en.has(r) && r in this.sipConnector) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sip-connector",
3
- "version": "13.2.0",
3
+ "version": "13.3.0",
4
4
  "description": "Module for connect to Vinteo server",
5
5
  "keywords": [
6
6
  "webrtc",