sip-connector 6.20.1 → 6.21.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-3317ff75.cjs +1 -0
- package/dist/SipConnector-abcad4a1.js +1098 -0
- package/dist/SipConnector.d.ts +1 -5
- package/dist/doMock.cjs +1 -0
- package/dist/doMock.d.ts +3 -0
- package/dist/doMock.js +629 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +376 -1450
- package/package.json +7 -3
|
@@ -0,0 +1,1098 @@
|
|
|
1
|
+
var Nt = Object.defineProperty;
|
|
2
|
+
var gt = (r, e, t) => e in r ? Nt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var i = (r, e, t) => (gt(r, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { CancelableRequest as T, isCanceledError as Ct } from "@krivega/cancelable-promise";
|
|
5
|
+
import Oe from "events-constructor";
|
|
6
|
+
import W from "debug";
|
|
7
|
+
const At = "Connection Error", we = "Request Timeout", Rt = "SIP Failure Code", mt = "Internal Error", It = "Busy", Ue = "Rejected", ft = "Redirected", Ot = "Unavailable", Mt = "Not Found", Dt = "Address Incomplete", Pt = "Incompatible SDP", pt = "Missing SDP", vt = "Authentication Error", Le = "Terminated", bt = "WebRTC Error", He = "Canceled", yt = "No Answer", wt = "Expires", Ut = "No ACK", Lt = "Dialog Error", Ht = "User Denied Media Access", kt = "Bad Media Description", Ft = "RTP Timeout", Ys = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
8
|
+
__proto__: null,
|
|
9
|
+
ADDRESS_INCOMPLETE: Dt,
|
|
10
|
+
AUTHENTICATION_ERROR: vt,
|
|
11
|
+
BAD_MEDIA_DESCRIPTION: kt,
|
|
12
|
+
BUSY: It,
|
|
13
|
+
BYE: Le,
|
|
14
|
+
CANCELED: He,
|
|
15
|
+
CONNECTION_ERROR: At,
|
|
16
|
+
DIALOG_ERROR: Lt,
|
|
17
|
+
EXPIRES: wt,
|
|
18
|
+
INCOMPATIBLE_SDP: Pt,
|
|
19
|
+
INTERNAL_ERROR: mt,
|
|
20
|
+
MISSING_SDP: pt,
|
|
21
|
+
NOT_FOUND: Mt,
|
|
22
|
+
NO_ACK: Ut,
|
|
23
|
+
NO_ANSWER: yt,
|
|
24
|
+
REDIRECTED: ft,
|
|
25
|
+
REJECTED: Ue,
|
|
26
|
+
REQUEST_TIMEOUT: we,
|
|
27
|
+
RTP_TIMEOUT: Ft,
|
|
28
|
+
SIP_FAILURE_CODE: Rt,
|
|
29
|
+
UNAVAILABLE: Ot,
|
|
30
|
+
USER_DENIED_MEDIA_ACCESS: Ht,
|
|
31
|
+
WEBRTC_ERROR: bt
|
|
32
|
+
}, Symbol.toStringTag, { value: "Module" })), B = "incomingCall", V = "declinedIncomingCall", Y = "failedIncomingCall", x = "terminatedIncomingCall", w = "connecting", O = "connected", N = "disconnected", M = "newRTCSession", A = "registered", $ = "unregistered", R = "registrationFailed", ke = "newMessage", G = "sipEvent", X = "availableSecondRemoteStream", J = "notAvailableSecondRemoteStream", z = "mustStopPresentation", D = "shareState", Q = "enterRoom", K = "useLicense", j = "peerconnection:confirmed", Z = "peerconnection:ontrack", P = "channels", ee = "channels:notify", te = "ended:fromserver", se = "main-cam-control", ne = "admin-stop-main-cam", ie = "admin-start-main-cam", re = "admin-stop-mic", oe = "admin-start-mic", p = "admin-force-sync-media-state", ae = "participant:added-to-list-moderators", ce = "participant:removed-from-list-moderators", Ee = "participant:move-request-to-conference", _e = "participant:move-request-to-stream", he = "participant:canceling-word-request", de = "webcast:started", le = "webcast:stopped", ue = "account:changed", Te = "account:deleted", Se = "conference:participant-token-issued", m = "ended", Fe = "sending", qe = "reinvite", We = "replaces", Be = "refer", Ve = "progress", Ye = "accepted", v = "confirmed", b = "peerconnection", g = "failed", xe = "muted", $e = "unmuted", Ne = "newDTMF", ge = "newInfo", Ge = "hold", Xe = "unhold", Je = "update", ze = "sdp", Qe = "icecandidate", Ke = "getusermediafailed", je = "peerconnection:createofferfailed", Ze = "peerconnection:createanswerfailed", et = "peerconnection:setlocaldescriptionfailed", tt = "peerconnection:setremotedescriptionfailed", st = "presentation:start", nt = "presentation:started", it = "presentation:end", Ce = "presentation:ended", y = "presentation:failed", xs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
33
|
+
__proto__: null,
|
|
34
|
+
ACCEPTED: Ye,
|
|
35
|
+
ACCOUNT_CHANGED: ue,
|
|
36
|
+
ACCOUNT_DELETED: Te,
|
|
37
|
+
ADMIN_FORCE_SYNC_MEDIA_STATE: p,
|
|
38
|
+
ADMIN_START_MAIN_CAM: ie,
|
|
39
|
+
ADMIN_START_MIC: oe,
|
|
40
|
+
ADMIN_STOP_MAIN_CAM: ne,
|
|
41
|
+
ADMIN_STOP_MIC: re,
|
|
42
|
+
AVAILABLE_SECOND_REMOTE_STREAM_EVENT: X,
|
|
43
|
+
CHANNELS: P,
|
|
44
|
+
CHANNELS_NOTIFY: ee,
|
|
45
|
+
CONFERENCE_PARTICIPANT_TOKEN_ISSUED: Se,
|
|
46
|
+
CONFIRMED: v,
|
|
47
|
+
CONNECTED: O,
|
|
48
|
+
CONNECTING: w,
|
|
49
|
+
DECLINED_INCOMING_CALL: V,
|
|
50
|
+
DISCONNECTED: N,
|
|
51
|
+
ENDED: m,
|
|
52
|
+
ENDED_FROM_SERVER: te,
|
|
53
|
+
ENTER_ROOM: Q,
|
|
54
|
+
FAILED: g,
|
|
55
|
+
FAILED_INCOMING_CALL: Y,
|
|
56
|
+
GET_USER_MEDIA_FAILED: Ke,
|
|
57
|
+
HOLD: Ge,
|
|
58
|
+
ICE_CANDIDATE: Qe,
|
|
59
|
+
INCOMING_CALL: B,
|
|
60
|
+
MAIN_CAM_CONTROL: se,
|
|
61
|
+
MUST_STOP_PRESENTATION_EVENT: z,
|
|
62
|
+
MUTED: xe,
|
|
63
|
+
NEW_DTMF: Ne,
|
|
64
|
+
NEW_INFO: ge,
|
|
65
|
+
NEW_MESSAGE: ke,
|
|
66
|
+
NEW_RTC_SESSION: M,
|
|
67
|
+
NOT_AVAILABLE_SECOND_REMOTE_STREAM_EVENT: J,
|
|
68
|
+
PARTICIPANT_ADDED_TO_LIST_MODERATORS: ae,
|
|
69
|
+
PARTICIPANT_CANCELLING_WORD_REQUEST: he,
|
|
70
|
+
PARTICIPANT_MOVE_REQUEST_TO_CONFERENCE: Ee,
|
|
71
|
+
PARTICIPANT_MOVE_REQUEST_TO_STREAM: _e,
|
|
72
|
+
PARTICIPANT_REMOVED_FROM_LIST_MODERATORS: ce,
|
|
73
|
+
PEER_CONNECTION: b,
|
|
74
|
+
PEER_CONNECTION_CONFIRMED: j,
|
|
75
|
+
PEER_CONNECTION_CREATE_ANSWER_FAILED: Ze,
|
|
76
|
+
PEER_CONNECTION_CREATE_OFFER_FAILED: je,
|
|
77
|
+
PEER_CONNECTION_ONTRACK: Z,
|
|
78
|
+
PEER_CONNECTION_SET_LOCAL_DESCRIPTION_FAILED: et,
|
|
79
|
+
PEER_CONNECTION_SET_REMOTE_DESCRIPTION_FAILED: tt,
|
|
80
|
+
PRESENTATION_END: it,
|
|
81
|
+
PRESENTATION_ENDED: Ce,
|
|
82
|
+
PRESENTATION_FAILED: y,
|
|
83
|
+
PRESENTATION_START: st,
|
|
84
|
+
PRESENTATION_STARTED: nt,
|
|
85
|
+
PROGRESS: Ve,
|
|
86
|
+
REFER: Be,
|
|
87
|
+
REGISTERED: A,
|
|
88
|
+
REGISTRATION_FAILED: R,
|
|
89
|
+
REINVITE: qe,
|
|
90
|
+
REPLACES: We,
|
|
91
|
+
SDP: ze,
|
|
92
|
+
SENDING: Fe,
|
|
93
|
+
SHARE_STATE: D,
|
|
94
|
+
SIP_EVENT: G,
|
|
95
|
+
TERMINATED_INCOMING_CALL: x,
|
|
96
|
+
UNHOLD: Xe,
|
|
97
|
+
UNMUTED: $e,
|
|
98
|
+
UNREGISTERED: $,
|
|
99
|
+
UPDATE: Je,
|
|
100
|
+
USE_LICENSE: K,
|
|
101
|
+
WEBCAST_STARTED: de,
|
|
102
|
+
WEBCAST_STOPPED: le
|
|
103
|
+
}, Symbol.toStringTag, { value: "Module" })), rt = [
|
|
104
|
+
B,
|
|
105
|
+
V,
|
|
106
|
+
x,
|
|
107
|
+
Y,
|
|
108
|
+
he,
|
|
109
|
+
_e,
|
|
110
|
+
Ee,
|
|
111
|
+
ee,
|
|
112
|
+
Se,
|
|
113
|
+
ue,
|
|
114
|
+
Te,
|
|
115
|
+
de,
|
|
116
|
+
le,
|
|
117
|
+
ae,
|
|
118
|
+
ce
|
|
119
|
+
], Ae = [
|
|
120
|
+
w,
|
|
121
|
+
O,
|
|
122
|
+
N,
|
|
123
|
+
M,
|
|
124
|
+
A,
|
|
125
|
+
$,
|
|
126
|
+
R,
|
|
127
|
+
ke,
|
|
128
|
+
G
|
|
129
|
+
], ot = [
|
|
130
|
+
X,
|
|
131
|
+
J,
|
|
132
|
+
z,
|
|
133
|
+
D,
|
|
134
|
+
Q,
|
|
135
|
+
K,
|
|
136
|
+
j,
|
|
137
|
+
Z,
|
|
138
|
+
P,
|
|
139
|
+
te,
|
|
140
|
+
se,
|
|
141
|
+
ie,
|
|
142
|
+
ne,
|
|
143
|
+
re,
|
|
144
|
+
oe,
|
|
145
|
+
p
|
|
146
|
+
], Re = [
|
|
147
|
+
m,
|
|
148
|
+
w,
|
|
149
|
+
Fe,
|
|
150
|
+
qe,
|
|
151
|
+
We,
|
|
152
|
+
Be,
|
|
153
|
+
Ve,
|
|
154
|
+
Ye,
|
|
155
|
+
v,
|
|
156
|
+
b,
|
|
157
|
+
g,
|
|
158
|
+
xe,
|
|
159
|
+
$e,
|
|
160
|
+
Ne,
|
|
161
|
+
ge,
|
|
162
|
+
Ge,
|
|
163
|
+
Xe,
|
|
164
|
+
Je,
|
|
165
|
+
ze,
|
|
166
|
+
Qe,
|
|
167
|
+
Ke,
|
|
168
|
+
je,
|
|
169
|
+
Ze,
|
|
170
|
+
et,
|
|
171
|
+
tt,
|
|
172
|
+
st,
|
|
173
|
+
nt,
|
|
174
|
+
it,
|
|
175
|
+
Ce,
|
|
176
|
+
y
|
|
177
|
+
], at = [...Ae, ...rt], ct = [
|
|
178
|
+
...Re,
|
|
179
|
+
...ot
|
|
180
|
+
], $s = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
181
|
+
__proto__: null,
|
|
182
|
+
SESSION_EVENT_NAMES: ct,
|
|
183
|
+
SESSION_JSSIP_EVENT_NAMES: Re,
|
|
184
|
+
SESSION_SYNTHETICS_EVENT_NAMES: ot,
|
|
185
|
+
UA_EVENT_NAMES: at,
|
|
186
|
+
UA_JSSIP_EVENT_NAMES: Ae,
|
|
187
|
+
UA_SYNTHETICS_EVENT_NAMES: rt
|
|
188
|
+
}, Symbol.toStringTag, { value: "Module" })), qt = (r) => {
|
|
189
|
+
const e = [];
|
|
190
|
+
return r && e.push(`X-Vinteo-Remote: ${r}`), e;
|
|
191
|
+
}, Wt = "content-type", Bt = "x-webrtc-enter-room", L = "application/vinteo.webrtc.sharedesktop", Vt = "application/vinteo.webrtc.roomname", Yt = "application/vinteo.webrtc.channels", xt = "application/vinteo.webrtc.mediastate", $t = "application/vinteo.webrtc.refusal", Me = "application/vinteo.webrtc.maincam", Gt = "application/vinteo.webrtc.mic", Xt = "application/vinteo.webrtc.uselic", Jt = "X-WEBRTC-USE-LICENSE", De = "X-WEBRTC-INPUT-CHANNELS", Pe = "X-WEBRTC-OUTPUT-CHANNELS", zt = "X-WEBRTC-MAINCAM", Qt = "X-WEBRTC-MIC", pe = "X-WEBRTC-SYNC", Kt = "X-WEBRTC-MAINCAM-RESOLUTION", jt = "X-WEBRTC-MEDIA-STATE", Zt = "X-Vinteo-Media-Type", es = "X-Vinteo-MainCam-State", ts = "X-Vinteo-Mic-State", ss = "application/vinteo.webrtc.notify", ns = "X-VINTEO-NOTIFY", I = "x-webrtc-share-state", is = `${I}: LETMESTARTPRESENTATION`, rs = `${I}: STOPPRESENTATION`, Et = "YOUCANRECEIVECONTENT", _t = "CONTENTEND", os = "YOUMUSTSTOPSENDCONTENT", as = `${I}: ${Et}`, cs = `${I}: ${_t}`, Es = "X-WEBRTC-REQUEST-ENABLE-MEDIA-DEVICE", _s = `${Es}: LETMESTARTMAINCAM`, me = "sip-connector", ve = W(me), Gs = () => {
|
|
192
|
+
W.enable(`${me}`);
|
|
193
|
+
}, Xs = () => {
|
|
194
|
+
W.enable(`-${me}`);
|
|
195
|
+
};
|
|
196
|
+
var C = /* @__PURE__ */ ((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))(C || {}), k = /* @__PURE__ */ ((r) => (r.ADMIN_STOP_MIC = "ADMINSTOPMIC", r.ADMIN_START_MIC = "ADMINSTARTMIC", r))(k || {}), F = /* @__PURE__ */ ((r) => (r.ADMIN_SYNC_FORCED = "1", r.ADMIN_SYNC_NOT_FORCED = "0", r))(F || {}), hs = /* @__PURE__ */ ((r) => (r.AUDIO = "AUDIO", r.VIDEO = "VIDEO", r.AUDIOPLUSPRESENTATION = "AUDIOPLUSPRESENTATION", r))(hs || {});
|
|
197
|
+
function ds(r) {
|
|
198
|
+
return (e) => `sip:${e}@${r}`;
|
|
199
|
+
}
|
|
200
|
+
const ls = (r, e) => () => Math.floor(Math.random() * (e - r)) + r, be = (r) => r.trim().replaceAll(" ", "_"), us = ls(1e5, 99999999), H = (r, {
|
|
201
|
+
videoMode: e,
|
|
202
|
+
audioMode: t
|
|
203
|
+
} = {}) => {
|
|
204
|
+
if (!r || e === "recvonly" && t === "recvonly")
|
|
205
|
+
return;
|
|
206
|
+
const s = t === "recvonly" ? [] : r.getAudioTracks(), n = e === "recvonly" ? [] : r.getVideoTracks(), o = [...s, ...n], a = new MediaStream(o);
|
|
207
|
+
return a.getTracks = () => [...a.getAudioTracks(), ...a.getVideoTracks()], a;
|
|
208
|
+
}, Ts = (r) => r.some((t) => {
|
|
209
|
+
const { kind: s } = t;
|
|
210
|
+
return s === "video";
|
|
211
|
+
}), Ss = "Error decline with 603", Ns = (r) => r.message === Ss, gs = (r, e) => r.find((t) => t.track && e.getTracks().includes(t.track)), ht = 1, dt = (r) => (e, t) => t !== void 0 && e !== t || t === void 0 && e !== r, Cs = dt(
|
|
212
|
+
ht
|
|
213
|
+
), As = (r, e) => {
|
|
214
|
+
const t = r === void 0 ? void 0 : Math.max(r, ht);
|
|
215
|
+
if (t !== void 0 && Cs(
|
|
216
|
+
t,
|
|
217
|
+
e
|
|
218
|
+
))
|
|
219
|
+
return t;
|
|
220
|
+
}, Rs = dt(), ms = (r, e) => {
|
|
221
|
+
if (Rs(r, e))
|
|
222
|
+
return r;
|
|
223
|
+
}, Is = async (r, e, t) => {
|
|
224
|
+
const s = r.getParameters();
|
|
225
|
+
(s.encodings === void 0 || s.encodings.length === 0) && (s.encodings = [{}]);
|
|
226
|
+
const [n] = s.encodings, o = n.scaleResolutionDownBy, a = As(
|
|
227
|
+
e.scaleResolutionDownBy,
|
|
228
|
+
o
|
|
229
|
+
);
|
|
230
|
+
let c = !1;
|
|
231
|
+
a !== void 0 && (s.encodings[0].scaleResolutionDownBy = a, c = !0);
|
|
232
|
+
const E = n.maxBitrate, _ = ms(e.maxBitrate, E);
|
|
233
|
+
return _ !== void 0 && (s.encodings[0].maxBitrate = _, c = !0), c ? (t && t(s), r.setParameters(s).then(() => ({ parameters: s, isChanged: c }))) : { parameters: s, isChanged: c };
|
|
234
|
+
}, fs = async (r, e, t) => {
|
|
235
|
+
const s = gs(r, e);
|
|
236
|
+
if (s)
|
|
237
|
+
return Is(s, { maxBitrate: t });
|
|
238
|
+
}, Os = 486, Ms = 487, q = "local", ye = "remote", Js = (r = new Error()) => {
|
|
239
|
+
const { originator: e, cause: t } = r;
|
|
240
|
+
return Ct(r) ? !0 : typeof t == "string" ? t === we || t === Ue || e === q && (t === He || t === Le) : !1;
|
|
241
|
+
}, S = "SipConnector", Ds = "channels", Ps = "WebcastStarted", ps = "WebcastStopped", vs = "accountChanged", bs = "accountDeleted", ys = "addedToListModerators", ws = "removedFromListModerators", Us = "WebcastParticipationAccepted", Ls = "WebcastParticipationRejected", Hs = "ParticipantMovedToWebcast", ks = "ConferenceParticipantTokenIssued";
|
|
242
|
+
class zs {
|
|
243
|
+
constructor({ JsSIP: e }) {
|
|
244
|
+
i(this, "_isRegisterConfig", !1);
|
|
245
|
+
i(this, "_connectionConfiguration", {});
|
|
246
|
+
i(this, "_remoteStreams", {});
|
|
247
|
+
i(this, "JsSIP");
|
|
248
|
+
i(this, "_sessionEvents");
|
|
249
|
+
i(this, "_uaEvents");
|
|
250
|
+
i(this, "_cancelableConnect");
|
|
251
|
+
i(this, "_cancelableCreateUa");
|
|
252
|
+
i(this, "_cancelableDisconnect");
|
|
253
|
+
i(this, "_cancelableSet");
|
|
254
|
+
i(this, "_cancelableCall");
|
|
255
|
+
i(this, "_cancelableAnswer");
|
|
256
|
+
i(this, "_cancelableSendDTMF");
|
|
257
|
+
i(this, "getSipServerUrl", (e) => e);
|
|
258
|
+
i(this, "promisePendingStartPresentation");
|
|
259
|
+
i(this, "promisePendingStopPresentation");
|
|
260
|
+
i(this, "ua");
|
|
261
|
+
i(this, "session");
|
|
262
|
+
i(this, "incomingSession");
|
|
263
|
+
i(this, "_streamPresentationCurrent");
|
|
264
|
+
i(this, "socket");
|
|
265
|
+
i(this, "connect", async (e) => (this._cancelRequests(), this._cancelableConnect.request(e)));
|
|
266
|
+
i(this, "createUa", async (e) => this._cancelableCreateUa.request(e));
|
|
267
|
+
i(this, "set", async (e) => this._cancelableSet.request(e));
|
|
268
|
+
i(this, "call", async (e) => this._cancelableCall.request(e));
|
|
269
|
+
i(this, "disconnect", async () => (this._cancelRequests(), this._disconnectWithoutCancelRequests()));
|
|
270
|
+
i(this, "answerToIncomingCall", async (e) => this._cancelableAnswer.request(e));
|
|
271
|
+
i(this, "sendDTMF", async (e) => this._cancelableSendDTMF.request(e));
|
|
272
|
+
i(this, "hangUp", async () => (this._cancelRequests(), this._hangUpWithoutCancelRequests()));
|
|
273
|
+
i(this, "tryRegister", async () => {
|
|
274
|
+
if (!this.isRegisterConfig)
|
|
275
|
+
throw new Error("Config is not registered");
|
|
276
|
+
this._uaEvents.trigger(w, void 0);
|
|
277
|
+
try {
|
|
278
|
+
await this.unregister();
|
|
279
|
+
} catch (e) {
|
|
280
|
+
ve("tryRegister", e);
|
|
281
|
+
}
|
|
282
|
+
return this.register();
|
|
283
|
+
});
|
|
284
|
+
i(this, "declineToIncomingCall", async ({ statusCode: e = Ms } = {}) => new Promise((t, s) => {
|
|
285
|
+
if (!this.isAvailableIncomingCall) {
|
|
286
|
+
s(new Error("no incomingSession"));
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const n = this.incomingSession, o = this.remoteCallerData;
|
|
290
|
+
this._cancelableCall.cancelRequest(), this._cancelableAnswer.cancelRequest(), this.removeIncomingSession(), this._uaEvents.trigger(V, o), t(n.terminate({ status_code: e }));
|
|
291
|
+
}));
|
|
292
|
+
i(this, "busyIncomingCall", async () => this.declineToIncomingCall({ statusCode: Os }));
|
|
293
|
+
i(this, "removeIncomingSession", () => {
|
|
294
|
+
delete this.incomingSession;
|
|
295
|
+
});
|
|
296
|
+
i(this, "handleNewRTCSession", ({ originator: e, session: t }) => {
|
|
297
|
+
if (e === ye) {
|
|
298
|
+
this.incomingSession = t;
|
|
299
|
+
const s = this.remoteCallerData;
|
|
300
|
+
t.on(g, (n) => {
|
|
301
|
+
this.removeIncomingSession(), n.originator === q ? this._uaEvents.trigger(x, s) : this._uaEvents.trigger(Y, s);
|
|
302
|
+
}), this._uaEvents.trigger(B, s);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
i(this, "_connect", async (e) => this.createUa(e).then(async () => this._start()));
|
|
306
|
+
i(this, "_createUa", async ({
|
|
307
|
+
displayName: e = "",
|
|
308
|
+
user: t,
|
|
309
|
+
password: s,
|
|
310
|
+
register: n = !1,
|
|
311
|
+
sipServerUrl: o,
|
|
312
|
+
sipWebSocketServerURL: a,
|
|
313
|
+
remoteAddress: c,
|
|
314
|
+
extraHeaders: E = [],
|
|
315
|
+
sdpSemantics: _ = "plan-b",
|
|
316
|
+
sessionTimers: h = !1,
|
|
317
|
+
registerExpires: d = 60 * 5,
|
|
318
|
+
// 5 minutes in sec
|
|
319
|
+
connectionRecoveryMinInterval: l = 2,
|
|
320
|
+
connectionRecoveryMaxInterval: u = 6,
|
|
321
|
+
userAgent: f
|
|
322
|
+
}) => {
|
|
323
|
+
if (!o)
|
|
324
|
+
throw new Error("sipServerUrl is required");
|
|
325
|
+
if (!a)
|
|
326
|
+
throw new Error("sipWebSocketServerURL is required");
|
|
327
|
+
if (n && !t)
|
|
328
|
+
throw new Error("user is required for authorized connection");
|
|
329
|
+
if (n && !s)
|
|
330
|
+
throw new Error("password is required for authorized connection");
|
|
331
|
+
this._connectionConfiguration = {
|
|
332
|
+
sipServerUrl: o,
|
|
333
|
+
displayName: e,
|
|
334
|
+
register: n,
|
|
335
|
+
user: t,
|
|
336
|
+
password: s
|
|
337
|
+
}, this._init({ sipServerUrl: o, sipWebSocketServerURL: a });
|
|
338
|
+
const U = n && t ? t.trim() : `${us()}`, Ie = {
|
|
339
|
+
password: s,
|
|
340
|
+
register: n,
|
|
341
|
+
display_name: be(e),
|
|
342
|
+
user_agent: f,
|
|
343
|
+
sdp_semantics: _,
|
|
344
|
+
sockets: [this.socket],
|
|
345
|
+
uri: this.getSipServerUrl(U),
|
|
346
|
+
session_timers: h,
|
|
347
|
+
register_expires: d,
|
|
348
|
+
connection_recovery_min_interval: l,
|
|
349
|
+
connection_recovery_max_interval: u
|
|
350
|
+
};
|
|
351
|
+
this.ua && await this._disconnectWithoutCancelRequests(), this._isRegisterConfig = !!Ie.register, this.ua = new this.JsSIP.UA(Ie), this._uaEvents.eachTriggers((ut, Tt) => {
|
|
352
|
+
const fe = Ae.find((St) => St === Tt);
|
|
353
|
+
fe && this.ua && this.ua.on(fe, ut);
|
|
354
|
+
});
|
|
355
|
+
const lt = [...qt(c), ...E];
|
|
356
|
+
return this.ua.registrator().setExtraHeaders(lt), this.ua;
|
|
357
|
+
});
|
|
358
|
+
i(this, "_start", async () => new Promise((e, t) => {
|
|
359
|
+
const { ua: s } = this;
|
|
360
|
+
if (!s) {
|
|
361
|
+
t(new Error("this.ua is not initialized"));
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const n = () => {
|
|
365
|
+
c(), e(s);
|
|
366
|
+
}, o = (E) => {
|
|
367
|
+
c(), t(E);
|
|
368
|
+
}, a = () => {
|
|
369
|
+
this.isRegisterConfig ? (this.on(A, n), this.on(R, o)) : this.on(O, n), this.on(N, o);
|
|
370
|
+
}, c = () => {
|
|
371
|
+
this.off(A, n), this.off(R, o), this.off(O, n), this.off(N, o);
|
|
372
|
+
};
|
|
373
|
+
a(), this.on(M, this.handleNewRTCSession), s.start();
|
|
374
|
+
}));
|
|
375
|
+
i(this, "_set", async ({ displayName: e, password: t }) => new Promise((s, n) => {
|
|
376
|
+
const { ua: o } = this;
|
|
377
|
+
if (!o) {
|
|
378
|
+
n(new Error("this.ua is not initialized"));
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
let a = !1, c = !1;
|
|
382
|
+
e !== void 0 && e !== this._connectionConfiguration.displayName && (a = o.set("display_name", be(e)), this._connectionConfiguration.displayName = e), t !== void 0 && t !== this._connectionConfiguration.password && (c = o.set("password", t), this._connectionConfiguration.password = t);
|
|
383
|
+
const E = a || c;
|
|
384
|
+
c && this.isRegisterConfig ? this.register().then(() => {
|
|
385
|
+
s(E);
|
|
386
|
+
}).catch(n) : E ? s(E) : n(E);
|
|
387
|
+
}));
|
|
388
|
+
i(this, "_disconnectWithoutCancelRequests", async () => this._cancelableDisconnect.request());
|
|
389
|
+
i(this, "_disconnect", async () => {
|
|
390
|
+
this.off(M, this.handleNewRTCSession);
|
|
391
|
+
const e = new Promise((t) => {
|
|
392
|
+
this.once(N, () => {
|
|
393
|
+
delete this.ua, t();
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
return this.ua ? (await this._hangUpWithoutCancelRequests(), this.ua ? this.ua.stop() : this._uaEvents.trigger(N, void 0)) : this._uaEvents.trigger(N, void 0), e;
|
|
397
|
+
});
|
|
398
|
+
i(this, "_call", async ({
|
|
399
|
+
number: e,
|
|
400
|
+
mediaStream: t,
|
|
401
|
+
extraHeaders: s = [],
|
|
402
|
+
ontrack: n,
|
|
403
|
+
iceServers: o,
|
|
404
|
+
videoMode: a,
|
|
405
|
+
audioMode: c,
|
|
406
|
+
degradationPreference: E,
|
|
407
|
+
offerToReceiveAudio: _ = !0,
|
|
408
|
+
offerToReceiveVideo: h = !0
|
|
409
|
+
}) => new Promise((d, l) => {
|
|
410
|
+
const { ua: u } = this;
|
|
411
|
+
if (!u) {
|
|
412
|
+
l(new Error("this.ua is not initialized"));
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
this._connectionConfiguration.number = e, this._connectionConfiguration.answer = !1, this._handleCall({ ontrack: n }).then(d).catch(l), this.session = u.call(this.getSipServerUrl(e), {
|
|
416
|
+
extraHeaders: s,
|
|
417
|
+
mediaStream: H(t, {
|
|
418
|
+
videoMode: a,
|
|
419
|
+
audioMode: c
|
|
420
|
+
}),
|
|
421
|
+
eventHandlers: this._sessionEvents.triggers,
|
|
422
|
+
videoMode: a,
|
|
423
|
+
audioMode: c,
|
|
424
|
+
degradationPreference: E,
|
|
425
|
+
pcConfig: {
|
|
426
|
+
iceServers: o
|
|
427
|
+
},
|
|
428
|
+
rtcOfferConstraints: {
|
|
429
|
+
offerToReceiveAudio: _,
|
|
430
|
+
offerToReceiveVideo: h
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
}));
|
|
434
|
+
i(this, "_answer", async ({
|
|
435
|
+
mediaStream: e,
|
|
436
|
+
ontrack: t,
|
|
437
|
+
extraHeaders: s = [],
|
|
438
|
+
iceServers: n,
|
|
439
|
+
videoMode: o,
|
|
440
|
+
audioMode: a,
|
|
441
|
+
degradationPreference: c
|
|
442
|
+
}) => new Promise((E, _) => {
|
|
443
|
+
if (!this.isAvailableIncomingCall) {
|
|
444
|
+
_(new Error("no incomingSession"));
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
this.session = this.incomingSession, this.removeIncomingSession();
|
|
448
|
+
const { session: h } = this;
|
|
449
|
+
if (!h) {
|
|
450
|
+
_(new Error("No session established"));
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
this._sessionEvents.eachTriggers((l, u) => {
|
|
454
|
+
const f = Re.find((U) => U === u);
|
|
455
|
+
f && h.on(f, l);
|
|
456
|
+
}), this._connectionConfiguration.answer = !0, this._connectionConfiguration.number = h.remote_identity.uri.user, this._handleCall({ ontrack: t }).then(E).catch(_);
|
|
457
|
+
const d = H(e, {
|
|
458
|
+
videoMode: o,
|
|
459
|
+
audioMode: a
|
|
460
|
+
});
|
|
461
|
+
h.answer({
|
|
462
|
+
extraHeaders: s,
|
|
463
|
+
videoMode: o,
|
|
464
|
+
audioMode: a,
|
|
465
|
+
degradationPreference: c,
|
|
466
|
+
mediaStream: d,
|
|
467
|
+
pcConfig: {
|
|
468
|
+
iceServers: n
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}));
|
|
472
|
+
i(this, "_handleCall", async ({ ontrack: e }) => new Promise((t, s) => {
|
|
473
|
+
const n = () => {
|
|
474
|
+
this.onSession(b, h), this.onSession(v, d);
|
|
475
|
+
}, o = () => {
|
|
476
|
+
this.offSession(b, h), this.offSession(v, d);
|
|
477
|
+
}, a = () => {
|
|
478
|
+
this.onSession(g, E), this.onSession(m, E);
|
|
479
|
+
}, c = () => {
|
|
480
|
+
this.offSession(g, E), this.offSession(m, E);
|
|
481
|
+
}, E = (l) => {
|
|
482
|
+
o(), c(), s(l);
|
|
483
|
+
};
|
|
484
|
+
let _;
|
|
485
|
+
const h = ({ peerconnection: l }) => {
|
|
486
|
+
_ = l, _.ontrack = (u) => {
|
|
487
|
+
this._sessionEvents.trigger(Z, _), e && e(u);
|
|
488
|
+
};
|
|
489
|
+
}, d = () => {
|
|
490
|
+
_ && this._sessionEvents.trigger(j, _), o(), c(), t(_);
|
|
491
|
+
};
|
|
492
|
+
n(), a();
|
|
493
|
+
}));
|
|
494
|
+
i(this, "_restoreSession", () => {
|
|
495
|
+
this._resetPresentation(), delete this._connectionConfiguration.number, delete this.session, this._remoteStreams = {};
|
|
496
|
+
});
|
|
497
|
+
i(this, "_sendDTMF", async (e) => new Promise((t, s) => {
|
|
498
|
+
const { session: n } = this;
|
|
499
|
+
if (!n) {
|
|
500
|
+
s(new Error("No session established"));
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
this.onceSession(Ne, ({ originator: o }) => {
|
|
504
|
+
o === q && t();
|
|
505
|
+
}), n.sendDTMF(e, {
|
|
506
|
+
duration: 120,
|
|
507
|
+
interToneGap: 600
|
|
508
|
+
});
|
|
509
|
+
}));
|
|
510
|
+
i(this, "_hangUpWithoutCancelRequests", async () => {
|
|
511
|
+
if (this.ua && this.session) {
|
|
512
|
+
const { session: e } = this;
|
|
513
|
+
this._streamPresentationCurrent && await this.stopPresentation(), this._restoreSession(), e.isEnded() || e.terminate();
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
i(this, "_handleShareState", (e) => {
|
|
517
|
+
switch (e) {
|
|
518
|
+
case Et: {
|
|
519
|
+
this._sessionEvents.trigger(X, void 0);
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
case _t: {
|
|
523
|
+
this._sessionEvents.trigger(J, void 0);
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
case os: {
|
|
527
|
+
this._sessionEvents.trigger(z, void 0);
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
i(this, "_maybeTriggerChannels", (e) => {
|
|
533
|
+
const t = e.getHeader(De), s = e.getHeader(Pe);
|
|
534
|
+
if (t && s) {
|
|
535
|
+
const n = {
|
|
536
|
+
inputChannels: t,
|
|
537
|
+
outputChannels: s
|
|
538
|
+
};
|
|
539
|
+
this._sessionEvents.trigger(P, n);
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
i(this, "_handleNotify", (e) => {
|
|
543
|
+
switch (e.cmd) {
|
|
544
|
+
case Ds: {
|
|
545
|
+
const t = e;
|
|
546
|
+
this._triggerChannelsNotify(t);
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
case Ps: {
|
|
550
|
+
const t = e;
|
|
551
|
+
this._triggerWebcastStartedNotify(t);
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
case ps: {
|
|
555
|
+
const t = e;
|
|
556
|
+
this._triggerWebcastStoppedNotify(t);
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
case ys: {
|
|
560
|
+
const t = e;
|
|
561
|
+
this._triggerAddedToListModeratorsNotify(t);
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
case ws: {
|
|
565
|
+
const t = e;
|
|
566
|
+
this._triggerRemovedFromListModeratorsNotify(t);
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
case Us: {
|
|
570
|
+
const t = e;
|
|
571
|
+
this._triggerParticipantMoveRequestToConference(t);
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
case Ls: {
|
|
575
|
+
const t = e;
|
|
576
|
+
this._triggerParticipantCancelingWordRequest(t);
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
case Hs: {
|
|
580
|
+
const t = e;
|
|
581
|
+
this._triggerParticipantMoveRequestToStream(t);
|
|
582
|
+
break;
|
|
583
|
+
}
|
|
584
|
+
case vs: {
|
|
585
|
+
this._triggerAccountChangedNotify();
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
case bs: {
|
|
589
|
+
this._triggerAccountDeletedNotify();
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
case ks: {
|
|
593
|
+
const t = e;
|
|
594
|
+
this._triggerConferenceParticipantTokenIssued(t);
|
|
595
|
+
break;
|
|
596
|
+
}
|
|
597
|
+
default:
|
|
598
|
+
ve("unknown cmd", e.cmd);
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
i(this, "_triggerRemovedFromListModeratorsNotify", ({
|
|
602
|
+
conference: e
|
|
603
|
+
}) => {
|
|
604
|
+
const t = {
|
|
605
|
+
conference: e
|
|
606
|
+
};
|
|
607
|
+
this._uaEvents.trigger(
|
|
608
|
+
ce,
|
|
609
|
+
t
|
|
610
|
+
);
|
|
611
|
+
});
|
|
612
|
+
i(this, "_triggerAddedToListModeratorsNotify", ({ conference: e }) => {
|
|
613
|
+
const t = {
|
|
614
|
+
conference: e
|
|
615
|
+
};
|
|
616
|
+
this._uaEvents.trigger(ae, t);
|
|
617
|
+
});
|
|
618
|
+
i(this, "_triggerWebcastStartedNotify", ({ body: { conference: e, type: t } }) => {
|
|
619
|
+
const s = {
|
|
620
|
+
conference: e,
|
|
621
|
+
type: t
|
|
622
|
+
};
|
|
623
|
+
this._uaEvents.trigger(de, s);
|
|
624
|
+
});
|
|
625
|
+
i(this, "_triggerWebcastStoppedNotify", ({ body: { conference: e, type: t } }) => {
|
|
626
|
+
const s = {
|
|
627
|
+
conference: e,
|
|
628
|
+
type: t
|
|
629
|
+
};
|
|
630
|
+
this._uaEvents.trigger(le, s);
|
|
631
|
+
});
|
|
632
|
+
i(this, "_triggerAccountChangedNotify", () => {
|
|
633
|
+
this._uaEvents.trigger(ue, void 0);
|
|
634
|
+
});
|
|
635
|
+
i(this, "_triggerAccountDeletedNotify", () => {
|
|
636
|
+
this._uaEvents.trigger(Te, void 0);
|
|
637
|
+
});
|
|
638
|
+
i(this, "_triggerConferenceParticipantTokenIssued", ({
|
|
639
|
+
body: { conference: e, participant: t, jwt: s }
|
|
640
|
+
}) => {
|
|
641
|
+
const n = {
|
|
642
|
+
conference: e,
|
|
643
|
+
participant: t,
|
|
644
|
+
jwt: s
|
|
645
|
+
};
|
|
646
|
+
this._uaEvents.trigger(
|
|
647
|
+
Se,
|
|
648
|
+
n
|
|
649
|
+
);
|
|
650
|
+
});
|
|
651
|
+
i(this, "_triggerChannelsNotify", (e) => {
|
|
652
|
+
const t = e.input, s = e.output, n = {
|
|
653
|
+
inputChannels: t,
|
|
654
|
+
outputChannels: s
|
|
655
|
+
};
|
|
656
|
+
this._uaEvents.trigger(ee, n);
|
|
657
|
+
});
|
|
658
|
+
i(this, "_triggerParticipantMoveRequestToConference", ({
|
|
659
|
+
body: { conference: e }
|
|
660
|
+
}) => {
|
|
661
|
+
const t = {
|
|
662
|
+
conference: e
|
|
663
|
+
};
|
|
664
|
+
this._uaEvents.trigger(Ee, t);
|
|
665
|
+
});
|
|
666
|
+
i(this, "_triggerParticipantCancelingWordRequest", ({
|
|
667
|
+
body: { conference: e }
|
|
668
|
+
}) => {
|
|
669
|
+
const t = {
|
|
670
|
+
conference: e
|
|
671
|
+
};
|
|
672
|
+
this._uaEvents.trigger(he, t);
|
|
673
|
+
});
|
|
674
|
+
i(this, "_triggerParticipantMoveRequestToStream", ({
|
|
675
|
+
body: { conference: e }
|
|
676
|
+
}) => {
|
|
677
|
+
const t = {
|
|
678
|
+
conference: e
|
|
679
|
+
};
|
|
680
|
+
this._uaEvents.trigger(_e, t);
|
|
681
|
+
});
|
|
682
|
+
i(this, "_triggerEnterRoom", (e) => {
|
|
683
|
+
const t = e.getHeader(Bt);
|
|
684
|
+
this._sessionEvents.trigger(Q, t);
|
|
685
|
+
});
|
|
686
|
+
i(this, "_triggerShareState", (e) => {
|
|
687
|
+
const t = e.getHeader(I);
|
|
688
|
+
this._sessionEvents.trigger(D, t);
|
|
689
|
+
});
|
|
690
|
+
i(this, "_triggerMainCamControl", (e) => {
|
|
691
|
+
const t = e.getHeader(zt), s = e.getHeader(pe), n = s === F.ADMIN_SYNC_FORCED;
|
|
692
|
+
if (t === C.ADMIN_START_MAIN_CAM)
|
|
693
|
+
this._sessionEvents.trigger(ie, { isSyncForced: n });
|
|
694
|
+
else if (t === C.ADMIN_STOP_MAIN_CAM)
|
|
695
|
+
this._sessionEvents.trigger(ne, { isSyncForced: n });
|
|
696
|
+
else if ((t === C.RESUME_MAIN_CAM || t === C.PAUSE_MAIN_CAM) && s)
|
|
697
|
+
this._sessionEvents.trigger(p, { isSyncForced: n });
|
|
698
|
+
else {
|
|
699
|
+
const o = e.getHeader(Kt);
|
|
700
|
+
this._sessionEvents.trigger(se, {
|
|
701
|
+
mainCam: t,
|
|
702
|
+
resolutionMainCam: o
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
i(this, "_triggerMicControl", (e) => {
|
|
707
|
+
const t = e.getHeader(Qt), n = e.getHeader(pe) === F.ADMIN_SYNC_FORCED;
|
|
708
|
+
t === k.ADMIN_START_MIC ? this._sessionEvents.trigger(oe, { isSyncForced: n }) : t === k.ADMIN_STOP_MIC && this._sessionEvents.trigger(re, { isSyncForced: n });
|
|
709
|
+
});
|
|
710
|
+
i(this, "_triggerUseLicense", (e) => {
|
|
711
|
+
const t = e.getHeader(Jt);
|
|
712
|
+
this._sessionEvents.trigger(K, t);
|
|
713
|
+
});
|
|
714
|
+
i(this, "_handleNewInfo", (e) => {
|
|
715
|
+
const { originator: t } = e;
|
|
716
|
+
if (t !== "remote")
|
|
717
|
+
return;
|
|
718
|
+
const { request: s } = e, n = s.getHeader(Wt);
|
|
719
|
+
if (n)
|
|
720
|
+
switch (n) {
|
|
721
|
+
case Vt: {
|
|
722
|
+
this._triggerEnterRoom(s), this._maybeTriggerChannels(s);
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
case ss: {
|
|
726
|
+
this._maybeHandleNotify(s);
|
|
727
|
+
break;
|
|
728
|
+
}
|
|
729
|
+
case L: {
|
|
730
|
+
this._triggerShareState(s);
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
case Me: {
|
|
734
|
+
this._triggerMainCamControl(s);
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
case Gt: {
|
|
738
|
+
this._triggerMicControl(s);
|
|
739
|
+
break;
|
|
740
|
+
}
|
|
741
|
+
case Xt: {
|
|
742
|
+
this._triggerUseLicense(s);
|
|
743
|
+
break;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
i(this, "_handleSipEvent", ({ request: e }) => {
|
|
748
|
+
this._maybeHandleNotify(e);
|
|
749
|
+
});
|
|
750
|
+
i(this, "_maybeHandleNotify", (e) => {
|
|
751
|
+
const t = e.getHeader(ns);
|
|
752
|
+
if (t) {
|
|
753
|
+
const s = JSON.parse(t);
|
|
754
|
+
this._handleNotify(s);
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
i(this, "_handleEnded", (e) => {
|
|
758
|
+
const { originator: t } = e;
|
|
759
|
+
t === ye && this._sessionEvents.trigger(te, e), this._restoreSession();
|
|
760
|
+
});
|
|
761
|
+
this.JsSIP = e, this._sessionEvents = new Oe(ct), this._uaEvents = new Oe(at), this._cancelableConnect = new T(
|
|
762
|
+
this._connect,
|
|
763
|
+
{
|
|
764
|
+
moduleName: S,
|
|
765
|
+
afterCancelRequest: () => {
|
|
766
|
+
this._cancelableCreateUa.cancelRequest(), this._cancelableDisconnect.cancelRequest();
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
), this._cancelableCreateUa = new T(this._createUa, { moduleName: S }), this._cancelableDisconnect = new T(
|
|
770
|
+
this._disconnect,
|
|
771
|
+
{ moduleName: S }
|
|
772
|
+
), this._cancelableSet = new T(this._set, {
|
|
773
|
+
moduleName: S
|
|
774
|
+
}), this._cancelableCall = new T(
|
|
775
|
+
this._call,
|
|
776
|
+
{ moduleName: S }
|
|
777
|
+
), this._cancelableAnswer = new T(this._answer, { moduleName: S }), this._cancelableSendDTMF = new T(this._sendDTMF, { moduleName: S }), this.onSession(D, this._handleShareState), this.onSession(ge, this._handleNewInfo), this.on(G, this._handleSipEvent), this.onSession(g, this._handleEnded), this.onSession(m, this._handleEnded);
|
|
778
|
+
}
|
|
779
|
+
async register() {
|
|
780
|
+
return new Promise((e, t) => {
|
|
781
|
+
this.isRegisterConfig && this.ua ? (this.ua.on(A, e), this.ua.on(R, t), this.ua.register()) : t(new Error("Config is not registered"));
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
async unregister() {
|
|
785
|
+
return new Promise((e, t) => {
|
|
786
|
+
this.isRegistered && this.ua ? (this.ua.on($, e), this.ua.unregister()) : t(new Error("ua is not registered"));
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
async sendOptions(e, t, s) {
|
|
790
|
+
if (!this.ua)
|
|
791
|
+
throw new Error("is not connected");
|
|
792
|
+
return new Promise((n, o) => {
|
|
793
|
+
try {
|
|
794
|
+
this.ua.sendOptions(e, t, {
|
|
795
|
+
extraHeaders: s,
|
|
796
|
+
eventHandlers: {
|
|
797
|
+
succeeded: () => {
|
|
798
|
+
n();
|
|
799
|
+
},
|
|
800
|
+
failed: o
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
} catch (a) {
|
|
804
|
+
o(a);
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
async ping(e, t) {
|
|
809
|
+
var n;
|
|
810
|
+
if (!((n = this.ua) != null && n.configuration.uri))
|
|
811
|
+
throw new Error("is not connected");
|
|
812
|
+
const s = this.ua.configuration.uri;
|
|
813
|
+
return this.sendOptions(s, e, t);
|
|
814
|
+
}
|
|
815
|
+
async replaceMediaStream(e, t) {
|
|
816
|
+
if (!this.session)
|
|
817
|
+
throw new Error("No session established");
|
|
818
|
+
return this.session.replaceMediaStream(e, t);
|
|
819
|
+
}
|
|
820
|
+
async askPermissionToEnableCam(e = {}) {
|
|
821
|
+
if (!this.session)
|
|
822
|
+
throw new Error("No session established");
|
|
823
|
+
const t = [_s];
|
|
824
|
+
return this.session.sendInfo(Me, void 0, {
|
|
825
|
+
noTerminateWhenError: !0,
|
|
826
|
+
...e,
|
|
827
|
+
extraHeaders: t
|
|
828
|
+
}).catch((s) => {
|
|
829
|
+
if (Ns(s))
|
|
830
|
+
throw s;
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
get isPendingPresentation() {
|
|
834
|
+
return !!this.promisePendingStartPresentation || !!this.promisePendingStopPresentation;
|
|
835
|
+
}
|
|
836
|
+
async _sendPresentation(e, t, {
|
|
837
|
+
maxBitrate: s,
|
|
838
|
+
degradationPreference: n,
|
|
839
|
+
isNeedReinvite: o = !0,
|
|
840
|
+
isP2P: a = !1
|
|
841
|
+
}) {
|
|
842
|
+
const c = H(t);
|
|
843
|
+
this._streamPresentationCurrent = c;
|
|
844
|
+
const E = a ? [as] : [is], _ = e.sendInfo(L, void 0, {
|
|
845
|
+
extraHeaders: E
|
|
846
|
+
}).then(async () => e.startPresentation(
|
|
847
|
+
c,
|
|
848
|
+
o,
|
|
849
|
+
n
|
|
850
|
+
)).then(async () => {
|
|
851
|
+
const { connection: h } = this;
|
|
852
|
+
if (!h || s === void 0)
|
|
853
|
+
return;
|
|
854
|
+
const d = h.getSenders();
|
|
855
|
+
return fs(d, t, s);
|
|
856
|
+
}).then(() => t).catch((h) => {
|
|
857
|
+
throw this._sessionEvents.trigger(y, h), h;
|
|
858
|
+
});
|
|
859
|
+
return this.promisePendingStartPresentation = _, _.finally(() => {
|
|
860
|
+
this.promisePendingStartPresentation = void 0;
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
async startPresentation(e, {
|
|
864
|
+
isNeedReinvite: t = !0,
|
|
865
|
+
isP2P: s = !1,
|
|
866
|
+
maxBitrate: n,
|
|
867
|
+
degradationPreference: o
|
|
868
|
+
} = {}) {
|
|
869
|
+
const a = this.establishedSession;
|
|
870
|
+
if (!a)
|
|
871
|
+
throw new Error("No session established");
|
|
872
|
+
if (this._streamPresentationCurrent)
|
|
873
|
+
throw new Error("Presentation is already started");
|
|
874
|
+
return this._sendPresentation(a, e, {
|
|
875
|
+
isNeedReinvite: t,
|
|
876
|
+
isP2P: s,
|
|
877
|
+
maxBitrate: n,
|
|
878
|
+
degradationPreference: o
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
async stopPresentation({
|
|
882
|
+
isP2P: e = !1
|
|
883
|
+
} = {}) {
|
|
884
|
+
const t = this._streamPresentationCurrent;
|
|
885
|
+
let s = this.promisePendingStartPresentation ?? Promise.resolve();
|
|
886
|
+
const n = e ? [cs] : [rs], o = this.establishedSession;
|
|
887
|
+
return o && t && (s = s.then(async () => o.sendInfo(L, void 0, {
|
|
888
|
+
extraHeaders: n
|
|
889
|
+
})).then(async () => o.stopPresentation(t)).catch((a) => {
|
|
890
|
+
throw this._sessionEvents.trigger(y, a), a;
|
|
891
|
+
})), !o && t && this._sessionEvents.trigger(Ce, t), this.promisePendingStopPresentation = s, s.finally(() => {
|
|
892
|
+
this._resetPresentation();
|
|
893
|
+
});
|
|
894
|
+
}
|
|
895
|
+
async updatePresentation(e, {
|
|
896
|
+
isP2P: t = !1,
|
|
897
|
+
maxBitrate: s,
|
|
898
|
+
degradationPreference: n
|
|
899
|
+
} = {}) {
|
|
900
|
+
const o = this.establishedSession;
|
|
901
|
+
if (!o)
|
|
902
|
+
throw new Error("No session established");
|
|
903
|
+
if (!this._streamPresentationCurrent)
|
|
904
|
+
throw new Error("Presentation has not started yet");
|
|
905
|
+
return this.promisePendingStartPresentation && await this.promisePendingStartPresentation, this._sendPresentation(o, e, {
|
|
906
|
+
isP2P: t,
|
|
907
|
+
maxBitrate: s,
|
|
908
|
+
degradationPreference: n,
|
|
909
|
+
isNeedReinvite: !1
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
_resetPresentation() {
|
|
913
|
+
delete this._streamPresentationCurrent, this.promisePendingStartPresentation = void 0, this.promisePendingStopPresentation = void 0;
|
|
914
|
+
}
|
|
915
|
+
on(e, t) {
|
|
916
|
+
return this._uaEvents.on(e, t);
|
|
917
|
+
}
|
|
918
|
+
once(e, t) {
|
|
919
|
+
return this._uaEvents.once(e, t);
|
|
920
|
+
}
|
|
921
|
+
onceRace(e, t) {
|
|
922
|
+
return this._uaEvents.onceRace(e, t);
|
|
923
|
+
}
|
|
924
|
+
async wait(e) {
|
|
925
|
+
return this._uaEvents.wait(e);
|
|
926
|
+
}
|
|
927
|
+
off(e, t) {
|
|
928
|
+
this._uaEvents.off(e, t);
|
|
929
|
+
}
|
|
930
|
+
onSession(e, t) {
|
|
931
|
+
return this._sessionEvents.on(e, t);
|
|
932
|
+
}
|
|
933
|
+
onceSession(e, t) {
|
|
934
|
+
return this._sessionEvents.once(e, t);
|
|
935
|
+
}
|
|
936
|
+
onceRaceSession(e, t) {
|
|
937
|
+
return this._sessionEvents.onceRace(e, t);
|
|
938
|
+
}
|
|
939
|
+
async waitSession(e) {
|
|
940
|
+
return this._sessionEvents.wait(e);
|
|
941
|
+
}
|
|
942
|
+
offSession(e, t) {
|
|
943
|
+
this._sessionEvents.off(e, t);
|
|
944
|
+
}
|
|
945
|
+
isConfigured() {
|
|
946
|
+
return !!this.ua;
|
|
947
|
+
}
|
|
948
|
+
getConnectionConfiguration() {
|
|
949
|
+
return { ...this._connectionConfiguration };
|
|
950
|
+
}
|
|
951
|
+
getRemoteStreams() {
|
|
952
|
+
if (!this.connection)
|
|
953
|
+
return;
|
|
954
|
+
const t = this.connection.getReceivers().map(({ track: s }) => s);
|
|
955
|
+
return Ts(t) ? this._generateStreams(t) : this._generateAudioStreams(t);
|
|
956
|
+
}
|
|
957
|
+
get connection() {
|
|
958
|
+
var t;
|
|
959
|
+
return (t = this.session) == null ? void 0 : t.connection;
|
|
960
|
+
}
|
|
961
|
+
get remoteCallerData() {
|
|
962
|
+
var e, t, s, n, o, a;
|
|
963
|
+
return {
|
|
964
|
+
displayName: (t = (e = this.incomingSession) == null ? void 0 : e.remote_identity) == null ? void 0 : t.display_name,
|
|
965
|
+
host: (n = (s = this.incomingSession) == null ? void 0 : s.remote_identity) == null ? void 0 : n.uri.host,
|
|
966
|
+
incomingNumber: (a = (o = this.incomingSession) == null ? void 0 : o.remote_identity) == null ? void 0 : a.uri.user,
|
|
967
|
+
session: this.incomingSession
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
get requested() {
|
|
971
|
+
return this._cancelableConnect.requested || this._cancelableCreateUa.requested || this._cancelableCall.requested || this._cancelableAnswer.requested;
|
|
972
|
+
}
|
|
973
|
+
get establishedSession() {
|
|
974
|
+
return this.session && this.session.isEstablished() ? this.session : void 0;
|
|
975
|
+
}
|
|
976
|
+
get isRegistered() {
|
|
977
|
+
return !!this.ua && this.ua.isRegistered();
|
|
978
|
+
}
|
|
979
|
+
get isRegisterConfig() {
|
|
980
|
+
return !!this.ua && this._isRegisterConfig;
|
|
981
|
+
}
|
|
982
|
+
get isCallActive() {
|
|
983
|
+
return !!(this.ua && this.session);
|
|
984
|
+
}
|
|
985
|
+
get isAvailableIncomingCall() {
|
|
986
|
+
return !!this.incomingSession;
|
|
987
|
+
}
|
|
988
|
+
_init({
|
|
989
|
+
sipServerUrl: e,
|
|
990
|
+
sipWebSocketServerURL: t
|
|
991
|
+
}) {
|
|
992
|
+
this.getSipServerUrl = ds(e), this.socket = new this.JsSIP.WebSocketInterface(t);
|
|
993
|
+
}
|
|
994
|
+
_generateStream(e, t) {
|
|
995
|
+
const { id: s } = e, n = this._remoteStreams[s] || new MediaStream();
|
|
996
|
+
return t && n.addTrack(t), n.addTrack(e), this._remoteStreams[s] = n, n;
|
|
997
|
+
}
|
|
998
|
+
_generateAudioStream(e) {
|
|
999
|
+
const { id: t } = e, s = this._remoteStreams[t] || new MediaStream();
|
|
1000
|
+
return s.addTrack(e), this._remoteStreams[t] = s, s;
|
|
1001
|
+
}
|
|
1002
|
+
_generateStreams(e) {
|
|
1003
|
+
const t = [];
|
|
1004
|
+
return e.forEach((s, n) => {
|
|
1005
|
+
if (s.kind === "audio")
|
|
1006
|
+
return;
|
|
1007
|
+
const o = s, a = e[n - 1];
|
|
1008
|
+
let c;
|
|
1009
|
+
a && a.kind === "audio" && (c = a);
|
|
1010
|
+
const E = this._generateStream(o, c);
|
|
1011
|
+
t.push(E);
|
|
1012
|
+
}), t;
|
|
1013
|
+
}
|
|
1014
|
+
_generateAudioStreams(e) {
|
|
1015
|
+
return e.map((s) => this._generateAudioStream(s));
|
|
1016
|
+
}
|
|
1017
|
+
_cancelRequests() {
|
|
1018
|
+
this._cancelActionsRequests(), this._cancelCallRequests(), this._cancelConnectRequests();
|
|
1019
|
+
}
|
|
1020
|
+
_cancelConnectRequests() {
|
|
1021
|
+
this._cancelableConnect.cancelRequest();
|
|
1022
|
+
}
|
|
1023
|
+
_cancelCallRequests() {
|
|
1024
|
+
this._cancelableCall.cancelRequest(), this._cancelableAnswer.cancelRequest();
|
|
1025
|
+
}
|
|
1026
|
+
_cancelActionsRequests() {
|
|
1027
|
+
this._cancelableAnswer.cancelRequest(), this._cancelableSendDTMF.cancelRequest();
|
|
1028
|
+
}
|
|
1029
|
+
async waitChannels() {
|
|
1030
|
+
return this.waitSession(P);
|
|
1031
|
+
}
|
|
1032
|
+
async waitSyncMediaState() {
|
|
1033
|
+
return this.waitSession(p);
|
|
1034
|
+
}
|
|
1035
|
+
async sendChannels({ inputChannels: e, outputChannels: t }) {
|
|
1036
|
+
if (!this.session)
|
|
1037
|
+
throw new Error("No session established");
|
|
1038
|
+
const s = `${De}: ${e}`, n = `${Pe}: ${t}`, o = [
|
|
1039
|
+
s,
|
|
1040
|
+
n
|
|
1041
|
+
];
|
|
1042
|
+
return this.session.sendInfo(Yt, void 0, { extraHeaders: o });
|
|
1043
|
+
}
|
|
1044
|
+
async sendMediaState({ cam: e, mic: t }, s = {}) {
|
|
1045
|
+
if (!this.session)
|
|
1046
|
+
throw new Error("No session established");
|
|
1047
|
+
const n = `${jt}: currentstate`, o = `${es}: ${Number(e)}`, a = `${ts}: ${Number(t)}`, c = [
|
|
1048
|
+
n,
|
|
1049
|
+
o,
|
|
1050
|
+
a
|
|
1051
|
+
];
|
|
1052
|
+
return this.session.sendInfo(xt, void 0, {
|
|
1053
|
+
noTerminateWhenError: !0,
|
|
1054
|
+
...s,
|
|
1055
|
+
extraHeaders: c
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
async _sendRefusalToTurnOn(e, t = {}) {
|
|
1059
|
+
if (!this.session)
|
|
1060
|
+
throw new Error("No session established");
|
|
1061
|
+
const c = [`${Zt}: ${e === "mic" ? 0 : 1}`];
|
|
1062
|
+
return this.session.sendInfo($t, void 0, {
|
|
1063
|
+
noTerminateWhenError: !0,
|
|
1064
|
+
...t,
|
|
1065
|
+
extraHeaders: c
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
async sendRefusalToTurnOnMic(e = {}) {
|
|
1069
|
+
if (!this.session)
|
|
1070
|
+
throw new Error("No session established");
|
|
1071
|
+
return this._sendRefusalToTurnOn("mic", { noTerminateWhenError: !0, ...e });
|
|
1072
|
+
}
|
|
1073
|
+
async sendRefusalToTurnOnCam(e = {}) {
|
|
1074
|
+
if (!this.session)
|
|
1075
|
+
throw new Error("No session established");
|
|
1076
|
+
return this._sendRefusalToTurnOn("cam", { noTerminateWhenError: !0, ...e });
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
export {
|
|
1080
|
+
kt as B,
|
|
1081
|
+
C as E,
|
|
1082
|
+
Mt as N,
|
|
1083
|
+
Ue as R,
|
|
1084
|
+
zs as S,
|
|
1085
|
+
at as U,
|
|
1086
|
+
xs as a,
|
|
1087
|
+
Gs as b,
|
|
1088
|
+
Ys as c,
|
|
1089
|
+
Xs as d,
|
|
1090
|
+
$s as e,
|
|
1091
|
+
k as f,
|
|
1092
|
+
F as g,
|
|
1093
|
+
Js as h,
|
|
1094
|
+
hs as i,
|
|
1095
|
+
ct as j,
|
|
1096
|
+
ve as l,
|
|
1097
|
+
Is as s
|
|
1098
|
+
};
|