sip-connector 18.0.0 → 19.0.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.
- package/README.md +123 -29
- package/dist/@SipConnector-DNQcZdY9.cjs +1 -0
- package/dist/{@SipConnector-UTHCoMXw.js → @SipConnector-Wp8bjnnP.js} +832 -473
- package/dist/AutoConnectorManager/@AutoConnectorManager.d.ts +41 -0
- package/dist/AutoConnectorManager/AttemptsState.d.ts +21 -0
- package/dist/AutoConnectorManager/CheckTelephonyRequester.d.ts +19 -0
- package/dist/AutoConnectorManager/PingServerIfNotActiveCallRequester.d.ts +18 -0
- package/dist/AutoConnectorManager/PingServerRequester.d.ts +13 -0
- package/dist/AutoConnectorManager/RegistrationFailedOutOfCallSubscriber.d.ts +18 -0
- package/dist/AutoConnectorManager/eventNames.d.ts +18 -0
- package/dist/AutoConnectorManager/index.d.ts +3 -0
- package/dist/AutoConnectorManager/types.d.ts +22 -0
- package/dist/AutoConnectorManager/utils/errors.d.ts +2 -0
- package/dist/AutoConnectorManager/utils/index.d.ts +1 -0
- package/dist/CallManager/@CallManager.d.ts +3 -0
- package/dist/CallManager/eventNames.d.ts +6 -2
- package/dist/ConnectionManager/@ConnectionManager.d.ts +10 -1
- package/dist/ConnectionManager/eventNames.d.ts +6 -2
- package/dist/ConnectionManager/index.d.ts +1 -0
- package/dist/ConnectionManager/utils/errors.d.ts +2 -0
- package/dist/ConnectionManager/utils/index.d.ts +2 -0
- package/dist/ConnectionManager/utils/resolveParameters.d.ts +2 -0
- package/dist/ConnectionQueueManager/@ConnectionQueueManager.d.ts +1 -7
- package/dist/ConnectionQueueManager/index.d.ts +1 -0
- package/dist/SipConnector/@SipConnector.d.ts +8 -4
- package/dist/SipConnector/eventNames.d.ts +1 -1
- package/dist/SipConnectorFacade/@SipConnectorFacade.d.ts +16 -10
- package/dist/doMock.cjs +1 -1
- package/dist/doMock.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +227 -213
- package/package.json +5 -5
- package/dist/@SipConnector-CFYT0HQB.cjs +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ConnectionManager } from '../ConnectionManager';
|
|
2
|
+
import { CallManager } from '../CallManager';
|
|
3
|
+
import { ConnectionQueueManager } from '../ConnectionQueueManager';
|
|
4
|
+
import { TEventMap, TEvents } from './eventNames';
|
|
5
|
+
import { IAutoConnectorOptions, TParametersAutoConnect } from './types';
|
|
6
|
+
declare class AutoConnectorManager {
|
|
7
|
+
readonly events: TEvents;
|
|
8
|
+
private readonly connectionManager;
|
|
9
|
+
private readonly connectionQueueManager;
|
|
10
|
+
private readonly checkTelephonyRequester;
|
|
11
|
+
private readonly pingServerIfNotActiveCallRequester;
|
|
12
|
+
private readonly registrationFailedOutOfCallSubscriber;
|
|
13
|
+
private readonly attemptsState;
|
|
14
|
+
private readonly delayBetweenAttempts;
|
|
15
|
+
private readonly cancelableRequestBeforeRetry;
|
|
16
|
+
private readonly onBeforeRetry;
|
|
17
|
+
constructor({ connectionQueueManager, connectionManager, callManager, }: {
|
|
18
|
+
connectionQueueManager: ConnectionQueueManager;
|
|
19
|
+
connectionManager: ConnectionManager;
|
|
20
|
+
callManager: CallManager;
|
|
21
|
+
}, options?: IAutoConnectorOptions);
|
|
22
|
+
start(parameters: TParametersAutoConnect): void;
|
|
23
|
+
stop(): void;
|
|
24
|
+
on<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): () => void;
|
|
25
|
+
once<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): () => void;
|
|
26
|
+
onceRace<T extends keyof TEventMap>(eventNames: T[], handler: (data: TEventMap[T], eventName: string) => void): () => void;
|
|
27
|
+
wait<T extends keyof TEventMap>(eventName: T): Promise<TEventMap[T]>;
|
|
28
|
+
off<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): void;
|
|
29
|
+
private stopAttempts;
|
|
30
|
+
private stopConnectTriggers;
|
|
31
|
+
private runCheckTelephony;
|
|
32
|
+
private connect;
|
|
33
|
+
private processConnect;
|
|
34
|
+
private handleLimitReached;
|
|
35
|
+
private handleSucceededAttempt;
|
|
36
|
+
private subscribeToConnectTriggers;
|
|
37
|
+
private connectIfDisconnected;
|
|
38
|
+
private reconnect;
|
|
39
|
+
private hasFailedOrDisconnectedConnection;
|
|
40
|
+
}
|
|
41
|
+
export default AutoConnectorManager;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TEvents } from './eventNames';
|
|
2
|
+
declare class AttemptsState {
|
|
3
|
+
private readonly events;
|
|
4
|
+
private countInner;
|
|
5
|
+
private readonly initialCount;
|
|
6
|
+
private readonly limitInner;
|
|
7
|
+
private isInProgress;
|
|
8
|
+
constructor({ events }: {
|
|
9
|
+
events: TEvents;
|
|
10
|
+
});
|
|
11
|
+
get count(): number;
|
|
12
|
+
get limit(): number;
|
|
13
|
+
get isAttemptInProgress(): boolean;
|
|
14
|
+
hasLimitReached(): boolean;
|
|
15
|
+
startAttempt(): void;
|
|
16
|
+
finishAttempt(): void;
|
|
17
|
+
increment(): void;
|
|
18
|
+
reset(): void;
|
|
19
|
+
private emitStatusChange;
|
|
20
|
+
}
|
|
21
|
+
export default AttemptsState;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConnectionManager } from '../ConnectionManager';
|
|
2
|
+
import { TParametersCheckTelephony } from './types';
|
|
3
|
+
declare class CheckTelephonyRequester {
|
|
4
|
+
private readonly connectionManager;
|
|
5
|
+
private readonly interval;
|
|
6
|
+
private checkTelephonyByTimeout;
|
|
7
|
+
private cancelableBeforeRequest;
|
|
8
|
+
constructor({ connectionManager, interval, }: {
|
|
9
|
+
connectionManager: ConnectionManager;
|
|
10
|
+
interval: number;
|
|
11
|
+
});
|
|
12
|
+
start({ onBeforeRequest, onSuccessRequest, onFailRequest, }: {
|
|
13
|
+
onBeforeRequest: () => Promise<TParametersCheckTelephony>;
|
|
14
|
+
onSuccessRequest: () => void;
|
|
15
|
+
onFailRequest: () => void;
|
|
16
|
+
}): void;
|
|
17
|
+
stop(): void;
|
|
18
|
+
}
|
|
19
|
+
export default CheckTelephonyRequester;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CallManager } from '../CallManager';
|
|
2
|
+
import { ConnectionManager } from '../ConnectionManager';
|
|
3
|
+
declare class PingServerIfNotActiveCallRequester {
|
|
4
|
+
private readonly callManager;
|
|
5
|
+
private readonly pingServerRequester;
|
|
6
|
+
private disposeCallStatusChange;
|
|
7
|
+
constructor({ connectionManager, callManager, }: {
|
|
8
|
+
connectionManager: ConnectionManager;
|
|
9
|
+
callManager: CallManager;
|
|
10
|
+
});
|
|
11
|
+
start({ onFailRequest }: {
|
|
12
|
+
onFailRequest: () => void;
|
|
13
|
+
}): void;
|
|
14
|
+
stop(): void;
|
|
15
|
+
private unsubscribeCallStatusChange;
|
|
16
|
+
private handleCallStatusChange;
|
|
17
|
+
}
|
|
18
|
+
export default PingServerIfNotActiveCallRequester;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ConnectionManager } from '../ConnectionManager';
|
|
2
|
+
declare class PingServerRequester {
|
|
3
|
+
private readonly connectionManager;
|
|
4
|
+
private readonly pingServerByTimeoutWithFailCalls;
|
|
5
|
+
constructor({ connectionManager }: {
|
|
6
|
+
connectionManager: ConnectionManager;
|
|
7
|
+
});
|
|
8
|
+
start({ onFailRequest }: {
|
|
9
|
+
onFailRequest: () => void;
|
|
10
|
+
}): void;
|
|
11
|
+
stop(): void;
|
|
12
|
+
}
|
|
13
|
+
export default PingServerRequester;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CallManager } from '../CallManager';
|
|
2
|
+
import { ConnectionManager } from '../ConnectionManager';
|
|
3
|
+
import { ISubscriber } from './types';
|
|
4
|
+
declare class RegistrationFailedOutOfCallSubscriber implements ISubscriber {
|
|
5
|
+
private readonly connectionManager;
|
|
6
|
+
private readonly callManager;
|
|
7
|
+
private isRegistrationFailed;
|
|
8
|
+
private disposers;
|
|
9
|
+
constructor({ connectionManager, callManager, }: {
|
|
10
|
+
connectionManager: ConnectionManager;
|
|
11
|
+
callManager: CallManager;
|
|
12
|
+
});
|
|
13
|
+
subscribe(callback: () => void): void;
|
|
14
|
+
unsubscribe(): void;
|
|
15
|
+
private setIsRegistrationFailed;
|
|
16
|
+
private resetIsRegistrationFailed;
|
|
17
|
+
}
|
|
18
|
+
export default RegistrationFailedOutOfCallSubscriber;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TypedEvents } from 'events-constructor';
|
|
2
|
+
import { TAttemptStatus } from './types';
|
|
3
|
+
export declare enum EEvent {
|
|
4
|
+
BEFORE_ATTEMPT = "before-attempt",
|
|
5
|
+
SUCCEEDED_ATTEMPT = "succeeded-attempt",
|
|
6
|
+
FAILED_ATTEMPT = "failed-attempt",
|
|
7
|
+
CANCELLED_ATTEMPT = "cancelled-attempt",
|
|
8
|
+
CHANGED_ATTEMPT_STATUS = "changed-attempt-status"
|
|
9
|
+
}
|
|
10
|
+
export declare const EVENT_NAMES: readonly ["before-attempt", "succeeded-attempt", "failed-attempt", "cancelled-attempt", "changed-attempt-status"];
|
|
11
|
+
export type TEventMap = {
|
|
12
|
+
'before-attempt': Record<string, never>;
|
|
13
|
+
'succeeded-attempt': Record<string, never>;
|
|
14
|
+
'failed-attempt': Error;
|
|
15
|
+
'cancelled-attempt': Error;
|
|
16
|
+
'changed-attempt-status': TAttemptStatus;
|
|
17
|
+
};
|
|
18
|
+
export type TEvents = TypedEvents<TEventMap>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ConnectionManager } from '../ConnectionManager';
|
|
2
|
+
import { ConnectionQueueManager } from '../ConnectionQueueManager';
|
|
3
|
+
export interface IAutoConnectorOptions {
|
|
4
|
+
checkTelephonyRequestInterval?: number;
|
|
5
|
+
timeoutBetweenAttempts?: number;
|
|
6
|
+
onBeforeRetry?: () => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export type ISubscriber<T = void> = {
|
|
9
|
+
subscribe: (callback: (value: T) => void) => void;
|
|
10
|
+
unsubscribe: () => void;
|
|
11
|
+
};
|
|
12
|
+
export type TParametersCheckTelephony = Parameters<ConnectionManager['checkTelephony']>[0];
|
|
13
|
+
export type TParametersConnect = Parameters<ConnectionQueueManager['connect']>[0] extends (() => Promise<infer T>) | infer T ? T : never;
|
|
14
|
+
type TOptionsConnect = Parameters<ConnectionQueueManager['connect']>[1];
|
|
15
|
+
export type TParametersAutoConnect = {
|
|
16
|
+
getParameters: () => Promise<TParametersConnect & TParametersCheckTelephony>;
|
|
17
|
+
options?: TOptionsConnect;
|
|
18
|
+
};
|
|
19
|
+
export type TAttemptStatus = {
|
|
20
|
+
isInProgress: boolean;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { hasParametersNotExistError, createParametersNotExistError } from './errors';
|
|
@@ -10,6 +10,7 @@ declare class CallManager {
|
|
|
10
10
|
get establishedRTCSession(): RTCSession | undefined;
|
|
11
11
|
get isCallActive(): ICallStrategy['isCallActive'];
|
|
12
12
|
on<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): () => void;
|
|
13
|
+
onRace<T extends keyof TEventMap>(eventNames: T[], handler: (data: TEventMap[T], eventName: string) => void): () => void;
|
|
13
14
|
once<T extends keyof TEventMap>(eventName: T, handler: (data: TEventMap[T]) => void): () => void;
|
|
14
15
|
onceRace<T extends keyof TEventMap>(eventNames: T[], handler: (data: TEventMap[T], eventName: string) => void): () => void;
|
|
15
16
|
wait<T extends keyof TEventMap>(eventName: T): Promise<TEventMap[T]>;
|
|
@@ -24,5 +25,7 @@ declare class CallManager {
|
|
|
24
25
|
addTransceiver: ICallStrategy['addTransceiver'];
|
|
25
26
|
replaceMediaStream: ICallStrategy['replaceMediaStream'];
|
|
26
27
|
restartIce: ICallStrategy['restartIce'];
|
|
28
|
+
private subscribeCallStatusChange;
|
|
29
|
+
private maybeTriggerCallStatus;
|
|
27
30
|
}
|
|
28
31
|
export default CallManager;
|
|
@@ -33,7 +33,8 @@ export declare enum EEvent {
|
|
|
33
33
|
FAILED_PRESENTATION = "presentation:failed",
|
|
34
34
|
PEER_CONNECTION_CONFIRMED = "peerconnection:confirmed",
|
|
35
35
|
PEER_CONNECTION_ONTRACK = "peerconnection:ontrack",
|
|
36
|
-
ENDED_FROM_SERVER = "ended:fromserver"
|
|
36
|
+
ENDED_FROM_SERVER = "ended:fromserver",
|
|
37
|
+
CALL_STATUS_CHANGED = "call-status-changed"
|
|
37
38
|
}
|
|
38
39
|
export declare enum Originator {
|
|
39
40
|
LOCAL = "local",
|
|
@@ -41,7 +42,7 @@ export declare enum Originator {
|
|
|
41
42
|
SYSTEM = "system"
|
|
42
43
|
}
|
|
43
44
|
export declare const SESSION_JSSIP_EVENT_NAMES: readonly ["peerconnection", "connecting", "sending", "progress", "accepted", "confirmed", "ended", "failed", "newInfo", "newDTMF", "presentation:start", "presentation:started", "presentation:end", "presentation:ended", "presentation:failed", "reinvite", "update", "refer", "replaces", "sdp", "icecandidate", "getusermediafailed", "peerconnection:createofferfailed", "peerconnection:createanswerfailed", "peerconnection:setlocaldescriptionfailed", "peerconnection:setremotedescriptionfailed"];
|
|
44
|
-
export declare const EVENT_NAMES: readonly ["peerconnection", "connecting", "sending", "progress", "accepted", "confirmed", "ended", "failed", "newInfo", "newDTMF", "presentation:start", "presentation:started", "presentation:end", "presentation:ended", "presentation:failed", "reinvite", "update", "refer", "replaces", "sdp", "icecandidate", "getusermediafailed", "peerconnection:createofferfailed", "peerconnection:createanswerfailed", "peerconnection:setlocaldescriptionfailed", "peerconnection:setremotedescriptionfailed", "peerconnection:confirmed", "peerconnection:ontrack", "ended:fromserver"];
|
|
45
|
+
export declare const EVENT_NAMES: readonly ["peerconnection", "connecting", "sending", "progress", "accepted", "confirmed", "ended", "failed", "newInfo", "newDTMF", "presentation:start", "presentation:started", "presentation:end", "presentation:ended", "presentation:failed", "reinvite", "update", "refer", "replaces", "sdp", "icecandidate", "getusermediafailed", "peerconnection:createofferfailed", "peerconnection:createanswerfailed", "peerconnection:setlocaldescriptionfailed", "peerconnection:setremotedescriptionfailed", "peerconnection:confirmed", "peerconnection:ontrack", "ended:fromserver", "call-status-changed"];
|
|
45
46
|
export type TEvent = (typeof EVENT_NAMES)[number];
|
|
46
47
|
export type TEventMap = {
|
|
47
48
|
peerconnection: {
|
|
@@ -81,5 +82,8 @@ export type TEventMap = {
|
|
|
81
82
|
'peerconnection:confirmed': RTCPeerConnection;
|
|
82
83
|
'peerconnection:ontrack': RTCTrackEvent;
|
|
83
84
|
'ended:fromserver': EndEvent;
|
|
85
|
+
'call-status-changed': {
|
|
86
|
+
isCallActive: boolean;
|
|
87
|
+
};
|
|
84
88
|
};
|
|
85
89
|
export type TEvents = TypedEvents<TEventMap>;
|
|
@@ -5,6 +5,10 @@ import { RegisteredEvent, UA, UnRegisteredEvent, WebSocketInterface } from '@kri
|
|
|
5
5
|
import { TGetServerUrl } from '../CallManager';
|
|
6
6
|
import { TJsSIP } from '../types';
|
|
7
7
|
import { TConnect, TSet } from './ConnectionFlow';
|
|
8
|
+
type TConnectParameters = (() => Promise<Parameters<TConnect>[0]>) | Parameters<TConnect>[0];
|
|
9
|
+
type TConnectOptions = Parameters<TConnect>[1] & {
|
|
10
|
+
hasReadyForConnection?: () => boolean;
|
|
11
|
+
};
|
|
8
12
|
export default class ConnectionManager {
|
|
9
13
|
readonly events: Events<typeof EVENT_NAMES>;
|
|
10
14
|
ua?: UA;
|
|
@@ -22,10 +26,12 @@ export default class ConnectionManager {
|
|
|
22
26
|
get requested(): boolean;
|
|
23
27
|
get isPendingConnect(): boolean;
|
|
24
28
|
get isPendingInitUa(): boolean;
|
|
29
|
+
get isDisconnected(): boolean;
|
|
30
|
+
get isFailed(): boolean;
|
|
25
31
|
get connectionState(): import('./ConnectionStateMachine').EState;
|
|
26
32
|
get isRegistered(): boolean;
|
|
27
33
|
get isRegisterConfig(): boolean;
|
|
28
|
-
connect:
|
|
34
|
+
connect: (parameters: TConnectParameters, options?: TConnectOptions) => Promise<UA>;
|
|
29
35
|
set: TSet;
|
|
30
36
|
disconnect: () => Promise<void>;
|
|
31
37
|
register(): Promise<RegisteredEvent>;
|
|
@@ -45,4 +51,7 @@ export default class ConnectionManager {
|
|
|
45
51
|
getSipServerUrl: TGetServerUrl;
|
|
46
52
|
readonly getUaProtected: () => UA;
|
|
47
53
|
private readonly getUa;
|
|
54
|
+
private readonly connectWithProcessError;
|
|
55
|
+
private readonly processConnect;
|
|
48
56
|
}
|
|
57
|
+
export {};
|
|
@@ -3,14 +3,18 @@ export declare enum EEvent {
|
|
|
3
3
|
CONNECTING = "connecting",
|
|
4
4
|
CONNECTED = "connected",
|
|
5
5
|
DISCONNECTED = "disconnected",
|
|
6
|
+
DISCONNECTING = "disconnecting",
|
|
6
7
|
NEW_RTC_SESSION = "newRTCSession",
|
|
7
8
|
REGISTERED = "registered",
|
|
8
9
|
UNREGISTERED = "unregistered",
|
|
9
10
|
REGISTRATION_FAILED = "registrationFailed",
|
|
10
11
|
NEW_MESSAGE = "newMessage",
|
|
11
|
-
SIP_EVENT = "sipEvent"
|
|
12
|
+
SIP_EVENT = "sipEvent",
|
|
13
|
+
CONNECT_STARTED = "connect-started",
|
|
14
|
+
CONNECT_SUCCEEDED = "connect-succeeded",
|
|
15
|
+
CONNECT_FAILED = "connect-failed"
|
|
12
16
|
}
|
|
13
17
|
export declare const UA_EVENT_NAMES: readonly ["connecting", "connected", "disconnected", "newRTCSession", "registered", "unregistered", "registrationFailed", "newMessage", "sipEvent"];
|
|
14
|
-
export declare const EVENT_NAMES:
|
|
18
|
+
export declare const EVENT_NAMES: readonly ["connecting", "connected", "disconnected", "newRTCSession", "registered", "unregistered", "registrationFailed", "newMessage", "sipEvent", "disconnecting", "connect-started", "connect-succeeded", "connect-failed"];
|
|
15
19
|
export type TEvent = (typeof EVENT_NAMES)[number];
|
|
16
20
|
export type TEvents = Events<typeof EVENT_NAMES>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { default as ConnectionManager } from './@ConnectionManager';
|
|
2
2
|
export { EVENT_NAMES as CONNECTION_MANAGER_EVENT_NAMES, EEvent as EConnectionManagerEvent, } from './eventNames';
|
|
3
3
|
export type { TEvent as TConnectionManagerEvent, TEvents as TConnectionManagerEvents, } from './eventNames';
|
|
4
|
+
export { hasNotReadyForConnectionError, resolveParameters } from './utils';
|
|
@@ -7,12 +7,6 @@ declare class ConnectionQueueManager {
|
|
|
7
7
|
});
|
|
8
8
|
connect: ConnectionManager['connect'];
|
|
9
9
|
disconnect: ConnectionManager['disconnect'];
|
|
10
|
-
|
|
11
|
-
unregister: ConnectionManager['unregister'];
|
|
12
|
-
tryRegister: ConnectionManager['tryRegister'];
|
|
13
|
-
checkTelephony: ConnectionManager['checkTelephony'];
|
|
14
|
-
sendOptions: ConnectionManager['sendOptions'];
|
|
15
|
-
ping: ConnectionManager['ping'];
|
|
16
|
-
set: ConnectionManager['set'];
|
|
10
|
+
stop(): void;
|
|
17
11
|
}
|
|
18
12
|
export default ConnectionQueueManager;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Events } from 'events-constructor';
|
|
2
2
|
import { ApiManager } from '../ApiManager';
|
|
3
|
-
import {
|
|
3
|
+
import { AutoConnectorManager, IAutoConnectorOptions } from '../AutoConnectorManager';
|
|
4
|
+
import { CallManager, TGetServerUrl } from '../CallManager';
|
|
4
5
|
import { ConnectionManager } from '../ConnectionManager';
|
|
5
6
|
import { ConnectionQueueManager } from '../ConnectionQueueManager';
|
|
6
7
|
import { IncomingCallManager } from '../IncomingCallManager';
|
|
@@ -9,7 +10,6 @@ import { StatsManager } from '../StatsManager';
|
|
|
9
10
|
import { TransceiverManager } from '../TransceiverManager';
|
|
10
11
|
import { VideoSendingBalancerManager } from '../VideoSendingBalancerManager';
|
|
11
12
|
import { EVENT_NAMES, TEvent } from './eventNames';
|
|
12
|
-
import { TGetServerUrl } from '../CallManager';
|
|
13
13
|
import { TJsSIP } from '../types';
|
|
14
14
|
import { IBalancerOptions } from '../VideoSendingBalancer';
|
|
15
15
|
declare class SipConnector {
|
|
@@ -17,6 +17,7 @@ declare class SipConnector {
|
|
|
17
17
|
readonly connectionManager: ConnectionManager;
|
|
18
18
|
readonly connectionQueueManager: ConnectionQueueManager;
|
|
19
19
|
readonly callManager: CallManager;
|
|
20
|
+
readonly autoConnectorManager: AutoConnectorManager;
|
|
20
21
|
readonly apiManager: ApiManager;
|
|
21
22
|
readonly incomingCallManager: IncomingCallManager;
|
|
22
23
|
readonly presentationManager: PresentationManager;
|
|
@@ -27,10 +28,11 @@ declare class SipConnector {
|
|
|
27
28
|
private readonly excludeMimeTypesVideoCodecs?;
|
|
28
29
|
constructor({ JsSIP }: {
|
|
29
30
|
JsSIP: TJsSIP;
|
|
30
|
-
}, { preferredMimeTypesVideoCodecs, excludeMimeTypesVideoCodecs, videoBalancerOptions, }?: {
|
|
31
|
+
}, { preferredMimeTypesVideoCodecs, excludeMimeTypesVideoCodecs, videoBalancerOptions, autoConnectorOptions, }?: {
|
|
31
32
|
preferredMimeTypesVideoCodecs?: string[];
|
|
32
33
|
excludeMimeTypesVideoCodecs?: string[];
|
|
33
34
|
videoBalancerOptions?: IBalancerOptions;
|
|
35
|
+
autoConnectorOptions?: IAutoConnectorOptions;
|
|
34
36
|
});
|
|
35
37
|
get requestedConnection(): boolean;
|
|
36
38
|
get isPendingConnect(): boolean;
|
|
@@ -51,17 +53,19 @@ declare class SipConnector {
|
|
|
51
53
|
wait<T>(eventName: TEvent): Promise<T>;
|
|
52
54
|
off<T>(eventName: TEvent, handler: (data: T) => void): void;
|
|
53
55
|
connect: ConnectionManager['connect'];
|
|
54
|
-
set: ConnectionManager['set'];
|
|
55
56
|
disconnect: () => Promise<void>;
|
|
56
57
|
register: () => Promise<import('@krivega/jssip').RegisteredEvent>;
|
|
57
58
|
unregister: () => Promise<import('@krivega/jssip').UnRegisteredEvent>;
|
|
58
59
|
tryRegister: () => Promise<import('@krivega/jssip').RegisteredEvent>;
|
|
60
|
+
set: ConnectionManager['set'];
|
|
59
61
|
sendOptions: (target: Parameters<ConnectionManager["sendOptions"]>[0], body?: Parameters<ConnectionManager["sendOptions"]>[1], extraHeaders?: Parameters<ConnectionManager["sendOptions"]>[2]) => Promise<void>;
|
|
60
62
|
ping: (body?: Parameters<ConnectionManager["ping"]>[0], extraHeaders?: Parameters<ConnectionManager["ping"]>[1]) => Promise<void>;
|
|
61
63
|
checkTelephony: ConnectionManager['checkTelephony'];
|
|
62
64
|
isConfigured: () => boolean;
|
|
63
65
|
getConnectionConfiguration: () => import('../ConnectionManager/ConfigurationManager').IConnectionConfiguration;
|
|
64
66
|
getSipServerUrl: TGetServerUrl;
|
|
67
|
+
startAutoConnect: AutoConnectorManager['start'];
|
|
68
|
+
stopAutoConnect: AutoConnectorManager['stop'];
|
|
65
69
|
call: (params: Parameters<CallManager["startCall"]>[2]) => Promise<RTCPeerConnection>;
|
|
66
70
|
hangUp: CallManager['endCall'];
|
|
67
71
|
answerToIncomingCall: (params: Parameters<CallManager["answerToIncomingCall"]>[1]) => Promise<RTCPeerConnection>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Events } from 'events-constructor';
|
|
2
|
-
export declare const EVENT_NAMES: readonly ("connection:connecting" | "connection:connected" | "connection:disconnected" | "connection:newRTCSession" | "connection:registered" | "connection:unregistered" | "connection:registrationFailed" | "connection:newMessage" | "connection:sipEvent" | "call:newDTMF" | "call:peerconnection" | "call:connecting" | "call:sending" | "call:progress" | "call:accepted" | "call:confirmed" | "call:ended" | "call:failed" | "call:newInfo" | "call:reinvite" | "call:update" | "call:refer" | "call:replaces" | "call:sdp" | "call:icecandidate" | "call:getusermediafailed" | "call:peerconnection:createofferfailed" | "call:peerconnection:createanswerfailed" | "call:peerconnection:setlocaldescriptionfailed" | "call:peerconnection:setremotedescriptionfailed" | "call:presentation:start" | "call:presentation:started" | "call:presentation:end" | "call:presentation:ended" | "call:presentation:failed" | "call:peerconnection:confirmed" | "call:peerconnection:ontrack" | "call:ended:fromserver" | "api:channels:notify" | "api:participant:added-to-list-moderators" | "api:participant:removed-from-list-moderators" | "api:participant:move-request-to-stream" | "api:participant:move-request-to-spectators" | "api:participant:move-request-to-participants" | "api:participation:accepting-word-request" | "api:participation:cancelling-word-request" | "api:webcast:started" | "api:webcast:stopped" | "api:account:changed" | "api:account:deleted" | "api:conference:participant-token-issued" | "api:channels" | "api:enterRoom" | "api:shareState" | "api:main-cam-control" | "api:useLicense" | "api:admin-start-main-cam" | "api:admin-stop-main-cam" | "api:admin-start-mic" | "api:admin-stop-mic" | "api:admin-force-sync-media-state" | "api:availableSecondRemoteStream" | "api:notAvailableSecondRemoteStream" | "api:mustStopPresentation" | "api:newDTMF" | "api:restart" | "incoming-call:incomingCall" | "incoming-call:declinedIncomingCall" | "incoming-call:terminatedIncomingCall" | "incoming-call:failedIncomingCall" | "presentation:presentation:start" | "presentation:presentation:started" | "presentation:presentation:end" | "presentation:presentation:ended" | "presentation:presentation:failed" | "stats:collected" | "video-balancer:balancing-scheduled" | "video-balancer:balancing-started" | "video-balancer:balancing-stopped" | "video-balancer:parameters-updated")[];
|
|
2
|
+
export declare const EVENT_NAMES: readonly ("auto-connect:before-attempt" | "auto-connect:succeeded-attempt" | "auto-connect:failed-attempt" | "auto-connect:cancelled-attempt" | "auto-connect:changed-attempt-status" | "connection:connecting" | "connection:connected" | "connection:disconnected" | "connection:disconnecting" | "connection:newRTCSession" | "connection:registered" | "connection:unregistered" | "connection:registrationFailed" | "connection:newMessage" | "connection:sipEvent" | "connection:connect-started" | "connection:connect-succeeded" | "connection:connect-failed" | "call:newDTMF" | "call:peerconnection" | "call:connecting" | "call:sending" | "call:progress" | "call:accepted" | "call:confirmed" | "call:ended" | "call:failed" | "call:newInfo" | "call:reinvite" | "call:update" | "call:refer" | "call:replaces" | "call:sdp" | "call:icecandidate" | "call:getusermediafailed" | "call:peerconnection:createofferfailed" | "call:peerconnection:createanswerfailed" | "call:peerconnection:setlocaldescriptionfailed" | "call:peerconnection:setremotedescriptionfailed" | "call:presentation:start" | "call:presentation:started" | "call:presentation:end" | "call:presentation:ended" | "call:presentation:failed" | "call:peerconnection:confirmed" | "call:peerconnection:ontrack" | "call:ended:fromserver" | "call:call-status-changed" | "api:channels:notify" | "api:participant:added-to-list-moderators" | "api:participant:removed-from-list-moderators" | "api:participant:move-request-to-stream" | "api:participant:move-request-to-spectators" | "api:participant:move-request-to-participants" | "api:participation:accepting-word-request" | "api:participation:cancelling-word-request" | "api:webcast:started" | "api:webcast:stopped" | "api:account:changed" | "api:account:deleted" | "api:conference:participant-token-issued" | "api:channels" | "api:enterRoom" | "api:shareState" | "api:main-cam-control" | "api:useLicense" | "api:admin-start-main-cam" | "api:admin-stop-main-cam" | "api:admin-start-mic" | "api:admin-stop-mic" | "api:admin-force-sync-media-state" | "api:availableSecondRemoteStream" | "api:notAvailableSecondRemoteStream" | "api:mustStopPresentation" | "api:newDTMF" | "api:restart" | "incoming-call:incomingCall" | "incoming-call:declinedIncomingCall" | "incoming-call:terminatedIncomingCall" | "incoming-call:failedIncomingCall" | "presentation:presentation:start" | "presentation:presentation:started" | "presentation:presentation:end" | "presentation:presentation:ended" | "presentation:presentation:failed" | "stats:collected" | "video-balancer:balancing-scheduled" | "video-balancer:balancing-started" | "video-balancer:balancing-stopped" | "video-balancer:parameters-updated")[];
|
|
3
3
|
export type TEvent = (typeof EVENT_NAMES)[number];
|
|
4
4
|
export type TEvents = Events<typeof EVENT_NAMES>;
|
|
@@ -15,6 +15,16 @@ export declare const TEST_HOOKS: {
|
|
|
15
15
|
handleOnceRaceEvent: (unsubscribeEnterConference: () => void, onEndedCall?: () => void) => void;
|
|
16
16
|
handleFailProgressEvent: (onFailProgressCall: (() => void) | undefined, unsubscribeEnterConference: () => void, error: Error) => never;
|
|
17
17
|
};
|
|
18
|
+
type TConnectToServerParameters = {
|
|
19
|
+
userAgent: string;
|
|
20
|
+
sipWebSocketServerURL: string;
|
|
21
|
+
sipServerUrl: string;
|
|
22
|
+
remoteAddress?: string;
|
|
23
|
+
displayName?: string;
|
|
24
|
+
name?: string;
|
|
25
|
+
password?: string;
|
|
26
|
+
isRegisteredUser?: boolean;
|
|
27
|
+
};
|
|
18
28
|
interface IProxyMethods {
|
|
19
29
|
on: SipConnector['on'];
|
|
20
30
|
once: SipConnector['once'];
|
|
@@ -28,6 +38,8 @@ interface IProxyMethods {
|
|
|
28
38
|
checkTelephony: SipConnector['checkTelephony'];
|
|
29
39
|
waitChannels: SipConnector['waitChannels'];
|
|
30
40
|
ping: SipConnector['ping'];
|
|
41
|
+
startAutoConnect: SipConnector['startAutoConnect'];
|
|
42
|
+
stopAutoConnect: SipConnector['stopAutoConnect'];
|
|
31
43
|
connection: SipConnector['connection'];
|
|
32
44
|
isConfigured: SipConnector['isConfigured'];
|
|
33
45
|
isRegistered: SipConnector['isRegistered'];
|
|
@@ -45,21 +57,15 @@ declare class SipConnectorFacade implements IProxyMethods {
|
|
|
45
57
|
checkTelephony: IProxyMethods['checkTelephony'];
|
|
46
58
|
waitChannels: IProxyMethods['waitChannels'];
|
|
47
59
|
ping: IProxyMethods['ping'];
|
|
60
|
+
startAutoConnect: IProxyMethods['startAutoConnect'];
|
|
61
|
+
stopAutoConnect: IProxyMethods['stopAutoConnect'];
|
|
48
62
|
connection: IProxyMethods['connection'];
|
|
49
63
|
isConfigured: IProxyMethods['isConfigured'];
|
|
50
64
|
isRegistered: IProxyMethods['isRegistered'];
|
|
51
65
|
readonly sipConnector: SipConnector;
|
|
52
66
|
constructor(sipConnector: SipConnector);
|
|
53
|
-
connectToServer: (parameters: {
|
|
54
|
-
|
|
55
|
-
sipWebSocketServerURL: string;
|
|
56
|
-
sipServerUrl: string;
|
|
57
|
-
remoteAddress?: string;
|
|
58
|
-
displayName?: string;
|
|
59
|
-
name?: string;
|
|
60
|
-
password?: string;
|
|
61
|
-
isRegisteredUser?: boolean;
|
|
62
|
-
isDisconnectOnFail?: boolean;
|
|
67
|
+
connectToServer: (parameters: (() => Promise<TConnectToServerParameters>) | TConnectToServerParameters, options?: {
|
|
68
|
+
hasReadyForConnection?: () => boolean;
|
|
63
69
|
}) => Promise<{
|
|
64
70
|
ua?: UA;
|
|
65
71
|
isSuccessful: boolean;
|
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"),H=require("@krivega/jssip/lib/URI"),q=require("@krivega/jssip/lib/SIPMessage"),a=require("@krivega/jssip"),f=require("webrtc-mock"),S=require("events-constructor"),D=require("./@SipConnector-CFYT0HQB.cjs");class w extends q.IncomingRequest{headers;constructor(e){super(),this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)??""}}const G="incomingCall",x="declinedIncomingCall",z="failedIncomingCall",j="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="shareState",oe="enterRoom",ie="useLicense",se="peerconnection:confirmed",ae="peerconnection:ontrack",ce="channels",de="channels:notify",he="ended:fromserver",Ee="main-cam-control",ue="admin-stop-main-cam",me="admin-start-main-cam",le="admin-stop-mic",pe="admin-start-mic",ge="admin-force-sync-media-state",_e="participant:added-to-list-moderators",Te="participant:removed-from-list-moderators",Ie="participant:move-request-to-stream",Se="participant:move-request-to-spectators",we="participant:move-request-to-participants",Ne="participation:accepting-word-request",Ce="participation:cancelling-word-request",Re="webcast:started",fe="webcast:stopped",Ae="account:changed",Me="account:deleted",Oe="conference:participant-token-issued",Pe="ended",ve="sending",De="reinvite",ye="replaces",Le="refer",Fe="progress",We="accepted",be="confirmed",ke="peerconnection",Ve="failed",Ue="muted",He="unmuted",qe="newDTMF",Ge="newInfo",xe="hold",ze="unhold",je="update",Ye="sdp",Be="icecandidate",Ke="getusermediafailed",Je="peerconnection:createofferfailed",$e="peerconnection:createanswerfailed",Qe="peerconnection:setlocaldescriptionfailed",Xe="peerconnection:setremotedescriptionfailed",Ze="presentation:start",et="presentation:started",tt="presentation:end",rt="presentation:ended",nt="presentation:failed",ot=[G,x,j,z,Ne,Ce,Ie,de,Oe,Ae,Me,Re,fe,_e,Te],L=[y,Y,B,K,J,$,Q,X,Z],it=[ee,te,re,ne,oe,ie,se,ae,ce,he,Ee,me,ue,le,pe,ge,Se,we],_=[Pe,y,ve,De,ye,Le,Fe,We,be,ke,Ve,Ue,He,qe,Ge,xe,ze,je,Ye,Be,Ke,Je,$e,Qe,Xe,Ze,et,tt,rt,nt];[...L,...ot];[..._,...it];class st{originator;connection;events;remote_identity;mutedOptions={audio:!1,video:!1};constructor({originator:e="local",eventHandlers:t,remoteIdentity:r}){this.originator=e,this.events=new S.Events(_),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 _.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 A{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 M{currentDirection="sendrecv";direction="sendrecv";mid=null;receiver;sender;stopped=!1;constructor(e){this.sender=e}setCodecPreferences(e){}stop(){}}const at=["track"];class ct{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;events;constructor(e,t){this.events=new S.Events(at),this.receivers=t.map(r=>({track:r}))}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,r){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,r){this.events.on(e,t)}removeEventListener(e,t,r){this.events.off(e,t)}dispatchEvent(e){throw new Error("Method not implemented.")}getReceivers=()=>this.receivers;getSenders=()=>this.senders;addTrack=(e,...t)=>{const r=new A({track:e}),n=new M(r);return n.mid=e.kind==="audio"?"0":"1",this.senders.push(r),this.events.trigger("track",{track:e,transceiver:n}),r};addTrackWithMid=(e,t)=>{const r=new A({track:e}),n=new M(r);return t===void 0?n.mid=e.kind==="audio"?"0":"1":n.mid=t,this.senders.push(r),this.events.trigger("track",{track:e,transceiver:n}),r}}function dt(o){const e=o.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const O=400,F="777",ht=o=>o.getVideoTracks().length>0;class s extends st{static presentationError;static startPresentationError;static countStartPresentationError=Number.POSITIVE_INFINITY;static countStartsPresentation=0;url;status_code;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)},O)});replaceMediaStream=jest.fn(async e=>{});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:n=0}){super({originator:t,eventHandlers:e,remoteIdentity:r}),this.delayStartPresentation=n}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=f.createAudioMediaStreamTrackMock();t.id="mainaudio1";const r=[t];if(ht(e)){const c=f.createVideoMediaStreamTrackMock();c.id="mainvideo1",r.push(c)}this.connection=new ct(void 0,r),this.addStream(e),this.trigger("peerconnection",{peerconnection:this.connection})}connect(e,{mediaStream:t}={}){const r=dt(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:n=>n==="content-type"?"application/vinteo.webrtc.roomname":n==="x-webrtc-enter-room"?r:n==="x-webrtc-participant-name"?"Test Caller 1":""}})},100),this.timeoutAccepted=setTimeout(()=>{this.trigger("accepted")},200),this.timeoutConfirmed=setTimeout(()=>{this.trigger("confirmed")},300))},O),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))}forEachSenders(e){const t=this.connection.getSenders();for(const r of t)e(r);return t}toggleMuteAudio(e){this.forEachSenders(({track:t})=>{t&&t.kind==="audio"&&(t.enabled=!e)})}toggleMuteVideo(e){this.forEachSenders(({track:t})=>{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 Et{extraHeaders=[];setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",T="PASSWORD_CORRECT_2",W="NAME_INCORRECT",E=400,g={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},P={status_code:200,reason_phrase:"OK"},v={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:n}=t;return this.session=new s({eventHandlers:n,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 S.Events(L);const[t,r]=e.uri.split(":"),[n,c]=r.split("@"),p={...e,uri:new a.URI(t,n,c)};this.configuration=p,this.registratorInner=new Et}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:v,cause:a.C.causes.REJECTED})},E)):!this.isRegistered()&&t===!0&&(e===d||e===T)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:P})},E)):t===!0&&e!==d&&e!==T&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:v,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:P})}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 ut{url;constructor(e){this.url=e}}class mt extends V.EventEmitter{contentType;body;constructor(e,t){super(),this.contentType=e,this.body=t}}const I="remote",lt=(o,e)=>{const t=new w(e),r={originator:I,request:t,info:new mt("","")};o.newInfo(r)},pt=(o,e)=>{const r={event:"sipEvent",request:new w(e)};o.newSipEvent(r)},gt=(o,{incomingNumber:e="1234",displayName:t,host:r})=>{const n=new s({originator:I,eventHandlers:{}}),c=new H("sip",e,r);n.remote_identity=new U(c,t);const p=new w([]);o.trigger("newRTCSession",{originator:I,session:n,request:p})},_t=(o,e)=>{e?o.trigger("failed",e):o.trigger("failed",o)},N={triggerNewInfo:lt,triggerNewSipEvent:pt,triggerIncomingSession:gt,triggerFailIncomingSession:_t,WebSocketInterface:ut,UA:i,C:{INVITE:"INVITE"}},u="user",h="displayName",m="SIP_SERVER_URL",C="SIP_WEB_SOCKET_SERVER_URL",Tt=new N.WebSocketInterface(C),R={userAgent:"Chrome",sipServerUrl:m,sipWebSocketServerURL:C},It={...R},b={...R,user:u,password:d,register:!0},St={...b,displayName:h},wt={...R,displayName:h,register:!1},l={session_timers:!1,sockets:[Tt],user_agent:"Chrome",sdpSemantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},Nt={...l,password:d,uri:new a.URI("sip",u,m),display_name:"",register:!0},Ct={...l,password:d,uri:new a.URI("sip",u,m),display_name:h,register:!0},Rt={...l,display_name:h,register:!1},ft={...l,display_name:"",register:!1},k="10.10.10.10",At=[`X-Vinteo-Remote: ${k}`],Mt=()=>new D.SipConnector({JsSIP:N});exports.FAILED_CONFERENCE_NUMBER=F;exports.JsSIP=N;exports.NAME_INCORRECT=W;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=T;exports.SIP_SERVER_URL=m;exports.SIP_WEB_SOCKET_SERVER_URL=C;exports.dataForConnectionWithAuthorization=b;exports.dataForConnectionWithAuthorizationWithDisplayName=St;exports.dataForConnectionWithoutAuthorization=wt;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=It;exports.displayName=h;exports.doMockSipConnector=Mt;exports.extraHeadersRemoteAddress=At;exports.remoteAddress=k;exports.uaConfigurationWithAuthorization=Nt;exports.uaConfigurationWithAuthorizationWithDisplayName=Ct;exports.uaConfigurationWithoutAuthorization=Rt;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ft;exports.user=u;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("node:events"),U=require("@krivega/jssip/lib/NameAddrHeader"),H=require("@krivega/jssip/lib/URI"),q=require("@krivega/jssip/lib/SIPMessage"),a=require("@krivega/jssip"),f=require("webrtc-mock"),S=require("events-constructor"),D=require("./@SipConnector-DNQcZdY9.cjs");class w extends q.IncomingRequest{headers;constructor(e){super(),this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)??""}}const G="incomingCall",x="declinedIncomingCall",z="failedIncomingCall",j="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="shareState",oe="enterRoom",ie="useLicense",se="peerconnection:confirmed",ae="peerconnection:ontrack",ce="channels",de="channels:notify",he="ended:fromserver",Ee="main-cam-control",ue="admin-stop-main-cam",me="admin-start-main-cam",le="admin-stop-mic",pe="admin-start-mic",ge="admin-force-sync-media-state",_e="participant:added-to-list-moderators",Te="participant:removed-from-list-moderators",Ie="participant:move-request-to-stream",Se="participant:move-request-to-spectators",we="participant:move-request-to-participants",Ne="participation:accepting-word-request",Ce="participation:cancelling-word-request",Re="webcast:started",fe="webcast:stopped",Ae="account:changed",Me="account:deleted",Oe="conference:participant-token-issued",Pe="ended",ve="sending",De="reinvite",ye="replaces",Le="refer",Fe="progress",We="accepted",be="confirmed",ke="peerconnection",Ve="failed",Ue="muted",He="unmuted",qe="newDTMF",Ge="newInfo",xe="hold",ze="unhold",je="update",Ye="sdp",Be="icecandidate",Ke="getusermediafailed",Je="peerconnection:createofferfailed",$e="peerconnection:createanswerfailed",Qe="peerconnection:setlocaldescriptionfailed",Xe="peerconnection:setremotedescriptionfailed",Ze="presentation:start",et="presentation:started",tt="presentation:end",rt="presentation:ended",nt="presentation:failed",ot=[G,x,j,z,Ne,Ce,Ie,de,Oe,Ae,Me,Re,fe,_e,Te],L=[y,Y,B,K,J,$,Q,X,Z],it=[ee,te,re,ne,oe,ie,se,ae,ce,he,Ee,me,ue,le,pe,ge,Se,we],_=[Pe,y,ve,De,ye,Le,Fe,We,be,ke,Ve,Ue,He,qe,Ge,xe,ze,je,Ye,Be,Ke,Je,$e,Qe,Xe,Ze,et,tt,rt,nt];[...L,...ot];[..._,...it];class st{originator;connection;events;remote_identity;mutedOptions={audio:!1,video:!1};constructor({originator:e="local",eventHandlers:t,remoteIdentity:r}){this.originator=e,this.events=new S.Events(_),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 _.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 A{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 M{currentDirection="sendrecv";direction="sendrecv";mid=null;receiver;sender;stopped=!1;constructor(e){this.sender=e}setCodecPreferences(e){}stop(){}}const at=["track"];class ct{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;events;constructor(e,t){this.events=new S.Events(at),this.receivers=t.map(r=>({track:r}))}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,r){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,r){this.events.on(e,t)}removeEventListener(e,t,r){this.events.off(e,t)}dispatchEvent(e){throw new Error("Method not implemented.")}getReceivers=()=>this.receivers;getSenders=()=>this.senders;addTrack=(e,...t)=>{const r=new A({track:e}),n=new M(r);return n.mid=e.kind==="audio"?"0":"1",this.senders.push(r),this.events.trigger("track",{track:e,transceiver:n}),r};addTrackWithMid=(e,t)=>{const r=new A({track:e}),n=new M(r);return t===void 0?n.mid=e.kind==="audio"?"0":"1":n.mid=t,this.senders.push(r),this.events.trigger("track",{track:e,transceiver:n}),r}}function dt(o){const e=o.match(/(purgatory)|[\d.]+/g);if(!e)throw new Error("wrong sip url");return e[0]}const O=400,F="777",ht=o=>o.getVideoTracks().length>0;class s extends st{static presentationError;static startPresentationError;static countStartPresentationError=Number.POSITIVE_INFINITY;static countStartsPresentation=0;url;status_code;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)},O)});replaceMediaStream=jest.fn(async e=>{});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:n=0}){super({originator:t,eventHandlers:e,remoteIdentity:r}),this.delayStartPresentation=n}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=f.createAudioMediaStreamTrackMock();t.id="mainaudio1";const r=[t];if(ht(e)){const c=f.createVideoMediaStreamTrackMock();c.id="mainvideo1",r.push(c)}this.connection=new ct(void 0,r),this.addStream(e),this.trigger("peerconnection",{peerconnection:this.connection})}connect(e,{mediaStream:t}={}){const r=dt(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:n=>n==="content-type"?"application/vinteo.webrtc.roomname":n==="x-webrtc-enter-room"?r:n==="x-webrtc-participant-name"?"Test Caller 1":""}})},100),this.timeoutAccepted=setTimeout(()=>{this.trigger("accepted")},200),this.timeoutConfirmed=setTimeout(()=>{this.trigger("confirmed")},300))},O),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))}forEachSenders(e){const t=this.connection.getSenders();for(const r of t)e(r);return t}toggleMuteAudio(e){this.forEachSenders(({track:t})=>{t&&t.kind==="audio"&&(t.enabled=!e)})}toggleMuteVideo(e){this.forEachSenders(({track:t})=>{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 Et{extraHeaders=[];setExtraHeaders(e){this.extraHeaders=e}setExtraContactParams(){}}const d="PASSWORD_CORRECT",T="PASSWORD_CORRECT_2",W="NAME_INCORRECT",E=400,g={url:"wss://sipServerUrl/webrtc/wss/",sip_uri:"sip:sipServerUrl;transport=ws",via_transport:"WSS"},P={status_code:200,reason_phrase:"OK"},v={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:n}=t;return this.session=new s({eventHandlers:n,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 S.Events(L);const[t,r]=e.uri.split(":"),[n,c]=r.split("@"),p={...e,uri:new a.URI(t,n,c)};this.configuration=p,this.registratorInner=new Et}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:v,cause:a.C.causes.REJECTED})},E)):!this.isRegistered()&&t===!0&&(e===d||e===T)?(this.isRegisteredInner=!0,this.startedTimeout=setTimeout(()=>{this.trigger("registered",{response:P})},E)):t===!0&&e!==d&&e!==T&&(this.isRegisteredInner=!1,this.isConnectedInner=!1,this.startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:v,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:P})}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 ut{url;constructor(e){this.url=e}}class mt extends V.EventEmitter{contentType;body;constructor(e,t){super(),this.contentType=e,this.body=t}}const I="remote",lt=(o,e)=>{const t=new w(e),r={originator:I,request:t,info:new mt("","")};o.newInfo(r)},pt=(o,e)=>{const r={event:"sipEvent",request:new w(e)};o.newSipEvent(r)},gt=(o,{incomingNumber:e="1234",displayName:t,host:r})=>{const n=new s({originator:I,eventHandlers:{}}),c=new H("sip",e,r);n.remote_identity=new U(c,t);const p=new w([]);o.trigger("newRTCSession",{originator:I,session:n,request:p})},_t=(o,e)=>{e?o.trigger("failed",e):o.trigger("failed",o)},N={triggerNewInfo:lt,triggerNewSipEvent:pt,triggerIncomingSession:gt,triggerFailIncomingSession:_t,WebSocketInterface:ut,UA:i,C:{INVITE:"INVITE"}},u="user",h="displayName",m="SIP_SERVER_URL",C="SIP_WEB_SOCKET_SERVER_URL",Tt=new N.WebSocketInterface(C),R={userAgent:"Chrome",sipServerUrl:m,sipWebSocketServerURL:C},It={...R},b={...R,user:u,password:d,register:!0},St={...b,displayName:h},wt={...R,displayName:h,register:!1},l={session_timers:!1,sockets:[Tt],user_agent:"Chrome",sdpSemantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},Nt={...l,password:d,uri:new a.URI("sip",u,m),display_name:"",register:!0},Ct={...l,password:d,uri:new a.URI("sip",u,m),display_name:h,register:!0},Rt={...l,display_name:h,register:!1},ft={...l,display_name:"",register:!1},k="10.10.10.10",At=[`X-Vinteo-Remote: ${k}`],Mt=()=>new D.SipConnector({JsSIP:N});exports.FAILED_CONFERENCE_NUMBER=F;exports.JsSIP=N;exports.NAME_INCORRECT=W;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=T;exports.SIP_SERVER_URL=m;exports.SIP_WEB_SOCKET_SERVER_URL=C;exports.dataForConnectionWithAuthorization=b;exports.dataForConnectionWithAuthorizationWithDisplayName=St;exports.dataForConnectionWithoutAuthorization=wt;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=It;exports.displayName=h;exports.doMockSipConnector=Mt;exports.extraHeadersRemoteAddress=At;exports.remoteAddress=k;exports.uaConfigurationWithAuthorization=Nt;exports.uaConfigurationWithAuthorizationWithDisplayName=Ct;exports.uaConfigurationWithoutAuthorization=Rt;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ft;exports.user=u;
|
package/dist/doMock.js
CHANGED
|
@@ -5,7 +5,7 @@ import { IncomingRequest as k } from "@krivega/jssip/lib/SIPMessage";
|
|
|
5
5
|
import { NameAddrHeader as V, URI as E, C as N } from "@krivega/jssip";
|
|
6
6
|
import { createAudioMediaStreamTrackMock as W, createVideoMediaStreamTrackMock as U } from "webrtc-mock";
|
|
7
7
|
import { Events as T } from "events-constructor";
|
|
8
|
-
import { O as G, S as H } from "./@SipConnector-
|
|
8
|
+
import { O as G, S as H } from "./@SipConnector-Wp8bjnnP.js";
|
|
9
9
|
class _ extends k {
|
|
10
10
|
headers;
|
|
11
11
|
constructor(e) {
|