sip-connector 10.0.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SipConnector-5B3QzrjB.cjs +1 -0
- package/dist/{SipConnector-P-kMtUcq.js → SipConnector-zEWljwQJ.js} +496 -487
- package/dist/SipConnector.d.ts +14 -9
- package/dist/__fixtures__/RTCRtpSenderMock.d.ts +1 -0
- package/dist/doMock.cjs +1 -1
- package/dist/doMock.js +20 -15
- package/dist/index.cjs +1 -1
- package/dist/index.js +239 -241
- package/dist/setParametersToSender/configureEncodings.d.ts +1 -8
- package/dist/tools/answerIncomingCall.d.ts +2 -2
- package/dist/tools/callToServer.d.ts +2 -2
- package/dist/tools/resolveStartPresentation.d.ts +3 -3
- package/dist/tools/resolveUpdatePresentation.d.ts +3 -3
- package/dist/types.d.ts +1 -1
- package/package.json +4 -4
- package/dist/SipConnector-93CcnqPF.cjs +0 -1
- package/dist/tools/resolveHandleAddedSender.d.ts +0 -3
package/dist/SipConnector.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IncomingInfoEvent, IncomingRTCSessionEvent, IncomingRequest, OutgoingInfoEvent, RTCSession, RegisteredEvent, UA, UAConfigurationParams, URI, UnRegisteredEvent, WebSocketInterface } from '@krivega/jssip';
|
|
2
2
|
import { TEventSession, TEventUA } from './eventNames';
|
|
3
|
-
import { TContentHint, TCustomError, TJsSIP,
|
|
3
|
+
import { TContentHint, TCustomError, TJsSIP, TOnAddedTransceiver } from './types';
|
|
4
4
|
export declare const hasCanceledCallError: (error?: TCustomError) => boolean;
|
|
5
5
|
type TChannels = {
|
|
6
6
|
inputChannels: string;
|
|
@@ -110,7 +110,7 @@ type TSet = ({ displayName, password, }: {
|
|
|
110
110
|
displayName?: string;
|
|
111
111
|
password?: string;
|
|
112
112
|
}) => Promise<boolean>;
|
|
113
|
-
type TCall = ({ number, mediaStream, extraHeaders, ontrack, iceServers, videoMode, audioMode, offerToReceiveAudio, offerToReceiveVideo,
|
|
113
|
+
type TCall = ({ number, mediaStream, extraHeaders, ontrack, iceServers, videoMode, audioMode, offerToReceiveAudio, offerToReceiveVideo, contentHint, sendEncodings, onAddedTransceiver, }: {
|
|
114
114
|
number: string;
|
|
115
115
|
mediaStream: MediaStream;
|
|
116
116
|
extraHeaders?: TOptionsExtraHeaders['extraHeaders'];
|
|
@@ -120,8 +120,9 @@ type TCall = ({ number, mediaStream, extraHeaders, ontrack, iceServers, videoMod
|
|
|
120
120
|
audioMode?: 'recvonly' | 'sendonly' | 'sendrecv';
|
|
121
121
|
offerToReceiveAudio?: boolean;
|
|
122
122
|
offerToReceiveVideo?: boolean;
|
|
123
|
-
onAddedSender?: TOnAddedSender;
|
|
124
123
|
contentHint?: TContentHint;
|
|
124
|
+
sendEncodings?: RTCRtpEncodingParameters[];
|
|
125
|
+
onAddedTransceiver?: TOnAddedTransceiver;
|
|
125
126
|
}) => Promise<RTCPeerConnection>;
|
|
126
127
|
type TDisconnect = () => Promise<void>;
|
|
127
128
|
type TParametersAnswerToIncomingCall = {
|
|
@@ -131,8 +132,9 @@ type TParametersAnswerToIncomingCall = {
|
|
|
131
132
|
iceServers?: RTCIceServer[];
|
|
132
133
|
videoMode?: 'recvonly' | 'sendonly' | 'sendrecv';
|
|
133
134
|
audioMode?: 'recvonly' | 'sendonly' | 'sendrecv';
|
|
134
|
-
onAddedSender?: TOnAddedSender;
|
|
135
135
|
contentHint?: TContentHint;
|
|
136
|
+
sendEncodings?: RTCRtpEncodingParameters[];
|
|
137
|
+
onAddedTransceiver?: TOnAddedTransceiver;
|
|
136
138
|
};
|
|
137
139
|
type TAnswerToIncomingCall = (parameters: TParametersAnswerToIncomingCall) => Promise<RTCPeerConnection>;
|
|
138
140
|
type TSendDTMF = (tone: number | string) => Promise<void>;
|
|
@@ -183,7 +185,8 @@ export default class SipConnector {
|
|
|
183
185
|
addMissing: boolean;
|
|
184
186
|
forceRenegotiation: boolean;
|
|
185
187
|
contentHint?: TContentHint;
|
|
186
|
-
|
|
188
|
+
sendEncodings?: RTCRtpEncodingParameters[];
|
|
189
|
+
onAddedTransceiver?: TOnAddedTransceiver;
|
|
187
190
|
}): Promise<void>;
|
|
188
191
|
declineToIncomingCall: ({ statusCode }?: {
|
|
189
192
|
statusCode?: number | undefined;
|
|
@@ -197,12 +200,13 @@ export default class SipConnector {
|
|
|
197
200
|
private hasEqualConnectionConfiguration;
|
|
198
201
|
private createUaConfiguration;
|
|
199
202
|
private _sendPresentation;
|
|
200
|
-
startPresentation(stream: MediaStream, { isNeedReinvite, isP2P, maxBitrate,
|
|
203
|
+
startPresentation(stream: MediaStream, { isNeedReinvite, isP2P, maxBitrate, contentHint, sendEncodings, onAddedTransceiver, }?: {
|
|
201
204
|
isNeedReinvite?: boolean;
|
|
202
205
|
isP2P?: boolean;
|
|
203
206
|
maxBitrate?: number;
|
|
204
|
-
onAddedSender?: TOnAddedSender;
|
|
205
207
|
contentHint?: TContentHint;
|
|
208
|
+
sendEncodings?: RTCRtpEncodingParameters[];
|
|
209
|
+
onAddedTransceiver?: TOnAddedTransceiver;
|
|
206
210
|
}, options?: {
|
|
207
211
|
callLimit: number;
|
|
208
212
|
}): Promise<MediaStream>;
|
|
@@ -210,11 +214,12 @@ export default class SipConnector {
|
|
|
210
214
|
stopPresentation({ isP2P, }?: {
|
|
211
215
|
isP2P?: boolean;
|
|
212
216
|
}): Promise<MediaStream | void>;
|
|
213
|
-
updatePresentation(stream: MediaStream, { isP2P, maxBitrate,
|
|
217
|
+
updatePresentation(stream: MediaStream, { isP2P, maxBitrate, contentHint, sendEncodings, onAddedTransceiver, }?: {
|
|
214
218
|
isP2P?: boolean;
|
|
215
219
|
maxBitrate?: number;
|
|
216
|
-
onAddedSender?: TOnAddedSender;
|
|
217
220
|
contentHint?: TContentHint;
|
|
221
|
+
sendEncodings?: RTCRtpEncodingParameters[];
|
|
222
|
+
onAddedTransceiver?: TOnAddedTransceiver;
|
|
218
223
|
}): Promise<MediaStream | void>;
|
|
219
224
|
_removeStreamPresentationCurrent(): void;
|
|
220
225
|
_resetPresentation(): void;
|
package/dist/doMock.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var k=Object.defineProperty;var b=(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)=>b(o,typeof t!="symbol"?t+"":t,e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("./SipConnector-93CcnqPF.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({track:t}={}){r(this,"dtmf",null);r(this,"track",null);r(this,"transport",null);r(this,"transform",null);r(this,"_parameters",{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}});this.track=t??null}async getStats(){throw new Error("Method not implemented.")}async replaceTrack(t){this.track=t??null}async setParameters(t){const{transactionId:e}=this._parameters;this._parameters={...this._parameters,...t,transactionId:`${Number(e)+1}`}}getParameters(){return{...this._parameters}}setStreams(){throw new Error("Method not implemented.")}}class q{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=new U({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 x(o){const t=o.match(/(purgatory)|[\d.]+/g);if(!t)throw new Error("wrong sip url");return t[0]}const w=400,N="777",H=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(H(e)){const u=C.createVideoMediaStreamTrackMock();u.id="mainvideo1",i.push(u)}this._connection=new q(void 0,i),this._addStream(e),setTimeout(()=>{this.trigger("peerconnection",{peerconnection:this.connection})},w)}connect(e){const n=x(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 Y{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 Y}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 j{constructor(t){r(this,"url");this.url=t}}class B extends F.EventEmitter{constructor(e,n){super();r(this,"contentType");r(this,"body");this.contentType=e,this.body=n}}const S="remote",K=(o,t)=>{const e=new y(t),n={originator:S,request:e,info:new B("","")};o.newInfo(n)},$=(o,t)=>{const n={request:new y(t)};o.newSipEvent(n)},J=(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})},G=(o,t)=>{t?o.trigger("failed",t):o.trigger("failed",o)},A={triggerNewInfo:K,triggerNewSipEvent:$,triggerIncomingSession:J,triggerFailIncomingSession:G,WebSocketInterface:j,UA:M,C:{INVITE:"INVITE"}},_="user",h="displayName",p="SIP_SERVER_URL",R="SIP_WEB_SOCKET_SERVER_URL",X=new A.WebSocketInterface(R),v={userAgent:"Chrome",sipServerUrl:p,sipWebSocketServerURL:R},Q={...v},O={...v,user:_,password:c,register:!0},Z={...O,displayName:h},ee={...v,displayName:h,register:!1},E={session_timers:!1,sockets:[X],user_agent:"Chrome",sdp_semantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},te={...E,password:c,uri:new T.URI("sip",_,p),display_name:"",register:!0},re={...E,password:c,uri:new T.URI("sip",_,p),display_name:h,register:!0},ne={...E,display_name:h,register:!1},oe={...E,display_name:"",register:!1},W="10.10.10.10",ie=[`X-Vinteo-Remote: ${W}`],se=()=>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=p;exports.SIP_WEB_SOCKET_SERVER_URL=R;exports.dataForConnectionWithAuthorization=O;exports.dataForConnectionWithAuthorizationWithDisplayName=Z;exports.dataForConnectionWithoutAuthorization=ee;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=Q;exports.default=se;exports.displayName=h;exports.extraHeadersRemoteAddress=ie;exports.remoteAddress=W;exports.uaConfigurationWithAuthorization=te;exports.uaConfigurationWithAuthorizationWithDisplayName=re;exports.uaConfigurationWithoutAuthorization=ne;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=oe;exports.user=_;
|
|
1
|
+
"use strict";var k=Object.defineProperty;var b=(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)=>b(o,typeof t!="symbol"?t+"":t,e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const g=require("./SipConnector-5B3QzrjB.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 x{constructor({track:t}={}){r(this,"dtmf",null);r(this,"track",null);r(this,"transport",null);r(this,"transform",null);r(this,"_parameters",{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}});r(this,"_parametersGets");this.track=t??null}async getStats(){throw new Error("Method not implemented.")}async replaceTrack(t){this.track=t??null}async setParameters(t){if(t!==this._parametersGets)throw new Error("Failed to execute 'setParameters' on 'RTCRtpSender': Read-only field modified in setParameters().");const{transactionId:e}=this._parameters;this._parameters={...this._parameters,...t,transactionId:`${Number(e)+1}`}}getParameters(){return this._parametersGets={...this._parameters},this._parametersGets}setStreams(){throw new Error("Method not implemented.")}}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=new x({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",H=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(H(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 Y{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 Y}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 j{constructor(t){r(this,"url");this.url=t}}class B extends F.EventEmitter{constructor(e,n){super();r(this,"contentType");r(this,"body");this.contentType=e,this.body=n}}const S="remote",G=(o,t)=>{const e=new y(t),n={originator:S,request:e,info:new B("","")};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:G,triggerNewSipEvent:K,triggerIncomingSession:$,triggerFailIncomingSession:J,WebSocketInterface:j,UA:M,C:{INVITE:"INVITE"}},_="user",h="displayName",p="SIP_SERVER_URL",R="SIP_WEB_SOCKET_SERVER_URL",X=new A.WebSocketInterface(R),v={userAgent:"Chrome",sipServerUrl:p,sipWebSocketServerURL:R},Q={...v},O={...v,user:_,password:c,register:!0},Z={...O,displayName:h},ee={...v,displayName:h,register:!1},E={session_timers:!1,sockets:[X],user_agent:"Chrome",sdp_semantics:"unified-plan",register_expires:300,connection_recovery_max_interval:6,connection_recovery_min_interval:2},te={...E,password:c,uri:new T.URI("sip",_,p),display_name:"",register:!0},re={...E,password:c,uri:new T.URI("sip",_,p),display_name:h,register:!0},ne={...E,display_name:h,register:!1},oe={...E,display_name:"",register:!1},W="10.10.10.10",ie=[`X-Vinteo-Remote: ${W}`],se=()=>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=p;exports.SIP_WEB_SOCKET_SERVER_URL=R;exports.dataForConnectionWithAuthorization=O;exports.dataForConnectionWithAuthorizationWithDisplayName=Z;exports.dataForConnectionWithoutAuthorization=ee;exports.dataForConnectionWithoutAuthorizationWithoutDisplayName=Q;exports.default=se;exports.displayName=h;exports.extraHeadersRemoteAddress=ie;exports.remoteAddress=W;exports.uaConfigurationWithAuthorization=te;exports.uaConfigurationWithAuthorizationWithDisplayName=re;exports.uaConfigurationWithoutAuthorization=ne;exports.uaConfigurationWithoutAuthorizationWithoutDisplayName=oe;exports.user=_;
|
package/dist/doMock.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var y = Object.defineProperty;
|
|
2
2
|
var N = (o, t, e) => t in o ? y(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
|
|
3
3
|
var r = (o, t, e) => N(o, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { k as P, R as O, U as k, S as A } from "./SipConnector-
|
|
4
|
+
import { k as P, R as O, U as k, S as A } from "./SipConnector-zEWljwQJ.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";
|
|
@@ -214,6 +214,7 @@ class U {
|
|
|
214
214
|
headerExtensions: [],
|
|
215
215
|
rtcp: {}
|
|
216
216
|
});
|
|
217
|
+
r(this, "_parametersGets");
|
|
217
218
|
this.track = t ?? null;
|
|
218
219
|
}
|
|
219
220
|
async getStats() {
|
|
@@ -223,6 +224,10 @@ class U {
|
|
|
223
224
|
this.track = t ?? null;
|
|
224
225
|
}
|
|
225
226
|
async setParameters(t) {
|
|
227
|
+
if (t !== this._parametersGets)
|
|
228
|
+
throw new Error(
|
|
229
|
+
"Failed to execute 'setParameters' on 'RTCRtpSender': Read-only field modified in setParameters()."
|
|
230
|
+
);
|
|
226
231
|
const { transactionId: e } = this._parameters;
|
|
227
232
|
this._parameters = {
|
|
228
233
|
...this._parameters,
|
|
@@ -231,7 +236,7 @@ class U {
|
|
|
231
236
|
};
|
|
232
237
|
}
|
|
233
238
|
getParameters() {
|
|
234
|
-
return { ...this._parameters };
|
|
239
|
+
return this._parametersGets = { ...this._parameters }, this._parametersGets;
|
|
235
240
|
}
|
|
236
241
|
setStreams() {
|
|
237
242
|
throw new Error("Method not implemented.");
|
|
@@ -473,7 +478,7 @@ const p = 400, Y = "777", q = (o) => o.getVideoTracks().length > 0, a = class a
|
|
|
473
478
|
};
|
|
474
479
|
r(a, "startPresentationError"), r(a, "countStartPresentationError", Number.POSITIVE_INFINITY), r(a, "countStartsPresentation", 0);
|
|
475
480
|
let u = a;
|
|
476
|
-
class
|
|
481
|
+
class G {
|
|
477
482
|
constructor() {
|
|
478
483
|
r(this, "extraHeaders", []);
|
|
479
484
|
}
|
|
@@ -483,7 +488,7 @@ class j {
|
|
|
483
488
|
setExtraContactParams() {
|
|
484
489
|
}
|
|
485
490
|
}
|
|
486
|
-
const c = "PASSWORD_CORRECT", T = "PASSWORD_CORRECT_2",
|
|
491
|
+
const c = "PASSWORD_CORRECT", T = "PASSWORD_CORRECT_2", j = "NAME_INCORRECT", m = 400, s = class s {
|
|
487
492
|
constructor(t) {
|
|
488
493
|
r(this, "_events");
|
|
489
494
|
r(this, "_startedTimeout");
|
|
@@ -503,7 +508,7 @@ const c = "PASSWORD_CORRECT", T = "PASSWORD_CORRECT_2", B = "NAME_INCORRECT", m
|
|
|
503
508
|
...t,
|
|
504
509
|
uri: new E(e, i, d)
|
|
505
510
|
};
|
|
506
|
-
this.configuration = h, this._registrator = new
|
|
511
|
+
this.configuration = h, this._registrator = new G();
|
|
507
512
|
}
|
|
508
513
|
static setStartError(t, { count: e = Number.POSITIVE_INFINITY } = {}) {
|
|
509
514
|
this.startError = t, this.countStartError = e;
|
|
@@ -587,7 +592,7 @@ const c = "PASSWORD_CORRECT", T = "PASSWORD_CORRECT_2", B = "NAME_INCORRECT", m
|
|
|
587
592
|
register() {
|
|
588
593
|
this._startedTimeout && clearTimeout(this._startedTimeout);
|
|
589
594
|
const { password: t, register: e, uri: n } = this.configuration;
|
|
590
|
-
e && n.user.includes(
|
|
595
|
+
e && n.user.includes(j) ? (this._isRegistered = !1, this._isConnected = !1, this._startedTimeout = setTimeout(() => {
|
|
591
596
|
this.trigger("registrationFailed", { response: null, cause: "Request Timeout" });
|
|
592
597
|
}, m)) : !this._isRegistered && e && (t === c || t === T) ? (this._isRegistered = !0, this._startedTimeout = setTimeout(() => {
|
|
593
598
|
this.trigger("registered");
|
|
@@ -628,13 +633,13 @@ const c = "PASSWORD_CORRECT", T = "PASSWORD_CORRECT_2", B = "NAME_INCORRECT", m
|
|
|
628
633
|
};
|
|
629
634
|
r(s, "isAvailableTelephony", !0), r(s, "startError"), r(s, "countStartError", Number.POSITIVE_INFINITY), r(s, "countStarts", 0);
|
|
630
635
|
let _ = s;
|
|
631
|
-
class
|
|
636
|
+
class B {
|
|
632
637
|
constructor(t) {
|
|
633
638
|
r(this, "url");
|
|
634
639
|
this.url = t;
|
|
635
640
|
}
|
|
636
641
|
}
|
|
637
|
-
class
|
|
642
|
+
class $ extends L {
|
|
638
643
|
constructor(e, n) {
|
|
639
644
|
super();
|
|
640
645
|
r(this, "contentType");
|
|
@@ -642,14 +647,14 @@ class K extends L {
|
|
|
642
647
|
this.contentType = e, this.body = n;
|
|
643
648
|
}
|
|
644
649
|
}
|
|
645
|
-
const w = "remote",
|
|
650
|
+
const w = "remote", K = (o, t) => {
|
|
646
651
|
const e = new I(t), n = {
|
|
647
652
|
originator: w,
|
|
648
653
|
request: e,
|
|
649
|
-
info: new
|
|
654
|
+
info: new $("", "")
|
|
650
655
|
};
|
|
651
656
|
o.newInfo(n);
|
|
652
|
-
},
|
|
657
|
+
}, J = (o, t) => {
|
|
653
658
|
const n = { request: new I(t) };
|
|
654
659
|
o.newSipEvent(n);
|
|
655
660
|
}, X = (o, {
|
|
@@ -662,11 +667,11 @@ const w = "remote", J = (o, t) => {
|
|
|
662
667
|
}, Q = (o, t) => {
|
|
663
668
|
t ? o.trigger("failed", t) : o.trigger("failed", o);
|
|
664
669
|
}, R = {
|
|
665
|
-
triggerNewInfo:
|
|
666
|
-
triggerNewSipEvent:
|
|
670
|
+
triggerNewInfo: K,
|
|
671
|
+
triggerNewSipEvent: J,
|
|
667
672
|
triggerIncomingSession: X,
|
|
668
673
|
triggerFailIncomingSession: Q,
|
|
669
|
-
WebSocketInterface:
|
|
674
|
+
WebSocketInterface: B,
|
|
670
675
|
UA: _,
|
|
671
676
|
C: {
|
|
672
677
|
INVITE: "INVITE"
|
|
@@ -722,7 +727,7 @@ const w = "remote", J = (o, t) => {
|
|
|
722
727
|
});
|
|
723
728
|
export {
|
|
724
729
|
Y as FAILED_CONFERENCE_NUMBER,
|
|
725
|
-
|
|
730
|
+
j as NAME_INCORRECT,
|
|
726
731
|
c as PASSWORD_CORRECT,
|
|
727
732
|
T as PASSWORD_CORRECT_2,
|
|
728
733
|
M as SIP_SERVER_URL,
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./SipConnector-93CcnqPF.cjs"),Y=require("ts-debounce"),z=require("@krivega/cancelable-promise"),J=require("repeated-calls"),Q=require("sequent-promises"),Z=require("stack-promises"),ee=require("debug"),x="purgatory",p=e=>e===x,w=e=>()=>(r.logger("getRemoteStreams"),e.getRemoteStreams()),N=e=>async(t,n)=>{n.kind==="video"&&e!==void 0&&await r.setParametersToSender(t,e)},ne=({kind:e,readyState:t})=>e==="video"&&t==="live",$=e=>({track:t})=>{ne(t)&&e()},F=({getRemoteStreams:e,setRemoteStreams:t})=>Y.debounce(()=>{const n=e();r.logger("remoteStreams",n),n&&t(n)},200),te=e=>async n=>{const{mediaStream:s,extraHeaders:o,iceServers:a,rtpSendParameters:c,contentHint:i,setRemoteStreams:l,onBeforeProgressCall:d,onSuccessProgressCall:m,onEnterPurgatory:S,onEnterConference:g,onFailProgressCall:C,onFinishProgressCall:f,onEndedCall:R}=n,M=F({setRemoteStreams:l,getRemoteStreams:w(e)}),v=$(M);r.logger("answerIncomingCall",n);const _=async()=>e.answerToIncomingCall({mediaStream:s,extraHeaders:o,iceServers:a,contentHint:i,onAddedSender:N(c),ontrack:v}),h=()=>{const{remoteCallerData:u}=e;return u.incomingNumber};let T=!1,y;const b=(r.logger("subscribeEnterConference: onEnterConference",g),S??g?e.onSession("enterRoom",u=>{r.logger("enterRoom",{_room:u,isSuccessProgressCall:T}),y=u,p(y)?S&&S():g&&g({isSuccessProgressCall:T})}):()=>{}),O=u=>(r.logger("onSuccess"),T=!0,M(),m&&m({isPurgatory:p(y)}),e.onceRaceSession(["ended","failed"],()=>{b(),R&&R()}),u),A=u=>{throw r.logger("onFail"),C&&C(),b(),u},B=()=>{r.logger("onFinish"),f&&f()};if(r.logger("onBeforeProgressCall"),d){const u=h();d(u)}return _().then(O).catch(u=>A(u)).finally(B)},re=e=>async n=>{const{conference:s,mediaStream:o,extraHeaders:a,iceServers:c,rtpSendParameters:i,contentHint:l,setRemoteStreams:d,onBeforeProgressCall:m,onSuccessProgressCall:S,onEnterPurgatory:g,onEnterConference:C,onFailProgressCall:f,onFinishProgressCall:R,onEndedCall:M}=n,v=F({setRemoteStreams:d,getRemoteStreams:w(e)}),_=$(v);r.logger("callToServer",n);const h=async()=>(r.logger("startCall"),e.call({mediaStream:o,extraHeaders:a,iceServers:c,contentHint:l,number:s,ontrack:_,onAddedSender:N(i)}));let T=!1,y;const b=(r.logger("subscribeEnterConference: onEnterConference",C),g??C?e.onSession("enterRoom",({room:u})=>{r.logger("enterRoom",{_room:u,isSuccessProgressCall:T}),y=u,p(y)?g&&g():C&&C({isSuccessProgressCall:T})}):()=>{}),O=u=>(r.logger("onSuccess"),T=!0,v(),S&&S({isPurgatory:p(y)}),e.onceRaceSession(["ended","failed"],()=>{b(),M&&M()}),u),A=u=>{throw r.logger("onFail"),f&&f(),b(),u},B=()=>{r.logger("onFinish"),R&&R()};return r.logger("onBeforeProgressCall"),m&&m(s),h().then(O).catch(u=>A(u)).finally(B)},D=e=>{if(!z.isCanceledError(e)&&!J.hasCanceledError(e))throw e;return{isSuccessful:!1}},se=e=>async n=>{const{userAgent:s,sipWebSocketServerURL:o,sipServerUrl:a,remoteAddress:c,displayName:i,name:l,password:d,isRegisteredUser:m,isDisconnectOnFail:S}=n;return r.logger("connectToServer",n),e.connect({userAgent:s,sipWebSocketServerURL:o,sipServerUrl:a,remoteAddress:c,displayName:i,password:d,user:l,register:m}).then(g=>(r.logger("connectToServer then"),{ua:g,isSuccessful:!0})).catch(async g=>(r.logger("connectToServer catch: error",g),S===!0?e.disconnect().then(()=>D(g)).catch(()=>D(g)):D(g)))},oe=e=>async()=>(r.logger("disconnectFromServer"),e.disconnect().then(()=>(r.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(t=>(r.logger("disconnectFromServer: catch",t),{isSuccessful:!1}))),k=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 q=(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))(q||{});const ae=(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":k(e)&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},ce=e=>{let t="";try{t=JSON.stringify(e)}catch(n){r.logger("failed to stringify message",n)}return t},ie=(e=new Error)=>{const{code:t,cause:n,message:s}=e,o=k(e),a={code:"",cause:"",message:""};return typeof s=="object"&&s!==null?a.message=ce(s):s&&(a.message=String(s)),o&&(a.link=o),t&&(a.code=t),n&&(a.cause=n),a},ue=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:q,getLinkError:k,getTypeFromError:ae,getValuesFromError:ie},Symbol.toStringTag,{value:"Module"})),le=({sessionId:e,remoteAddress:t,isMutedAudio:n,isMutedVideo:s,isRegistered:o,isPresentationCall:a})=>{const c=[],i=n?"0":"1",l=s?"0":"1";return c.push(`X-Vinteo-Mic-State: ${i}`,`X-Vinteo-MainCam-State: ${l}`),o||c.push("X-Vinteo-Purgatory-Call: yes"),e&&c.push(`X-Vinteo-Session: ${e}`),a&&c.push("X-Vinteo-Presentation-Call: yes"),t&&c.push(`X-Vinteo-Remote: ${t}`),c},ge="[@*!|]",Se="_",de=e=>{let t=e;return t=t.replaceAll(new RegExp(ge,"g"),Se),t},me=({appName:e,appVersion:t,browserName:n,browserVersion:s})=>{const a=`${de(e)} ${t}`;return`ChromeNew - ${n?`${n} ${s}, ${a}`:a}`},fe=({isUnifiedSdpSemantic:e,appVersion:t,browserName:n,browserVersion:s,appName:o})=>e?me({appVersion:t,browserName:n,browserVersion:s,appName:o}):"Chrome",Ce=e=>async()=>{if(e.isCallActive)return r.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},Ee=e=>n=>(r.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",n)),Re=e=>n=>(r.logger("onMoveToSpectators"),e.onSession("participant:move-request-to-spectators",n)),Me=e=>n=>(r.logger("onUseLicense"),e.onSession("useLicense",n)),Te=e=>async({isEnabledCam:n,isEnabledMic:s})=>{if(e.isCallActive)return r.logger("sendMediaState"),e.sendMediaState({cam:n,mic:s})},ye=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(n=>{r.logger("sendRefusalToTurnOnCam: error",n)})},be=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(n=>{r.logger("sendRefusalToTurnOnMic: error",n)})},ve=e=>async({mediaStream:n,isP2P:s,maxBitrate:o,rtpSendParameters:a,contentHint:c},i)=>(r.logger("startPresentation"),e.startPresentation(n,{isP2P:s,maxBitrate:o,contentHint:c,onAddedSender:N(a)},i)),_e=e=>async({isP2P:n=!1}={})=>(r.logger("stopShareSipConnector"),e.stopPresentation({isP2P:n}).catch(s=>{r.logger(s)})),he=e=>async({mediaStream:n,isP2P:s,maxBitrate:o,rtpSendParameters:a,contentHint:c})=>(r.logger("updatePresentation"),e.updatePresentation(n,{isP2P:s,maxBitrate:o,contentHint:c,onAddedSender:N(a)})),Oe=e=>t=>[...t].map(s=>async()=>e(s)),Ae=async({accumulatedKeys:e,sendKey:t,canRunTask:n})=>{const o=Oe(t)(e);return Q.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)),De=({sipConnector:e})=>{const t=(f,R)=>({isSyncForced:M=!1})=>{if(M){f();return}R()},n=pe(e),s=Pe(e),o=Ne(e),a=Be(e);let c=()=>{},i=()=>{},l=()=>{},d=()=>{};const m=({onStartMainCamForced:f,onStartMainCamNotForced:R,onStopMainCamForced:M,onStopMainCamNotForced:v,onStartMicForced:_,onStartMicNotForced:h,onStopMicForced:T,onStopMicNotForced:y})=>{const P=t(f,R);c=n(P);const b=t(M,v);i=s(b);const O=t(_,h);l=o(O);const A=t(T,y);d=a(A)},S=()=>{c(),i(),l(),d()};return{start:f=>{m(f)},stop:()=>{S()}}},Ie=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:x,createSyncMediaState:De,error:ue,getExtraHeaders:le,getUserAgent:fe,hasPurgatory:p,resolveAnswerIncomingCall:te,resolveAskPermissionToEnableCam:Ce,resolveCallToServer:re,resolveConnectToServer:se,resolveDisconnectFromServer:oe,resolveGetRemoteStreams:w,resolveOnMoveToSpectators:Re,resolveOnMustStopPresentation:Ee,resolveOnUseLicense:Me,resolveSendMediaState:Te,resolveSendRefusalToTurnOnCam:ye,resolveSendRefusalToTurnOnMic:be,resolveStartPresentation:ve,resolveStopShareSipConnector:_e,resolveUpdatePresentation:he,resolveUpdateRemoteStreams:F,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),H=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"}),X=(e,t)=>e!==void 0&&t!==void 0&&e.toLowerCase().includes(t.toLowerCase()),Ue=1e6,E=e=>e*Ue,W=E(.06),Le=E(4),Ve=e=>e<=64?W: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,xe="av1",$e=e=>X(e,xe),qe=.6,j=(e,t)=>$e(t)?e*qe:e,He=e=>j(W,e),G=(e,t)=>{const n=Ve(e);return j(n,t)},K=Z.createStackPromises(),Xe=async()=>K().catch(e=>{r.logger("videoSendingBalancer: error",e)}),We=async e=>(K.add(e),Xe()),U=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=He(t);return U({sender:e,maxBitrate:o,onSetParameters:n,scaleResolutionDownBy:200})},I=async({sender:e,track:t,codec:n},s)=>{const c=t.getSettings().width,i=G(c,n);return U({sender:e,maxBitrate:i,onSetParameters:s,scaleResolutionDownBy:1})},Ge=async({sender:e,track:t,resolution:n,codec:s},o)=>{const a=t.getSettings(),c=a.width,i=a.height,[l,d]=n.split("x"),m=c/Number(l),S=i/Number(d),C=Math.max(m,S,1),f=G(Number(l),s);return U({sender:e,maxBitrate:f,onSetParameters:o,scaleResolutionDownBy:C})},Ke=async({mainCam:e,resolutionMainCam:t,sender:n,track:s,codec:o},a)=>{switch(e){case r.EEventsMainCAM.PAUSE_MAIN_CAM:return je({sender:n,codec:o},a);case r.EEventsMainCAM.RESUME_MAIN_CAM:return I({sender:n,track:s,codec:o},a);case r.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return t!==void 0?Ge({sender:n,track:s,codec:o,resolution:t},a):I({sender:n,track:s,codec:o},a);default:return I({sender:n,track:s,codec:o},a)}},L={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},V=async({mainCam:e,resolutionMainCam:t,connection:n,onSetParameters:s,ignoreForCodec:o})=>{const a=n.getSenders(),c=ke(a);if(!(c!=null&&c.track))return L;const i=await H(c);return X(i,o)?L:Ke({mainCam:e,resolutionMainCam:t,sender:c,codec:i,track:c.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 V({connection:l,onSetParameters:n,ignoreForCodec:t})};let o=s;const a=async l=>(o=async()=>{const{mainCam:d,resolutionMainCam:m}=l,{connection:S}=e;if(!S)throw new Error("connection is not exist");return V({mainCam:d,resolutionMainCam:m,connection:S,onSetParameters:n,ignoreForCodec:t})},o());return{subscribe:()=>{e.onSession("main-cam-control",a)},unsubscribe:()=>{e.offSession("main-cam-control",a)},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.setParametersToSender=r.setParametersToSender;exports.debug=ee;exports.getCodecFromSender=H;exports.resolveVideoSendingBalancer=Ye;exports.tools=Ie;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("./SipConnector-5B3QzrjB.cjs"),K=require("ts-debounce"),Y=require("@krivega/cancelable-promise"),z=require("repeated-calls"),J=require("sequent-promises"),Q=require("stack-promises"),Z=require("debug"),V="purgatory",A=e=>e===V,I=e=>()=>(r.logger("getRemoteStreams"),e.getRemoteStreams()),ee=({kind:e,readyState:t})=>e==="video"&&t==="live",x=e=>({track:t})=>{ee(t)&&e()},w=({getRemoteStreams:e,setRemoteStreams:t})=>K.debounce(()=>{const n=e();r.logger("remoteStreams",n),n&&t(n)},200),ne=e=>async n=>{const{mediaStream:s,extraHeaders:o,iceServers:c,contentHint:a,sendEncodings:i,setRemoteStreams:l,onBeforeProgressCall:d,onSuccessProgressCall:m,onEnterPurgatory:S,onEnterConference:g,onFailProgressCall:C,onFinishProgressCall:f,onEndedCall:R}=n,M=w({setRemoteStreams:l,getRemoteStreams:I(e)}),_=x(M);r.logger("answerIncomingCall",n);const h=async()=>e.answerToIncomingCall({mediaStream:s,extraHeaders:o,iceServers:c,contentHint:a,sendEncodings:i,ontrack:_}),v=()=>{const{remoteCallerData:u}=e;return u.incomingNumber};let T=!1,y;const b=(r.logger("subscribeEnterConference: onEnterConference",g),S??g?e.onSession("enterRoom",u=>{r.logger("enterRoom",{_room:u,isSuccessProgressCall:T}),y=u,A(y)?S&&S():g&&g({isSuccessProgressCall:T})}):()=>{}),O=u=>(r.logger("onSuccess"),T=!0,M(),m&&m({isPurgatory:A(y)}),e.onceRaceSession(["ended","failed"],()=>{b(),R&&R()}),u),p=u=>{throw r.logger("onFail"),C&&C(),b(),u},P=()=>{r.logger("onFinish"),f&&f()};if(r.logger("onBeforeProgressCall"),d){const u=v();d(u)}return h().then(O).catch(u=>p(u)).finally(P)},te=e=>async n=>{const{conference:s,mediaStream:o,extraHeaders:c,iceServers:a,contentHint:i,sendEncodings:l,setRemoteStreams:d,onBeforeProgressCall:m,onSuccessProgressCall:S,onEnterPurgatory:g,onEnterConference:C,onFailProgressCall:f,onFinishProgressCall:R,onEndedCall:M}=n,_=w({setRemoteStreams:d,getRemoteStreams:I(e)}),h=x(_);r.logger("callToServer",n);const v=async()=>(r.logger("startCall"),e.call({mediaStream:o,extraHeaders:c,iceServers:a,contentHint:i,sendEncodings:l,number:s,ontrack:h}));let T=!1,y;const b=(r.logger("subscribeEnterConference: onEnterConference",C),g??C?e.onSession("enterRoom",({room:u})=>{r.logger("enterRoom",{_room:u,isSuccessProgressCall:T}),y=u,A(y)?g&&g():C&&C({isSuccessProgressCall:T})}):()=>{}),O=u=>(r.logger("onSuccess"),T=!0,_(),S&&S({isPurgatory:A(y)}),e.onceRaceSession(["ended","failed"],()=>{b(),M&&M()}),u),p=u=>{throw r.logger("onFail"),f&&f(),b(),u},P=()=>{r.logger("onFinish"),R&&R()};return r.logger("onBeforeProgressCall"),m&&m(s),v().then(O).catch(u=>p(u)).finally(P)},B=e=>{if(!Y.isCanceledError(e)&&!z.hasCanceledError(e))throw e;return{isSuccessful:!1}},re=e=>async n=>{const{userAgent:s,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:i,name:l,password:d,isRegisteredUser:m,isDisconnectOnFail:S}=n;return r.logger("connectToServer",n),e.connect({userAgent:s,sipWebSocketServerURL:o,sipServerUrl:c,remoteAddress:a,displayName:i,password:d,user:l,register:m}).then(g=>(r.logger("connectToServer then"),{ua:g,isSuccessful:!0})).catch(async g=>(r.logger("connectToServer catch: error",g),S===!0?e.disconnect().then(()=>B(g)).catch(()=>B(g)):B(g)))},se=e=>async()=>(r.logger("disconnectFromServer"),e.disconnect().then(()=>(r.logger("disconnectFromServer: then"),{isSuccessful:!0})).catch(t=>(r.logger("disconnectFromServer: catch",t),{isSuccessful:!1}))),F=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 oe=(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":F(e)&&(s="CONNECT_SERVER_FAILED_BY_LINK")}return s},ce=e=>{let t="";try{t=JSON.stringify(e)}catch(n){r.logger("failed to stringify message",n)}return t},ae=(e=new Error)=>{const{code:t,cause:n,message:s}=e,o=F(e),c={code:"",cause:"",message:""};return typeof s=="object"&&s!==null?c.message=ce(s):s&&(c.message=String(s)),o&&(c.link=o),t&&(c.code=t),n&&(c.cause=n),c},ie=Object.freeze(Object.defineProperty({__proto__:null,EErrorTypes:$,getLinkError:F,getTypeFromError:oe,getValuesFromError:ae},Symbol.toStringTag,{value:"Module"})),ue=({sessionId:e,remoteAddress:t,isMutedAudio:n,isMutedVideo:s,isRegistered:o,isPresentationCall:c})=>{const a=[],i=n?"0":"1",l=s?"0":"1";return a.push(`X-Vinteo-Mic-State: ${i}`,`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},le="[@*!|]",ge="_",Se=e=>{let t=e;return t=t.replaceAll(new RegExp(le,"g"),ge),t},de=({appName:e,appVersion:t,browserName:n,browserVersion:s})=>{const c=`${Se(e)} ${t}`;return`ChromeNew - ${n?`${n} ${s}, ${c}`:c}`},me=({isUnifiedSdpSemantic:e,appVersion:t,browserName:n,browserVersion:s,appName:o})=>e?de({appVersion:t,browserName:n,browserVersion:s,appName:o}):"Chrome",fe=e=>async()=>{if(e.isCallActive)return r.logger("askPermissionToEnableCam"),e.askPermissionToEnableCam()},Ce=e=>n=>(r.logger("onMustStopPresentation"),e.onSession("mustStopPresentation",n)),Ee=e=>n=>(r.logger("onMoveToSpectators"),e.onSession("participant:move-request-to-spectators",n)),Re=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})},Te=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnCam"),e.sendRefusalToTurnOnCam().catch(n=>{r.logger("sendRefusalToTurnOnCam: error",n)})},ye=e=>async()=>{if(e.isCallActive)return r.logger("sendRefusalToTurnOnMic"),e.sendRefusalToTurnOnMic().catch(n=>{r.logger("sendRefusalToTurnOnMic: error",n)})},be=e=>async({mediaStream:n,isP2P:s,maxBitrate:o,contentHint:c,sendEncodings:a},i)=>(r.logger("startPresentation"),e.startPresentation(n,{isP2P:s,maxBitrate:o,contentHint:c,sendEncodings:a},i)),_e=e=>async({isP2P:n=!1}={})=>(r.logger("stopShareSipConnector"),e.stopPresentation({isP2P:n}).catch(s=>{r.logger(s)})),he=e=>async({mediaStream:n,isP2P:s,maxBitrate:o,contentHint:c,sendEncodings:a})=>(r.logger("updatePresentation"),e.updatePresentation(n,{isP2P:s,maxBitrate:o,contentHint:c,sendEncodings:a})),ve=e=>t=>[...t].map(s=>async()=>e(s)),Oe=async({accumulatedKeys:e,sendKey:t,canRunTask:n})=>{const o=ve(t)(e);return J.sequentPromises(o,n)},pe=e=>n=>(r.logger("onStartMainCam"),e.onSession("admin-start-main-cam",n)),Ae=e=>n=>(r.logger("onStartMic"),e.onSession("admin-start-mic",n)),Ne=e=>n=>(r.logger("onStopMainCam"),e.onSession("admin-stop-main-cam",n)),Pe=e=>n=>(r.logger("onStopMic"),e.onSession("admin-stop-mic",n)),Be=({sipConnector:e})=>{const t=(f,R)=>({isSyncForced:M=!1})=>{if(M){f();return}R()},n=pe(e),s=Ne(e),o=Ae(e),c=Pe(e);let a=()=>{},i=()=>{},l=()=>{},d=()=>{};const m=({onStartMainCamForced:f,onStartMainCamNotForced:R,onStopMainCamForced:M,onStopMainCamNotForced:_,onStartMicForced:h,onStartMicNotForced:v,onStopMicForced:T,onStopMicNotForced:y})=>{const N=t(f,R);a=n(N);const b=t(M,_);i=s(b);const O=t(h,v);l=o(O);const p=t(T,y);d=c(p)},S=()=>{a(),i(),l(),d()};return{start:f=>{m(f)},stop:()=>{S()}}},De=Object.freeze(Object.defineProperty({__proto__:null,PURGATORY_CONFERENCE_NUMBER:V,createSyncMediaState:Be,error:ie,getExtraHeaders:ue,getUserAgent:me,hasPurgatory:A,resolveAnswerIncomingCall:ne,resolveAskPermissionToEnableCam:fe,resolveCallToServer:te,resolveConnectToServer:re,resolveDisconnectFromServer:se,resolveGetRemoteStreams:I,resolveOnMoveToSpectators:Ee,resolveOnMustStopPresentation:Ce,resolveOnUseLicense:Re,resolveSendMediaState:Me,resolveSendRefusalToTurnOnCam:Te,resolveSendRefusalToTurnOnMic:ye,resolveStartPresentation:be,resolveStopShareSipConnector:_e,resolveUpdatePresentation:he,resolveUpdateRemoteStreams:w,sendDTMFAccumulated:Oe},Symbol.toStringTag,{value:"Module"})),Ie=e=>[...e.keys()].map(t=>e.get(t)),we=(e,t)=>Ie(e).find(n=>n.type===t),q=async e=>e.getStats().then(t=>{const n=we(t,"codec");return n==null?void 0:n.mimeType}),Fe=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()),ke=1e6,E=e=>e*ke,H=E(.06),Ue=E(4),Le=e=>e<=64?H: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):Ue,Ve="av1",xe=e=>X(e,Ve),$e=.6,W=(e,t)=>xe(t)?e*$e:e,qe=e=>W(H,e),j=(e,t)=>{const n=Le(e);return W(n,t)},G=Q.createStackPromises(),Xe=async()=>G().catch(e=>{r.logger("videoSendingBalancer: error",e)}),He=async e=>(G.add(e),Xe()),k=async({sender:e,scaleResolutionDownBy:t,maxBitrate:n,onSetParameters:s})=>He(async()=>r.setEncodingsToSender(e,{scaleResolutionDownBy:t,maxBitrate:n},s)),We=async({sender:e,codec:t},n)=>{const o=qe(t);return k({sender:e,maxBitrate:o,onSetParameters:n,scaleResolutionDownBy:200})},D=async({sender:e,track:t,codec:n},s)=>{const a=t.getSettings().width,i=j(a,n);return k({sender:e,maxBitrate:i,onSetParameters:s,scaleResolutionDownBy:1})},je=async({sender:e,track:t,resolution:n,codec:s},o)=>{const c=t.getSettings(),a=c.width,i=c.height,[l,d]=n.split("x"),m=a/Number(l),S=i/Number(d),C=Math.max(m,S,1),f=j(Number(l),s);return k({sender:e,maxBitrate:f,onSetParameters:o,scaleResolutionDownBy:C})},Ge=async({mainCam:e,resolutionMainCam:t,sender:n,track:s,codec:o},c)=>{switch(e){case r.EEventsMainCAM.PAUSE_MAIN_CAM:return We({sender:n,codec:o},c);case r.EEventsMainCAM.RESUME_MAIN_CAM:return D({sender:n,track:s,codec:o},c);case r.EEventsMainCAM.MAX_MAIN_CAM_RESOLUTION:return t!==void 0?je({sender:n,track:s,codec:o,resolution:t},c):D({sender:n,track:s,codec:o},c);default:return D({sender:n,track:s,codec:o},c)}},U={isChanged:!1,parameters:{encodings:[{}],transactionId:"0",codecs:[],headerExtensions:[],rtcp:{}}},L=async({mainCam:e,resolutionMainCam:t,connection:n,onSetParameters:s,ignoreForCodec:o})=>{const c=n.getSenders(),a=Fe(c);if(!(a!=null&&a.track))return U;const i=await q(a);return X(i,o)?U:Ge({mainCam:e,resolutionMainCam:t,sender:a,codec:i,track:a.track},s)},Ke=(e,{ignoreForCodec:t,onSetParameters:n}={})=>{const s=async()=>{const{connection:l}=e;if(!l)throw new Error("connection is not exist");return L({connection:l,onSetParameters:n,ignoreForCodec:t})};let o=s;const c=async l=>(o=async()=>{const{mainCam:d,resolutionMainCam:m}=l,{connection:S}=e;if(!S)throw new Error("connection is not exist");return L({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.setParametersToSender=r.setParametersToSender;exports.debug=Z;exports.getCodecFromSender=q;exports.resolveVideoSendingBalancer=Ke;exports.tools=De;
|