sip-connector 14.1.2-1 → 14.1.2-2

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.
Files changed (97) hide show
  1. package/dist/SipConnector-DGYQOyHy.cjs +1 -0
  2. package/dist/SipConnector-DTNc5BfW.js +1352 -0
  3. package/dist/doMock.cjs +1 -1
  4. package/dist/doMock.js +1 -1
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +85 -86
  7. package/dist/src/SipConnector.d.ts +235 -0
  8. package/dist/{SipConnectorFacade → src/SipConnectorFacade}/SipConnectorFacade.d.ts +1 -1
  9. package/package.json +1 -1
  10. package/dist/SipConnector-CZwqeStw.cjs +0 -1
  11. package/dist/SipConnector-DfaRIKWv.js +0 -1345
  12. package/dist/SipConnector.d.ts +0 -315
  13. package/dist/utils/utils.d.ts +0 -4
  14. /package/dist/{SipConnectorFacade → src/SipConnectorFacade}/index.d.ts +0 -0
  15. /package/dist/{__fixtures__ → src/__fixtures__}/BaseSession.mock.d.ts +0 -0
  16. /package/dist/{__fixtures__ → src/__fixtures__}/RTCPeerConnectionMock.d.ts +0 -0
  17. /package/dist/{__fixtures__ → src/__fixtures__}/RTCRtpSenderMock.d.ts +0 -0
  18. /package/dist/{__fixtures__ → src/__fixtures__}/RTCSessionMock.d.ts +0 -0
  19. /package/dist/{__fixtures__ → src/__fixtures__}/Registrator.mock.d.ts +0 -0
  20. /package/dist/{__fixtures__ → src/__fixtures__}/Request.mock.d.ts +0 -0
  21. /package/dist/{__fixtures__ → src/__fixtures__}/UA.mock.d.ts +0 -0
  22. /package/dist/{__fixtures__ → src/__fixtures__}/WebSocketInterface.mock.d.ts +0 -0
  23. /package/dist/{__fixtures__ → src/__fixtures__}/accountNotify.d.ts +0 -0
  24. /package/dist/{__fixtures__ → src/__fixtures__}/channels.d.ts +0 -0
  25. /package/dist/{__fixtures__ → src/__fixtures__}/channelsNotify.d.ts +0 -0
  26. /package/dist/{__fixtures__ → src/__fixtures__}/conferenceParticipantTokenIssuedNotify.d.ts +0 -0
  27. /package/dist/{__fixtures__ → src/__fixtures__}/delayPromise.d.ts +0 -0
  28. /package/dist/{__fixtures__ → src/__fixtures__}/enterRoom.d.ts +0 -0
  29. /package/dist/{__fixtures__ → src/__fixtures__}/index.d.ts +0 -0
  30. /package/dist/{__fixtures__ → src/__fixtures__}/jssip.mock.d.ts +0 -0
  31. /package/dist/{__fixtures__ → src/__fixtures__}/mediaState.d.ts +0 -0
  32. /package/dist/{__fixtures__ → src/__fixtures__}/participantMoveRequests.d.ts +0 -0
  33. /package/dist/{__fixtures__ → src/__fixtures__}/participantNotify.d.ts +0 -0
  34. /package/dist/{__fixtures__ → src/__fixtures__}/remoteCallerData.d.ts +0 -0
  35. /package/dist/{__fixtures__ → src/__fixtures__}/utils.d.ts +0 -0
  36. /package/dist/{__fixtures__ → src/__fixtures__}/webcastNotify.d.ts +0 -0
  37. /package/dist/{causes.d.ts → src/causes.d.ts} +0 -0
  38. /package/dist/{constants.d.ts → src/constants.d.ts} +0 -0
  39. /package/dist/{doMock.d.ts → src/doMock.d.ts} +0 -0
  40. /package/dist/{eventNames.d.ts → src/eventNames.d.ts} +0 -0
  41. /package/dist/{getExtraHeadersRemoteAddress.d.ts → src/getExtraHeadersRemoteAddress.d.ts} +0 -0
  42. /package/dist/{headers.d.ts → src/headers.d.ts} +0 -0
  43. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  44. /package/dist/{logger.d.ts → src/logger.d.ts} +0 -0
  45. /package/dist/{setParametersToSender → src/setParametersToSender}/configureDegradationPreference.d.ts +0 -0
  46. /package/dist/{setParametersToSender → src/setParametersToSender}/configureEmptyEncodings.d.ts +0 -0
  47. /package/dist/{setParametersToSender → src/setParametersToSender}/configureEncodings.d.ts +0 -0
  48. /package/dist/{setParametersToSender → src/setParametersToSender}/configureMaxBitrate.d.ts +0 -0
  49. /package/dist/{setParametersToSender → src/setParametersToSender}/configureScaleResolutionDownBy.d.ts +0 -0
  50. /package/dist/{setParametersToSender → src/setParametersToSender}/hasChangedRTCRtpSendParameters.d.ts +0 -0
  51. /package/dist/{setParametersToSender → src/setParametersToSender}/index.d.ts +0 -0
  52. /package/dist/{setParametersToSender → src/setParametersToSender}/resolveHasNeedToUpdateItemEncoding.d.ts +0 -0
  53. /package/dist/{setParametersToSender → src/setParametersToSender}/setParametersToSender.d.ts +0 -0
  54. /package/dist/{tools → src/tools}/__fixtures__/call.d.ts +0 -0
  55. /package/dist/{tools → src/tools}/__fixtures__/connectToServer.d.ts +0 -0
  56. /package/dist/{tools → src/tools}/__fixtures__/hasValidUri.d.ts +0 -0
  57. /package/dist/{tools → src/tools}/__fixtures__/permissions.d.ts +0 -0
  58. /package/dist/{tools → src/tools}/__fixtures__/processRequest.d.ts +0 -0
  59. /package/dist/{tools → src/tools}/__tests-utils__/parseObject.d.ts +0 -0
  60. /package/dist/{tools → src/tools}/__tests-utils__/resolveParseArray.d.ts +0 -0
  61. /package/dist/{tools → src/tools}/error/getLinkError.d.ts +0 -0
  62. /package/dist/{tools → src/tools}/error/getTypeFromError.d.ts +0 -0
  63. /package/dist/{tools → src/tools}/error/getValuesFromError.d.ts +0 -0
  64. /package/dist/{tools → src/tools}/error/index.d.ts +0 -0
  65. /package/dist/{tools → src/tools}/error/stringifyMessage.d.ts +0 -0
  66. /package/dist/{tools → src/tools}/generateSimulcastEncodings.d.ts +0 -0
  67. /package/dist/{tools → src/tools}/getExtraHeaders.d.ts +0 -0
  68. /package/dist/{tools → src/tools}/getUserAgent.d.ts +0 -0
  69. /package/dist/{tools → src/tools}/hasPurgatory.d.ts +0 -0
  70. /package/dist/{tools → src/tools}/index.d.ts +0 -0
  71. /package/dist/{tools → src/tools}/prepareMediaStream.d.ts +0 -0
  72. /package/dist/{tools → src/tools}/resolveUpdateTransceiver.d.ts +0 -0
  73. /package/dist/{tools → src/tools}/sendDTMFAccumulated.d.ts +0 -0
  74. /package/dist/{tools → src/tools}/setVideoTrackContentHints.d.ts +0 -0
  75. /package/dist/{tools → src/tools}/syncMediaState/index.d.ts +0 -0
  76. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStartMainCam.d.ts +0 -0
  77. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStartMic.d.ts +0 -0
  78. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStopMainCam.d.ts +0 -0
  79. /package/dist/{tools → src/tools}/syncMediaState/resolveOnStopMic.d.ts +0 -0
  80. /package/dist/{types.d.ts → src/types.d.ts} +0 -0
  81. /package/dist/{utils → src/utils}/errors.d.ts +0 -0
  82. /package/dist/{utils → src/utils}/findSenderByStream.d.ts +0 -0
  83. /package/dist/{utils → src/utils}/findVideoSender.d.ts +0 -0
  84. /package/dist/{utils → src/utils}/findVideoTrack.d.ts +0 -0
  85. /package/dist/{utils → src/utils}/getCodecFromSender.d.ts +0 -0
  86. /package/dist/{utils → src/utils}/replaceForbiddenSymbolsWithUnderscore.d.ts +0 -0
  87. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/balance.d.ts +0 -0
  88. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/getMaxBitrateByWidth.d.ts +0 -0
  89. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/getMaxBitrateByWidthAndCodec.d.ts +0 -0
  90. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/hasAv1Codec.d.ts +0 -0
  91. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/hasIncludesString.d.ts +0 -0
  92. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/index.d.ts +0 -0
  93. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/processSender.d.ts +0 -0
  94. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/scaleBitrate.d.ts +0 -0
  95. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/scaleBitrateByCodec.d.ts +0 -0
  96. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/scaleResolutionAndBitrate.d.ts +0 -0
  97. /package/dist/{videoSendingBalancer → src/videoSendingBalancer}/setEncodingsToSender.d.ts +0 -0
package/dist/doMock.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var F=Object.defineProperty;var L=(o,e,t)=>e in o?F(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var r=(o,e,t)=>L(o,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./SipConnector-CZwqeStw.cjs"),V=require("@krivega/jssip/lib/NameAddrHeader"),U=require("@krivega/jssip/lib/URI"),z=require("node:events"),x=require("@krivega/jssip/lib/SIPMessage"),y=require("webrtc-mock"),A=require("events-constructor"),u=require("@krivega/jssip");class v extends x.IncomingRequest{constructor(t){super();r(this,"headers");this.headers=new Headers(t)}getHeader(t){return this.headers.get(t)??""}}class q{constructor({originator:e="local",eventHandlers:t}){r(this,"originator");r(this,"connection");r(this,"events");r(this,"remote_identity");r(this,"mutedOptions",{audio:!1,video:!1});this.originator=e,this.events=new A(p.SESSION_EVENT_NAMES),this.initEvents(t)}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}set data(e){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(e){throw new Error("Method not implemented.")}terminate(e){throw new Error("Method not implemented.")}async sendInfo(e,t,n){throw new Error("Method not implemented.")}hold(e,t){throw new Error("Method not implemented.")}unhold(e,t){throw new Error("Method not implemented.")}async renegotiate(e,t){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(e){throw new Error("Method not implemented.")}unmute(e){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(e,t){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(e,t){throw new Error("Method not implemented.")}addListener(e,t){throw new Error("Method not implemented.")}once(e,t){throw new Error("Method not implemented.")}removeListener(e,t){throw new Error("Method not implemented.")}off(e,t){throw new Error("Method not implemented.")}removeAllListeners(e){throw new Error("Method not implemented.")}setMaxListeners(e){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(e){throw new Error("Method not implemented.")}rawListeners(e){throw new Error("Method not implemented.")}emit(e,...t){throw new Error("Method not implemented.")}listenerCount(e){throw new Error("Method not implemented.")}prependListener(e,t){throw new Error("Method not implemented.")}prependOnceListener(e,t){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(e){Object.entries(e).forEach(([t,n])=>this.on(t,n))}on(e,t){return this.events.on(e,t),this}trigger(e,t){this.events.trigger(e,t)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(e){return e}async updatePresentation(e){return e}async stopPresentation(e){return e}isEstablished(){return!0}}class H{constructor({track:e}={}){r(this,"dtmf",null);r(this,"track",null);r(this,"transport",null);r(this,"transform",null);r(this,"parameters",{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}});r(this,"parametersGets");this.track=e??null}async getStats(){throw new Error("Method not implemented.")}async replaceTrack(e){this.track=e??null}async setParameters(e){if(e!==this.parametersGets)throw new Error("Failed to execute 'setParameters' on 'RTCRtpSender': Read-only field modified in setParameters().");const{transactionId:t}=this.parameters;this.parameters={...this.parameters,...e,transactionId:`${Number(t)+1}`}}getParameters(){return this.parametersGets={...this.parameters},this.parametersGets}setStreams(){throw new Error("Method not implemented.")}}class Y{constructor(e,t){r(this,"senders",[]);r(this,"receivers",[]);r(this,"canTrickleIceCandidates");r(this,"connectionState");r(this,"currentLocalDescription");r(this,"currentRemoteDescription");r(this,"iceConnectionState");r(this,"iceGatheringState");r(this,"idpErrorInfo");r(this,"idpLoginUrl");r(this,"localDescription");r(this,"onconnectionstatechange");r(this,"ondatachannel");r(this,"onicecandidate");r(this,"onicecandidateerror",null);r(this,"oniceconnectionstatechange");r(this,"onicegatheringstatechange");r(this,"onnegotiationneeded");r(this,"onsignalingstatechange");r(this,"ontrack");r(this,"peerIdentity");r(this,"pendingLocalDescription");r(this,"pendingRemoteDescription");r(this,"remoteDescription");r(this,"sctp",null);r(this,"signalingState");r(this,"getReceivers",()=>this.receivers);r(this,"getSenders",()=>this.senders);r(this,"addTrack",e=>{const t=new H({track:e});return this.senders.push(t),t});this.receivers=t.map(n=>({track:n}))}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(e){throw new Error("Method not implemented.")}addTransceiver(e,t){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(e,t){throw new Error("Method not implemented.")}createDataChannel(e,t){throw new Error("Method not implemented.")}async createOffer(e,t,n){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(e){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(e){throw new Error("Method not implemented.")}setConfiguration(e){throw new Error("Method not implemented.")}async setLocalDescription(e){throw new Error("Method not implemented.")}async setRemoteDescription(e){throw new Error("Method not implemented.")}addEventListener(e,t,n){throw new Error("Method not implemented.")}removeEventListener(e,t,n){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}}function j(o){const e=o.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const S=400,O="777",B=o=>o.getVideoTracks().length>0,a=class a extends q{constructor({url:t="",mediaStream:n,eventHandlers:i,originator:d}){super({originator:d,eventHandlers:i});r(this,"url");r(this,"status_code");r(this,"answer",jest.fn(({mediaStream:t})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(t),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},S)}));r(this,"isEndedInner",!1);this.url=t,this.initPeerconnection(n)}static setStartPresentationError(t,{count:n=Number.POSITIVE_INFINITY}={}){this.startPresentationError=t,this.countStartPresentationError=n}static resetStartPresentationError(){this.startPresentationError=void 0,this.countStartPresentationError=Number.POSITIVE_INFINITY,this.countStartsPresentation=0}async startPresentation(t){if(a.countStartsPresentation+=1,a.startPresentationError&&a.countStartsPresentation<a.countStartPresentationError)throw a.startPresentationError;return super.startPresentation(t)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const n=y.createAudioMediaStreamTrackMock();n.id="mainaudio1";const i=[n];if(B(t)){const c=y.createVideoMediaStreamTrackMock();c.id="mainvideo1",i.push(c)}this.connection=new Y(void 0,i),this.addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},S)}connect(t){const n=j(t);setTimeout(()=>{this.url.includes(O)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:p.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",{room:n})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},S)}terminate({status_code:t,cause:n}={}){return this.status_code=t,this.trigger("ended",{status_code:t,cause:n,originator:"local"}),this.isEndedInner=!1,this}async terminateAsync({status_code:t,cause:n}={}){this.terminate({status_code:t,cause:n})}terminateRemote({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t,originator:"remote"}),this}addStream(t,n="getTracks"){t[n]().forEach(i=>this.connection.addTrack(i))}forEachSenders(t){const n=this.connection.getSenders();for(const i of n)t(i);return n}toggleMuteAudio(t){this.forEachSenders(({track:n})=>{n&&n.kind==="audio"&&(n.enabled=!t)})}toggleMuteVideo(t){this.forEachSenders(({track:n})=>{n&&n.kind==="video"&&(n.enabled=!t)})}mute(t){t.audio&&(this.mutedOptions.audio=!0,this.toggleMuteAudio(this.mutedOptions.audio)),t.video&&(this.mutedOptions.video=!0,this.toggleMuteVideo(this.mutedOptions.video)),this.onmute(t)}unmute(t){t.audio&&(this.mutedOptions.audio=!1),t.video&&(this.mutedOptions.video=!1),this.trigger("unmuted",t)}isMuted(){return this.mutedOptions}async replaceMediaStream(t){}onmute({audio:t,video:n}){this.trigger("muted",{audio:t,video:n})}async sendInfo(){}isEnded(){return this.isEndedInner}newInfo(t){this.trigger("newInfo",t)}};r(a,"startPresentationError"),r(a,"countStartPresentationError",Number.POSITIVE_INFINITY),r(a,"countStartsPresentation",0);let g=a;class G{constructor(){r(this,"extraHeaders",[])}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const h="PASSWORD_CORRECT",I="PASSWORD_CORRECT_2",k="NAME_INCORRECT",l=400,f={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},N={status_code:200,reason_phrase:"OK"},P={status_code:401,reason_phrase:"Unauthorized"},s=class s{constructor(e){r(this,"events");r(this,"registratorInner");r(this,"call",jest.fn((e,t)=>{const{mediaStream:n,eventHandlers:i}=t;return this.session=new g({url:e,mediaStream:n,eventHandlers:i,originator:"local"}),this.session.connect(e),this.session}));r(this,"startedTimeout");r(this,"stopedTimeout");r(this,"session");r(this,"isRegisteredInner");r(this,"isConnectedInner");r(this,"configuration");this.events=new A(p.UA_JSSIP_EVENT_NAMES);const[t,n]=e.uri.split(":"),[i,d]=n.split("@"),c={...e,uri:new u.URI(t,i,d)};this.configuration=c,this.registratorInner=new G}static setStartError(e,{count:t=Number.POSITIVE_INFINITY}={}){this.startError=e,this.countStartError=t}static resetStartError(){this.startError=void 0,this.countStartError=Number.POSITIVE_INFINITY,this.countStarts=0}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}start(){if(s.countStarts+=1,s.startError&&s.countStarts<s.countStartError){this.trigger("disconnected",s.startError);return}this.register()}stop(){this.startedTimeout&&clearTimeout(this.startedTimeout),this.stopedTimeout&&clearTimeout(this.stopedTimeout),this.unregister(),this.isStarted()?this.stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:!0,socket:f})},l):this.trigger("disconnected",{error:!0,socket:f})}on(e,t){return this.events.on(e,t),this}once(e,t){return this.events.once(e,t),this}off(e,t){return this.events.off(e,t),this}removeAllListeners(){return this.events.removeEventHandlers(),this}trigger(e,t){this.events.trigger(e,t)}terminateSessions(){var e;(e=this.session)==null||e.terminate()}set(e,t){return this.configuration[e]=t,!0}register(){this.startedTimeout&&clearTimeout(this.startedTimeout);const{password:e,register:t,uri:n}=this.configuration;t===!0&&n.user.includes(k)?(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:u.C.causes.REJECTED})},l)):!this.isRegistered()&&t===!0&&(e===h||e===I)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:N})},l)):t===!0&&e!==h&&e!==I&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:u.C.causes.REJECTED})},l)),s.isAvailableTelephony?(this.trigger("connected",{socket:f}),this.isConnectedInner=!0):this.stop()}unregister(){this.isRegisteredInner=!1,this.isConnectedInner=!1,this.trigger("unregistered",{response:N})}isRegistered(){return this.isRegisteredInner===!0}isConnected(){return this.isConnectedInner===!0}isStarted(){return this.configuration.register===!0&&this.isRegisteredInner===!0||this.configuration.register!==!0&&this.isConnectedInner===!0}newSipEvent(e){this.trigger("sipEvent",e)}registrator(){return this.registratorInner}};r(s,"isAvailableTelephony",!0),r(s,"startError"),r(s,"countStartError",Number.POSITIVE_INFINITY),r(s,"countStarts",0);let M=s;class J{constructor(e){r(this,"url");this.url=e}}class K extends z.EventEmitter{constructor(t,n){super();r(this,"contentType");r(this,"body");this.contentType=t,this.body=n}}const T="remote",$=(o,e)=>{const t=new v(e),n={originator:T,request:t,info:new K("","")};o.newInfo(n)},X=(o,e)=>{const n={event:"sipEvent",request:new v(e)};o.newSipEvent(n)},Q=(o,{incomingNumber:e="1234",displayName:t,host:n})=>{const i=new g({originator:T,eventHandlers:{}}),d=new U("sip",e,n);i.remote_identity=new V(d,t);const c=new v([]);o.trigger("newRTCSession",{originator:T,session:i,request:c})},Z=(o,e)=>{e?o.trigger("failed",e):o.trigger("failed",o)},W={triggerNewInfo:$,triggerNewSipEvent:X,triggerIncomingSession:Q,triggerFailIncomingSession:Z,WebSocketInterface:J,UA:M,C:{INVITE:"INVITE"}},E="user",m="displayName",w="SIP_SERVER_URL",R="SIP_WEB_SOCKET_SERVER_URL",ee=new W.WebSocketInterface(R),C={userAgent:"Chrome",sipServerUrl:w,sipWebSocketServerURL:R},te={...C},b={...C,user:E,password:h,register:!0},re={...b,displayName:m},ne={...C,displayName:m,register:!1},_={session_timers:!1,sockets:[ee],user_agent:"Chrome",sdp_semantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},oe={..._,password:h,uri:new u.URI("sip",E,w),display_name:"",register:!0},ie={..._,password:h,uri:new u.URI("sip",E,w),display_name:m,register:!0},se={..._,display_name:m,register:!1},ae={..._,display_name:"",register:!1},D="10.10.10.10",de=[`X-Vinteo-Remote: ${D}`],ce=()=>new p.SipConnector({JsSIP:W});exports.FAILED_CONFERENCE_NUMBER=O;exports.NAME_INCORRECT=k;exports.PASSWORD_CORRECT=h;exports.PASSWORD_CORRECT_2=I;exports.SIP_SERVER_URL=w;exports.SIP_WEB_SOCKET_SERVER_URL=R;exports.dataForConnectionWithAuthorization=b;exports.dataForConnectionWithAuthorizationWithDisplayName=re;exports.dataForConnectionWithoutAuthorization=ne;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=te;exports.displayName=m;exports.doMockSipConnector=ce;exports.extraHeadersRemoteAddress=de;exports.remoteAddress=D;exports.uaConfigurationWithAuthorization=oe;exports.uaConfigurationWithAuthorizationWithDisplayName=ie;exports.uaConfigurationWithoutAuthorization=se;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ae;exports.user=E;
1
+ "use strict";var F=Object.defineProperty;var L=(o,e,t)=>e in o?F(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var r=(o,e,t)=>L(o,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./SipConnector-DGYQOyHy.cjs"),V=require("@krivega/jssip/lib/NameAddrHeader"),U=require("@krivega/jssip/lib/URI"),z=require("node:events"),x=require("@krivega/jssip/lib/SIPMessage"),y=require("webrtc-mock"),A=require("events-constructor"),u=require("@krivega/jssip");class v extends x.IncomingRequest{constructor(t){super();r(this,"headers");this.headers=new Headers(t)}getHeader(t){return this.headers.get(t)??""}}class q{constructor({originator:e="local",eventHandlers:t}){r(this,"originator");r(this,"connection");r(this,"events");r(this,"remote_identity");r(this,"mutedOptions",{audio:!1,video:!1});this.originator=e,this.events=new A(p.SESSION_EVENT_NAMES),this.initEvents(t)}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}set data(e){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(e){throw new Error("Method not implemented.")}terminate(e){throw new Error("Method not implemented.")}async sendInfo(e,t,n){throw new Error("Method not implemented.")}hold(e,t){throw new Error("Method not implemented.")}unhold(e,t){throw new Error("Method not implemented.")}async renegotiate(e,t){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(e){throw new Error("Method not implemented.")}unmute(e){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(e,t){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(e,t){throw new Error("Method not implemented.")}addListener(e,t){throw new Error("Method not implemented.")}once(e,t){throw new Error("Method not implemented.")}removeListener(e,t){throw new Error("Method not implemented.")}off(e,t){throw new Error("Method not implemented.")}removeAllListeners(e){throw new Error("Method not implemented.")}setMaxListeners(e){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(e){throw new Error("Method not implemented.")}rawListeners(e){throw new Error("Method not implemented.")}emit(e,...t){throw new Error("Method not implemented.")}listenerCount(e){throw new Error("Method not implemented.")}prependListener(e,t){throw new Error("Method not implemented.")}prependOnceListener(e,t){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(e){Object.entries(e).forEach(([t,n])=>this.on(t,n))}on(e,t){return this.events.on(e,t),this}trigger(e,t){this.events.trigger(e,t)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(e){return e}async updatePresentation(e){return e}async stopPresentation(e){return e}isEstablished(){return!0}}class H{constructor({track:e}={}){r(this,"dtmf",null);r(this,"track",null);r(this,"transport",null);r(this,"transform",null);r(this,"parameters",{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}});r(this,"parametersGets");this.track=e??null}async getStats(){throw new Error("Method not implemented.")}async replaceTrack(e){this.track=e??null}async setParameters(e){if(e!==this.parametersGets)throw new Error("Failed to execute 'setParameters' on 'RTCRtpSender': Read-only field modified in setParameters().");const{transactionId:t}=this.parameters;this.parameters={...this.parameters,...e,transactionId:`${Number(t)+1}`}}getParameters(){return this.parametersGets={...this.parameters},this.parametersGets}setStreams(){throw new Error("Method not implemented.")}}class Y{constructor(e,t){r(this,"senders",[]);r(this,"receivers",[]);r(this,"canTrickleIceCandidates");r(this,"connectionState");r(this,"currentLocalDescription");r(this,"currentRemoteDescription");r(this,"iceConnectionState");r(this,"iceGatheringState");r(this,"idpErrorInfo");r(this,"idpLoginUrl");r(this,"localDescription");r(this,"onconnectionstatechange");r(this,"ondatachannel");r(this,"onicecandidate");r(this,"onicecandidateerror",null);r(this,"oniceconnectionstatechange");r(this,"onicegatheringstatechange");r(this,"onnegotiationneeded");r(this,"onsignalingstatechange");r(this,"ontrack");r(this,"peerIdentity");r(this,"pendingLocalDescription");r(this,"pendingRemoteDescription");r(this,"remoteDescription");r(this,"sctp",null);r(this,"signalingState");r(this,"getReceivers",()=>this.receivers);r(this,"getSenders",()=>this.senders);r(this,"addTrack",e=>{const t=new H({track:e});return this.senders.push(t),t});this.receivers=t.map(n=>({track:n}))}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(e){throw new Error("Method not implemented.")}addTransceiver(e,t){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(e,t){throw new Error("Method not implemented.")}createDataChannel(e,t){throw new Error("Method not implemented.")}async createOffer(e,t,n){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(e){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(e){throw new Error("Method not implemented.")}setConfiguration(e){throw new Error("Method not implemented.")}async setLocalDescription(e){throw new Error("Method not implemented.")}async setRemoteDescription(e){throw new Error("Method not implemented.")}addEventListener(e,t,n){throw new Error("Method not implemented.")}removeEventListener(e,t,n){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}}function j(o){const e=o.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const S=400,O="777",B=o=>o.getVideoTracks().length>0,a=class a extends q{constructor({url:t="",mediaStream:n,eventHandlers:i,originator:d}){super({originator:d,eventHandlers:i});r(this,"url");r(this,"status_code");r(this,"answer",jest.fn(({mediaStream:t})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(t),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},S)}));r(this,"isEndedInner",!1);this.url=t,this.initPeerconnection(n)}static setStartPresentationError(t,{count:n=Number.POSITIVE_INFINITY}={}){this.startPresentationError=t,this.countStartPresentationError=n}static resetStartPresentationError(){this.startPresentationError=void 0,this.countStartPresentationError=Number.POSITIVE_INFINITY,this.countStartsPresentation=0}async startPresentation(t){if(a.countStartsPresentation+=1,a.startPresentationError&&a.countStartsPresentation<a.countStartPresentationError)throw a.startPresentationError;return super.startPresentation(t)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const n=y.createAudioMediaStreamTrackMock();n.id="mainaudio1";const i=[n];if(B(t)){const c=y.createVideoMediaStreamTrackMock();c.id="mainvideo1",i.push(c)}this.connection=new Y(void 0,i),this.addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},S)}connect(t){const n=j(t);setTimeout(()=>{this.url.includes(O)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:p.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",{room:n})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},S)}terminate({status_code:t,cause:n}={}){return this.status_code=t,this.trigger("ended",{status_code:t,cause:n,originator:"local"}),this.isEndedInner=!1,this}async terminateAsync({status_code:t,cause:n}={}){this.terminate({status_code:t,cause:n})}terminateRemote({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t,originator:"remote"}),this}addStream(t,n="getTracks"){t[n]().forEach(i=>this.connection.addTrack(i))}forEachSenders(t){const n=this.connection.getSenders();for(const i of n)t(i);return n}toggleMuteAudio(t){this.forEachSenders(({track:n})=>{n&&n.kind==="audio"&&(n.enabled=!t)})}toggleMuteVideo(t){this.forEachSenders(({track:n})=>{n&&n.kind==="video"&&(n.enabled=!t)})}mute(t){t.audio&&(this.mutedOptions.audio=!0,this.toggleMuteAudio(this.mutedOptions.audio)),t.video&&(this.mutedOptions.video=!0,this.toggleMuteVideo(this.mutedOptions.video)),this.onmute(t)}unmute(t){t.audio&&(this.mutedOptions.audio=!1),t.video&&(this.mutedOptions.video=!1),this.trigger("unmuted",t)}isMuted(){return this.mutedOptions}async replaceMediaStream(t){}onmute({audio:t,video:n}){this.trigger("muted",{audio:t,video:n})}async sendInfo(){}isEnded(){return this.isEndedInner}newInfo(t){this.trigger("newInfo",t)}};r(a,"startPresentationError"),r(a,"countStartPresentationError",Number.POSITIVE_INFINITY),r(a,"countStartsPresentation",0);let g=a;class G{constructor(){r(this,"extraHeaders",[])}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const h="PASSWORD_CORRECT",I="PASSWORD_CORRECT_2",k="NAME_INCORRECT",l=400,f={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},N={status_code:200,reason_phrase:"OK"},P={status_code:401,reason_phrase:"Unauthorized"},s=class s{constructor(e){r(this,"events");r(this,"registratorInner");r(this,"call",jest.fn((e,t)=>{const{mediaStream:n,eventHandlers:i}=t;return this.session=new g({url:e,mediaStream:n,eventHandlers:i,originator:"local"}),this.session.connect(e),this.session}));r(this,"startedTimeout");r(this,"stopedTimeout");r(this,"session");r(this,"isRegisteredInner");r(this,"isConnectedInner");r(this,"configuration");this.events=new A(p.UA_JSSIP_EVENT_NAMES);const[t,n]=e.uri.split(":"),[i,d]=n.split("@"),c={...e,uri:new u.URI(t,i,d)};this.configuration=c,this.registratorInner=new G}static setStartError(e,{count:t=Number.POSITIVE_INFINITY}={}){this.startError=e,this.countStartError=t}static resetStartError(){this.startError=void 0,this.countStartError=Number.POSITIVE_INFINITY,this.countStarts=0}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}start(){if(s.countStarts+=1,s.startError&&s.countStarts<s.countStartError){this.trigger("disconnected",s.startError);return}this.register()}stop(){this.startedTimeout&&clearTimeout(this.startedTimeout),this.stopedTimeout&&clearTimeout(this.stopedTimeout),this.unregister(),this.isStarted()?this.stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:!0,socket:f})},l):this.trigger("disconnected",{error:!0,socket:f})}on(e,t){return this.events.on(e,t),this}once(e,t){return this.events.once(e,t),this}off(e,t){return this.events.off(e,t),this}removeAllListeners(){return this.events.removeEventHandlers(),this}trigger(e,t){this.events.trigger(e,t)}terminateSessions(){var e;(e=this.session)==null||e.terminate()}set(e,t){return this.configuration[e]=t,!0}register(){this.startedTimeout&&clearTimeout(this.startedTimeout);const{password:e,register:t,uri:n}=this.configuration;t===!0&&n.user.includes(k)?(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:u.C.causes.REJECTED})},l)):!this.isRegistered()&&t===!0&&(e===h||e===I)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:N})},l)):t===!0&&e!==h&&e!==I&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:u.C.causes.REJECTED})},l)),s.isAvailableTelephony?(this.trigger("connected",{socket:f}),this.isConnectedInner=!0):this.stop()}unregister(){this.isRegisteredInner=!1,this.isConnectedInner=!1,this.trigger("unregistered",{response:N})}isRegistered(){return this.isRegisteredInner===!0}isConnected(){return this.isConnectedInner===!0}isStarted(){return this.configuration.register===!0&&this.isRegisteredInner===!0||this.configuration.register!==!0&&this.isConnectedInner===!0}newSipEvent(e){this.trigger("sipEvent",e)}registrator(){return this.registratorInner}};r(s,"isAvailableTelephony",!0),r(s,"startError"),r(s,"countStartError",Number.POSITIVE_INFINITY),r(s,"countStarts",0);let M=s;class J{constructor(e){r(this,"url");this.url=e}}class K extends z.EventEmitter{constructor(t,n){super();r(this,"contentType");r(this,"body");this.contentType=t,this.body=n}}const T="remote",$=(o,e)=>{const t=new v(e),n={originator:T,request:t,info:new K("","")};o.newInfo(n)},X=(o,e)=>{const n={event:"sipEvent",request:new v(e)};o.newSipEvent(n)},Q=(o,{incomingNumber:e="1234",displayName:t,host:n})=>{const i=new g({originator:T,eventHandlers:{}}),d=new U("sip",e,n);i.remote_identity=new V(d,t);const c=new v([]);o.trigger("newRTCSession",{originator:T,session:i,request:c})},Z=(o,e)=>{e?o.trigger("failed",e):o.trigger("failed",o)},W={triggerNewInfo:$,triggerNewSipEvent:X,triggerIncomingSession:Q,triggerFailIncomingSession:Z,WebSocketInterface:J,UA:M,C:{INVITE:"INVITE"}},E="user",m="displayName",w="SIP_SERVER_URL",R="SIP_WEB_SOCKET_SERVER_URL",ee=new W.WebSocketInterface(R),C={userAgent:"Chrome",sipServerUrl:w,sipWebSocketServerURL:R},te={...C},b={...C,user:E,password:h,register:!0},re={...b,displayName:m},ne={...C,displayName:m,register:!1},_={session_timers:!1,sockets:[ee],user_agent:"Chrome",sdp_semantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},oe={..._,password:h,uri:new u.URI("sip",E,w),display_name:"",register:!0},ie={..._,password:h,uri:new u.URI("sip",E,w),display_name:m,register:!0},se={..._,display_name:m,register:!1},ae={..._,display_name:"",register:!1},D="10.10.10.10",de=[`X-Vinteo-Remote: ${D}`],ce=()=>new p.SipConnector({JsSIP:W});exports.FAILED_CONFERENCE_NUMBER=O;exports.NAME_INCORRECT=k;exports.PASSWORD_CORRECT=h;exports.PASSWORD_CORRECT_2=I;exports.SIP_SERVER_URL=w;exports.SIP_WEB_SOCKET_SERVER_URL=R;exports.dataForConnectionWithAuthorization=b;exports.dataForConnectionWithAuthorizationWithDisplayName=re;exports.dataForConnectionWithoutAuthorization=ne;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=te;exports.displayName=m;exports.doMockSipConnector=ce;exports.extraHeadersRemoteAddress=de;exports.remoteAddress=D;exports.uaConfigurationWithAuthorization=oe;exports.uaConfigurationWithAuthorizationWithDisplayName=ie;exports.uaConfigurationWithoutAuthorization=se;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ae;exports.user=E;
package/dist/doMock.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var k = Object.defineProperty;
2
2
  var A = (o, e, t) => e in o ? k(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
3
  var r = (o, e, t) => A(o, typeof e != "symbol" ? e + "" : e, t);
4
- import { o as b, R as D, U as L, S as W } from "./SipConnector-DfaRIKWv.js";
4
+ import { o as b, R as D, U as L, S as W } from "./SipConnector-DTNc5BfW.js";
5
5
  import V from "@krivega/jssip/lib/NameAddrHeader";
6
6
  import F from "@krivega/jssip/lib/URI";
7
7
  import { EventEmitter as x } from "node:events";
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var se=Object.defineProperty;var oe=(n,e,t)=>e in n?se(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>oe(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./SipConnector-CZwqeStw.cjs"),re=require("sequent-promises"),ie=require("stack-promises"),_=require("debug"),ce=require("@krivega/cancelable-promise"),ae=require("repeated-calls"),le=require("ts-debounce"),U=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 G=(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))(G||{});const ue=new Error("Unknown error"),de=(n=ue)=>{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!==void 0&&((r=t._ws)==null?void 0:r.readyState)===3?s="WS_CONNECTION_FAILED":U(n)!==void 0&&U(n)!==""&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},ge=n=>{let e="";try{e=JSON.stringify(n)}catch(t){o.logger("failed to stringify message",t)}return e},Ce=new Error("Unknown error"),Se=(n=Ce)=>{const{code:e,cause:t,message:s}=n,r=U(n),i={code:"",cause:"",message:""};return typeof s=="object"&&s!==null?i.message=ge(s):s&&(i.message=String(s)),r!==void 0&&r!==""&&(i.link=r),e!==void 0&&e!==""&&(i.code=e),t!==void 0&&t!==""&&(i.cause=t),i},fe=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:G,getLinkError:U,getTypeFromError:de,getValuesFromError:Se},Symbol.toStringTag,{value:"Module"})),me=({sessionId:n,remoteAddress:e,isMutedAudio:t,isMutedVideo:s,isRegistered:r,isPresentationCall:i})=>{const c=[],l=t?"0":"1",u=s?"0":"1";return c.push(`X-Vinteo-Mic-State: ${l}`,`X-Vinteo-MainCam-State: ${u}`),(r===!1||r===void 0)&&c.push("X-Vinteo-Purgatory-Call: yes"),n!==void 0&&n!==""&&c.push(`X-Vinteo-Session: ${n}`),i===!0&&c.push("X-Vinteo-Presentation-Call: yes"),e!==void 0&&e!==""&&c.push(`X-Vinteo-Remote: ${e}`),c},he="[@*!|]",Re="_",pe=n=>{let e=n;return e=e.replaceAll(new RegExp(he,"g"),Re),e},Ee=({appName:n,appVersion:e,browserName:t,browserVersion:s})=>{const i=`${pe(n)} ${e}`;return`ChromeNew - ${t===void 0?i:`${t} ${s}, ${i}`}`},ye=({isUnifiedSdpSemantic:n,appVersion:e,browserName:t,browserVersion:s,appName:r})=>n?Ee({appVersion:e,browserName:t,browserVersion:s,appName:r}):"Chrome",K="purgatory",I=n=>n===K,Te=n=>e=>[...e].map(s=>async()=>n(s)),Me=async({accumulatedKeys:n,sendKey:e,canRunTask:t})=>{const r=Te(e)(n);return re.sequentPromises(r,t)},be=n=>t=>(o.logger("onStartMainCam"),n.onSession("admin-start-main-cam",t)),ve=n=>t=>(o.logger("onStartMic"),n.onSession("admin-start-mic",t)),Ae=n=>t=>(o.logger("onStopMainCam"),n.onSession("admin-stop-main-cam",t)),_e=n=>t=>(o.logger("onStopMic"),n.onSession("admin-stop-mic",t)),Oe=({sipConnector:n})=>{const e=(f,p)=>({isSyncForced:m=!1})=>{if(m){f();return}p()},t=be(n),s=Ae(n),r=ve(n),i=_e(n);let c=()=>{},l=()=>{},u=()=>{},g=()=>{};const S=({onStartMainCamForced:f,onStartMainCamNotForced:p,onStopMainCamForced:m,onStopMainCamNotForced:h,onStartMicForced:E,onStartMicNotForced:y,onStopMicForced:T,onStopMicNotForced:M})=>{const A=e(f,p);c=t(A);const O=e(m,h);l=s(O);const N=e(E,y);u=r(N);const w=e(T,M);g=i(w)},C=()=>{c(),l(),u(),g()};return{start:f=>{S(f)},stop:()=>{C()}}},Ne=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:K,createSyncMediaState:Oe,error:fe,getExtraHeaders:me,getUserAgent:ye,hasPurgatory:I,sendDtmfAccumulated:Me},Symbol.toStringTag,{value:"Module"})),we=n=>[...n.keys()].map(e=>n.get(e)),Pe=(n,e)=>we(n).find(t=>(t==null?void 0:t.type)===e),Y=async n=>n.getStats().then(e=>{const t=Pe(e,"codec");return t==null?void 0:t.mimeType}),De=n=>n.find(e=>{var t;return((t=e.track)==null?void 0:t.kind)==="video"}),z=(n,e)=>n!==void 0&&e!==void 0&&n.toLowerCase().includes(e.toLowerCase()),Be=1e6,R=n=>n*Be,Q=R(.06),Ie=R(4),Fe=n=>n<=64?Q: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):Ie,ke="av1",Ve=n=>z(n,ke),Ue=.6,J=(n,e)=>Ve(e)?n*Ue:n,xe=n=>J(Q,n),Z=(n,e)=>{const t=Fe(n);return J(t,e)},H=1,ee=({videoTrack:n,targetSize:e,codec:t})=>{const s=n.getSettings(),r=s.width,i=s.height,c=r===void 0?H:r/e.width,l=i===void 0?H:i/e.height,u=Math.max(c,l,H),g=Z(e.width,t);return{scaleResolutionDownBy:u,maxBitrate:g}},ne=ie.createStackPromises(),Le=async()=>ne().catch(n=>{o.logger("videoSendingBalancer: error",n)}),$e=async n=>(ne.add(n),Le()),X=async({sender:n,scaleResolutionDownBy:e,maxBitrate:t,onSetParameters:s})=>$e(async()=>o.setEncodingsToSender(n,{scaleResolutionDownBy:e,maxBitrate:t},s)),He=async({sender:n,codec:e},t)=>{const r=xe(e);return X({sender:n,maxBitrate:r,onSetParameters:t,scaleResolutionDownBy:200})},V=async({sender:n,videoTrack:e,codec:t},s)=>{const c=e.getSettings().width,l=Z(c??0,t);return X({sender:n,maxBitrate:l,onSetParameters:s,scaleResolutionDownBy:1})},qe=async({sender:n,videoTrack:e,resolution:t,codec:s},r)=>{const[i,c]=t.split("x"),{maxBitrate:l,scaleResolutionDownBy:u}=ee({videoTrack:e,codec:s,targetSize:{width:Number(i),height:Number(c)}});return X({sender:n,maxBitrate:l,onSetParameters:r,scaleResolutionDownBy:u})},Xe=async({mainCam:n,resolutionMainCam:e,sender:t,videoTrack:s,codec:r},i)=>{switch(n){case o.EEventsMainCAM.PAUSE_MAIN_CAM:return He({sender:t,codec:r},i);case o.EEventsMainCAM.RESUME_MAIN_CAM:return V({sender:t,videoTrack:s,codec:r},i);case o.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return e!==void 0?qe({sender:t,videoTrack:s,codec:r,resolution:e},i):V({sender:t,videoTrack:s,codec:r},i);case o.EEventsMainCAM.ADMIN_STOP_MAIN_CAM:case o.EEventsMainCAM.ADMIN_START_MAIN_CAM:case void 0:return V({sender:t,videoTrack:s,codec:r},i);default:return V({sender:t,videoTrack:s,codec:r},i)}},j={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},W=async({mainCam:n,resolutionMainCam:e,connection:t,onSetParameters:s,ignoreForCodec:r})=>{const i=t.getSenders(),c=De(i);if(!(c!=null&&c.track))return j;const l=await Y(c);return z(l,r)?j:Xe({mainCam:n,resolutionMainCam:e,sender:c,codec:l,videoTrack:c.track},s)},je=(n,{ignoreForCodec:e,onSetParameters:t}={})=>{const s=async()=>{const{connection:u}=n;if(!u)throw new Error("connection is not exist");return W({connection:u,onSetParameters:t,ignoreForCodec:e})};let r=s;const i=u=>{r=async()=>{const{mainCam:g,resolutionMainCam:S}=u,{connection:C}=n;if(!C)throw new Error("connection is not exist");return W({mainCam:g,resolutionMainCam:S,connection:C,onSetParameters:t,ignoreForCodec:e})},r().catch(_)};return{subscribe:()=>{n.onSession("main-cam-control",i)},unsubscribe:()=>{n.offSession("main-cam-control",i)},balanceByTrack:s,resetMainCamControl(){r=s},async reBalance(){return r()}}},We=n=>n.getVideoTracks()[0],D=({mediaStream:n,simulcastEncodings:e,sendEncodings:t})=>{if(e&&e.length>0){const s=t??[],r=We(n);if(r===void 0)throw new Error("No video track");return e.forEach((i,c)=>{const l=s[c]??{};l.active=!0,i.rid!==void 0&&(l.rid=i.rid),i.scalabilityMode!==void 0&&(l.scalabilityMode=i.scalabilityMode);const{maxBitrate:u,scaleResolutionDownBy:g}=ee({videoTrack:r,targetSize:{width:i.width,height:i.height}});l.maxBitrate=u,l.scaleResolutionDownBy=g,s[c]=l}),s}return t},Ge=(n,e)=>n.filter(s=>e.some(r=>r.clockRate===s.clockRate&&r.mimeType===s.mimeType&&r.channels===s.channels&&r.sdpFmtpLine===s.sdpFmtpLine)),Ke=n=>{const e=RTCRtpSender.getCapabilities(n),t=RTCRtpReceiver.getCapabilities(n),s=e===null?[]:e.codecs,r=t===null?[]:t.codecs;return Ge(s,r)},Ye=(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,l=i===-1?Number.MAX_VALUE:i;return c-l}),ze=(n,e)=>e===void 0||e.length===0?n:n.filter(t=>!e.includes(t.mimeType)),B=(n,{preferredMimeTypesVideoCodecs:e,excludeMimeTypesVideoCodecs:t})=>async s=>{var r;try{if(typeof s.setCodecPreferences=="function"&&((r=s.sender.track)==null?void 0:r.kind)==="video"&&(e!==void 0&&e.length>0||t!==void 0&&t.length>0)){const i=Ke("video"),c=ze(i,t),l=Ye(c,e);s.setCodecPreferences(l)}Object.keys(n).length>0&&await o.setParametersToSender(s.sender,n)}catch(i){o.logger("updateTransceiver error",i)}},q=n=>{if(!ce.isCanceledError(n)&&!ae.hasCanceledError(n))throw n;return{isSuccessful:!1}},Qe=({kind:n,readyState:e})=>n==="video"&&e==="live",Je=new Set(["on","once","onceRace","wait","off","onSession","onceSession","onceRaceSession","waitSession","offSession","sendDTMF","hangUp","declineToIncomingCall","sendChannels","checkTelephony","waitChannels","ping","connection","isConfigured","isRegistered"]);class Ze{constructor(e,{preferredMimeTypesVideoCodecs:t,excludeMimeTypesVideoCodecs:s}={}){a(this,"on");a(this,"once");a(this,"onceRace");a(this,"wait");a(this,"off");a(this,"onSession");a(this,"onceSession");a(this,"onceRaceSession");a(this,"waitSession");a(this,"offSession");a(this,"sendDTMF");a(this,"hangUp");a(this,"declineToIncomingCall");a(this,"sendChannels");a(this,"checkTelephony");a(this,"waitChannels");a(this,"ping");a(this,"connection");a(this,"isConfigured");a(this,"isRegistered");a(this,"sipConnector");a(this,"preferredMimeTypesVideoCodecs");a(this,"excludeMimeTypesVideoCodecs");a(this,"connectToServer",async e=>{const{userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,name:l,password:u,isRegisteredUser:g,isDisconnectOnFail:S}=e;return o.logger("connectToServer",e),this.sipConnector.connect({userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,password:u,user:l,register:g}).then(C=>(o.logger("connectToServer then"),{ua:C,isSuccessful:!0})).catch(async C=>(o.logger("connectToServer catch: error",C),S===!0?this.sipConnector.disconnect().then(()=>q(C)).catch(()=>q(C)):q(C)))});a(this,"callToServer",async e=>{const{conference:t,mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,simulcastEncodings:l,degradationPreference:u,sendEncodings:g,offerToReceiveAudio:S,offerToReceiveVideo:C,directionVideo:F,directionAudio:k,setRemoteStreams:f,onBeforeProgressCall:p,onSuccessProgressCall:m,onEnterPurgatory:h,onEnterConference:E,onFailProgressCall:y,onFinishProgressCall:T,onEndedCall:M}=e,A=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:f}),O=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{A().catch(_)}}),N=B({degradationPreference:u},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("callToServer",e);const w=async()=>(o.logger("startCall"),this.sipConnector.call({mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,offerToReceiveAudio:S,offerToReceiveVideo:C,directionVideo:F,directionAudio:k,sendEncodings:D({mediaStream:s,simulcastEncodings:l,sendEncodings:g}),number:t,onAddedTransceiver:N,ontrack:O}));let b=!1,v;const P=(o.logger("subscribeEnterConference: onEnterConference",E),h??E?this.sipConnector.onSession("enterRoom",({room:d})=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:b}),v=d,I(v)?h&&h():E&&E({isSuccessProgressCall:b})}):()=>{}),x=d=>(o.logger("onSuccess"),b=!0,A().catch(_),m&&m({isPurgatory:I(v)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),M&&M()}),d),L=d=>{throw o.logger("onFail"),y&&y(),P(),d},$=()=>{o.logger("onFinish"),T&&T()};return o.logger("onBeforeProgressCall"),p&&p(t),w().then(x).catch(d=>L(d)).finally($)});a(this,"disconnectFromServer",async()=>this.sipConnector.disconnect().then(()=>(o.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(e=>(o.logger("disconnectFromServer: catch",e),{isSuccessful:!1})));a(this,"answerIncomingCall",async e=>{const{mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,simulcastEncodings:c,degradationPreference:l,sendEncodings:u,offerToReceiveAudio:g,offerToReceiveVideo:S,directionVideo:C,directionAudio:F,setRemoteStreams:k,onBeforeProgressCall:f,onSuccessProgressCall:p,onEnterPurgatory:m,onEnterConference:h,onFailProgressCall:E,onFinishProgressCall:y,onEndedCall:T}=e,M=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:k}),A=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{M().catch(_)}}),O=B({degradationPreference:l},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("answerIncomingCall",e);const N=async()=>this.sipConnector.answerToIncomingCall({mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,offerToReceiveAudio:g,offerToReceiveVideo:S,directionVideo:C,directionAudio:F,sendEncodings:D({mediaStream:t,simulcastEncodings:c,sendEncodings:u}),onAddedTransceiver:O,ontrack:A}),w=()=>{const{remoteCallerData:d}=this.sipConnector;return d.incomingNumber};let b=!1,v;const P=(o.logger("subscribeEnterConference: onEnterConference",h),m??h?this.sipConnector.onSession("enterRoom",d=>{o.logger("enterRoom",{_room:d,isSuccessProgressCall:b}),v=d,I(v)?m&&m():h&&h({isSuccessProgressCall:b})}):()=>{}),x=d=>(o.logger("onSuccess"),b=!0,M().catch(_),p&&p({isPurgatory:I(v)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),T&&T()}),d),L=d=>{throw o.logger("onFail"),E&&E(),P(),d},$=()=>{o.logger("onFinish"),y&&y()};if(o.logger("onBeforeProgressCall"),f){const d=w();f(d)}return N().then(x).catch(d=>L(d)).finally($)});a(this,"updatePresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:l,preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g})=>{const S=B({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:l}),onAddedTransceiver:S})});a(this,"startPresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:l,preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g},S)=>{const C=B({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:l}),onAddedTransceiver:C},S)});a(this,"stopShareSipConnector",async({isP2P:e=!1}={})=>(o.logger("stopShareSipConnector"),this.sipConnector.stopPresentation({isP2P:e}).catch(t=>{o.logger(t)})));a(this,"sendRefusalToTurnOnMic",async()=>{this.sipConnector.isCallActive&&(o.logger("sendRefusalToTurnOnMic"),await this.sipConnector.sendRefusalToTurnOnMic().catch(e=>{o.logger("sendRefusalToTurnOnMic: error",e)}))});a(this,"sendRefusalToTurnOnCam",async()=>{this.sipConnector.isCallActive&&(o.logger("sendRefusalToTurnOnCam"),await this.sipConnector.sendRefusalToTurnOnCam().catch(e=>{o.logger("sendRefusalToTurnOnCam: error",e)}))});a(this,"sendMediaState",async({isEnabledCam:e,isEnabledMic:t})=>{this.sipConnector.isCallActive&&(o.logger("sendMediaState"),await this.sipConnector.sendMediaState({cam:e,mic:t}))});a(this,"replaceMediaStream",async(e,{deleteExisting:t,addMissing:s,forceRenegotiation:r,contentHint:i,simulcastEncodings:c,degradationPreference:l,sendEncodings:u}={})=>{const g=B({degradationPreference:l},{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})});a(this,"askPermissionToEnableCam",async()=>{this.sipConnector.isCallActive&&(o.logger("askPermissionToEnableCam"),await this.sipConnector.askPermissionToEnableCam())});a(this,"resolveHandleReadyRemoteStreamsDebounced",({onReadyRemoteStreams:e})=>le.debounce(()=>{const t=this.sipConnector.getRemoteStreams();o.logger("remoteStreams",t),t&&e(t)},200));a(this,"resolveHandleReadyRemoteStreams",({onReadyRemoteStreams:e})=>({track:t})=>{Qe(t)&&e()});a(this,"getRemoteStreams",()=>(o.logger("getRemoteStreams"),this.sipConnector.getRemoteStreams()));a(this,"onUseLicense",e=>(o.logger("onUseLicense"),this.sipConnector.onSession("useLicense",e)));a(this,"onMustStopPresentation",e=>(o.logger("onMustStopPresentation"),this.sipConnector.onSession("mustStopPresentation",e)));a(this,"onMoveToSpectators",e=>(o.logger("onMoveToSpectators"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS,e)));a(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"&&Je.has(i)&&i in this.sipConnector){const u=Reflect.get(this.sipConnector,i,this.sipConnector);return typeof u=="function"?u.bind(this.sipConnector):u}const l=Reflect.get(r,i,c);return typeof l=="function"?l.bind(r):l}})}}exports.EEventsMainCAM=o.EEventsMainCAM;exports.EEventsMic=o.EEventsMic;exports.EEventsSyncMediaState=o.EEventsSyncMediaState;exports.EMimeTypesVideoCodecs=o.EMimeTypesVideoCodecs;exports.EUseLicense=o.EUseLicense;exports.SipConnector=o.SipConnector;exports.causes=o.causes;exports.constants=o.constants;exports.disableDebug=o.disableDebug;exports.enableDebug=o.enableDebug;exports.eventNames=o.eventNames;exports.hasCanceledCallError=o.hasCanceledCallError;exports.hasCanceledStartPresentationError=o.hasCanceledStartPresentationError;exports.setParametersToSender=o.setParametersToSender;exports.debug=_;exports.SipConnectorFacade=Ze;exports.getCodecFromSender=Y;exports.resolveVideoSendingBalancer=je;exports.tools=Ne;
1
+ "use strict";var te=Object.defineProperty;var se=(n,e,t)=>e in n?te(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>se(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./SipConnector-DGYQOyHy.cjs"),oe=require("sequent-promises"),re=require("stack-promises"),_=require("debug"),ie=require("@krivega/cancelable-promise"),ce=require("repeated-calls"),ae=require("ts-debounce"),U=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 W=(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))(W||{});const le=new Error("Unknown error"),ue=(n=le)=>{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!==void 0&&((r=t._ws)==null?void 0:r.readyState)===3?s="WS_CONNECTION_FAILED":U(n)!==void 0&&U(n)!==""&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},de=n=>{let e="";try{e=JSON.stringify(n)}catch(t){o.logger("failed to stringify message",t)}return e},ge=new Error("Unknown error"),Ce=(n=ge)=>{const{code:e,cause:t,message:s}=n,r=U(n),i={code:"",cause:"",message:""};return typeof s=="object"&&s!==null?i.message=de(s):s&&(i.message=String(s)),r!==void 0&&r!==""&&(i.link=r),e!==void 0&&e!==""&&(i.code=e),t!==void 0&&t!==""&&(i.cause=t),i},Se=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:W,getLinkError:U,getTypeFromError:ue,getValuesFromError:Ce},Symbol.toStringTag,{value:"Module"})),fe=({sessionId:n,remoteAddress:e,isMutedAudio:t,isMutedVideo:s,isRegistered:r,isPresentationCall:i})=>{const c=[],l=t?"0":"1",u=s?"0":"1";return c.push(`X-Vinteo-Mic-State: ${l}`,`X-Vinteo-MainCam-State: ${u}`),(r===!1||r===void 0)&&c.push("X-Vinteo-Purgatory-Call: yes"),n!==void 0&&n!==""&&c.push(`X-Vinteo-Session: ${n}`),i===!0&&c.push("X-Vinteo-Presentation-Call: yes"),e!==void 0&&e!==""&&c.push(`X-Vinteo-Remote: ${e}`),c},me="[@*!|]",he="_",Re=n=>{let e=n;return e=e.replaceAll(new RegExp(me,"g"),he),e},pe=({appName:n,appVersion:e,browserName:t,browserVersion:s})=>{const i=`${Re(n)} ${e}`;return`ChromeNew - ${t?`${t} ${s}, ${i}`:i}`},Ee=({isUnifiedSdpSemantic:n,appVersion:e,browserName:t,browserVersion:s,appName:r})=>n?pe({appVersion:e,browserName:t,browserVersion:s,appName:r}):"Chrome",G="purgatory",I=n=>n===G,ye=n=>e=>[...e].map(s=>async()=>n(s)),Te=async({accumulatedKeys:n,sendKey:e,canRunTask:t})=>{const r=ye(e)(n);return oe.sequentPromises(r,t)},Me=n=>t=>(o.logger("onStartMainCam"),n.onSession("admin-start-main-cam",t)),be=n=>t=>(o.logger("onStartMic"),n.onSession("admin-start-mic",t)),Ae=n=>t=>(o.logger("onStopMainCam"),n.onSession("admin-stop-main-cam",t)),ve=n=>t=>(o.logger("onStopMic"),n.onSession("admin-stop-mic",t)),_e=({sipConnector:n})=>{const e=(f,p)=>({isSyncForced:m=!1})=>{if(m){f();return}p()},t=Me(n),s=Ae(n),r=be(n),i=ve(n);let c=()=>{},l=()=>{},u=()=>{},g=()=>{};const S=({onStartMainCamForced:f,onStartMainCamNotForced:p,onStopMainCamForced:m,onStopMainCamNotForced:h,onStartMicForced:E,onStartMicNotForced:y,onStopMicForced:T,onStopMicNotForced:M})=>{const v=e(f,p);c=t(v);const O=e(m,h);l=s(O);const N=e(E,y);u=r(N);const w=e(T,M);g=i(w)},C=()=>{c(),l(),u(),g()};return{start:f=>{S(f)},stop:()=>{C()}}},Oe=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:G,createSyncMediaState:_e,error:Se,getExtraHeaders:fe,getUserAgent:Ee,hasPurgatory:I,sendDtmfAccumulated:Te},Symbol.toStringTag,{value:"Module"})),Ne=n=>[...n.keys()].map(e=>n.get(e)),we=(n,e)=>Ne(n).find(t=>t.type===e),K=async n=>n.getStats().then(e=>{const t=we(e,"codec");return t==null?void 0:t.mimeType}),Pe=n=>n.find(e=>{var t;return((t=e==null?void 0:e.track)==null?void 0:t.kind)==="video"}),Y=(n,e)=>n!==void 0&&e!==void 0&&n.toLowerCase().includes(e.toLowerCase()),De=1e6,R=n=>n*De,z=R(.06),Be=R(4),Ie=n=>n<=64?z: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,Fe="av1",ke=n=>Y(n,Fe),Ve=.6,Q=(n,e)=>ke(e)?n*Ve:n,Ue=n=>Q(z,n),J=(n,e)=>{const t=Ie(n);return Q(t,e)},xe=1,Z=({videoTrack:n,targetSize:e,codec:t})=>{const s=n.getSettings(),r=s.width,i=s.height,c=r/e.width,l=i/e.height,u=Math.max(c,l,xe),g=J(e.width,t);return{scaleResolutionDownBy:u,maxBitrate:g}},ee=re.createStackPromises(),Le=async()=>ee().catch(n=>{o.logger("videoSendingBalancer: error",n)}),$e=async n=>(ee.add(n),Le()),q=async({sender:n,scaleResolutionDownBy:e,maxBitrate:t,onSetParameters:s})=>$e(async()=>o.setEncodingsToSender(n,{scaleResolutionDownBy:e,maxBitrate:t},s)),He=async({sender:n,codec:e},t)=>{const r=Ue(e);return q({sender:n,maxBitrate:r,onSetParameters:t,scaleResolutionDownBy:200})},V=async({sender:n,videoTrack:e,codec:t},s)=>{const c=e.getSettings().width,l=J(c,t);return q({sender:n,maxBitrate:l,onSetParameters:s,scaleResolutionDownBy:1})},qe=async({sender:n,videoTrack:e,resolution:t,codec:s},r)=>{const[i,c]=t.split("x"),{maxBitrate:l,scaleResolutionDownBy:u}=Z({videoTrack:e,codec:s,targetSize:{width:Number(i),height:Number(c)}});return q({sender:n,maxBitrate:l,onSetParameters:r,scaleResolutionDownBy:u})},Xe=async({mainCam:n,resolutionMainCam:e,sender:t,videoTrack:s,codec:r},i)=>{switch(n){case o.EEventsMainCAM.PAUSE_MAIN_CAM:return He({sender:t,codec:r},i);case o.EEventsMainCAM.RESUME_MAIN_CAM:return V({sender:t,videoTrack:s,codec:r},i);case o.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return e!==void 0?qe({sender:t,videoTrack:s,codec:r,resolution:e},i):V({sender:t,videoTrack:s,codec:r},i);case o.EEventsMainCAM.ADMIN_STOP_MAIN_CAM:case o.EEventsMainCAM.ADMIN_START_MAIN_CAM:case void 0:return V({sender:t,videoTrack:s,codec:r},i);default:return V({sender:t,videoTrack:s,codec:r},i)}},X={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},j=async({mainCam:n,resolutionMainCam:e,connection:t,onSetParameters:s,ignoreForCodec:r})=>{const i=t.getSenders(),c=Pe(i);if(!(c!=null&&c.track))return X;const l=await K(c);return Y(l,r)?X:Xe({mainCam:n,resolutionMainCam:e,sender:c,codec:l,videoTrack:c.track},s)},je=(n,{ignoreForCodec:e,onSetParameters:t}={})=>{const s=async()=>{const{connection:u}=n;if(!u)throw new Error("connection is not exist");return j({connection:u,onSetParameters:t,ignoreForCodec:e})};let r=s;const i=u=>{r=async()=>{const{mainCam:g,resolutionMainCam:S}=u,{connection:C}=n;if(!C)throw new Error("connection is not exist");return j({mainCam:g,resolutionMainCam:S,connection:C,onSetParameters:t,ignoreForCodec:e})},r().catch(_)};return{subscribe:()=>{n.onSession("main-cam-control",i)},unsubscribe:()=>{n.offSession("main-cam-control",i)},balanceByTrack:s,resetMainCamControl(){r=s},async reBalance(){return r()}}},We=n=>n.getVideoTracks()[0],D=({mediaStream:n,simulcastEncodings:e,sendEncodings:t})=>{if(e&&e.length>0){const s=t??[],r=We(n);return e.forEach((i,c)=>{const l=s[c]??{};l.active=!0,i.rid!==void 0&&(l.rid=i.rid),i.scalabilityMode!==void 0&&(l.scalabilityMode=i.scalabilityMode);const{maxBitrate:u,scaleResolutionDownBy:g}=Z({videoTrack:r,targetSize:{width:i.width,height:i.height}});l.maxBitrate=u,l.scaleResolutionDownBy=g,s[c]=l}),s}return t},Ge=(n,e)=>n.filter(s=>e.some(r=>r.clockRate===s.clockRate&&r.mimeType===s.mimeType&&r.channels===s.channels&&r.sdpFmtpLine===s.sdpFmtpLine)),Ke=n=>{const e=RTCRtpSender.getCapabilities(n),t=RTCRtpReceiver.getCapabilities(n),s=e===null?[]:e.codecs,r=t===null?[]:t.codecs;return Ge(s,r)},Ye=(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,l=i===-1?Number.MAX_VALUE:i;return c-l}),ze=(n,e)=>e===void 0||e.length===0?n:n.filter(t=>!e.includes(t.mimeType)),B=(n,{preferredMimeTypesVideoCodecs:e,excludeMimeTypesVideoCodecs:t})=>async s=>{var r;try{if(typeof s.setCodecPreferences=="function"&&((r=s.sender.track)==null?void 0:r.kind)==="video"&&(e!==void 0&&e.length>0||t!==void 0&&t.length>0)){const i=Ke("video"),c=ze(i,t),l=Ye(c,e);s.setCodecPreferences(l)}Object.keys(n).length>0&&await o.setParametersToSender(s.sender,n)}catch(i){o.logger("updateTransceiver error",i)}},H=n=>{if(!ie.isCanceledError(n)&&!ce.hasCanceledError(n))throw n;return{isSuccessful:!1}},Qe=({kind:n,readyState:e})=>n==="video"&&e==="live",Je=new Set(["on","once","onceRace","wait","off","onSession","onceSession","onceRaceSession","waitSession","offSession","sendDTMF","hangUp","declineToIncomingCall","sendChannels","checkTelephony","waitChannels","ping","connection","isConfigured","isRegistered"]);class Ze{constructor(e,{preferredMimeTypesVideoCodecs:t,excludeMimeTypesVideoCodecs:s}={}){a(this,"on");a(this,"once");a(this,"onceRace");a(this,"wait");a(this,"off");a(this,"onSession");a(this,"onceSession");a(this,"onceRaceSession");a(this,"waitSession");a(this,"offSession");a(this,"sendDTMF");a(this,"hangUp");a(this,"declineToIncomingCall");a(this,"sendChannels");a(this,"checkTelephony");a(this,"waitChannels");a(this,"ping");a(this,"connection");a(this,"isConfigured");a(this,"isRegistered");a(this,"sipConnector");a(this,"preferredMimeTypesVideoCodecs");a(this,"excludeMimeTypesVideoCodecs");a(this,"connectToServer",async e=>{const{userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,name:l,password:u,isRegisteredUser:g,isDisconnectOnFail:S}=e;return o.logger("connectToServer",e),this.sipConnector.connect({userAgent:t,sipWebSocketServerURL:s,sipServerUrl:r,remoteAddress:i,displayName:c,password:u,user:l,register:g}).then(C=>(o.logger("connectToServer then"),{ua:C,isSuccessful:!0})).catch(async C=>(o.logger("connectToServer catch: error",C),S===!0?this.sipConnector.disconnect().then(()=>H(C)).catch(()=>H(C)):H(C)))});a(this,"callToServer",async e=>{const{conference:t,mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,simulcastEncodings:l,degradationPreference:u,sendEncodings:g,offerToReceiveAudio:S,offerToReceiveVideo:C,directionVideo:F,directionAudio:k,setRemoteStreams:f,onBeforeProgressCall:p,onSuccessProgressCall:m,onEnterPurgatory:h,onEnterConference:E,onFailProgressCall:y,onFinishProgressCall:T,onEndedCall:M}=e,v=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:f}),O=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{v().catch(_)}}),N=B({degradationPreference:u},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("callToServer",e);const w=async()=>(o.logger("startCall"),this.sipConnector.call({mediaStream:s,extraHeaders:r,iceServers:i,contentHint:c,offerToReceiveAudio:S,offerToReceiveVideo:C,directionVideo:F,directionAudio:k,sendEncodings:D({mediaStream:s,simulcastEncodings:l,sendEncodings:g}),number:t,onAddedTransceiver:N,ontrack:O}));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,I(A)?h&&h():E&&E({isSuccessProgressCall:b})}):()=>{}),x=d=>(o.logger("onSuccess"),b=!0,v().catch(_),m&&m({isPurgatory:I(A)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),M&&M()}),d),L=d=>{throw o.logger("onFail"),y&&y(),P(),d},$=()=>{o.logger("onFinish"),T&&T()};return o.logger("onBeforeProgressCall"),p&&p(t),w().then(x).catch(d=>L(d)).finally($)});a(this,"disconnectFromServer",async()=>this.sipConnector.disconnect().then(()=>(o.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(e=>(o.logger("disconnectFromServer: catch",e),{isSuccessful:!1})));a(this,"answerIncomingCall",async e=>{const{mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,simulcastEncodings:c,degradationPreference:l,sendEncodings:u,offerToReceiveAudio:g,offerToReceiveVideo:S,directionVideo:C,directionAudio:F,setRemoteStreams:k,onBeforeProgressCall:f,onSuccessProgressCall:p,onEnterPurgatory:m,onEnterConference:h,onFailProgressCall:E,onFinishProgressCall:y,onEndedCall:T}=e,M=this.resolveHandleReadyRemoteStreamsDebounced({onReadyRemoteStreams:k}),v=this.resolveHandleReadyRemoteStreams({onReadyRemoteStreams:()=>{M().catch(_)}}),O=B({degradationPreference:l},{preferredMimeTypesVideoCodecs:this.preferredMimeTypesVideoCodecs,excludeMimeTypesVideoCodecs:this.excludeMimeTypesVideoCodecs});o.logger("answerIncomingCall",e);const N=async()=>this.sipConnector.answerToIncomingCall({mediaStream:t,extraHeaders:s,iceServers:r,contentHint:i,offerToReceiveAudio:g,offerToReceiveVideo:S,directionVideo:C,directionAudio:F,sendEncodings:D({mediaStream:t,simulcastEncodings:c,sendEncodings:u}),onAddedTransceiver:O,ontrack:v}),w=()=>{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,I(A)?m&&m():h&&h({isSuccessProgressCall:b})}):()=>{}),x=d=>(o.logger("onSuccess"),b=!0,M().catch(_),p&&p({isPurgatory:I(A)}),this.sipConnector.onceRaceSession(["ended","failed"],()=>{P(),T&&T()}),d),L=d=>{throw o.logger("onFail"),E&&E(),P(),d},$=()=>{o.logger("onFinish"),y&&y()};if(o.logger("onBeforeProgressCall"),f){const d=w();f(d)}return N().then(x).catch(d=>L(d)).finally($)});a(this,"updatePresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:l,preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g})=>{const S=B({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:l}),onAddedTransceiver:S})});a(this,"startPresentation",async({mediaStream:e,isP2P:t,maxBitrate:s,contentHint:r,simulcastEncodings:i,degradationPreference:c,sendEncodings:l,preferredMimeTypesVideoCodecs:u,excludeMimeTypesVideoCodecs:g},S)=>{const C=B({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:l}),onAddedTransceiver:C},S)});a(this,"stopShareSipConnector",async({isP2P:e=!1}={})=>(o.logger("stopShareSipConnector"),this.sipConnector.stopPresentation({isP2P:e}).catch(t=>{o.logger(t)})));a(this,"sendRefusalToTurnOnMic",async()=>{this.sipConnector.isCallActive&&(o.logger("sendRefusalToTurnOnMic"),await this.sipConnector.sendRefusalToTurnOnMic().catch(e=>{o.logger("sendRefusalToTurnOnMic: error",e)}))});a(this,"sendRefusalToTurnOnCam",async()=>{this.sipConnector.isCallActive&&(o.logger("sendRefusalToTurnOnCam"),await this.sipConnector.sendRefusalToTurnOnCam().catch(e=>{o.logger("sendRefusalToTurnOnCam: error",e)}))});a(this,"sendMediaState",async({isEnabledCam:e,isEnabledMic:t})=>{this.sipConnector.isCallActive&&(o.logger("sendMediaState"),await this.sipConnector.sendMediaState({cam:e,mic:t}))});a(this,"replaceMediaStream",async(e,{deleteExisting:t,addMissing:s,forceRenegotiation:r,contentHint:i,simulcastEncodings:c,degradationPreference:l,sendEncodings:u}={})=>{const g=B({degradationPreference:l},{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})});a(this,"askPermissionToEnableCam",async()=>{this.sipConnector.isCallActive&&(o.logger("askPermissionToEnableCam"),await this.sipConnector.askPermissionToEnableCam())});a(this,"resolveHandleReadyRemoteStreamsDebounced",({onReadyRemoteStreams:e})=>ae.debounce(()=>{const t=this.sipConnector.getRemoteStreams();o.logger("remoteStreams",t),t&&e(t)},200));a(this,"resolveHandleReadyRemoteStreams",({onReadyRemoteStreams:e})=>({track:t})=>{Qe(t)&&e()});a(this,"getRemoteStreams",()=>(o.logger("getRemoteStreams"),this.sipConnector.getRemoteStreams()));a(this,"onUseLicense",e=>(o.logger("onUseLicense"),this.sipConnector.onSession("useLicense",e)));a(this,"onMustStopPresentation",e=>(o.logger("onMustStopPresentation"),this.sipConnector.onSession("mustStopPresentation",e)));a(this,"onMoveToSpectators",e=>(o.logger("onMoveToSpectators"),this.sipConnector.onSession(o.PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS,e)));a(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"&&Je.has(i)&&i in this.sipConnector){const u=Reflect.get(this.sipConnector,i,this.sipConnector);return typeof u=="function"?u.bind(this.sipConnector):u}const l=Reflect.get(r,i,c);return typeof l=="function"?l.bind(r):l}})}}exports.EEventsMainCAM=o.EEventsMainCAM;exports.EEventsMic=o.EEventsMic;exports.EEventsSyncMediaState=o.EEventsSyncMediaState;exports.EMimeTypesVideoCodecs=o.EMimeTypesVideoCodecs;exports.EUseLicense=o.EUseLicense;exports.SipConnector=o.SipConnector;exports.causes=o.causes;exports.constants=o.constants;exports.disableDebug=o.disableDebug;exports.enableDebug=o.enableDebug;exports.eventNames=o.eventNames;exports.hasCanceledCallError=o.hasCanceledCallError;exports.hasCanceledStartPresentationError=o.hasCanceledStartPresentationError;exports.setParametersToSender=o.setParametersToSender;exports.debug=_;exports.SipConnectorFacade=Ze;exports.getCodecFromSender=K;exports.resolveVideoSendingBalancer=je;exports.tools=Oe;
package/dist/index.js CHANGED
@@ -1,22 +1,22 @@
1
- var re = Object.defineProperty;
2
- var ie = (n, e, t) => e in n ? re(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var a = (n, e, t) => ie(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { B as Y, N as q, l as c, E as B, s as ce, a as ae, P as ue, b as de } from "./SipConnector-DfaRIKWv.js";
5
- import { j as Rn, k as gn, n as yn, m as Tn, S as En, c as Mn, d as bn, f as _n, g as An, e as vn, h as On, i as Nn } from "./SipConnector-DfaRIKWv.js";
6
- import { sequentPromises as le } from "sequent-promises";
7
- import { createStackPromises as Ce } from "stack-promises";
1
+ var oe = Object.defineProperty;
2
+ var re = (n, e, t) => e in n ? oe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var a = (n, e, t) => re(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { B as K, N as Y, l as c, E as B, s as ie, a as ce, P as ae, b as ue } from "./SipConnector-DTNc5BfW.js";
5
+ import { j as Rn, k as gn, n as yn, m as Tn, S as En, c as Mn, d as bn, f as _n, g as An, e as vn, h as On, i as Nn } from "./SipConnector-DTNc5BfW.js";
6
+ import { sequentPromises as de } from "sequent-promises";
7
+ import { createStackPromises as le } from "stack-promises";
8
8
  import D from "debug";
9
9
  import { default as Bn } from "debug";
10
- import { isCanceledError as Se } from "@krivega/cancelable-promise";
11
- import { hasCanceledError as fe } from "repeated-calls";
12
- import { debounce as me } from "ts-debounce";
10
+ import { isCanceledError as Ce } from "@krivega/cancelable-promise";
11
+ import { hasCanceledError as Se } from "repeated-calls";
12
+ import { debounce as fe } from "ts-debounce";
13
13
  const x = (n) => {
14
14
  const { url: e, cause: t } = n;
15
15
  let s = e;
16
- return (t === Y || t === q) && (s = `${n.message.to.uri.user}@${n.message.to.uri.host}`), s;
16
+ return (t === K || t === Y) && (s = `${n.message.to.uri.user}@${n.message.to.uri.host}`), s;
17
17
  };
18
- var z = /* @__PURE__ */ ((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))(z || {});
19
- const he = new Error("Unknown error"), pe = (n = he) => {
18
+ var q = /* @__PURE__ */ ((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))(q || {});
19
+ const me = new Error("Unknown error"), he = (n = me) => {
20
20
  var o;
21
21
  const { cause: e, socket: t } = n;
22
22
  let s = "CONNECT_SERVER_FAILED";
@@ -25,11 +25,11 @@ const he = new Error("Unknown error"), pe = (n = he) => {
25
25
  s = "WRONG_USER_OR_PASSWORD";
26
26
  break;
27
27
  }
28
- case Y: {
28
+ case K: {
29
29
  s = "BAD_MEDIA_ERROR";
30
30
  break;
31
31
  }
32
- case q: {
32
+ case Y: {
33
33
  s = "NOT_FOUND_ERROR";
34
34
  break;
35
35
  }
@@ -37,7 +37,7 @@ const he = new Error("Unknown error"), pe = (n = he) => {
37
37
  t !== void 0 && ((o = t._ws) == null ? void 0 : o.readyState) === 3 ? s = "WS_CONNECTION_FAILED" : x(n) !== void 0 && x(n) !== "" && (s = "CONNECT_SERVER_FAILED_BY_LINK");
38
38
  }
39
39
  return s;
40
- }, Re = (n) => {
40
+ }, pe = (n) => {
41
41
  let e = "";
42
42
  try {
43
43
  e = JSON.stringify(n);
@@ -45,16 +45,16 @@ const he = new Error("Unknown error"), pe = (n = he) => {
45
45
  c("failed to stringify message", t);
46
46
  }
47
47
  return e;
48
- }, ge = new Error("Unknown error"), ye = (n = ge) => {
48
+ }, Re = new Error("Unknown error"), ge = (n = Re) => {
49
49
  const { code: e, cause: t, message: s } = n, o = x(n), r = { code: "", cause: "", message: "" };
50
- return typeof s == "object" && s !== null ? r.message = Re(s) : s && (r.message = String(s)), o !== void 0 && o !== "" && (r.link = o), e !== void 0 && e !== "" && (r.code = e), t !== void 0 && t !== "" && (r.cause = t), r;
51
- }, Te = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
50
+ return typeof s == "object" && s !== null ? r.message = pe(s) : s && (r.message = String(s)), o !== void 0 && o !== "" && (r.link = o), e !== void 0 && e !== "" && (r.code = e), t !== void 0 && t !== "" && (r.cause = t), r;
51
+ }, ye = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
52
52
  __proto__: null,
53
- EErrorTypes: z,
53
+ EErrorTypes: q,
54
54
  getLinkError: x,
55
- getTypeFromError: pe,
56
- getValuesFromError: ye
57
- }, Symbol.toStringTag, { value: "Module" })), Ee = ({
55
+ getTypeFromError: he,
56
+ getValuesFromError: ge
57
+ }, Symbol.toStringTag, { value: "Module" })), Te = ({
58
58
  sessionId: n,
59
59
  remoteAddress: e,
60
60
  isMutedAudio: t,
@@ -64,38 +64,38 @@ const he = new Error("Unknown error"), pe = (n = he) => {
64
64
  }) => {
65
65
  const i = [], u = t ? "0" : "1", d = s ? "0" : "1";
66
66
  return i.push(`X-Vinteo-Mic-State: ${u}`, `X-Vinteo-MainCam-State: ${d}`), (o === !1 || o === void 0) && i.push("X-Vinteo-Purgatory-Call: yes"), n !== void 0 && n !== "" && i.push(`X-Vinteo-Session: ${n}`), r === !0 && i.push("X-Vinteo-Presentation-Call: yes"), e !== void 0 && e !== "" && i.push(`X-Vinteo-Remote: ${e}`), i;
67
- }, Me = "[@*!|]", be = "_", _e = (n) => {
67
+ }, Ee = "[@*!|]", Me = "_", be = (n) => {
68
68
  let e = n;
69
- return e = e.replaceAll(new RegExp(Me, "g"), be), e;
70
- }, Ae = ({
69
+ return e = e.replaceAll(new RegExp(Ee, "g"), Me), e;
70
+ }, _e = ({
71
71
  appName: n,
72
72
  appVersion: e,
73
73
  browserName: t,
74
74
  browserVersion: s
75
75
  }) => {
76
- const r = `${_e(n)} ${e}`;
77
- return `ChromeNew - ${t === void 0 ? r : `${t} ${s}, ${r}`}`;
78
- }, ve = ({
76
+ const r = `${be(n)} ${e}`;
77
+ return `ChromeNew - ${t ? `${t} ${s}, ${r}` : r}`;
78
+ }, Ae = ({
79
79
  isUnifiedSdpSemantic: n,
80
80
  appVersion: e,
81
81
  browserName: t,
82
82
  browserVersion: s,
83
83
  appName: o
84
- }) => n ? Ae({ appVersion: e, browserName: t, browserVersion: s, appName: o }) : "Chrome", Q = "purgatory", k = (n) => n === Q, Oe = (n) => (e) => [...e].map((s) => async () => n(s)), Ne = async ({
84
+ }) => n ? _e({ appVersion: e, browserName: t, browserVersion: s, appName: o }) : "Chrome", z = "purgatory", F = (n) => n === z, ve = (n) => (e) => [...e].map((s) => async () => n(s)), Oe = async ({
85
85
  accumulatedKeys: n,
86
86
  sendKey: e,
87
87
  canRunTask: t
88
88
  }) => {
89
- const o = Oe(e)(n);
90
- return le(o, t);
91
- }, we = (n) => (t) => (c("onStartMainCam"), n.onSession("admin-start-main-cam", t)), Be = (n) => (t) => (c("onStartMic"), n.onSession("admin-start-mic", t)), Pe = (n) => (t) => (c("onStopMainCam"), n.onSession("admin-stop-main-cam", t)), Ie = (n) => (t) => (c("onStopMic"), n.onSession("admin-stop-mic", t)), De = ({ sipConnector: n }) => {
89
+ const o = ve(e)(n);
90
+ return de(o, t);
91
+ }, Ne = (n) => (t) => (c("onStartMainCam"), n.onSession("admin-start-main-cam", t)), we = (n) => (t) => (c("onStartMic"), n.onSession("admin-start-mic", t)), Be = (n) => (t) => (c("onStopMainCam"), n.onSession("admin-stop-main-cam", t)), Pe = (n) => (t) => (c("onStopMic"), n.onSession("admin-stop-mic", t)), Ie = ({ sipConnector: n }) => {
92
92
  const e = (m, g) => ({ isSyncForced: h = !1 }) => {
93
93
  if (h) {
94
94
  m();
95
95
  return;
96
96
  }
97
97
  g();
98
- }, t = we(n), s = Pe(n), o = Be(n), r = Ie(n);
98
+ }, t = Ne(n), s = Be(n), o = we(n), r = Pe(n);
99
99
  let i = () => {
100
100
  }, u = () => {
101
101
  }, d = () => {
@@ -138,39 +138,39 @@ const he = new Error("Unknown error"), pe = (n = he) => {
138
138
  };
139
139
  }, Sn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
140
140
  __proto__: null,
141
- PURGATORY_CONFERENCE_NUMBER: Q,
142
- createSyncMediaState: De,
143
- error: Te,
144
- getExtraHeaders: Ee,
145
- getUserAgent: ve,
146
- hasPurgatory: k,
147
- sendDtmfAccumulated: Ne
148
- }, Symbol.toStringTag, { value: "Module" })), ke = (n) => [...n.keys()].map((e) => n.get(e)), Fe = (n, e) => ke(n).find((t) => (t == null ? void 0 : t.type) === e), Ve = async (n) => n.getStats().then((e) => {
141
+ PURGATORY_CONFERENCE_NUMBER: z,
142
+ createSyncMediaState: Ie,
143
+ error: ye,
144
+ getExtraHeaders: Te,
145
+ getUserAgent: Ae,
146
+ hasPurgatory: F,
147
+ sendDtmfAccumulated: Oe
148
+ }, Symbol.toStringTag, { value: "Module" })), De = (n) => [...n.keys()].map((e) => n.get(e)), Fe = (n, e) => De(n).find((t) => t.type === e), ke = async (n) => n.getStats().then((e) => {
149
149
  const t = Fe(e, "codec");
150
150
  return t == null ? void 0 : t.mimeType;
151
- }), Ue = (n) => n.find((e) => {
151
+ }), Ve = (n) => n.find((e) => {
152
152
  var t;
153
- return ((t = e.track) == null ? void 0 : t.kind) === "video";
154
- }), J = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), xe = 1e6, R = (n) => n * xe, Z = R(0.06), Le = R(4), $e = (n) => n <= 64 ? Z : n <= 128 ? R(0.12) : n <= 256 ? R(0.25) : n <= 384 ? R(0.32) : n <= 426 ? R(0.38) : n <= 640 ? R(0.5) : n <= 848 ? R(0.7) : n <= 1280 ? R(1) : n <= 1920 ? R(2) : Le, He = "av1", Xe = (n) => J(n, He), je = 0.6, ee = (n, e) => Xe(e) ? n * je : n, We = (n) => ee(Z, n), ne = (n, e) => {
155
- const t = $e(n);
156
- return ee(t, e);
157
- }, X = 1, te = ({
153
+ return ((t = e == null ? void 0 : e.track) == null ? void 0 : t.kind) === "video";
154
+ }), Q = (n, e) => n !== void 0 && e !== void 0 && n.toLowerCase().includes(e.toLowerCase()), Ue = 1e6, R = (n) => n * Ue, J = R(0.06), xe = R(4), Le = (n) => n <= 64 ? J : n <= 128 ? R(0.12) : n <= 256 ? R(0.25) : n <= 384 ? R(0.32) : n <= 426 ? R(0.38) : n <= 640 ? R(0.5) : n <= 848 ? R(0.7) : n <= 1280 ? R(1) : n <= 1920 ? R(2) : xe, $e = "av1", He = (n) => Q(n, $e), Xe = 0.6, Z = (n, e) => He(e) ? n * Xe : n, je = (n) => Z(J, n), ee = (n, e) => {
155
+ const t = Le(n);
156
+ return Z(t, e);
157
+ }, We = 1, ne = ({
158
158
  videoTrack: n,
159
159
  targetSize: e,
160
160
  codec: t
161
161
  }) => {
162
- const s = n.getSettings(), o = s.width, r = s.height, i = o === void 0 ? X : o / e.width, u = r === void 0 ? X : r / e.height, d = Math.max(i, u, X), C = ne(e.width, t);
162
+ const s = n.getSettings(), o = s.width, r = s.height, i = o / e.width, u = r / e.height, d = Math.max(i, u, We), C = ee(e.width, t);
163
163
  return { scaleResolutionDownBy: d, maxBitrate: C };
164
- }, se = Ce(), Ge = async () => se().catch((n) => {
164
+ }, te = le(), Ge = async () => te().catch((n) => {
165
165
  c("videoSendingBalancer: error", n);
166
- }), Ke = async (n) => (se.add(n), Ge()), W = async ({
166
+ }), Ke = async (n) => (te.add(n), Ge()), j = async ({
167
167
  sender: n,
168
168
  scaleResolutionDownBy: e,
169
169
  maxBitrate: t,
170
170
  onSetParameters: s
171
- }) => Ke(async () => ce(n, { scaleResolutionDownBy: e, maxBitrate: t }, s)), Ye = async ({ sender: n, codec: e }, t) => {
172
- const o = We(e);
173
- return W({
171
+ }) => Ke(async () => ie(n, { scaleResolutionDownBy: e, maxBitrate: t }, s)), Ye = async ({ sender: n, codec: e }, t) => {
172
+ const o = je(e);
173
+ return j({
174
174
  sender: n,
175
175
  maxBitrate: o,
176
176
  onSetParameters: t,
@@ -181,8 +181,8 @@ const he = new Error("Unknown error"), pe = (n = he) => {
181
181
  videoTrack: e,
182
182
  codec: t
183
183
  }, s) => {
184
- const i = e.getSettings().width, u = ne(i ?? 0, t);
185
- return W({
184
+ const i = e.getSettings().width, u = ee(i, t);
185
+ return j({
186
186
  sender: n,
187
187
  maxBitrate: u,
188
188
  onSetParameters: s,
@@ -194,7 +194,7 @@ const he = new Error("Unknown error"), pe = (n = he) => {
194
194
  resolution: t,
195
195
  codec: s
196
196
  }, o) => {
197
- const [r, i] = t.split("x"), { maxBitrate: u, scaleResolutionDownBy: d } = te({
197
+ const [r, i] = t.split("x"), { maxBitrate: u, scaleResolutionDownBy: d } = ne({
198
198
  videoTrack: e,
199
199
  codec: s,
200
200
  targetSize: {
@@ -202,7 +202,7 @@ const he = new Error("Unknown error"), pe = (n = he) => {
202
202
  height: Number(i)
203
203
  }
204
204
  });
205
- return W({
205
+ return j({
206
206
  sender: n,
207
207
  maxBitrate: u,
208
208
  onSetParameters: o,
@@ -232,7 +232,7 @@ const he = new Error("Unknown error"), pe = (n = he) => {
232
232
  default:
233
233
  return U({ sender: t, videoTrack: s, codec: o }, r);
234
234
  }
235
- }, G = {
235
+ }, W = {
236
236
  isChanged: !1,
237
237
  parameters: {
238
238
  encodings: [{}],
@@ -241,18 +241,18 @@ const he = new Error("Unknown error"), pe = (n = he) => {
241
241
  headerExtensions: [],
242
242
  rtcp: {}
243
243
  }
244
- }, K = async ({
244
+ }, G = async ({
245
245
  mainCam: n,
246
246
  resolutionMainCam: e,
247
247
  connection: t,
248
248
  onSetParameters: s,
249
249
  ignoreForCodec: o
250
250
  }) => {
251
- const r = t.getSenders(), i = Ue(r);
251
+ const r = t.getSenders(), i = Ve(r);
252
252
  if (!(i != null && i.track))
253
- return G;
254
- const u = await Ve(i);
255
- return J(u, o) ? G : ze(
253
+ return W;
254
+ const u = await ke(i);
255
+ return Q(u, o) ? W : ze(
256
256
  {
257
257
  mainCam: n,
258
258
  resolutionMainCam: e,
@@ -270,7 +270,7 @@ const he = new Error("Unknown error"), pe = (n = he) => {
270
270
  const { connection: d } = n;
271
271
  if (!d)
272
272
  throw new Error("connection is not exist");
273
- return K({
273
+ return G({
274
274
  connection: d,
275
275
  onSetParameters: t,
276
276
  ignoreForCodec: e
@@ -282,7 +282,7 @@ const he = new Error("Unknown error"), pe = (n = he) => {
282
282
  const { mainCam: C, resolutionMainCam: f } = d, { connection: S } = n;
283
283
  if (!S)
284
284
  throw new Error("connection is not exist");
285
- return K({
285
+ return G({
286
286
  mainCam: C,
287
287
  resolutionMainCam: f,
288
288
  connection: S,
@@ -313,12 +313,11 @@ const he = new Error("Unknown error"), pe = (n = he) => {
313
313
  }) => {
314
314
  if (e && e.length > 0) {
315
315
  const s = t ?? [], o = Qe(n);
316
- if (o === void 0)
317
- throw new Error("No video track");
318
316
  return e.forEach((r, i) => {
319
317
  const u = s[i] ?? {};
320
318
  u.active = !0, r.rid !== void 0 && (u.rid = r.rid), r.scalabilityMode !== void 0 && (u.scalabilityMode = r.scalabilityMode);
321
- const { maxBitrate: d, scaleResolutionDownBy: C } = te({
319
+ const { maxBitrate: d, scaleResolutionDownBy: C } = ne({
320
+ // @ts-expect-error
322
321
  videoTrack: o,
323
322
  targetSize: {
324
323
  width: r.width,
@@ -345,12 +344,12 @@ const he = new Error("Unknown error"), pe = (n = he) => {
345
344
  const r = Ze("video"), i = nn(r, t), u = en(i, e);
346
345
  s.setCodecPreferences(u);
347
346
  }
348
- Object.keys(n).length > 0 && await ae(s.sender, n);
347
+ Object.keys(n).length > 0 && await ce(s.sender, n);
349
348
  } catch (r) {
350
349
  c("updateTransceiver error", r);
351
350
  }
352
- }, j = (n) => {
353
- if (!Se(n) && !fe(n))
351
+ }, X = (n) => {
352
+ if (!Ce(n) && !Se(n))
354
353
  throw n;
355
354
  return { isSuccessful: !1 };
356
355
  }, tn = ({ kind: n, readyState: e }) => n === "video" && e === "live", sn = /* @__PURE__ */ new Set([
@@ -444,7 +443,7 @@ class mn {
444
443
  password: d,
445
444
  user: u,
446
445
  register: C
447
- }).then((S) => (c("connectToServer then"), { ua: S, isSuccessful: !0 })).catch(async (S) => (c("connectToServer catch: error", S), f === !0 ? this.sipConnector.disconnect().then(() => j(S)).catch(() => j(S)) : j(S)));
446
+ }).then((S) => (c("connectToServer then"), { ua: S, isSuccessful: !0 })).catch(async (S) => (c("connectToServer catch: error", S), f === !0 ? this.sipConnector.disconnect().then(() => X(S)).catch(() => X(S)) : X(S)));
448
447
  });
449
448
  a(this, "callToServer", async (e) => {
450
449
  const {
@@ -458,7 +457,7 @@ class mn {
458
457
  sendEncodings: C,
459
458
  offerToReceiveAudio: f,
460
459
  offerToReceiveVideo: S,
461
- directionVideo: F,
460
+ directionVideo: k,
462
461
  directionAudio: V,
463
462
  setRemoteStreams: m,
464
463
  onBeforeProgressCall: g,
@@ -491,7 +490,7 @@ class mn {
491
490
  contentHint: i,
492
491
  offerToReceiveAudio: f,
493
492
  offerToReceiveVideo: S,
494
- directionVideo: F,
493
+ directionVideo: k,
495
494
  directionAudio: V,
496
495
  sendEncodings: P({
497
496
  mediaStream: s,
@@ -504,9 +503,9 @@ class mn {
504
503
  }));
505
504
  let b = !1, _;
506
505
  const w = (c("subscribeEnterConference: onEnterConference", y), p ?? y ? this.sipConnector.onSession("enterRoom", ({ room: l }) => {
507
- c("enterRoom", { _room: l, isSuccessProgressCall: b }), _ = l, k(_) ? p && p() : y && y({ isSuccessProgressCall: b });
506
+ c("enterRoom", { _room: l, isSuccessProgressCall: b }), _ = l, F(_) ? p && p() : y && y({ isSuccessProgressCall: b });
508
507
  }) : () => {
509
- }), L = (l) => (c("onSuccess"), b = !0, A().catch(D), h && h({ isPurgatory: k(_) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
508
+ }), L = (l) => (c("onSuccess"), b = !0, A().catch(D), h && h({ isPurgatory: F(_) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
510
509
  w(), M && M();
511
510
  }), l), $ = (l) => {
512
511
  throw c("onFail"), T && T(), w(), l;
@@ -528,7 +527,7 @@ class mn {
528
527
  offerToReceiveAudio: C,
529
528
  offerToReceiveVideo: f,
530
529
  directionVideo: S,
531
- directionAudio: F,
530
+ directionAudio: k,
532
531
  setRemoteStreams: V,
533
532
  onBeforeProgressCall: m,
534
533
  onSuccessProgressCall: g,
@@ -561,7 +560,7 @@ class mn {
561
560
  offerToReceiveAudio: C,
562
561
  offerToReceiveVideo: f,
563
562
  directionVideo: S,
564
- directionAudio: F,
563
+ directionAudio: k,
565
564
  sendEncodings: P({
566
565
  mediaStream: t,
567
566
  simulcastEncodings: i,
@@ -575,9 +574,9 @@ class mn {
575
574
  };
576
575
  let b = !1, _;
577
576
  const w = (c("subscribeEnterConference: onEnterConference", p), h ?? p ? this.sipConnector.onSession("enterRoom", (l) => {
578
- c("enterRoom", { _room: l, isSuccessProgressCall: b }), _ = l, k(_) ? h && h() : p && p({ isSuccessProgressCall: b });
577
+ c("enterRoom", { _room: l, isSuccessProgressCall: b }), _ = l, F(_) ? h && h() : p && p({ isSuccessProgressCall: b });
579
578
  }) : () => {
580
- }), L = (l) => (c("onSuccess"), b = !0, M().catch(D), g && g({ isPurgatory: k(_) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
579
+ }), L = (l) => (c("onSuccess"), b = !0, M().catch(D), g && g({ isPurgatory: F(_) }), this.sipConnector.onceRaceSession(["ended", "failed"], () => {
581
580
  w(), E && E();
582
581
  }), l), $ = (l) => {
583
582
  throw c("onFail"), y && y(), w(), l;
@@ -715,7 +714,7 @@ class mn {
715
714
  });
716
715
  a(this, "resolveHandleReadyRemoteStreamsDebounced", ({
717
716
  onReadyRemoteStreams: e
718
- }) => me(() => {
717
+ }) => fe(() => {
719
718
  const t = this.sipConnector.getRemoteStreams();
720
719
  c("remoteStreams", t), t && e(t);
721
720
  }, 200));
@@ -728,8 +727,8 @@ class mn {
728
727
  a(this, "getRemoteStreams", () => (c("getRemoteStreams"), this.sipConnector.getRemoteStreams()));
729
728
  a(this, "onUseLicense", (e) => (c("onUseLicense"), this.sipConnector.onSession("useLicense", e)));
730
729
  a(this, "onMustStopPresentation", (e) => (c("onMustStopPresentation"), this.sipConnector.onSession("mustStopPresentation", e)));
731
- a(this, "onMoveToSpectators", (e) => (c("onMoveToSpectators"), this.sipConnector.onSession(ue, e)));
732
- a(this, "onMoveToParticipants", (e) => (c("onMoveToParticipants"), this.sipConnector.onSession(de, e)));
730
+ a(this, "onMoveToSpectators", (e) => (c("onMoveToSpectators"), this.sipConnector.onSession(ae, e)));
731
+ a(this, "onMoveToParticipants", (e) => (c("onMoveToParticipants"), this.sipConnector.onSession(ue, e)));
733
732
  return this.preferredMimeTypesVideoCodecs = t, this.excludeMimeTypesVideoCodecs = s, this.sipConnector = e, new Proxy(this, {
734
733
  get: (o, r, i) => {
735
734
  if (typeof r == "string" && sn.has(r) && r in this.sipConnector) {
@@ -756,10 +755,10 @@ export {
756
755
  _n as disableDebug,
757
756
  An as enableDebug,
758
757
  vn as eventNames,
759
- Ve as getCodecFromSender,
758
+ ke as getCodecFromSender,
760
759
  On as hasCanceledCallError,
761
760
  Nn as hasCanceledStartPresentationError,
762
761
  fn as resolveVideoSendingBalancer,
763
- ae as setParametersToSender,
762
+ ce as setParametersToSender,
764
763
  Sn as tools
765
764
  };