sip-connector 7.0.5 → 7.0.7
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/dist/SipConnector-BHUjGzwS.cjs +1 -0
- package/dist/{SipConnector-CxSB1Bmp.js → SipConnector-DE2T85rT.js} +367 -331
- package/dist/SipConnector.d.ts +10 -19
- package/dist/__fixtures__/Session.mock.d.ts +3 -0
- package/dist/__fixtures__/UA.mock.d.ts +19 -0
- package/dist/doMock.cjs +1 -1
- package/dist/doMock.js +78 -62
- package/dist/index.cjs +1 -1
- package/dist/index.js +97 -96
- package/dist/types.d.ts +15 -0
- package/dist/utils/errors.d.ts +1 -0
- package/package.json +27 -25
- package/dist/SipConnector-DxGNVRHG.cjs +0 -1
package/dist/SipConnector.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IncomingInfoEvent, IncomingRTCSessionEvent, IncomingRequest, OutgoingInfoEvent, RTCSession, RegisteredEvent, UA, URI, UnRegisteredEvent, WebSocketInterface } from '@krivega/jssip';
|
|
1
|
+
import { IncomingInfoEvent, IncomingRTCSessionEvent, IncomingRequest, OutgoingInfoEvent, RTCSession, RegisteredEvent, UA, UAConfigurationParams, URI, UnRegisteredEvent, WebSocketInterface } from '@krivega/jssip';
|
|
2
2
|
import { TEventSession, TEventUA } from './eventNames';
|
|
3
3
|
import { TCustomError, TJsSIP } from './types';
|
|
4
4
|
|
|
@@ -75,7 +75,6 @@ type TOptionsExtraHeaders = {
|
|
|
75
75
|
extraHeaders?: string[];
|
|
76
76
|
};
|
|
77
77
|
type TOntrack = (track: RTCTrackEvent) => void;
|
|
78
|
-
type TGetServerUrl = (id: string) => string;
|
|
79
78
|
type TParametersConnection = TOptionsExtraHeaders & {
|
|
80
79
|
displayName?: string;
|
|
81
80
|
user?: string;
|
|
@@ -91,20 +90,6 @@ type TParametersConnection = TOptionsExtraHeaders & {
|
|
|
91
90
|
connectionRecoveryMaxInterval?: number;
|
|
92
91
|
userAgent?: string;
|
|
93
92
|
};
|
|
94
|
-
type TParametersCreateUa = {
|
|
95
|
-
socket: WebSocketInterface;
|
|
96
|
-
displayName: string;
|
|
97
|
-
getSipServerUrl: TGetServerUrl;
|
|
98
|
-
user?: string;
|
|
99
|
-
register?: boolean;
|
|
100
|
-
password?: string;
|
|
101
|
-
sdpSemantics?: 'plan-b' | 'unified-plan';
|
|
102
|
-
sessionTimers?: boolean;
|
|
103
|
-
registerExpires?: number;
|
|
104
|
-
connectionRecoveryMinInterval?: number;
|
|
105
|
-
connectionRecoveryMaxInterval?: number;
|
|
106
|
-
userAgent?: string;
|
|
107
|
-
};
|
|
108
93
|
type TParametersCheckTelephony = {
|
|
109
94
|
displayName: string;
|
|
110
95
|
sipServerUrl: string;
|
|
@@ -112,9 +97,11 @@ type TParametersCheckTelephony = {
|
|
|
112
97
|
sdpSemantics?: 'plan-b' | 'unified-plan';
|
|
113
98
|
userAgent?: string;
|
|
114
99
|
};
|
|
115
|
-
type TConnect = (parameters: TParametersConnection
|
|
100
|
+
type TConnect = (parameters: TParametersConnection, options?: {
|
|
101
|
+
callLimit?: number;
|
|
102
|
+
}) => Promise<UA>;
|
|
116
103
|
type TInitUa = (parameters: TParametersConnection) => Promise<UA>;
|
|
117
|
-
type TCreateUa = (parameters:
|
|
104
|
+
type TCreateUa = (parameters: UAConfigurationParams) => UA;
|
|
118
105
|
type TStart = () => Promise<UA>;
|
|
119
106
|
type TSet = ({ displayName, password, }: {
|
|
120
107
|
displayName?: string;
|
|
@@ -154,6 +141,7 @@ export default class SipConnector {
|
|
|
154
141
|
private readonly _sessionEvents;
|
|
155
142
|
private readonly _uaEvents;
|
|
156
143
|
private readonly _cancelableConnect;
|
|
144
|
+
private _cancelableConnectWithRepeatedCalls;
|
|
157
145
|
private readonly _cancelableInitUa;
|
|
158
146
|
private readonly _cancelableDisconnect;
|
|
159
147
|
private readonly _cancelableSet;
|
|
@@ -198,6 +186,9 @@ export default class SipConnector {
|
|
|
198
186
|
removeIncomingSession: () => void;
|
|
199
187
|
askPermissionToEnableCam(options?: TOptionsInfoMediaState): Promise<void>;
|
|
200
188
|
get isPendingPresentation(): boolean;
|
|
189
|
+
private readonly _connectWithDuplicatedCalls;
|
|
190
|
+
private hasEqualConnectionConfiguration;
|
|
191
|
+
private createUaConfiguration;
|
|
201
192
|
private _sendPresentation;
|
|
202
193
|
startPresentation(stream: MediaStream, { isNeedReinvite, isP2P, maxBitrate, degradationPreference, }?: {
|
|
203
194
|
isNeedReinvite?: boolean;
|
|
@@ -270,7 +261,7 @@ export default class SipConnector {
|
|
|
270
261
|
_generateAudioStreams(remoteTracks: MediaStreamTrack[]): MediaStream[];
|
|
271
262
|
_hangUpWithoutCancelRequests: THangUp;
|
|
272
263
|
_cancelRequests(): void;
|
|
273
|
-
|
|
264
|
+
_cancelConnectWithRepeatedCalls(): void;
|
|
274
265
|
_cancelCallRequests(): void;
|
|
275
266
|
_cancelActionsRequests(): void;
|
|
276
267
|
_handleShareState: (eventName: string) => void;
|
|
@@ -28,6 +28,9 @@ declare class Session extends BaseSession {
|
|
|
28
28
|
terminate({ status_code }?: {
|
|
29
29
|
status_code?: number;
|
|
30
30
|
}): this;
|
|
31
|
+
terminateAsync({ status_code }?: {
|
|
32
|
+
status_code?: number;
|
|
33
|
+
}): Promise<void>;
|
|
31
34
|
terminateRemote({ status_code }?: {
|
|
32
35
|
status_code?: number;
|
|
33
36
|
}): this;
|
|
@@ -7,8 +7,26 @@ import { default as Session } from './Session.mock';
|
|
|
7
7
|
export declare const PASSWORD_CORRECT = "PASSWORD_CORRECT";
|
|
8
8
|
export declare const PASSWORD_CORRECT_2 = "PASSWORD_CORRECT_2";
|
|
9
9
|
export declare const NAME_INCORRECT = "NAME_INCORRECT";
|
|
10
|
+
export declare const createWebsocketHandshakeTimeoutError: (sipServerUrl: string) => {
|
|
11
|
+
socket: {
|
|
12
|
+
_url: string;
|
|
13
|
+
_sip_uri: string;
|
|
14
|
+
_via_transport: string;
|
|
15
|
+
_ws: null;
|
|
16
|
+
};
|
|
17
|
+
error: boolean;
|
|
18
|
+
code: number;
|
|
19
|
+
reason: string;
|
|
20
|
+
};
|
|
10
21
|
declare class UA implements IUA {
|
|
11
22
|
private static isAvailableTelephony;
|
|
23
|
+
private static startError?;
|
|
24
|
+
private static countStartError;
|
|
25
|
+
private static countStarts;
|
|
26
|
+
static setStartError(startError: unknown, { count }?: {
|
|
27
|
+
count?: number;
|
|
28
|
+
}): void;
|
|
29
|
+
static resetStartError(): void;
|
|
12
30
|
static setAvailableTelephony(): void;
|
|
13
31
|
static setNotAvailableTelephony(): void;
|
|
14
32
|
_events: Events<typeof UA_EVENT_NAMES>;
|
|
@@ -20,6 +38,7 @@ declare class UA implements IUA {
|
|
|
20
38
|
configuration: UAConfiguration;
|
|
21
39
|
_registrator: Registrator;
|
|
22
40
|
constructor(_configuration: UAConfigurationParams);
|
|
41
|
+
isConnected(): boolean;
|
|
23
42
|
/**
|
|
24
43
|
* start
|
|
25
44
|
*
|
package/dist/doMock.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var k=Object.defineProperty;var D=(o,t,e)=>t in o?k(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var r=(o,t,e)=>(D(o,typeof t!="symbol"?t+"":t,e),e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const u=require("./SipConnector-DxGNVRHG.cjs"),b=require("@krivega/jssip/lib/NameAddrHeader"),L=require("@krivega/jssip/lib/URI"),P=require("node:events"),F=require("@krivega/jssip/lib/SIPMessage"),C=require("webrtc-mock"),T=require("events-constructor"),M=require("@krivega/jssip");class S extends F.IncomingRequest{constructor(e){super();r(this,"headers");this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)||""}}class U{constructor({originator:t="local",eventHandlers:e}){r(this,"originator");r(this,"_connection");r(this,"_events");r(this,"_remote_identity");r(this,"_mutedOptions",{audio:!1,video:!1});this.originator=t,this._events=new T(u.SESSION_EVENT_NAMES),this.initEvents(e)}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}set data(t){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}get connection(){return this._connection}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get remote_identity(){return this._remote_identity}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(t){throw new Error("Method not implemented.")}terminate(t){throw new Error("Method not implemented.")}async sendInfo(t,e,n){throw new Error("Method not implemented.")}hold(t,e){throw new Error("Method not implemented.")}unhold(t,e){throw new Error("Method not implemented.")}async renegotiate(t,e){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(t){throw new Error("Method not implemented.")}unmute(t){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(t,e){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(t,e){throw new Error("Method not implemented.")}addListener(t,e){throw new Error("Method not implemented.")}once(t,e){throw new Error("Method not implemented.")}removeListener(t,e){throw new Error("Method not implemented.")}off(t,e){throw new Error("Method not implemented.")}removeAllListeners(t){throw new Error("Method not implemented.")}setMaxListeners(t){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(t){throw new Error("Method not implemented.")}rawListeners(t){throw new Error("Method not implemented.")}emit(t,...e){throw new Error("Method not implemented.")}listenerCount(t){throw new Error("Method not implemented.")}prependListener(t,e){throw new Error("Method not implemented.")}prependOnceListener(t,e){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(t=[]){Object.entries(t).forEach(([e,n])=>this.on(e,n))}on(t,e){return this._events.on(t,e),this}trigger(t,e){this._events.trigger(t,e)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(t){return t}async updatePresentation(t){return t}async stopPresentation(t){return t}isEstablished(){return!0}}class V{constructor(t,e){r(this,"_senders",[]);r(this,"_receivers",[]);r(this,"canTrickleIceCandidates");r(this,"connectionState");r(this,"currentLocalDescription");r(this,"currentRemoteDescription");r(this,"iceConnectionState");r(this,"iceGatheringState");r(this,"idpErrorInfo");r(this,"idpLoginUrl");r(this,"localDescription");r(this,"onconnectionstatechange");r(this,"ondatachannel");r(this,"onicecandidate");r(this,"onicecandidateerror",null);r(this,"oniceconnectionstatechange");r(this,"onicegatheringstatechange");r(this,"onnegotiationneeded");r(this,"onsignalingstatechange");r(this,"ontrack");r(this,"peerIdentity");r(this,"pendingLocalDescription");r(this,"pendingRemoteDescription");r(this,"remoteDescription");r(this,"sctp",null);r(this,"signalingState");r(this,"getReceivers",()=>this._receivers);r(this,"getSenders",()=>this._senders);r(this,"addTrack",t=>{const e={track:t};return this._senders.push(e),e});this._receivers=e.map(n=>({track:n}))}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(t){throw new Error("Method not implemented.")}addTransceiver(t,e){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(t,e){throw new Error("Method not implemented.")}createDataChannel(t,e){throw new Error("Method not implemented.")}async createOffer(t,e,n){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(t){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(t){throw new Error("Method not implemented.")}setConfiguration(t){throw new Error("Method not implemented.")}async setLocalDescription(t){throw new Error("Method not implemented.")}async setRemoteDescription(t){throw new Error("Method not implemented.")}addEventListener(t,e,n){throw new Error("Method not implemented.")}removeEventListener(t,e,n){throw new Error("Method not implemented.")}dispatchEvent(t){throw new Error("Method not implemented.")}}function z(o){const t=o.match(/(purgatory)|[\d.]+/g);if(!t)throw new Error("wrong sip url");return t[0]}const p=400,y="777",q=o=>o.getVideoTracks().length>0;class A extends U{constructor({url:e="",mediaStream:n,eventHandlers:i,originator:s}){super({originator:s,eventHandlers:i});r(this,"url");r(this,"status_code");r(this,"_isEnded",!1);r(this,"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)},p)}));this.url=e,this.initPeerconnection(n)}initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const n=C.createAudioMediaStreamTrackMock();n.id="mainaudio1";const i=[n];if(q(e)){const c=C.createVideoMediaStreamTrackMock();c.id="mainvideo1",i.push(c)}this._connection=new V(void 0,i),this._addStream(e),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},p)}connect(e){const n=z(e);setTimeout(()=>{this.url.includes(y)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:u.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",{room:n})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},p)}terminate({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e}),this._isEnded=!1,this}terminateRemote({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e,originator:"remote"}),this}_addStream(e,n="getTracks"){e[n]().forEach(i=>this.connection.addTrack(i))}_forEachSenders(e){const n=this.connection.getSenders();for(const i of n)e(i);return n}_toggleMuteAudio(e){this._forEachSenders(({track:n})=>{n&&n.kind==="audio"&&(n.enabled=!e)})}_toggleMuteVideo(e){this._forEachSenders(({track:n})=>{n&&n.kind==="video"&&(n.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}async replaceMediaStream(e){return e}_onmute({audio:e,video:n}){this.trigger("muted",{audio:e,video:n})}async sendInfo(){}isEnded(){return this._isEnded}newInfo(e){this.trigger("newInfo",e)}}class x{constructor(){r(this,"extraHeaders")}setExtraHeaders(t){this.extraHeaders=t}setExtraContactParams(){}}const a="PASSWORD_CORRECT",w="PASSWORD_CORRECT_2",I="NAME_INCORRECT",h=400,m=class m{constructor(t){r(this,"_events");r(this,"_startedTimeout");r(this,"_stopedTimeout");r(this,"session");r(this,"_isRegistered");r(this,"_isConnected");r(this,"configuration");r(this,"_registrator");r(this,"call",jest.fn((t,e)=>{const{mediaStream:n,eventHandlers:i}=e;return this.session=new A({url:t,mediaStream:n,eventHandlers:i,originator:"local"}),this.session.connect(t),this.session}));this._events=new T(u.UA_EVENT_NAMES);const[e,n]=t.uri.split(":"),[i,s]=n.split("@"),c={...t,uri:new M.URI(e,i,s)};this.configuration=c,this._registrator=new x}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}start(){this.register()}stop(){this._startedTimeout&&clearTimeout(this._startedTimeout),this._stopedTimeout&&clearTimeout(this._stopedTimeout),this.unregister(),this.isStarted()?this._stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:new Error("stoped")})},h):this.trigger("disconnected",{error:new Error("stoped")})}on(t,e){return this._events.on(t,e),this}once(t,e){return this._events.once(t,e),this}off(t,e){return this._events.off(t,e),this}removeAllListeners(){return this._events.removeEventHandlers(),this}trigger(t,e){this._events.trigger(t,e)}terminateSessions(){this.session.terminate()}set(t,e){return this.configuration[t]=e,!0}register(){this._startedTimeout&&clearTimeout(this._startedTimeout);const{password:t,register:e,uri:n}=this.configuration;e&&n.user.includes(I)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},h)):!this._isRegistered&&e&&(t===a||t===w)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},h)):e&&t!==a&&t!==w&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},h)),m.isAvailableTelephony?(this.trigger("connected"),this._isConnected=!0):this.stop()}unregister(){this._isRegistered=!1,this._isConnected=!1,this.trigger("unregistered")}isRegistered(){return!!this._isRegistered}isStarted(){return this.configuration&&(this.configuration.register&&!!this._isRegistered||!this.configuration.register&&!!this._isConnected)}registrator(){return this._registrator}newSipEvent(t){this.trigger("sipEvent",t)}};r(m,"isAvailableTelephony",!0);let E=m;class H{constructor(t){r(this,"url");this.url=t}}class j extends P.EventEmitter{constructor(e,n){super();r(this,"contentType");r(this,"body");this.contentType=e,this.body=n}}const f="remote",B=(o,t)=>{const e=new S(t),n={originator:f,request:e,info:new j("","")};o.newInfo(n)},K=(o,t)=>{const n={request:new S(t)};o.newSipEvent(n)},$=(o,{incomingNumber:t="1234",displayName:e,host:n})=>{const i=new A({originator:f}),s=new L("sip",t,n);i._remote_identity=new b(s,e),o.trigger("newRTCSession",{originator:f,session:i})},J=(o,t)=>{t?o.trigger("failed",t):o.trigger("failed",o)},N={triggerNewInfo:B,triggerNewSipEvent:K,triggerIncomingSession:$,triggerFailIncomingSession:J,WebSocketInterface:H,UA:E,C:{INVITE:"INVITE"}},l="user",d="displayName",g="SIP_SERVER_URL",R="SIP_WEB_SOCKET_SERVER_URL",Y=new N.WebSocketInterface(R),v={userAgent:"Chrome",sipServerUrl:g,sipWebSocketServerURL:R},G={...v},O={...v,user:l,password:a,register:!0},X={...O,displayName:d},Q={...v,displayName:d,register:!1},_={session_timers:!1,sockets:[Y],user_agent:"Chrome",sdp_semantics:"plan-b",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},Z={..._,password:a,uri:new M.URI("sip",l,g),display_name:"",register:!0},ee={..._,password:a,uri:new M.URI("sip",l,g),display_name:d,register:!0},te={..._,display_name:d,register:!1},re={..._,display_name:"",register:!1},W="10.10.10.10",ne=[`X-Vinteo-Remote: ${W}`],oe=()=>new u.SipConnector({JsSIP:N});exports.FAILED_CONFERENCE_NUMBER=y;exports.NAME_INCORRECT=I;exports.PASSWORD_CORRECT=a;exports.PASSWORD_CORRECT_2=w;exports.SIP_SERVER_URL=g;exports.SIP_WEB_SOCKET_SERVER_URL=R;exports.dataForConnectionWithAuthorization=O;exports.dataForConnectionWithAuthorizationWithDisplayName=X;exports.dataForConnectionWithoutAuthorization=Q;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=G;exports.default=oe;exports.displayName=d;exports.extraHeadersRemoteAddress=ne;exports.remoteAddress=W;exports.uaConfigurationWithAuthorization=Z;exports.uaConfigurationWithAuthorizationWithDisplayName=ee;exports.uaConfigurationWithoutAuthorization=te;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=re;exports.user=l;
|
|
1
|
+
"use strict";var b=Object.defineProperty;var k=(o,t,e)=>t in o?b(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var r=(o,t,e)=>k(o,typeof t!="symbol"?t+"":t,e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("./SipConnector-BHUjGzwS.cjs"),D=require("@krivega/jssip/lib/NameAddrHeader"),P=require("@krivega/jssip/lib/URI"),L=require("node:events"),F=require("@krivega/jssip/lib/SIPMessage"),T=require("webrtc-mock"),v=require("events-constructor"),M=require("@krivega/jssip");class C extends F.IncomingRequest{constructor(e){super();r(this,"headers");this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)||""}}class V{constructor({originator:t="local",eventHandlers:e}){r(this,"originator");r(this,"_connection");r(this,"_events");r(this,"_remote_identity");r(this,"_mutedOptions",{audio:!1,video:!1});this.originator=t,this._events=new v(m.SESSION_EVENT_NAMES),this.initEvents(e)}get C(){throw new Error("Method not implemented.")}get causes(){throw new Error("Method not implemented.")}get id(){throw new Error("Method not implemented.")}set data(t){throw new Error("Method not implemented.")}get data(){throw new Error("Method not implemented.")}get connection(){return this._connection}get contact(){throw new Error("Method not implemented.")}get direction(){throw new Error("Method not implemented.")}get local_identity(){throw new Error("Method not implemented.")}get remote_identity(){return this._remote_identity}get start_time(){throw new Error("Method not implemented.")}get end_time(){throw new Error("Method not implemented.")}get status(){throw new Error("Method not implemented.")}isInProgress(){throw new Error("Method not implemented.")}isEnded(){throw new Error("Method not implemented.")}isReadyToReOffer(){throw new Error("Method not implemented.")}answer(t){throw new Error("Method not implemented.")}terminate(t){throw new Error("Method not implemented.")}async sendInfo(t,e,n){throw new Error("Method not implemented.")}hold(t,e){throw new Error("Method not implemented.")}unhold(t,e){throw new Error("Method not implemented.")}async renegotiate(t,e){throw new Error("Method not implemented.")}isOnHold(){throw new Error("Method not implemented.")}mute(t){throw new Error("Method not implemented.")}unmute(t){throw new Error("Method not implemented.")}isMuted(){throw new Error("Method not implemented.")}refer(t,e){throw new Error("Method not implemented.")}resetLocalMedia(){throw new Error("Method not implemented.")}async replaceMediaStream(t,e){throw new Error("Method not implemented.")}addListener(t,e){throw new Error("Method not implemented.")}once(t,e){throw new Error("Method not implemented.")}removeListener(t,e){throw new Error("Method not implemented.")}off(t,e){throw new Error("Method not implemented.")}removeAllListeners(t){throw new Error("Method not implemented.")}setMaxListeners(t){throw new Error("Method not implemented.")}getMaxListeners(){throw new Error("Method not implemented.")}listeners(t){throw new Error("Method not implemented.")}rawListeners(t){throw new Error("Method not implemented.")}emit(t,...e){throw new Error("Method not implemented.")}listenerCount(t){throw new Error("Method not implemented.")}prependListener(t,e){throw new Error("Method not implemented.")}prependOnceListener(t,e){throw new Error("Method not implemented.")}eventNames(){throw new Error("Method not implemented.")}initEvents(t=[]){Object.entries(t).forEach(([e,n])=>this.on(e,n))}on(t,e){return this._events.on(t,e),this}trigger(t,e){this._events.trigger(t,e)}sendDTMF(){this.trigger("newDTMF",{originator:this.originator})}async startPresentation(t){return t}async updatePresentation(t){return t}async stopPresentation(t){return t}isEstablished(){return!0}}class z{constructor(t,e){r(this,"_senders",[]);r(this,"_receivers",[]);r(this,"canTrickleIceCandidates");r(this,"connectionState");r(this,"currentLocalDescription");r(this,"currentRemoteDescription");r(this,"iceConnectionState");r(this,"iceGatheringState");r(this,"idpErrorInfo");r(this,"idpLoginUrl");r(this,"localDescription");r(this,"onconnectionstatechange");r(this,"ondatachannel");r(this,"onicecandidate");r(this,"onicecandidateerror",null);r(this,"oniceconnectionstatechange");r(this,"onicegatheringstatechange");r(this,"onnegotiationneeded");r(this,"onsignalingstatechange");r(this,"ontrack");r(this,"peerIdentity");r(this,"pendingLocalDescription");r(this,"pendingRemoteDescription");r(this,"remoteDescription");r(this,"sctp",null);r(this,"signalingState");r(this,"getReceivers",()=>this._receivers);r(this,"getSenders",()=>this._senders);r(this,"addTrack",t=>{const e={track:t};return this._senders.push(e),e});this._receivers=e.map(n=>({track:n}))}getRemoteStreams(){throw new Error("Method not implemented.")}async addIceCandidate(t){throw new Error("Method not implemented.")}addTransceiver(t,e){throw new Error("Method not implemented.")}close(){throw new Error("Method not implemented.")}restartIce(){throw new Error("Method not implemented.")}async createAnswer(t,e){throw new Error("Method not implemented.")}createDataChannel(t,e){throw new Error("Method not implemented.")}async createOffer(t,e,n){throw new Error("Method not implemented.")}getConfiguration(){throw new Error("Method not implemented.")}async getIdentityAssertion(){throw new Error("Method not implemented.")}async getStats(t){throw new Error("Method not implemented.")}getTransceivers(){throw new Error("Method not implemented.")}removeTrack(t){throw new Error("Method not implemented.")}setConfiguration(t){throw new Error("Method not implemented.")}async setLocalDescription(t){throw new Error("Method not implemented.")}async setRemoteDescription(t){throw new Error("Method not implemented.")}addEventListener(t,e,n){throw new Error("Method not implemented.")}removeEventListener(t,e,n){throw new Error("Method not implemented.")}dispatchEvent(t){throw new Error("Method not implemented.")}}function U(o){const t=o.match(/(purgatory)|[\d.]+/g);if(!t)throw new Error("wrong sip url");return t[0]}const p=400,I="777",q=o=>o.getVideoTracks().length>0;class y extends V{constructor({url:e="",mediaStream:n,eventHandlers:i,originator:a}){super({originator:a,eventHandlers:i});r(this,"url");r(this,"status_code");r(this,"_isEnded",!1);r(this,"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)},p)}));this.url=e,this.initPeerconnection(n)}initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const n=T.createAudioMediaStreamTrackMock();n.id="mainaudio1";const i=[n];if(q(e)){const h=T.createVideoMediaStreamTrackMock();h.id="mainvideo1",i.push(h)}this._connection=new z(void 0,i),this._addStream(e),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},p)}connect(e){const n=U(e);setTimeout(()=>{this.url.includes(I)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:m.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",{room:n})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},p)}terminate({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e}),this._isEnded=!1,this}async terminateAsync({status_code:e}={}){this.terminate({status_code:e})}terminateRemote({status_code:e}={}){return this.status_code=e,this.trigger("ended",{status_code:e,originator:"remote"}),this}_addStream(e,n="getTracks"){e[n]().forEach(i=>this.connection.addTrack(i))}_forEachSenders(e){const n=this.connection.getSenders();for(const i of n)e(i);return n}_toggleMuteAudio(e){this._forEachSenders(({track:n})=>{n&&n.kind==="audio"&&(n.enabled=!e)})}_toggleMuteVideo(e){this._forEachSenders(({track:n})=>{n&&n.kind==="video"&&(n.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}async replaceMediaStream(e){return e}_onmute({audio:e,video:n}){this.trigger("muted",{audio:e,video:n})}async sendInfo(){}isEnded(){return this._isEnded}newInfo(e){this.trigger("newInfo",e)}}class x{constructor(){r(this,"extraHeaders")}setExtraHeaders(t){this.extraHeaders=t}setExtraContactParams(){}}const d="PASSWORD_CORRECT",w="PASSWORD_CORRECT_2",N="NAME_INCORRECT",u=400,s=class s{constructor(t){r(this,"_events");r(this,"_startedTimeout");r(this,"_stopedTimeout");r(this,"session");r(this,"_isRegistered");r(this,"_isConnected");r(this,"configuration");r(this,"_registrator");r(this,"call",jest.fn((t,e)=>{const{mediaStream:n,eventHandlers:i}=e;return this.session=new y({url:t,mediaStream:n,eventHandlers:i,originator:"local"}),this.session.connect(t),this.session}));this._events=new v(m.UA_EVENT_NAMES);const[e,n]=t.uri.split(":"),[i,a]=n.split("@"),h={...t,uri:new M.URI(e,i,a)};this.configuration=h,this._registrator=new x}static setStartError(t,{count:e=Number.POSITIVE_INFINITY}={}){this.startError=t,this.countStartError=e}static resetStartError(){this.startError=void 0,this.countStartError=Number.POSITIVE_INFINITY,this.countStarts=0}static setAvailableTelephony(){this.isAvailableTelephony=!0}static setNotAvailableTelephony(){this.isAvailableTelephony=!1}isConnected(){return!!this._isConnected}start(){if(s.countStarts+=1,s.startError&&s.countStarts<s.countStartError){this.trigger("disconnected",[s.startError]);return}this.register()}stop(){this._startedTimeout&&clearTimeout(this._startedTimeout),this._stopedTimeout&&clearTimeout(this._stopedTimeout),this.unregister(),this.isStarted()?this._stopedTimeout=setTimeout(()=>{this.trigger("disconnected",{error:new Error("stoped")})},u):this.trigger("disconnected",{error:new Error("stoped")})}on(t,e){return this._events.on(t,e),this}once(t,e){return this._events.once(t,e),this}off(t,e){return this._events.off(t,e),this}removeAllListeners(){return this._events.removeEventHandlers(),this}trigger(t,e){this._events.trigger(t,e)}terminateSessions(){this.session.terminate()}set(t,e){return this.configuration[t]=e,!0}register(){this._startedTimeout&&clearTimeout(this._startedTimeout);const{password:t,register:e,uri:n}=this.configuration;e&&n.user.includes(N)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},u)):!this._isRegistered&&e&&(t===d||t===w)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},u)):e&&t!==d&&t!==w&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},u)),s.isAvailableTelephony?(this.trigger("connected"),this._isConnected=!0):this.stop()}unregister(){this._isRegistered=!1,this._isConnected=!1,this.trigger("unregistered")}isRegistered(){return!!this._isRegistered}isStarted(){return this.configuration&&(this.configuration.register&&!!this._isRegistered||!this.configuration.register&&!!this._isConnected)}registrator(){return this._registrator}newSipEvent(t){this.trigger("sipEvent",t)}};r(s,"isAvailableTelephony",!0),r(s,"startError"),r(s,"countStartError",Number.POSITIVE_INFINITY),r(s,"countStarts",0);let E=s;class H{constructor(t){r(this,"url");this.url=t}}class j extends L.EventEmitter{constructor(e,n){super();r(this,"contentType");r(this,"body");this.contentType=e,this.body=n}}const f="remote",B=(o,t)=>{const e=new C(t),n={originator:f,request:e,info:new j("","")};o.newInfo(n)},Y=(o,t)=>{const n={request:new C(t)};o.newSipEvent(n)},K=(o,{incomingNumber:t="1234",displayName:e,host:n})=>{const i=new y({originator:f}),a=new P("sip",t,n);i._remote_identity=new D(a,e),o.trigger("newRTCSession",{originator:f,session:i})},$=(o,t)=>{t?o.trigger("failed",t):o.trigger("failed",o)},A={triggerNewInfo:B,triggerNewSipEvent:Y,triggerIncomingSession:K,triggerFailIncomingSession:$,WebSocketInterface:H,UA:E,C:{INVITE:"INVITE"}},l="user",c="displayName",g="SIP_SERVER_URL",S="SIP_WEB_SOCKET_SERVER_URL",J=new A.WebSocketInterface(S),R={userAgent:"Chrome",sipServerUrl:g,sipWebSocketServerURL:S},G={...R},O={...R,user:l,password:d,register:!0},X={...O,displayName:c},Q={...R,displayName:c,register:!1},_={session_timers:!1,sockets:[J],user_agent:"Chrome",sdp_semantics:"plan-b",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},Z={..._,password:d,uri:new M.URI("sip",l,g),display_name:"",register:!0},ee={..._,password:d,uri:new M.URI("sip",l,g),display_name:c,register:!0},te={..._,display_name:c,register:!1},re={..._,display_name:"",register:!1},W="10.10.10.10",ne=[`X-Vinteo-Remote: ${W}`],oe=()=>new m.SipConnector({JsSIP:A});exports.FAILED_CONFERENCE_NUMBER=I;exports.NAME_INCORRECT=N;exports.PASSWORD_CORRECT=d;exports.PASSWORD_CORRECT_2=w;exports.SIP_SERVER_URL=g;exports.SIP_WEB_SOCKET_SERVER_URL=S;exports.dataForConnectionWithAuthorization=O;exports.dataForConnectionWithAuthorizationWithDisplayName=X;exports.dataForConnectionWithoutAuthorization=Q;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=G;exports.default=oe;exports.displayName=c;exports.extraHeadersRemoteAddress=ne;exports.remoteAddress=W;exports.uaConfigurationWithAuthorization=Z;exports.uaConfigurationWithAuthorizationWithDisplayName=ee;exports.uaConfigurationWithoutAuthorization=te;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=re;exports.user=l;
|
package/dist/doMock.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var r = (o, t, e) => (
|
|
4
|
-
import { j as
|
|
1
|
+
var I = Object.defineProperty;
|
|
2
|
+
var y = (o, t, e) => t in o ? I(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
|
+
var r = (o, t, e) => y(o, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { j as N, R as O, U as A, S as k } from "./SipConnector-DE2T85rT.js";
|
|
5
5
|
import b from "@krivega/jssip/lib/NameAddrHeader";
|
|
6
6
|
import D from "@krivega/jssip/lib/URI";
|
|
7
7
|
import { EventEmitter as L } from "node:events";
|
|
8
|
-
import { IncomingRequest as
|
|
9
|
-
import { createAudioMediaStreamTrackMock as
|
|
8
|
+
import { IncomingRequest as P } from "@krivega/jssip/lib/SIPMessage";
|
|
9
|
+
import { createAudioMediaStreamTrackMock as W, createVideoMediaStreamTrackMock as V } from "webrtc-mock";
|
|
10
10
|
import v from "events-constructor";
|
|
11
11
|
import { URI as p } from "@krivega/jssip";
|
|
12
|
-
class T extends
|
|
12
|
+
class T extends P {
|
|
13
13
|
constructor(e) {
|
|
14
14
|
super();
|
|
15
15
|
r(this, "headers");
|
|
@@ -19,7 +19,7 @@ class T extends W {
|
|
|
19
19
|
return this.headers.get(e) || "";
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
class
|
|
22
|
+
class F {
|
|
23
23
|
// @ts-expect-error
|
|
24
24
|
constructor({ originator: t = "local", eventHandlers: e }) {
|
|
25
25
|
r(this, "originator");
|
|
@@ -27,7 +27,7 @@ class U {
|
|
|
27
27
|
r(this, "_events");
|
|
28
28
|
r(this, "_remote_identity");
|
|
29
29
|
r(this, "_mutedOptions", { audio: !1, video: !1 });
|
|
30
|
-
this.originator = t, this._events = new v(
|
|
30
|
+
this.originator = t, this._events = new v(N), this.initEvents(e);
|
|
31
31
|
}
|
|
32
32
|
// @ts-expect-error
|
|
33
33
|
get C() {
|
|
@@ -294,21 +294,21 @@ class x {
|
|
|
294
294
|
throw new Error("Method not implemented.");
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
|
-
function
|
|
297
|
+
function U(o) {
|
|
298
298
|
const t = o.match(/(purgatory)|[\d.]+/g);
|
|
299
299
|
if (!t)
|
|
300
300
|
throw new Error("wrong sip url");
|
|
301
301
|
return t[0];
|
|
302
302
|
}
|
|
303
|
-
const
|
|
304
|
-
class
|
|
303
|
+
const l = 400, H = "777", z = (o) => o.getVideoTracks().length > 0;
|
|
304
|
+
class S extends F {
|
|
305
305
|
constructor({
|
|
306
306
|
url: e = "",
|
|
307
307
|
mediaStream: n,
|
|
308
308
|
eventHandlers: i,
|
|
309
|
-
originator:
|
|
309
|
+
originator: a
|
|
310
310
|
}) {
|
|
311
|
-
super({ originator:
|
|
311
|
+
super({ originator: a, eventHandlers: i });
|
|
312
312
|
r(this, "url");
|
|
313
313
|
r(this, "status_code");
|
|
314
314
|
r(this, "_isEnded", !1);
|
|
@@ -330,7 +330,7 @@ class R extends U {
|
|
|
330
330
|
}, 100), setTimeout(() => {
|
|
331
331
|
this.trigger("confirmed");
|
|
332
332
|
}, 200);
|
|
333
|
-
},
|
|
333
|
+
}, l);
|
|
334
334
|
}));
|
|
335
335
|
this.url = e, this.initPeerconnection(n);
|
|
336
336
|
}
|
|
@@ -338,19 +338,19 @@ class R extends U {
|
|
|
338
338
|
return e ? (this.createPeerconnection(e), !0) : !1;
|
|
339
339
|
}
|
|
340
340
|
createPeerconnection(e) {
|
|
341
|
-
const n =
|
|
341
|
+
const n = W();
|
|
342
342
|
n.id = "mainaudio1";
|
|
343
343
|
const i = [n];
|
|
344
344
|
if (z(e)) {
|
|
345
|
-
const
|
|
346
|
-
|
|
345
|
+
const c = V();
|
|
346
|
+
c.id = "mainvideo1", i.push(c);
|
|
347
347
|
}
|
|
348
348
|
this._connection = new x(void 0, i), this._addStream(e), setTimeout(() => {
|
|
349
349
|
this.trigger("peerconnection", { peerconnection: this.connection });
|
|
350
|
-
},
|
|
350
|
+
}, l);
|
|
351
351
|
}
|
|
352
352
|
connect(e) {
|
|
353
|
-
const n =
|
|
353
|
+
const n = U(e);
|
|
354
354
|
setTimeout(() => {
|
|
355
355
|
this.url.includes(H) ? this.trigger("failed", {
|
|
356
356
|
originator: "remote",
|
|
@@ -363,11 +363,14 @@ class R extends U {
|
|
|
363
363
|
}, 200), setTimeout(() => {
|
|
364
364
|
this.trigger("confirmed");
|
|
365
365
|
}, 300));
|
|
366
|
-
},
|
|
366
|
+
}, l);
|
|
367
367
|
}
|
|
368
368
|
terminate({ status_code: e } = {}) {
|
|
369
369
|
return this.status_code = e, this.trigger("ended", { status_code: e }), this._isEnded = !1, this;
|
|
370
370
|
}
|
|
371
|
+
async terminateAsync({ status_code: e } = {}) {
|
|
372
|
+
this.terminate({ status_code: e });
|
|
373
|
+
}
|
|
371
374
|
terminateRemote({ status_code: e } = {}) {
|
|
372
375
|
return this.status_code = e, this.trigger("ended", { status_code: e, originator: "remote" }), this;
|
|
373
376
|
}
|
|
@@ -431,7 +434,7 @@ class q {
|
|
|
431
434
|
setExtraContactParams() {
|
|
432
435
|
}
|
|
433
436
|
}
|
|
434
|
-
const
|
|
437
|
+
const d = "PASSWORD_CORRECT", M = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", h = 400, s = class s {
|
|
435
438
|
constructor(t) {
|
|
436
439
|
r(this, "_events");
|
|
437
440
|
r(this, "_startedTimeout");
|
|
@@ -444,14 +447,20 @@ const a = "PASSWORD_CORRECT", M = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", c
|
|
|
444
447
|
// @ts-expect-error
|
|
445
448
|
r(this, "call", jest.fn((t, e) => {
|
|
446
449
|
const { mediaStream: n, eventHandlers: i } = e;
|
|
447
|
-
return this.session = new
|
|
450
|
+
return this.session = new S({ url: t, mediaStream: n, eventHandlers: i, originator: "local" }), this.session.connect(t), this.session;
|
|
448
451
|
}));
|
|
449
|
-
this._events = new v(
|
|
450
|
-
const [e, n] = t.uri.split(":"), [i,
|
|
452
|
+
this._events = new v(A);
|
|
453
|
+
const [e, n] = t.uri.split(":"), [i, a] = n.split("@"), c = {
|
|
451
454
|
...t,
|
|
452
|
-
uri: new p(e, i,
|
|
455
|
+
uri: new p(e, i, a)
|
|
453
456
|
};
|
|
454
|
-
this.configuration =
|
|
457
|
+
this.configuration = c, this._registrator = new q();
|
|
458
|
+
}
|
|
459
|
+
static setStartError(t, { count: e = Number.POSITIVE_INFINITY } = {}) {
|
|
460
|
+
this.startError = t, this.countStartError = e;
|
|
461
|
+
}
|
|
462
|
+
static resetStartError() {
|
|
463
|
+
this.startError = void 0, this.countStartError = Number.POSITIVE_INFINITY, this.countStarts = 0;
|
|
455
464
|
}
|
|
456
465
|
static setAvailableTelephony() {
|
|
457
466
|
this.isAvailableTelephony = !0;
|
|
@@ -459,12 +468,19 @@ const a = "PASSWORD_CORRECT", M = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", c
|
|
|
459
468
|
static setNotAvailableTelephony() {
|
|
460
469
|
this.isAvailableTelephony = !1;
|
|
461
470
|
}
|
|
471
|
+
isConnected() {
|
|
472
|
+
return !!this._isConnected;
|
|
473
|
+
}
|
|
462
474
|
/**
|
|
463
475
|
* start
|
|
464
476
|
*
|
|
465
477
|
* @returns {undefined}
|
|
466
478
|
*/
|
|
467
479
|
start() {
|
|
480
|
+
if (s.countStarts += 1, s.startError && s.countStarts < s.countStartError) {
|
|
481
|
+
this.trigger("disconnected", [s.startError]);
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
468
484
|
this.register();
|
|
469
485
|
}
|
|
470
486
|
/**
|
|
@@ -475,7 +491,7 @@ const a = "PASSWORD_CORRECT", M = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", c
|
|
|
475
491
|
stop() {
|
|
476
492
|
this._startedTimeout && clearTimeout(this._startedTimeout), this._stopedTimeout && clearTimeout(this._stopedTimeout), this.unregister(), this.isStarted() ? this._stopedTimeout = setTimeout(() => {
|
|
477
493
|
this.trigger("disconnected", { error: new Error("stoped") });
|
|
478
|
-
},
|
|
494
|
+
}, h) : this.trigger("disconnected", { error: new Error("stoped") });
|
|
479
495
|
}
|
|
480
496
|
// @ts-expect-error
|
|
481
497
|
on(t, e) {
|
|
@@ -524,11 +540,11 @@ const a = "PASSWORD_CORRECT", M = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", c
|
|
|
524
540
|
const { password: t, register: e, uri: n } = this.configuration;
|
|
525
541
|
e && n.user.includes(j) ? (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
|
|
526
542
|
this.trigger("registrationFailed", { response: null, cause: "Request Timeout" });
|
|
527
|
-
},
|
|
543
|
+
}, h)) : !this._isRegistered && e && (t === d || t === M) ? (this._isRegistered = !0, this._startedTimeout = setTimeout(() => {
|
|
528
544
|
this.trigger("registered");
|
|
529
|
-
},
|
|
545
|
+
}, h)) : e && t !== d && t !== M && (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
|
|
530
546
|
this.trigger("registrationFailed", { response: null, cause: "Wrong credentials" });
|
|
531
|
-
},
|
|
547
|
+
}, h)), s.isAvailableTelephony ? (this.trigger("connected"), this._isConnected = !0) : this.stop();
|
|
532
548
|
}
|
|
533
549
|
/**
|
|
534
550
|
* unregister
|
|
@@ -561,15 +577,15 @@ const a = "PASSWORD_CORRECT", M = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", c
|
|
|
561
577
|
this.trigger("sipEvent", t);
|
|
562
578
|
}
|
|
563
579
|
};
|
|
564
|
-
r(
|
|
565
|
-
let g =
|
|
566
|
-
class
|
|
580
|
+
r(s, "isAvailableTelephony", !0), r(s, "startError"), r(s, "countStartError", Number.POSITIVE_INFINITY), r(s, "countStarts", 0);
|
|
581
|
+
let g = s;
|
|
582
|
+
class Y {
|
|
567
583
|
constructor(t) {
|
|
568
584
|
r(this, "url");
|
|
569
585
|
this.url = t;
|
|
570
586
|
}
|
|
571
587
|
}
|
|
572
|
-
class
|
|
588
|
+
class B extends L {
|
|
573
589
|
constructor(e, n) {
|
|
574
590
|
super();
|
|
575
591
|
r(this, "contentType");
|
|
@@ -577,36 +593,36 @@ class K extends L {
|
|
|
577
593
|
this.contentType = e, this.body = n;
|
|
578
594
|
}
|
|
579
595
|
}
|
|
580
|
-
const _ = "remote",
|
|
596
|
+
const _ = "remote", K = (o, t) => {
|
|
581
597
|
const e = new T(t), n = {
|
|
582
598
|
originator: _,
|
|
583
599
|
request: e,
|
|
584
|
-
info: new
|
|
600
|
+
info: new B("", "")
|
|
585
601
|
};
|
|
586
602
|
o.newInfo(n);
|
|
587
|
-
},
|
|
603
|
+
}, $ = (o, t) => {
|
|
588
604
|
const n = { request: new T(t) };
|
|
589
605
|
o.newSipEvent(n);
|
|
590
|
-
},
|
|
606
|
+
}, J = (o, {
|
|
591
607
|
incomingNumber: t = "1234",
|
|
592
608
|
displayName: e,
|
|
593
609
|
host: n
|
|
594
610
|
}) => {
|
|
595
|
-
const i = new
|
|
596
|
-
i._remote_identity = new b(
|
|
611
|
+
const i = new S({ originator: _ }), a = new D("sip", t, n);
|
|
612
|
+
i._remote_identity = new b(a, e), o.trigger("newRTCSession", { originator: _, session: i });
|
|
597
613
|
}, G = (o, t) => {
|
|
598
614
|
t ? o.trigger("failed", t) : o.trigger("failed", o);
|
|
599
|
-
},
|
|
600
|
-
triggerNewInfo:
|
|
601
|
-
triggerNewSipEvent:
|
|
602
|
-
triggerIncomingSession:
|
|
615
|
+
}, R = {
|
|
616
|
+
triggerNewInfo: K,
|
|
617
|
+
triggerNewSipEvent: $,
|
|
618
|
+
triggerIncomingSession: J,
|
|
603
619
|
triggerFailIncomingSession: G,
|
|
604
|
-
WebSocketInterface:
|
|
620
|
+
WebSocketInterface: Y,
|
|
605
621
|
UA: g,
|
|
606
622
|
C: {
|
|
607
623
|
INVITE: "INVITE"
|
|
608
624
|
}
|
|
609
|
-
}, w = "user", m = "displayName", E = "SIP_SERVER_URL", C = "SIP_WEB_SOCKET_SERVER_URL", X = new
|
|
625
|
+
}, w = "user", m = "displayName", E = "SIP_SERVER_URL", C = "SIP_WEB_SOCKET_SERVER_URL", X = new R.WebSocketInterface(C), f = {
|
|
610
626
|
userAgent: "Chrome",
|
|
611
627
|
sipServerUrl: E,
|
|
612
628
|
sipWebSocketServerURL: C
|
|
@@ -615,7 +631,7 @@ const _ = "remote", $ = (o, t) => {
|
|
|
615
631
|
}, Q = {
|
|
616
632
|
...f,
|
|
617
633
|
user: w,
|
|
618
|
-
password:
|
|
634
|
+
password: d,
|
|
619
635
|
register: !0
|
|
620
636
|
}, he = {
|
|
621
637
|
...Q,
|
|
@@ -624,7 +640,7 @@ const _ = "remote", $ = (o, t) => {
|
|
|
624
640
|
...f,
|
|
625
641
|
displayName: m,
|
|
626
642
|
register: !1
|
|
627
|
-
},
|
|
643
|
+
}, u = {
|
|
628
644
|
session_timers: !1,
|
|
629
645
|
sockets: [X],
|
|
630
646
|
user_agent: "Chrome",
|
|
@@ -632,33 +648,33 @@ const _ = "remote", $ = (o, t) => {
|
|
|
632
648
|
register_expires: 300,
|
|
633
649
|
connection_recovery_max_interval: 6,
|
|
634
650
|
connection_recovery_min_interval: 2
|
|
635
|
-
},
|
|
636
|
-
...
|
|
637
|
-
password:
|
|
651
|
+
}, ue = {
|
|
652
|
+
...u,
|
|
653
|
+
password: d,
|
|
638
654
|
uri: new p("sip", w, E),
|
|
639
655
|
display_name: "",
|
|
640
656
|
register: !0
|
|
641
|
-
},
|
|
642
|
-
...
|
|
643
|
-
password:
|
|
657
|
+
}, le = {
|
|
658
|
+
...u,
|
|
659
|
+
password: d,
|
|
644
660
|
uri: new p("sip", w, E),
|
|
645
661
|
display_name: m,
|
|
646
662
|
register: !0
|
|
647
663
|
}, ge = {
|
|
648
|
-
...
|
|
664
|
+
...u,
|
|
649
665
|
display_name: m,
|
|
650
666
|
register: !1
|
|
651
667
|
}, _e = {
|
|
652
|
-
...
|
|
668
|
+
...u,
|
|
653
669
|
display_name: "",
|
|
654
670
|
register: !1
|
|
655
|
-
}, Z = "10.10.10.10", pe = [`X-Vinteo-Remote: ${Z}`], we = () => new
|
|
656
|
-
JsSIP:
|
|
671
|
+
}, Z = "10.10.10.10", pe = [`X-Vinteo-Remote: ${Z}`], we = () => new k({
|
|
672
|
+
JsSIP: R
|
|
657
673
|
});
|
|
658
674
|
export {
|
|
659
675
|
H as FAILED_CONFERENCE_NUMBER,
|
|
660
676
|
j as NAME_INCORRECT,
|
|
661
|
-
|
|
677
|
+
d as PASSWORD_CORRECT,
|
|
662
678
|
M as PASSWORD_CORRECT_2,
|
|
663
679
|
E as SIP_SERVER_URL,
|
|
664
680
|
C as SIP_WEB_SOCKET_SERVER_URL,
|
|
@@ -670,8 +686,8 @@ export {
|
|
|
670
686
|
m as displayName,
|
|
671
687
|
pe as extraHeadersRemoteAddress,
|
|
672
688
|
Z as remoteAddress,
|
|
673
|
-
|
|
674
|
-
|
|
689
|
+
ue as uaConfigurationWithAuthorization,
|
|
690
|
+
le as uaConfigurationWithAuthorizationWithDisplayName,
|
|
675
691
|
ge as uaConfigurationWithoutAuthorization,
|
|
676
692
|
_e as uaConfigurationWithoutAuthorizationWithoutDisplayName,
|
|
677
693
|
w as user
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./SipConnector-DxGNVRHG.cjs"),j=require("ts-debounce"),H=require("@krivega/cancelable-promise"),Y=require("sequent-promises"),z=require("stack-promises"),J=require("debug"),L="purgatory",N=e=>e===L,I=e=>()=>(r.logger("getRemoteStreams"),e.getRemoteStreams()),Q=({kind:e,readyState:t})=>e==="video"&&t==="live",V=e=>({track:t})=>{Q(t)&&e()},D=({getRemoteStreams:e,setRemoteStreams:t})=>j.debounce(()=>{const n=e();r.logger("remoteStreams",n),n&&t(n)},200),Z=e=>async n=>{const{mediaStream:s,extraHeaders:o,iceServers:c,degradationPreference:a,setRemoteStreams:l,onBeforeProgressCall:u,onSuccessProgressCall:d,onEnterPurgatory:m,onEnterConference:S,onFailProgressCall:C,onFinishProgressCall:g,onEndedCall:f}=n,M=D({setRemoteStreams:l,getRemoteStreams:I(e)}),_=V(M);r.logger("answerIncomingCall",n);const y=async()=>e.answerToIncomingCall({mediaStream:s,extraHeaders:o,iceServers:c,degradationPreference:a,ontrack:_}),v=()=>{const{remoteCallerData:i}=e;return i.incomingNumber};let R=!1,T;const b=(r.logger("subscribeEnterConference: onEnterConference",S),m??S?e.onSession("enterRoom",i=>{r.logger("enterRoom",{_room:i,isSuccessProgressCall:R}),T=i,N(T)?m&&m():S&&S({isSuccessProgressCall:R})}):()=>{}),h=i=>(r.logger("onSuccess"),R=!0,M(),d&&d({isPurgatory:N(T)}),e.onceRaceSession(["ended","failed"],()=>{b(),f&&f()}),i),O=i=>{throw r.logger("onFail"),C&&C(),b(),i},A=()=>{r.logger("onFinish"),g&&g()};if(r.logger("onBeforeProgressCall"),u){const i=v();u(i)}return y().then(h).catch(i=>O(i)).finally(A)},ee=e=>async n=>{const{conference:s,mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:l,setRemoteStreams:u,onBeforeProgressCall:d,onSuccessProgressCall:m,onEnterPurgatory:S,onEnterConference:C,onFailProgressCall:g,onFinishProgressCall:f,onEndedCall:M}=n,_=D({setRemoteStreams:u,getRemoteStreams:I(e)}),y=V(_);r.logger("callToServer",n);const v=async()=>(r.logger("startCall"),e.call({mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:l,number:s,ontrack:y}));let R=!1,T;const b=(r.logger("subscribeEnterConference: onEnterConference",C),S??C?e.onSession("enterRoom",({room:i})=>{r.logger("enterRoom",{_room:i,isSuccessProgressCall:R}),T=i,N(T)?S&&S():C&&C({isSuccessProgressCall:R})}):()=>{}),h=i=>(r.logger("onSuccess"),R=!0,_(),m&&m({isPurgatory:N(T)}),e.onceRaceSession(["ended","failed"],()=>{b(),M&&M()}),i),O=i=>{throw r.logger("onFail"),g&&g(),b(),i},A=()=>{r.logger("onFinish"),f&&f()};return r.logger("onBeforeProgressCall"),d&&d(s),v().then(h).catch(i=>O(i)).finally(A)},P=e=>{if(!H.isCanceledError(e))throw e;return{isSuccessful:!1}},ne=e=>async n=>{const{userAgent:s,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:l,name:u,password:d,isRegisteredUser:m,sdpSemantics:S,isDisconnectOnFail:C}=n;return r.logger("connectToServer",n),e.connect({userAgent:s,sdpSemantics:S,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:l,password:d,user:u,register:m}).then(g=>(r.logger("connectToServer then"),{ua:g,isSuccessful:!0})).catch(async g=>(r.logger("connectToServer catch: error",g),C===!0?e.disconnect().then(()=>P(g)).catch(()=>P(g)):P(g)))},te=e=>async()=>(r.logger("disconnectFromServer"),e.disconnect().then(()=>(r.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(t=>(r.logger("disconnectFromServer: catch",t),{isSuccessful:!1}))),w=e=>{const{url:t,cause:n}=e;let s=t;return(n===r.BAD_MEDIA_DESCRIPTION||n===r.NOT_FOUND)&&(s=`${e.message.to.uri.user}@${e.message.to.uri.host}`),s};var $=(e=>(e.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",e.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",e.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",e.NOT_FOUND_ERROR="NOT_FOUND_ERROR",e.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",e.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",e))($||{});const re=(e=new Error)=>{var o;const{cause:t,socket:n}=e;let s="CONNECT_SERVER_FAILED";switch(t){case"Forbidden":{s="WRONG_USER_OR_PASSWORD";break}case r.BAD_MEDIA_DESCRIPTION:{s="BAD_MEDIA_ERROR";break}case r.NOT_FOUND:{s="NOT_FOUND_ERROR";break}default:n&&((o=n==null?void 0:n._ws)==null?void 0:o.readyState)===3?s="WS_CONNECTION_FAILED":w(e)&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},se=(e=new Error)=>{const{code:t,cause:n,message:s}=e,o=w(e),c={};return s&&(c.message=s),o&&(c.link=o),t&&(c.code=t),n&&(c.cause=n),c},oe=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:w,getTypeFromError:re,getValuesFromError:se},Symbol.toStringTag,{value:"Module"})),ce=({sessionId:e,remoteAddress:t,isMutedAudio:n,isMutedVideo:s,isRegistered:o,isPresentationCall:c})=>{const a=[],l=n?"0":"1",u=s?"0":"1";return a.push(`X-Vinteo-Mic-State: ${l}`,`X-Vinteo-MainCam-State: ${u}`),o||a.push("X-Vinteo-Purgatory-Call: yes"),e&&a.push(`X-Vinteo-Session: ${e}`),c&&a.push("X-Vinteo-Presentation-Call: yes"),t&&a.push(`X-Vinteo-Remote: ${t}`),a},ae=({appName:e,appVersion:t,browserName:n,browserVersion:s})=>{const o=`${e} ${t}`;return`ChromeNew - ${n?`${n} ${s}, ${o}`:o}`},ie=({isUnifiedSdpSemantic:e,appVersion:t,browserName:n,browserVersion:s,appName:o})=>e?ae({appVersion:t,browserName:n,browserVersion:s,appName:o}):"Chrome",ue=e=>async()=>{if(e.isCallActive)return r.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},le=e=>n=>(r.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",n)),Se=e=>n=>(r.logger("onMoveToSpectators"),e.onSession("participant:move-request-to-spectators",n)),ge=e=>n=>(r.logger("onUseLicense"),e.onSession("useLicense",n)),de=e=>async({isEnabledCam:n,isEnabledMic:s})=>{if(e.isCallActive)return r.logger("sendMediaState"),e.sendMediaState({cam:n,mic:s})},me=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(n=>{r.logger("sendRefusalToTurnOnCam: error",n)})},fe=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(n=>{r.logger("sendRefusalToTurnOnMic: error",n)})},Ce=1e6,Ee=({maxBitrate:e=Ce,sipConnector:t})=>async({mediaStream:s,isP2P:o=!1})=>(r.logger("startPresentation"),t.startPresentation(s,{isP2P:o,maxBitrate:e})),Me=({sipConnector:e})=>async({isP2P:n=!1}={})=>(r.logger("stopShareSipConnector"),e.stopPresentation({isP2P:n}).catch(s=>{r.logger(s)})),Re=1e6,Te=({sipConnector:e,maxBitrate:t=Re})=>async({mediaStream:s,isP2P:o=!1})=>(r.logger("updatePresentation"),e.updatePresentation(s,{isP2P:o,maxBitrate:t})),_e=e=>t=>[...t].map(s=>async()=>e(s)),be=async({accumulatedKeys:e,sendKey:t,canRunTask:n})=>{const o=_e(t)(e);return Y.sequentPromises(o,n)},ye=e=>n=>(r.logger("onStartMainCam"),e.onSession("admin-start-main-cam",n)),ve=e=>n=>(r.logger("onStartMic"),e.onSession("admin-start-mic",n)),he=e=>n=>(r.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",n)),Oe=e=>n=>(r.logger("onStopMic"),e.onSession("admin-stop-mic",n)),Ae=({sipConnector:e})=>{const t=(f,M)=>({isSyncForced:_=!1})=>{if(_){f();return}M()},n=ye(e),s=he(e),o=ve(e),c=Oe(e);let a=()=>{},l=()=>{},u=()=>{},d=()=>{};const m=({onStartMainCamForced:f,onStartMainCamNotForced:M,onStopMainCamForced:_,onStopMainCamNotForced:y,onStartMicForced:v,onStartMicNotForced:R,onStopMicForced:T,onStopMicNotForced:p})=>{const b=t(f,M);a=n(b);const h=t(_,y);l=s(h);const O=t(v,R);u=o(O);const A=t(T,p);d=c(A)},S=()=>{a(),l(),u(),d()};return{start:f=>{m(f)},stop:()=>{S()}}},Ne=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:L,createSyncMediaState:Ae,error:oe,getExtraHeaders:ce,getUserAgent:ie,hasPurgatory:N,resolveAnswerIncomingCall:Z,resolveAskPermissionToEnableCam:ue,resolveCallToServer:ee,resolveConnectToServer:ne,resolveDisconnectFromServer:te,resolveGetRemoteStreams:I,resolveOnMoveToSpectators:Se,resolveOnMustStopPresentation:le,resolveOnUseLicense:ge,resolveSendMediaState:de,resolveSendRefusalToTurnOnCam:me,resolveSendRefusalToTurnOnMic:fe,resolveStartPresentation:Ee,resolveStopShareSipConnector:Me,resolveUpdatePresentation:Te,resolveUpdateRemoteStreams:D,sendDTMFAccumulated:be},Symbol.toStringTag,{value:"Module"})),pe=e=>[...e.keys()].map(t=>e.get(t)),Pe=(e,t)=>pe(e).find(n=>n.type===t),x=async e=>e.getStats().then(t=>{const n=Pe(t,"codec");return n==null?void 0:n.mimeType}),Be=e=>e.find(t=>{var n;return((n=t==null?void 0:t.track)==null?void 0:n.kind)==="video"}),q=(e,t)=>e!==void 0&&t!==void 0&&e.toLowerCase().includes(t.toLowerCase()),Ie=1e6,E=e=>e*Ie,G=E(.06),De=E(4),we=e=>e<=64?G:e<=128?E(.12):e<=256?E(.25):e<=384?E(.32):e<=426?E(.38):e<=640?E(.5):e<=848?E(.7):e<=1280?E(1):e<=1920?E(2):De,Fe="av1",ke=e=>q(e,Fe),Ue=.6,X=(e,t)=>ke(t)?e*Ue:e,Le=e=>X(G,e),K=(e,t)=>{const n=we(e);return X(n,t)},W=z.createStackPromises(),Ve=async()=>W().catch(e=>{r.logger("videoSendingBalancer: error",e)}),$e=async e=>(W.add(e),Ve()),F=async({sender:e,scaleResolutionDownBy:t,maxBitrate:n,onSetParameters:s})=>$e(async()=>r.setEncodingsToSender(e,{scaleResolutionDownBy:t,maxBitrate:n},s)),xe=async({sender:e,codec:t},n)=>{const o=Le(t);return F({sender:e,maxBitrate:o,onSetParameters:n,scaleResolutionDownBy:200})},B=async({sender:e,track:t,codec:n},s)=>{const a=t.getSettings().width,l=K(a,n);return F({sender:e,maxBitrate:l,onSetParameters:s,scaleResolutionDownBy:1})},qe=async({sender:e,track:t,resolution:n,codec:s},o)=>{const c=t.getSettings(),a=c.width,l=c.height,[u,d]=n.split("x"),m=a/Number(u),S=l/Number(d),g=Math.max(m,S,1),f=K(Number(u),s);return F({sender:e,maxBitrate:f,onSetParameters:o,scaleResolutionDownBy:g})},Ge=async({mainCam:e,resolutionMainCam:t,sender:n,track:s,codec:o},c)=>{switch(e){case r.EEventsMainCAM.PAUSE_MAIN_CAM:return xe({sender:n,codec:o},c);case r.EEventsMainCAM.RESUME_MAIN_CAM:return B({sender:n,track:s,codec:o},c);case r.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return t!==void 0?qe({sender:n,track:s,codec:o,resolution:t},c):B({sender:n,track:s,codec:o},c);default:return B({sender:n,track:s,codec:o},c)}},k={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},U=async({mainCam:e,resolutionMainCam:t,connection:n,onSetParameters:s,ignoreForCodec:o})=>{const c=n.getSenders(),a=Be(c);if(!(a!=null&&a.track))return k;const l=await x(a);return q(l,o)?k:Ge({mainCam:e,resolutionMainCam:t,sender:a,codec:l,track:a.track},s)},Xe=(e,{ignoreForCodec:t,onSetParameters:n}={})=>{const s=async()=>{const{connection:u}=e;if(!u)throw new Error("connection is not exist");return U({connection:u,onSetParameters:n,ignoreForCodec:t})};let o=s;const c=async u=>(o=async()=>{const{mainCam:d,resolutionMainCam:m}=u,{connection:S}=e;if(!S)throw new Error("connection is not exist");return U({mainCam:d,resolutionMainCam:m,connection:S,onSetParameters:n,ignoreForCodec:t})},o());return{subscribe:()=>{e.onSession("main-cam-control",c)},unsubscribe:()=>{e.offSession("main-cam-control",c)},balanceByTrack:s,resetMainCamControl(){o=s},async reBalance(){return o()}}};exports.EEventsMainCAM=r.EEventsMainCAM;exports.EEventsMic=r.EEventsMic;exports.EEventsSyncMediaState=r.EEventsSyncMediaState;exports.EUseLicense=r.EUseLicense;exports.causes=r.causes;exports.constants=r.constants;exports.default=r.SipConnector;exports.disableDebug=r.disableDebug;exports.enableDebug=r.enableDebug;exports.eventNames=r.eventNames;exports.hasCanceledCallError=r.hasCanceledCallError;exports.debug=J;exports.getCodecFromSender=x;exports.resolveVideoSendingBalancer=Xe;exports.tools=Ne;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./SipConnector-BHUjGzwS.cjs"),j=require("ts-debounce"),H=require("@krivega/cancelable-promise"),Y=require("repeated-calls"),z=require("sequent-promises"),J=require("stack-promises"),Q=require("debug"),L="purgatory",N=e=>e===L,I=e=>()=>(r.logger("getRemoteStreams"),e.getRemoteStreams()),Z=({kind:e,readyState:t})=>e==="video"&&t==="live",V=e=>({track:t})=>{Z(t)&&e()},D=({getRemoteStreams:e,setRemoteStreams:t})=>j.debounce(()=>{const n=e();r.logger("remoteStreams",n),n&&t(n)},200),ee=e=>async n=>{const{mediaStream:s,extraHeaders:o,iceServers:c,degradationPreference:a,setRemoteStreams:l,onBeforeProgressCall:u,onSuccessProgressCall:d,onEnterPurgatory:m,onEnterConference:S,onFailProgressCall:f,onFinishProgressCall:g,onEndedCall:C}=n,M=D({setRemoteStreams:l,getRemoteStreams:I(e)}),_=V(M);r.logger("answerIncomingCall",n);const y=async()=>e.answerToIncomingCall({mediaStream:s,extraHeaders:o,iceServers:c,degradationPreference:a,ontrack:_}),v=()=>{const{remoteCallerData:i}=e;return i.incomingNumber};let R=!1,T;const b=(r.logger("subscribeEnterConference: onEnterConference",S),m??S?e.onSession("enterRoom",i=>{r.logger("enterRoom",{_room:i,isSuccessProgressCall:R}),T=i,N(T)?m&&m():S&&S({isSuccessProgressCall:R})}):()=>{}),h=i=>(r.logger("onSuccess"),R=!0,M(),d&&d({isPurgatory:N(T)}),e.onceRaceSession(["ended","failed"],()=>{b(),C&&C()}),i),O=i=>{throw r.logger("onFail"),f&&f(),b(),i},A=()=>{r.logger("onFinish"),g&&g()};if(r.logger("onBeforeProgressCall"),u){const i=v();u(i)}return y().then(h).catch(i=>O(i)).finally(A)},ne=e=>async n=>{const{conference:s,mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:l,setRemoteStreams:u,onBeforeProgressCall:d,onSuccessProgressCall:m,onEnterPurgatory:S,onEnterConference:f,onFailProgressCall:g,onFinishProgressCall:C,onEndedCall:M}=n,_=D({setRemoteStreams:u,getRemoteStreams:I(e)}),y=V(_);r.logger("callToServer",n);const v=async()=>(r.logger("startCall"),e.call({mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:l,number:s,ontrack:y}));let R=!1,T;const b=(r.logger("subscribeEnterConference: onEnterConference",f),S??f?e.onSession("enterRoom",({room:i})=>{r.logger("enterRoom",{_room:i,isSuccessProgressCall:R}),T=i,N(T)?S&&S():f&&f({isSuccessProgressCall:R})}):()=>{}),h=i=>(r.logger("onSuccess"),R=!0,_(),m&&m({isPurgatory:N(T)}),e.onceRaceSession(["ended","failed"],()=>{b(),M&&M()}),i),O=i=>{throw r.logger("onFail"),g&&g(),b(),i},A=()=>{r.logger("onFinish"),C&&C()};return r.logger("onBeforeProgressCall"),d&&d(s),v().then(h).catch(i=>O(i)).finally(A)},P=e=>{if(!H.isCanceledError(e)&&!Y.hasCanceledError(e))throw e;return{isSuccessful:!1}},te=e=>async n=>{const{userAgent:s,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:l,name:u,password:d,isRegisteredUser:m,sdpSemantics:S,isDisconnectOnFail:f}=n;return r.logger("connectToServer",n),e.connect({userAgent:s,sdpSemantics:S,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:l,password:d,user:u,register:m}).then(g=>(r.logger("connectToServer then"),{ua:g,isSuccessful:!0})).catch(async g=>(r.logger("connectToServer catch: error",g),f===!0?e.disconnect().then(()=>P(g)).catch(()=>P(g)):P(g)))},re=e=>async()=>(r.logger("disconnectFromServer"),e.disconnect().then(()=>(r.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(t=>(r.logger("disconnectFromServer: catch",t),{isSuccessful:!1}))),w=e=>{const{url:t,cause:n}=e;let s=t;return(n===r.BAD_MEDIA_DESCRIPTION||n===r.NOT_FOUND)&&(s=`${e.message.to.uri.user}@${e.message.to.uri.host}`),s};var $=(e=>(e.CONNECT_SERVER_FAILED="CONNECT_SERVER_FAILED",e.WRONG_USER_OR_PASSWORD="WRONG_USER_OR_PASSWORD",e.BAD_MEDIA_ERROR="BAD_MEDIA_ERROR",e.NOT_FOUND_ERROR="NOT_FOUND_ERROR",e.WS_CONNECTION_FAILED="WS_CONNECTION_FAILED",e.CONNECT_SERVER_FAILED_BY_LINK="CONNECT_SERVER_FAILED_BY_LINK",e))($||{});const se=(e=new Error)=>{var o;const{cause:t,socket:n}=e;let s="CONNECT_SERVER_FAILED";switch(t){case"Forbidden":{s="WRONG_USER_OR_PASSWORD";break}case r.BAD_MEDIA_DESCRIPTION:{s="BAD_MEDIA_ERROR";break}case r.NOT_FOUND:{s="NOT_FOUND_ERROR";break}default:n&&((o=n==null?void 0:n._ws)==null?void 0:o.readyState)===3?s="WS_CONNECTION_FAILED":w(e)&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},oe=(e=new Error)=>{const{code:t,cause:n,message:s}=e,o=w(e),c={};return s&&(c.message=s),o&&(c.link=o),t&&(c.code=t),n&&(c.cause=n),c},ce=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:w,getTypeFromError:se,getValuesFromError:oe},Symbol.toStringTag,{value:"Module"})),ae=({sessionId:e,remoteAddress:t,isMutedAudio:n,isMutedVideo:s,isRegistered:o,isPresentationCall:c})=>{const a=[],l=n?"0":"1",u=s?"0":"1";return a.push(`X-Vinteo-Mic-State: ${l}`,`X-Vinteo-MainCam-State: ${u}`),o||a.push("X-Vinteo-Purgatory-Call: yes"),e&&a.push(`X-Vinteo-Session: ${e}`),c&&a.push("X-Vinteo-Presentation-Call: yes"),t&&a.push(`X-Vinteo-Remote: ${t}`),a},ie=({appName:e,appVersion:t,browserName:n,browserVersion:s})=>{const o=`${e} ${t}`;return`ChromeNew - ${n?`${n} ${s}, ${o}`:o}`},ue=({isUnifiedSdpSemantic:e,appVersion:t,browserName:n,browserVersion:s,appName:o})=>e?ie({appVersion:t,browserName:n,browserVersion:s,appName:o}):"Chrome",le=e=>async()=>{if(e.isCallActive)return r.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},Se=e=>n=>(r.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",n)),ge=e=>n=>(r.logger("onMoveToSpectators"),e.onSession("participant:move-request-to-spectators",n)),de=e=>n=>(r.logger("onUseLicense"),e.onSession("useLicense",n)),me=e=>async({isEnabledCam:n,isEnabledMic:s})=>{if(e.isCallActive)return r.logger("sendMediaState"),e.sendMediaState({cam:n,mic:s})},Ce=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(n=>{r.logger("sendRefusalToTurnOnCam: error",n)})},fe=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(n=>{r.logger("sendRefusalToTurnOnMic: error",n)})},Ee=1e6,Me=({maxBitrate:e=Ee,sipConnector:t})=>async({mediaStream:s,isP2P:o=!1})=>(r.logger("startPresentation"),t.startPresentation(s,{isP2P:o,maxBitrate:e})),Re=({sipConnector:e})=>async({isP2P:n=!1}={})=>(r.logger("stopShareSipConnector"),e.stopPresentation({isP2P:n}).catch(s=>{r.logger(s)})),Te=1e6,_e=({sipConnector:e,maxBitrate:t=Te})=>async({mediaStream:s,isP2P:o=!1})=>(r.logger("updatePresentation"),e.updatePresentation(s,{isP2P:o,maxBitrate:t})),be=e=>t=>[...t].map(s=>async()=>e(s)),ye=async({accumulatedKeys:e,sendKey:t,canRunTask:n})=>{const o=be(t)(e);return z.sequentPromises(o,n)},ve=e=>n=>(r.logger("onStartMainCam"),e.onSession("admin-start-main-cam",n)),he=e=>n=>(r.logger("onStartMic"),e.onSession("admin-start-mic",n)),Oe=e=>n=>(r.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",n)),Ae=e=>n=>(r.logger("onStopMic"),e.onSession("admin-stop-mic",n)),Ne=({sipConnector:e})=>{const t=(C,M)=>({isSyncForced:_=!1})=>{if(_){C();return}M()},n=ve(e),s=Oe(e),o=he(e),c=Ae(e);let a=()=>{},l=()=>{},u=()=>{},d=()=>{};const m=({onStartMainCamForced:C,onStartMainCamNotForced:M,onStopMainCamForced:_,onStopMainCamNotForced:y,onStartMicForced:v,onStartMicNotForced:R,onStopMicForced:T,onStopMicNotForced:p})=>{const b=t(C,M);a=n(b);const h=t(_,y);l=s(h);const O=t(v,R);u=o(O);const A=t(T,p);d=c(A)},S=()=>{a(),l(),u(),d()};return{start:C=>{m(C)},stop:()=>{S()}}},pe=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:L,createSyncMediaState:Ne,error:ce,getExtraHeaders:ae,getUserAgent:ue,hasPurgatory:N,resolveAnswerIncomingCall:ee,resolveAskPermissionToEnableCam:le,resolveCallToServer:ne,resolveConnectToServer:te,resolveDisconnectFromServer:re,resolveGetRemoteStreams:I,resolveOnMoveToSpectators:ge,resolveOnMustStopPresentation:Se,resolveOnUseLicense:de,resolveSendMediaState:me,resolveSendRefusalToTurnOnCam:Ce,resolveSendRefusalToTurnOnMic:fe,resolveStartPresentation:Me,resolveStopShareSipConnector:Re,resolveUpdatePresentation:_e,resolveUpdateRemoteStreams:D,sendDTMFAccumulated:ye},Symbol.toStringTag,{value:"Module"})),Pe=e=>[...e.keys()].map(t=>e.get(t)),Be=(e,t)=>Pe(e).find(n=>n.type===t),q=async e=>e.getStats().then(t=>{const n=Be(t,"codec");return n==null?void 0:n.mimeType}),Ie=e=>e.find(t=>{var n;return((n=t==null?void 0:t.track)==null?void 0:n.kind)==="video"}),x=(e,t)=>e!==void 0&&t!==void 0&&e.toLowerCase().includes(t.toLowerCase()),De=1e6,E=e=>e*De,G=E(.06),we=E(4),Fe=e=>e<=64?G:e<=128?E(.12):e<=256?E(.25):e<=384?E(.32):e<=426?E(.38):e<=640?E(.5):e<=848?E(.7):e<=1280?E(1):e<=1920?E(2):we,ke="av1",Ue=e=>x(e,ke),Le=.6,X=(e,t)=>Ue(t)?e*Le:e,Ve=e=>X(G,e),K=(e,t)=>{const n=Fe(e);return X(n,t)},W=J.createStackPromises(),$e=async()=>W().catch(e=>{r.logger("videoSendingBalancer: error",e)}),qe=async e=>(W.add(e),$e()),F=async({sender:e,scaleResolutionDownBy:t,maxBitrate:n,onSetParameters:s})=>qe(async()=>r.setEncodingsToSender(e,{scaleResolutionDownBy:t,maxBitrate:n},s)),xe=async({sender:e,codec:t},n)=>{const o=Ve(t);return F({sender:e,maxBitrate:o,onSetParameters:n,scaleResolutionDownBy:200})},B=async({sender:e,track:t,codec:n},s)=>{const a=t.getSettings().width,l=K(a,n);return F({sender:e,maxBitrate:l,onSetParameters:s,scaleResolutionDownBy:1})},Ge=async({sender:e,track:t,resolution:n,codec:s},o)=>{const c=t.getSettings(),a=c.width,l=c.height,[u,d]=n.split("x"),m=a/Number(u),S=l/Number(d),g=Math.max(m,S,1),C=K(Number(u),s);return F({sender:e,maxBitrate:C,onSetParameters:o,scaleResolutionDownBy:g})},Xe=async({mainCam:e,resolutionMainCam:t,sender:n,track:s,codec:o},c)=>{switch(e){case r.EEventsMainCAM.PAUSE_MAIN_CAM:return xe({sender:n,codec:o},c);case r.EEventsMainCAM.RESUME_MAIN_CAM:return B({sender:n,track:s,codec:o},c);case r.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return t!==void 0?Ge({sender:n,track:s,codec:o,resolution:t},c):B({sender:n,track:s,codec:o},c);default:return B({sender:n,track:s,codec:o},c)}},k={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},U=async({mainCam:e,resolutionMainCam:t,connection:n,onSetParameters:s,ignoreForCodec:o})=>{const c=n.getSenders(),a=Ie(c);if(!(a!=null&&a.track))return k;const l=await q(a);return x(l,o)?k:Xe({mainCam:e,resolutionMainCam:t,sender:a,codec:l,track:a.track},s)},Ke=(e,{ignoreForCodec:t,onSetParameters:n}={})=>{const s=async()=>{const{connection:u}=e;if(!u)throw new Error("connection is not exist");return U({connection:u,onSetParameters:n,ignoreForCodec:t})};let o=s;const c=async u=>(o=async()=>{const{mainCam:d,resolutionMainCam:m}=u,{connection:S}=e;if(!S)throw new Error("connection is not exist");return U({mainCam:d,resolutionMainCam:m,connection:S,onSetParameters:n,ignoreForCodec:t})},o());return{subscribe:()=>{e.onSession("main-cam-control",c)},unsubscribe:()=>{e.offSession("main-cam-control",c)},balanceByTrack:s,resetMainCamControl(){o=s},async reBalance(){return o()}}};exports.EEventsMainCAM=r.EEventsMainCAM;exports.EEventsMic=r.EEventsMic;exports.EEventsSyncMediaState=r.EEventsSyncMediaState;exports.EUseLicense=r.EUseLicense;exports.causes=r.causes;exports.constants=r.constants;exports.default=r.SipConnector;exports.disableDebug=r.disableDebug;exports.enableDebug=r.enableDebug;exports.eventNames=r.eventNames;exports.hasCanceledCallError=r.hasCanceledCallError;exports.debug=Q;exports.getCodecFromSender=q;exports.resolveVideoSendingBalancer=Ke;exports.tools=pe;
|