sip-connector 6.24.2 → 6.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/SipConnector-BrUmibLH.cjs +1 -0
  2. package/dist/{SipConnector-BmPmOGi6.js → SipConnector-Dq76GLMy.js} +216 -205
  3. package/dist/SipConnector.d.ts +6 -4
  4. package/dist/__fixtures__/BaseSession.mock.d.ts +4 -4
  5. package/dist/__fixtures__/RTCPeerConnectionMock.d.ts +3 -2
  6. package/dist/__fixtures__/Registrator.mock.d.ts +2 -1
  7. package/dist/__fixtures__/Request.mock.d.ts +1 -0
  8. package/dist/__fixtures__/Session.mock.d.ts +3 -3
  9. package/dist/__fixtures__/UA.mock.d.ts +6 -7
  10. package/dist/__fixtures__/index.d.ts +5 -4
  11. package/dist/__fixtures__/jssip.mock.d.ts +5 -4
  12. package/dist/__fixtures__/participantMoveRequests.d.ts +1 -0
  13. package/dist/constants.d.ts +2 -0
  14. package/dist/doMock.cjs +1 -1
  15. package/dist/doMock.d.ts +2 -1
  16. package/dist/doMock.js +1 -1
  17. package/dist/eventNames.d.ts +2 -2
  18. package/dist/headers.d.ts +3 -0
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.d.ts +2 -1
  21. package/dist/index.js +156 -155
  22. package/dist/logger.d.ts +2 -1
  23. package/dist/tools/__fixtures__/call.d.ts +3 -3
  24. package/dist/tools/__fixtures__/connectToServer.d.ts +3 -2
  25. package/dist/tools/__fixtures__/hasValidUri.d.ts +2 -1
  26. package/dist/tools/__fixtures__/processRequest.d.ts +2 -1
  27. package/dist/tools/answerIncomingCall.d.ts +13 -12
  28. package/dist/tools/callToServer.d.ts +13 -12
  29. package/dist/tools/connectToServer.d.ts +3 -2
  30. package/dist/tools/disconnectFromServer.d.ts +2 -1
  31. package/dist/tools/error/getLinkError.d.ts +2 -1
  32. package/dist/tools/error/getTypeFromError.d.ts +2 -1
  33. package/dist/tools/error/getValuesFromError.d.ts +2 -1
  34. package/dist/tools/getExtraHeaders.d.ts +4 -4
  35. package/dist/tools/getUserAgent.d.ts +2 -2
  36. package/dist/tools/index.d.ts +1 -0
  37. package/dist/tools/resolveAskPermissionToEnableCam.d.ts +2 -1
  38. package/dist/tools/resolveGetRemoteStreams.d.ts +2 -1
  39. package/dist/tools/resolveOnMoveToSpectators.d.ts +4 -0
  40. package/dist/tools/resolveOnMustStopPresentation.d.ts +2 -1
  41. package/dist/tools/resolveOnUseLicense.d.ts +3 -2
  42. package/dist/tools/resolveSendMediaState.d.ts +2 -1
  43. package/dist/tools/resolveSendRefusalToTurnOnCam.d.ts +2 -1
  44. package/dist/tools/resolveSendRefusalToTurnOnMic.d.ts +2 -1
  45. package/dist/tools/resolveStartPresentation.d.ts +3 -2
  46. package/dist/tools/resolveStopShareSipConnector.d.ts +3 -2
  47. package/dist/tools/resolveUpdatePresentation.d.ts +3 -2
  48. package/dist/tools/sendDTMFAccumulated.d.ts +1 -1
  49. package/dist/tools/syncMediaState/index.d.ts +2 -1
  50. package/dist/tools/syncMediaState/resolveOnStartMainCam.d.ts +2 -1
  51. package/dist/tools/syncMediaState/resolveOnStartMic.d.ts +2 -1
  52. package/dist/tools/syncMediaState/resolveOnStopMainCam.d.ts +2 -1
  53. package/dist/tools/syncMediaState/resolveOnStopMic.d.ts +2 -1
  54. package/dist/types.d.ts +2 -1
  55. package/dist/utils.d.ts +2 -2
  56. package/dist/videoSendingBalancer/balance.d.ts +7 -6
  57. package/dist/videoSendingBalancer/index.d.ts +7 -6
  58. package/dist/videoSendingBalancer/processSender.d.ts +5 -4
  59. package/dist/videoSendingBalancer/scaleBitrate.d.ts +1 -1
  60. package/package.json +8 -8
  61. package/dist/SipConnector-DMjzYyq_.cjs +0 -1
@@ -1,6 +1,7 @@
1
- import type { IncomingInfoEvent, IncomingRTCSessionEvent, IncomingRequest, OutgoingInfoEvent, RTCSession, RegisteredEvent, UA, URI, UnRegisteredEvent, WebSocketInterface } from '@krivega/jssip';
2
- import type { TEventSession, TEventUA } from './eventNames';
3
- import type { TCustomError, TJsSIP } from './types';
1
+ import { TCustomError, TJsSIP } from './types';
2
+ import { TEventSession, TEventUA } from './eventNames';
3
+ import { IncomingInfoEvent, IncomingRTCSessionEvent, IncomingRequest, OutgoingInfoEvent, RTCSession, RegisteredEvent, UA, URI, UnRegisteredEvent, WebSocketInterface } from '@krivega/jssip';
4
+
4
5
  export declare const hasCanceledCallError: (error?: TCustomError) => boolean;
5
6
  type TChannels = {
6
7
  inputChannels: string;
@@ -259,7 +260,7 @@ export default class SipConnector {
259
260
  _call: TCall;
260
261
  _answer: TAnswerToIncomingCall;
261
262
  _handleCall: ({ ontrack }: {
262
- ontrack?: TOntrack | undefined;
263
+ ontrack?: TOntrack;
263
264
  }) => Promise<RTCPeerConnection>;
264
265
  _restoreSession: () => void;
265
266
  _sendDTMF: TSendDTMF;
@@ -288,6 +289,7 @@ export default class SipConnector {
288
289
  _triggerParticipantMoveRequestToStream: ({ body: { conference }, }: TMoveRequestToStreamInfoNotify) => void;
289
290
  _triggerEnterRoom: (request: IncomingRequest) => void;
290
291
  _triggerShareState: (request: IncomingRequest) => void;
292
+ _maybeTriggerParticipantMoveRequestToSpectators: (request: IncomingRequest) => void;
291
293
  _triggerMainCamControl: (request: IncomingRequest) => void;
292
294
  _triggerMicControl: (request: IncomingRequest) => void;
293
295
  _triggerUseLicense: (request: IncomingRequest) => void;
@@ -1,7 +1,7 @@
1
- import type { AnswerOptions, ExtraHeaders, HoldOptions, MediaStreamTypes, NameAddrHeader, OnHoldResult, RTCPeerConnectionDeprecated, RTCSession, ReferOptions, RenegotiateOptions, SessionDirection, SessionStatus, TerminateOptions, URI, C as constants } from '@krivega/jssip';
2
- import Events from 'events-constructor';
3
- import type { TEventSession } from '../eventNames';
4
- import { SESSION_EVENT_NAMES } from '../eventNames';
1
+ import { TEventSession, SESSION_EVENT_NAMES } from '../eventNames';
2
+ import { default as Events } from 'events-constructor';
3
+ import { AnswerOptions, ExtraHeaders, HoldOptions, MediaStreamTypes, NameAddrHeader, OnHoldResult, RTCPeerConnectionDeprecated, RTCSession, ReferOptions, RenegotiateOptions, SessionDirection, SessionStatus, TerminateOptions, URI, C as constants } from '@krivega/jssip';
4
+
5
5
  /**
6
6
  * BaseSession
7
7
  * @class
@@ -1,5 +1,6 @@
1
- import type { RTCPeerConnectionDeprecated } from '@krivega/jssip';
2
- import type { MediaStreamTrackMock } from 'webrtc-mock';
1
+ import { MediaStreamTrackMock } from 'webrtc-mock';
2
+ import { RTCPeerConnectionDeprecated } from '@krivega/jssip';
3
+
3
4
  declare class RTCPeerConnectionMock implements RTCPeerConnectionDeprecated {
4
5
  _senders: RTCRtpSender[];
5
6
  _receivers: any[];
@@ -1,4 +1,5 @@
1
- import type { Registrator } from '@krivega/jssip';
1
+ import { Registrator } from '@krivega/jssip';
2
+
2
3
  declare class RegistratorMock implements Registrator {
3
4
  extraHeaders?: string[];
4
5
  setExtraHeaders(extraHeaders: string[]): void;
@@ -1,4 +1,5 @@
1
1
  import { IncomingRequest } from '@krivega/jssip/lib/SIPMessage';
2
+
2
3
  type TExtraHeaders = [string, string][];
3
4
  declare class Request extends IncomingRequest {
4
5
  private readonly headers;
@@ -1,6 +1,6 @@
1
- /// <reference types="jest" />
2
- import type { IncomingInfoEvent } from '@krivega/jssip';
3
- import BaseSession from './BaseSession.mock';
1
+ import { default as BaseSession } from './BaseSession.mock';
2
+ import { IncomingInfoEvent } from '@krivega/jssip';
3
+
4
4
  export declare const FAILED_CONFERENCE_NUMBER = "777";
5
5
  declare class Session extends BaseSession {
6
6
  url: string;
@@ -1,10 +1,9 @@
1
- /// <reference types="jest" />
2
- import type { UA as IUA, IncomingRequest, UAConfiguration, UAConfigurationParams } from '@krivega/jssip';
3
- import Events from 'events-constructor';
4
- import type { TEventUA } from '../eventNames';
5
- import { UA_EVENT_NAMES } from '../eventNames';
6
- import Registrator from './Registrator.mock';
7
- import Session from './Session.mock';
1
+ import { default as Session } from './Session.mock';
2
+ import { default as Registrator } from './Registrator.mock';
3
+ import { TEventUA, UA_EVENT_NAMES } from '../eventNames';
4
+ import { default as Events } from 'events-constructor';
5
+ import { UA as IUA, IncomingRequest, UAConfiguration, UAConfigurationParams } from '@krivega/jssip';
6
+
8
7
  export declare const PASSWORD_CORRECT = "PASSWORD_CORRECT";
9
8
  export declare const PASSWORD_CORRECT_2 = "PASSWORD_CORRECT_2";
10
9
  export declare const NAME_INCORRECT = "NAME_INCORRECT";
@@ -1,4 +1,5 @@
1
1
  import { URI } from '@krivega/jssip';
2
+
2
3
  export declare const user = "user";
3
4
  export declare const displayName = "displayName";
4
5
  export declare const SIP_SERVER_URL = "SIP_SERVER_URL";
@@ -38,7 +39,7 @@ export declare const uaConfigurationWithAuthorization: {
38
39
  display_name: string;
39
40
  register: boolean;
40
41
  session_timers: boolean;
41
- sockets: import("src/__fixtures__/WebSocketInterface.mock").default[];
42
+ sockets: import('./WebSocketInterface.mock').default[];
42
43
  user_agent: string;
43
44
  sdp_semantics: string;
44
45
  register_expires: number;
@@ -51,7 +52,7 @@ export declare const uaConfigurationWithAuthorizationWithDisplayName: {
51
52
  display_name: string;
52
53
  register: boolean;
53
54
  session_timers: boolean;
54
- sockets: import("src/__fixtures__/WebSocketInterface.mock").default[];
55
+ sockets: import('./WebSocketInterface.mock').default[];
55
56
  user_agent: string;
56
57
  sdp_semantics: string;
57
58
  register_expires: number;
@@ -62,7 +63,7 @@ export declare const uaConfigurationWithoutAuthorization: {
62
63
  display_name: string;
63
64
  register: boolean;
64
65
  session_timers: boolean;
65
- sockets: import("src/__fixtures__/WebSocketInterface.mock").default[];
66
+ sockets: import('./WebSocketInterface.mock').default[];
66
67
  user_agent: string;
67
68
  sdp_semantics: string;
68
69
  register_expires: number;
@@ -73,7 +74,7 @@ export declare const uaConfigurationWithoutAuthorizationWithoutDisplayName: {
73
74
  display_name: string;
74
75
  register: boolean;
75
76
  session_timers: boolean;
76
- sockets: import("src/__fixtures__/WebSocketInterface.mock").default[];
77
+ sockets: import('./WebSocketInterface.mock').default[];
77
78
  user_agent: string;
78
79
  sdp_semantics: string;
79
80
  register_expires: number;
@@ -1,6 +1,7 @@
1
- import type { RTCSession, UA } from '@krivega/jssip';
2
- import UAmock from './UA.mock';
3
- import WebSocketInterfaceMock from './WebSocketInterface.mock';
1
+ import { default as WebSocketInterfaceMock } from './WebSocketInterface.mock';
2
+ import { default as UAmock } from './UA.mock';
3
+ import { RTCSession, UA } from '@krivega/jssip';
4
+
4
5
  declare const jssip: {
5
6
  triggerNewInfo: (session: RTCSession, extraHeaders: [
6
7
  string,
@@ -11,7 +12,7 @@ declare const jssip: {
11
12
  string
12
13
  ][]) => void;
13
14
  triggerIncomingSession: (ua: UAmock, { incomingNumber, displayName, host, }: {
14
- incomingNumber?: string | undefined;
15
+ incomingNumber?: string;
15
16
  displayName: string;
16
17
  host: string;
17
18
  }) => void;
@@ -10,3 +10,4 @@ export declare const moveRequestToStreamHeaders: [string, string][];
10
10
  export declare const moveRequestToStreamData: {
11
11
  conference: string;
12
12
  };
13
+ export declare const moveRequestToSpectatorsHeaders: [string, string][];
@@ -31,6 +31,7 @@ export declare const ADMIN_FORCE_SYNC_MEDIA_STATE = "admin-force-sync-media-stat
31
31
  export declare const PARTICIPANT_ADDED_TO_LIST_MODERATORS = "participant:added-to-list-moderators";
32
32
  export declare const PARTICIPANT_REMOVED_FROM_LIST_MODERATORS = "participant:removed-from-list-moderators";
33
33
  export declare const PARTICIPANT_MOVE_REQUEST_TO_STREAM = "participant:move-request-to-stream";
34
+ export declare const PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS = "participant:move-request-to-spectators";
34
35
  export declare const PARTICIPATION_ACCEPTING_WORD_REQUEST = "participation:accepting-word-request";
35
36
  export declare const PARTICIPATION_CANCELLING_WORD_REQUEST = "participation:cancelling-word-request";
36
37
  export declare const WEBCAST_STARTED = "webcast:started";
@@ -67,3 +68,4 @@ export declare const PRESENTATION_STARTED = "presentation:started";
67
68
  export declare const PRESENTATION_END = "presentation:end";
68
69
  export declare const PRESENTATION_ENDED = "presentation:ended";
69
70
  export declare const PRESENTATION_FAILED = "presentation:failed";
71
+ export declare const SPECTATOR = "SPECTATOR";
package/dist/doMock.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var k=Object.defineProperty;var L=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(L(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("./SipConnector-DMjzYyq_.cjs"),P=require("@krivega/jssip/lib/NameAddrHeader"),x=require("@krivega/jssip/lib/URI"),F=require("node:events"),U=require("@krivega/jssip/lib/SIPMessage"),R=require("events-constructor"),C=require("@krivega/jssip");class y extends U.IncomingRequest{constructor(t){super();n(this,"headers");this.headers=new Headers(t)}getHeader(t){return this.headers.get(t)||""}}var V=Object.defineProperty,z=(r,e,t)=>e in r?V(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,s=(r,e,t)=>(z(r,typeof e!="symbol"?e+"":e,t),t);const m="ended",q="mute",H="isolationchange",j="overconstrained",B="unmute",$=[m,q,B,H,j];class A{constructor(e,{id:t="identifier",constraints:i={}}={}){s(this,"events"),s(this,"id"),s(this,"kind"),s(this,"constraints"),s(this,"enabled"),s(this,"contentHint",""),s(this,"readyState","live"),s(this,"isolated",!1),s(this,"label",""),s(this,"muted",!1),s(this,"onended",null),s(this,"onisolationchange",null),s(this,"onmute",null),s(this,"onunmute",null),s(this,"getConstraints",()=>this.constraints),s(this,"stop",()=>{const o={...new Event(m)};this.events.trigger(m,o),this.readyState=m,this.onended&&this.onended(o)}),s(this,"addEventListener",(o,a)=>{this.events.on(o,a)}),s(this,"removeEventListener",(o,a)=>{this.events.off(o,a)}),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints={...i},this.events=new R($)}clone(){return{...this}}getCapabilities(){return{width:{min:352,max:4096},height:{min:288,max:2160}}}getSettings(){let e=0,t=0;return typeof this.constraints.width=="object"&&this.constraints.width.ideal!==void 0?e=this.constraints.width.ideal:typeof this.constraints.width=="object"&&this.constraints.width.exact!==void 0?e=this.constraints.width.exact:typeof this.constraints.width=="number"&&this.constraints.width&&(e=this.constraints.width),typeof this.constraints.height=="object"&&this.constraints.height.ideal!==void 0?t=this.constraints.height.ideal:typeof this.constraints.height=="object"&&this.constraints.height.exact!==void 0?t=this.constraints.height.exact:typeof this.constraints.height=="number"&&this.constraints.height&&(t=this.constraints.height),{width:e,height:t}}async applyConstraints(e){this.constraints={...e}}dispatchEvent(e){const t=e.type;return this.events.trigger(t,e),!0}}const K=r=>new A("audio",r),Y=r=>new A("video",r);class J{constructor({originator:e="local",eventHandlers:t}){n(this,"originator");n(this,"_connection");n(this,"_events");n(this,"_remote_identity");n(this,"_mutedOptions",{audio:!1,video:!1});this.originator=e,this._events=new R(g.SESSION_EVENT_NAMES),this.initEvents(t)}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}set data(e){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}get connection(){return this._connection}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 remote_identity(){return this._remote_identity}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.")}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,i){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,i])=>this.on(t,i))}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 G{constructor(e,t){n(this,"_senders",[]);n(this,"_receivers",[]);n(this,"canTrickleIceCandidates");n(this,"connectionState");n(this,"currentLocalDescription");n(this,"currentRemoteDescription");n(this,"iceConnectionState");n(this,"iceGatheringState");n(this,"idpErrorInfo");n(this,"idpLoginUrl");n(this,"localDescription");n(this,"onconnectionstatechange");n(this,"ondatachannel");n(this,"onicecandidate");n(this,"onicecandidateerror",null);n(this,"oniceconnectionstatechange");n(this,"onicegatheringstatechange");n(this,"onnegotiationneeded");n(this,"onsignalingstatechange");n(this,"ontrack");n(this,"peerIdentity");n(this,"pendingLocalDescription");n(this,"pendingRemoteDescription");n(this,"remoteDescription");n(this,"sctp",null);n(this,"signalingState");n(this,"getReceivers",()=>this._receivers);n(this,"getSenders",()=>this._senders);n(this,"addTrack",e=>{const t={track:e};return this._senders.push(t),t});this._receivers=t.map(i=>({track:i}))}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,i){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,i){throw new Error("Method not implemented.")}removeEventListener(e,t,i){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}}function X(r){const e=r.match(/[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const E=400,I="777",Q=r=>r.getVideoTracks().length>0;class b extends J{constructor({url:t="",mediaStream:i,eventHandlers:o,originator:a}){super({originator:a,eventHandlers:o});n(this,"url");n(this,"status_code");n(this,"_isEnded",!1);n(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)},E)}));this.url=t,this.initPeerconnection(i)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const i=K();i.id="mainaudio1";const o=[i];if(Q(t)){const c=Y();c.id="mainvideo1",o.push(c)}this._connection=new G(void 0,o),this._addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},E)}connect(t){const i=X(t);setTimeout(()=>{this.url.includes(I)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:g.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",i)},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},E)}terminate({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t}),this._isEnded=!1,this}terminateRemote({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t,originator:"remote"}),this}_addStream(t,i="getTracks"){t[i]().forEach(o=>this.connection.addTrack(o))}_forEachSenders(t){const i=this.connection.getSenders();for(const o of i)t(o);return i}_toggleMuteAudio(t){this._forEachSenders(({track:i})=>{i&&i.kind==="audio"&&(i.enabled=!t)})}_toggleMuteVideo(t){this._forEachSenders(({track:i})=>{i&&i.kind==="video"&&(i.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){return t}_onmute({audio:t,video:i}){this.trigger("muted",{audio:t,video:i})}async sendInfo(){}isEnded(){return this._isEnded}newInfo(t){this.trigger("newInfo",t)}}class Z{constructor(){n(this,"extraHeaders")}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",f="PASSWORD_CORRECT_2",O="NAME_INCORRECT",u=400,l=class l{constructor(e){n(this,"_events");n(this,"_startedTimeout");n(this,"_stopedTimeout");n(this,"session");n(this,"_isRegistered");n(this,"_isConnected");n(this,"configuration");n(this,"_registrator");n(this,"call",jest.fn((e,t)=>{const{mediaStream:i,eventHandlers:o}=t;return this.session=new b({url:e,mediaStream:i,eventHandlers:o,originator:"local"}),this.session.connect(e),this.session}));this._events=new R(g.UA_EVENT_NAMES);const[t,i]=e.uri.split(":"),[o,a]=i.split("@"),c={...e,uri:new C.URI(t,o,a)};this.configuration=c,this._registrator=new Z}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}start(){this.register()}stop(){this._startedTimeout&&clearTimeout(this._startedTimeout),this._stopedTimeout&&clearTimeout(this._stopedTimeout),this.unregister(),this.isStarted()?this._stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:new Error("stoped")})},u):this.trigger("disconnected",{error:new Error("stoped")})}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(){this.session.terminate()}set(e,t){return this.configuration[e]=t,!0}register(){this._startedTimeout&&clearTimeout(this._startedTimeout);const{password:e,register:t,uri:i}=this.configuration;t&&i.user.includes(O)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},u)):!this._isRegistered&&t&&(e===d||e===f)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},u)):t&&e!==d&&e!==f&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},u)),l.isAvailableTelephony?(this.trigger("connected"),this._isConnected=!0):this.stop()}unregister(){this._isRegistered=!1,this._isConnected=!1,this.trigger("unregistered")}isRegistered(){return!!this._isRegistered}isStarted(){return this.configuration&&(this.configuration.register&&!!this._isRegistered||!this.configuration.register&&!!this._isConnected)}registrator(){return this._registrator}newSipEvent(e){this.trigger("sipEvent",e)}};n(l,"isAvailableTelephony",!0);let v=l;class ee{constructor(e){n(this,"url");this.url=e}}class te extends F.EventEmitter{constructor(t,i){super();n(this,"contentType");n(this,"body");this.contentType=t,this.body=i}}const M="remote",ne=(r,e)=>{const t=new y(e),i={originator:M,request:t,info:new te("","")};r.newInfo(i)},ie=(r,e)=>{const i={request:new y(e)};r.newSipEvent(i)},re=(r,{incomingNumber:e="1234",displayName:t,host:i})=>{const o=new b({originator:M}),a=new x("sip",e,i);o._remote_identity=new P(a,t),r.trigger("newRTCSession",{originator:M,session:o})},oe=(r,e)=>{e?r.trigger("failed",e):r.trigger("failed",r)},N={triggerNewInfo:ne,triggerNewSipEvent:ie,triggerIncomingSession:re,triggerFailIncomingSession:oe,WebSocketInterface:ee,UA:v,C:{INVITE:"INVITE"}},_="user",h="displayName",p="SIP_SERVER_URL",S="SIP_WEB_SOCKET_SERVER_URL",se=new N.WebSocketInterface(S),T={userAgent:"Chrome",sipServerUrl:p,sipWebSocketServerURL:S},ae={...T},W={...T,user:_,password:d,register:!0},de={...W,displayName:h},he={...T,displayName:h,register:!1},w={session_timers:!1,sockets:[se],user_agent:"Chrome",sdp_semantics:"plan-b",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},ce={...w,password:d,uri:new C.URI("sip",_,p),display_name:"",register:!0},ue={...w,password:d,uri:new C.URI("sip",_,p),display_name:h,register:!0},me={...w,display_name:h,register:!1},le={...w,display_name:"",register:!1},D="10.10.10.10",ge=[`X-Vinteo-Remote: ${D}`],_e=()=>new g.SipConnector({JsSIP:N});exports.FAILED_CONFERENCE_NUMBER=I;exports.NAME_INCORRECT=O;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=f;exports.SIP_SERVER_URL=p;exports.SIP_WEB_SOCKET_SERVER_URL=S;exports.dataForConnectionWithAuthorization=W;exports.dataForConnectionWithAuthorizationWithDisplayName=de;exports.dataForConnectionWithoutAuthorization=he;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=ae;exports.default=_e;exports.displayName=h;exports.extraHeadersRemoteAddress=ge;exports.remoteAddress=D;exports.uaConfigurationWithAuthorization=ce;exports.uaConfigurationWithAuthorizationWithDisplayName=ue;exports.uaConfigurationWithoutAuthorization=me;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=le;exports.user=_;
1
+ "use strict";var k=Object.defineProperty;var L=(r,e,t)=>e in r?k(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(L(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("./SipConnector-BrUmibLH.cjs"),P=require("@krivega/jssip/lib/NameAddrHeader"),x=require("@krivega/jssip/lib/URI"),F=require("node:events"),U=require("@krivega/jssip/lib/SIPMessage"),R=require("events-constructor"),C=require("@krivega/jssip");class y extends U.IncomingRequest{constructor(t){super();n(this,"headers");this.headers=new Headers(t)}getHeader(t){return this.headers.get(t)||""}}var V=Object.defineProperty,z=(r,e,t)=>e in r?V(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,s=(r,e,t)=>(z(r,typeof e!="symbol"?e+"":e,t),t);const m="ended",q="mute",H="isolationchange",j="overconstrained",B="unmute",$=[m,q,B,H,j];class A{constructor(e,{id:t="identifier",constraints:i={}}={}){s(this,"events"),s(this,"id"),s(this,"kind"),s(this,"constraints"),s(this,"enabled"),s(this,"contentHint",""),s(this,"readyState","live"),s(this,"isolated",!1),s(this,"label",""),s(this,"muted",!1),s(this,"onended",null),s(this,"onisolationchange",null),s(this,"onmute",null),s(this,"onunmute",null),s(this,"getConstraints",()=>this.constraints),s(this,"stop",()=>{const o={...new Event(m)};this.events.trigger(m,o),this.readyState=m,this.onended&&this.onended(o)}),s(this,"addEventListener",(o,a)=>{this.events.on(o,a)}),s(this,"removeEventListener",(o,a)=>{this.events.off(o,a)}),this.id=`${t}-${e}-track`,this.kind=e,this.enabled=!0,this.constraints={...i},this.events=new R($)}clone(){return{...this}}getCapabilities(){return{width:{min:352,max:4096},height:{min:288,max:2160}}}getSettings(){let e=0,t=0;return typeof this.constraints.width=="object"&&this.constraints.width.ideal!==void 0?e=this.constraints.width.ideal:typeof this.constraints.width=="object"&&this.constraints.width.exact!==void 0?e=this.constraints.width.exact:typeof this.constraints.width=="number"&&this.constraints.width&&(e=this.constraints.width),typeof this.constraints.height=="object"&&this.constraints.height.ideal!==void 0?t=this.constraints.height.ideal:typeof this.constraints.height=="object"&&this.constraints.height.exact!==void 0?t=this.constraints.height.exact:typeof this.constraints.height=="number"&&this.constraints.height&&(t=this.constraints.height),{width:e,height:t}}async applyConstraints(e){this.constraints={...e}}dispatchEvent(e){const t=e.type;return this.events.trigger(t,e),!0}}const K=r=>new A("audio",r),Y=r=>new A("video",r);class J{constructor({originator:e="local",eventHandlers:t}){n(this,"originator");n(this,"_connection");n(this,"_events");n(this,"_remote_identity");n(this,"_mutedOptions",{audio:!1,video:!1});this.originator=e,this._events=new R(g.SESSION_EVENT_NAMES),this.initEvents(t)}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}set data(e){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}get connection(){return this._connection}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 remote_identity(){return this._remote_identity}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.")}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,i){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,i])=>this.on(t,i))}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 G{constructor(e,t){n(this,"_senders",[]);n(this,"_receivers",[]);n(this,"canTrickleIceCandidates");n(this,"connectionState");n(this,"currentLocalDescription");n(this,"currentRemoteDescription");n(this,"iceConnectionState");n(this,"iceGatheringState");n(this,"idpErrorInfo");n(this,"idpLoginUrl");n(this,"localDescription");n(this,"onconnectionstatechange");n(this,"ondatachannel");n(this,"onicecandidate");n(this,"onicecandidateerror",null);n(this,"oniceconnectionstatechange");n(this,"onicegatheringstatechange");n(this,"onnegotiationneeded");n(this,"onsignalingstatechange");n(this,"ontrack");n(this,"peerIdentity");n(this,"pendingLocalDescription");n(this,"pendingRemoteDescription");n(this,"remoteDescription");n(this,"sctp",null);n(this,"signalingState");n(this,"getReceivers",()=>this._receivers);n(this,"getSenders",()=>this._senders);n(this,"addTrack",e=>{const t={track:e};return this._senders.push(t),t});this._receivers=t.map(i=>({track:i}))}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,i){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,i){throw new Error("Method not implemented.")}removeEventListener(e,t,i){throw new Error("Method not implemented.")}dispatchEvent(e){throw new Error("Method not implemented.")}}function X(r){const e=r.match(/[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const E=400,I="777",Q=r=>r.getVideoTracks().length>0;class b extends J{constructor({url:t="",mediaStream:i,eventHandlers:o,originator:a}){super({originator:a,eventHandlers:o});n(this,"url");n(this,"status_code");n(this,"_isEnded",!1);n(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)},E)}));this.url=t,this.initPeerconnection(i)}initPeerconnection(t){return t?(this.createPeerconnection(t),!0):!1}createPeerconnection(t){const i=K();i.id="mainaudio1";const o=[i];if(Q(t)){const c=Y();c.id="mainvideo1",o.push(c)}this._connection=new G(void 0,o),this._addStream(t),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},E)}connect(t){const i=X(t);setTimeout(()=>{this.url.includes(I)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:g.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",i)},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},E)}terminate({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t}),this._isEnded=!1,this}terminateRemote({status_code:t}={}){return this.status_code=t,this.trigger("ended",{status_code:t,originator:"remote"}),this}_addStream(t,i="getTracks"){t[i]().forEach(o=>this.connection.addTrack(o))}_forEachSenders(t){const i=this.connection.getSenders();for(const o of i)t(o);return i}_toggleMuteAudio(t){this._forEachSenders(({track:i})=>{i&&i.kind==="audio"&&(i.enabled=!t)})}_toggleMuteVideo(t){this._forEachSenders(({track:i})=>{i&&i.kind==="video"&&(i.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){return t}_onmute({audio:t,video:i}){this.trigger("muted",{audio:t,video:i})}async sendInfo(){}isEnded(){return this._isEnded}newInfo(t){this.trigger("newInfo",t)}}class Z{constructor(){n(this,"extraHeaders")}setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",f="PASSWORD_CORRECT_2",O="NAME_INCORRECT",u=400,l=class l{constructor(e){n(this,"_events");n(this,"_startedTimeout");n(this,"_stopedTimeout");n(this,"session");n(this,"_isRegistered");n(this,"_isConnected");n(this,"configuration");n(this,"_registrator");n(this,"call",jest.fn((e,t)=>{const{mediaStream:i,eventHandlers:o}=t;return this.session=new b({url:e,mediaStream:i,eventHandlers:o,originator:"local"}),this.session.connect(e),this.session}));this._events=new R(g.UA_EVENT_NAMES);const[t,i]=e.uri.split(":"),[o,a]=i.split("@"),c={...e,uri:new C.URI(t,o,a)};this.configuration=c,this._registrator=new Z}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}start(){this.register()}stop(){this._startedTimeout&&clearTimeout(this._startedTimeout),this._stopedTimeout&&clearTimeout(this._stopedTimeout),this.unregister(),this.isStarted()?this._stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:new Error("stoped")})},u):this.trigger("disconnected",{error:new Error("stoped")})}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(){this.session.terminate()}set(e,t){return this.configuration[e]=t,!0}register(){this._startedTimeout&&clearTimeout(this._startedTimeout);const{password:e,register:t,uri:i}=this.configuration;t&&i.user.includes(O)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},u)):!this._isRegistered&&t&&(e===d||e===f)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},u)):t&&e!==d&&e!==f&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},u)),l.isAvailableTelephony?(this.trigger("connected"),this._isConnected=!0):this.stop()}unregister(){this._isRegistered=!1,this._isConnected=!1,this.trigger("unregistered")}isRegistered(){return!!this._isRegistered}isStarted(){return this.configuration&&(this.configuration.register&&!!this._isRegistered||!this.configuration.register&&!!this._isConnected)}registrator(){return this._registrator}newSipEvent(e){this.trigger("sipEvent",e)}};n(l,"isAvailableTelephony",!0);let v=l;class ee{constructor(e){n(this,"url");this.url=e}}class te extends F.EventEmitter{constructor(t,i){super();n(this,"contentType");n(this,"body");this.contentType=t,this.body=i}}const M="remote",ne=(r,e)=>{const t=new y(e),i={originator:M,request:t,info:new te("","")};r.newInfo(i)},ie=(r,e)=>{const i={request:new y(e)};r.newSipEvent(i)},re=(r,{incomingNumber:e="1234",displayName:t,host:i})=>{const o=new b({originator:M}),a=new x("sip",e,i);o._remote_identity=new P(a,t),r.trigger("newRTCSession",{originator:M,session:o})},oe=(r,e)=>{e?r.trigger("failed",e):r.trigger("failed",r)},N={triggerNewInfo:ne,triggerNewSipEvent:ie,triggerIncomingSession:re,triggerFailIncomingSession:oe,WebSocketInterface:ee,UA:v,C:{INVITE:"INVITE"}},_="user",h="displayName",p="SIP_SERVER_URL",S="SIP_WEB_SOCKET_SERVER_URL",se=new N.WebSocketInterface(S),T={userAgent:"Chrome",sipServerUrl:p,sipWebSocketServerURL:S},ae={...T},W={...T,user:_,password:d,register:!0},de={...W,displayName:h},he={...T,displayName:h,register:!1},w={session_timers:!1,sockets:[se],user_agent:"Chrome",sdp_semantics:"plan-b",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},ce={...w,password:d,uri:new C.URI("sip",_,p),display_name:"",register:!0},ue={...w,password:d,uri:new C.URI("sip",_,p),display_name:h,register:!0},me={...w,display_name:h,register:!1},le={...w,display_name:"",register:!1},D="10.10.10.10",ge=[`X-Vinteo-Remote: ${D}`],_e=()=>new g.SipConnector({JsSIP:N});exports.FAILED_CONFERENCE_NUMBER=I;exports.NAME_INCORRECT=O;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=f;exports.SIP_SERVER_URL=p;exports.SIP_WEB_SOCKET_SERVER_URL=S;exports.dataForConnectionWithAuthorization=W;exports.dataForConnectionWithAuthorizationWithDisplayName=de;exports.dataForConnectionWithoutAuthorization=he;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=ae;exports.default=_e;exports.displayName=h;exports.extraHeadersRemoteAddress=ge;exports.remoteAddress=D;exports.uaConfigurationWithAuthorization=ce;exports.uaConfigurationWithAuthorizationWithDisplayName=ue;exports.uaConfigurationWithoutAuthorization=me;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=le;exports.user=_;
package/dist/doMock.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import SIPconnector from './SipConnector';
1
+ import { default as SIPconnector } from './SipConnector';
2
+
2
3
  declare const doMock: () => SIPconnector;
3
4
  export default doMock;
4
5
  export { FAILED_CONFERENCE_NUMBER } from './__fixtures__/Session.mock';
package/dist/doMock.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var A = Object.defineProperty;
2
2
  var O = (i, e, t) => e in i ? A(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
3
  var n = (i, e, t) => (O(i, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { j as k, R as N, U as L, S as D } from "./SipConnector-BmPmOGi6.js";
4
+ import { j as k, R as N, U as L, S as D } from "./SipConnector-Dq76GLMy.js";
5
5
  import W from "@krivega/jssip/lib/NameAddrHeader";
6
6
  import P from "@krivega/jssip/lib/URI";
7
7
  import { EventEmitter as x } from "node:events";
@@ -1,8 +1,8 @@
1
1
  export declare const UA_SYNTHETICS_EVENT_NAMES: readonly ["incomingCall", "declinedIncomingCall", "terminatedIncomingCall", "failedIncomingCall", "participation:accepting-word-request", "participation:cancelling-word-request", "participant:move-request-to-stream", "channels:notify", "conference:participant-token-issued", "account:changed", "account:deleted", "webcast:started", "webcast:stopped", "participant:added-to-list-moderators", "participant:removed-from-list-moderators"];
2
2
  export declare const UA_JSSIP_EVENT_NAMES: readonly ["connecting", "connected", "disconnected", "newRTCSession", "registered", "unregistered", "registrationFailed", "newMessage", "sipEvent"];
3
- export declare const SESSION_SYNTHETICS_EVENT_NAMES: readonly ["availableSecondRemoteStream", "notAvailableSecondRemoteStream", "mustStopPresentation", "shareState", "enterRoom", "useLicense", "peerconnection:confirmed", "peerconnection:ontrack", "channels", "ended:fromserver", "main-cam-control", "admin-start-main-cam", "admin-stop-main-cam", "admin-stop-mic", "admin-start-mic", "admin-force-sync-media-state"];
3
+ export declare const SESSION_SYNTHETICS_EVENT_NAMES: readonly ["availableSecondRemoteStream", "notAvailableSecondRemoteStream", "mustStopPresentation", "shareState", "enterRoom", "useLicense", "peerconnection:confirmed", "peerconnection:ontrack", "channels", "ended:fromserver", "main-cam-control", "admin-start-main-cam", "admin-stop-main-cam", "admin-stop-mic", "admin-start-mic", "admin-force-sync-media-state", "participant:move-request-to-spectators"];
4
4
  export declare const SESSION_JSSIP_EVENT_NAMES: readonly ["ended", "connecting", "sending", "reinvite", "replaces", "refer", "progress", "accepted", "confirmed", "peerconnection", "failed", "muted", "unmuted", "newDTMF", "newInfo", "hold", "unhold", "update", "sdp", "icecandidate", "getusermediafailed", "peerconnection:createofferfailed", "peerconnection:createanswerfailed", "peerconnection:setlocaldescriptionfailed", "peerconnection:setremotedescriptionfailed", "presentation:start", "presentation:started", "presentation:end", "presentation:ended", "presentation:failed"];
5
5
  export declare const UA_EVENT_NAMES: ("incomingCall" | "declinedIncomingCall" | "failedIncomingCall" | "terminatedIncomingCall" | "connecting" | "connected" | "disconnected" | "newRTCSession" | "registered" | "unregistered" | "registrationFailed" | "newMessage" | "sipEvent" | "channels:notify" | "participant:added-to-list-moderators" | "participant:removed-from-list-moderators" | "participant:move-request-to-stream" | "participation:accepting-word-request" | "participation:cancelling-word-request" | "webcast:started" | "webcast:stopped" | "account:changed" | "account:deleted" | "conference:participant-token-issued")[];
6
- export declare const SESSION_EVENT_NAMES: readonly ["ended", "connecting", "sending", "reinvite", "replaces", "refer", "progress", "accepted", "confirmed", "peerconnection", "failed", "muted", "unmuted", "newDTMF", "newInfo", "hold", "unhold", "update", "sdp", "icecandidate", "getusermediafailed", "peerconnection:createofferfailed", "peerconnection:createanswerfailed", "peerconnection:setlocaldescriptionfailed", "peerconnection:setremotedescriptionfailed", "presentation:start", "presentation:started", "presentation:end", "presentation:ended", "presentation:failed", "availableSecondRemoteStream", "notAvailableSecondRemoteStream", "mustStopPresentation", "shareState", "enterRoom", "useLicense", "peerconnection:confirmed", "peerconnection:ontrack", "channels", "ended:fromserver", "main-cam-control", "admin-start-main-cam", "admin-stop-main-cam", "admin-stop-mic", "admin-start-mic", "admin-force-sync-media-state"];
6
+ export declare const SESSION_EVENT_NAMES: readonly ["ended", "connecting", "sending", "reinvite", "replaces", "refer", "progress", "accepted", "confirmed", "peerconnection", "failed", "muted", "unmuted", "newDTMF", "newInfo", "hold", "unhold", "update", "sdp", "icecandidate", "getusermediafailed", "peerconnection:createofferfailed", "peerconnection:createanswerfailed", "peerconnection:setlocaldescriptionfailed", "peerconnection:setremotedescriptionfailed", "presentation:start", "presentation:started", "presentation:end", "presentation:ended", "presentation:failed", "availableSecondRemoteStream", "notAvailableSecondRemoteStream", "mustStopPresentation", "shareState", "enterRoom", "useLicense", "peerconnection:confirmed", "peerconnection:ontrack", "channels", "ended:fromserver", "main-cam-control", "admin-start-main-cam", "admin-stop-main-cam", "admin-stop-mic", "admin-start-mic", "admin-force-sync-media-state", "participant:move-request-to-spectators"];
7
7
  export type TEventUA = (typeof UA_EVENT_NAMES)[number];
8
8
  export type TEventSession = (typeof SESSION_EVENT_NAMES)[number];
package/dist/headers.d.ts CHANGED
@@ -19,6 +19,8 @@ export declare const HEADER_MEDIA_STATE = "X-WEBRTC-MEDIA-STATE";
19
19
  export declare const HEADER_MEDIA_TYPE = "X-Vinteo-Media-Type";
20
20
  export declare const HEADER_MAIN_CAM_STATE = "X-Vinteo-MainCam-State";
21
21
  export declare const HEADER_MIC_STATE = "X-Vinteo-Mic-State";
22
+ export declare const CONTENT_TYPE_PARTICIPANT_STATE = "application/vinteo.webrtc.partstate";
23
+ export declare const HEADER_CONTENT_PARTICIPANT_STATE = "X-WEBRTC-PARTSTATE";
22
24
  export declare const CONTENT_TYPE_NOTIFY = "application/vinteo.webrtc.notify";
23
25
  export declare const HEADER_NOTIFY = "X-VINTEO-NOTIFY";
24
26
  export declare const HEADER_CONTENT_SHARE_STATE = "x-webrtc-share-state";
@@ -27,6 +29,7 @@ export declare const HEADER_STOP_PRESENTATION = "x-webrtc-share-state: STOPPRESE
27
29
  export declare const AVAILABLE_SECOND_REMOTE_STREAM = "YOUCANRECEIVECONTENT";
28
30
  export declare const NOT_AVAILABLE_SECOND_REMOTE_STREAM = "CONTENTEND";
29
31
  export declare const MUST_STOP_PRESENTATION = "YOUMUSTSTOPSENDCONTENT";
32
+ export declare const HEADER_MUST_STOP_PRESENTATION_P2P = "x-webrtc-share-state: YOUMUSTSTOPSENDCONTENT";
30
33
  export declare const HEADER_START_PRESENTATION_P2P = "x-webrtc-share-state: YOUCANRECEIVECONTENT";
31
34
  export declare const HEADER_STOP_PRESENTATION_P2P = "x-webrtc-share-state: CONTENTEND";
32
35
  export declare const HEADER_CONTENT_ENABLE_MEDIA_DEVICE = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE";
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("./SipConnector-DMjzYyq_.cjs"),q=require("ts-debounce"),Y=require("@krivega/cancelable-promise"),z=require("debug"),x="purgatory",P=e=>e===x,B=e=>()=>(s.logger("getRemoteStreams"),e.getRemoteStreams()),J=({kind:e,readyState:n})=>e==="video"&&n==="live",V=e=>({track:n})=>{J(n)&&e()},D=({getRemoteStreams:e,setRemoteStreams:n})=>q.debounce(()=>{const t=e();s.logger("remoteStreams",t),t&&n(t)},200),Q=e=>async t=>{const{mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,setRemoteStreams:u,onBeforeProgressCall:d,onSuccessProgressCall:C,onEnterPurgatory:f,onEnterConference:m,onFailProgressCall:y,onFinishProgressCall:E,onEndedCall:M}=t,R=D({setRemoteStreams:u,getRemoteStreams:B(e)}),T=V(R);s.logger("answerIncomingCall",t);const O=async()=>e.answerToIncomingCall({mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,ontrack:T}),A=()=>{const{remoteCallerData:l}=e;return l.incomingNumber};let _=!1,i;const g=(s.logger("subscribeEnterConference: onEnterConference",m),f??m?e.onSession("enterRoom",l=>{s.logger("enterRoom",{_room:l,isSuccessProgressCall:_}),i=l,P(i)?f&&f():m&&m({isSuccessProgressCall:_})}):()=>{}),h=l=>(s.logger("onSuccess"),_=!0,R(),C&&C({isPurgatory:P(i)}),e.onceRaceSession(["ended","failed"],()=>{g(),M&&M()}),l),b=l=>{throw s.logger("onFail"),y&&y(),g(),l},N=()=>{s.logger("onFinish"),E&&E()};if(s.logger("onBeforeProgressCall"),d){const l=A();d(l)}return O().then(h).catch(l=>b(l)).finally(N)},Z=e=>async t=>{const{conference:r,mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,setRemoteStreams:d,onBeforeProgressCall:C,onSuccessProgressCall:f,onEnterPurgatory:m,onEnterConference:y,onFailProgressCall:E,onFinishProgressCall:M,onEndedCall:R}=t,T=D({setRemoteStreams:d,getRemoteStreams:B(e)}),O=V(T);s.logger("callToServer",t);const A=async()=>(s.logger("startCall"),e.call({mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,number:r,ontrack:O}));let _=!1,i;const g=(s.logger("subscribeEnterConference: onEnterConference",y),m??y?e.onSession("enterRoom",l=>{s.logger("enterRoom",{_room:l,isSuccessProgressCall:_}),i=l,P(i)?m&&m():y&&y({isSuccessProgressCall:_})}):()=>{}),h=l=>(s.logger("onSuccess"),_=!0,T(),f&&f({isPurgatory:P(i)}),e.onceRaceSession(["ended","failed"],()=>{g(),R&&R()}),l),b=l=>{throw s.logger("onFail"),E&&E(),g(),l},N=()=>{s.logger("onFinish"),M&&M()};return s.logger("onBeforeProgressCall"),C&&C(r),A().then(h).catch(l=>b(l)).finally(N)},p=e=>{if(!Y.isCanceledError(e))throw e;return{isSuccessful:!1}},ee=e=>async t=>{const{userAgent:r,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,name:d,password:C,isRegisteredUser:f,sdpSemantics:m,isDisconnectOnFail:y}=t;return s.logger("connectToServer",t),e.connect({userAgent:r,sdpSemantics:m,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,password:C,user:d,register:f}).then(E=>(s.logger("connectToServer then"),{ua:E,isSuccessful:!0})).catch(async E=>(s.logger("connectToServer catch: error",E),y===!0?e.disconnect().then(()=>p(E)).catch(()=>p(E)):p(E)))},ne=e=>async()=>(s.logger("disconnectFromServer"),e.disconnect().then(()=>(s.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(n=>(s.logger("disconnectFromServer: catch",n),{isSuccessful:!1}))),k=e=>{const{url:n,cause:t}=e;let r=n;return(t===s.BAD_MEDIA_DESCRIPTION||t===s.NOT_FOUND)&&(r=`${e.message.to.uri.user}@${e.message.to.uri.host}`),r};var $=(e=>(e.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",e.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",e.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",e.NOT_FOUND_ERROR="NOT_FOUND_ERROR",e.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",e.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",e))($||{});const te=(e=new Error)=>{var o;const{cause:n,socket:t}=e;let r="CONNECT_SERVER_FAILED";switch(n){case"Forbidden":{r="WRONG_USER_OR_PASSWORD";break}case s.BAD_MEDIA_DESCRIPTION:{r="BAD_MEDIA_ERROR";break}case s.NOT_FOUND:{r="NOT_FOUND_ERROR";break}default:t&&((o=t==null?void 0:t._ws)==null?void 0:o.readyState)===3?r="WS_CONNECTION_FAILED":k(e)&&(r="CONNECT_SERVER_FAILED_BY_LINK")}return r},re=(e=new Error)=>{const{code:n,cause:t,message:r}=e,o=k(e),c={};return r&&(c.message=r),o&&(c.link=o),n&&(c.code=n),t&&(c.cause=t),c},se=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:k,getTypeFromError:te,getValuesFromError:re},Symbol.toStringTag,{value:"Module"})),oe=({sessionId:e,remoteAddress:n,isMutedAudio:t,isMutedVideo:r,isRegistered:o,isPresentationCall:c})=>{const a=[],u=t?"0":"1",d=r?"0":"1";return a.push(`X-Vinteo-Mic-State: ${u}`,`X-Vinteo-MainCam-State: ${d}`),o||a.push("X-Vinteo-Purgatory-Call: yes"),e&&a.push(`X-Vinteo-Session: ${e}`),c&&a.push("X-Vinteo-Presentation-Call: yes"),n&&a.push(`X-Vinteo-Remote: ${n}`),a},ce=({appName:e,appVersion:n,browserName:t,browserVersion:r})=>{const o=`${e} ${n}`;return`ChromeNew - ${t?`${t} ${r}, ${o}`:o}`},ae=({isUnifiedSdpSemantic:e,appVersion:n,browserName:t,browserVersion:r,appName:o})=>e?ce({appVersion:n,browserName:t,browserVersion:r,appName:o}):"Chrome",ie=e=>async()=>{if(e.isCallActive)return s.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},ue=e=>t=>(s.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",t)),le=e=>t=>(s.logger("onUseLicense"),e.onSession("useLicense",t)),ge=e=>async({isEnabledCam:t,isEnabledMic:r})=>{if(e.isCallActive)return s.logger("sendMediaState"),e.sendMediaState({cam:t,mic:r})},Se=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(t=>{s.logger("sendRefusalToTurnOnCam: error",t)})},de=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(t=>{s.logger("sendRefusalToTurnOnMic: error",t)})},me=1e6,fe=({maxBitrate:e=me,sipConnector:n})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("startPresentation"),n.startPresentation(r,{isP2P:o,maxBitrate:e})),Ee=({sipConnector:e})=>async({isP2P:t=!1}={})=>(s.logger("stopShareSipConnector"),e.stopPresentation({isP2P:t}).catch(r=>{s.logger(r)})),Ce=1e6,Re=({sipConnector:e,maxBitrate:n=Ce})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("updatePresentation"),e.updatePresentation(r,{isP2P:o,maxBitrate:n})),he="ERROR_NOT_RUNNING",Me=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=he,n.name="Not running",n},ye=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(Me(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),Te=e=>n=>[...n].map(r=>async()=>e(r)),_e=async({accumulatedKeys:e,sendKey:n,canRunTask:t})=>{const o=Te(n)(e);return ye(o,t)},be=e=>t=>(s.logger("onStartMainCam"),e.onSession("admin-start-main-cam",t)),ve=e=>t=>(s.logger("onStartMic"),e.onSession("admin-start-mic",t)),Ne=e=>t=>(s.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",t)),Oe=e=>t=>(s.logger("onStopMic"),e.onSession("admin-stop-mic",t)),Ae=({sipConnector:e})=>{const n=(M,R)=>({isSyncForced:T=!1})=>{if(T){M();return}R()},t=be(e),r=Ne(e),o=ve(e),c=Oe(e);let a=()=>{},u=()=>{},d=()=>{},C=()=>{};const f=({onStartMainCamForced:M,onStartMainCamNotForced:R,onStopMainCamForced:T,onStopMainCamNotForced:O,onStartMicForced:A,onStartMicNotForced:_,onStopMicForced:i,onStopMicNotForced:S})=>{const g=n(M,R);a=t(g);const h=n(T,O);u=r(h);const b=n(A,_);d=o(b);const N=n(i,S);C=c(N)},m=()=>{a(),u(),d(),C()};return{start:M=>{f(M)},stop:()=>{m()}}},Pe=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:x,createSyncMediaState:Ae,error:se,getExtraHeaders:oe,getUserAgent:ae,hasPurgatory:P,resolveAnswerIncomingCall:Q,resolveAskPermissionToEnableCam:ie,resolveCallToServer:Z,resolveConnectToServer:ee,resolveDisconnectFromServer:ne,resolveGetRemoteStreams:B,resolveOnMustStopPresentation:ue,resolveOnUseLicense:le,resolveSendMediaState:ge,resolveSendRefusalToTurnOnCam:Se,resolveSendRefusalToTurnOnMic:de,resolveStartPresentation:fe,resolveStopShareSipConnector:Ee,resolveUpdatePresentation:Re,resolveUpdateRemoteStreams:D,sendDTMFAccumulated:_e},Symbol.toStringTag,{value:"Module"})),pe=e=>[...e.keys()].map(n=>e.get(n)),Ie=(e,n)=>pe(e).find(t=>t.type===n),j=async e=>e.getStats().then(n=>{const t=Ie(n,"codec");return t==null?void 0:t.mimeType}),we=e=>e.find(n=>{var t;return((t=n==null?void 0:n.track)==null?void 0:t.kind)==="video"}),G=(e,n)=>e!==void 0&&n!==void 0&&e.toLowerCase().includes(n.toLowerCase()),Be="ERROR_NOT_RUNNING",De=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=Be,n.name="Not running",n},ke=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(De(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),Fe=new Error("Stack is empty"),I=e=>e[e.length-1],Ue=new Error("Promise is not actual"),Le=new Error("stackPromises only works with functions that returns a Promise"),xe=({noRejectIsNotActual:e=!1,noRunIsNotActual:n=!1}={})=>{const t=[],r=[],o=({task:i,index:S})=>{r.push({task:i,index:S})},c=(i,{task:S,index:g})=>{const h=r.find(({task:b,index:N})=>S===b&&g===N);if(!h)throw new Error("Task not found");if(h.promise)throw new Error("Task is already running");h.promise=i},a=({task:i,index:S})=>{const g=r.find(({task:h,index:b})=>i===h&&S===b);if(g)return g.promise},u=({task:i})=>{const S=I(r);return(S==null?void 0:S.task)===i},d=({task:i,index:S})=>(o({task:i,index:S}),async()=>{let g=a({task:i,index:S});const h=u({task:i});return!g&&n&&!h?Promise.resolve():(g||(g=i({isActual:h}),c(g,{task:i,index:S})),g)}),C=({resolve:i,reject:S})=>({results:g,isSuccessful:h})=>{const b=g.length,N=t.length;if(b===N){const l=I(g);if(h){i(l);return}S(l);return}if(e){const l=I(g);i(l);return}S(Ue)};let f=!1;const m=()=>{f=!0},y=()=>{f=!1},E=()=>f,M=async()=>(m(),ke(t,E)),R=async()=>{if(t.length===0)throw Fe;return new Promise((i,S)=>{const g=C({resolve:i,reject:S});M().then(g).catch(g)})},T=i=>{if(typeof i!="function")throw Le;const S=t.length;return t.push(d({task:i,index:S})),R},O=async i=>(T(i),R()),A=()=>{t.length=0,r.length=0},_=()=>{y(),A()};return R.add=T,R.run=O,R.stop=_,R},Ve=1e6,v=e=>e*Ve,X=v(.06),$e=v(4),je=e=>e<=64?X:e<=128?v(.12):e<=256?v(.25):e<=384?v(.32):e<=426?v(.38):e<=640?v(.5):e<=848?v(.7):e<=1280?v(1):e<=1920?v(2):$e,Ge="av1",Xe=e=>G(e,Ge),Ke=.6,K=(e,n)=>Xe(n)?e*Ke:e,We=e=>K(X,e),W=(e,n)=>{const t=je(e);return K(t,n)},H=xe(),He=async()=>H().catch(e=>{s.logger("videoSendingBalancer: error",e)}),qe=async e=>(H.add(e),He()),F=async({sender:e,scaleResolutionDownBy:n,maxBitrate:t,onSetParameters:r})=>qe(async()=>s.setEncodingsToSender(e,{scaleResolutionDownBy:n,maxBitrate:t},r)),Ye=async({sender:e,codec:n},t)=>{const o=We(n);return F({sender:e,maxBitrate:o,onSetParameters:t,scaleResolutionDownBy:200})},w=async({sender:e,track:n,codec:t},r)=>{const a=n.getSettings().width,u=W(a,t);return F({sender:e,maxBitrate:u,onSetParameters:r,scaleResolutionDownBy:1})},ze=async({sender:e,track:n,resolution:t,codec:r},o)=>{const c=n.getSettings(),a=c.width,u=c.height,[d,C]=t.split("x"),f=a/Number(d),m=u/Number(C),E=Math.max(f,m,1),M=W(Number(d),r);return F({sender:e,maxBitrate:M,onSetParameters:o,scaleResolutionDownBy:E})},Je=async({mainCam:e,resolutionMainCam:n,sender:t,track:r,codec:o},c)=>{switch(e){case s.EEventsMainCAM.PAUSE_MAIN_CAM:return Ye({sender:t,codec:o},c);case s.EEventsMainCAM.RESUME_MAIN_CAM:return w({sender:t,track:r,codec:o},c);case s.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return n!==void 0?ze({sender:t,track:r,codec:o,resolution:n},c):w({sender:t,track:r,codec:o},c);default:return w({sender:t,track:r,codec:o},c)}},U={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},L=async({mainCam:e,resolutionMainCam:n,connection:t,onSetParameters:r,ignoreForCodec:o})=>{const c=t.getSenders(),a=we(c);if(!(a!=null&&a.track))return U;const u=await j(a);return G(u,o)?U:Je({mainCam:e,resolutionMainCam:n,sender:a,codec:u,track:a.track},r)},Qe=(e,{ignoreForCodec:n,onSetParameters:t}={})=>{const r=async()=>{const{connection:d}=e;if(!d)throw new Error("connection is not exist");return L({connection:d,onSetParameters:t,ignoreForCodec:n})};let o=r;const c=async d=>(o=async()=>{const{mainCam:C,resolutionMainCam:f}=d,{connection:m}=e;if(!m)throw new Error("connection is not exist");return L({mainCam:C,resolutionMainCam:f,connection:m,onSetParameters:t,ignoreForCodec:n})},o());return{subscribe:()=>{e.onSession("main-cam-control",c)},unsubscribe:()=>{e.offSession("main-cam-control",c)},balanceByTrack:r,resetMainCamControl(){o=r},async reBalance(){return o()}}};exports.EEventsMainCAM=s.EEventsMainCAM;exports.EEventsMic=s.EEventsMic;exports.EEventsSyncMediaState=s.EEventsSyncMediaState;exports.EUseLicense=s.EUseLicense;exports.causes=s.causes;exports.constants=s.constants;exports.default=s.SipConnector;exports.disableDebug=s.disableDebug;exports.enableDebug=s.enableDebug;exports.eventNames=s.eventNames;exports.hasCanceledCallError=s.hasCanceledCallError;exports.debug=z;exports.getCodecFromSender=j;exports.resolveVideoSendingBalancer=Qe;exports.tools=Pe;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("./SipConnector-BrUmibLH.cjs"),H=require("ts-debounce"),Y=require("@krivega/cancelable-promise"),z=require("debug"),x="purgatory",p=e=>e===x,B=e=>()=>(s.logger("getRemoteStreams"),e.getRemoteStreams()),J=({kind:e,readyState:n})=>e==="video"&&n==="live",V=e=>({track:n})=>{J(n)&&e()},D=({getRemoteStreams:e,setRemoteStreams:n})=>H.debounce(()=>{const t=e();s.logger("remoteStreams",t),t&&n(t)},200),Q=e=>async t=>{const{mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,setRemoteStreams:u,onBeforeProgressCall:d,onSuccessProgressCall:C,onEnterPurgatory:f,onEnterConference:m,onFailProgressCall:T,onFinishProgressCall:E,onEndedCall:h}=t,R=D({setRemoteStreams:u,getRemoteStreams:B(e)}),y=V(R);s.logger("answerIncomingCall",t);const N=async()=>e.answerToIncomingCall({mediaStream:r,extraHeaders:o,iceServers:c,degradationPreference:a,ontrack:y}),A=()=>{const{remoteCallerData:l}=e;return l.incomingNumber};let _=!1,i;const g=(s.logger("subscribeEnterConference: onEnterConference",m),f??m?e.onSession("enterRoom",l=>{s.logger("enterRoom",{_room:l,isSuccessProgressCall:_}),i=l,p(i)?f&&f():m&&m({isSuccessProgressCall:_})}):()=>{}),M=l=>(s.logger("onSuccess"),_=!0,R(),C&&C({isPurgatory:p(i)}),e.onceRaceSession(["ended","failed"],()=>{g(),h&&h()}),l),b=l=>{throw s.logger("onFail"),T&&T(),g(),l},O=()=>{s.logger("onFinish"),E&&E()};if(s.logger("onBeforeProgressCall"),d){const l=A();d(l)}return N().then(M).catch(l=>b(l)).finally(O)},Z=e=>async t=>{const{conference:r,mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,setRemoteStreams:d,onBeforeProgressCall:C,onSuccessProgressCall:f,onEnterPurgatory:m,onEnterConference:T,onFailProgressCall:E,onFinishProgressCall:h,onEndedCall:R}=t,y=D({setRemoteStreams:d,getRemoteStreams:B(e)}),N=V(y);s.logger("callToServer",t);const A=async()=>(s.logger("startCall"),e.call({mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,number:r,ontrack:N}));let _=!1,i;const g=(s.logger("subscribeEnterConference: onEnterConference",T),m??T?e.onSession("enterRoom",l=>{s.logger("enterRoom",{_room:l,isSuccessProgressCall:_}),i=l,p(i)?m&&m():T&&T({isSuccessProgressCall:_})}):()=>{}),M=l=>(s.logger("onSuccess"),_=!0,y(),f&&f({isPurgatory:p(i)}),e.onceRaceSession(["ended","failed"],()=>{g(),R&&R()}),l),b=l=>{throw s.logger("onFail"),E&&E(),g(),l},O=()=>{s.logger("onFinish"),h&&h()};return s.logger("onBeforeProgressCall"),C&&C(r),A().then(M).catch(l=>b(l)).finally(O)},P=e=>{if(!Y.isCanceledError(e))throw e;return{isSuccessful:!1}},ee=e=>async t=>{const{userAgent:r,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,name:d,password:C,isRegisteredUser:f,sdpSemantics:m,isDisconnectOnFail:T}=t;return s.logger("connectToServer",t),e.connect({userAgent:r,sdpSemantics:m,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,password:C,user:d,register:f}).then(E=>(s.logger("connectToServer then"),{ua:E,isSuccessful:!0})).catch(async E=>(s.logger("connectToServer catch: error",E),T===!0?e.disconnect().then(()=>P(E)).catch(()=>P(E)):P(E)))},ne=e=>async()=>(s.logger("disconnectFromServer"),e.disconnect().then(()=>(s.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(n=>(s.logger("disconnectFromServer: catch",n),{isSuccessful:!1}))),k=e=>{const{url:n,cause:t}=e;let r=n;return(t===s.BAD_MEDIA_DESCRIPTION||t===s.NOT_FOUND)&&(r=`${e.message.to.uri.user}@${e.message.to.uri.host}`),r};var $=(e=>(e.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",e.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",e.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",e.NOT_FOUND_ERROR="NOT_FOUND_ERROR",e.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",e.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",e))($||{});const te=(e=new Error)=>{var o;const{cause:n,socket:t}=e;let r="CONNECT_SERVER_FAILED";switch(n){case"Forbidden":{r="WRONG_USER_OR_PASSWORD";break}case s.BAD_MEDIA_DESCRIPTION:{r="BAD_MEDIA_ERROR";break}case s.NOT_FOUND:{r="NOT_FOUND_ERROR";break}default:t&&((o=t==null?void 0:t._ws)==null?void 0:o.readyState)===3?r="WS_CONNECTION_FAILED":k(e)&&(r="CONNECT_SERVER_FAILED_BY_LINK")}return r},re=(e=new Error)=>{const{code:n,cause:t,message:r}=e,o=k(e),c={};return r&&(c.message=r),o&&(c.link=o),n&&(c.code=n),t&&(c.cause=t),c},se=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:k,getTypeFromError:te,getValuesFromError:re},Symbol.toStringTag,{value:"Module"})),oe=({sessionId:e,remoteAddress:n,isMutedAudio:t,isMutedVideo:r,isRegistered:o,isPresentationCall:c})=>{const a=[],u=t?"0":"1",d=r?"0":"1";return a.push(`X-Vinteo-Mic-State: ${u}`,`X-Vinteo-MainCam-State: ${d}`),o||a.push("X-Vinteo-Purgatory-Call: yes"),e&&a.push(`X-Vinteo-Session: ${e}`),c&&a.push("X-Vinteo-Presentation-Call: yes"),n&&a.push(`X-Vinteo-Remote: ${n}`),a},ce=({appName:e,appVersion:n,browserName:t,browserVersion:r})=>{const o=`${e} ${n}`;return`ChromeNew - ${t?`${t} ${r}, ${o}`:o}`},ae=({isUnifiedSdpSemantic:e,appVersion:n,browserName:t,browserVersion:r,appName:o})=>e?ce({appVersion:n,browserName:t,browserVersion:r,appName:o}):"Chrome",ie=e=>async()=>{if(e.isCallActive)return s.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},ue=e=>t=>(s.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",t)),le=e=>t=>(s.logger("onMoveToSpectators"),e.onSession("participant:move-request-to-spectators",t)),ge=e=>t=>(s.logger("onUseLicense"),e.onSession("useLicense",t)),Se=e=>async({isEnabledCam:t,isEnabledMic:r})=>{if(e.isCallActive)return s.logger("sendMediaState"),e.sendMediaState({cam:t,mic:r})},de=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(t=>{s.logger("sendRefusalToTurnOnCam: error",t)})},me=e=>async()=>{if(e.isCallActive)return s.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(t=>{s.logger("sendRefusalToTurnOnMic: error",t)})},fe=1e6,Ee=({maxBitrate:e=fe,sipConnector:n})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("startPresentation"),n.startPresentation(r,{isP2P:o,maxBitrate:e})),Ce=({sipConnector:e})=>async({isP2P:t=!1}={})=>(s.logger("stopShareSipConnector"),e.stopPresentation({isP2P:t}).catch(r=>{s.logger(r)})),Re=1e6,Me=({sipConnector:e,maxBitrate:n=Re})=>async({mediaStream:r,isP2P:o=!1})=>(s.logger("updatePresentation"),e.updatePresentation(r,{isP2P:o,maxBitrate:n})),he="ERROR_NOT_RUNNING",Te=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=he,n.name="Not running",n},ye=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(Te(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),_e=e=>n=>[...n].map(r=>async()=>e(r)),be=async({accumulatedKeys:e,sendKey:n,canRunTask:t})=>{const o=_e(n)(e);return ye(o,t)},ve=e=>t=>(s.logger("onStartMainCam"),e.onSession("admin-start-main-cam",t)),Oe=e=>t=>(s.logger("onStartMic"),e.onSession("admin-start-mic",t)),Ne=e=>t=>(s.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",t)),Ae=e=>t=>(s.logger("onStopMic"),e.onSession("admin-stop-mic",t)),pe=({sipConnector:e})=>{const n=(h,R)=>({isSyncForced:y=!1})=>{if(y){h();return}R()},t=ve(e),r=Ne(e),o=Oe(e),c=Ae(e);let a=()=>{},u=()=>{},d=()=>{},C=()=>{};const f=({onStartMainCamForced:h,onStartMainCamNotForced:R,onStopMainCamForced:y,onStopMainCamNotForced:N,onStartMicForced:A,onStartMicNotForced:_,onStopMicForced:i,onStopMicNotForced:S})=>{const g=n(h,R);a=t(g);const M=n(y,N);u=r(M);const b=n(A,_);d=o(b);const O=n(i,S);C=c(O)},m=()=>{a(),u(),d(),C()};return{start:h=>{f(h)},stop:()=>{m()}}},Pe=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:x,createSyncMediaState:pe,error:se,getExtraHeaders:oe,getUserAgent:ae,hasPurgatory:p,resolveAnswerIncomingCall:Q,resolveAskPermissionToEnableCam:ie,resolveCallToServer:Z,resolveConnectToServer:ee,resolveDisconnectFromServer:ne,resolveGetRemoteStreams:B,resolveOnMoveToSpectators:le,resolveOnMustStopPresentation:ue,resolveOnUseLicense:ge,resolveSendMediaState:Se,resolveSendRefusalToTurnOnCam:de,resolveSendRefusalToTurnOnMic:me,resolveStartPresentation:Ee,resolveStopShareSipConnector:Ce,resolveUpdatePresentation:Me,resolveUpdateRemoteStreams:D,sendDTMFAccumulated:be},Symbol.toStringTag,{value:"Module"})),Ie=e=>[...e.keys()].map(n=>e.get(n)),we=(e,n)=>Ie(e).find(t=>t.type===n),j=async e=>e.getStats().then(n=>{const t=we(n,"codec");return t==null?void 0:t.mimeType}),Be=e=>e.find(n=>{var t;return((t=n==null?void 0:n.track)==null?void 0:t.kind)==="video"}),G=(e,n)=>e!==void 0&&n!==void 0&&e.toLowerCase().includes(n.toLowerCase()),De="ERROR_NOT_RUNNING",ke=e=>{const n=new Error("Promise was not running");return n.basePromise=e,n.id=De,n.name="Not running",n},Fe=async(e,n)=>e.reduce(async(t,r)=>t.then(async({success:o,errors:c,results:a})=>(!n||n(r)?r():Promise.reject(ke(r))).then(u=>({errors:c,success:[...o,u],results:[...a,u],isSuccessful:!0,isError:!1})).catch(u=>({success:o,errors:[...c,u],results:[...a,u],isSuccessful:!1,isError:!0}))),Promise.resolve({success:[],errors:[],results:[],isSuccessful:!1,isError:!1})),Ue=new Error("Stack is empty"),I=e=>e[e.length-1],Le=new Error("Promise is not actual"),xe=new Error("stackPromises only works with functions that returns a Promise"),Ve=({noRejectIsNotActual:e=!1,noRunIsNotActual:n=!1}={})=>{const t=[],r=[],o=({task:i,index:S})=>{r.push({task:i,index:S})},c=(i,{task:S,index:g})=>{const M=r.find(({task:b,index:O})=>S===b&&g===O);if(!M)throw new Error("Task not found");if(M.promise)throw new Error("Task is already running");M.promise=i},a=({task:i,index:S})=>{const g=r.find(({task:M,index:b})=>i===M&&S===b);if(g)return g.promise},u=({task:i})=>{const S=I(r);return(S==null?void 0:S.task)===i},d=({task:i,index:S})=>(o({task:i,index:S}),async()=>{let g=a({task:i,index:S});const M=u({task:i});return!g&&n&&!M?Promise.resolve():(g||(g=i({isActual:M}),c(g,{task:i,index:S})),g)}),C=({resolve:i,reject:S})=>({results:g,isSuccessful:M})=>{const b=g.length,O=t.length;if(b===O){const l=I(g);if(M){i(l);return}S(l);return}if(e){const l=I(g);i(l);return}S(Le)};let f=!1;const m=()=>{f=!0},T=()=>{f=!1},E=()=>f,h=async()=>(m(),Fe(t,E)),R=async()=>{if(t.length===0)throw Ue;return new Promise((i,S)=>{const g=C({resolve:i,reject:S});h().then(g).catch(g)})},y=i=>{if(typeof i!="function")throw xe;const S=t.length;return t.push(d({task:i,index:S})),R},N=async i=>(y(i),R()),A=()=>{t.length=0,r.length=0},_=()=>{T(),A()};return R.add=y,R.run=N,R.stop=_,R},$e=1e6,v=e=>e*$e,X=v(.06),je=v(4),Ge=e=>e<=64?X:e<=128?v(.12):e<=256?v(.25):e<=384?v(.32):e<=426?v(.38):e<=640?v(.5):e<=848?v(.7):e<=1280?v(1):e<=1920?v(2):je,Xe="av1",Ke=e=>G(e,Xe),We=.6,K=(e,n)=>Ke(n)?e*We:e,qe=e=>K(X,e),W=(e,n)=>{const t=Ge(e);return K(t,n)},q=Ve(),He=async()=>q().catch(e=>{s.logger("videoSendingBalancer: error",e)}),Ye=async e=>(q.add(e),He()),F=async({sender:e,scaleResolutionDownBy:n,maxBitrate:t,onSetParameters:r})=>Ye(async()=>s.setEncodingsToSender(e,{scaleResolutionDownBy:n,maxBitrate:t},r)),ze=async({sender:e,codec:n},t)=>{const o=qe(n);return F({sender:e,maxBitrate:o,onSetParameters:t,scaleResolutionDownBy:200})},w=async({sender:e,track:n,codec:t},r)=>{const a=n.getSettings().width,u=W(a,t);return F({sender:e,maxBitrate:u,onSetParameters:r,scaleResolutionDownBy:1})},Je=async({sender:e,track:n,resolution:t,codec:r},o)=>{const c=n.getSettings(),a=c.width,u=c.height,[d,C]=t.split("x"),f=a/Number(d),m=u/Number(C),E=Math.max(f,m,1),h=W(Number(d),r);return F({sender:e,maxBitrate:h,onSetParameters:o,scaleResolutionDownBy:E})},Qe=async({mainCam:e,resolutionMainCam:n,sender:t,track:r,codec:o},c)=>{switch(e){case s.EEventsMainCAM.PAUSE_MAIN_CAM:return ze({sender:t,codec:o},c);case s.EEventsMainCAM.RESUME_MAIN_CAM:return w({sender:t,track:r,codec:o},c);case s.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return n!==void 0?Je({sender:t,track:r,codec:o,resolution:n},c):w({sender:t,track:r,codec:o},c);default:return w({sender:t,track:r,codec:o},c)}},U={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},L=async({mainCam:e,resolutionMainCam:n,connection:t,onSetParameters:r,ignoreForCodec:o})=>{const c=t.getSenders(),a=Be(c);if(!(a!=null&&a.track))return U;const u=await j(a);return G(u,o)?U:Qe({mainCam:e,resolutionMainCam:n,sender:a,codec:u,track:a.track},r)},Ze=(e,{ignoreForCodec:n,onSetParameters:t}={})=>{const r=async()=>{const{connection:d}=e;if(!d)throw new Error("connection is not exist");return L({connection:d,onSetParameters:t,ignoreForCodec:n})};let o=r;const c=async d=>(o=async()=>{const{mainCam:C,resolutionMainCam:f}=d,{connection:m}=e;if(!m)throw new Error("connection is not exist");return L({mainCam:C,resolutionMainCam:f,connection:m,onSetParameters:t,ignoreForCodec:n})},o());return{subscribe:()=>{e.onSession("main-cam-control",c)},unsubscribe:()=>{e.offSession("main-cam-control",c)},balanceByTrack:r,resetMainCamControl(){o=r},async reBalance(){return o()}}};exports.EEventsMainCAM=s.EEventsMainCAM;exports.EEventsMic=s.EEventsMic;exports.EEventsSyncMediaState=s.EEventsSyncMediaState;exports.EUseLicense=s.EUseLicense;exports.causes=s.causes;exports.constants=s.constants;exports.default=s.SipConnector;exports.disableDebug=s.disableDebug;exports.enableDebug=s.enableDebug;exports.eventNames=s.eventNames;exports.hasCanceledCallError=s.hasCanceledCallError;exports.debug=z;exports.getCodecFromSender=j;exports.resolveVideoSendingBalancer=Ze;exports.tools=Pe;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import SipConnector from './SipConnector';
1
+ import { default as SipConnector } from './SipConnector';
2
+
2
3
  export { hasCanceledCallError } from './SipConnector';
3
4
  export * as causes from './causes';
4
5
  export * as constants from './constants';