sip-connector 13.1.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.
@@ -1,10 +1,7 @@
1
1
  import { UA } from '@krivega/jssip';
2
2
  import { default as SipConnector } from '../SipConnector';
3
3
  import { EUseLicense, TContentHint, TSimulcastEncoding } from '../types';
4
- declare class SipConnectorFacade {
5
- readonly sipConnector: SipConnector;
6
- private readonly preferredMimeTypesVideoCodecs?;
7
- private readonly excludeMimeTypesVideoCodecs?;
4
+ interface IProxyMethods {
8
5
  on: SipConnector['on'];
9
6
  once: SipConnector['once'];
10
7
  onceRace: SipConnector['onceRace'];
@@ -18,16 +15,42 @@ declare class SipConnectorFacade {
18
15
  sendDTMF: SipConnector['sendDTMF'];
19
16
  hangUp: SipConnector['hangUp'];
20
17
  declineToIncomingCall: SipConnector['declineToIncomingCall'];
21
- isConfigured: SipConnector['isConfigured'];
22
18
  sendChannels: SipConnector['sendChannels'];
23
19
  checkTelephony: SipConnector['checkTelephony'];
24
20
  waitChannels: SipConnector['waitChannels'];
25
21
  ping: SipConnector['ping'];
22
+ connection: SipConnector['connection'];
23
+ isConfigured: SipConnector['isConfigured'];
24
+ isRegistered: SipConnector['isRegistered'];
25
+ }
26
+ declare class SipConnectorFacade implements IProxyMethods {
27
+ readonly sipConnector: SipConnector;
28
+ private readonly preferredMimeTypesVideoCodecs?;
29
+ private readonly excludeMimeTypesVideoCodecs?;
30
+ on: IProxyMethods['on'];
31
+ once: IProxyMethods['once'];
32
+ onceRace: IProxyMethods['onceRace'];
33
+ wait: IProxyMethods['wait'];
34
+ off: IProxyMethods['off'];
35
+ onSession: IProxyMethods['onSession'];
36
+ onceSession: IProxyMethods['onceSession'];
37
+ onceRaceSession: IProxyMethods['onceRaceSession'];
38
+ waitSession: IProxyMethods['waitSession'];
39
+ offSession: IProxyMethods['offSession'];
40
+ sendDTMF: IProxyMethods['sendDTMF'];
41
+ hangUp: IProxyMethods['hangUp'];
42
+ declineToIncomingCall: IProxyMethods['declineToIncomingCall'];
43
+ sendChannels: IProxyMethods['sendChannels'];
44
+ checkTelephony: IProxyMethods['checkTelephony'];
45
+ waitChannels: IProxyMethods['waitChannels'];
46
+ ping: IProxyMethods['ping'];
47
+ connection: IProxyMethods['connection'];
48
+ isConfigured: IProxyMethods['isConfigured'];
49
+ isRegistered: IProxyMethods['isRegistered'];
26
50
  constructor(sipConnector: SipConnector, { preferredMimeTypesVideoCodecs, excludeMimeTypesVideoCodecs, }?: {
27
51
  preferredMimeTypesVideoCodecs?: string[];
28
52
  excludeMimeTypesVideoCodecs?: string[];
29
53
  });
30
- get isRegistered(): boolean;
31
54
  connectToServer: (parameters: {
32
55
  userAgent: string;
33
56
  sipWebSocketServerURL: 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 l=(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 le=(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},ue=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=ue(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:le,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",u=s?"0":"1";return c.push(`X-Vinteo-Mic-State: ${a}`,`X-Vinteo-MainCam-State: ${u}`),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="[@*!|]",he="_",fe=n=>{let e=n;return e=e.replaceAll(new RegExp(Ce,"g"),he),e},me=({appName:n,appVersion:e,browserName:t,browserVersion:s})=>{const i=`${fe(n)} ${e}`;return`ChromeNew - ${t?`${t} ${s}, ${i}`:i}`},Re=({isUnifiedSdpSemantic:n,appVersion:e,browserName:t,browserVersion:s,appName:r})=>n?me({appVersion:e,browserName:t,browserVersion:s,appName:r}):"Chrome",W="purgatory",B=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)),be=n=>t=>(o.logger("onStopMainCam"),n.onSession("admin-stop-main-cam",t)),Me=n=>t=>(o.logger("onStopMic"),n.onSession("admin-stop-mic",t)),Ae=({sipConnector:n})=>{const e=(h,p)=>({isSyncForced:f=!1})=>{if(f){h();return}p()},t=ye(n),s=be(n),r=Te(n),i=Me(n);let c=()=>{},a=()=>{},u=()=>{},g=()=>{};const C=({onStartMainCamForced:h,onStartMainCamNotForced:p,onStopMainCamForced:f,onStopMainCamNotForced:m,onStartMicForced:E,onStartMicNotForced:y,onStopMicForced:T,onStopMicNotForced:b})=>{const _=e(h,p);c=t(_);const v=e(f,m);a=s(v);const O=e(E,y);u=r(O);const N=e(T,b);g=i(N)},S=()=>{c(),a(),u(),g()};return{start:h=>{C(h)},stop:()=>{S()}}},_e=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:W,createSyncMediaState:Ae,error:ge,getExtraHeaders:Se,getUserAgent:Re,hasPurgatory:B,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),De=R(4),we=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):De,Be="av1",Ie=n=>K(n,Be),Fe=.6,z=(n,e)=>Ie(e)?n*Fe:n,ke=n=>z(Y,n),Q=(n,e)=>{const t=we(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,u=Math.max(c,a,Ue),g=Q(e.width,t);return{scaleResolutionDownBy:u,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:u}=J({videoTrack:e,codec:s,targetSize:{width:Number(i),height:Number(c)}});return q({sender:n,maxBitrate:a,onSetParameters:r,scaleResolutionDownBy:u})},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:u}=n;if(!u)throw new Error("connection is not exist");return X({connection:u,onSetParameters:t,ignoreForCodec:e})};let r=s;const i=async u=>(r=async()=>{const{mainCam:g,resolutionMainCam:C}=u,{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],D=({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:u,scaleResolutionDownBy:g}=J({videoTrack:r,targetSize:{width:i.width,height:i.height}});a.maxBitrate=u,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)),w=(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";class ze{constructor(e,{preferredMimeTypesVideoCodecs:t,excludeMimeTypesVideoCodecs:s}={}){l(this,"sipConnector");l(this,"preferredMimeTypesVideoCodecs");l(this,"excludeMimeTypesVideoCodecs");l(this,"on");l(this,"once");l(this,"onceRace");l(this,"wait");l(this,"off");l(this,"onSession");l(this,"onceSession");l(this,"onceRaceSession");l(this,"waitSession");l(this,"offSession");l(this,"sendDTMF");l(this,"hangUp");l(this,"declineToIncomingCall");l(this,"isConfigured");l(this,"sendChannels");l(this,"checkTelephony");l(this,"waitChannels");l(this,"ping");l(this,"connectToServer",async e=>{const{userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,name:a,password:u,isRegisteredUser:g,isDisconnectOnFail:C}=e;return o.logger("connectToServer",e),this.sipConnector.connect({userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,password:u,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)))});l(this,"callToServer",async e=>{const{conference:t,mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,simulcastEncodings:a,degradationPreference:u,sendEncodings:g,offerToReceiveAudio:C,offerToReceiveVideo:S,directionVideo:I,directionAudio:F,setRemoteStreams:h,onBeforeProgressCall:p,onSuccessProgressCall:f,onEnterPurgatory:m,onEnterConference:E,onFailProgressCall:y,onFinishProgressCall:T,onEndedCall:b}=e,_=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:h}),v=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:_}),O=w({degradationPreference:u},{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:D({mediaStream:s,simulcastEncodings:a,sendEncodings:g}),number:t,onAddedTransceiver:O,ontrack:v}));let M=!1,A;const P=(o.logger("subscribeEnterConference: onEnterConference",E),m??E?this.sipConnector.onSession("enterRoom",({room:d})=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:M}),A=d,B(A)?m&&m():E&&E({isSuccessProgressCall:M})}):()=>{}),k=d=>(o.logger("onSuccess"),M=!0,_(),f&&f({isPurgatory:B(A)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),b&&b()}),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)});l(this,"disconnectFromServer",async()=>this.sipConnector.disconnect().then(()=>(o.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(e=>(o.logger("disconnectFromServer: catch",e),{isSuccessful:!1})));l(this,"answerIncomingCall",async e=>{const{mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,simulcastEncodings:c,degradationPreference:a,sendEncodings:u,offerToReceiveAudio:g,offerToReceiveVideo:C,directionVideo:S,directionAudio:I,setRemoteStreams:F,onBeforeProgressCall:h,onSuccessProgressCall:p,onEnterPurgatory:f,onEnterConference:m,onFailProgressCall:E,onFinishProgressCall:y,onEndedCall:T}=e,b=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:F}),_=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:b}),v=w({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:D({mediaStream:t,simulcastEncodings:c,sendEncodings:u}),onAddedTransceiver:v,ontrack:_}),N=()=>{const{remoteCallerData:d}=this.sipConnector;return d.incomingNumber};let M=!1,A;const P=(o.logger("subscribeEnterConference: onEnterConference",m),f??m?this.sipConnector.onSession("enterRoom",d=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:M}),A=d,B(A)?f&&f():m&&m({isSuccessProgressCall:M})}):()=>{}),k=d=>(o.logger("onSuccess"),M=!0,b(),p&&p({isPurgatory:B(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"),h){const d=N();h(d)}return O().then(k).catch(d=>U(d)).finally(V)});l(this,"updatePresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:a,preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g})=>{const C=w({degradationPreference:c},{preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g});return o.logger("updatePresentation"),this.sipConnector.updatePresentation(e,{isP2P:t,maxBitrate:s,contentHint:r,sendEncodings:D({mediaStream:e,simulcastEncodings:i,sendEncodings:a}),onAddedTransceiver:C})});l(this,"startPresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:a,preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g},C)=>{const S=w({degradationPreference:c},{preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g});return o.logger("startPresentation"),this.sipConnector.startPresentation(e,{isP2P:t,maxBitrate:s,contentHint:r,sendEncodings:D({mediaStream:e,simulcastEncodings:i,sendEncodings:a}),onAddedTransceiver:S},C)});l(this,"stopShareSipConnector",async({isP2P:e=!1}={})=>(o.logger("stopShareSipConnector"),this.sipConnector.stopPresentation({isP2P:e}).catch(t=>{o.logger(t)})));l(this,"sendRefusalToTurnOnMic",async()=>{if(this.sipConnector.isCallActive)return o.logger("sendRefusalToTurnOnMic"),this.sipConnector.sendRefusalToTurnOnMic().catch(e=>{o.logger("sendRefusalToTurnOnMic: error",e)})});l(this,"sendRefusalToTurnOnCam",async()=>{if(this.sipConnector.isCallActive)return o.logger("sendRefusalToTurnOnCam"),this.sipConnector.sendRefusalToTurnOnCam().catch(e=>{o.logger("sendRefusalToTurnOnCam: error",e)})});l(this,"sendMediaState",async({isEnabledCam:e,isEnabledMic:t})=>{if(this.sipConnector.isCallActive)return o.logger("sendMediaState"),this.sipConnector.sendMediaState({cam:e,mic:t})});l(this,"replaceMediaStream",async(e,{deleteExisting:t,addMissing:s,forceRenegotiation:r,contentHint:i,simulcastEncodings:c,degradationPreference:a,sendEncodings:u}={})=>{const g=w({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:D({mediaStream:e,simulcastEncodings:c,sendEncodings:u}),onAddedTransceiver:g})});l(this,"askPermissionToEnableCam",async()=>{if(this.sipConnector.isCallActive)return o.logger("askPermissionToEnableCam"),this.sipConnector.askPermissionToEnableCam()});l(this,"resolveHandleReadyRemoteStreamsDebounced",({onReadyRemoteStreams:e})=>ce.debounce(()=>{const t=this.sipConnector.getRemoteStreams();o.logger("remoteStreams",t),t&&e(t)},200));l(this,"resolveHandleReadyRemoteStreams",({onReadyRemoteStreams:e})=>({track:t})=>{Ye(t)&&e()});l(this,"getRemoteStreams",()=>(o.logger("getRemoteStreams"),this.sipConnector.getRemoteStreams()));l(this,"onUseLicense",e=>(o.logger("onUseLicense"),this.sipConnector.onSession("useLicense",e)));l(this,"onMustStopPresentation",e=>(o.logger("onMustStopPresentation"),this.sipConnector.onSession("mustStopPresentation",e)));l(this,"onMoveToSpectators",e=>(o.logger("onMoveToSpectators"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS,e)));l(this,"onMoveToParticipants",e=>(o.logger("onMoveToParticipants"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_PARTICIPANTS,e)));this.preferredMimeTypesVideoCodecs=t,this.excludeMimeTypesVideoCodecs=s,this.sipConnector=e,this.on=this.sipConnector.on.bind(e),this.once=this.sipConnector.once.bind(e),this.onceRace=this.sipConnector.onceRace.bind(e),this.wait=this.sipConnector.wait.bind(e),this.off=this.sipConnector.off.bind(e),this.onSession=this.sipConnector.onSession.bind(e),this.onceSession=this.sipConnector.onceSession.bind(e),this.onceRaceSession=this.sipConnector.onceRaceSession.bind(e),this.waitSession=this.sipConnector.waitSession.bind(e),this.offSession=this.sipConnector.offSession.bind(e),this.sendDTMF=this.sipConnector.sendDTMF.bind(e),this.hangUp=this.sipConnector.hangUp.bind(e),this.declineToIncomingCall=this.sipConnector.declineToIncomingCall.bind(e),this.isConfigured=this.sipConnector.isConfigured.bind(e),this.sendChannels=this.sipConnector.sendChannels.bind(e),this.checkTelephony=this.sipConnector.checkTelephony.bind(e),this.waitChannels=this.sipConnector.waitChannels.bind(e),this.ping=this.sipConnector.ping.bind(e)}get isRegistered(){return this.sipConnector.isRegistered}}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=ze;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,14 +1,14 @@
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 L, s as re, a as ie, P as ce, b as ae, S as tn } from "./SipConnector-B4xLnl6L.js";
5
- import { i as Cn, j as fn, m as mn, k as Rn, c as gn, d as pn, f as yn, g as Tn, e as En, h as bn } 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
+ 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
- import { createStackPromises as de } from "stack-promises";
8
- import { isCanceledError as le } from "@krivega/cancelable-promise";
7
+ import { createStackPromises as le } from "stack-promises";
8
+ import { isCanceledError as de } from "@krivega/cancelable-promise";
9
9
  import { hasCanceledError as Se } from "repeated-calls";
10
- import { debounce as he } from "ts-debounce";
11
- import { default as An } from "debug";
10
+ import { debounce as fe } from "ts-debounce";
11
+ import { default as _n } from "debug";
12
12
  const H = (n) => {
13
13
  const { url: e, cause: t } = n;
14
14
  let s = e;
@@ -36,23 +36,23 @@ const Ce = (n = new Error()) => {
36
36
  t && ((o = t == null ? void 0 : t._ws) == null ? void 0 : o.readyState) === 3 ? s = "WS_CONNECTION_FAILED" : H(n) && (s = "CONNECT_SERVER_FAILED_BY_LINK");
37
37
  }
38
38
  return s;
39
- }, fe = (n) => {
39
+ }, me = (n) => {
40
40
  let e = "";
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
- }, me = (n = new Error()) => {
47
+ }, he = (n = new Error()) => {
48
48
  const { code: e, cause: t, message: s } = n, o = H(n), r = { code: "", cause: "", message: "" };
49
- return typeof s == "object" && s !== null ? r.message = fe(s) : s && (r.message = String(s)), o && (r.link = o), e && (r.code = e), t && (r.cause = t), r;
49
+ return typeof s == "object" && s !== null ? r.message = me(s) : s && (r.message = String(s)), o && (r.link = o), e && (r.code = e), t && (r.cause = t), r;
50
50
  }, Re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
51
51
  __proto__: null,
52
52
  EErrorTypes: q,
53
53
  getLinkError: H,
54
54
  getTypeFromError: Ce,
55
- getValuesFromError: me
55
+ getValuesFromError: he
56
56
  }, Symbol.toStringTag, { value: "Module" })), ge = ({
57
57
  sessionId: n,
58
58
  remoteAddress: e,
@@ -61,18 +61,18 @@ const Ce = (n = new Error()) => {
61
61
  isRegistered: o,
62
62
  isPresentationCall: r
63
63
  }) => {
64
- const i = [], c = t ? "0" : "1", d = s ? "0" : "1";
65
- return i.push(`X-Vinteo-Mic-State: ${c}`, `X-Vinteo-MainCam-State: ${d}`), o || i.push("X-Vinteo-Purgatory-Call: yes"), n && i.push(`X-Vinteo-Session: ${n}`), r && i.push("X-Vinteo-Presentation-Call: yes"), e && i.push(`X-Vinteo-Remote: ${e}`), i;
66
- }, pe = "[@*!|]", ye = "_", Te = (n) => {
64
+ const i = [], c = t ? "0" : "1", l = s ? "0" : "1";
65
+ return i.push(`X-Vinteo-Mic-State: ${c}`, `X-Vinteo-MainCam-State: ${l}`), o || i.push("X-Vinteo-Purgatory-Call: yes"), n && i.push(`X-Vinteo-Session: ${n}`), r && i.push("X-Vinteo-Presentation-Call: yes"), e && i.push(`X-Vinteo-Remote: ${e}`), i;
66
+ }, pe = "[@*!|]", ye = "_", Ee = (n) => {
67
67
  let e = n;
68
68
  return e = e.replaceAll(new RegExp(pe, "g"), ye), e;
69
- }, Ee = ({
69
+ }, Te = ({
70
70
  appName: n,
71
71
  appVersion: e,
72
72
  browserName: t,
73
73
  browserVersion: s
74
74
  }) => {
75
- const r = `${Te(n)} ${e}`;
75
+ const r = `${Ee(n)} ${e}`;
76
76
  return `ChromeNew - ${t ? `${t} ${s}, ${r}` : r}`;
77
77
  }, be = ({
78
78
  isUnifiedSdpSemantic: n,
@@ -80,62 +80,62 @@ const Ce = (n = new Error()) => {
80
80
  browserName: t,
81
81
  browserVersion: s,
82
82
  appName: o
83
- }) => n ? Ee({ appVersion: e, browserName: t, browserVersion: s, appName: o }) : "Chrome", Y = "purgatory", D = (n) => n === Y, Me = (n) => (e) => [...e].map((s) => async () => n(s)), Ae = async ({
83
+ }) => n ? Te({ appVersion: e, browserName: t, browserVersion: s, appName: o }) : "Chrome", Y = "purgatory", D = (n) => n === Y, Me = (n) => (e) => [...e].map((s) => async () => n(s)), Ae = async ({
84
84
  accumulatedKeys: n,
85
85
  sendKey: e,
86
86
  canRunTask: t
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 }) => {
91
- const e = (f, p) => ({ isSyncForced: m = !1 }) => {
92
- if (m) {
93
- f();
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
+ const e = (m, p) => ({ isSyncForced: h = !1 }) => {
92
+ if (h) {
93
+ m();
94
94
  return;
95
95
  }
96
96
  p();
97
97
  }, t = _e(n), s = Oe(n), o = ve(n), r = Ne(n);
98
98
  let i = () => {
99
99
  }, c = () => {
100
- }, d = () => {
100
+ }, l = () => {
101
101
  }, S = () => {
102
102
  };
103
103
  const C = ({
104
- onStartMainCamForced: f,
104
+ onStartMainCamForced: m,
105
105
  onStartMainCamNotForced: p,
106
- onStopMainCamForced: m,
106
+ onStopMainCamForced: h,
107
107
  onStopMainCamNotForced: R,
108
108
  onStartMicForced: y,
109
- onStartMicNotForced: T,
110
- onStopMicForced: E,
109
+ onStartMicNotForced: E,
110
+ onStopMicForced: T,
111
111
  onStopMicNotForced: b
112
112
  }) => {
113
113
  const _ = e(
114
- f,
114
+ m,
115
115
  p
116
116
  );
117
117
  i = t(_);
118
118
  const v = e(
119
- m,
119
+ h,
120
120
  R
121
121
  );
122
122
  c = s(v);
123
- const O = e(y, T);
124
- d = o(O);
125
- const N = e(E, b);
123
+ const O = e(y, E);
124
+ l = o(O);
125
+ const N = e(T, b);
126
126
  S = r(N);
127
- }, h = () => {
128
- i(), c(), d(), S();
127
+ }, f = () => {
128
+ i(), c(), l(), S();
129
129
  };
130
130
  return {
131
- start: (f) => {
132
- C(f);
131
+ start: (m) => {
132
+ C(m);
133
133
  },
134
134
  stop: () => {
135
- h();
135
+ f();
136
136
  }
137
137
  };
138
- }, un = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
138
+ }, ln = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
139
139
  __proto__: null,
140
140
  PURGATORY_CONFERENCE_NUMBER: Y,
141
141
  createSyncMediaState: we,
@@ -150,7 +150,7 @@ const Ce = (n = new Error()) => {
150
150
  }), Ie = (n) => n.find((e) => {
151
151
  var t;
152
152
  return ((t = e == null ? void 0 : e.track) == null ? void 0 : t.kind) === "video";
153
- }), z = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Fe = 1e6, g = (n) => n * Fe, Q = g(0.06), ke = g(4), Ue = (n) => n <= 64 ? Q : n <= 128 ? g(0.12) : n <= 256 ? g(0.25) : n <= 384 ? g(0.32) : n <= 426 ? g(0.38) : n <= 640 ? g(0.5) : n <= 848 ? g(0.7) : n <= 1280 ? g(1) : n <= 1920 ? g(2) : ke, Ve = "av1", Le = (n) => z(n, Ve), xe = 0.6, J = (n, e) => Le(e) ? n * xe : n, $e = (n) => J(Q, n), Z = (n, e) => {
153
+ }), z = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Fe = 1e6, g = (n) => n * Fe, Q = g(0.06), ke = g(4), Ue = (n) => n <= 64 ? Q : n <= 128 ? g(0.12) : n <= 256 ? g(0.25) : n <= 384 ? g(0.32) : n <= 426 ? g(0.38) : n <= 640 ? g(0.5) : n <= 848 ? g(0.7) : n <= 1280 ? g(1) : n <= 1920 ? g(2) : ke, Ve = "av1", xe = (n) => z(n, Ve), Le = 0.6, J = (n, e) => xe(e) ? n * Le : n, $e = (n) => J(Q, n), Z = (n, e) => {
154
154
  const t = Ue(n);
155
155
  return J(t, e);
156
156
  }, He = 1, ee = ({
@@ -158,10 +158,10 @@ const Ce = (n = new Error()) => {
158
158
  targetSize: e,
159
159
  codec: t
160
160
  }) => {
161
- const s = n.getSettings(), o = s.width, r = s.height, i = o / e.width, c = r / e.height, d = Math.max(i, c, He), S = Z(e.width, t);
162
- return { scaleResolutionDownBy: d, maxBitrate: S };
163
- }, ne = de(), Xe = async () => ne().catch((n) => {
164
- a("videoSendingBalancer: error", n);
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
+ return { scaleResolutionDownBy: l, maxBitrate: S };
163
+ }, ne = le(), Xe = async () => ne().catch((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,
@@ -175,7 +175,7 @@ const Ce = (n = new Error()) => {
175
175
  onSetParameters: t,
176
176
  scaleResolutionDownBy: 200
177
177
  });
178
- }, x = async ({
178
+ }, L = async ({
179
179
  sender: n,
180
180
  videoTrack: e,
181
181
  codec: t
@@ -193,7 +193,7 @@ const Ce = (n = new Error()) => {
193
193
  resolution: t,
194
194
  codec: s
195
195
  }, o) => {
196
- const [r, i] = t.split("x"), { maxBitrate: c, scaleResolutionDownBy: d } = ee({
196
+ const [r, i] = t.split("x"), { maxBitrate: c, scaleResolutionDownBy: l } = ee({
197
197
  videoTrack: e,
198
198
  codec: s,
199
199
  targetSize: {
@@ -205,7 +205,7 @@ const Ce = (n = new Error()) => {
205
205
  sender: n,
206
206
  maxBitrate: c,
207
207
  onSetParameters: o,
208
- scaleResolutionDownBy: d
208
+ scaleResolutionDownBy: l
209
209
  });
210
210
  }, Ke = async ({
211
211
  mainCam: n,
@@ -215,17 +215,17 @@ const Ce = (n = new Error()) => {
215
215
  codec: o
216
216
  }, r) => {
217
217
  switch (n) {
218
- case L.PAUSE_MAIN_CAM:
218
+ case x.PAUSE_MAIN_CAM:
219
219
  return We({ sender: t, codec: o }, r);
220
- case L.RESUME_MAIN_CAM:
221
- return x({ sender: t, videoTrack: s, codec: o }, r);
222
- case L.MAX_MAIN_CAM_RESOLUTION:
220
+ case x.RESUME_MAIN_CAM:
221
+ return L({ sender: t, videoTrack: s, codec: o }, r);
222
+ case x.MAX_MAIN_CAM_RESOLUTION:
223
223
  return e !== void 0 ? Ge(
224
224
  { sender: t, videoTrack: s, codec: o, resolution: e },
225
225
  r
226
- ) : x({ sender: t, videoTrack: s, codec: o }, r);
226
+ ) : L({ sender: t, videoTrack: s, codec: o }, r);
227
227
  default:
228
- return x({ sender: t, videoTrack: s, codec: o }, r);
228
+ return L({ sender: t, videoTrack: s, codec: o }, r);
229
229
  }
230
230
  }, j = {
231
231
  isChanged: !1,
@@ -262,24 +262,24 @@ const Ce = (n = new Error()) => {
262
262
  onSetParameters: t
263
263
  } = {}) => {
264
264
  const s = async () => {
265
- const { connection: d } = n;
266
- if (!d)
265
+ const { connection: l } = n;
266
+ if (!l)
267
267
  throw new Error("connection is not exist");
268
268
  return W({
269
- connection: d,
269
+ connection: l,
270
270
  onSetParameters: t,
271
271
  ignoreForCodec: e
272
272
  });
273
273
  };
274
274
  let o = s;
275
- const r = async (d) => (o = async () => {
276
- const { mainCam: S, resolutionMainCam: C } = d, { connection: h } = n;
277
- if (!h)
275
+ const r = async (l) => (o = async () => {
276
+ const { mainCam: S, resolutionMainCam: C } = l, { connection: f } = n;
277
+ if (!f)
278
278
  throw new Error("connection is not exist");
279
279
  return W({
280
280
  mainCam: S,
281
281
  resolutionMainCam: C,
282
- connection: h,
282
+ connection: f,
283
283
  onSetParameters: t,
284
284
  ignoreForCodec: e
285
285
  });
@@ -309,14 +309,14 @@ const Ce = (n = new Error()) => {
309
309
  return e.forEach((r, i) => {
310
310
  const c = s[i] ?? {};
311
311
  c.active = !0, r.rid !== void 0 && (c.rid = r.rid), r.scalabilityMode !== void 0 && (c.scalabilityMode = r.scalabilityMode);
312
- const { maxBitrate: d, scaleResolutionDownBy: S } = ee({
312
+ const { maxBitrate: l, scaleResolutionDownBy: S } = ee({
313
313
  videoTrack: o,
314
314
  targetSize: {
315
315
  width: r.width,
316
316
  height: r.height
317
317
  }
318
318
  });
319
- c.maxBitrate = d, c.scaleResolutionDownBy = S, s[i] = c;
319
+ c.maxBitrate = l, c.scaleResolutionDownBy = S, s[i] = c;
320
320
  }), s;
321
321
  }
322
322
  return t;
@@ -337,37 +337,80 @@ const Ce = (n = new Error()) => {
337
337
  }
338
338
  Object.keys(n).length > 0 && await ie(s.sender, n);
339
339
  }, $ = (n) => {
340
- if (!le(n) && !Se(n))
340
+ if (!de(n) && !Se(n))
341
341
  throw n;
342
342
  return { isSuccessful: !1 };
343
- }, Ze = ({ kind: n, readyState: e }) => n === "video" && e === "live";
344
- class ln {
343
+ }, Ze = ({ kind: n, readyState: e }) => n === "video" && e === "live", en = /* @__PURE__ */ new Set([
344
+ "on",
345
+ "once",
346
+ "onceRace",
347
+ "wait",
348
+ "off",
349
+ "onSession",
350
+ "onceSession",
351
+ "onceRaceSession",
352
+ "waitSession",
353
+ "offSession",
354
+ "sendDTMF",
355
+ "hangUp",
356
+ "declineToIncomingCall",
357
+ "sendChannels",
358
+ "checkTelephony",
359
+ "waitChannels",
360
+ "ping",
361
+ "connection",
362
+ "isConfigured",
363
+ "isRegistered"
364
+ ]);
365
+ class Sn {
345
366
  constructor(e, {
346
367
  preferredMimeTypesVideoCodecs: t,
347
368
  excludeMimeTypesVideoCodecs: s
348
369
  } = {}) {
349
- u(this, "sipConnector");
350
- u(this, "preferredMimeTypesVideoCodecs");
351
- u(this, "excludeMimeTypesVideoCodecs");
352
- u(this, "on");
353
- u(this, "once");
354
- u(this, "onceRace");
355
- u(this, "wait");
356
- u(this, "off");
357
- u(this, "onSession");
358
- u(this, "onceSession");
359
- u(this, "onceRaceSession");
360
- u(this, "waitSession");
361
- u(this, "offSession");
362
- u(this, "sendDTMF");
363
- u(this, "hangUp");
364
- u(this, "declineToIncomingCall");
365
- u(this, "isConfigured");
366
- u(this, "sendChannels");
367
- u(this, "checkTelephony");
368
- u(this, "waitChannels");
369
- u(this, "ping");
370
- u(this, "connectToServer", async (e) => {
370
+ a(this, "sipConnector");
371
+ a(this, "preferredMimeTypesVideoCodecs");
372
+ a(this, "excludeMimeTypesVideoCodecs");
373
+ // @ts-expect-error: proxy method
374
+ a(this, "on");
375
+ // @ts-expect-error: proxy method
376
+ a(this, "once");
377
+ // @ts-expect-error: proxy method
378
+ a(this, "onceRace");
379
+ // @ts-expect-error: proxy method
380
+ a(this, "wait");
381
+ // @ts-expect-error: proxy method
382
+ a(this, "off");
383
+ // @ts-expect-error: proxy method
384
+ a(this, "onSession");
385
+ // @ts-expect-error: proxy method
386
+ a(this, "onceSession");
387
+ // @ts-expect-error: proxy method
388
+ a(this, "onceRaceSession");
389
+ // @ts-expect-error: proxy method
390
+ a(this, "waitSession");
391
+ // @ts-expect-error: proxy method
392
+ a(this, "offSession");
393
+ // @ts-expect-error: proxy method
394
+ a(this, "sendDTMF");
395
+ // @ts-expect-error: proxy method
396
+ a(this, "hangUp");
397
+ // @ts-expect-error: proxy method
398
+ a(this, "declineToIncomingCall");
399
+ // @ts-expect-error: proxy method
400
+ a(this, "sendChannels");
401
+ // @ts-expect-error: proxy method
402
+ a(this, "checkTelephony");
403
+ // @ts-expect-error: proxy method
404
+ a(this, "waitChannels");
405
+ // @ts-expect-error: proxy method
406
+ a(this, "ping");
407
+ // proxy method
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) => {
371
414
  const {
372
415
  userAgent: t,
373
416
  sipWebSocketServerURL: s,
@@ -375,22 +418,22 @@ class ln {
375
418
  remoteAddress: r,
376
419
  displayName: i,
377
420
  name: c,
378
- password: d,
421
+ password: l,
379
422
  isRegisteredUser: S,
380
423
  isDisconnectOnFail: C
381
424
  } = e;
382
- return a("connectToServer", e), this.sipConnector.connect({
425
+ return u("connectToServer", e), this.sipConnector.connect({
383
426
  userAgent: t,
384
427
  sipWebSocketServerURL: s,
385
428
  sipServerUrl: o,
386
429
  remoteAddress: r,
387
430
  displayName: i,
388
- password: d,
431
+ password: l,
389
432
  user: c,
390
433
  register: S
391
- }).then((h) => (a("connectToServer then"), { ua: h, isSuccessful: !0 })).catch(async (h) => (a("connectToServer catch: error", h), C === !0 ? this.sipConnector.disconnect().then(() => $(h)).catch(() => $(h)) : $(h)));
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)));
392
435
  });
393
- u(this, "callToServer", async (e) => {
436
+ a(this, "callToServer", async (e) => {
394
437
  const {
395
438
  conference: t,
396
439
  mediaStream: s,
@@ -398,41 +441,41 @@ class ln {
398
441
  iceServers: r,
399
442
  contentHint: i,
400
443
  simulcastEncodings: c,
401
- degradationPreference: d,
444
+ degradationPreference: l,
402
445
  sendEncodings: S,
403
446
  offerToReceiveAudio: C,
404
- offerToReceiveVideo: h,
447
+ offerToReceiveVideo: f,
405
448
  directionVideo: I,
406
449
  directionAudio: F,
407
- setRemoteStreams: f,
450
+ setRemoteStreams: m,
408
451
  onBeforeProgressCall: p,
409
- onSuccessProgressCall: m,
452
+ onSuccessProgressCall: h,
410
453
  onEnterPurgatory: R,
411
454
  onEnterConference: y,
412
- onFailProgressCall: T,
413
- onFinishProgressCall: E,
455
+ onFailProgressCall: E,
456
+ onFinishProgressCall: T,
414
457
  onEndedCall: b
415
458
  } = e, _ = this.resolveHandleReadyRemoteStreamsDebounced({
416
- onReadyRemoteStreams: f
459
+ onReadyRemoteStreams: m
417
460
  }), v = this.resolveHandleReadyRemoteStreams({
418
461
  onReadyRemoteStreams: _
419
462
  }), O = P(
420
463
  {
421
- degradationPreference: d
464
+ degradationPreference: l
422
465
  },
423
466
  {
424
467
  preferredMimeTypesVideoCodecs: this.preferredMimeTypesVideoCodecs,
425
468
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
426
469
  }
427
470
  );
428
- a("callToServer", e);
429
- const N = async () => (a("startCall"), this.sipConnector.call({
471
+ u("callToServer", e);
472
+ const N = async () => (u("startCall"), this.sipConnector.call({
430
473
  mediaStream: s,
431
474
  extraHeaders: o,
432
475
  iceServers: r,
433
476
  contentHint: i,
434
477
  offerToReceiveAudio: C,
435
- offerToReceiveVideo: h,
478
+ offerToReceiveVideo: f,
436
479
  directionVideo: I,
437
480
  directionAudio: F,
438
481
  sendEncodings: B({
@@ -445,20 +488,20 @@ class ln {
445
488
  ontrack: v
446
489
  }));
447
490
  let M = !1, A;
448
- const w = (a("subscribeEnterConference: onEnterConference", y), R ?? y ? this.sipConnector.onSession("enterRoom", ({ room: l }) => {
449
- a("enterRoom", { _room: l, isSuccessProgressCall: M }), A = l, 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 });
450
493
  }) : () => {
451
- }), k = (l) => (a("onSuccess"), M = !0, _(), m && m({ 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"], () => {
452
495
  w(), b && b();
453
- }), l), U = (l) => {
454
- throw a("onFail"), T && T(), w(), l;
496
+ }), d), U = (d) => {
497
+ throw u("onFail"), E && E(), w(), d;
455
498
  }, V = () => {
456
- a("onFinish"), E && E();
499
+ u("onFinish"), T && T();
457
500
  };
458
- return a("onBeforeProgressCall"), p && p(t), N().then(k).catch((l) => U(l)).finally(V);
501
+ return u("onBeforeProgressCall"), p && p(t), N().then(k).catch((d) => U(d)).finally(V);
459
502
  });
460
- u(this, "disconnectFromServer", async () => this.sipConnector.disconnect().then(() => (a("disconnectFromServer: then"), { isSuccessful: !0 })).catch((e) => (a("disconnectFromServer: catch", e), { isSuccessful: !1 })));
461
- 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) => {
462
505
  const {
463
506
  mediaStream: t,
464
507
  extraHeaders: s,
@@ -466,19 +509,19 @@ class ln {
466
509
  contentHint: r,
467
510
  simulcastEncodings: i,
468
511
  degradationPreference: c,
469
- sendEncodings: d,
512
+ sendEncodings: l,
470
513
  offerToReceiveAudio: S,
471
514
  offerToReceiveVideo: C,
472
- directionVideo: h,
515
+ directionVideo: f,
473
516
  directionAudio: I,
474
517
  setRemoteStreams: F,
475
- onBeforeProgressCall: f,
518
+ onBeforeProgressCall: m,
476
519
  onSuccessProgressCall: p,
477
- onEnterPurgatory: m,
520
+ onEnterPurgatory: h,
478
521
  onEnterConference: R,
479
522
  onFailProgressCall: y,
480
- onFinishProgressCall: T,
481
- onEndedCall: E
523
+ onFinishProgressCall: E,
524
+ onEndedCall: T
482
525
  } = e, b = this.resolveHandleReadyRemoteStreamsDebounced({
483
526
  onReadyRemoteStreams: F
484
527
  }), _ = this.resolveHandleReadyRemoteStreams({
@@ -492,7 +535,7 @@ class ln {
492
535
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
493
536
  }
494
537
  );
495
- a("answerIncomingCall", e);
538
+ u("answerIncomingCall", e);
496
539
  const O = async () => this.sipConnector.answerToIncomingCall({
497
540
  mediaStream: t,
498
541
  extraHeaders: s,
@@ -500,37 +543,37 @@ class ln {
500
543
  contentHint: r,
501
544
  offerToReceiveAudio: S,
502
545
  offerToReceiveVideo: C,
503
- directionVideo: h,
546
+ directionVideo: f,
504
547
  directionAudio: I,
505
548
  sendEncodings: B({
506
549
  mediaStream: t,
507
550
  simulcastEncodings: i,
508
- sendEncodings: d
551
+ sendEncodings: l
509
552
  }),
510
553
  onAddedTransceiver: v,
511
554
  ontrack: _
512
555
  }), N = () => {
513
- const { remoteCallerData: l } = this.sipConnector;
514
- return l.incomingNumber;
556
+ const { remoteCallerData: d } = this.sipConnector;
557
+ return d.incomingNumber;
515
558
  };
516
559
  let M = !1, A;
517
- const w = (a("subscribeEnterConference: onEnterConference", R), m ?? R ? this.sipConnector.onSession("enterRoom", (l) => {
518
- a("enterRoom", { _room: l, isSuccessProgressCall: M }), A = l, D(A) ? m && m() : 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 });
519
562
  }) : () => {
520
- }), k = (l) => (a("onSuccess"), M = !0, b(), p && p({ isPurgatory: D(A) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
521
- w(), E && E();
522
- }), l), U = (l) => {
523
- throw a("onFail"), y && y(), w(), l;
563
+ }), k = (d) => (u("onSuccess"), M = !0, b(), p && p({ isPurgatory: D(A) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
564
+ w(), T && T();
565
+ }), d), U = (d) => {
566
+ throw u("onFail"), y && y(), w(), d;
524
567
  }, V = () => {
525
- a("onFinish"), T && T();
568
+ u("onFinish"), E && E();
526
569
  };
527
- if (a("onBeforeProgressCall"), f) {
528
- const l = N();
529
- f(l);
570
+ if (u("onBeforeProgressCall"), m) {
571
+ const d = N();
572
+ m(d);
530
573
  }
531
- return O().then(k).catch((l) => U(l)).finally(V);
574
+ return O().then(k).catch((d) => U(d)).finally(V);
532
575
  });
533
- u(this, "updatePresentation", async ({
576
+ a(this, "updatePresentation", async ({
534
577
  mediaStream: e,
535
578
  isP2P: t,
536
579
  maxBitrate: s,
@@ -538,7 +581,7 @@ class ln {
538
581
  simulcastEncodings: r,
539
582
  degradationPreference: i,
540
583
  sendEncodings: c,
541
- preferredMimeTypesVideoCodecs: d,
584
+ preferredMimeTypesVideoCodecs: l,
542
585
  excludeMimeTypesVideoCodecs: S
543
586
  }) => {
544
587
  const C = P(
@@ -546,11 +589,11 @@ class ln {
546
589
  degradationPreference: i
547
590
  },
548
591
  {
549
- preferredMimeTypesVideoCodecs: d,
592
+ preferredMimeTypesVideoCodecs: l,
550
593
  excludeMimeTypesVideoCodecs: S
551
594
  }
552
595
  );
553
- return a("updatePresentation"), this.sipConnector.updatePresentation(e, {
596
+ return u("updatePresentation"), this.sipConnector.updatePresentation(e, {
554
597
  isP2P: t,
555
598
  maxBitrate: s,
556
599
  contentHint: o,
@@ -562,7 +605,7 @@ class ln {
562
605
  onAddedTransceiver: C
563
606
  });
564
607
  });
565
- u(this, "startPresentation", async ({
608
+ a(this, "startPresentation", async ({
566
609
  mediaStream: e,
567
610
  isP2P: t,
568
611
  maxBitrate: s,
@@ -570,19 +613,19 @@ class ln {
570
613
  simulcastEncodings: r,
571
614
  degradationPreference: i,
572
615
  sendEncodings: c,
573
- preferredMimeTypesVideoCodecs: d,
616
+ preferredMimeTypesVideoCodecs: l,
574
617
  excludeMimeTypesVideoCodecs: S
575
618
  }, C) => {
576
- const h = P(
619
+ const f = P(
577
620
  {
578
621
  degradationPreference: i
579
622
  },
580
623
  {
581
- preferredMimeTypesVideoCodecs: d,
624
+ preferredMimeTypesVideoCodecs: l,
582
625
  excludeMimeTypesVideoCodecs: S
583
626
  }
584
627
  );
585
- return a("startPresentation"), this.sipConnector.startPresentation(
628
+ return u("startPresentation"), this.sipConnector.startPresentation(
586
629
  e,
587
630
  {
588
631
  isP2P: t,
@@ -593,43 +636,43 @@ class ln {
593
636
  simulcastEncodings: r,
594
637
  sendEncodings: c
595
638
  }),
596
- onAddedTransceiver: h
639
+ onAddedTransceiver: f
597
640
  },
598
641
  C
599
642
  );
600
643
  });
601
- 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({
602
645
  isP2P: e
603
646
  }).catch((t) => {
604
- a(t);
647
+ u(t);
605
648
  })));
606
- u(this, "sendRefusalToTurnOnMic", async () => {
649
+ a(this, "sendRefusalToTurnOnMic", async () => {
607
650
  if (this.sipConnector.isCallActive)
608
- return a("sendRefusalToTurnOnMic"), this.sipConnector.sendRefusalToTurnOnMic().catch((e) => {
609
- a("sendRefusalToTurnOnMic: error", e);
651
+ return u("sendRefusalToTurnOnMic"), this.sipConnector.sendRefusalToTurnOnMic().catch((e) => {
652
+ u("sendRefusalToTurnOnMic: error", e);
610
653
  });
611
654
  });
612
- u(this, "sendRefusalToTurnOnCam", async () => {
655
+ a(this, "sendRefusalToTurnOnCam", async () => {
613
656
  if (this.sipConnector.isCallActive)
614
- return a("sendRefusalToTurnOnCam"), this.sipConnector.sendRefusalToTurnOnCam().catch((e) => {
615
- a("sendRefusalToTurnOnCam: error", e);
657
+ return u("sendRefusalToTurnOnCam"), this.sipConnector.sendRefusalToTurnOnCam().catch((e) => {
658
+ u("sendRefusalToTurnOnCam: error", e);
616
659
  });
617
660
  });
618
- u(this, "sendMediaState", async ({
661
+ a(this, "sendMediaState", async ({
619
662
  isEnabledCam: e,
620
663
  isEnabledMic: t
621
664
  }) => {
622
665
  if (this.sipConnector.isCallActive)
623
- return a("sendMediaState"), this.sipConnector.sendMediaState({ cam: e, mic: t });
666
+ return u("sendMediaState"), this.sipConnector.sendMediaState({ cam: e, mic: t });
624
667
  });
625
- u(this, "replaceMediaStream", async (e, {
668
+ a(this, "replaceMediaStream", async (e, {
626
669
  deleteExisting: t,
627
670
  addMissing: s,
628
671
  forceRenegotiation: o,
629
672
  contentHint: r,
630
673
  simulcastEncodings: i,
631
674
  degradationPreference: c,
632
- sendEncodings: d
675
+ sendEncodings: l
633
676
  } = {}) => {
634
677
  const S = P(
635
678
  {
@@ -640,7 +683,7 @@ class ln {
640
683
  excludeMimeTypesVideoCodecs: this.excludeMimeTypesVideoCodecs
641
684
  }
642
685
  );
643
- return a("replaceMediaStream"), this.sipConnector.replaceMediaStream(e, {
686
+ return u("replaceMediaStream"), this.sipConnector.replaceMediaStream(e, {
644
687
  deleteExisting: t,
645
688
  addMissing: s,
646
689
  forceRenegotiation: o,
@@ -648,54 +691,60 @@ class ln {
648
691
  sendEncodings: B({
649
692
  mediaStream: e,
650
693
  simulcastEncodings: i,
651
- sendEncodings: d
694
+ sendEncodings: l
652
695
  }),
653
696
  onAddedTransceiver: S
654
697
  });
655
698
  });
656
- u(this, "askPermissionToEnableCam", async () => {
699
+ a(this, "askPermissionToEnableCam", async () => {
657
700
  if (this.sipConnector.isCallActive)
658
- return a("askPermissionToEnableCam"), this.sipConnector.askPermissionToEnableCam();
701
+ return u("askPermissionToEnableCam"), this.sipConnector.askPermissionToEnableCam();
659
702
  });
660
- u(this, "resolveHandleReadyRemoteStreamsDebounced", ({
703
+ a(this, "resolveHandleReadyRemoteStreamsDebounced", ({
661
704
  onReadyRemoteStreams: e
662
- }) => he(() => {
705
+ }) => fe(() => {
663
706
  const t = this.sipConnector.getRemoteStreams();
664
- a("remoteStreams", t), t && e(t);
707
+ u("remoteStreams", t), t && e(t);
665
708
  }, 200));
666
- u(this, "resolveHandleReadyRemoteStreams", ({
709
+ a(this, "resolveHandleReadyRemoteStreams", ({
667
710
  onReadyRemoteStreams: e
668
711
  }) => ({ track: t }) => {
669
712
  Ze(t) && e();
670
713
  });
671
- u(this, "getRemoteStreams", () => (a("getRemoteStreams"), this.sipConnector.getRemoteStreams()));
672
- u(this, "onUseLicense", (e) => (a("onUseLicense"), this.sipConnector.onSession("useLicense", e)));
673
- u(this, "onMustStopPresentation", (e) => (a("onMustStopPresentation"), this.sipConnector.onSession("mustStopPresentation", e)));
674
- u(this, "onMoveToSpectators", (e) => (a("onMoveToSpectators"), this.sipConnector.onSession(ce, e)));
675
- u(this, "onMoveToParticipants", (e) => (a("onMoveToParticipants"), this.sipConnector.onSession(ae, e)));
676
- this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.sipConnector = e, this.on = this.sipConnector.on.bind(e), this.once = this.sipConnector.once.bind(e), this.onceRace = this.sipConnector.onceRace.bind(e), this.wait = this.sipConnector.wait.bind(e), this.off = this.sipConnector.off.bind(e), this.onSession = this.sipConnector.onSession.bind(e), this.onceSession = this.sipConnector.onceSession.bind(e), this.onceRaceSession = this.sipConnector.onceRaceSession.bind(e), this.waitSession = this.sipConnector.waitSession.bind(e), this.offSession = this.sipConnector.offSession.bind(e), this.sendDTMF = this.sipConnector.sendDTMF.bind(e), this.hangUp = this.sipConnector.hangUp.bind(e), this.declineToIncomingCall = this.sipConnector.declineToIncomingCall.bind(e), this.isConfigured = this.sipConnector.isConfigured.bind(e), this.sendChannels = this.sipConnector.sendChannels.bind(e), this.checkTelephony = this.sipConnector.checkTelephony.bind(e), this.waitChannels = this.sipConnector.waitChannels.bind(e), this.ping = this.sipConnector.ping.bind(e);
677
- }
678
- get isRegistered() {
679
- return this.sipConnector.isRegistered;
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)));
719
+ return this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.sipConnector = e, new Proxy(this, {
720
+ get: (o, r, i) => {
721
+ if (typeof r == "string" && en.has(r) && r in this.sipConnector) {
722
+ const l = Reflect.get(this.sipConnector, r, this.sipConnector);
723
+ return typeof l == "function" ? l.bind(this.sipConnector) : l;
724
+ }
725
+ const c = Reflect.get(o, r, i);
726
+ return typeof c == "function" ? c.bind(o) : c;
727
+ }
728
+ });
680
729
  }
681
730
  }
682
731
  export {
683
- L as EEventsMainCAM,
684
- Cn as EEventsMic,
685
- fn as EEventsSyncMediaState,
686
- mn as EMimeTypesVideoCodecs,
687
- Rn as EUseLicense,
688
- ln as SipConnectorFacade,
689
- gn as causes,
690
- pn as constants,
691
- An as debug,
692
- tn as default,
693
- yn as disableDebug,
732
+ x as EEventsMainCAM,
733
+ mn as EEventsMic,
734
+ hn as EEventsSyncMediaState,
735
+ Rn as EMimeTypesVideoCodecs,
736
+ gn as EUseLicense,
737
+ Sn as SipConnectorFacade,
738
+ pn as causes,
739
+ yn as constants,
740
+ _n as debug,
741
+ sn as default,
742
+ En as disableDebug,
694
743
  Tn as enableDebug,
695
- En as eventNames,
744
+ bn as eventNames,
696
745
  De as getCodecFromSender,
697
- bn as hasCanceledCallError,
746
+ Mn as hasCanceledCallError,
698
747
  dn as resolveVideoSendingBalancer,
699
748
  ie as setParametersToSender,
700
- un as tools
749
+ ln as tools
701
750
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sip-connector",
3
- "version": "13.1.0",
3
+ "version": "13.3.0",
4
4
  "description": "Module for connect to Vinteo server",
5
5
  "keywords": [
6
6
  "webrtc",
@@ -64,7 +64,7 @@
64
64
  "dependencies": {
65
65
  "@krivega/cancelable-promise": "^1.1.3",
66
66
  "@krivega/jssip": "^5.1.0",
67
- "debug": "^4.3.7",
67
+ "debug": "^4.4.0",
68
68
  "events-constructor": "^1.3.0",
69
69
  "repeated-calls": "^2.3.0",
70
70
  "sequent-promises": "^2.0.1",
@@ -105,14 +105,14 @@
105
105
  "ts-node": "^10.9.2",
106
106
  "tsc-files": "^1.1.4",
107
107
  "typescript": "^5.7.2",
108
- "vite": "^6.0.2",
108
+ "vite": "^6.0.3",
109
109
  "vite-plugin-dts": "^4.3.0",
110
- "vite-tsconfig-paths": "^5.1.3"
110
+ "vite-tsconfig-paths": "^5.1.4"
111
111
  },
112
112
  "peerDependencies": {
113
113
  "@krivega/cancelable-promise": "^1.1.3",
114
114
  "@krivega/jssip": "^5.1.0",
115
- "debug": "^4.3.7",
115
+ "debug": "^4.4.0",
116
116
  "events-constructor": "^1.3.0",
117
117
  "repeated-calls": "^2.2.1",
118
118
  "sequent-promises": "^2.0.1",