sip-connector 7.0.10 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SipConnector-BA8w-WR5.cjs +1 -0
- package/dist/{SipConnector-3gRIidBJ.js → SipConnector-C5s0hhzA.js} +434 -396
- package/dist/SipConnector.d.ts +8 -3
- package/dist/__fixtures__/Session.mock.d.ts +9 -0
- package/dist/doMock.cjs +1 -1
- package/dist/doMock.js +114 -102
- package/dist/index.cjs +1 -1
- package/dist/index.js +33 -35
- package/dist/tools/__fixtures__/connectToServer.d.ts +0 -10
- package/dist/tools/connectToServer.d.ts +0 -1
- package/dist/types.d.ts +0 -1
- package/package.json +1 -1
- package/dist/SipConnector-3pnvrFP5.cjs +0 -1
package/dist/SipConnector.d.ts
CHANGED
|
@@ -83,7 +83,6 @@ type TParametersConnection = TOptionsExtraHeaders & {
|
|
|
83
83
|
sipServerUrl: string;
|
|
84
84
|
sipWebSocketServerURL: string;
|
|
85
85
|
remoteAddress?: string;
|
|
86
|
-
sdpSemantics?: 'plan-b' | 'unified-plan';
|
|
87
86
|
sessionTimers?: boolean;
|
|
88
87
|
registerExpires?: number;
|
|
89
88
|
connectionRecoveryMinInterval?: number;
|
|
@@ -94,7 +93,6 @@ type TParametersCheckTelephony = {
|
|
|
94
93
|
displayName: string;
|
|
95
94
|
sipServerUrl: string;
|
|
96
95
|
sipWebSocketServerURL: string;
|
|
97
|
-
sdpSemantics?: 'plan-b' | 'unified-plan';
|
|
98
96
|
userAgent?: string;
|
|
99
97
|
};
|
|
100
98
|
type TConnect = (parameters: TParametersConnection, options?: {
|
|
@@ -142,6 +140,7 @@ export default class SipConnector {
|
|
|
142
140
|
private readonly _uaEvents;
|
|
143
141
|
private readonly _cancelableConnect;
|
|
144
142
|
private _cancelableConnectWithRepeatedCalls;
|
|
143
|
+
private _cancelableSendPresentationWithRepeatedCalls;
|
|
145
144
|
private readonly _cancelableInitUa;
|
|
146
145
|
private readonly _cancelableDisconnect;
|
|
147
146
|
private readonly _cancelableSet;
|
|
@@ -172,7 +171,7 @@ export default class SipConnector {
|
|
|
172
171
|
tryRegister: () => Promise<RegisteredEvent>;
|
|
173
172
|
sendOptions(target: URI | string, body?: string, extraHeaders?: string[]): Promise<void>;
|
|
174
173
|
ping(body?: string, extraHeaders?: string[]): Promise<void>;
|
|
175
|
-
checkTelephony({ userAgent, displayName, sipServerUrl, sipWebSocketServerURL,
|
|
174
|
+
checkTelephony({ userAgent, displayName, sipServerUrl, sipWebSocketServerURL, }: TParametersCheckTelephony): Promise<void>;
|
|
176
175
|
replaceMediaStream(mediaStream: MediaStream, options?: {
|
|
177
176
|
deleteExisting: boolean;
|
|
178
177
|
addMissing: boolean;
|
|
@@ -187,6 +186,7 @@ export default class SipConnector {
|
|
|
187
186
|
askPermissionToEnableCam(options?: TOptionsInfoMediaState): Promise<void>;
|
|
188
187
|
get isPendingPresentation(): boolean;
|
|
189
188
|
private readonly _connectWithDuplicatedCalls;
|
|
189
|
+
private _sendPresentationWithDuplicatedCalls;
|
|
190
190
|
private hasEqualConnectionConfiguration;
|
|
191
191
|
private createUaConfiguration;
|
|
192
192
|
private _sendPresentation;
|
|
@@ -195,6 +195,8 @@ export default class SipConnector {
|
|
|
195
195
|
isP2P?: boolean;
|
|
196
196
|
maxBitrate?: number;
|
|
197
197
|
degradationPreference?: TDegradationPreference;
|
|
198
|
+
}, options?: {
|
|
199
|
+
callLimit: number;
|
|
198
200
|
}): Promise<MediaStream>;
|
|
199
201
|
private sendMustStopPresentation;
|
|
200
202
|
stopPresentation({ isP2P, }?: {
|
|
@@ -205,7 +207,9 @@ export default class SipConnector {
|
|
|
205
207
|
maxBitrate?: number;
|
|
206
208
|
degradationPreference?: TDegradationPreference;
|
|
207
209
|
}): Promise<MediaStream | void>;
|
|
210
|
+
_removeStreamPresentationCurrent(): void;
|
|
208
211
|
_resetPresentation(): void;
|
|
212
|
+
_cancelRequestsAndResetPresentation(): void;
|
|
209
213
|
handleNewRTCSession: ({ originator, session }: IncomingRTCSessionEvent) => void;
|
|
210
214
|
on<T = void>(eventName: TEventUA, handler: (data: T) => void): () => void;
|
|
211
215
|
once<T>(eventName: TEventUA, handler: (data: T) => void): () => void;
|
|
@@ -262,6 +266,7 @@ export default class SipConnector {
|
|
|
262
266
|
_hangUpWithoutCancelRequests: THangUp;
|
|
263
267
|
_cancelRequests(): void;
|
|
264
268
|
_cancelConnectWithRepeatedCalls(): void;
|
|
269
|
+
_cancelSendPresentationWithRepeatedCalls(): void;
|
|
265
270
|
_cancelCallRequests(): void;
|
|
266
271
|
_cancelActionsRequests(): void;
|
|
267
272
|
_handleShareState: (eventName: string) => void;
|
|
@@ -2,16 +2,25 @@ import { IncomingInfoEvent } from '@krivega/jssip';
|
|
|
2
2
|
import { default as BaseSession } from './BaseSession.mock';
|
|
3
3
|
|
|
4
4
|
export declare const FAILED_CONFERENCE_NUMBER = "777";
|
|
5
|
+
export declare const createDeclineStartPresentationError: () => Error;
|
|
5
6
|
declare class Session extends BaseSession {
|
|
6
7
|
url: string;
|
|
7
8
|
status_code?: number;
|
|
8
9
|
private _isEnded;
|
|
10
|
+
private static startPresentationError?;
|
|
11
|
+
private static countStartPresentationError;
|
|
12
|
+
private static countStartsPresentation;
|
|
9
13
|
constructor({ url, mediaStream, eventHandlers, originator, }: {
|
|
10
14
|
url?: string;
|
|
11
15
|
mediaStream?: any;
|
|
12
16
|
eventHandlers?: any;
|
|
13
17
|
originator: string;
|
|
14
18
|
});
|
|
19
|
+
static setStartPresentationError(startPresentationError: Error, { count }?: {
|
|
20
|
+
count?: number;
|
|
21
|
+
}): void;
|
|
22
|
+
static resetStartPresentationError(): void;
|
|
23
|
+
startPresentation(stream: MediaStream): Promise<MediaStream>;
|
|
15
24
|
initPeerconnection(mediaStream: any): boolean;
|
|
16
25
|
createPeerconnection(sendedStream: any): void;
|
|
17
26
|
connect(target: string): void;
|
package/dist/doMock.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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-3pnvrFP5.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;
|
|
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 g=require("./SipConnector-BA8w-WR5.cjs"),D=require("@krivega/jssip/lib/NameAddrHeader"),L=require("@krivega/jssip/lib/URI"),F=require("node:events"),V=require("@krivega/jssip/lib/SIPMessage"),C=require("webrtc-mock"),I=require("events-constructor"),T=require("@krivega/jssip");class y extends V.IncomingRequest{constructor(e){super();r(this,"headers");this.headers=new Headers(e)}getHeader(e){return this.headers.get(e)||""}}class z{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 I(g.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 U{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 q(o){const t=o.match(/(purgatory)|[\d.]+/g);if(!t)throw new Error("wrong sip url");return t[0]}const w=400,N="777",x=o=>o.getVideoTracks().length>0,a=class a extends z{constructor({url:e="",mediaStream:n,eventHandlers:i,originator:d}){super({originator:d,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)},w)}));this.url=e,this.initPeerconnection(n)}static setStartPresentationError(e,{count:n=Number.POSITIVE_INFINITY}={}){this.startPresentationError=e,this.countStartPresentationError=n}static resetStartPresentationError(){this.startPresentationError=void 0,this.countStartPresentationError=Number.POSITIVE_INFINITY,this.countStartsPresentation=0}async startPresentation(e){if(a.countStartsPresentation+=1,a.startPresentationError&&a.countStartsPresentation<a.countStartPresentationError)throw a.startPresentationError;return super.startPresentation(e)}initPeerconnection(e){return e?(this.createPeerconnection(e),!0):!1}createPeerconnection(e){const n=C.createAudioMediaStreamTrackMock();n.id="mainaudio1";const i=[n];if(x(e)){const u=C.createVideoMediaStreamTrackMock();u.id="mainvideo1",i.push(u)}this._connection=new U(void 0,i),this._addStream(e),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},w)}connect(e){const n=q(e);setTimeout(()=>{this.url.includes(N)?this.trigger("failed",{originator:"remote",message:"IncomingResponse",cause:g.REJECTED}):(this.trigger("connecting"),setTimeout(()=>{this.trigger("enterRoom",{room:n})},100),setTimeout(()=>{this.trigger("accepted")},200),setTimeout(()=>{this.trigger("confirmed")},300))},w)}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)}};r(a,"startPresentationError"),r(a,"countStartPresentationError",Number.POSITIVE_INFINITY),r(a,"countStartsPresentation",0);let l=a;class H{constructor(){r(this,"extraHeaders")}setExtraHeaders(t){this.extraHeaders=t}setExtraContactParams(){}}const c="PASSWORD_CORRECT",f="PASSWORD_CORRECT_2",P="NAME_INCORRECT",m=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 l({url:t,mediaStream:n,eventHandlers:i,originator:"local"}),this.session.connect(t),this.session}));this._events=new I(g.UA_EVENT_NAMES);const[e,n]=t.uri.split(":"),[i,d]=n.split("@"),u={...t,uri:new T.URI(e,i,d)};this.configuration=u,this._registrator=new H}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")})},m):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(P)?(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Request Timeout"})},m)):!this._isRegistered&&e&&(t===c||t===f)?(this._isRegistered=!0,this._startedTimeout=setTimeout(()=>{this.trigger("registered")},m)):e&&t!==c&&t!==f&&(this._isRegistered=!1,this._isConnected=!1,this._startedTimeout=setTimeout(()=>{this.trigger("registrationFailed",{response:null,cause:"Wrong credentials"})},m)),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 M=s;class Y{constructor(t){r(this,"url");this.url=t}}class j extends F.EventEmitter{constructor(e,n){super();r(this,"contentType");r(this,"body");this.contentType=e,this.body=n}}const S="remote",B=(o,t)=>{const e=new y(t),n={originator:S,request:e,info:new j("","")};o.newInfo(n)},K=(o,t)=>{const n={request:new y(t)};o.newSipEvent(n)},$=(o,{incomingNumber:t="1234",displayName:e,host:n})=>{const i=new l({originator:S}),d=new L("sip",t,n);i._remote_identity=new D(d,e),o.trigger("newRTCSession",{originator:S,session:i})},J=(o,t)=>{t?o.trigger("failed",t):o.trigger("failed",o)},A={triggerNewInfo:B,triggerNewSipEvent:K,triggerIncomingSession:$,triggerFailIncomingSession:J,WebSocketInterface:Y,UA:M,C:{INVITE:"INVITE"}},_="user",h="displayName",E="SIP_SERVER_URL",R="SIP_WEB_SOCKET_SERVER_URL",G=new A.WebSocketInterface(R),v={userAgent:"Chrome",sipServerUrl:E,sipWebSocketServerURL:R},X={...v},O={...v,user:_,password:c,register:!0},Q={...O,displayName:h},Z={...v,displayName:h,register:!1},p={session_timers:!1,sockets:[G],user_agent:"Chrome",sdp_semantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},ee={...p,password:c,uri:new T.URI("sip",_,E),display_name:"",register:!0},te={...p,password:c,uri:new T.URI("sip",_,E),display_name:h,register:!0},re={...p,display_name:h,register:!1},ne={...p,display_name:"",register:!1},W="10.10.10.10",oe=[`X-Vinteo-Remote: ${W}`],ie=()=>new g.SipConnector({JsSIP:A});exports.FAILED_CONFERENCE_NUMBER=N;exports.NAME_INCORRECT=P;exports.PASSWORD_CORRECT=c;exports.PASSWORD_CORRECT_2=f;exports.SIP_SERVER_URL=E;exports.SIP_WEB_SOCKET_SERVER_URL=R;exports.dataForConnectionWithAuthorization=O;exports.dataForConnectionWithAuthorizationWithDisplayName=Q;exports.dataForConnectionWithoutAuthorization=Z;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=X;exports.default=ie;exports.displayName=h;exports.extraHeadersRemoteAddress=oe;exports.remoteAddress=W;exports.uaConfigurationWithAuthorization=ee;exports.uaConfigurationWithAuthorizationWithDisplayName=te;exports.uaConfigurationWithoutAuthorization=re;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=ne;exports.user=_;
|
package/dist/doMock.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var r = (o, t, e) =>
|
|
4
|
-
import { j as
|
|
5
|
-
import
|
|
1
|
+
var y = Object.defineProperty;
|
|
2
|
+
var N = (o, t, e) => t in o ? y(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
|
+
var r = (o, t, e) => N(o, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { j as P, R as O, U as A, S as b } from "./SipConnector-C5s0hhzA.js";
|
|
5
|
+
import k 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 W } from "@krivega/jssip/lib/SIPMessage";
|
|
9
|
+
import { createAudioMediaStreamTrackMock as V, createVideoMediaStreamTrackMock as F } from "webrtc-mock";
|
|
10
10
|
import v from "events-constructor";
|
|
11
|
-
import { URI as
|
|
12
|
-
class
|
|
11
|
+
import { URI as E } from "@krivega/jssip";
|
|
12
|
+
class I extends W {
|
|
13
13
|
constructor(e) {
|
|
14
14
|
super();
|
|
15
15
|
r(this, "headers");
|
|
@@ -19,7 +19,7 @@ class T extends P {
|
|
|
19
19
|
return this.headers.get(e) || "";
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
class
|
|
22
|
+
class x {
|
|
23
23
|
// @ts-expect-error
|
|
24
24
|
constructor({ originator: t = "local", eventHandlers: e }) {
|
|
25
25
|
r(this, "originator");
|
|
@@ -27,7 +27,7 @@ class F {
|
|
|
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(P), this.initEvents(e);
|
|
31
31
|
}
|
|
32
32
|
// @ts-expect-error
|
|
33
33
|
get C() {
|
|
@@ -200,7 +200,7 @@ class F {
|
|
|
200
200
|
return !0;
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
class
|
|
203
|
+
class U {
|
|
204
204
|
constructor(t, e) {
|
|
205
205
|
r(this, "_senders", []);
|
|
206
206
|
r(this, "_receivers", []);
|
|
@@ -294,21 +294,20 @@ class x {
|
|
|
294
294
|
throw new Error("Method not implemented.");
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
|
-
function
|
|
297
|
+
function H(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 S extends F {
|
|
303
|
+
const p = 400, z = "777", Y = (o) => o.getVideoTracks().length > 0, a = class a extends x {
|
|
305
304
|
constructor({
|
|
306
305
|
url: e = "",
|
|
307
306
|
mediaStream: n,
|
|
308
307
|
eventHandlers: i,
|
|
309
|
-
originator:
|
|
308
|
+
originator: d
|
|
310
309
|
}) {
|
|
311
|
-
super({ originator:
|
|
310
|
+
super({ originator: d, eventHandlers: i });
|
|
312
311
|
r(this, "url");
|
|
313
312
|
r(this, "status_code");
|
|
314
313
|
r(this, "_isEnded", !1);
|
|
@@ -330,29 +329,40 @@ class S extends F {
|
|
|
330
329
|
}, 100), setTimeout(() => {
|
|
331
330
|
this.trigger("confirmed");
|
|
332
331
|
}, 200);
|
|
333
|
-
},
|
|
332
|
+
}, p);
|
|
334
333
|
}));
|
|
335
334
|
this.url = e, this.initPeerconnection(n);
|
|
336
335
|
}
|
|
336
|
+
static setStartPresentationError(e, { count: n = Number.POSITIVE_INFINITY } = {}) {
|
|
337
|
+
this.startPresentationError = e, this.countStartPresentationError = n;
|
|
338
|
+
}
|
|
339
|
+
static resetStartPresentationError() {
|
|
340
|
+
this.startPresentationError = void 0, this.countStartPresentationError = Number.POSITIVE_INFINITY, this.countStartsPresentation = 0;
|
|
341
|
+
}
|
|
342
|
+
async startPresentation(e) {
|
|
343
|
+
if (a.countStartsPresentation += 1, a.startPresentationError && a.countStartsPresentation < a.countStartPresentationError)
|
|
344
|
+
throw a.startPresentationError;
|
|
345
|
+
return super.startPresentation(e);
|
|
346
|
+
}
|
|
337
347
|
initPeerconnection(e) {
|
|
338
348
|
return e ? (this.createPeerconnection(e), !0) : !1;
|
|
339
349
|
}
|
|
340
350
|
createPeerconnection(e) {
|
|
341
|
-
const n =
|
|
351
|
+
const n = V();
|
|
342
352
|
n.id = "mainaudio1";
|
|
343
353
|
const i = [n];
|
|
344
|
-
if (
|
|
345
|
-
const
|
|
346
|
-
|
|
354
|
+
if (Y(e)) {
|
|
355
|
+
const h = F();
|
|
356
|
+
h.id = "mainvideo1", i.push(h);
|
|
347
357
|
}
|
|
348
|
-
this._connection = new
|
|
358
|
+
this._connection = new U(void 0, i), this._addStream(e), setTimeout(() => {
|
|
349
359
|
this.trigger("peerconnection", { peerconnection: this.connection });
|
|
350
|
-
},
|
|
360
|
+
}, p);
|
|
351
361
|
}
|
|
352
362
|
connect(e) {
|
|
353
|
-
const n =
|
|
363
|
+
const n = H(e);
|
|
354
364
|
setTimeout(() => {
|
|
355
|
-
this.url.includes(
|
|
365
|
+
this.url.includes(z) ? this.trigger("failed", {
|
|
356
366
|
originator: "remote",
|
|
357
367
|
message: "IncomingResponse",
|
|
358
368
|
cause: O
|
|
@@ -363,7 +373,7 @@ class S extends F {
|
|
|
363
373
|
}, 200), setTimeout(() => {
|
|
364
374
|
this.trigger("confirmed");
|
|
365
375
|
}, 300));
|
|
366
|
-
},
|
|
376
|
+
}, p);
|
|
367
377
|
}
|
|
368
378
|
terminate({ status_code: e } = {}) {
|
|
369
379
|
return this.status_code = e, this.trigger("ended", { status_code: e }), this._isEnded = !1, this;
|
|
@@ -423,7 +433,9 @@ class S extends F {
|
|
|
423
433
|
this.trigger("newInfo", e);
|
|
424
434
|
}
|
|
425
435
|
/* eslint-enable no-param-reassign */
|
|
426
|
-
}
|
|
436
|
+
};
|
|
437
|
+
r(a, "startPresentationError"), r(a, "countStartPresentationError", Number.POSITIVE_INFINITY), r(a, "countStartsPresentation", 0);
|
|
438
|
+
let u = a;
|
|
427
439
|
class q {
|
|
428
440
|
constructor() {
|
|
429
441
|
r(this, "extraHeaders");
|
|
@@ -434,7 +446,7 @@ class q {
|
|
|
434
446
|
setExtraContactParams() {
|
|
435
447
|
}
|
|
436
448
|
}
|
|
437
|
-
const
|
|
449
|
+
const c = "PASSWORD_CORRECT", T = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", m = 400, s = class s {
|
|
438
450
|
constructor(t) {
|
|
439
451
|
r(this, "_events");
|
|
440
452
|
r(this, "_startedTimeout");
|
|
@@ -447,14 +459,14 @@ const d = "PASSWORD_CORRECT", M = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", h
|
|
|
447
459
|
// @ts-expect-error
|
|
448
460
|
r(this, "call", jest.fn((t, e) => {
|
|
449
461
|
const { mediaStream: n, eventHandlers: i } = e;
|
|
450
|
-
return this.session = new
|
|
462
|
+
return this.session = new u({ url: t, mediaStream: n, eventHandlers: i, originator: "local" }), this.session.connect(t), this.session;
|
|
451
463
|
}));
|
|
452
464
|
this._events = new v(A);
|
|
453
|
-
const [e, n] = t.uri.split(":"), [i,
|
|
465
|
+
const [e, n] = t.uri.split(":"), [i, d] = n.split("@"), h = {
|
|
454
466
|
...t,
|
|
455
|
-
uri: new
|
|
467
|
+
uri: new E(e, i, d)
|
|
456
468
|
};
|
|
457
|
-
this.configuration =
|
|
469
|
+
this.configuration = h, this._registrator = new q();
|
|
458
470
|
}
|
|
459
471
|
static setStartError(t, { count: e = Number.POSITIVE_INFINITY } = {}) {
|
|
460
472
|
this.startError = t, this.countStartError = e;
|
|
@@ -491,7 +503,7 @@ const d = "PASSWORD_CORRECT", M = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", h
|
|
|
491
503
|
stop() {
|
|
492
504
|
this._startedTimeout && clearTimeout(this._startedTimeout), this._stopedTimeout && clearTimeout(this._stopedTimeout), this.unregister(), this.isStarted() ? this._stopedTimeout = setTimeout(() => {
|
|
493
505
|
this.trigger("disconnected", { error: new Error("stoped") });
|
|
494
|
-
},
|
|
506
|
+
}, m) : this.trigger("disconnected", { error: new Error("stoped") });
|
|
495
507
|
}
|
|
496
508
|
// @ts-expect-error
|
|
497
509
|
on(t, e) {
|
|
@@ -540,11 +552,11 @@ const d = "PASSWORD_CORRECT", M = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", h
|
|
|
540
552
|
const { password: t, register: e, uri: n } = this.configuration;
|
|
541
553
|
e && n.user.includes(j) ? (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
|
|
542
554
|
this.trigger("registrationFailed", { response: null, cause: "Request Timeout" });
|
|
543
|
-
},
|
|
555
|
+
}, m)) : !this._isRegistered && e && (t === c || t === T) ? (this._isRegistered = !0, this._startedTimeout = setTimeout(() => {
|
|
544
556
|
this.trigger("registered");
|
|
545
|
-
},
|
|
557
|
+
}, m)) : e && t !== c && t !== T && (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
|
|
546
558
|
this.trigger("registrationFailed", { response: null, cause: "Wrong credentials" });
|
|
547
|
-
},
|
|
559
|
+
}, m)), s.isAvailableTelephony ? (this.trigger("connected"), this._isConnected = !0) : this.stop();
|
|
548
560
|
}
|
|
549
561
|
/**
|
|
550
562
|
* unregister
|
|
@@ -578,14 +590,14 @@ const d = "PASSWORD_CORRECT", M = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", h
|
|
|
578
590
|
}
|
|
579
591
|
};
|
|
580
592
|
r(s, "isAvailableTelephony", !0), r(s, "startError"), r(s, "countStartError", Number.POSITIVE_INFINITY), r(s, "countStarts", 0);
|
|
581
|
-
let
|
|
582
|
-
class
|
|
593
|
+
let _ = s;
|
|
594
|
+
class B {
|
|
583
595
|
constructor(t) {
|
|
584
596
|
r(this, "url");
|
|
585
597
|
this.url = t;
|
|
586
598
|
}
|
|
587
599
|
}
|
|
588
|
-
class
|
|
600
|
+
class K extends L {
|
|
589
601
|
constructor(e, n) {
|
|
590
602
|
super();
|
|
591
603
|
r(this, "contentType");
|
|
@@ -593,102 +605,102 @@ class B extends L {
|
|
|
593
605
|
this.contentType = e, this.body = n;
|
|
594
606
|
}
|
|
595
607
|
}
|
|
596
|
-
const
|
|
597
|
-
const e = new
|
|
598
|
-
originator:
|
|
608
|
+
const w = "remote", $ = (o, t) => {
|
|
609
|
+
const e = new I(t), n = {
|
|
610
|
+
originator: w,
|
|
599
611
|
request: e,
|
|
600
|
-
info: new
|
|
612
|
+
info: new K("", "")
|
|
601
613
|
};
|
|
602
614
|
o.newInfo(n);
|
|
603
|
-
},
|
|
604
|
-
const n = { request: new
|
|
615
|
+
}, J = (o, t) => {
|
|
616
|
+
const n = { request: new I(t) };
|
|
605
617
|
o.newSipEvent(n);
|
|
606
|
-
},
|
|
618
|
+
}, G = (o, {
|
|
607
619
|
incomingNumber: t = "1234",
|
|
608
620
|
displayName: e,
|
|
609
621
|
host: n
|
|
610
622
|
}) => {
|
|
611
|
-
const i = new
|
|
612
|
-
i._remote_identity = new
|
|
613
|
-
},
|
|
623
|
+
const i = new u({ originator: w }), d = new D("sip", t, n);
|
|
624
|
+
i._remote_identity = new k(d, e), o.trigger("newRTCSession", { originator: w, session: i });
|
|
625
|
+
}, X = (o, t) => {
|
|
614
626
|
t ? o.trigger("failed", t) : o.trigger("failed", o);
|
|
615
627
|
}, R = {
|
|
616
|
-
triggerNewInfo:
|
|
617
|
-
triggerNewSipEvent:
|
|
618
|
-
triggerIncomingSession:
|
|
619
|
-
triggerFailIncomingSession:
|
|
620
|
-
WebSocketInterface:
|
|
621
|
-
UA:
|
|
628
|
+
triggerNewInfo: $,
|
|
629
|
+
triggerNewSipEvent: J,
|
|
630
|
+
triggerIncomingSession: G,
|
|
631
|
+
triggerFailIncomingSession: X,
|
|
632
|
+
WebSocketInterface: B,
|
|
633
|
+
UA: _,
|
|
622
634
|
C: {
|
|
623
635
|
INVITE: "INVITE"
|
|
624
636
|
}
|
|
625
|
-
},
|
|
637
|
+
}, f = "user", l = "displayName", M = "SIP_SERVER_URL", C = "SIP_WEB_SOCKET_SERVER_URL", Q = new R.WebSocketInterface(C), S = {
|
|
626
638
|
userAgent: "Chrome",
|
|
627
|
-
sipServerUrl:
|
|
639
|
+
sipServerUrl: M,
|
|
628
640
|
sipWebSocketServerURL: C
|
|
629
|
-
}, ce = {
|
|
630
|
-
...f
|
|
631
|
-
}, Q = {
|
|
632
|
-
...f,
|
|
633
|
-
user: w,
|
|
634
|
-
password: d,
|
|
635
|
-
register: !0
|
|
636
641
|
}, he = {
|
|
637
|
-
...
|
|
638
|
-
|
|
642
|
+
...S
|
|
643
|
+
}, Z = {
|
|
644
|
+
...S,
|
|
645
|
+
user: f,
|
|
646
|
+
password: c,
|
|
647
|
+
register: !0
|
|
639
648
|
}, me = {
|
|
640
|
-
...
|
|
641
|
-
displayName:
|
|
649
|
+
...Z,
|
|
650
|
+
displayName: l
|
|
651
|
+
}, ue = {
|
|
652
|
+
...S,
|
|
653
|
+
displayName: l,
|
|
642
654
|
register: !1
|
|
643
|
-
},
|
|
655
|
+
}, g = {
|
|
644
656
|
session_timers: !1,
|
|
645
|
-
sockets: [
|
|
657
|
+
sockets: [Q],
|
|
646
658
|
user_agent: "Chrome",
|
|
647
|
-
sdp_semantics: "plan
|
|
659
|
+
sdp_semantics: "unified-plan",
|
|
648
660
|
register_expires: 300,
|
|
649
661
|
connection_recovery_max_interval: 6,
|
|
650
662
|
connection_recovery_min_interval: 2
|
|
651
|
-
}, ue = {
|
|
652
|
-
...u,
|
|
653
|
-
password: d,
|
|
654
|
-
uri: new p("sip", w, E),
|
|
655
|
-
display_name: "",
|
|
656
|
-
register: !0
|
|
657
663
|
}, le = {
|
|
658
|
-
...
|
|
659
|
-
password:
|
|
660
|
-
uri: new
|
|
661
|
-
display_name:
|
|
664
|
+
...g,
|
|
665
|
+
password: c,
|
|
666
|
+
uri: new E("sip", f, M),
|
|
667
|
+
display_name: "",
|
|
662
668
|
register: !0
|
|
663
669
|
}, ge = {
|
|
664
|
-
...
|
|
665
|
-
|
|
670
|
+
...g,
|
|
671
|
+
password: c,
|
|
672
|
+
uri: new E("sip", f, M),
|
|
673
|
+
display_name: l,
|
|
674
|
+
register: !0
|
|
675
|
+
}, pe = {
|
|
676
|
+
...g,
|
|
677
|
+
display_name: l,
|
|
666
678
|
register: !1
|
|
667
679
|
}, _e = {
|
|
668
|
-
...
|
|
680
|
+
...g,
|
|
669
681
|
display_name: "",
|
|
670
682
|
register: !1
|
|
671
|
-
},
|
|
683
|
+
}, ee = "10.10.10.10", we = [`X-Vinteo-Remote: ${ee}`], Ee = () => new b({
|
|
672
684
|
JsSIP: R
|
|
673
685
|
});
|
|
674
686
|
export {
|
|
675
|
-
|
|
687
|
+
z as FAILED_CONFERENCE_NUMBER,
|
|
676
688
|
j as NAME_INCORRECT,
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
689
|
+
c as PASSWORD_CORRECT,
|
|
690
|
+
T as PASSWORD_CORRECT_2,
|
|
691
|
+
M as SIP_SERVER_URL,
|
|
680
692
|
C as SIP_WEB_SOCKET_SERVER_URL,
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
693
|
+
Z as dataForConnectionWithAuthorization,
|
|
694
|
+
me as dataForConnectionWithAuthorizationWithDisplayName,
|
|
695
|
+
ue as dataForConnectionWithoutAuthorization,
|
|
696
|
+
he as dataForConnectionWithoutAuthorizationWithoutDisplayName,
|
|
697
|
+
Ee as default,
|
|
698
|
+
l as displayName,
|
|
699
|
+
we as extraHeadersRemoteAddress,
|
|
700
|
+
ee as remoteAddress,
|
|
701
|
+
le as uaConfigurationWithAuthorization,
|
|
702
|
+
ge as uaConfigurationWithAuthorizationWithDisplayName,
|
|
703
|
+
pe as uaConfigurationWithoutAuthorization,
|
|
692
704
|
_e as uaConfigurationWithoutAuthorizationWithoutDisplayName,
|
|
693
|
-
|
|
705
|
+
f as user
|
|
694
706
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./SipConnector-3pnvrFP5.cjs"),K=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",p=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})=>K.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:u,onBeforeProgressCall:l,onSuccessProgressCall:d,onEnterPurgatory:m,onEnterConference:g,onFailProgressCall:C,onFinishProgressCall:S,onEndedCall:f}=n,M=D({setRemoteStreams:u,getRemoteStreams:I(e)}),y=V(M);r.logger("answerIncomingCall",n);const _=async()=>e.answerToIncomingCall({mediaStream:s,extraHeaders:o,iceServers:c,degradationPreference:a,ontrack:y}),h=()=>{const{remoteCallerData:i}=e;return i.incomingNumber};let R=!1,T;const b=(r.logger("subscribeEnterConference: onEnterConference",g),m??g?e.onSession("enterRoom",i=>{r.logger("enterRoom",{_room:i,isSuccessProgressCall:R}),T=i,p(T)?m&&m():g&&g({isSuccessProgressCall:R})}):()=>{}),v=i=>(r.logger("onSuccess"),R=!0,M(),d&&d({isPurgatory:p(T)}),e.onceRaceSession(["ended","failed"],()=>{b(),f&&f()}),i),O=i=>{throw r.logger("onFail"),C&&C(),b(),i},A=()=>{r.logger("onFinish"),S&&S()};if(r.logger("onBeforeProgressCall"),l){const i=h();l(i)}return _().then(v).catch(i=>O(i)).finally(A)},ne=e=>async n=>{const{conference:s,mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,setRemoteStreams:l,onBeforeProgressCall:d,onSuccessProgressCall:m,onEnterPurgatory:g,onEnterConference:C,onFailProgressCall:S,onFinishProgressCall:f,onEndedCall:M}=n,y=D({setRemoteStreams:l,getRemoteStreams:I(e)}),_=V(y);r.logger("callToServer",n);const h=async()=>(r.logger("startCall"),e.call({mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,number:s,ontrack:_}));let R=!1,T;const b=(r.logger("subscribeEnterConference: onEnterConference",C),g??C?e.onSession("enterRoom",({room:i})=>{r.logger("enterRoom",{_room:i,isSuccessProgressCall:R}),T=i,p(T)?g&&g():C&&C({isSuccessProgressCall:R})}):()=>{}),v=i=>(r.logger("onSuccess"),R=!0,y(),m&&m({isPurgatory:p(T)}),e.onceRaceSession(["ended","failed"],()=>{b(),M&&M()}),i),O=i=>{throw r.logger("onFail"),S&&S(),b(),i},A=()=>{r.logger("onFinish"),f&&f()};return r.logger("onBeforeProgressCall"),d&&d(s),h().then(v).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:u,name:l,password:d,isRegisteredUser:m,sdpSemantics:g,isDisconnectOnFail:C}=n;return r.logger("connectToServer",n),e.connect({userAgent:s,sdpSemantics:g,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,password:d,user:l,register:m}).then(S=>(r.logger("connectToServer then"),{ua:S,isSuccessful:!0})).catch(async S=>(r.logger("connectToServer catch: error",S),C===!0?e.disconnect().then(()=>P(S)).catch(()=>P(S)):P(S)))},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=>{let t="";try{t=JSON.stringify(e)}catch(n){r.logger("failed to stringify message",n)}return t},ce=(e=new Error)=>{const{code:t,cause:n,message:s}=e,o=w(e),c={code:"",cause:"",message:""};return typeof s=="object"&&s!==null?c.message=oe(s):s&&(c.message=String(s)),o&&(c.link=o),t&&(c.code=t),n&&(c.cause=n),c},ae=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:w,getTypeFromError:se,getValuesFromError:ce},Symbol.toStringTag,{value:"Module"})),ie=({sessionId:e,remoteAddress:t,isMutedAudio:n,isMutedVideo:s,isRegistered:o,isPresentationCall:c})=>{const a=[],u=n?"0":"1",l=s?"0":"1";return a.push(`X-Vinteo-Mic-State: ${u}`,`X-Vinteo-MainCam-State: ${l}`),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},ue="[@*!|]",le="_",ge=e=>{let t=e;return t=t.replaceAll(new RegExp(ue,"g"),le),t},Se=({appName:e,appVersion:t,browserName:n,browserVersion:s})=>{const c=`${ge(e)} ${t}`;return`ChromeNew - ${n?`${n} ${s}, ${c}`:c}`},de=({isUnifiedSdpSemantic:e,appVersion:t,browserName:n,browserVersion:s,appName:o})=>e?Se({appVersion:t,browserName:n,browserVersion:s,appName:o}):"Chrome",me=e=>async()=>{if(e.isCallActive)return r.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},fe=e=>n=>(r.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",n)),Ce=e=>n=>(r.logger("onMoveToSpectators"),e.onSession("participant:move-request-to-spectators",n)),Ee=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})},Re=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(n=>{r.logger("sendRefusalToTurnOnCam: error",n)})},Te=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(n=>{r.logger("sendRefusalToTurnOnMic: error",n)})},ye=1e6,be=({maxBitrate:e=ye,sipConnector:t})=>async({mediaStream:s,isP2P:o=!1})=>(r.logger("startPresentation"),t.startPresentation(s,{isP2P:o,maxBitrate:e})),_e=({sipConnector:e})=>async({isP2P:n=!1}={})=>(r.logger("stopShareSipConnector"),e.stopPresentation({isP2P:n}).catch(s=>{r.logger(s)})),he=1e6,ve=({sipConnector:e,maxBitrate:t=he})=>async({mediaStream:s,isP2P:o=!1})=>(r.logger("updatePresentation"),e.updatePresentation(s,{isP2P:o,maxBitrate:t})),Oe=e=>t=>[...t].map(s=>async()=>e(s)),Ae=async({accumulatedKeys:e,sendKey:t,canRunTask:n})=>{const o=Oe(t)(e);return z.sequentPromises(o,n)},pe=e=>n=>(r.logger("onStartMainCam"),e.onSession("admin-start-main-cam",n)),Ne=e=>n=>(r.logger("onStartMic"),e.onSession("admin-start-mic",n)),Pe=e=>n=>(r.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",n)),Be=e=>n=>(r.logger("onStopMic"),e.onSession("admin-stop-mic",n)),Ie=({sipConnector:e})=>{const t=(f,M)=>({isSyncForced:y=!1})=>{if(y){f();return}M()},n=pe(e),s=Pe(e),o=Ne(e),c=Be(e);let a=()=>{},u=()=>{},l=()=>{},d=()=>{};const m=({onStartMainCamForced:f,onStartMainCamNotForced:M,onStopMainCamForced:y,onStopMainCamNotForced:_,onStartMicForced:h,onStartMicNotForced:R,onStopMicForced:T,onStopMicNotForced:N})=>{const b=t(f,M);a=n(b);const v=t(y,_);u=s(v);const O=t(h,R);l=o(O);const A=t(T,N);d=c(A)},g=()=>{a(),u(),l(),d()};return{start:f=>{m(f)},stop:()=>{g()}}},De=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:L,createSyncMediaState:Ie,error:ae,getExtraHeaders:ie,getUserAgent:de,hasPurgatory:p,resolveAnswerIncomingCall:ee,resolveAskPermissionToEnableCam:me,resolveCallToServer:ne,resolveConnectToServer:te,resolveDisconnectFromServer:re,resolveGetRemoteStreams:I,resolveOnMoveToSpectators:Ce,resolveOnMustStopPresentation:fe,resolveOnUseLicense:Ee,resolveSendMediaState:Me,resolveSendRefusalToTurnOnCam:Re,resolveSendRefusalToTurnOnMic:Te,resolveStartPresentation:be,resolveStopShareSipConnector:_e,resolveUpdatePresentation:ve,resolveUpdateRemoteStreams:D,sendDTMFAccumulated:Ae},Symbol.toStringTag,{value:"Module"})),we=e=>[...e.keys()].map(t=>e.get(t)),Fe=(e,t)=>we(e).find(n=>n.type===t),x=async e=>e.getStats().then(t=>{const n=Fe(t,"codec");return n==null?void 0:n.mimeType}),ke=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()),Ue=1e6,E=e=>e*Ue,G=E(.06),Le=E(4),Ve=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):Le,$e="av1",xe=e=>q(e,$e),qe=.6,X=(e,t)=>xe(t)?e*qe:e,Ge=e=>X(G,e),W=(e,t)=>{const n=Ve(e);return X(n,t)},j=J.createStackPromises(),Xe=async()=>j().catch(e=>{r.logger("videoSendingBalancer: error",e)}),We=async e=>(j.add(e),Xe()),F=async({sender:e,scaleResolutionDownBy:t,maxBitrate:n,onSetParameters:s})=>We(async()=>r.setEncodingsToSender(e,{scaleResolutionDownBy:t,maxBitrate:n},s)),je=async({sender:e,codec:t},n)=>{const o=Ge(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,u=W(a,n);return F({sender:e,maxBitrate:u,onSetParameters:s,scaleResolutionDownBy:1})},Ke=async({sender:e,track:t,resolution:n,codec:s},o)=>{const c=t.getSettings(),a=c.width,u=c.height,[l,d]=n.split("x"),m=a/Number(l),g=u/Number(d),S=Math.max(m,g,1),f=W(Number(l),s);return F({sender:e,maxBitrate:f,onSetParameters:o,scaleResolutionDownBy:S})},He=async({mainCam:e,resolutionMainCam:t,sender:n,track:s,codec:o},c)=>{switch(e){case r.EEventsMainCAM.PAUSE_MAIN_CAM:return je({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?Ke({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=ke(c);if(!(a!=null&&a.track))return k;const u=await x(a);return q(u,o)?k:He({mainCam:e,resolutionMainCam:t,sender:a,codec:u,track:a.track},s)},Ye=(e,{ignoreForCodec:t,onSetParameters:n}={})=>{const s=async()=>{const{connection:l}=e;if(!l)throw new Error("connection is not exist");return U({connection:l,onSetParameters:n,ignoreForCodec:t})};let o=s;const c=async l=>(o=async()=>{const{mainCam:d,resolutionMainCam:m}=l,{connection:g}=e;if(!g)throw new Error("connection is not exist");return U({mainCam:d,resolutionMainCam:m,connection:g,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=x;exports.resolveVideoSendingBalancer=Ye;exports.tools=De;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./SipConnector-BA8w-WR5.cjs"),K=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",p=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})=>K.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:u,onBeforeProgressCall:l,onSuccessProgressCall:d,onEnterPurgatory:m,onEnterConference:g,onFailProgressCall:S,onFinishProgressCall:T,onEndedCall:f}=n,E=D({setRemoteStreams:u,getRemoteStreams:I(e)}),y=V(E);r.logger("answerIncomingCall",n);const _=async()=>e.answerToIncomingCall({mediaStream:s,extraHeaders:o,iceServers:c,degradationPreference:a,ontrack:y}),h=()=>{const{remoteCallerData:i}=e;return i.incomingNumber};let M=!1,R;const b=(r.logger("subscribeEnterConference: onEnterConference",g),m??g?e.onSession("enterRoom",i=>{r.logger("enterRoom",{_room:i,isSuccessProgressCall:M}),R=i,p(R)?m&&m():g&&g({isSuccessProgressCall:M})}):()=>{}),v=i=>(r.logger("onSuccess"),M=!0,E(),d&&d({isPurgatory:p(R)}),e.onceRaceSession(["ended","failed"],()=>{b(),f&&f()}),i),O=i=>{throw r.logger("onFail"),S&&S(),b(),i},A=()=>{r.logger("onFinish"),T&&T()};if(r.logger("onBeforeProgressCall"),l){const i=h();l(i)}return _().then(v).catch(i=>O(i)).finally(A)},ne=e=>async n=>{const{conference:s,mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,setRemoteStreams:l,onBeforeProgressCall:d,onSuccessProgressCall:m,onEnterPurgatory:g,onEnterConference:S,onFailProgressCall:T,onFinishProgressCall:f,onEndedCall:E}=n,y=D({setRemoteStreams:l,getRemoteStreams:I(e)}),_=V(y);r.logger("callToServer",n);const h=async()=>(r.logger("startCall"),e.call({mediaStream:o,extraHeaders:c,iceServers:a,degradationPreference:u,number:s,ontrack:_}));let M=!1,R;const b=(r.logger("subscribeEnterConference: onEnterConference",S),g??S?e.onSession("enterRoom",({room:i})=>{r.logger("enterRoom",{_room:i,isSuccessProgressCall:M}),R=i,p(R)?g&&g():S&&S({isSuccessProgressCall:M})}):()=>{}),v=i=>(r.logger("onSuccess"),M=!0,y(),m&&m({isPurgatory:p(R)}),e.onceRaceSession(["ended","failed"],()=>{b(),E&&E()}),i),O=i=>{throw r.logger("onFail"),T&&T(),b(),i},A=()=>{r.logger("onFinish"),f&&f()};return r.logger("onBeforeProgressCall"),d&&d(s),h().then(v).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:u,name:l,password:d,isRegisteredUser:m,isDisconnectOnFail:g}=n;return r.logger("connectToServer",n),e.connect({userAgent:s,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:u,password:d,user:l,register:m}).then(S=>(r.logger("connectToServer then"),{ua:S,isSuccessful:!0})).catch(async S=>(r.logger("connectToServer catch: error",S),g===!0?e.disconnect().then(()=>P(S)).catch(()=>P(S)):P(S)))},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=>{let t="";try{t=JSON.stringify(e)}catch(n){r.logger("failed to stringify message",n)}return t},ce=(e=new Error)=>{const{code:t,cause:n,message:s}=e,o=w(e),c={code:"",cause:"",message:""};return typeof s=="object"&&s!==null?c.message=oe(s):s&&(c.message=String(s)),o&&(c.link=o),t&&(c.code=t),n&&(c.cause=n),c},ae=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:w,getTypeFromError:se,getValuesFromError:ce},Symbol.toStringTag,{value:"Module"})),ie=({sessionId:e,remoteAddress:t,isMutedAudio:n,isMutedVideo:s,isRegistered:o,isPresentationCall:c})=>{const a=[],u=n?"0":"1",l=s?"0":"1";return a.push(`X-Vinteo-Mic-State: ${u}`,`X-Vinteo-MainCam-State: ${l}`),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},ue="[@*!|]",le="_",ge=e=>{let t=e;return t=t.replaceAll(new RegExp(ue,"g"),le),t},Se=({appName:e,appVersion:t,browserName:n,browserVersion:s})=>{const c=`${ge(e)} ${t}`;return`ChromeNew - ${n?`${n} ${s}, ${c}`:c}`},de=({isUnifiedSdpSemantic:e,appVersion:t,browserName:n,browserVersion:s,appName:o})=>e?Se({appVersion:t,browserName:n,browserVersion:s,appName:o}):"Chrome",me=e=>async()=>{if(e.isCallActive)return r.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},fe=e=>n=>(r.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",n)),Ce=e=>n=>(r.logger("onMoveToSpectators"),e.onSession("participant:move-request-to-spectators",n)),Ee=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})},Re=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(n=>{r.logger("sendRefusalToTurnOnCam: error",n)})},Te=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(n=>{r.logger("sendRefusalToTurnOnMic: error",n)})},ye=1e6,be=({maxBitrate:e=ye,sipConnector:t})=>async({mediaStream:s,isP2P:o=!1})=>(r.logger("startPresentation"),t.startPresentation(s,{isP2P:o,maxBitrate:e})),_e=({sipConnector:e})=>async({isP2P:n=!1}={})=>(r.logger("stopShareSipConnector"),e.stopPresentation({isP2P:n}).catch(s=>{r.logger(s)})),he=1e6,ve=({sipConnector:e,maxBitrate:t=he})=>async({mediaStream:s,isP2P:o=!1})=>(r.logger("updatePresentation"),e.updatePresentation(s,{isP2P:o,maxBitrate:t})),Oe=e=>t=>[...t].map(s=>async()=>e(s)),Ae=async({accumulatedKeys:e,sendKey:t,canRunTask:n})=>{const o=Oe(t)(e);return z.sequentPromises(o,n)},pe=e=>n=>(r.logger("onStartMainCam"),e.onSession("admin-start-main-cam",n)),Ne=e=>n=>(r.logger("onStartMic"),e.onSession("admin-start-mic",n)),Pe=e=>n=>(r.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",n)),Be=e=>n=>(r.logger("onStopMic"),e.onSession("admin-stop-mic",n)),Ie=({sipConnector:e})=>{const t=(f,E)=>({isSyncForced:y=!1})=>{if(y){f();return}E()},n=pe(e),s=Pe(e),o=Ne(e),c=Be(e);let a=()=>{},u=()=>{},l=()=>{},d=()=>{};const m=({onStartMainCamForced:f,onStartMainCamNotForced:E,onStopMainCamForced:y,onStopMainCamNotForced:_,onStartMicForced:h,onStartMicNotForced:M,onStopMicForced:R,onStopMicNotForced:N})=>{const b=t(f,E);a=n(b);const v=t(y,_);u=s(v);const O=t(h,M);l=o(O);const A=t(R,N);d=c(A)},g=()=>{a(),u(),l(),d()};return{start:f=>{m(f)},stop:()=>{g()}}},De=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:L,createSyncMediaState:Ie,error:ae,getExtraHeaders:ie,getUserAgent:de,hasPurgatory:p,resolveAnswerIncomingCall:ee,resolveAskPermissionToEnableCam:me,resolveCallToServer:ne,resolveConnectToServer:te,resolveDisconnectFromServer:re,resolveGetRemoteStreams:I,resolveOnMoveToSpectators:Ce,resolveOnMustStopPresentation:fe,resolveOnUseLicense:Ee,resolveSendMediaState:Me,resolveSendRefusalToTurnOnCam:Re,resolveSendRefusalToTurnOnMic:Te,resolveStartPresentation:be,resolveStopShareSipConnector:_e,resolveUpdatePresentation:ve,resolveUpdateRemoteStreams:D,sendDTMFAccumulated:Ae},Symbol.toStringTag,{value:"Module"})),we=e=>[...e.keys()].map(t=>e.get(t)),Fe=(e,t)=>we(e).find(n=>n.type===t),x=async e=>e.getStats().then(t=>{const n=Fe(t,"codec");return n==null?void 0:n.mimeType}),ke=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()),Ue=1e6,C=e=>e*Ue,G=C(.06),Le=C(4),Ve=e=>e<=64?G:e<=128?C(.12):e<=256?C(.25):e<=384?C(.32):e<=426?C(.38):e<=640?C(.5):e<=848?C(.7):e<=1280?C(1):e<=1920?C(2):Le,$e="av1",xe=e=>q(e,$e),qe=.6,X=(e,t)=>xe(t)?e*qe:e,Ge=e=>X(G,e),W=(e,t)=>{const n=Ve(e);return X(n,t)},j=J.createStackPromises(),Xe=async()=>j().catch(e=>{r.logger("videoSendingBalancer: error",e)}),We=async e=>(j.add(e),Xe()),F=async({sender:e,scaleResolutionDownBy:t,maxBitrate:n,onSetParameters:s})=>We(async()=>r.setEncodingsToSender(e,{scaleResolutionDownBy:t,maxBitrate:n},s)),je=async({sender:e,codec:t},n)=>{const o=Ge(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,u=W(a,n);return F({sender:e,maxBitrate:u,onSetParameters:s,scaleResolutionDownBy:1})},Ke=async({sender:e,track:t,resolution:n,codec:s},o)=>{const c=t.getSettings(),a=c.width,u=c.height,[l,d]=n.split("x"),m=a/Number(l),g=u/Number(d),T=Math.max(m,g,1),f=W(Number(l),s);return F({sender:e,maxBitrate:f,onSetParameters:o,scaleResolutionDownBy:T})},He=async({mainCam:e,resolutionMainCam:t,sender:n,track:s,codec:o},c)=>{switch(e){case r.EEventsMainCAM.PAUSE_MAIN_CAM:return je({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?Ke({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=ke(c);if(!(a!=null&&a.track))return k;const u=await x(a);return q(u,o)?k:He({mainCam:e,resolutionMainCam:t,sender:a,codec:u,track:a.track},s)},Ye=(e,{ignoreForCodec:t,onSetParameters:n}={})=>{const s=async()=>{const{connection:l}=e;if(!l)throw new Error("connection is not exist");return U({connection:l,onSetParameters:n,ignoreForCodec:t})};let o=s;const c=async l=>(o=async()=>{const{mainCam:d,resolutionMainCam:m}=l,{connection:g}=e;if(!g)throw new Error("connection is not exist");return U({mainCam:d,resolutionMainCam:m,connection:g,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=x;exports.resolveVideoSendingBalancer=Ye;exports.tools=De;
|