sip-connector 7.0.5 → 7.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SipConnector-BHUjGzwS.cjs +1 -0
- package/dist/{SipConnector-CxSB1Bmp.js → SipConnector-DE2T85rT.js} +367 -331
- package/dist/SipConnector.d.ts +10 -19
- package/dist/__fixtures__/Session.mock.d.ts +3 -0
- package/dist/__fixtures__/UA.mock.d.ts +19 -0
- package/dist/doMock.cjs +1 -1
- package/dist/doMock.js +78 -62
- package/dist/index.cjs +1 -1
- package/dist/index.js +97 -96
- package/dist/types.d.ts +15 -0
- package/dist/utils/errors.d.ts +1 -0
- package/package.json +27 -25
- package/dist/SipConnector-DxGNVRHG.cjs +0 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import { l as o, B as V, N as $, E as B, s as q, S as
|
|
2
|
-
import { f as
|
|
1
|
+
import { l as o, B as V, N as $, E as B, s as q, S as Ye } from "./SipConnector-DE2T85rT.js";
|
|
2
|
+
import { f as sn, g as on, i as an, c as cn, a as un, d as ln, b as Sn, e as mn, h as dn } from "./SipConnector-DE2T85rT.js";
|
|
3
3
|
import { debounce as z } from "ts-debounce";
|
|
4
4
|
import { isCanceledError as J } from "@krivega/cancelable-promise";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { hasCanceledError as Q } from "repeated-calls";
|
|
6
|
+
import { sequentPromises as Z } from "sequent-promises";
|
|
7
|
+
import { createStackPromises as ee } from "stack-promises";
|
|
8
|
+
import { default as Cn } from "debug";
|
|
9
|
+
const x = "purgatory", N = (e) => e === x, D = (e) => () => (o("getRemoteStreams"), e.getRemoteStreams()), ne = ({ kind: e, readyState: t }) => e === "video" && t === "live", G = (e) => ({ track: t }) => {
|
|
10
|
+
ne(t) && e();
|
|
10
11
|
}, w = ({
|
|
11
12
|
getRemoteStreams: e,
|
|
12
13
|
setRemoteStreams: t
|
|
13
14
|
}) => z(() => {
|
|
14
15
|
const n = e();
|
|
15
16
|
o("remoteStreams", n), n && t(n);
|
|
16
|
-
}, 200),
|
|
17
|
+
}, 200), te = (e) => async (n) => {
|
|
17
18
|
const {
|
|
18
19
|
mediaStream: r,
|
|
19
20
|
extraHeaders: s,
|
|
@@ -32,13 +33,13 @@ const x = "purgatory", N = (e) => e === x, D = (e) => () => (o("getRemoteStreams
|
|
|
32
33
|
getRemoteStreams: D(e)
|
|
33
34
|
}), _ = G(E);
|
|
34
35
|
o("answerIncomingCall", n);
|
|
35
|
-
const
|
|
36
|
+
const h = async () => e.answerToIncomingCall({
|
|
36
37
|
mediaStream: r,
|
|
37
38
|
extraHeaders: s,
|
|
38
39
|
iceServers: a,
|
|
39
40
|
degradationPreference: c,
|
|
40
41
|
ontrack: _
|
|
41
|
-
}),
|
|
42
|
+
}), b = () => {
|
|
42
43
|
const { remoteCallerData: i } = e;
|
|
43
44
|
return i.incomingNumber;
|
|
44
45
|
};
|
|
@@ -54,11 +55,11 @@ const x = "purgatory", N = (e) => e === x, D = (e) => () => (o("getRemoteStreams
|
|
|
54
55
|
o("onFinish"), m && m();
|
|
55
56
|
};
|
|
56
57
|
if (o("onBeforeProgressCall"), u) {
|
|
57
|
-
const i =
|
|
58
|
+
const i = b();
|
|
58
59
|
u(i);
|
|
59
60
|
}
|
|
60
|
-
return
|
|
61
|
-
},
|
|
61
|
+
return h().then(O).catch((i) => v(i)).finally(p);
|
|
62
|
+
}, re = (e) => async (n) => {
|
|
62
63
|
const {
|
|
63
64
|
conference: r,
|
|
64
65
|
mediaStream: s,
|
|
@@ -76,15 +77,15 @@ const x = "purgatory", N = (e) => e === x, D = (e) => () => (o("getRemoteStreams
|
|
|
76
77
|
} = n, _ = w({
|
|
77
78
|
setRemoteStreams: u,
|
|
78
79
|
getRemoteStreams: D(e)
|
|
79
|
-
}),
|
|
80
|
+
}), h = G(_);
|
|
80
81
|
o("callToServer", n);
|
|
81
|
-
const
|
|
82
|
+
const b = async () => (o("startCall"), e.call({
|
|
82
83
|
mediaStream: s,
|
|
83
84
|
extraHeaders: a,
|
|
84
85
|
iceServers: c,
|
|
85
86
|
degradationPreference: l,
|
|
86
87
|
number: r,
|
|
87
|
-
ontrack:
|
|
88
|
+
ontrack: h
|
|
88
89
|
}));
|
|
89
90
|
let T = !1, M;
|
|
90
91
|
const y = (o("subscribeEnterConference: onEnterConference", R), S ?? R ? e.onSession("enterRoom", ({ room: i }) => {
|
|
@@ -97,12 +98,12 @@ const x = "purgatory", N = (e) => e === x, D = (e) => () => (o("getRemoteStreams
|
|
|
97
98
|
}, p = () => {
|
|
98
99
|
o("onFinish"), C && C();
|
|
99
100
|
};
|
|
100
|
-
return o("onBeforeProgressCall"), d && d(r),
|
|
101
|
+
return o("onBeforeProgressCall"), d && d(r), b().then(O).catch((i) => v(i)).finally(p);
|
|
101
102
|
}, I = (e) => {
|
|
102
|
-
if (!J(e))
|
|
103
|
+
if (!J(e) && !Q(e))
|
|
103
104
|
throw e;
|
|
104
105
|
return { isSuccessful: !1 };
|
|
105
|
-
},
|
|
106
|
+
}, se = (e) => async (n) => {
|
|
106
107
|
const {
|
|
107
108
|
userAgent: r,
|
|
108
109
|
sipWebSocketServerURL: s,
|
|
@@ -126,13 +127,13 @@ const x = "purgatory", N = (e) => e === x, D = (e) => () => (o("getRemoteStreams
|
|
|
126
127
|
user: u,
|
|
127
128
|
register: f
|
|
128
129
|
}).then((m) => (o("connectToServer then"), { ua: m, isSuccessful: !0 })).catch(async (m) => (o("connectToServer catch: error", m), R === !0 ? e.disconnect().then(() => I(m)).catch(() => I(m)) : I(m)));
|
|
129
|
-
},
|
|
130
|
+
}, oe = (e) => async () => (o("disconnectFromServer"), e.disconnect().then(() => (o("disconnectFromServer: then"), { isSuccessful: !0 })).catch((t) => (o("disconnectFromServer: catch", t), { isSuccessful: !1 }))), F = (e) => {
|
|
130
131
|
const { url: t, cause: n } = e;
|
|
131
132
|
let r = t;
|
|
132
133
|
return (n === V || n === $) && (r = `${e.message.to.uri.user}@${e.message.to.uri.host}`), r;
|
|
133
134
|
};
|
|
134
135
|
var X = /* @__PURE__ */ ((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))(X || {});
|
|
135
|
-
const
|
|
136
|
+
const ae = (e = new Error()) => {
|
|
136
137
|
var s;
|
|
137
138
|
const { cause: t, socket: n } = e;
|
|
138
139
|
let r = "CONNECT_SERVER_FAILED";
|
|
@@ -153,16 +154,16 @@ const oe = (e = new Error()) => {
|
|
|
153
154
|
n && ((s = n == null ? void 0 : n._ws) == null ? void 0 : s.readyState) === 3 ? r = "WS_CONNECTION_FAILED" : F(e) && (r = "CONNECT_SERVER_FAILED_BY_LINK");
|
|
154
155
|
}
|
|
155
156
|
return r;
|
|
156
|
-
},
|
|
157
|
+
}, ce = (e = new Error()) => {
|
|
157
158
|
const { code: t, cause: n, message: r } = e, s = F(e), a = {};
|
|
158
159
|
return r && (a.message = r), s && (a.link = s), t && (a.code = t), n && (a.cause = n), a;
|
|
159
|
-
},
|
|
160
|
+
}, ie = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
160
161
|
__proto__: null,
|
|
161
162
|
EErrorTypes: X,
|
|
162
163
|
getLinkError: F,
|
|
163
|
-
getTypeFromError:
|
|
164
|
-
getValuesFromError:
|
|
165
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
164
|
+
getTypeFromError: ae,
|
|
165
|
+
getValuesFromError: ce
|
|
166
|
+
}, Symbol.toStringTag, { value: "Module" })), ue = ({
|
|
166
167
|
sessionId: e,
|
|
167
168
|
remoteAddress: t,
|
|
168
169
|
isMutedAudio: n,
|
|
@@ -172,7 +173,7 @@ const oe = (e = new Error()) => {
|
|
|
172
173
|
}) => {
|
|
173
174
|
const c = [], l = n ? "0" : "1", u = r ? "0" : "1";
|
|
174
175
|
return c.push(`X-Vinteo-Mic-State: ${l}`, `X-Vinteo-MainCam-State: ${u}`), s || 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;
|
|
175
|
-
},
|
|
176
|
+
}, le = ({
|
|
176
177
|
appName: e,
|
|
177
178
|
appVersion: t,
|
|
178
179
|
browserName: n,
|
|
@@ -180,33 +181,33 @@ const oe = (e = new Error()) => {
|
|
|
180
181
|
}) => {
|
|
181
182
|
const s = `${e} ${t}`;
|
|
182
183
|
return `ChromeNew - ${n ? `${n} ${r}, ${s}` : s}`;
|
|
183
|
-
},
|
|
184
|
+
}, Se = ({
|
|
184
185
|
isUnifiedSdpSemantic: e,
|
|
185
186
|
appVersion: t,
|
|
186
187
|
browserName: n,
|
|
187
188
|
browserVersion: r,
|
|
188
189
|
appName: s
|
|
189
|
-
}) => e ?
|
|
190
|
+
}) => e ? le({ appVersion: t, browserName: n, browserVersion: r, appName: s }) : "Chrome", me = (e) => async () => {
|
|
190
191
|
if (e.isCallActive)
|
|
191
192
|
return o("askPermissionToEnableCam"), e.askPermissionToEnableCam();
|
|
192
|
-
},
|
|
193
|
+
}, de = (e) => (n) => (o("onMustStopPresentation"), e.onSession("mustStopPresentation", n)), fe = (e) => (n) => (o("onMoveToSpectators"), e.onSession("participant:move-request-to-spectators", n)), Ce = (e) => (n) => (o("onUseLicense"), e.onSession("useLicense", n)), Re = (e) => async ({
|
|
193
194
|
isEnabledCam: n,
|
|
194
195
|
isEnabledMic: r
|
|
195
196
|
}) => {
|
|
196
197
|
if (e.isCallActive)
|
|
197
198
|
return o("sendMediaState"), e.sendMediaState({ cam: n, mic: r });
|
|
198
|
-
},
|
|
199
|
+
}, ge = (e) => async () => {
|
|
199
200
|
if (e.isCallActive)
|
|
200
201
|
return o("sendRefusalToTurnOnCam"), e.sendRefusalToTurnOnCam().catch((n) => {
|
|
201
202
|
o("sendRefusalToTurnOnCam: error", n);
|
|
202
203
|
});
|
|
203
|
-
},
|
|
204
|
+
}, Ee = (e) => async () => {
|
|
204
205
|
if (e.isCallActive)
|
|
205
206
|
return o("sendRefusalToTurnOnMic"), e.sendRefusalToTurnOnMic().catch((n) => {
|
|
206
207
|
o("sendRefusalToTurnOnMic: error", n);
|
|
207
208
|
});
|
|
208
|
-
},
|
|
209
|
-
maxBitrate: e =
|
|
209
|
+
}, Te = 1e6, Me = ({
|
|
210
|
+
maxBitrate: e = Te,
|
|
210
211
|
sipConnector: t
|
|
211
212
|
}) => async ({
|
|
212
213
|
mediaStream: r,
|
|
@@ -214,34 +215,34 @@ const oe = (e = new Error()) => {
|
|
|
214
215
|
}) => (o("startPresentation"), t.startPresentation(r, {
|
|
215
216
|
isP2P: s,
|
|
216
217
|
maxBitrate: e
|
|
217
|
-
})),
|
|
218
|
+
})), _e = ({ sipConnector: e }) => async ({ isP2P: n = !1 } = {}) => (o("stopShareSipConnector"), e.stopPresentation({
|
|
218
219
|
isP2P: n
|
|
219
220
|
}).catch((r) => {
|
|
220
221
|
o(r);
|
|
221
|
-
})),
|
|
222
|
+
})), ye = 1e6, he = ({
|
|
222
223
|
sipConnector: e,
|
|
223
|
-
maxBitrate: t =
|
|
224
|
+
maxBitrate: t = ye
|
|
224
225
|
}) => async ({
|
|
225
226
|
mediaStream: r,
|
|
226
227
|
isP2P: s = !1
|
|
227
228
|
}) => (o("updatePresentation"), e.updatePresentation(r, {
|
|
228
229
|
isP2P: s,
|
|
229
230
|
maxBitrate: t
|
|
230
|
-
})), be = (e) => (t) => [...t].map((r) => async () => e(r)),
|
|
231
|
+
})), be = (e) => (t) => [...t].map((r) => async () => e(r)), Oe = async ({
|
|
231
232
|
accumulatedKeys: e,
|
|
232
233
|
sendKey: t,
|
|
233
234
|
canRunTask: n
|
|
234
235
|
}) => {
|
|
235
236
|
const s = be(t)(e);
|
|
236
|
-
return
|
|
237
|
-
},
|
|
237
|
+
return Z(s, n);
|
|
238
|
+
}, ve = (e) => (n) => (o("onStartMainCam"), e.onSession("admin-start-main-cam", n)), pe = (e) => (n) => (o("onStartMic"), e.onSession("admin-start-mic", n)), Ne = (e) => (n) => (o("onStopMainCam"), e.onSession("admin-stop-main-cam", n)), Ae = (e) => (n) => (o("onStopMic"), e.onSession("admin-stop-mic", n)), Be = ({ sipConnector: e }) => {
|
|
238
239
|
const t = (C, E) => ({ isSyncForced: _ = !1 }) => {
|
|
239
240
|
if (_) {
|
|
240
241
|
C();
|
|
241
242
|
return;
|
|
242
243
|
}
|
|
243
244
|
E();
|
|
244
|
-
}, n =
|
|
245
|
+
}, n = ve(e), r = Ne(e), s = pe(e), a = Ae(e);
|
|
245
246
|
let c = () => {
|
|
246
247
|
}, l = () => {
|
|
247
248
|
}, u = () => {
|
|
@@ -251,8 +252,8 @@ const oe = (e = new Error()) => {
|
|
|
251
252
|
onStartMainCamForced: C,
|
|
252
253
|
onStartMainCamNotForced: E,
|
|
253
254
|
onStopMainCamForced: _,
|
|
254
|
-
onStopMainCamNotForced:
|
|
255
|
-
onStartMicForced:
|
|
255
|
+
onStopMainCamNotForced: h,
|
|
256
|
+
onStartMicForced: b,
|
|
256
257
|
onStartMicNotForced: T,
|
|
257
258
|
onStopMicForced: M,
|
|
258
259
|
onStopMicNotForced: A
|
|
@@ -264,10 +265,10 @@ const oe = (e = new Error()) => {
|
|
|
264
265
|
c = n(y);
|
|
265
266
|
const O = t(
|
|
266
267
|
_,
|
|
267
|
-
|
|
268
|
+
h
|
|
268
269
|
);
|
|
269
270
|
l = r(O);
|
|
270
|
-
const v = t(
|
|
271
|
+
const v = t(b, T);
|
|
271
272
|
u = s(v);
|
|
272
273
|
const p = t(M, A);
|
|
273
274
|
d = a(p);
|
|
@@ -282,49 +283,49 @@ const oe = (e = new Error()) => {
|
|
|
282
283
|
S();
|
|
283
284
|
}
|
|
284
285
|
};
|
|
285
|
-
},
|
|
286
|
+
}, en = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
286
287
|
__proto__: null,
|
|
287
288
|
PURGATORY_CONFERENCE_NUMBER: x,
|
|
288
|
-
createSyncMediaState:
|
|
289
|
-
error:
|
|
290
|
-
getExtraHeaders:
|
|
291
|
-
getUserAgent:
|
|
289
|
+
createSyncMediaState: Be,
|
|
290
|
+
error: ie,
|
|
291
|
+
getExtraHeaders: ue,
|
|
292
|
+
getUserAgent: Se,
|
|
292
293
|
hasPurgatory: N,
|
|
293
|
-
resolveAnswerIncomingCall:
|
|
294
|
-
resolveAskPermissionToEnableCam:
|
|
295
|
-
resolveCallToServer:
|
|
296
|
-
resolveConnectToServer:
|
|
297
|
-
resolveDisconnectFromServer:
|
|
294
|
+
resolveAnswerIncomingCall: te,
|
|
295
|
+
resolveAskPermissionToEnableCam: me,
|
|
296
|
+
resolveCallToServer: re,
|
|
297
|
+
resolveConnectToServer: se,
|
|
298
|
+
resolveDisconnectFromServer: oe,
|
|
298
299
|
resolveGetRemoteStreams: D,
|
|
299
|
-
resolveOnMoveToSpectators:
|
|
300
|
-
resolveOnMustStopPresentation:
|
|
301
|
-
resolveOnUseLicense:
|
|
302
|
-
resolveSendMediaState:
|
|
303
|
-
resolveSendRefusalToTurnOnCam:
|
|
304
|
-
resolveSendRefusalToTurnOnMic:
|
|
305
|
-
resolveStartPresentation:
|
|
306
|
-
resolveStopShareSipConnector:
|
|
307
|
-
resolveUpdatePresentation:
|
|
300
|
+
resolveOnMoveToSpectators: fe,
|
|
301
|
+
resolveOnMustStopPresentation: de,
|
|
302
|
+
resolveOnUseLicense: Ce,
|
|
303
|
+
resolveSendMediaState: Re,
|
|
304
|
+
resolveSendRefusalToTurnOnCam: ge,
|
|
305
|
+
resolveSendRefusalToTurnOnMic: Ee,
|
|
306
|
+
resolveStartPresentation: Me,
|
|
307
|
+
resolveStopShareSipConnector: _e,
|
|
308
|
+
resolveUpdatePresentation: he,
|
|
308
309
|
resolveUpdateRemoteStreams: w,
|
|
309
|
-
sendDTMFAccumulated:
|
|
310
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
311
|
-
const n =
|
|
310
|
+
sendDTMFAccumulated: Oe
|
|
311
|
+
}, Symbol.toStringTag, { value: "Module" })), Ie = (e) => [...e.keys()].map((t) => e.get(t)), Pe = (e, t) => Ie(e).find((n) => n.type === t), De = async (e) => e.getStats().then((t) => {
|
|
312
|
+
const n = Pe(t, "codec");
|
|
312
313
|
return n == null ? void 0 : n.mimeType;
|
|
313
|
-
}),
|
|
314
|
+
}), we = (e) => e.find((t) => {
|
|
314
315
|
var n;
|
|
315
316
|
return ((n = t == null ? void 0 : t.track) == null ? void 0 : n.kind) === "video";
|
|
316
|
-
}), K = (e, t) => e !== void 0 && t !== void 0 && e.toLowerCase().includes(t.toLowerCase()),
|
|
317
|
-
const n =
|
|
317
|
+
}), K = (e, t) => e !== void 0 && t !== void 0 && e.toLowerCase().includes(t.toLowerCase()), Fe = 1e6, g = (e) => e * Fe, W = g(0.06), ke = g(4), Ue = (e) => e <= 64 ? W : e <= 128 ? g(0.12) : e <= 256 ? g(0.25) : e <= 384 ? g(0.32) : e <= 426 ? g(0.38) : e <= 640 ? g(0.5) : e <= 848 ? g(0.7) : e <= 1280 ? g(1) : e <= 1920 ? g(2) : ke, Le = "av1", Ve = (e) => K(e, Le), $e = 0.6, H = (e, t) => Ve(t) ? e * $e : e, xe = (e) => H(W, e), j = (e, t) => {
|
|
318
|
+
const n = Ue(e);
|
|
318
319
|
return H(n, t);
|
|
319
|
-
}, Y =
|
|
320
|
+
}, Y = ee(), Ge = async () => Y().catch((e) => {
|
|
320
321
|
o("videoSendingBalancer: error", e);
|
|
321
|
-
}),
|
|
322
|
+
}), Xe = async (e) => (Y.add(e), Ge()), k = async ({
|
|
322
323
|
sender: e,
|
|
323
324
|
scaleResolutionDownBy: t,
|
|
324
325
|
maxBitrate: n,
|
|
325
326
|
onSetParameters: r
|
|
326
|
-
}) =>
|
|
327
|
-
const s =
|
|
327
|
+
}) => Xe(async () => q(e, { scaleResolutionDownBy: t, maxBitrate: n }, r)), Ke = async ({ sender: e, codec: t }, n) => {
|
|
328
|
+
const s = xe(t);
|
|
328
329
|
return k({
|
|
329
330
|
sender: e,
|
|
330
331
|
maxBitrate: s,
|
|
@@ -339,7 +340,7 @@ const oe = (e = new Error()) => {
|
|
|
339
340
|
onSetParameters: r,
|
|
340
341
|
scaleResolutionDownBy: 1
|
|
341
342
|
});
|
|
342
|
-
},
|
|
343
|
+
}, We = async ({
|
|
343
344
|
sender: e,
|
|
344
345
|
track: t,
|
|
345
346
|
resolution: n,
|
|
@@ -352,7 +353,7 @@ const oe = (e = new Error()) => {
|
|
|
352
353
|
onSetParameters: s,
|
|
353
354
|
scaleResolutionDownBy: m
|
|
354
355
|
});
|
|
355
|
-
},
|
|
356
|
+
}, He = async ({
|
|
356
357
|
mainCam: e,
|
|
357
358
|
resolutionMainCam: t,
|
|
358
359
|
sender: n,
|
|
@@ -361,11 +362,11 @@ const oe = (e = new Error()) => {
|
|
|
361
362
|
}, a) => {
|
|
362
363
|
switch (e) {
|
|
363
364
|
case B.PAUSE_MAIN_CAM:
|
|
364
|
-
return
|
|
365
|
+
return Ke({ sender: n, codec: s }, a);
|
|
365
366
|
case B.RESUME_MAIN_CAM:
|
|
366
367
|
return P({ sender: n, track: r, codec: s }, a);
|
|
367
368
|
case B.MAX_MAIN_CAM_RESOLUTION:
|
|
368
|
-
return t !== void 0 ?
|
|
369
|
+
return t !== void 0 ? We(
|
|
369
370
|
{ sender: n, track: r, codec: s, resolution: t },
|
|
370
371
|
a
|
|
371
372
|
) : P({ sender: n, track: r, codec: s }, a);
|
|
@@ -388,15 +389,15 @@ const oe = (e = new Error()) => {
|
|
|
388
389
|
onSetParameters: r,
|
|
389
390
|
ignoreForCodec: s
|
|
390
391
|
}) => {
|
|
391
|
-
const a = n.getSenders(), c =
|
|
392
|
+
const a = n.getSenders(), c = we(a);
|
|
392
393
|
if (!(c != null && c.track))
|
|
393
394
|
return U;
|
|
394
|
-
const l = await
|
|
395
|
-
return K(l, s) ? U :
|
|
395
|
+
const l = await De(c);
|
|
396
|
+
return K(l, s) ? U : He(
|
|
396
397
|
{ mainCam: e, resolutionMainCam: t, sender: c, codec: l, track: c.track },
|
|
397
398
|
r
|
|
398
399
|
);
|
|
399
|
-
},
|
|
400
|
+
}, nn = (e, {
|
|
400
401
|
ignoreForCodec: t,
|
|
401
402
|
onSetParameters: n
|
|
402
403
|
} = {}) => {
|
|
@@ -441,18 +442,18 @@ const oe = (e = new Error()) => {
|
|
|
441
442
|
};
|
|
442
443
|
export {
|
|
443
444
|
B as EEventsMainCAM,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
445
|
+
sn as EEventsMic,
|
|
446
|
+
on as EEventsSyncMediaState,
|
|
447
|
+
an as EUseLicense,
|
|
448
|
+
cn as causes,
|
|
449
|
+
un as constants,
|
|
450
|
+
Cn as debug,
|
|
451
|
+
Ye as default,
|
|
452
|
+
ln as disableDebug,
|
|
453
|
+
Sn as enableDebug,
|
|
454
|
+
mn as eventNames,
|
|
455
|
+
De as getCodecFromSender,
|
|
456
|
+
dn as hasCanceledCallError,
|
|
457
|
+
nn as resolveVideoSendingBalancer,
|
|
458
|
+
en as tools
|
|
458
459
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -33,3 +33,18 @@ export type TJsSIP = {
|
|
|
33
33
|
UA: typeof UA;
|
|
34
34
|
WebSocketInterface: typeof WebSocketInterface;
|
|
35
35
|
};
|
|
36
|
+
export type TGetServerUrl = (id: string) => string;
|
|
37
|
+
export type TParametersCreateUa = {
|
|
38
|
+
sipWebSocketServerURL: string;
|
|
39
|
+
displayName?: string;
|
|
40
|
+
sipServerUrl: string;
|
|
41
|
+
user?: string;
|
|
42
|
+
register?: boolean;
|
|
43
|
+
password?: string;
|
|
44
|
+
sdpSemantics?: 'plan-b' | 'unified-plan';
|
|
45
|
+
sessionTimers?: boolean;
|
|
46
|
+
registerExpires?: number;
|
|
47
|
+
connectionRecoveryMinInterval?: number;
|
|
48
|
+
connectionRecoveryMaxInterval?: number;
|
|
49
|
+
userAgent?: string;
|
|
50
|
+
};
|
package/dist/utils/errors.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sip-connector",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.7",
|
|
4
4
|
"description": "Module for connect to Vinteo server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webrtc",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"import": "./dist/doMock.js"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
"main": "./dist/index.
|
|
33
|
+
"main": "./dist/index.cjs",
|
|
34
34
|
"types": "dist/index.d.ts",
|
|
35
35
|
"typesVersions": {
|
|
36
36
|
"*": {
|
|
@@ -62,24 +62,25 @@
|
|
|
62
62
|
"test:coverage": "yarn test:ci --coverage --reporters=default --reporters=jest-junit"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@krivega/cancelable-promise": "^1.1.
|
|
66
|
-
"@krivega/jssip": "^3.24.
|
|
67
|
-
"debug": "^4.3.
|
|
68
|
-
"events-constructor": "^1.2.
|
|
69
|
-
"
|
|
70
|
-
"
|
|
65
|
+
"@krivega/cancelable-promise": "^1.1.3",
|
|
66
|
+
"@krivega/jssip": "^3.24.3",
|
|
67
|
+
"debug": "^4.3.5",
|
|
68
|
+
"events-constructor": "^1.2.3",
|
|
69
|
+
"repeated-calls": "^2.2.1",
|
|
70
|
+
"sequent-promises": "^2.0.1",
|
|
71
|
+
"stack-promises": "^2.0.2",
|
|
71
72
|
"ts-debounce": "^4.0.0",
|
|
72
|
-
"webrtc-mock": "^1.0.
|
|
73
|
+
"webrtc-mock": "^1.0.4"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
|
-
"@babel/preset-typescript": "^7.24.
|
|
76
|
+
"@babel/preset-typescript": "^7.24.7",
|
|
76
77
|
"@commitlint/cli": "^19.3.0",
|
|
77
78
|
"@commitlint/config-conventional": "^19.2.2",
|
|
78
79
|
"@nabla/vite-plugin-eslint": "^2.0.4",
|
|
79
80
|
"@types/debug": "^4.1.12",
|
|
80
81
|
"@types/jest": "^29.5.12",
|
|
81
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
82
|
-
"@typescript-eslint/parser": "^7.
|
|
82
|
+
"@typescript-eslint/eslint-plugin": "^7.13.0",
|
|
83
|
+
"@typescript-eslint/parser": "^7.13.0",
|
|
83
84
|
"cross-env": "^7.0.3",
|
|
84
85
|
"eslint": "^8.57.0",
|
|
85
86
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
@@ -88,34 +89,35 @@
|
|
|
88
89
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
89
90
|
"eslint-plugin-flowtype": "^8.0.3",
|
|
90
91
|
"eslint-plugin-import": "^2.29.1",
|
|
91
|
-
"eslint-plugin-jest": "^28.
|
|
92
|
+
"eslint-plugin-jest": "^28.6.0",
|
|
92
93
|
"eslint-plugin-prettier": "^5.1.3",
|
|
93
|
-
"eslint-plugin-unicorn": "^
|
|
94
|
+
"eslint-plugin-unicorn": "^54.0.0",
|
|
94
95
|
"husky": "^9.0.11",
|
|
95
96
|
"jest": "^29.7.0",
|
|
96
97
|
"jest-environment-jsdom": "^29.7.0",
|
|
97
98
|
"jest-extended": "^4.0.2",
|
|
98
99
|
"jest-junit": "^16.0.0",
|
|
99
|
-
"lint-staged": "^15.2.
|
|
100
|
-
"prettier": "^3.2
|
|
100
|
+
"lint-staged": "^15.2.7",
|
|
101
|
+
"prettier": "^3.3.2",
|
|
101
102
|
"standard-version": "^9.5.0",
|
|
102
|
-
"ts-jest": "^29.1.
|
|
103
|
+
"ts-jest": "^29.1.5",
|
|
103
104
|
"ts-node": "^10.9.2",
|
|
104
105
|
"tsc-files": "^1.1.4",
|
|
105
106
|
"typescript": "^5.4.5",
|
|
106
|
-
"vite": "^5.
|
|
107
|
+
"vite": "^5.3.1",
|
|
107
108
|
"vite-plugin-dts": "^3.9.1",
|
|
108
109
|
"vite-tsconfig-paths": "^4.3.2"
|
|
109
110
|
},
|
|
110
111
|
"peerDependencies": {
|
|
111
|
-
"@krivega/cancelable-promise": "^1.1.
|
|
112
|
-
"@krivega/jssip": "^3.24.
|
|
113
|
-
"debug": "^4.3.
|
|
114
|
-
"events-constructor": "^1.2.
|
|
115
|
-
"
|
|
116
|
-
"
|
|
112
|
+
"@krivega/cancelable-promise": "^1.1.3",
|
|
113
|
+
"@krivega/jssip": "^3.24.3",
|
|
114
|
+
"debug": "^4.3.5",
|
|
115
|
+
"events-constructor": "^1.2.3",
|
|
116
|
+
"repeated-calls": "^2.2.1",
|
|
117
|
+
"sequent-promises": "^2.0.1",
|
|
118
|
+
"stack-promises": "^2.0.2",
|
|
117
119
|
"ts-debounce": "^4.0.0",
|
|
118
|
-
"webrtc-mock": "^1.0.
|
|
120
|
+
"webrtc-mock": "^1.0.4"
|
|
119
121
|
},
|
|
120
122
|
"main:src": "src/index.ts"
|
|
121
123
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var ft=Object.defineProperty;var Ot=(r,e,t)=>e in r?ft(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e,t)=>(Ot(r,typeof e!="symbol"?e+"":e,t),t);const N=require("@krivega/cancelable-promise"),pe=require("events-constructor"),B=require("debug"),Mt="Connection Error",qe="Request Timeout",Pt="SIP Failure Code",Dt="Internal Error",pt="Busy",V="Rejected",vt="Redirected",bt="Unavailable",ke="Not Found",wt="Address Incomplete",yt="Incompatible SDP",Ut="Missing SDP",Lt="Authentication Error",We="Terminated",Ht="WebRTC Error",Fe="Canceled",qt="No Answer",kt="Expires",Wt="No ACK",Ft="Dialog Error",Bt="User Denied Media Access",Be="Bad Media Description",Vt="RTP Timeout",Yt=Object.freeze(Object.defineProperty({__proto__:null,ADDRESS_INCOMPLETE:wt,AUTHENTICATION_ERROR:Lt,BAD_MEDIA_DESCRIPTION:Be,BUSY:pt,BYE:We,CANCELED:Fe,CONNECTION_ERROR:Mt,DIALOG_ERROR:Ft,EXPIRES:kt,INCOMPATIBLE_SDP:yt,INTERNAL_ERROR:Dt,MISSING_SDP:Ut,NOT_FOUND:ke,NO_ACK:Wt,NO_ANSWER:qt,REDIRECTED:vt,REJECTED:V,REQUEST_TIMEOUT:qe,RTP_TIMEOUT:Vt,SIP_FAILURE_CODE:Pt,UNAVAILABLE:bt,USER_DENIED_MEDIA_ACCESS:Bt,WEBRTC_ERROR:Ht},Symbol.toStringTag,{value:"Module"})),Y="incomingCall",x="declinedIncomingCall",$="failedIncomingCall",G="terminatedIncomingCall",q="connecting",m="connected",u="disconnected",D="newRTCSession",f="registered",X="unregistered",O="registrationFailed",Ve="newMessage",J="sipEvent",z="availableSecondRemoteStream",Q="notAvailableSecondRemoteStream",K="mustStopPresentation",p="shareState",j="enterRoom",Z="useLicense",ee="peerconnection:confirmed",te="peerconnection:ontrack",v="channels",ne="channels:notify",se="ended:fromserver",ie="main-cam-control",re="admin-stop-main-cam",oe="admin-start-main-cam",ae="admin-stop-mic",ce="admin-start-mic",b="admin-force-sync-media-state",Ee="participant:added-to-list-moderators",_e="participant:removed-from-list-moderators",he="participant:move-request-to-stream",de="participant:move-request-to-spectators",le="participation:accepting-word-request",Te="participation:cancelling-word-request",ue="webcast:started",Se="webcast:stopped",Ne="account:changed",Ce="account:deleted",ge="conference:participant-token-issued",M="ended",Ye="sending",xe="reinvite",$e="replaces",Ge="refer",Xe="progress",Je="accepted",w="confirmed",y="peerconnection",g="failed",ze="muted",Qe="unmuted",Ae="newDTMF",Re="newInfo",Ke="hold",je="unhold",Ze="update",et="sdp",tt="icecandidate",nt="getusermediafailed",st="peerconnection:createofferfailed",it="peerconnection:createanswerfailed",rt="peerconnection:setlocaldescriptionfailed",ot="peerconnection:setremotedescriptionfailed",at="presentation:start",ct="presentation:started",Et="presentation:end",Ie="presentation:ended",U="presentation:failed",_t="SPECTATOR",xt=Object.freeze(Object.defineProperty({__proto__:null,ACCEPTED:Je,ACCOUNT_CHANGED:Ne,ACCOUNT_DELETED:Ce,ADMIN_FORCE_SYNC_MEDIA_STATE:b,ADMIN_START_MAIN_CAM:oe,ADMIN_START_MIC:ce,ADMIN_STOP_MAIN_CAM:re,ADMIN_STOP_MIC:ae,AVAILABLE_SECOND_REMOTE_STREAM_EVENT:z,CHANNELS:v,CHANNELS_NOTIFY:ne,CONFERENCE_PARTICIPANT_TOKEN_ISSUED:ge,CONFIRMED:w,CONNECTED:m,CONNECTING:q,DECLINED_INCOMING_CALL:x,DISCONNECTED:u,ENDED:M,ENDED_FROM_SERVER:se,ENTER_ROOM:j,FAILED:g,FAILED_INCOMING_CALL:$,GET_USER_MEDIA_FAILED:nt,HOLD:Ke,ICE_CANDIDATE:tt,INCOMING_CALL:Y,MAIN_CAM_CONTROL:ie,MUST_STOP_PRESENTATION_EVENT:K,MUTED:ze,NEW_DTMF:Ae,NEW_INFO:Re,NEW_MESSAGE:Ve,NEW_RTC_SESSION:D,NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT:Q,PARTICIPANT_ADDED_TO_LIST_MODERATORS:Ee,PARTICIPANT_MOVE_REQUEST_TO_SPECTATORS:de,PARTICIPANT_MOVE_REQUEST_TO_STREAM:he,PARTICIPANT_REMOVED_FROM_LIST_MODERATORS:_e,PARTICIPATION_ACCEPTING_WORD_REQUEST:le,PARTICIPATION_CANCELLING_WORD_REQUEST:Te,PEER_CONNECTION:y,PEER_CONNECTION_CONFIRMED:ee,PEER_CONNECTION_CREATE_ANSWER_FAILED:it,PEER_CONNECTION_CREATE_OFFER_FAILED:st,PEER_CONNECTION_ONTRACK:te,PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED:rt,PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED:ot,PRESENTATION_END:Et,PRESENTATION_ENDED:Ie,PRESENTATION_FAILED:U,PRESENTATION_START:at,PRESENTATION_STARTED:ct,PROGRESS:Xe,REFER:Ge,REGISTERED:f,REGISTRATION_FAILED:O,REINVITE:xe,REPLACES:$e,SDP:et,SENDING:Ye,SHARE_STATE:p,SIP_EVENT:J,SPECTATOR:_t,TERMINATED_INCOMING_CALL:G,UNHOLD:je,UNMUTED:Qe,UNREGISTERED:X,UPDATE:Ze,USE_LICENSE:Z,WEBCAST_STARTED:ue,WEBCAST_STOPPED:Se},Symbol.toStringTag,{value:"Module"})),ht=[Y,x,G,$,le,Te,he,ne,ge,Ne,Ce,ue,Se,Ee,_e],me=[q,m,u,D,f,X,O,Ve,J],dt=[z,Q,K,p,j,Z,ee,te,v,se,ie,oe,re,ae,ce,b,de],fe=[M,q,Ye,xe,$e,Ge,Xe,Je,w,y,g,ze,Qe,Ae,Re,Ke,je,Ze,et,tt,nt,st,it,rt,ot,at,ct,Et,Ie,U],Oe=[...me,...ht],Me=[...fe,...dt],$t=Object.freeze(Object.defineProperty({__proto__:null,SESSION_EVENT_NAMES:Me,SESSION_JSSIP_EVENT_NAMES:fe,SESSION_SYNTHETICS_EVENT_NAMES:dt,UA_EVENT_NAMES:Oe,UA_JSSIP_EVENT_NAMES:me,UA_SYNTHETICS_EVENT_NAMES:ht},Symbol.toStringTag,{value:"Module"})),Gt=r=>{const e=[];return r&&e.push(`X-Vinteo-Remote: ${r}`),e},Xt="content-type",Jt="x-webrtc-enter-room",P="application/vinteo.webrtc.sharedesktop",zt="application/vinteo.webrtc.roomname",Qt="application/vinteo.webrtc.channels",Kt="application/vinteo.webrtc.mediastate",jt="application/vinteo.webrtc.refusal",ve="application/vinteo.webrtc.maincam",Zt="application/vinteo.webrtc.mic",en="application/vinteo.webrtc.uselic",tn="X-WEBRTC-USE-LICENSE",nn="X-WEBRTC-PARTICIPANT-NAME",be="X-WEBRTC-INPUT-CHANNELS",we="X-WEBRTC-OUTPUT-CHANNELS",sn="X-WEBRTC-MAINCAM",rn="X-WEBRTC-MIC",ye="X-WEBRTC-SYNC",on="X-WEBRTC-MAINCAM-RESOLUTION",an="X-WEBRTC-MEDIA-STATE",cn="X-Vinteo-Media-Type",En="X-Vinteo-MainCam-State",_n="X-Vinteo-Mic-State",hn="application/vinteo.webrtc.partstate",dn="X-WEBRTC-PARTSTATE",ln="application/vinteo.webrtc.notify",Tn="X-VINTEO-NOTIFY",R="x-webrtc-share-state",un=`${R}: LETMESTARTPRESENTATION`,Sn=`${R}: STOPPRESENTATION`,lt="YOUCANRECEIVECONTENT",Tt="CONTENTEND",ut="YOUMUSTSTOPSENDCONTENT",Nn=`${R}: ${ut}`,Cn=`${R}: ${lt}`,gn=`${R}: ${Tt}`,An="X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE",Rn=`${An}: LETMESTARTMAINCAM`,Pe="sip-connector",W=B(Pe),In=()=>{B.enable(Pe)},mn=()=>{B.enable(`-${Pe}`)};var A=(r=>(r.PAUSE_MAIN_CAM="PAUSEMAINCAM",r.RESUME_MAIN_CAM="RESUMEMAINCAM",r.MAX_MAIN_CAM_RESOLUTION="MAXMAINCAMRESOLUTION",r.ADMIN_STOP_MAIN_CAM="ADMINSTOPMAINCAM",r.ADMIN_START_MAIN_CAM="ADMINSTARTMAINCAM",r))(A||{}),L=(r=>(r.ADMIN_STOP_MIC="ADMINSTOPMIC",r.ADMIN_START_MIC="ADMINSTARTMIC",r))(L||{}),H=(r=>(r.ADMIN_SYNC_FORCED="1",r.ADMIN_SYNC_NOT_FORCED="0",r))(H||{}),St=(r=>(r.AUDIO="AUDIO",r.VIDEO="VIDEO",r.AUDIOPLUSPRESENTATION="AUDIOPLUSPRESENTATION",r))(St||{});function Ue(r){return e=>`sip:${e}@${r}`}const fn=(r,e)=>()=>Math.floor(Math.random()*(e-r))+r,Le=r=>r.trim().replaceAll(" ","_"),On=fn(1e5,99999999),k=(r,{videoMode:e,audioMode:t}={})=>{if(!r||e==="recvonly"&&t==="recvonly")return;const n=t==="recvonly"?[]:r.getAudioTracks(),s=e==="recvonly"?[]:r.getVideoTracks(),o=[...n,...s],a=new MediaStream(o);return a.getTracks=()=>[...a.getAudioTracks(),...a.getVideoTracks()],a},Mn=r=>r.some(t=>{const{kind:n}=t;return n==="video"}),Pn="Error decline with 603",Dn=r=>r.message===Pn,pn=(r,e)=>r.find(t=>t.track&&e.getTracks().includes(t.track)),Nt=1,Ct=r=>(e,t)=>t!==void 0&&e!==t||t===void 0&&e!==r,vn=Ct(Nt),bn=(r,e)=>{const t=r===void 0?void 0:Math.max(r,Nt);if(t!==void 0&&vn(t,e))return t},wn=Ct(),yn=(r,e)=>{if(wn(r,e))return r},gt=async(r,e,t)=>{const n=r.getParameters();(n.encodings===void 0||n.encodings.length===0)&&(n.encodings=[{}]);const[s]=n.encodings,o=s.scaleResolutionDownBy,a=bn(e.scaleResolutionDownBy,o);let c=!1;a!==void 0&&(n.encodings[0].scaleResolutionDownBy=a,c=!0);const E=s.maxBitrate,_=yn(e.maxBitrate,E);return _!==void 0&&(n.encodings[0].maxBitrate=_,c=!0),c?(t&&t(n),r.setParameters(n).then(()=>({parameters:n,isChanged:c}))):{parameters:n,isChanged:c}},Un=async(r,e,t)=>{const n=pn(r,e);if(n)return gt(n,{maxBitrate:t})},Ln=486,Hn=487,F="local",He="remote",qn=(r=new Error)=>{const{originator:e,cause:t}=r;return N.isCanceledError(r)?!0:typeof t=="string"?t===qe||t===V||e===F&&(t===Fe||t===We):!1},C="SipConnector",kn="channels",Wn="WebcastStarted",Fn="WebcastStopped",Bn="accountChanged",Vn="accountDeleted",Yn="addedToListModerators",xn="removedFromListModerators",$n="ParticipationRequestAccepted",Gn="ParticipationRequestRejected",Xn="ParticipantMovedToWebcast",Jn="ConferenceParticipantTokenIssued";class zn{constructor({JsSIP:e}){i(this,"_isRegisterConfig",!1);i(this,"_connectionConfiguration",{});i(this,"_remoteStreams",{});i(this,"JsSIP");i(this,"_sessionEvents");i(this,"_uaEvents");i(this,"_cancelableConnect");i(this,"_cancelableInitUa");i(this,"_cancelableDisconnect");i(this,"_cancelableSet");i(this,"_cancelableCall");i(this,"_cancelableAnswer");i(this,"_cancelableSendDTMF");i(this,"getSipServerUrl",e=>e);i(this,"promisePendingStartPresentation");i(this,"promisePendingStopPresentation");i(this,"ua");i(this,"session");i(this,"incomingSession");i(this,"_streamPresentationCurrent");i(this,"socket");i(this,"connect",async e=>(this._cancelRequests(),this._cancelableConnect.request(e)));i(this,"initUa",async e=>this._cancelableInitUa.request(e));i(this,"set",async e=>this._cancelableSet.request(e));i(this,"call",async e=>this._cancelableCall.request(e));i(this,"disconnect",async()=>(this._cancelRequests(),this._disconnectWithoutCancelRequests()));i(this,"answerToIncomingCall",async e=>this._cancelableAnswer.request(e));i(this,"sendDTMF",async e=>this._cancelableSendDTMF.request(e));i(this,"hangUp",async()=>(this._cancelRequests(),this._hangUpWithoutCancelRequests()));i(this,"tryRegister",async()=>{if(!this.isRegisterConfig)throw new Error("Config is not registered");this._uaEvents.trigger(q,void 0);try{await this.unregister()}catch(e){W("tryRegister",e)}return this.register()});i(this,"declineToIncomingCall",async({statusCode:e=Hn}={})=>new Promise((t,n)=>{if(!this.isAvailableIncomingCall){n(new Error("no incomingSession"));return}const s=this.incomingSession,o=this.remoteCallerData;this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest(),this.removeIncomingSession(),this._uaEvents.trigger(x,o),t(s.terminate({status_code:e}))}));i(this,"busyIncomingCall",async()=>this.declineToIncomingCall({statusCode:Ln}));i(this,"removeIncomingSession",()=>{delete this.incomingSession});i(this,"handleNewRTCSession",({originator:e,session:t})=>{if(e===He){this.incomingSession=t;const n=this.remoteCallerData;t.on(g,s=>{this.removeIncomingSession(),s.originator===F?this._uaEvents.trigger(G,n):this._uaEvents.trigger($,n)}),this._uaEvents.trigger(Y,n)}});i(this,"_connect",async e=>this.initUa(e).then(async()=>this._start()));i(this,"_initUa",async({user:e,password:t,sipServerUrl:n,sipWebSocketServerURL:s,remoteAddress:o,sdpSemantics:a,sessionTimers:c,registerExpires:E,connectionRecoveryMinInterval:_,connectionRecoveryMaxInterval:h,userAgent:T,displayName:d="",register:l=!1,extraHeaders:S=[]})=>{if(!n)throw new Error("sipServerUrl is required");if(!s)throw new Error("sipWebSocketServerURL is required");if(l&&!e)throw new Error("user is required for authorized connection");if(l&&!t)throw new Error("password is required for authorized connection");this._connectionConfiguration={sipServerUrl:n,displayName:d,register:l,user:e,password:t},this.getSipServerUrl=Ue(n),this.socket=new this.JsSIP.WebSocketInterface(s),this.ua&&await this._disconnectWithoutCancelRequests(),this._isRegisterConfig=!!l;const{socket:I}=this;this.ua=this._createUa({user:e,password:t,socket:I,displayName:d,register:l,sdpSemantics:a,sessionTimers:c,registerExpires:E,connectionRecoveryMinInterval:_,connectionRecoveryMaxInterval:h,userAgent:T,getSipServerUrl:this.getSipServerUrl}),this._uaEvents.eachTriggers((Rt,It)=>{const De=me.find(mt=>mt===It);De&&this.ua&&this.ua.on(De,Rt)});const At=[...Gt(o),...S];return this.ua.registrator().setExtraHeaders(At),this.ua});i(this,"_createUa",({user:e,password:t,socket:n,displayName:s,getSipServerUrl:o,register:a=!1,sdpSemantics:c="plan-b",sessionTimers:E=!1,registerExpires:_=60*5,connectionRecoveryMinInterval:h=2,connectionRecoveryMaxInterval:T=6,userAgent:d})=>{if(a&&!t)throw new Error("password is required for authorized connection");const l=a&&e?e.trim():`${On()}`,S=o(l),I={password:t,register:a,uri:S,display_name:Le(s),user_agent:d,sdp_semantics:c,sockets:[n],session_timers:E,register_expires:_,connection_recovery_min_interval:h,connection_recovery_max_interval:T};return new this.JsSIP.UA(I)});i(this,"_start",async()=>new Promise((e,t)=>{const{ua:n}=this;if(!n){t(new Error("this.ua is not initialized"));return}const s=()=>{c(),e(n)},o=E=>{c(),t(E)},a=()=>{this.isRegisterConfig?(this.on(f,s),this.on(O,o)):this.on(m,s),this.on(u,o)},c=()=>{this.off(f,s),this.off(O,o),this.off(m,s),this.off(u,o)};a(),this.on(D,this.handleNewRTCSession),n.start()}));i(this,"_set",async({displayName:e,password:t})=>new Promise((n,s)=>{const{ua:o}=this;if(!o){s(new Error("this.ua is not initialized"));return}let a=!1,c=!1;e!==void 0&&e!==this._connectionConfiguration.displayName&&(a=o.set("display_name",Le(e)),this._connectionConfiguration.displayName=e),t!==void 0&&t!==this._connectionConfiguration.password&&(c=o.set("password",t),this._connectionConfiguration.password=t);const E=a||c;c&&this.isRegisterConfig?this.register().then(()=>{n(E)}).catch(_=>{s(_)}):E?n(E):s(new Error("nothing changed"))}));i(this,"_disconnectWithoutCancelRequests",async()=>this._cancelableDisconnect.request());i(this,"_disconnect",async()=>{this.off(D,this.handleNewRTCSession);const e=new Promise(t=>{this.once(u,()=>{delete this.ua,t()})});return this.ua?(await this._hangUpWithoutCancelRequests(),this.ua?this.ua.stop():this._uaEvents.trigger(u,void 0)):this._uaEvents.trigger(u,void 0),e});i(this,"_call",async({number:e,mediaStream:t,extraHeaders:n=[],ontrack:s,iceServers:o,videoMode:a,audioMode:c,degradationPreference:E,offerToReceiveAudio:_=!0,offerToReceiveVideo:h=!0})=>new Promise((T,d)=>{const{ua:l}=this;if(!l){d(new Error("this.ua is not initialized"));return}this._connectionConfiguration.number=e,this._connectionConfiguration.answer=!1,this._handleCall({ontrack:s}).then(T).catch(S=>{d(S)}),this.session=l.call(this.getSipServerUrl(e),{extraHeaders:n,mediaStream:k(t,{videoMode:a,audioMode:c}),eventHandlers:this._sessionEvents.triggers,videoMode:a,audioMode:c,degradationPreference:E,pcConfig:{iceServers:o},rtcOfferConstraints:{offerToReceiveAudio:_,offerToReceiveVideo:h}})}));i(this,"_answer",async({mediaStream:e,ontrack:t,extraHeaders:n=[],iceServers:s,videoMode:o,audioMode:a,degradationPreference:c})=>new Promise((E,_)=>{if(!this.isAvailableIncomingCall){_(new Error("no incomingSession"));return}this.session=this.incomingSession,this.removeIncomingSession();const{session:h}=this;if(!h){_(new Error("No session established"));return}this._sessionEvents.eachTriggers((d,l)=>{const S=fe.find(I=>I===l);S&&h.on(S,d)}),this._connectionConfiguration.answer=!0,this._connectionConfiguration.number=h.remote_identity.uri.user,this._handleCall({ontrack:t}).then(E).catch(d=>{_(d)});const T=k(e,{videoMode:o,audioMode:a});h.answer({extraHeaders:n,videoMode:o,audioMode:a,degradationPreference:c,mediaStream:T,pcConfig:{iceServers:s}})}));i(this,"_handleCall",async({ontrack:e})=>new Promise((t,n)=>{const s=()=>{this.onSession(y,h),this.onSession(w,T)},o=()=>{this.offSession(y,h),this.offSession(w,T)},a=()=>{this.onSession(g,E),this.onSession(M,E)},c=()=>{this.offSession(g,E),this.offSession(M,E)},E=d=>{o(),c(),n(d)};let _;const h=({peerconnection:d})=>{_=d,_.ontrack=l=>{this._sessionEvents.trigger(te,_),e&&e(l)}},T=()=>{_&&this._sessionEvents.trigger(ee,_),o(),c(),t(_)};s(),a()}));i(this,"_restoreSession",()=>{this._resetPresentation(),delete this._connectionConfiguration.number,delete this.session,this._remoteStreams={}});i(this,"_sendDTMF",async e=>new Promise((t,n)=>{const{session:s}=this;if(!s){n(new Error("No session established"));return}this.onceSession(Ae,({originator:o})=>{o===F&&t()}),s.sendDTMF(e,{duration:120,interToneGap:600})}));i(this,"_hangUpWithoutCancelRequests",async()=>{if(this.ua&&this.session){const{session:e}=this;if(this._streamPresentationCurrent&&await this.stopPresentation(),this._restoreSession(),!e.isEnded())return e.terminateAsync()}});i(this,"_handleShareState",e=>{switch(e){case lt:{this._sessionEvents.trigger(z,void 0);break}case Tt:{this._sessionEvents.trigger(Q,void 0);break}case ut:{this._sessionEvents.trigger(K,void 0);break}}});i(this,"_maybeTriggerChannels",e=>{const t=e.getHeader(be),n=e.getHeader(we);if(t&&n){const s={inputChannels:t,outputChannels:n};this._sessionEvents.trigger(v,s)}});i(this,"_handleNotify",e=>{switch(e.cmd){case kn:{const t=e;this._triggerChannelsNotify(t);break}case Wn:{const t=e;this._triggerWebcastStartedNotify(t);break}case Fn:{const t=e;this._triggerWebcastStoppedNotify(t);break}case Yn:{const t=e;this._triggerAddedToListModeratorsNotify(t);break}case xn:{const t=e;this._triggerRemovedFromListModeratorsNotify(t);break}case $n:{const t=e;this._triggerParticipationAcceptingWordRequest(t);break}case Gn:{const t=e;this._triggerParticipationCancellingWordRequest(t);break}case Xn:{const t=e;this._triggerParticipantMoveRequestToStream(t);break}case Bn:{this._triggerAccountChangedNotify();break}case Vn:{this._triggerAccountDeletedNotify();break}case Jn:{const t=e;this._triggerConferenceParticipantTokenIssued(t);break}default:W("unknown cmd",e.cmd)}});i(this,"_triggerRemovedFromListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(_e,t)});i(this,"_triggerAddedToListModeratorsNotify",({conference:e})=>{const t={conference:e};this._uaEvents.trigger(Ee,t)});i(this,"_triggerWebcastStartedNotify",({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger(ue,n)});i(this,"_triggerWebcastStoppedNotify",({body:{conference:e,type:t}})=>{const n={conference:e,type:t};this._uaEvents.trigger(Se,n)});i(this,"_triggerAccountChangedNotify",()=>{this._uaEvents.trigger(Ne,void 0)});i(this,"_triggerAccountDeletedNotify",()=>{this._uaEvents.trigger(Ce,void 0)});i(this,"_triggerConferenceParticipantTokenIssued",({body:{conference:e,participant:t,jwt:n}})=>{const s={conference:e,participant:t,jwt:n};this._uaEvents.trigger(ge,s)});i(this,"_triggerChannelsNotify",e=>{const t=e.input,n=e.output,s={inputChannels:t,outputChannels:n};this._uaEvents.trigger(ne,s)});i(this,"_triggerParticipationAcceptingWordRequest",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(le,t)});i(this,"_triggerParticipationCancellingWordRequest",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(Te,t)});i(this,"_triggerParticipantMoveRequestToStream",({body:{conference:e}})=>{const t={conference:e};this._uaEvents.trigger(he,t)});i(this,"_triggerEnterRoom",e=>{const t=e.getHeader(Jt),n=e.getHeader(nn);this._sessionEvents.trigger(j,{room:t,participantName:n})});i(this,"_triggerShareState",e=>{const t=e.getHeader(R);this._sessionEvents.trigger(p,t)});i(this,"_maybeTriggerParticipantMoveRequestToSpectators",e=>{e.getHeader(dn)===_t&&this._sessionEvents.trigger(de,void 0)});i(this,"_triggerMainCamControl",e=>{const t=e.getHeader(sn),n=e.getHeader(ye),s=n===H.ADMIN_SYNC_FORCED;if(t===A.ADMIN_START_MAIN_CAM){this._sessionEvents.trigger(oe,{isSyncForced:s});return}if(t===A.ADMIN_STOP_MAIN_CAM){this._sessionEvents.trigger(re,{isSyncForced:s});return}(t===A.RESUME_MAIN_CAM||t===A.PAUSE_MAIN_CAM)&&n&&this._sessionEvents.trigger(b,{isSyncForced:s});const o=e.getHeader(on);this._sessionEvents.trigger(ie,{mainCam:t,resolutionMainCam:o})});i(this,"_triggerMicControl",e=>{const t=e.getHeader(rn),s=e.getHeader(ye)===H.ADMIN_SYNC_FORCED;t===L.ADMIN_START_MIC?this._sessionEvents.trigger(ce,{isSyncForced:s}):t===L.ADMIN_STOP_MIC&&this._sessionEvents.trigger(ae,{isSyncForced:s})});i(this,"_triggerUseLicense",e=>{const t=e.getHeader(tn);this._sessionEvents.trigger(Z,t)});i(this,"_handleNewInfo",e=>{const{originator:t}=e;if(t!=="remote")return;const{request:n}=e,s=n.getHeader(Xt);if(s)switch(s){case zt:{this._triggerEnterRoom(n),this._maybeTriggerChannels(n);break}case ln:{this._maybeHandleNotify(n);break}case P:{this._triggerShareState(n);break}case ve:{this._triggerMainCamControl(n);break}case Zt:{this._triggerMicControl(n);break}case en:{this._triggerUseLicense(n);break}case hn:{this._maybeTriggerParticipantMoveRequestToSpectators(n);break}}});i(this,"_handleSipEvent",({request:e})=>{this._maybeHandleNotify(e)});i(this,"_maybeHandleNotify",e=>{const t=e.getHeader(Tn);if(t){const n=JSON.parse(t);this._handleNotify(n)}});i(this,"_handleEnded",e=>{const{originator:t}=e;t===He&&this._sessionEvents.trigger(se,e),this._restoreSession()});this.JsSIP=e,this._sessionEvents=new pe(Me),this._uaEvents=new pe(Oe),this._cancelableConnect=new N.CancelableRequest(this._connect,{moduleName:C,afterCancelRequest:()=>{this._cancelableInitUa.cancelRequest(),this._cancelableDisconnect.cancelRequest()}}),this._cancelableInitUa=new N.CancelableRequest(this._initUa,{moduleName:C}),this._cancelableDisconnect=new N.CancelableRequest(this._disconnect,{moduleName:C}),this._cancelableSet=new N.CancelableRequest(this._set,{moduleName:C}),this._cancelableCall=new N.CancelableRequest(this._call,{moduleName:C}),this._cancelableAnswer=new N.CancelableRequest(this._answer,{moduleName:C}),this._cancelableSendDTMF=new N.CancelableRequest(this._sendDTMF,{moduleName:C}),this.onSession(p,this._handleShareState),this.onSession(Re,this._handleNewInfo),this.on(J,this._handleSipEvent),this.onSession(g,this._handleEnded),this.onSession(M,this._handleEnded)}async register(){return new Promise((e,t)=>{this.isRegisterConfig&&this.ua?(this.ua.on(f,e),this.ua.on(O,t),this.ua.register()):t(new Error("Config is not registered"))})}async unregister(){return new Promise((e,t)=>{this.isRegistered&&this.ua?(this.ua.on(X,e),this.ua.unregister()):t(new Error("ua is not registered"))})}async sendOptions(e,t,n){if(!this.ua)throw new Error("is not connected");return new Promise((s,o)=>{try{this.ua.sendOptions(e,t,{extraHeaders:n,eventHandlers:{succeeded:()=>{s()},failed:o}})}catch(a){o(a)}})}async ping(e,t){var s;if(!((s=this.ua)!=null&&s.configuration.uri))throw new Error("is not connected");const n=this.ua.configuration.uri;return this.sendOptions(n,e,t)}async checkTelephony({userAgent:e,displayName:t,sipServerUrl:n,sipWebSocketServerURL:s,sdpSemantics:o}){return new Promise((a,c)=>{const E=Ue(n),_=new this.JsSIP.WebSocketInterface(s),h=this._createUa({socket:_,displayName:t,sdpSemantics:o,userAgent:e,getSipServerUrl:E}),T=()=>{const l=new Error("Telephony is not available");c(l)};h.once(u,T);const d=()=>{h.removeAllListeners(),h.once(u,a),h.stop()};h.once(m,d),h.start()})}async replaceMediaStream(e,t){if(!this.session)throw new Error("No session established");return this.session.replaceMediaStream(e,t)}async askPermissionToEnableCam(e={}){if(!this.session)throw new Error("No session established");const t=[Rn];return this.session.sendInfo(ve,void 0,{noTerminateWhenError:!0,...e,extraHeaders:t}).catch(n=>{if(Dn(n))throw n})}get isPendingPresentation(){return!!this.promisePendingStartPresentation||!!this.promisePendingStopPresentation}async _sendPresentation(e,t,{maxBitrate:n,degradationPreference:s,isNeedReinvite:o=!0,isP2P:a=!1}){const c=k(t);this._streamPresentationCurrent=c;const E=a?[Cn]:[un],_=e.sendInfo(P,void 0,{extraHeaders:E}).then(async()=>e.startPresentation(c,o,s)).then(async()=>{const{connection:h}=this;if(!h||n===void 0)return;const T=h.getSenders();await Un(T,t,n)}).then(()=>t).catch(h=>{throw this._sessionEvents.trigger(U,h),h});return this.promisePendingStartPresentation=_,_.finally(()=>{this.promisePendingStartPresentation=void 0})}async startPresentation(e,{isNeedReinvite:t=!0,isP2P:n=!1,maxBitrate:s,degradationPreference:o}={}){const a=this.establishedSession;if(!a)throw new Error("No session established");if(this._streamPresentationCurrent)throw new Error("Presentation is already started");return n&&await this.sendMustStopPresentation(a),this._sendPresentation(a,e,{isNeedReinvite:t,isP2P:n,maxBitrate:s,degradationPreference:o})}async sendMustStopPresentation(e){await e.sendInfo(P,void 0,{extraHeaders:[Nn]})}async stopPresentation({isP2P:e=!1}={}){const t=this._streamPresentationCurrent;let n=this.promisePendingStartPresentation??Promise.resolve();const s=e?[gn]:[Sn],o=this.establishedSession;return o&&t&&(n=n.then(async()=>o.sendInfo(P,void 0,{extraHeaders:s})).then(async()=>o.stopPresentation(t)).catch(a=>{throw this._sessionEvents.trigger(U,a),a})),!o&&t&&this._sessionEvents.trigger(Ie,t),this.promisePendingStopPresentation=n,n.finally(()=>{this._resetPresentation()})}async updatePresentation(e,{isP2P:t=!1,maxBitrate:n,degradationPreference:s}={}){const o=this.establishedSession;if(!o)throw new Error("No session established");if(!this._streamPresentationCurrent)throw new Error("Presentation has not started yet");return this.promisePendingStartPresentation&&await this.promisePendingStartPresentation,this._sendPresentation(o,e,{isP2P:t,maxBitrate:n,degradationPreference:s,isNeedReinvite:!1})}_resetPresentation(){delete this._streamPresentationCurrent,this.promisePendingStartPresentation=void 0,this.promisePendingStopPresentation=void 0}on(e,t){return this._uaEvents.on(e,t)}once(e,t){return this._uaEvents.once(e,t)}onceRace(e,t){return this._uaEvents.onceRace(e,t)}async wait(e){return this._uaEvents.wait(e)}off(e,t){this._uaEvents.off(e,t)}onSession(e,t){return this._sessionEvents.on(e,t)}onceSession(e,t){return this._sessionEvents.once(e,t)}onceRaceSession(e,t){return this._sessionEvents.onceRace(e,t)}async waitSession(e){return this._sessionEvents.wait(e)}offSession(e,t){this._sessionEvents.off(e,t)}isConfigured(){return!!this.ua}getConnectionConfiguration(){return{...this._connectionConfiguration}}getRemoteStreams(){if(!this.connection)return;const t=this.connection.getReceivers().map(({track:n})=>n);return Mn(t)?this._generateStreams(t):this._generateAudioStreams(t)}get connection(){var t;return(t=this.session)==null?void 0:t.connection}get remoteCallerData(){var e,t,n,s,o,a;return{displayName:(t=(e=this.incomingSession)==null?void 0:e.remote_identity)==null?void 0:t.display_name,host:(s=(n=this.incomingSession)==null?void 0:n.remote_identity)==null?void 0:s.uri.host,incomingNumber:(a=(o=this.incomingSession)==null?void 0:o.remote_identity)==null?void 0:a.uri.user,session:this.incomingSession}}get requested(){return this._cancelableConnect.requested||this._cancelableInitUa.requested||this._cancelableCall.requested||this._cancelableAnswer.requested}get establishedSession(){var e;return(e=this.session)!=null&&e.isEstablished()?this.session:void 0}get isRegistered(){return!!this.ua&&this.ua.isRegistered()}get isRegisterConfig(){return!!this.ua&&this._isRegisterConfig}get isCallActive(){return!!(this.ua&&this.session)}get isAvailableIncomingCall(){return!!this.incomingSession}_generateStream(e,t){const{id:n}=e,s=this._remoteStreams[n]||new MediaStream;return t&&s.addTrack(t),s.addTrack(e),this._remoteStreams[n]=s,s}_generateAudioStream(e){const{id:t}=e,n=this._remoteStreams[t]||new MediaStream;return n.addTrack(e),this._remoteStreams[t]=n,n}_generateStreams(e){const t=[];return e.forEach((n,s)=>{if(n.kind==="audio")return;const o=n,a=e[s-1];let c;a&&a.kind==="audio"&&(c=a);const E=this._generateStream(o,c);t.push(E)}),t}_generateAudioStreams(e){return e.map(n=>this._generateAudioStream(n))}_cancelRequests(){this._cancelActionsRequests(),this._cancelCallRequests(),this._cancelConnectRequests()}_cancelConnectRequests(){this._cancelableConnect.cancelRequest()}_cancelCallRequests(){this._cancelableCall.cancelRequest(),this._cancelableAnswer.cancelRequest()}_cancelActionsRequests(){this._cancelableAnswer.cancelRequest(),this._cancelableSendDTMF.cancelRequest()}async waitChannels(){return this.waitSession(v)}async waitSyncMediaState(){return this.waitSession(b)}async sendChannels({inputChannels:e,outputChannels:t}){if(!this.session)throw new Error("No session established");const n=`${be}: ${e}`,s=`${we}: ${t}`,o=[n,s];return this.session.sendInfo(Qt,void 0,{extraHeaders:o})}async sendMediaState({cam:e,mic:t},n={}){if(!this.session)throw new Error("No session established");const s=`${an}: currentstate`,o=`${En}: ${Number(e)}`,a=`${_n}: ${Number(t)}`,c=[s,o,a];return this.session.sendInfo(Kt,void 0,{noTerminateWhenError:!0,...n,extraHeaders:c})}async _sendRefusalToTurnOn(e,t={}){if(!this.session)throw new Error("No session established");const c=[`${cn}: ${e==="mic"?0:1}`];return this.session.sendInfo(jt,void 0,{noTerminateWhenError:!0,...t,extraHeaders:c})}async sendRefusalToTurnOnMic(e={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("mic",{noTerminateWhenError:!0,...e})}async sendRefusalToTurnOnCam(e={}){if(!this.session)throw new Error("No session established");return this._sendRefusalToTurnOn("cam",{noTerminateWhenError:!0,...e})}}exports.BAD_MEDIA_DESCRIPTION=Be;exports.EEventsMainCAM=A;exports.EEventsMic=L;exports.EEventsSyncMediaState=H;exports.EUseLicense=St;exports.NOT_FOUND=ke;exports.REJECTED=V;exports.SESSION_EVENT_NAMES=Me;exports.SipConnector=zn;exports.UA_EVENT_NAMES=Oe;exports.causes=Yt;exports.constants=xt;exports.disableDebug=mn;exports.enableDebug=In;exports.eventNames=$t;exports.hasCanceledCallError=qn;exports.logger=W;exports.setEncodingsToSender=gt;
|