@ikonai/sdk 1.11.3 → 1.13.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/assets/audio-capture-worker-ubWDRLA3.js +1 -0
- package/assets/audio-playback-worker-CLT3Fd56.js +1 -0
- package/assets/protocol-worker-CFNK2Kvc.js +3 -0
- package/assets/video-capture-worker-Desm980E.js +1 -0
- package/assets/video-playback-worker-CsK7Q7OV.js +1 -0
- package/assets/viseme-worker-BXdOSahC.js +1 -0
- package/{channel-manager-ehgy3BJp.js → channel-manager-C1NK3o9-.js} +26 -26
- package/client/ikon-client-config.d.ts +19 -12
- package/client/ikon-client-config.d.ts.map +1 -1
- package/client/ikon-client.d.ts +14 -0
- package/client/ikon-client.d.ts.map +1 -1
- package/connection/authenticator.d.ts.map +1 -1
- package/{dist-BrkppKKs.js → dist-CNpJsuru.js} +3 -3
- package/errors/index.d.ts +10 -0
- package/errors/index.d.ts.map +1 -1
- package/functions/browser-functions.d.ts.map +1 -1
- package/functions/media-capture-functions.d.ts.map +1 -1
- package/functions/sound-functions.d.ts +4 -0
- package/functions/sound-functions.d.ts.map +1 -1
- package/{ikon-media-BQjL59S_.js → ikon-media-BNN-Q8p2.js} +28 -8
- package/{ikon-media-capture-4aEsbGgC.js → ikon-media-capture-BM64MF85.js} +131 -127
- package/index.d.ts +2 -2
- package/index.d.ts.map +1 -1
- package/index.js +2524 -2948
- package/media/ikon-media-capture.d.ts +1 -1
- package/media/ikon-media-capture.d.ts.map +1 -1
- package/media/ikon-video-capture.d.ts +11 -1
- package/media/ikon-video-capture.d.ts.map +1 -1
- package/media/ikon-video-playback.d.ts +12 -0
- package/media/ikon-video-playback.d.ts.map +1 -1
- package/media/index.d.ts +1 -1
- package/media/index.d.ts.map +1 -1
- package/media/viseme-tracker.d.ts +16 -5
- package/media/viseme-tracker.d.ts.map +1 -1
- package/{media-session-helper-Do-OxyU6.js → media-session-helper-CTZ867xv.js} +2 -2
- package/package.json +4 -1
- package/upload/file-upload.d.ts +4 -5
- package/upload/file-upload.d.ts.map +1 -1
- package/utils/query-params.d.ts +3 -1
- package/utils/query-params.d.ts.map +1 -1
- package/{viseme-tracker-CAtczW00.js → viseme-tracker-Ctuu8PRU.js} +69 -58
- package/{web-transport-support-Cdyk4mQe.js → web-transport-support-DcxJuxz4.js} +28 -22
- package/webrtc/webrtc-signaling.d.ts +38 -5
- package/webrtc/webrtc-signaling.d.ts.map +1 -1
- package/webrtc-signaling-C_GA-iWk.js +812 -0
- package/worker/video-playback-worker.d.ts +3 -0
- package/worker/video-playback-worker.d.ts.map +1 -1
- package/assets/audio-capture-worker-CJ5S-nQt.js +0 -1
- package/assets/audio-playback-worker-BA5LbdyM.js +0 -1
- package/assets/libopus-CnBCihDi.js +0 -1
- package/assets/protocol-worker-Byc-OmNW.js +0 -3
- package/assets/src-BKYD07QQ.js +0 -1
- package/assets/src-DOUWsCWT.js +0 -1
- package/assets/video-capture-worker-DRYxkwR0.js +0 -1
- package/assets/video-playback-worker-v179IJ-C.js +0 -1
- package/assets/viseme-worker-CmvzHAbf.js +0 -1
|
@@ -0,0 +1,812 @@
|
|
|
1
|
+
import { _ as e, b as t, g as n, p as r, w as i, x as a, y as o } from "./log-type-DewKVFaU.js";
|
|
2
|
+
import { c as s, n as c } from "./logger-gjegmH6K.js";
|
|
3
|
+
import { d as l, o as u, r as d, s as ee, u as te } from "./capabilities-ljRyAKpA.js";
|
|
4
|
+
var f = 65567, p = 1455877031, m = 4167628991;
|
|
5
|
+
function h(e) {
|
|
6
|
+
let t = {};
|
|
7
|
+
return g(t), e && Object.assign(t, e), t;
|
|
8
|
+
}
|
|
9
|
+
function g(e) {
|
|
10
|
+
return e.Sdp = "", e.IceServersJson = "", e;
|
|
11
|
+
}
|
|
12
|
+
function _(e, t) {
|
|
13
|
+
return v(n.create(e), t);
|
|
14
|
+
}
|
|
15
|
+
function v(e, t) {
|
|
16
|
+
let n = t ?? h();
|
|
17
|
+
return g(n), ne(e, n), n;
|
|
18
|
+
}
|
|
19
|
+
function ne(e, t) {
|
|
20
|
+
let n;
|
|
21
|
+
for (; (n = e.next()) !== null;) switch (n.fieldId) {
|
|
22
|
+
case p:
|
|
23
|
+
if (n.isNull) throw Error();
|
|
24
|
+
t.Sdp = n.asString();
|
|
25
|
+
break;
|
|
26
|
+
case m:
|
|
27
|
+
if (n.isNull) throw Error();
|
|
28
|
+
t.IceServersJson = n.asString();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function re(e, t) {
|
|
32
|
+
return _(i(e, f, 1), t);
|
|
33
|
+
}
|
|
34
|
+
var ie = 65570, ae = 2514959030, oe = 2677673673;
|
|
35
|
+
function y(e) {
|
|
36
|
+
let t = {};
|
|
37
|
+
return se(t), e && Object.assign(t, e), t;
|
|
38
|
+
}
|
|
39
|
+
function se(e) {
|
|
40
|
+
return e.IsStart = !1, e.CorrelationId = void 0, e;
|
|
41
|
+
}
|
|
42
|
+
function ce(t) {
|
|
43
|
+
let n = new e(2);
|
|
44
|
+
return le(t, n), n.finish();
|
|
45
|
+
}
|
|
46
|
+
function le(e, t) {
|
|
47
|
+
let n = e.CorrelationId;
|
|
48
|
+
n != null && t.writeStringField(ae, n), t.writeBoolField(oe, e.IsStart);
|
|
49
|
+
}
|
|
50
|
+
function b(e, n, r) {
|
|
51
|
+
let i = ce(e);
|
|
52
|
+
return t(ie, i, 2, n, r);
|
|
53
|
+
}
|
|
54
|
+
var ue = 65575;
|
|
55
|
+
function de(e) {
|
|
56
|
+
let t = {};
|
|
57
|
+
return e && Object.assign(t, e), t;
|
|
58
|
+
}
|
|
59
|
+
function fe(t) {
|
|
60
|
+
return new e(1).finish();
|
|
61
|
+
}
|
|
62
|
+
function pe(e, n, r) {
|
|
63
|
+
let i = fe(e);
|
|
64
|
+
return t(ue, i, 1, n, r);
|
|
65
|
+
}
|
|
66
|
+
var x = 65568, S = 646075140, C = 2324511977, w = 4002097439;
|
|
67
|
+
function T(e) {
|
|
68
|
+
let t = {};
|
|
69
|
+
return E(t), e && Object.assign(t, e), t;
|
|
70
|
+
}
|
|
71
|
+
function E(e) {
|
|
72
|
+
return e.Candidate = "", e.SdpMid = "", e.SdpMLineIndex = 0, e;
|
|
73
|
+
}
|
|
74
|
+
function D(t) {
|
|
75
|
+
let n = new e(1);
|
|
76
|
+
return O(t, n), n.finish();
|
|
77
|
+
}
|
|
78
|
+
function O(e, t) {
|
|
79
|
+
t.writeStringField(S, e.Candidate), t.writeStringField(C, e.SdpMid), t.writeInt32Field(w, e.SdpMLineIndex | 0);
|
|
80
|
+
}
|
|
81
|
+
function k(e, t) {
|
|
82
|
+
return A(n.create(e), t);
|
|
83
|
+
}
|
|
84
|
+
function A(e, t) {
|
|
85
|
+
let n = t ?? T();
|
|
86
|
+
return E(n), j(e, n), n;
|
|
87
|
+
}
|
|
88
|
+
function j(e, t) {
|
|
89
|
+
let n;
|
|
90
|
+
for (; (n = e.next()) !== null;) switch (n.fieldId) {
|
|
91
|
+
case S:
|
|
92
|
+
if (n.isNull) throw Error();
|
|
93
|
+
t.Candidate = n.asString();
|
|
94
|
+
break;
|
|
95
|
+
case C:
|
|
96
|
+
if (n.isNull) throw Error();
|
|
97
|
+
t.SdpMid = n.asString();
|
|
98
|
+
break;
|
|
99
|
+
case w:
|
|
100
|
+
if (n.isNull) throw Error();
|
|
101
|
+
t.SdpMLineIndex = n.asInt32();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function M(e, n, r) {
|
|
105
|
+
let i = D(e);
|
|
106
|
+
return t(x, i, 1, n, r);
|
|
107
|
+
}
|
|
108
|
+
function N(e, t) {
|
|
109
|
+
return k(i(e, x, 1), t);
|
|
110
|
+
}
|
|
111
|
+
var P = 65573;
|
|
112
|
+
function F(e) {
|
|
113
|
+
let t = {};
|
|
114
|
+
return e && Object.assign(t, e), t;
|
|
115
|
+
}
|
|
116
|
+
function I(t) {
|
|
117
|
+
return new e(1).finish();
|
|
118
|
+
}
|
|
119
|
+
function L(e, n, r) {
|
|
120
|
+
let i = I(e);
|
|
121
|
+
return t(P, i, 1, n, r);
|
|
122
|
+
}
|
|
123
|
+
var R = 65574, z = 4167628991;
|
|
124
|
+
function B(e) {
|
|
125
|
+
let t = {};
|
|
126
|
+
return V(t), e && Object.assign(t, e), t;
|
|
127
|
+
}
|
|
128
|
+
function V(e) {
|
|
129
|
+
return e.IceServersJson = "", e;
|
|
130
|
+
}
|
|
131
|
+
function me(e, t) {
|
|
132
|
+
return he(n.create(e), t);
|
|
133
|
+
}
|
|
134
|
+
function he(e, t) {
|
|
135
|
+
let n = t ?? B();
|
|
136
|
+
return V(n), ge(e, n), n;
|
|
137
|
+
}
|
|
138
|
+
function ge(e, t) {
|
|
139
|
+
let n;
|
|
140
|
+
for (; (n = e.next()) !== null;) switch (n.fieldId) {
|
|
141
|
+
case z:
|
|
142
|
+
if (n.isNull) throw Error();
|
|
143
|
+
t.IceServersJson = n.asString();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function _e(e, t) {
|
|
147
|
+
return me(i(e, R, 1), t);
|
|
148
|
+
}
|
|
149
|
+
var ve = 65566, ye = 407060584, be = 1175184220, xe = 1241248827, Se = 1455877031, Ce = 3419353826, we = 3686066300;
|
|
150
|
+
function Te(e) {
|
|
151
|
+
let t = {};
|
|
152
|
+
return Ee(t), e && Object.assign(t, e), t;
|
|
153
|
+
}
|
|
154
|
+
function Ee(e) {
|
|
155
|
+
return e.Sdp = "", e.OpcodeGroupsFromServer = s.NONE, e.OpcodeGroupsToServer = s.NONE, e.UseAudioTrack = !1, e.UseVideoTrack = !1, e.UseDataChannel = !1, e;
|
|
156
|
+
}
|
|
157
|
+
function De(t) {
|
|
158
|
+
let n = new e(1);
|
|
159
|
+
return Oe(t, n), n.finish();
|
|
160
|
+
}
|
|
161
|
+
function Oe(e, t) {
|
|
162
|
+
t.writeBoolField(ye, e.UseVideoTrack), t.writeInt32Field(be, e.OpcodeGroupsFromServer), t.writeBoolField(xe, e.UseAudioTrack), t.writeStringField(Se, e.Sdp), t.writeBoolField(Ce, e.UseDataChannel), t.writeInt32Field(we, e.OpcodeGroupsToServer);
|
|
163
|
+
}
|
|
164
|
+
function ke(e, n, r) {
|
|
165
|
+
let i = De(e);
|
|
166
|
+
return t(ve, i, 1, n, r);
|
|
167
|
+
}
|
|
168
|
+
var H = 65569, Ae = 2838554230, je = 3673535008;
|
|
169
|
+
function Me(e) {
|
|
170
|
+
let t = {};
|
|
171
|
+
return U(t), e && Object.assign(t, e), t;
|
|
172
|
+
}
|
|
173
|
+
function U(e) {
|
|
174
|
+
return e.Success = !0, e.ErrorMessage = "", e;
|
|
175
|
+
}
|
|
176
|
+
function Ne(e, t) {
|
|
177
|
+
return Pe(n.create(e), t);
|
|
178
|
+
}
|
|
179
|
+
function Pe(e, t) {
|
|
180
|
+
let n = t ?? Me();
|
|
181
|
+
return U(n), Fe(e, n), n;
|
|
182
|
+
}
|
|
183
|
+
function Fe(e, t) {
|
|
184
|
+
let n;
|
|
185
|
+
for (; (n = e.next()) !== null;) switch (n.fieldId) {
|
|
186
|
+
case Ae:
|
|
187
|
+
if (n.isNull) throw Error();
|
|
188
|
+
t.ErrorMessage = n.asString();
|
|
189
|
+
break;
|
|
190
|
+
case je:
|
|
191
|
+
if (n.isNull) throw Error();
|
|
192
|
+
t.Success = n.asBool();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function Ie(e, t) {
|
|
196
|
+
return Ne(i(e, H, 1), t);
|
|
197
|
+
}
|
|
198
|
+
var W = 65571, Le = 161083277, Re = 317031266, ze = 1093174542, Be = 1970024675, Ve = 2481928696, He = 2762891795, Ue = 3282782683;
|
|
199
|
+
function We(e) {
|
|
200
|
+
let t = {};
|
|
201
|
+
return G(t), e && Object.assign(t, e), t;
|
|
202
|
+
}
|
|
203
|
+
function G(e) {
|
|
204
|
+
return e.Kind = "", e.TrackIndex = 0, e.SenderId = 0, e.SenderTrackId = 0, e.StreamId = "", e.SourceType = "", e.Active = !0, e;
|
|
205
|
+
}
|
|
206
|
+
function Ge(e, t) {
|
|
207
|
+
return Ke(n.create(e), t);
|
|
208
|
+
}
|
|
209
|
+
function Ke(e, t) {
|
|
210
|
+
let n = t ?? We();
|
|
211
|
+
return G(n), qe(e, n), n;
|
|
212
|
+
}
|
|
213
|
+
function qe(e, t) {
|
|
214
|
+
let n;
|
|
215
|
+
for (; (n = e.next()) !== null;) switch (n.fieldId) {
|
|
216
|
+
case Le:
|
|
217
|
+
if (n.isNull) throw Error();
|
|
218
|
+
t.StreamId = n.asString();
|
|
219
|
+
break;
|
|
220
|
+
case Re:
|
|
221
|
+
if (n.isNull) throw Error();
|
|
222
|
+
t.Kind = n.asString();
|
|
223
|
+
break;
|
|
224
|
+
case ze:
|
|
225
|
+
if (n.isNull) throw Error();
|
|
226
|
+
t.SenderTrackId = n.asInt32();
|
|
227
|
+
break;
|
|
228
|
+
case Be:
|
|
229
|
+
if (n.isNull) throw Error();
|
|
230
|
+
t.SenderId = n.asInt32();
|
|
231
|
+
break;
|
|
232
|
+
case Ve:
|
|
233
|
+
if (n.isNull) throw Error();
|
|
234
|
+
t.Active = n.asBool();
|
|
235
|
+
break;
|
|
236
|
+
case He:
|
|
237
|
+
if (n.isNull) throw Error();
|
|
238
|
+
t.TrackIndex = n.asInt32();
|
|
239
|
+
break;
|
|
240
|
+
case Ue:
|
|
241
|
+
if (n.isNull) throw Error();
|
|
242
|
+
t.SourceType = n.asString();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function Je(e, t) {
|
|
246
|
+
return Ge(i(e, W, 1), t);
|
|
247
|
+
}
|
|
248
|
+
var Ye = 65572, Xe = 2514959030, Ze = 3581890656;
|
|
249
|
+
function Qe(e) {
|
|
250
|
+
let t = {};
|
|
251
|
+
return $e(t), e && Object.assign(t, e), t;
|
|
252
|
+
}
|
|
253
|
+
function $e(e) {
|
|
254
|
+
return e.SenderIndex = 0, e.CorrelationId = void 0, e;
|
|
255
|
+
}
|
|
256
|
+
function et(t) {
|
|
257
|
+
let n = new e(1);
|
|
258
|
+
return tt(t, n), n.finish();
|
|
259
|
+
}
|
|
260
|
+
function tt(e, t) {
|
|
261
|
+
let n = e.CorrelationId;
|
|
262
|
+
n != null && t.writeStringField(Xe, n), t.writeInt32Field(Ze, e.SenderIndex | 0);
|
|
263
|
+
}
|
|
264
|
+
function nt(e, n, r) {
|
|
265
|
+
let i = et(e);
|
|
266
|
+
return t(Ye, i, 1, n, r);
|
|
267
|
+
}
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/webrtc/webrtc-config.ts
|
|
270
|
+
var rt = "opus", it = 48e3, at = 2, ot = 64e3, st = 150, ct = "VP8", lt = 5e6, ut = 30, dt = .05, K = "max-bundle", q = "require", ft = 5e3, pt = 8e3, mt = 16, ht = 16, J = "ikon-data", gt = !1, _t = 0, Y = c("WebRTCConnection"), X = class {
|
|
271
|
+
pc = null;
|
|
272
|
+
dataChannel = null;
|
|
273
|
+
_state = "new";
|
|
274
|
+
config;
|
|
275
|
+
hasRemoteDescription = !1;
|
|
276
|
+
pendingCandidates = [];
|
|
277
|
+
audioTrackCount = 0;
|
|
278
|
+
videoTrackCount = 0;
|
|
279
|
+
constructor(e) {
|
|
280
|
+
this.config = e;
|
|
281
|
+
}
|
|
282
|
+
get state() {
|
|
283
|
+
return this._state;
|
|
284
|
+
}
|
|
285
|
+
get peerConnection() {
|
|
286
|
+
return this.pc;
|
|
287
|
+
}
|
|
288
|
+
get isDataChannelOpen() {
|
|
289
|
+
return this.dataChannel?.readyState === "open";
|
|
290
|
+
}
|
|
291
|
+
async initialize() {
|
|
292
|
+
if (this.pc = new RTCPeerConnection({
|
|
293
|
+
iceServers: this.config.iceServers ?? [],
|
|
294
|
+
iceTransportPolicy: this.config.iceTransportPolicy,
|
|
295
|
+
bundlePolicy: K,
|
|
296
|
+
rtcpMuxPolicy: q
|
|
297
|
+
}), this.setupEventHandlers(), this.config.useAudioTrack) for (let e = 0; e < 16; e++) this.pc.addTransceiver("audio", { direction: "sendrecv" });
|
|
298
|
+
if (this.config.useVideoTrack) for (let e = 0; e < 16; e++) this.pc.addTransceiver("video", { direction: "sendrecv" });
|
|
299
|
+
this.config.useDataChannel && (this.dataChannel = this.pc.createDataChannel(J, {
|
|
300
|
+
ordered: !1,
|
|
301
|
+
maxRetransmits: 0
|
|
302
|
+
}), this.setupDataChannelHandlers(this.dataChannel));
|
|
303
|
+
}
|
|
304
|
+
async createOffer() {
|
|
305
|
+
if (!this.pc) throw Error("PeerConnection not initialized");
|
|
306
|
+
this.setState("connecting");
|
|
307
|
+
let e = await this.pc.createOffer();
|
|
308
|
+
return await this.pc.setLocalDescription(e), e.sdp ?? "";
|
|
309
|
+
}
|
|
310
|
+
async restartIce() {
|
|
311
|
+
if (!this.pc) throw Error("PeerConnection not initialized");
|
|
312
|
+
let e = await this.pc.createOffer({ iceRestart: !0 });
|
|
313
|
+
return await this.pc.setLocalDescription(e), e.sdp ?? "";
|
|
314
|
+
}
|
|
315
|
+
async setRemoteDescription(e, t) {
|
|
316
|
+
if (!this.pc) throw Error("PeerConnection not initialized");
|
|
317
|
+
let n = {
|
|
318
|
+
sdp: e,
|
|
319
|
+
type: t
|
|
320
|
+
};
|
|
321
|
+
if (await this.pc.setRemoteDescription(n), this.hasRemoteDescription = !0, this.pendingCandidates.length > 0) {
|
|
322
|
+
Y.debug(`Flushing ${this.pendingCandidates.length} queued ICE candidates`);
|
|
323
|
+
for (let e of this.pendingCandidates) try {
|
|
324
|
+
await this.pc.addIceCandidate(e);
|
|
325
|
+
} catch (e) {
|
|
326
|
+
Y.warn("Failed to add queued ICE candidate:", e);
|
|
327
|
+
}
|
|
328
|
+
this.pendingCandidates = [];
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
async addIceCandidate(e) {
|
|
332
|
+
if (!this.pc) throw Error("PeerConnection not initialized");
|
|
333
|
+
if (!this.hasRemoteDescription) {
|
|
334
|
+
this.pendingCandidates.push(e);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
await this.pc.addIceCandidate(e);
|
|
338
|
+
}
|
|
339
|
+
addTrack(e, t) {
|
|
340
|
+
if (!this.pc) throw Error("PeerConnection not initialized");
|
|
341
|
+
return this.pc.addTrack(e, t);
|
|
342
|
+
}
|
|
343
|
+
async replaceTrack(e, t, n) {
|
|
344
|
+
if (!this.pc) return Y.warn(`replaceTrack(${e}): no peer connection`), null;
|
|
345
|
+
let r = this.pc.getTransceivers().filter((t) => t.receiver.track?.kind === e);
|
|
346
|
+
if (n !== void 0) {
|
|
347
|
+
let i = r[n];
|
|
348
|
+
return i ? (await i.sender.replaceTrack(t), i.sender) : (Y.warn(`replaceTrack(${e}[${n}]): no transceiver at index`), null);
|
|
349
|
+
}
|
|
350
|
+
let i = r[0];
|
|
351
|
+
return i ? (await i.sender.replaceTrack(t), i.sender) : (Y.warn(`replaceTrack(${e}): no matching transceiver found`), null);
|
|
352
|
+
}
|
|
353
|
+
removeTrack(e) {
|
|
354
|
+
this.pc && this.pc.removeTrack(e);
|
|
355
|
+
}
|
|
356
|
+
sendDataChannelMessage(e) {
|
|
357
|
+
if (!this.dataChannel || this.dataChannel.readyState !== "open") {
|
|
358
|
+
Y.warn("DataChannel not open, cannot send message");
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
this.dataChannel.send(e);
|
|
362
|
+
}
|
|
363
|
+
close() {
|
|
364
|
+
this.dataChannel &&= (this.dataChannel.close(), null), this.pc &&= (this.pc.close(), null), this.setState("closed");
|
|
365
|
+
}
|
|
366
|
+
setupEventHandlers() {
|
|
367
|
+
this.pc && (this.pc.onicecandidate = (e) => {
|
|
368
|
+
this.config.onIceCandidate?.(e.candidate);
|
|
369
|
+
}, this.pc.onconnectionstatechange = () => {
|
|
370
|
+
if (this.pc) switch (this.pc.connectionState) {
|
|
371
|
+
case "connected":
|
|
372
|
+
this.setState("connected");
|
|
373
|
+
break;
|
|
374
|
+
case "disconnected":
|
|
375
|
+
this.setState("disconnected");
|
|
376
|
+
break;
|
|
377
|
+
case "failed":
|
|
378
|
+
this.setState("failed");
|
|
379
|
+
break;
|
|
380
|
+
case "closed": this.setState("closed");
|
|
381
|
+
}
|
|
382
|
+
}, this.pc.oniceconnectionstatechange = () => {
|
|
383
|
+
if (!this.pc) return;
|
|
384
|
+
let e = this.pc.iceConnectionState;
|
|
385
|
+
e === "disconnected" && this._state === "connected" ? this.setState("disconnected") : e === "failed" && this._state !== "failed" && this.setState("failed");
|
|
386
|
+
}, this.pc.ontrack = (e) => {
|
|
387
|
+
let t = e.track;
|
|
388
|
+
if (t.kind === "audio") {
|
|
389
|
+
try {
|
|
390
|
+
e.receiver.jitterBufferTarget = 150;
|
|
391
|
+
} catch (e) {
|
|
392
|
+
Y.warn("Failed to set jitterBufferTarget:", e);
|
|
393
|
+
}
|
|
394
|
+
let n = e.streams[0] ?? new MediaStream([t]), r = this.audioTrackCount++;
|
|
395
|
+
this.config.onAudioTrack?.(r, t, n);
|
|
396
|
+
} else if (t.kind === "video") {
|
|
397
|
+
try {
|
|
398
|
+
e.receiver.playoutDelayHint = dt;
|
|
399
|
+
} catch (e) {
|
|
400
|
+
Y.warn("Failed to set playoutDelayHint:", e);
|
|
401
|
+
}
|
|
402
|
+
let n = new MediaStream([t]), r = this.videoTrackCount;
|
|
403
|
+
this.videoTrackCount++, this.config.onVideoTrack?.(r, t, n);
|
|
404
|
+
}
|
|
405
|
+
}, this.pc.ondatachannel = (e) => {
|
|
406
|
+
Y.debug("Received data channel:", e.channel.label), this.setupDataChannelHandlers(e.channel);
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
setupDataChannelHandlers(e) {
|
|
410
|
+
e.binaryType = "arraybuffer", e.onopen = () => {
|
|
411
|
+
Y.debug("DataChannel opened"), this.config.onDataChannelOpen?.();
|
|
412
|
+
}, e.onclose = () => {
|
|
413
|
+
Y.debug("DataChannel closed"), this.config.onDataChannelClose?.();
|
|
414
|
+
}, e.onmessage = (e) => {
|
|
415
|
+
e.data instanceof ArrayBuffer && this.config.onDataChannelMessage?.(e.data);
|
|
416
|
+
}, e.onerror = (e) => {
|
|
417
|
+
Y.error("DataChannel error:", e);
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
setState(e) {
|
|
421
|
+
this._state !== e && (this._state = e, this.config.onStateChange?.(e));
|
|
422
|
+
}
|
|
423
|
+
}, Z = c("WebRTCSignaling"), vt = "webrtc-audio";
|
|
424
|
+
function yt(e, t, n) {
|
|
425
|
+
let r = { ...n };
|
|
426
|
+
return t?.framerate && !r.frameRate && (r.frameRate = { ideal: t.framerate }), e === "camera" ? (t?.width && !r.width && (r.width = { ideal: t.width }), t?.height && !r.height && (r.height = { ideal: t.height }), typeof r.deviceId == "string" && (r.deviceId = { exact: r.deviceId })) : delete r.deviceId, Object.keys(r).length > 0 ? r : void 0;
|
|
427
|
+
}
|
|
428
|
+
var Q = {
|
|
429
|
+
H264: r.H264,
|
|
430
|
+
VP8: r.Vp8,
|
|
431
|
+
VP9: r.Vp9,
|
|
432
|
+
AV1: r.Av1
|
|
433
|
+
};
|
|
434
|
+
function $(e) {
|
|
435
|
+
return (e ? Q[e.toUpperCase()] : void 0) ?? null;
|
|
436
|
+
}
|
|
437
|
+
function bt(e) {
|
|
438
|
+
let t = e.split(/\r?\n(?=m=)/).find((e) => e.startsWith("m=video"));
|
|
439
|
+
if (!t) return null;
|
|
440
|
+
let n = t.split(/\r?\n/), r = n[0].trim().split(/\s+/).slice(3), i = /* @__PURE__ */ new Map();
|
|
441
|
+
for (let e of n) {
|
|
442
|
+
let t = /^a=rtpmap:(\d+) ([^/\s]+)\//.exec(e);
|
|
443
|
+
t && i.set(t[1], t[2]);
|
|
444
|
+
}
|
|
445
|
+
for (let e of r) {
|
|
446
|
+
let t = $(i.get(e));
|
|
447
|
+
if (t !== null) return t;
|
|
448
|
+
}
|
|
449
|
+
return null;
|
|
450
|
+
}
|
|
451
|
+
var xt = class {
|
|
452
|
+
onAudioCaptureError = null;
|
|
453
|
+
config;
|
|
454
|
+
connection = null;
|
|
455
|
+
sendMessage = null;
|
|
456
|
+
isConnecting = !1;
|
|
457
|
+
audioTrackCount = 0;
|
|
458
|
+
videoTrackCount = 0;
|
|
459
|
+
iceServersResolve = null;
|
|
460
|
+
answerVideoCodec = null;
|
|
461
|
+
constructor(e) {
|
|
462
|
+
this.config = e;
|
|
463
|
+
}
|
|
464
|
+
get state() {
|
|
465
|
+
return this.connection?.state ?? "new";
|
|
466
|
+
}
|
|
467
|
+
get peerConnection() {
|
|
468
|
+
return this.connection?.peerConnection ?? null;
|
|
469
|
+
}
|
|
470
|
+
get isDataChannelOpen() {
|
|
471
|
+
return this.connection?.isDataChannelOpen ?? !1;
|
|
472
|
+
}
|
|
473
|
+
async connect(e) {
|
|
474
|
+
if (this.isConnecting || this.connection?.state === "connected") {
|
|
475
|
+
Z.warn("WebRTC already connecting or connected");
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
Z.debug(`Starting WebRTC connection (audio=${this.config.useAudioTrack}, video=${this.config.useVideoTrack}, dataChannel=${this.config.useDataChannel})`), this.isConnecting = !0, this.audioTrackCount = 0, this.videoTrackCount = 0, this.sendMessage = e;
|
|
479
|
+
try {
|
|
480
|
+
let e = await this.requestIceServers();
|
|
481
|
+
if (e.length === 0 && this.config.shouldAttemptWithoutIceServers?.() === !1) {
|
|
482
|
+
Z.debug("No ICE servers and no remembered direct success — abandoning WebRTC so media starts on the protocol channel"), this.isConnecting = !1, this.config.onStateChange?.("failed");
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
let t = {
|
|
486
|
+
useAudioTrack: this.config.useAudioTrack,
|
|
487
|
+
useVideoTrack: this.config.useVideoTrack,
|
|
488
|
+
useDataChannel: this.config.useDataChannel,
|
|
489
|
+
iceServers: e,
|
|
490
|
+
iceTransportPolicy: this.config.iceTransportPolicy,
|
|
491
|
+
onIceCandidate: (e) => this.handleLocalIceCandidate(e),
|
|
492
|
+
onStateChange: (e) => {
|
|
493
|
+
Z.debug(`WebRTC connection state: ${e}`), e === "connected" && Z.debug(`WebRTC tracks: ${this.audioTrackCount} audio, ${this.videoTrackCount} video`), this.config.onStateChange?.(e);
|
|
494
|
+
},
|
|
495
|
+
onDataChannelMessage: this.config.onDataChannelMessage,
|
|
496
|
+
onDataChannelOpen: this.config.onDataChannelOpen,
|
|
497
|
+
onDataChannelClose: this.config.onDataChannelClose,
|
|
498
|
+
onAudioTrack: (e, t, n) => {
|
|
499
|
+
this.audioTrackCount++, this.config.onAudioTrack?.(e, t, n);
|
|
500
|
+
},
|
|
501
|
+
onVideoTrack: (e, t, n) => {
|
|
502
|
+
this.videoTrackCount++, this.config.onVideoTrack?.(e, t, n);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
this.connection = new X(t), await this.connection.initialize();
|
|
506
|
+
let n = await this.connection.createOffer();
|
|
507
|
+
this.sendOffer(n);
|
|
508
|
+
} catch (e) {
|
|
509
|
+
throw Z.error("Failed to start WebRTC connection:", e), this.isConnecting = !1, e;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
handleProtocolMessage(e) {
|
|
513
|
+
let t = (e instanceof Uint8Array, e), n = o(t);
|
|
514
|
+
switch (a(n)) {
|
|
515
|
+
case R: return this.handleIceServersResponse(n), !0;
|
|
516
|
+
case f: return this.handleAnswer(n), !0;
|
|
517
|
+
case x: return this.handleRemoteIceCandidate(n), !0;
|
|
518
|
+
case H: return this.handleReady(n), !0;
|
|
519
|
+
case W: return this.handleTrackMap(n), !0;
|
|
520
|
+
default: return !1;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
notifyServerClose() {
|
|
524
|
+
if (!this.sendMessage) return;
|
|
525
|
+
let e = de();
|
|
526
|
+
this.sendMessage(pe(e, this.config.sessionId));
|
|
527
|
+
}
|
|
528
|
+
async restartIce() {
|
|
529
|
+
if (!this.connection || !this.sendMessage) return !1;
|
|
530
|
+
let e = await this.connection.restartIce();
|
|
531
|
+
return this.sendOffer(e), Z.debug("Sent WebRTC ICE restart offer"), !0;
|
|
532
|
+
}
|
|
533
|
+
disconnect() {
|
|
534
|
+
this.connection?.close(), this.connection = null, this.sendMessage = null, this.isConnecting = !1;
|
|
535
|
+
}
|
|
536
|
+
sendDataChannelMessage(e) {
|
|
537
|
+
this.connection?.sendDataChannelMessage(e);
|
|
538
|
+
}
|
|
539
|
+
audioCaptureStream = null;
|
|
540
|
+
audioCaptureConstraints;
|
|
541
|
+
audioSegmentActive = !1;
|
|
542
|
+
videoCaptureStreams = /* @__PURE__ */ new Map();
|
|
543
|
+
getActiveVideoCaptureStream() {
|
|
544
|
+
for (let e of this.videoCaptureStreams.values()) if (e.active) return e;
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
videoCaptureStreamId(e) {
|
|
548
|
+
return `webrtc_video_${this.config.sessionId}_${e}`;
|
|
549
|
+
}
|
|
550
|
+
videoCaptureSenderIndex(e) {
|
|
551
|
+
let t = `webrtc_video_${this.config.sessionId}_`;
|
|
552
|
+
if (!e || !e.startsWith(t)) return null;
|
|
553
|
+
let n = e.slice(t.length);
|
|
554
|
+
return /^\d+$/.test(n) ? Number(n) : null;
|
|
555
|
+
}
|
|
556
|
+
isAudioCaptureStreamId(e) {
|
|
557
|
+
return e === "webrtc-audio" || e === `webrtc_${this.config.sessionId}`;
|
|
558
|
+
}
|
|
559
|
+
getLocalVideoCaptureStreamByStreamId(e) {
|
|
560
|
+
let t = this.videoCaptureSenderIndex(e);
|
|
561
|
+
if (t === null) return null;
|
|
562
|
+
let n = this.videoCaptureStreams.get(t);
|
|
563
|
+
return n && n.active ? n : null;
|
|
564
|
+
}
|
|
565
|
+
async startAudioCapture(e) {
|
|
566
|
+
if (this.audioCaptureConstraints = e, !await this.acquireAudioTrack()) throw Error("Microphone stream carried no audio track");
|
|
567
|
+
Z.debug("Started audio capture via WebRTC");
|
|
568
|
+
}
|
|
569
|
+
startAudioSegment(e) {
|
|
570
|
+
if (!this.sendMessage) {
|
|
571
|
+
Z.warn("Cannot start audio segment: no send function");
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
this.audioSegmentActive = !0;
|
|
575
|
+
let t = this.audioCaptureStream?.getAudioTracks()[0];
|
|
576
|
+
t && t.readyState === "live" ? t.enabled = !0 : this.acquireAudioTrack().then((e) => {
|
|
577
|
+
e && (this.audioSegmentActive ? e.enabled = !0 : d() && this.releaseAudioTrack());
|
|
578
|
+
}).catch((t) => {
|
|
579
|
+
Z.warn(`Failed to re-acquire microphone for audio segment, ending the segment: ${String(t)}`), this.audioSegmentActive && this.endAudioSegment(e), this.onAudioCaptureError?.(t instanceof Error ? t : Error(String(t)));
|
|
580
|
+
});
|
|
581
|
+
let n = b(y({
|
|
582
|
+
IsStart: !0,
|
|
583
|
+
CorrelationId: e
|
|
584
|
+
}), this.config.sessionId);
|
|
585
|
+
this.sendMessage(n), Z.debug("Started audio segment");
|
|
586
|
+
}
|
|
587
|
+
endAudioSegment(e) {
|
|
588
|
+
if (!this.sendMessage) {
|
|
589
|
+
Z.warn("Cannot end audio segment: no send function");
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
this.audioSegmentActive = !1;
|
|
593
|
+
let t = b(y({
|
|
594
|
+
IsStart: !1,
|
|
595
|
+
CorrelationId: e
|
|
596
|
+
}), this.config.sessionId);
|
|
597
|
+
this.sendMessage(t);
|
|
598
|
+
let n = this.audioCaptureStream?.getAudioTracks()[0];
|
|
599
|
+
n && (n.enabled = !1, d() && this.releaseAudioTrack()), Z.debug("Ended audio segment");
|
|
600
|
+
}
|
|
601
|
+
async acquireAudioTrack() {
|
|
602
|
+
let e = await navigator.mediaDevices.getUserMedia({
|
|
603
|
+
audio: this.audioCaptureConstraints ?? !0,
|
|
604
|
+
video: !1
|
|
605
|
+
});
|
|
606
|
+
this.audioCaptureStream = e;
|
|
607
|
+
let t = e.getAudioTracks()[0] ?? null;
|
|
608
|
+
if (t && (t.enabled = !1, !await this.connection?.replaceTrack("audio", t))) throw this.releaseAudioTrack(), Error("No WebRTC audio sender to attach the microphone track to");
|
|
609
|
+
return t;
|
|
610
|
+
}
|
|
611
|
+
releaseAudioTrack() {
|
|
612
|
+
if (this.audioCaptureStream) {
|
|
613
|
+
for (let e of this.audioCaptureStream.getTracks()) e.stop();
|
|
614
|
+
this.audioCaptureStream = null, this.connection?.replaceTrack("audio", null);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
sendVideoCaptureCorrelation(e, t) {
|
|
618
|
+
if (!this.sendMessage) return;
|
|
619
|
+
let n = nt(Qe({
|
|
620
|
+
SenderIndex: e,
|
|
621
|
+
CorrelationId: t
|
|
622
|
+
}), this.config.sessionId);
|
|
623
|
+
this.sendMessage(n);
|
|
624
|
+
}
|
|
625
|
+
async startVideoCapture(e, t, n = 0, r) {
|
|
626
|
+
let i = await navigator.mediaDevices.getUserMedia({
|
|
627
|
+
audio: !1,
|
|
628
|
+
video: e ?? !0
|
|
629
|
+
});
|
|
630
|
+
this.videoCaptureStreams.set(n, i), this.config.onVideoCaptureChanged?.();
|
|
631
|
+
let a = i.getVideoTracks()[0];
|
|
632
|
+
if (a) {
|
|
633
|
+
let e = a.getSettings();
|
|
634
|
+
Z.debug(`Camera capture (track ${n}): ${e.width}x${e.height}@${e.frameRate}fps`);
|
|
635
|
+
let i = await this.connection?.replaceTrack("video", a, n);
|
|
636
|
+
if (!i) throw this.releaseVideoStream(n), Error(`No WebRTC video sender at index ${n} to attach the camera track to`);
|
|
637
|
+
await this.applyEncodingParams(i, t), this.sendVideoStreamBegin("camera", n, this.negotiatedVideoCodec(i), e.width ?? 0, e.height ?? 0, e.frameRate ?? 30, r);
|
|
638
|
+
}
|
|
639
|
+
return i;
|
|
640
|
+
}
|
|
641
|
+
async startScreenCapture(e, t, n = 1, r) {
|
|
642
|
+
let i = await navigator.mediaDevices.getDisplayMedia({
|
|
643
|
+
video: e ?? !0,
|
|
644
|
+
audio: !1
|
|
645
|
+
});
|
|
646
|
+
this.videoCaptureStreams.set(n, i), this.config.onVideoCaptureChanged?.();
|
|
647
|
+
let a = i.getVideoTracks()[0];
|
|
648
|
+
if (a) {
|
|
649
|
+
let e = a.getSettings();
|
|
650
|
+
Z.debug(`Screen capture (track ${n}): ${e.width}x${e.height}@${e.frameRate}fps`);
|
|
651
|
+
let i = await this.connection?.replaceTrack("video", a, n);
|
|
652
|
+
if (!i) throw this.releaseVideoStream(n), Error(`No WebRTC video sender at index ${n} to attach the screen track to`);
|
|
653
|
+
await this.applyEncodingParams(i, t), this.sendVideoStreamBegin("screen", n, this.negotiatedVideoCodec(i), e.width ?? 0, e.height ?? 0, e.frameRate ?? 30, r);
|
|
654
|
+
}
|
|
655
|
+
return i;
|
|
656
|
+
}
|
|
657
|
+
releaseVideoStream(e) {
|
|
658
|
+
let t = this.videoCaptureStreams.get(e);
|
|
659
|
+
if (t) {
|
|
660
|
+
for (let e of t.getTracks()) e.stop();
|
|
661
|
+
this.videoCaptureStreams.delete(e), this.config.onVideoCaptureChanged?.();
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
async stopVideoCapture(e) {
|
|
665
|
+
let t = this.videoCaptureStreams.get(e);
|
|
666
|
+
if (!t) return !1;
|
|
667
|
+
this.sendVideoStreamEnd(e);
|
|
668
|
+
for (let e of t.getTracks()) e.stop();
|
|
669
|
+
return this.videoCaptureStreams.delete(e), this.config.onVideoCaptureChanged?.(), await this.connection?.replaceTrack("video", null, e), Z.debug(`Stopped video capture (track ${e})`), !0;
|
|
670
|
+
}
|
|
671
|
+
negotiatedVideoCodec(e) {
|
|
672
|
+
let t = [];
|
|
673
|
+
try {
|
|
674
|
+
t = e.getParameters().codecs ?? [];
|
|
675
|
+
} catch (e) {
|
|
676
|
+
Z.debug("Could not read video sender parameters:", e);
|
|
677
|
+
}
|
|
678
|
+
for (let e of t) {
|
|
679
|
+
let t = $(e.mimeType.split("/")[1]);
|
|
680
|
+
if (t !== null) return t;
|
|
681
|
+
}
|
|
682
|
+
return this.answerVideoCodec ?? r.Vp8;
|
|
683
|
+
}
|
|
684
|
+
sendVideoStreamBegin(e, t, n, r, i, a, o) {
|
|
685
|
+
if (!this.sendMessage) return;
|
|
686
|
+
let s = u({
|
|
687
|
+
StreamId: this.videoCaptureStreamId(t),
|
|
688
|
+
Description: `webrtc_${e}`,
|
|
689
|
+
SourceType: e,
|
|
690
|
+
Codec: n,
|
|
691
|
+
CodecDetails: "",
|
|
692
|
+
Width: r,
|
|
693
|
+
Height: i,
|
|
694
|
+
Framerate: a,
|
|
695
|
+
CorrelationId: o
|
|
696
|
+
});
|
|
697
|
+
this.sendMessage(te(s, this.config.sessionId, { trackId: t }));
|
|
698
|
+
}
|
|
699
|
+
sendVideoStreamEnd(e) {
|
|
700
|
+
if (!this.sendMessage) return;
|
|
701
|
+
let t = ee({});
|
|
702
|
+
this.sendMessage(l(t, this.config.sessionId, { trackId: e }));
|
|
703
|
+
}
|
|
704
|
+
stopAudioCapture() {
|
|
705
|
+
this.audioSegmentActive = !1, this.releaseAudioTrack(), this.audioCaptureConstraints = void 0, Z.debug("Stopped audio capture");
|
|
706
|
+
}
|
|
707
|
+
async stopCapture() {
|
|
708
|
+
for (let e of [...this.videoCaptureStreams.keys()]) await this.stopVideoCapture(e);
|
|
709
|
+
if (this.audioSegmentActive = !1, this.audioCaptureStream) {
|
|
710
|
+
for (let e of this.audioCaptureStream.getTracks()) e.stop();
|
|
711
|
+
this.audioCaptureStream = null, await this.connection?.replaceTrack("audio", null);
|
|
712
|
+
}
|
|
713
|
+
this.audioCaptureConstraints = void 0, Z.debug("Stopped all capture");
|
|
714
|
+
}
|
|
715
|
+
async applyEncodingParams(e, t) {
|
|
716
|
+
try {
|
|
717
|
+
let n = t ?? 5e6, r = e.getParameters();
|
|
718
|
+
r.encodings?.length || (r.encodings = [{}]), r.encodings[0].maxBitrate = n, r.degradationPreference = "balanced", await e.setParameters(r);
|
|
719
|
+
} catch (e) {
|
|
720
|
+
Z.warn("Failed to set encoding params:", e);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
sendOffer(e) {
|
|
724
|
+
if (!this.sendMessage) {
|
|
725
|
+
Z.error("Cannot send offer: no send function");
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
let t = ke(Te({
|
|
729
|
+
Sdp: e,
|
|
730
|
+
OpcodeGroupsFromServer: this.config.opcodeGroupsFromServer,
|
|
731
|
+
OpcodeGroupsToServer: this.config.opcodeGroupsToServer,
|
|
732
|
+
UseAudioTrack: this.config.useAudioTrack,
|
|
733
|
+
UseVideoTrack: this.config.useVideoTrack,
|
|
734
|
+
UseDataChannel: this.config.useDataChannel
|
|
735
|
+
}), this.config.sessionId);
|
|
736
|
+
this.sendMessage(t), Z.debug("Sent WebRTC offer");
|
|
737
|
+
}
|
|
738
|
+
async requestIceServers() {
|
|
739
|
+
let e = this.config.iceServers ?? [];
|
|
740
|
+
if (!this.sendMessage) return e;
|
|
741
|
+
let t = new Promise((e) => {
|
|
742
|
+
this.iceServersResolve = e;
|
|
743
|
+
}), n, r = new Promise((t) => {
|
|
744
|
+
n = setTimeout(() => {
|
|
745
|
+
Z.warn("Timed out waiting for ICE servers from server, proceeding without TURN"), t(e);
|
|
746
|
+
}, ft);
|
|
747
|
+
}), i = F();
|
|
748
|
+
this.sendMessage(L(i, this.config.sessionId));
|
|
749
|
+
let a = await Promise.race([t, r]);
|
|
750
|
+
return clearTimeout(n), this.iceServersResolve = null, a;
|
|
751
|
+
}
|
|
752
|
+
handleIceServersResponse(e) {
|
|
753
|
+
if (!this.iceServersResolve) return;
|
|
754
|
+
let t = this.config.iceServers ?? [];
|
|
755
|
+
try {
|
|
756
|
+
let n = _e(e), r = n.IceServersJson ? JSON.parse(n.IceServersJson) : [];
|
|
757
|
+
Z.debug(`Received ${r.length} ICE server(s) from server`), this.iceServersResolve([...t, ...r]);
|
|
758
|
+
} catch (e) {
|
|
759
|
+
Z.warn("Failed to parse ICE servers response, proceeding with configured servers:", e), this.iceServersResolve(t);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
async handleAnswer(e) {
|
|
763
|
+
try {
|
|
764
|
+
let t = re(e);
|
|
765
|
+
await this.connection?.setRemoteDescription(t.Sdp, "answer"), this.answerVideoCodec = bt(t.Sdp), Z.debug(`WebRTC answer received and applied (video=${this.answerVideoCodec === null ? "unknown" : r[this.answerVideoCodec]})`);
|
|
766
|
+
} catch (e) {
|
|
767
|
+
Z.error("Failed to handle WebRTC answer:", e);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
handleLocalIceCandidate(e) {
|
|
771
|
+
if (!e || !this.sendMessage) return;
|
|
772
|
+
let t = M(T({
|
|
773
|
+
Candidate: e.candidate,
|
|
774
|
+
SdpMid: e.sdpMid ?? "",
|
|
775
|
+
SdpMLineIndex: e.sdpMLineIndex ?? 0
|
|
776
|
+
}), this.config.sessionId);
|
|
777
|
+
this.sendMessage(t);
|
|
778
|
+
}
|
|
779
|
+
async handleRemoteIceCandidate(e) {
|
|
780
|
+
try {
|
|
781
|
+
let t = N(e);
|
|
782
|
+
if (t.Candidate) {
|
|
783
|
+
let e = t.Candidate.startsWith("candidate:") ? t.Candidate : `candidate:${t.Candidate}`, n = t.SdpMid || String(t.SdpMLineIndex);
|
|
784
|
+
await this.connection?.addIceCandidate({
|
|
785
|
+
candidate: e,
|
|
786
|
+
sdpMid: n,
|
|
787
|
+
sdpMLineIndex: t.SdpMLineIndex
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
} catch (e) {
|
|
791
|
+
Z.error("Failed to add ICE candidate:", e);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
handleReady(e) {
|
|
795
|
+
try {
|
|
796
|
+
let t = Ie(e);
|
|
797
|
+
t.Success ? (Z.debug("WebRTC connection ready"), this.isConnecting = !1) : (Z.error(`WebRTC connection failed (server): ${t.ErrorMessage}`), this.config.onStateChange?.("failed"), this.disconnect());
|
|
798
|
+
} catch (e) {
|
|
799
|
+
Z.error("Failed to handle WebRTC ready:", e);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
handleTrackMap(e) {
|
|
803
|
+
try {
|
|
804
|
+
let t = Je(e);
|
|
805
|
+
this.config.onTrackMap?.(t);
|
|
806
|
+
} catch (e) {
|
|
807
|
+
Z.error("Failed to handle WebRTC track map:", e);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
//#endregion
|
|
812
|
+
export { q as _, ot as a, ut as b, st as c, pt as d, J as f, ht as g, mt as h, X as i, it as l, gt as m, xt as n, at as o, _t as p, yt as r, rt as s, vt as t, K as u, ct as v, lt as y };
|