sip-connector 22.0.0 → 23.1.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 (32) hide show
  1. package/dist/{@SipConnector-OAqRbRF0.js → @SipConnector-B599bzsb.js} +914 -671
  2. package/dist/@SipConnector-Cf-5oSvs.cjs +1 -0
  3. package/dist/ApiManager/@ApiManager.d.ts +8 -10
  4. package/dist/ApiManager/constants.d.ts +80 -44
  5. package/dist/ApiManager/events.d.ts +7 -5
  6. package/dist/ApiManager/getHeader.d.ts +3 -0
  7. package/dist/ApiManager/index.d.ts +3 -2
  8. package/dist/CallManager/@CallManager.d.ts +9 -1
  9. package/dist/CallManager/RecvSession.d.ts +1 -0
  10. package/dist/CallManager/StreamsChangeTracker.d.ts +35 -0
  11. package/dist/CallManager/StreamsManagerProvider.d.ts +12 -3
  12. package/dist/ConnectionManager/ConnectionStateMachine.d.ts +0 -2
  13. package/dist/ContentedStreamManager/@ContentedStreamManager.d.ts +19 -0
  14. package/dist/ContentedStreamManager/ContentedStreamStateMachine.d.ts +52 -0
  15. package/dist/ContentedStreamManager/events.d.ts +15 -0
  16. package/dist/ContentedStreamManager/index.d.ts +4 -0
  17. package/dist/ContentedStreamManager/types.d.ts +7 -0
  18. package/dist/SipConnector/@SipConnector.d.ts +2 -5
  19. package/dist/SipConnectorFacade/@SipConnectorFacade.d.ts +3 -3
  20. package/dist/StatsPeerConnection/@StatsPeerConnection.d.ts +2 -1
  21. package/dist/VideoSendingBalancer/types.d.ts +2 -2
  22. package/dist/__fixtures__/Request.mock.d.ts +1 -1
  23. package/dist/__fixtures__/UA.mock.d.ts +13 -3
  24. package/dist/__fixtures__/createManagers.d.ts +12 -0
  25. package/dist/doMock.cjs +1 -1
  26. package/dist/doMock.js +162 -134
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +22 -22
  30. package/dist/tools/BaseStateMachine.d.ts +2 -0
  31. package/package.json +3 -3
  32. package/dist/@SipConnector-mL9nMhkX.cjs +0 -1
@@ -0,0 +1,35 @@
1
+ import { TRemoteStreams } from './types';
2
+ /**
3
+ * Сравнивает два объекта TRemoteStreams на равенство по ID потоков
4
+ * @param streams1 - Первый объект streams для сравнения
5
+ * @param streams2 - Второй объект streams для сравнения
6
+ * @returns true, если streams равны (имеют одинаковые ID mainStream и contentedStream)
7
+ */
8
+ export declare const hasStreamsEqual: (streams1?: TRemoteStreams, streams2?: TRemoteStreams) => boolean;
9
+ /**
10
+ * Класс для отслеживания изменений удаленных streams
11
+ * Хранит последнее состояние streams и определяет, изменились ли они
12
+ */
13
+ export declare class StreamsChangeTracker {
14
+ private lastEmittedStreams?;
15
+ /**
16
+ * Проверяет, изменились ли streams с последнего сохраненного состояния
17
+ * @param streams - Текущие streams для проверки
18
+ * @returns true, если streams изменились
19
+ */
20
+ hasChanged(streams: TRemoteStreams): boolean;
21
+ /**
22
+ * Сохраняет текущие streams как последнее эмитнутое состояние
23
+ * @param streams - Streams для сохранения
24
+ */
25
+ updateLastEmittedStreams(streams: TRemoteStreams): void;
26
+ /**
27
+ * Получает последние эмитнутые streams
28
+ * @returns Последние сохраненные streams или undefined
29
+ */
30
+ getLastEmittedStreams(): TRemoteStreams | undefined;
31
+ /**
32
+ * Сбрасывает состояние трекера
33
+ */
34
+ reset(): void;
35
+ }
@@ -1,10 +1,19 @@
1
+ import { TContentedStreamStateInfo } from '../ContentedStreamManager';
1
2
  import { RemoteStreamsManager } from './RemoteStreamsManager';
2
3
  import { TStreamsManagerTools } from './types';
3
4
  export declare class StreamsManagerProvider {
4
5
  private readonly mainRemoteStreamsManager;
5
6
  private readonly recvRemoteStreamsManager;
6
7
  constructor(mainRemoteStreamsManager: RemoteStreamsManager, recvRemoteStreamsManager: RemoteStreamsManager);
7
- getActiveStreamsManagerTools(isSpectator: boolean): TStreamsManagerTools;
8
- getMainRemoteStreamsManagerTools(): TStreamsManagerTools;
9
- getRecvRemoteStreamsManagerTools(): TStreamsManagerTools;
8
+ getActiveStreamsManagerTools({ isSpectator, stateInfo, }: {
9
+ isSpectator: boolean;
10
+ stateInfo: TContentedStreamStateInfo;
11
+ }): TStreamsManagerTools;
12
+ getMainRemoteStreamsManagerTools({ stateInfo, }: {
13
+ stateInfo: TContentedStreamStateInfo;
14
+ }): TStreamsManagerTools;
15
+ getRecvRemoteStreamsManagerTools({ stateInfo, }: {
16
+ stateInfo: TContentedStreamStateInfo;
17
+ }): TStreamsManagerTools;
18
+ private getRecvRemoteContentedStream;
10
19
  }
@@ -71,7 +71,6 @@ declare const connectionMachine: import('xstate').StateMachine<IConnectionMachin
71
71
  export type TConnectionSnapshot = SnapshotFrom<typeof connectionMachine>;
72
72
  export type TConnectionActor = ActorRefFrom<typeof connectionMachine>;
73
73
  export default class ConnectionStateMachine extends BaseStateMachine<typeof connectionMachine, EState> {
74
- private readonly stateChangeListeners;
75
74
  private readonly events;
76
75
  private unsubscribeFromEvents?;
77
76
  constructor(events: TEvents);
@@ -92,7 +91,6 @@ export default class ConnectionStateMachine extends BaseStateMachine<typeof conn
92
91
  startInitUa(): void;
93
92
  reset(): void;
94
93
  destroy(): void;
95
- onStateChange(listener: (state: EState) => void): () => void;
96
94
  canTransition(event: TConnectionMachineEvent): boolean;
97
95
  getValidEvents(): TConnectionMachineEvent[];
98
96
  private hasState;
@@ -0,0 +1,19 @@
1
+ import { ContentedStreamStateMachine } from './ContentedStreamStateMachine';
2
+ import { ApiManager, EContentedStreamCodec } from '../ApiManager';
3
+ import { TEventMap, TEvents } from './events';
4
+ import { TContentedStreamStateInfo } from './types';
5
+ declare class ContentedStreamManager {
6
+ readonly events: TEvents;
7
+ readonly stateMachine: ContentedStreamStateMachine;
8
+ constructor();
9
+ get isAvailable(): boolean;
10
+ get codec(): EContentedStreamCodec | undefined;
11
+ getStateInfo(): TContentedStreamStateInfo;
12
+ reset(): void;
13
+ on<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): () => void;
14
+ once<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): () => void;
15
+ off<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): void;
16
+ subscribeToApiEvents(apiManager: ApiManager): void;
17
+ private proxyEvents;
18
+ }
19
+ export default ContentedStreamManager;
@@ -0,0 +1,52 @@
1
+ import { BaseStateMachine } from '../tools/BaseStateMachine';
2
+ import { ActorRefFrom, SnapshotFrom } from 'xstate';
3
+ import { TApiManagerEvents, EContentedStreamCodec } from '../ApiManager';
4
+ import { TContentedStreamStateInfo } from './types';
5
+ export declare enum EState {
6
+ NOT_AVAILABLE = "contented-stream:not-available",
7
+ AVAILABLE = "contented-stream:available"
8
+ }
9
+ type TContentedStreamEvent = {
10
+ type: 'CONTENTED_STREAM.AVAILABLE';
11
+ codec?: EContentedStreamCodec;
12
+ } | {
13
+ type: 'CONTENTED_STREAM.NOT_AVAILABLE';
14
+ } | {
15
+ type: 'CONTENTED_STREAM.RESET';
16
+ };
17
+ interface IContentedStreamContext {
18
+ codec?: EContentedStreamCodec;
19
+ }
20
+ declare const contentedStreamMachine: import('xstate').StateMachine<IContentedStreamContext, {
21
+ type: "CONTENTED_STREAM.AVAILABLE";
22
+ codec?: EContentedStreamCodec;
23
+ } | {
24
+ type: "CONTENTED_STREAM.NOT_AVAILABLE";
25
+ } | {
26
+ type: "CONTENTED_STREAM.RESET";
27
+ }, {}, never, {
28
+ type: "setCodec";
29
+ params: import('xstate').NonReducibleUnknown;
30
+ } | {
31
+ type: "clearCodec";
32
+ params: import('xstate').NonReducibleUnknown;
33
+ }, never, never, EState, string, import('xstate').NonReducibleUnknown, import('xstate').NonReducibleUnknown, import('xstate').EventObject, import('xstate').MetaObject, {
34
+ id: "contented-stream";
35
+ states: {
36
+ readonly "contented-stream:not-available": {};
37
+ readonly "contented-stream:available": {};
38
+ };
39
+ }>;
40
+ export type TContentedStreamSnapshot = SnapshotFrom<typeof contentedStreamMachine>;
41
+ export type TContentedStreamActor = ActorRefFrom<typeof contentedStreamMachine>;
42
+ export declare class ContentedStreamStateMachine extends BaseStateMachine<typeof contentedStreamMachine, EState> {
43
+ constructor();
44
+ get isAvailable(): boolean;
45
+ get isNotAvailable(): boolean;
46
+ get codec(): EContentedStreamCodec | undefined;
47
+ getStateInfo(): TContentedStreamStateInfo;
48
+ reset(): void;
49
+ send(event: TContentedStreamEvent): void;
50
+ subscribeToApiEvents(apiManager: TApiManagerEvents): void;
51
+ }
52
+ export {};
@@ -0,0 +1,15 @@
1
+ import { TypedEvents } from 'events-constructor';
2
+ import { EContentedStreamCodec } from '../ApiManager';
3
+ export declare enum EEvent {
4
+ AVAILABLE = "available",
5
+ NOT_AVAILABLE = "not-available"
6
+ }
7
+ export declare const EVENT_NAMES: readonly [EEvent.AVAILABLE, EEvent.NOT_AVAILABLE];
8
+ export type TEventMap = {
9
+ available: {
10
+ codec?: EContentedStreamCodec;
11
+ };
12
+ 'not-available': Record<string, never>;
13
+ };
14
+ export type TEvents = TypedEvents<TEventMap>;
15
+ export declare const createEvents: () => TypedEvents<TEventMap, readonly (keyof TEventMap)[]>;
@@ -0,0 +1,4 @@
1
+ export { default as ContentedStreamManager } from './@ContentedStreamManager';
2
+ export { ContentedStreamStateMachine, EState } from './ContentedStreamStateMachine';
3
+ export type { TContentedStreamActor, TContentedStreamSnapshot, } from './ContentedStreamStateMachine';
4
+ export type { TContentedStreamStateInfo } from './types';
@@ -0,0 +1,7 @@
1
+ import { EContentedStreamCodec } from '../ApiManager';
2
+ export type TContentedStreamStateInfo = {
3
+ isAvailable: true;
4
+ codec?: EContentedStreamCodec;
5
+ } | {
6
+ isAvailable: false;
7
+ };
@@ -4,6 +4,7 @@ import { CallManager, TGetUri } from '../CallManager';
4
4
  import { ConferenceStateManager } from '../ConferenceStateManager';
5
5
  import { ConnectionManager } from '../ConnectionManager';
6
6
  import { ConnectionQueueManager } from '../ConnectionQueueManager';
7
+ import { ContentedStreamManager } from '../ContentedStreamManager';
7
8
  import { IncomingCallManager } from '../IncomingCallManager';
8
9
  import { PresentationManager, TContentHint, TOnAddedTransceiver } from '../PresentationManager';
9
10
  import { SessionManager } from '../SessionManager';
@@ -18,6 +19,7 @@ declare class SipConnector {
18
19
  readonly connectionManager: ConnectionManager;
19
20
  readonly connectionQueueManager: ConnectionQueueManager;
20
21
  readonly conferenceStateManager: ConferenceStateManager;
22
+ readonly contentedStreamManager: ContentedStreamManager;
21
23
  readonly callManager: CallManager;
22
24
  readonly autoConnectorManager: AutoConnectorManager;
23
25
  readonly apiManager: ApiManager;
@@ -110,11 +112,6 @@ declare class SipConnector {
110
112
  sendRefusalToTurnOn(...args: Parameters<ApiManager['sendRefusalToTurnOn']>): Promise<void>;
111
113
  sendRefusalToTurnOnMic(...args: Parameters<ApiManager['sendRefusalToTurnOnMic']>): Promise<void>;
112
114
  sendRefusalToTurnOnCam(...args: Parameters<ApiManager['sendRefusalToTurnOnCam']>): Promise<void>;
113
- sendMustStopPresentationP2P(...args: Parameters<ApiManager['sendMustStopPresentationP2P']>): Promise<void>;
114
- sendStoppedPresentationP2P(...args: Parameters<ApiManager['sendStoppedPresentationP2P']>): Promise<void>;
115
- sendStoppedPresentation(...args: Parameters<ApiManager['sendStoppedPresentation']>): Promise<void>;
116
- askPermissionToStartPresentationP2P(...args: Parameters<ApiManager['askPermissionToStartPresentationP2P']>): Promise<void>;
117
- askPermissionToStartPresentation(...args: Parameters<ApiManager['askPermissionToStartPresentation']>): Promise<void>;
118
115
  askPermissionToEnableCam(...args: Parameters<ApiManager['askPermissionToEnableCam']>): Promise<void>;
119
116
  private subscribeDisconnectedFromOutOfCall;
120
117
  private subscribeConnectedWithConfigurationFromOutOfCall;
@@ -1,4 +1,4 @@
1
- import { EUseLicense } from '../ApiManager';
1
+ import { EContentUseLicense } from '../ApiManager';
2
2
  import { TOnAddedTransceiver, TRemoteStreams } from '../CallManager';
3
3
  import { TParametersConnection, TConnectionConfigurationWithUa } from '../ConnectionManager';
4
4
  import { TContentHint } from '../PresentationManager';
@@ -132,7 +132,7 @@ declare class SipConnectorFacade implements IProxyMethods {
132
132
  onAddedTransceiver?: TOnAddedTransceiver;
133
133
  callLimit?: number;
134
134
  }) => Promise<MediaStream | undefined>;
135
- stopShareSipConnector: ({ isP2P }?: {
135
+ stopPresentation: ({ isP2P }?: {
136
136
  isP2P?: boolean;
137
137
  }) => Promise<void | MediaStream | undefined>;
138
138
  sendRefusalToTurnOnMic: () => Promise<void>;
@@ -163,7 +163,7 @@ declare class SipConnectorFacade implements IProxyMethods {
163
163
  track: MediaStreamTrack;
164
164
  }) => void;
165
165
  getRemoteStreams: () => TRemoteStreams;
166
- onUseLicense: (handler: (license: EUseLicense) => void) => (() => void);
166
+ onUseLicense: (handler: (license: EContentUseLicense) => void) => (() => void);
167
167
  onMustStopPresentation: (handler: () => void) => (() => void);
168
168
  onMoveToSpectators: (handler: () => void) => (() => void);
169
169
  onMoveToParticipants: (handler: () => void) => (() => void);
@@ -5,7 +5,7 @@ declare class StatsPeerConnection {
5
5
  private readonly requesterAllStatistics;
6
6
  constructor();
7
7
  get requested(): boolean;
8
- start(peerConnection: RTCPeerConnection, { interval, onError, }?: {
8
+ start(getPeerConnection: () => RTCPeerConnection | undefined, { interval, onError, }?: {
9
9
  onError?: (error: unknown) => void;
10
10
  interval?: number;
11
11
  }): void;
@@ -16,5 +16,6 @@ declare class StatsPeerConnection {
16
16
  wait<T extends keyof TEventMap>(eventName: T): Promise<TEventMap[T]>;
17
17
  off<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): void;
18
18
  private readonly collectStatistics;
19
+ private readonly requestAllStatistics;
19
20
  }
20
21
  export default StatsPeerConnection;
@@ -1,11 +1,11 @@
1
- import { EEventsMainCAM } from '../ApiManager';
1
+ import { EContentMainCAM } from '../ApiManager';
2
2
  import { TOnSetParameters, TResultSetParametersToSender } from '../tools';
3
3
  export interface IBalancerOptions {
4
4
  ignoreForCodec?: string;
5
5
  onSetParameters?: TOnSetParameters;
6
6
  }
7
7
  export interface IMainCamHeaders {
8
- mainCam?: EEventsMainCAM;
8
+ mainCam?: EContentMainCAM;
9
9
  resolutionMainCam?: string;
10
10
  }
11
11
  export interface IBalancingContext {
@@ -1,4 +1,4 @@
1
- import { IncomingRequest } from '@krivega/jssip/lib/SIPMessage';
1
+ import { IncomingRequest } from '@krivega/jssip';
2
2
  type TExtraHeaders = [string, string][];
3
3
  declare class Request extends IncomingRequest {
4
4
  private readonly headers;
@@ -1,13 +1,15 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { URI, DisconnectEvent, UA as IUA, IncomingRequest, UAConfiguration, UAConfigurationParams, UAContact, UAEventMap, UAStatus } from '@krivega/jssip';
1
3
  import { Events } from 'events-constructor';
2
4
  import { default as Registrator } from './Registrator.mock';
3
5
  import { default as RTCSessionMock } from './RTCSessionMock';
4
- import { DisconnectEvent, UA as IUA, IncomingRequest, UAConfiguration, UAConfigurationParams, UAEventMap } from '@krivega/jssip';
6
+ import { default as Message } from '@krivega/jssip/src/Message';
5
7
  import { TEventHandlers } from './BaseSession.mock';
6
8
  export declare const PASSWORD_CORRECT = "PASSWORD_CORRECT";
7
9
  export declare const PASSWORD_CORRECT_2 = "PASSWORD_CORRECT_2";
8
10
  export declare const NAME_INCORRECT = "NAME_INCORRECT";
9
11
  export declare const createWebsocketHandshakeTimeoutError: (sipServerUrl: string) => DisconnectEvent;
10
- declare class UA implements IUA {
12
+ declare class UA extends EventEmitter implements IUA {
11
13
  private static isAvailableTelephony;
12
14
  private static startError?;
13
15
  private static countStartError;
@@ -29,13 +31,18 @@ declare class UA implements IUA {
29
31
  stop: jest.Mock<void, [], any>;
30
32
  removeAllListeners: jest.Mock<this, [], any>;
31
33
  once: jest.Mock<this, [eventName: string, handler: () => void], any>;
34
+ configuration: UAConfiguration;
32
35
  private startedTimeout?;
33
36
  private stopedTimeout?;
34
37
  private session?;
35
38
  private isRegisteredInner?;
36
39
  private isConnectedInner?;
37
- private configuration;
38
40
  constructor(_configuration: UAConfigurationParams);
41
+ get C(): typeof UAStatus;
42
+ get status(): UAStatus;
43
+ get contact(): UAContact;
44
+ get transport(): unknown;
45
+ static C(): UAStatus;
39
46
  static setStartError(startError: DisconnectEvent, { count }?: {
40
47
  count?: number;
41
48
  }): void;
@@ -44,6 +51,9 @@ declare class UA implements IUA {
44
51
  static setNotAvailableTelephony(): void;
45
52
  static reset(): void;
46
53
  on<T extends keyof UAEventMap>(eventName: T, handler: UAEventMap[T]): this;
54
+ sendMessage(): Message;
55
+ normalizeTarget(): URI | undefined;
56
+ get<T extends keyof UAConfiguration>(): UAConfiguration[T];
47
57
  off<T extends keyof UAEventMap>(eventName: T, handler: UAEventMap[T]): this;
48
58
  trigger<T extends keyof UAEventMap>(eventName: T, data: Parameters<UAEventMap[T]>[0]): void;
49
59
  /**
@@ -0,0 +1,12 @@
1
+ import { ApiManager } from '../ApiManager';
2
+ import { CallManager } from '../CallManager';
3
+ import { ConferenceStateManager } from '../ConferenceStateManager';
4
+ import { ConnectionManager } from '../ConnectionManager';
5
+ import { ContentedStreamManager } from '../ContentedStreamManager';
6
+ export declare const createManagers: () => {
7
+ conferenceStateManager: ConferenceStateManager;
8
+ connectionManager: ConnectionManager;
9
+ contentedStreamManager: ContentedStreamManager;
10
+ callManager: CallManager;
11
+ apiManager: ApiManager;
12
+ };
package/dist/doMock.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("node:events"),U=require("@krivega/jssip/lib/NameAddrHeader"),j=require("@krivega/jssip/lib/URI"),q=require("@krivega/jssip/lib/SIPMessage"),a=require("@krivega/jssip"),_=require("webrtc-mock"),v=require("events-constructor"),D=require("./@SipConnector-mL9nMhkX.cjs");class N extends q.IncomingRequest{headers;constructor(e){super(),this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)??""}}const G="incomingCall",H="declinedIncomingCall",x="failedIncomingCall",z="terminatedIncomingCall",y="connecting",Y="connected",B="disconnected",K="newRTCSession",J="registered",$="unregistered",Q="registrationFailed",X="newMessage",Z="sipEvent",ee="availableSecondRemoteStream",te="notAvailableSecondRemoteStream",re="mustStopPresentation",ne="enterRoom",oe="useLicense",ie="peerconnection:confirmed",se="peerconnection:ontrack",ae="channels",ce="channels:notify",de="ended:fromserver",he="main-cam-control",Ee="admin:stop-main-cam",ue="admin:start-main-cam",me="admin:stop-mic",le="admin:start-mic",pe="admin:force-sync-media-state",ge="participant:added-to-list-moderators",_e="participant:removed-from-list-moderators",Te="participant:move-request-to-stream",Ie="participant:move-request-to-spectators",Se="participant:move-request-to-participants",Ne="participation:accepting-word-request",we="participation:cancelling-word-request",Ce="webcast:started",fe="webcast:stopped",Re="account:changed",Ae="account:deleted",Me="conference:participant-token-issued",Oe="ended",Pe="sending",ve="reinvite",De="replaces",ye="refer",Le="progress",Fe="accepted",We="confirmed",be="peerconnection",ke="failed",Ve="muted",Ue="unmuted",je="newDTMF",qe="newInfo",Ge="hold",He="unhold",xe="update",ze="sdp",Ye="icecandidate",Be="getusermediafailed",Ke="peerconnection:createofferfailed",Je="peerconnection:createanswerfailed",$e="peerconnection:setlocaldescriptionfailed",Qe="peerconnection:setremotedescriptionfailed",Xe="presentation:start",Ze="presentation:started",et="presentation:end",tt="presentation:ended",rt="presentation:failed",nt=[G,H,z,x,Ne,we,Te,ce,Me,Re,Ae,Ce,fe,ge,_e],L=[y,Y,B,K,J,$,Q,X,Z],ot=[ee,te,re,ne,oe,ie,se,ae,de,he,ue,Ee,me,le,pe,Ie,Se],T=[Oe,y,Pe,ve,De,ye,Le,Fe,We,be,ke,Ve,Ue,je,qe,Ge,He,xe,ze,Ye,Be,Ke,Je,$e,Qe,Xe,Ze,et,tt,rt];[...L,...nt];[...T,...ot];class it{originator;connection;events;remote_identity;mutedOptions={audio:!1,video:!1};constructor({originator:e="local",eventHandlers:t,remoteIdentity:r}){this.originator=e,this.events=new v.Events(T),this.initEvents(t),this.remote_identity=r}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,r){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){return this.events.off(e,t),this}removeAllListeners(e){return console.warn("Method not implemented. Event:",e),this}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){e&&Object.entries(e).forEach(([t,r])=>{this.on(t,r)})}on(e,t){return T.includes(e)&&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 this.trigger("presentation:start",e),this.trigger("presentation:started",e),e}async stopPresentation(e){return this.trigger("presentation:end",e),this.trigger("presentation:ended",e),e}isEstablished(){return!0}}class R{stats=new Map().set("codec",{mimeType:"video/h264"});dtmf=null;track=null;transport=null;transform=null;parameters={encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}};parametersGets;constructor({track:e}={}){this.track=e??null}async getStats(){return this.stats}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 A{currentDirection="sendrecv";direction="sendrecv";mid=null;receiver;sender;stopped=!1;constructor(e){this.sender=e}setCodecPreferences(e){}stop(){}}class st extends EventTarget{senders=[];receivers=[];canTrickleIceCandidates;connectionState;currentLocalDescription;currentRemoteDescription;iceConnectionState;iceGatheringState;idpErrorInfo;idpLoginUrl;localDescription;onconnectionstatechange;ondatachannel;onicecandidate;onicecandidateerror=null;oniceconnectionstatechange;onicegatheringstatechange;onnegotiationneeded;onsignalingstatechange;ontrack;peerIdentity=void 0;pendingLocalDescription;pendingRemoteDescription;remoteDescription;sctp=null;signalingState;close=jest.fn();setLocalDescription=jest.fn(async e=>{});setRemoteDescription=jest.fn(async e=>{});addTransceiver=jest.fn((e,t)=>({}));createOffer=jest.fn(async(e,t,r)=>({type:"offer",sdp:"offer-sdp"}));constructor(e,t){super(),this.receivers=t?.map(r=>({track:r}))??[]}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(e){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.")}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.")}getReceivers=()=>this.receivers;getSenders=()=>this.senders;addTrack=(e,...t)=>{const r=new R({track:e}),o=new A(r);return o.mid=e.kind==="audio"?"0":"1",this.senders.push(r),this.dispatchTrackInternal(e,...t),r};addTrackWithMid=(e,t)=>{const r=new R({track:e}),o=new A(r);return t===void 0?o.mid=e.kind==="audio"?"0":"1":o.mid=t,this.senders.push(r),this.dispatchTrackInternal(e),r};dispatchTrack(e){this.dispatchTrackInternal(new _.MediaStreamTrackMock(e))}dispatchTrackInternal(e,...t){const r=new Event("track");Object.defineProperty(r,"track",{value:e}),Object.defineProperty(r,"streams",{value:t.length===0?[new MediaStream([e])]:t}),this.dispatchEvent(r)}}function at(n){const e=n.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const M=400,F="777",ct=n=>n.getVideoTracks().length>0;class s extends it{static presentationError;static startPresentationError;static countStartPresentationError=Number.POSITIVE_INFINITY;static countStartsPresentation=0;url;status_code;renegotiate=jest.fn(async()=>!0);answer=jest.fn(({mediaStream:e})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(e),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},M)});replaceMediaStream=jest.fn(async e=>{});_isReadyToReOffer=jest.fn(()=>!0);addTransceiver=jest.fn((e,t)=>({}));restartIce=jest.fn(async e=>!0);isEndedInner=!1;delayStartPresentation=0;timeoutStartPresentation;timeoutConnect;timeoutNewInfo;timeoutAccepted;timeoutConfirmed;constructor({eventHandlers:e,originator:t,remoteIdentity:r=new a.NameAddrHeader(new a.URI("sip","caller1","test1.com",5060),"Test Caller 1"),delayStartPresentation:o=0}){super({originator:t,eventHandlers:e,remoteIdentity:r}),this.delayStartPresentation=o}static get C(){return a.SessionStatus}static setPresentationError(e){this.presentationError=e}static resetPresentationError(){this.presentationError=void 0}static setStartPresentationError(e,{count:t=Number.POSITIVE_INFINITY}={}){this.startPresentationError=e,this.countStartPresentationError=t}static resetStartPresentationError(){this.startPresentationError=void 0,this.countStartPresentationError=Number.POSITIVE_INFINITY,this.countStartsPresentation=0}startPresentation=async e=>(s.countStartsPresentation+=1,new Promise((t,r)=>{this.timeoutStartPresentation=setTimeout(()=>{if(s.presentationError){this.trigger("presentation:start",e),this.trigger("presentation:failed",e),r(s.presentationError);return}if(s.startPresentationError&&s.countStartsPresentation<s.countStartPresentationError){this.trigger("presentation:start",e),this.trigger("presentation:failed",e),r(s.startPresentationError);return}t(super.startPresentation(e))},this.delayStartPresentation)}));stopPresentation=async e=>{if(s.presentationError)throw this.trigger("presentation:end",e),this.trigger("presentation:failed",e),s.presentationError;return super.stopPresentation(e)};initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const t=_.createAudioMediaStreamTrackMock();t.id="mainaudio1";const r=[t];if(ct(e)){const c=_.createVideoMediaStreamTrackMock();c.id="mainvideo1",r.push(c)}this.connection=new st(void 0,r),this.trigger("peerconnection",{peerconnection:this.connection}),this.addStream(e)}connect(e,{mediaStream:t}={}){const r=at(e);return this.initPeerconnection(t),this.timeoutConnect=setTimeout(()=>{e.includes(F)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:"Rejected"}):(this.trigger("connecting"),this.timeoutNewInfo=setTimeout(()=>{this.newInfo({originator:D.Originator.REMOTE,request:{getHeader:o=>o==="content-type"?"application/vinteo.webrtc.roomname":o==="x-webrtc-enter-room"?r:o==="x-webrtc-participant-name"?"Test Caller 1":""}})},100),this.timeoutAccepted=setTimeout(()=>{this.trigger("accepted")},200),this.timeoutConfirmed=setTimeout(()=>{this.trigger("confirmed")},300))},M),this.connection}terminate({status_code:e,cause:t}={}){return this.status_code=e,this.trigger("ended",{status_code:e,cause:t,originator:"local"}),this.isEndedInner=!1,this}async terminateAsync({status_code:e,cause:t}={}){this.terminate({status_code:e,cause:t})}terminateRemote({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e,originator:"remote"}),this}addStream(e,t="getTracks"){e[t]().forEach(r=>this.connection.addTrack(r,e))}forEachSenders(e){const t=this.connection.getSenders();for(const r of t)e(r);return t}toggleMuteAudio(e){this.forEachSenders(({track:t})=>{t?.kind==="audio"&&(t.enabled=!e)})}toggleMuteVideo(e){this.forEachSenders(({track:t})=>{t?.kind==="video"&&(t.enabled=!e)})}mute(e){e.audio&&(this.mutedOptions.audio=!0,this.toggleMuteAudio(this.mutedOptions.audio)),e.video&&(this.mutedOptions.video=!0,this.toggleMuteVideo(this.mutedOptions.video)),this.onmute(e)}unmute(e){e.audio&&(this.mutedOptions.audio=!1),e.video&&(this.mutedOptions.video=!1),this.trigger("unmuted",e)}isMuted(){return this.mutedOptions}onmute({audio:e,video:t}){this.trigger("muted",{audio:e,video:t})}async sendInfo(){}isEnded(){return this.isEndedInner}newInfo(e){this.trigger("newInfo",e)}clear(){clearTimeout(this.timeoutStartPresentation),clearTimeout(this.timeoutConnect),clearTimeout(this.timeoutNewInfo),clearTimeout(this.timeoutAccepted),clearTimeout(this.timeoutConfirmed)}}class dt{extraHeaders=[];setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",I="PASSWORD_CORRECT_2",W="NAME_INCORRECT",E=400,g={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},O={status_code:200,reason_phrase:"OK"},P={status_code:401,reason_phrase:"Unauthorized"};class i{static isAvailableTelephony=!0;static startError;static countStartError=Number.POSITIVE_INFINITY;static countStarts=0;events;registratorInner;call=jest.fn((e,t)=>{const{mediaStream:r,eventHandlers:o}=t;return this.session=new s({eventHandlers:o,originator:"local"}),this.session.connect(e,{mediaStream:r}),this.session});sendOptions=jest.fn((e,t,r)=>{console.log("sendOptions",e,t,r)});start=jest.fn(()=>{if(i.countStarts+=1,i.startError&&i.countStarts<i.countStartError){this.trigger("disconnected",i.startError);return}this.register()});stop=jest.fn(()=>{this.startedTimeout&&clearTimeout(this.startedTimeout),this.stopedTimeout&&clearTimeout(this.stopedTimeout),this.unregister(),this.isStarted()?this.stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:!0,socket:g})},E):this.trigger("disconnected",{error:!0,socket:g})});removeAllListeners=jest.fn(()=>(this.events.removeEventHandlers(),this));once=jest.fn((e,t)=>(this.events.once(e,t),this));startedTimeout;stopedTimeout;session;isRegisteredInner;isConnectedInner;configuration;constructor(e){this.events=new v.Events(L);const[t,r]=e.uri.split(":"),[o,c]=r.split("@"),p={...e,uri:new a.URI(t,o,c)};this.configuration=p,this.registratorInner=new dt}static setStartError(e,{count:t=Number.POSITIVE_INFINITY}={}){i.startError=e,i.countStartError=t}static resetStartError(){i.startError=void 0,i.countStartError=Number.POSITIVE_INFINITY,i.countStarts=0}static setAvailableTelephony(){i.isAvailableTelephony=!0}static setNotAvailableTelephony(){i.isAvailableTelephony=!1}static reset(){i.resetStartError(),i.setAvailableTelephony()}on(e,t){return this.events.on(e,t),this}off(e,t){return this.events.off(e,t),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:r}=this.configuration;t===!0&&r.user.includes(W)?(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:a.C.causes.REJECTED})},E)):!this.isRegistered()&&t===!0&&(e===d||e===I)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:O})},E)):t===!0&&e!==d&&e!==I&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:a.C.causes.REJECTED})},E)),i.isAvailableTelephony?(this.trigger("connected",{socket:g}),this.isConnectedInner=!0):this.stop()}unregister(){this.isRegisteredInner=!1,this.isConnectedInner=!1,this.trigger("unregistered",{response:O})}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}}class ht{url;constructor(e){this.url=e}}class Et extends V.EventEmitter{contentType;body;constructor(e,t){super(),this.contentType=e,this.body=t}}const S="remote",ut=(n,e)=>{const t=new N(e),r={originator:S,request:t,info:new Et("","")};n.newInfo(r)},mt=(n,e)=>{const r={event:"sipEvent",request:new N(e)};n.newSipEvent(r)},lt=(n,{incomingNumber:e="1234",displayName:t,host:r})=>{const o=new s({originator:S,eventHandlers:{}}),c=new j("sip",e,r);o.remote_identity=new U(c,t);const p=new N([]);n.trigger("newRTCSession",{originator:S,session:o,request:p})},pt=(n,e)=>{e?n.trigger("failed",e):n.trigger("failed",n)},w={triggerNewInfo:ut,triggerNewSipEvent:mt,triggerIncomingSession:lt,triggerFailIncomingSession:pt,WebSocketInterface:ht,UA:i,C:{INVITE:"INVITE"}},u="user",h="displayName",m="SIP_SERVER_URL",C="SIP_WEB_SOCKET_SERVER_URL",gt=new w.WebSocketInterface(`wss://${C}/webrtc/wss/`),f={displayName:"DISPLAY_NAME",userAgent:"Chrome",sipServerIp:m,sipServerUrl:C},_t={...f,displayName:"DISPLAY_NAME",register:!1},b={...f,user:u,password:d,register:!0},Tt={...b,displayName:h},It={...f,displayName:h,register:!1},l={session_timers:!1,sockets:[gt],user_agent:"Chrome",sdpSemantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},St={...l,password:d,uri:new a.URI("sip",u,m),display_name:"DISPLAY_NAME",register:!0},Nt={...l,password:d,uri:new a.URI("sip",u,m),display_name:h,register:!0},wt={...l,display_name:h,register:!1},Ct={...l,display_name:"DISPLAY_NAME",register:!1},k="10.10.10.10",ft=[`X-Vinteo-Remote: ${k}`],Rt=()=>new D.SipConnector({JsSIP:w});exports.FAILED_CONFERENCE_NUMBER=F;exports.JsSIP=w;exports.NAME_INCORRECT=W;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=I;exports.SIP_SERVER_URL=m;exports.SIP_WEB_SOCKET_SERVER_URL=C;exports.dataForConnectionWithAuthorization=b;exports.dataForConnectionWithAuthorizationWithDisplayName=Tt;exports.dataForConnectionWithoutAuthorization=It;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=_t;exports.displayName=h;exports.doMockSipConnector=Rt;exports.extraHeadersRemoteAddress=ft;exports.remoteAddress=k;exports.uaConfigurationWithAuthorization=St;exports.uaConfigurationWithAuthorizationWithDisplayName=Nt;exports.uaConfigurationWithoutAuthorization=wt;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=Ct;exports.user=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("node:events"),a=require("@krivega/jssip"),_=require("webrtc-mock"),D=require("events-constructor"),y=require("./@SipConnector-Cf-5oSvs.cjs");class w extends a.IncomingRequest{headers;constructor(e){super(),this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)??""}}const U="incomingCall",j="declinedIncomingCall",G="failedIncomingCall",H="terminatedIncomingCall",L="connecting",x="connected",z="disconnected",q="newRTCSession",Y="registered",B="unregistered",K="registrationFailed",J="newMessage",$="sipEvent",Q="availableSecondRemoteStream",X="notAvailableSecondRemoteStream",Z="mustStopPresentation",ee="enterRoom",te="useLicense",re="peerconnection:confirmed",ne="peerconnection:ontrack",oe="channels",ie="channels:notify",se="ended:fromserver",ae="main-cam-control",ce="admin:stop-main-cam",de="admin:start-main-cam",he="admin:stop-mic",Ee="admin:start-mic",ue="admin:force-sync-media-state",me="participant:added-to-list-moderators",le="participant:removed-from-list-moderators",pe="participant:move-request-to-stream",ge="participant:move-request-to-spectators",_e="participant:move-request-to-participants",Te="participation:accepting-word-request",Ie="participation:cancelling-word-request",Se="webcast:started",we="webcast:stopped",Ne="account:changed",Ce="account:deleted",fe="conference:participant-token-issued",Re="ended",Ae="sending",Me="reinvite",Oe="replaces",Pe="refer",ve="progress",De="accepted",ye="confirmed",Le="peerconnection",Fe="failed",We="muted",be="unmuted",ke="newDTMF",Ve="newInfo",Ue="hold",je="unhold",Ge="update",He="sdp",xe="icecandidate",ze="getusermediafailed",qe="peerconnection:createofferfailed",Ye="peerconnection:createanswerfailed",Be="peerconnection:setlocaldescriptionfailed",Ke="peerconnection:setremotedescriptionfailed",Je="presentation:start",$e="presentation:started",Qe="presentation:end",Xe="presentation:ended",Ze="presentation:failed",et=[U,j,H,G,Te,Ie,pe,ie,fe,Ne,Ce,Se,we,me,le],F=[L,x,z,q,Y,B,K,J,$],tt=[Q,X,Z,ee,te,re,ne,oe,se,ae,de,ce,he,Ee,ue,ge,_e],T=[Re,L,Ae,Me,Oe,Pe,ve,De,ye,Le,Fe,We,be,ke,Ve,Ue,je,Ge,He,xe,ze,qe,Ye,Be,Ke,Je,$e,Qe,Xe,Ze];[...F,...et];[...T,...tt];class rt{originator;connection;events;remote_identity;mutedOptions={audio:!1,video:!1};constructor({originator:e="local",eventHandlers:t,remoteIdentity:r}){this.originator=e,this.events=new D.Events(T),this.initEvents(t),this.remote_identity=r}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,r){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){return this.events.off(e,t),this}removeAllListeners(e){return console.warn("Method not implemented. Event:",e),this}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){e&&Object.entries(e).forEach(([t,r])=>{this.on(t,r)})}on(e,t){return T.includes(e)&&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 this.trigger("presentation:start",e),this.trigger("presentation:started",e),e}async stopPresentation(e){return this.trigger("presentation:end",e),this.trigger("presentation:ended",e),e}isEstablished(){return!0}}class R{stats=new Map().set("codec",{mimeType:"video/h264"});dtmf=null;track=null;transport=null;transform=null;parameters={encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}};parametersGets;constructor({track:e}={}){this.track=e??null}async getStats(){return this.stats}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 A{currentDirection="sendrecv";direction="sendrecv";mid=null;receiver;sender;stopped=!1;constructor(e){this.sender=e}setCodecPreferences(e){}stop(){}}class nt extends EventTarget{senders=[];receivers=[];canTrickleIceCandidates;connectionState;currentLocalDescription;currentRemoteDescription;iceConnectionState;iceGatheringState;idpErrorInfo;idpLoginUrl;localDescription;onconnectionstatechange;ondatachannel;onicecandidate;onicecandidateerror=null;oniceconnectionstatechange;onicegatheringstatechange;onnegotiationneeded;onsignalingstatechange;ontrack;peerIdentity=void 0;pendingLocalDescription;pendingRemoteDescription;remoteDescription;sctp=null;signalingState;close=jest.fn();setLocalDescription=jest.fn(async e=>{});setRemoteDescription=jest.fn(async e=>{});addTransceiver=jest.fn((e,t)=>({}));createOffer=jest.fn(async(e,t,r)=>({type:"offer",sdp:"offer-sdp"}));constructor(e,t){super(),this.receivers=t?.map(r=>({track:r}))??[]}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(e){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.")}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.")}getReceivers=()=>this.receivers;getSenders=()=>this.senders;addTrack=(e,...t)=>{const r=new R({track:e}),o=new A(r);return o.mid=e.kind==="audio"?"0":"1",this.senders.push(r),this.dispatchTrackInternal(e,...t),r};addTrackWithMid=(e,t)=>{const r=new R({track:e}),o=new A(r);return t===void 0?o.mid=e.kind==="audio"?"0":"1":o.mid=t,this.senders.push(r),this.dispatchTrackInternal(e),r};dispatchTrack(e){this.dispatchTrackInternal(new _.MediaStreamTrackMock(e))}dispatchTrackInternal(e,...t){const r=new Event("track");Object.defineProperty(r,"track",{value:e}),Object.defineProperty(r,"streams",{value:t.length===0?[new MediaStream([e])]:t}),this.dispatchEvent(r)}}function ot(n){const e=n.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const M=400,W="777",it=n=>n.getVideoTracks().length>0;class s extends rt{static presentationError;static startPresentationError;static countStartPresentationError=Number.POSITIVE_INFINITY;static countStartsPresentation=0;url;status_code;renegotiate=jest.fn(async()=>!0);answer=jest.fn(({mediaStream:e})=>{if(this.originator!=="remote")throw new Error("answer available only for remote sessions");this.initPeerconnection(e),setTimeout(()=>{this.trigger("connecting"),setTimeout(()=>{this.trigger("accepted")},100),setTimeout(()=>{this.trigger("confirmed")},200)},M)});replaceMediaStream=jest.fn(async e=>{});_isReadyToReOffer=jest.fn(()=>!0);addTransceiver=jest.fn((e,t)=>({}));restartIce=jest.fn(async e=>!0);isEndedInner=!1;delayStartPresentation=0;timeoutStartPresentation;timeoutConnect;timeoutNewInfo;timeoutAccepted;timeoutConfirmed;constructor({eventHandlers:e,originator:t,remoteIdentity:r=new a.NameAddrHeader(new a.URI("sip","caller1","test1.com",5060),"Test Caller 1"),delayStartPresentation:o=0}){super({originator:t,eventHandlers:e,remoteIdentity:r}),this.delayStartPresentation=o}static get C(){return a.SessionStatus}static setPresentationError(e){this.presentationError=e}static resetPresentationError(){this.presentationError=void 0}static setStartPresentationError(e,{count:t=Number.POSITIVE_INFINITY}={}){this.startPresentationError=e,this.countStartPresentationError=t}static resetStartPresentationError(){this.startPresentationError=void 0,this.countStartPresentationError=Number.POSITIVE_INFINITY,this.countStartsPresentation=0}startPresentation=async e=>(s.countStartsPresentation+=1,new Promise((t,r)=>{this.timeoutStartPresentation=setTimeout(()=>{if(s.presentationError){this.trigger("presentation:start",e),this.trigger("presentation:failed",e),r(s.presentationError);return}if(s.startPresentationError&&s.countStartsPresentation<s.countStartPresentationError){this.trigger("presentation:start",e),this.trigger("presentation:failed",e),r(s.startPresentationError);return}t(super.startPresentation(e))},this.delayStartPresentation)}));stopPresentation=async e=>{if(s.presentationError)throw this.trigger("presentation:end",e),this.trigger("presentation:failed",e),s.presentationError;return super.stopPresentation(e)};initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const t=_.createAudioMediaStreamTrackMock();t.id="mainaudio1";const r=[t];if(it(e)){const c=_.createVideoMediaStreamTrackMock();c.id="mainvideo1",r.push(c)}this.connection=new nt(void 0,r),this.trigger("peerconnection",{peerconnection:this.connection}),this.addStream(e)}connect(e,{mediaStream:t}={}){const r=ot(e);return this.initPeerconnection(t),this.timeoutConnect=setTimeout(()=>{e.includes(W)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:"Rejected"}):(this.trigger("connecting"),this.timeoutNewInfo=setTimeout(()=>{this.newInfo({originator:y.Originator.REMOTE,request:{getHeader:o=>o==="content-type"?"application/vinteo.webrtc.roomname":o==="x-webrtc-enter-room"?r:o==="x-webrtc-participant-name"?"Test Caller 1":""}})},100),this.timeoutAccepted=setTimeout(()=>{this.trigger("accepted")},200),this.timeoutConfirmed=setTimeout(()=>{this.trigger("confirmed")},300))},M),this.connection}terminate({status_code:e,cause:t}={}){return this.status_code=e,this.trigger("ended",{status_code:e,cause:t,originator:"local"}),this.isEndedInner=!1,this}async terminateAsync({status_code:e,cause:t}={}){this.terminate({status_code:e,cause:t})}terminateRemote({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e,originator:"remote"}),this}addStream(e,t="getTracks"){e[t]().forEach(r=>this.connection.addTrack(r,e))}forEachSenders(e){const t=this.connection.getSenders();for(const r of t)e(r);return t}toggleMuteAudio(e){this.forEachSenders(({track:t})=>{t?.kind==="audio"&&(t.enabled=!e)})}toggleMuteVideo(e){this.forEachSenders(({track:t})=>{t?.kind==="video"&&(t.enabled=!e)})}mute(e){e.audio&&(this.mutedOptions.audio=!0,this.toggleMuteAudio(this.mutedOptions.audio)),e.video&&(this.mutedOptions.video=!0,this.toggleMuteVideo(this.mutedOptions.video)),this.onmute(e)}unmute(e){e.audio&&(this.mutedOptions.audio=!1),e.video&&(this.mutedOptions.video=!1),this.trigger("unmuted",e)}isMuted(){return this.mutedOptions}onmute({audio:e,video:t}){this.trigger("muted",{audio:e,video:t})}async sendInfo(){}isEnded(){return this.isEndedInner}newInfo(e){this.trigger("newInfo",e)}clear(){clearTimeout(this.timeoutStartPresentation),clearTimeout(this.timeoutConnect),clearTimeout(this.timeoutNewInfo),clearTimeout(this.timeoutAccepted),clearTimeout(this.timeoutConfirmed)}}class st{extraHeaders=[];setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",I="PASSWORD_CORRECT_2",b="NAME_INCORRECT",E=400,g={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},O={status_code:200,reason_phrase:"OK"},P={status_code:401,reason_phrase:"Unauthorized"};class i extends v.EventEmitter{static isAvailableTelephony=!0;static startError;static countStartError=Number.POSITIVE_INFINITY;static countStarts=0;events;registratorInner;call=jest.fn((e,t)=>{const{mediaStream:r,eventHandlers:o}=t;return this.session=new s({eventHandlers:o,originator:"local"}),this.session.connect(e,{mediaStream:r}),this.session});sendOptions=jest.fn((e,t,r)=>{console.log("sendOptions",e,t,r)});start=jest.fn(()=>{if(i.countStarts+=1,i.startError&&i.countStarts<i.countStartError){this.trigger("disconnected",i.startError);return}this.register()});stop=jest.fn(()=>{this.startedTimeout&&clearTimeout(this.startedTimeout),this.stopedTimeout&&clearTimeout(this.stopedTimeout),this.unregister(),this.isStarted()?this.stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:!0,socket:g})},E):this.trigger("disconnected",{error:!0,socket:g})});removeAllListeners=jest.fn(()=>(this.events.removeEventHandlers(),this));once=jest.fn((e,t)=>(this.events.once(e,t),this));configuration;startedTimeout;stopedTimeout;session;isRegisteredInner;isConnectedInner;constructor(e){super(),this.events=new D.Events(F);const[t,r]=e.uri.split(":"),[o,c]=r.split("@"),p={...e,uri:new a.URI(t,o,c)};this.configuration=p,this.registratorInner=new st}get C(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}get contact(){throw new Error("Method not implemented.")}get transport(){throw new Error("Method not implemented.")}static C(){throw new Error("Method not implemented.")}static setStartError(e,{count:t=Number.POSITIVE_INFINITY}={}){i.startError=e,i.countStartError=t}static resetStartError(){i.startError=void 0,i.countStartError=Number.POSITIVE_INFINITY,i.countStarts=0}static setAvailableTelephony(){i.isAvailableTelephony=!0}static setNotAvailableTelephony(){i.isAvailableTelephony=!1}static reset(){i.resetStartError(),i.setAvailableTelephony()}on(e,t){return this.events.on(e,t),this}sendMessage(){throw new Error("Method not implemented.")}normalizeTarget(){throw new Error("Method not implemented.")}get(){throw new Error("Method not implemented.")}off(e,t){return this.events.off(e,t),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:r}=this.configuration;t===!0&&r.user.includes(b)?(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:a.C.causes.REJECTED})},E)):!this.isRegistered()&&t===!0&&(e===d||e===I)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:O})},E)):t===!0&&e!==d&&e!==I&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:P,cause:a.C.causes.REJECTED})},E)),i.isAvailableTelephony?(this.trigger("connected",{socket:g}),this.isConnectedInner=!0):this.stop()}unregister(){this.isRegisteredInner=!1,this.isConnectedInner=!1,this.trigger("unregistered",{response:O})}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}}class at{url;constructor(e){this.url=e}}class ct extends v.EventEmitter{contentType;body;constructor(e,t){super(),this.contentType=e,this.body=t}}const S="remote",dt=(n,e)=>{const t=new w(e),r={originator:S,request:t,info:new ct("","")};n.newInfo(r)},ht=(n,e)=>{const r={event:"sipEvent",request:new w(e)};n.newSipEvent(r)},Et=(n,{incomingNumber:e="1234",displayName:t,host:r})=>{const o=new s({originator:S,eventHandlers:{}}),c=new a.URI("sip",e,r);o.remote_identity=new a.NameAddrHeader(c,t);const p=new w([]);n.trigger("newRTCSession",{originator:S,session:o,request:p})},ut=(n,e)=>{e?n.trigger("failed",e):n.trigger("failed",n)},N={triggerNewInfo:dt,triggerNewSipEvent:ht,triggerIncomingSession:Et,triggerFailIncomingSession:ut,WebSocketInterface:at,UA:i,C:{INVITE:"INVITE"}},u="user",h="displayName",m="SIP_SERVER_URL",C="SIP_WEB_SOCKET_SERVER_URL",mt=new N.WebSocketInterface(`wss://${C}/webrtc/wss/`),f={displayName:"DISPLAY_NAME",userAgent:"Chrome",sipServerIp:m,sipServerUrl:C},lt={...f,displayName:"DISPLAY_NAME",register:!1},k={...f,user:u,password:d,register:!0},pt={...k,displayName:h},gt={...f,displayName:h,register:!1},l={session_timers:!1,sockets:[mt],user_agent:"Chrome",sdpSemantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},_t={...l,password:d,uri:new a.URI("sip",u,m),display_name:"DISPLAY_NAME",register:!0},Tt={...l,password:d,uri:new a.URI("sip",u,m),display_name:h,register:!0},It={...l,display_name:h,register:!1},St={...l,display_name:"DISPLAY_NAME",register:!1},V="10.10.10.10",wt=[`X-Vinteo-Remote: ${V}`],Nt=()=>new y.SipConnector({JsSIP:N});exports.FAILED_CONFERENCE_NUMBER=W;exports.JsSIP=N;exports.NAME_INCORRECT=b;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=I;exports.SIP_SERVER_URL=m;exports.SIP_WEB_SOCKET_SERVER_URL=C;exports.dataForConnectionWithAuthorization=k;exports.dataForConnectionWithAuthorizationWithDisplayName=pt;exports.dataForConnectionWithoutAuthorization=gt;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=lt;exports.displayName=h;exports.doMockSipConnector=Nt;exports.extraHeadersRemoteAddress=wt;exports.remoteAddress=V;exports.uaConfigurationWithAuthorization=_t;exports.uaConfigurationWithAuthorizationWithDisplayName=Tt;exports.uaConfigurationWithoutAuthorization=It;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=St;exports.user=u;