@ikonai/sdk 1.0.67 → 1.0.68
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/index.js +104 -94
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -489,7 +489,7 @@ class P {
|
|
|
489
489
|
throw new Error("Teleport payload too short");
|
|
490
490
|
if (n[0] !== hr || n[n.length - 1] !== fr)
|
|
491
491
|
throw new Error("Teleport object missing markers");
|
|
492
|
-
const r = { offset: 1 }, i =
|
|
492
|
+
const r = { offset: 1 }, i = V(n, r, "InvalidLength");
|
|
493
493
|
return new P(n, i, r.offset);
|
|
494
494
|
}
|
|
495
495
|
next() {
|
|
@@ -505,10 +505,10 @@ class P {
|
|
|
505
505
|
const i = we(r);
|
|
506
506
|
let s;
|
|
507
507
|
if (i >= 0)
|
|
508
|
-
|
|
508
|
+
x(this.buffer, this.offset, i), s = this.buffer.subarray(this.offset, this.offset + i), this.offset += i;
|
|
509
509
|
else {
|
|
510
|
-
const o = { offset: this.offset }, a =
|
|
511
|
-
|
|
510
|
+
const o = { offset: this.offset }, a = V(this.buffer, o, "InvalidLength");
|
|
511
|
+
x(this.buffer, o.offset, a), s = this.buffer.subarray(o.offset, o.offset + a), this.offset = o.offset + a;
|
|
512
512
|
}
|
|
513
513
|
return new Aa(e, r, s);
|
|
514
514
|
}
|
|
@@ -627,7 +627,7 @@ class an {
|
|
|
627
627
|
if (this.elementType = n >> 4 & 15, (n & 15) !== 0)
|
|
628
628
|
throw new Error("Array flags must be zero");
|
|
629
629
|
const r = { offset: 1 };
|
|
630
|
-
this.count =
|
|
630
|
+
this.count = V(e, r, "ArrayMalformed"), this.offset = r.offset;
|
|
631
631
|
}
|
|
632
632
|
static create(e) {
|
|
633
633
|
return new an(Ae(e));
|
|
@@ -652,20 +652,20 @@ class an {
|
|
|
652
652
|
case 6:
|
|
653
653
|
case 14: {
|
|
654
654
|
const e = we(this.elementType);
|
|
655
|
-
|
|
655
|
+
x(this.payload, this.offset, e);
|
|
656
656
|
const n = this.payload.subarray(this.offset, this.offset + e);
|
|
657
657
|
return this.offset += e, new ke(this.elementType, n);
|
|
658
658
|
}
|
|
659
659
|
case 12:
|
|
660
660
|
case 13: {
|
|
661
|
-
const e = { offset: this.offset }, n =
|
|
662
|
-
|
|
661
|
+
const e = { offset: this.offset }, n = V(this.payload, e, "ArrayMalformed");
|
|
662
|
+
x(this.payload, e.offset, n);
|
|
663
663
|
const r = this.payload.subarray(e.offset, e.offset + n);
|
|
664
664
|
return this.offset = e.offset + n, new ke(this.elementType, r);
|
|
665
665
|
}
|
|
666
666
|
case 11: {
|
|
667
|
-
const e = { offset: this.offset }, n =
|
|
668
|
-
|
|
667
|
+
const e = { offset: this.offset }, n = V(this.payload, e, "ArrayMalformed");
|
|
668
|
+
x(this.payload, e.offset, n);
|
|
669
669
|
const r = this.payload.subarray(e.offset, e.offset + n);
|
|
670
670
|
return this.offset = e.offset + n, new ke(11, r);
|
|
671
671
|
}
|
|
@@ -701,7 +701,7 @@ class cn {
|
|
|
701
701
|
throw new Error("Dictionary key/value flags must be zero");
|
|
702
702
|
ln(this.keyType);
|
|
703
703
|
const n = { offset: 2 };
|
|
704
|
-
this.count =
|
|
704
|
+
this.count = V(e, n, "DictMalformed"), this.offset = n.offset;
|
|
705
705
|
}
|
|
706
706
|
static create(e) {
|
|
707
707
|
return new cn(Ae(e));
|
|
@@ -718,13 +718,13 @@ class cn {
|
|
|
718
718
|
readKey() {
|
|
719
719
|
const e = we(this.keyType);
|
|
720
720
|
if (e >= 0) {
|
|
721
|
-
|
|
721
|
+
x(this.payload, this.offset, e);
|
|
722
722
|
const n = this.payload.subarray(this.offset, this.offset + e);
|
|
723
723
|
return this.offset += e, new X(this.keyType, n);
|
|
724
724
|
}
|
|
725
725
|
if (this.keyType === 12 || this.keyType === 13) {
|
|
726
|
-
const n = { offset: this.offset }, r =
|
|
727
|
-
|
|
726
|
+
const n = { offset: this.offset }, r = V(this.payload, n, "DictMalformed");
|
|
727
|
+
x(this.payload, n.offset, r);
|
|
728
728
|
const i = this.payload.subarray(n.offset, n.offset + r);
|
|
729
729
|
return this.offset = n.offset + r, new X(this.keyType, i);
|
|
730
730
|
}
|
|
@@ -734,14 +734,14 @@ class cn {
|
|
|
734
734
|
switch (this.valueType) {
|
|
735
735
|
case 12:
|
|
736
736
|
case 13: {
|
|
737
|
-
const e = { offset: this.offset }, n =
|
|
738
|
-
|
|
737
|
+
const e = { offset: this.offset }, n = V(this.payload, e, "DictMalformed");
|
|
738
|
+
x(this.payload, e.offset, n);
|
|
739
739
|
const r = this.payload.subarray(e.offset, e.offset + n);
|
|
740
740
|
return this.offset = e.offset + n, new X(this.valueType, r);
|
|
741
741
|
}
|
|
742
742
|
case 11: {
|
|
743
|
-
const e = { offset: this.offset }, n =
|
|
744
|
-
|
|
743
|
+
const e = { offset: this.offset }, n = V(this.payload, e, "DictMalformed");
|
|
744
|
+
x(this.payload, e.offset, n);
|
|
745
745
|
const r = this.payload.subarray(e.offset, e.offset + n);
|
|
746
746
|
return this.offset = e.offset + n, new X(11, r);
|
|
747
747
|
}
|
|
@@ -763,7 +763,7 @@ class cn {
|
|
|
763
763
|
case 14:
|
|
764
764
|
case 1: {
|
|
765
765
|
const e = we(this.valueType);
|
|
766
|
-
|
|
766
|
+
x(this.payload, this.offset, e);
|
|
767
767
|
const n = this.payload.subarray(this.offset, this.offset + e);
|
|
768
768
|
return this.offset += e, new X(this.valueType, n);
|
|
769
769
|
}
|
|
@@ -899,7 +899,7 @@ class le {
|
|
|
899
899
|
return this.buffer.slice(0, this.length);
|
|
900
900
|
}
|
|
901
901
|
}
|
|
902
|
-
function
|
|
902
|
+
function V(t, e, n) {
|
|
903
903
|
if (e.offset >= t.length)
|
|
904
904
|
throw new Error(n);
|
|
905
905
|
let r = 0, i = 0, s = 0;
|
|
@@ -950,7 +950,7 @@ function ln(t) {
|
|
|
950
950
|
if (t === 9 || t === 11 || t === 10 || t === 1)
|
|
951
951
|
throw new Error("Dictionary keys must be primitive Teleport types");
|
|
952
952
|
}
|
|
953
|
-
function
|
|
953
|
+
function x(t, e, n) {
|
|
954
954
|
if (e < 0 || n < 0 || e + n > t.length)
|
|
955
955
|
throw new Error("Teleport payload exceeds bounds");
|
|
956
956
|
}
|
|
@@ -963,10 +963,10 @@ function un(t, e) {
|
|
|
963
963
|
const n = t[e], r = n >> 4 & 15;
|
|
964
964
|
if ((n & 15) !== 0)
|
|
965
965
|
throw new Error("Array flags must be zero");
|
|
966
|
-
const i = { offset: e + 1 }, s =
|
|
966
|
+
const i = { offset: e + 1 }, s = V(t, i, "ArrayMalformed"), o = we(r);
|
|
967
967
|
if (o >= 0) {
|
|
968
968
|
const c = o * s;
|
|
969
|
-
return
|
|
969
|
+
return x(t, i.offset, c), i.offset + c - e;
|
|
970
970
|
}
|
|
971
971
|
let a = i.offset;
|
|
972
972
|
for (let c = 0; c < s; c++)
|
|
@@ -980,7 +980,7 @@ function dn(t, e) {
|
|
|
980
980
|
if ((t[e] & 15) !== 0 || (t[e + 1] & 15) !== 0)
|
|
981
981
|
throw new Error("Dictionary key/value flags must be zero");
|
|
982
982
|
ln(n);
|
|
983
|
-
const i = { offset: e + 2 }, s =
|
|
983
|
+
const i = { offset: e + 2 }, s = V(t, i, "DictMalformed");
|
|
984
984
|
let o = i.offset;
|
|
985
985
|
for (let a = 0; a < s; a++)
|
|
986
986
|
o = Wt(n, t, o, "DictMalformed"), o = Wt(r, t, o, "DictMalformed");
|
|
@@ -989,16 +989,16 @@ function dn(t, e) {
|
|
|
989
989
|
function Wt(t, e, n, r) {
|
|
990
990
|
const i = we(t);
|
|
991
991
|
if (i >= 0)
|
|
992
|
-
return
|
|
992
|
+
return x(e, n, i), n + i;
|
|
993
993
|
switch (t) {
|
|
994
994
|
case 12:
|
|
995
995
|
case 13: {
|
|
996
|
-
const s = { offset: n }, o =
|
|
997
|
-
return
|
|
996
|
+
const s = { offset: n }, o = V(e, s, r);
|
|
997
|
+
return x(e, s.offset, o), s.offset + o;
|
|
998
998
|
}
|
|
999
999
|
case 11: {
|
|
1000
|
-
const s = { offset: n }, o =
|
|
1001
|
-
return
|
|
1000
|
+
const s = { offset: n }, o = V(e, s, r);
|
|
1001
|
+
return x(e, s.offset, o), s.offset + o;
|
|
1002
1002
|
}
|
|
1003
1003
|
case 9:
|
|
1004
1004
|
return n + un(e, n);
|
|
@@ -3898,7 +3898,7 @@ class Vp {
|
|
|
3898
3898
|
this.state !== e && (this.state = e, this.config.onStateChange?.(e));
|
|
3899
3899
|
}
|
|
3900
3900
|
}
|
|
3901
|
-
const
|
|
3901
|
+
const B = M("ChannelManager"), Hp = 5e3;
|
|
3902
3902
|
class $p {
|
|
3903
3903
|
channels = /* @__PURE__ */ new Map();
|
|
3904
3904
|
// keyed by opcode group
|
|
@@ -3955,7 +3955,7 @@ class $p {
|
|
|
3955
3955
|
i.send(e);
|
|
3956
3956
|
return;
|
|
3957
3957
|
}
|
|
3958
|
-
this.state === "connected" &&
|
|
3958
|
+
this.state === "connected" && B.warn("No channel found for message");
|
|
3959
3959
|
}
|
|
3960
3960
|
/**
|
|
3961
3961
|
* Send a protocol message to all channels (for broadcast messages).
|
|
@@ -3983,7 +3983,7 @@ class $p {
|
|
|
3983
3983
|
*/
|
|
3984
3984
|
triggerReconnect(e) {
|
|
3985
3985
|
if (this.state === "connected") {
|
|
3986
|
-
|
|
3986
|
+
B.debug(`Forcing reconnect: ${e}`);
|
|
3987
3987
|
for (const n of this.channels.values())
|
|
3988
3988
|
n.triggerReconnect(e);
|
|
3989
3989
|
}
|
|
@@ -4002,30 +4002,30 @@ class $p {
|
|
|
4002
4002
|
const s = new Set(r.keys());
|
|
4003
4003
|
i = this.config.orderedEndpointTypes.filter((o) => s.has(o));
|
|
4004
4004
|
} else this.config.endpointSelector ? i = this.config.endpointSelector.getOrderedTypes(r) : i = Array.from(r.keys());
|
|
4005
|
-
this.connectionTimeoutMs = i.length > 1 ? 5e3 : 1e4,
|
|
4005
|
+
this.connectionTimeoutMs = i.length > 1 ? 5e3 : 1e4, B.debug(`Endpoint types to try: [${i.map((s) => y[s]).join(", ")}], transport timeout: ${this.connectionTimeoutMs}ms`);
|
|
4006
4006
|
for (const s of i) {
|
|
4007
4007
|
if (!this.shouldReconnect)
|
|
4008
4008
|
return;
|
|
4009
4009
|
const o = r.get(s), a = Date.now();
|
|
4010
|
-
|
|
4010
|
+
B.debug(`Trying ${y[s]} (${o.length} channel(s))`);
|
|
4011
4011
|
try {
|
|
4012
|
-
await this.connectAllChannels(o), this.config.endpointSelector?.rememberWorkingType(s), this.config.onRememberWorkingType?.(s), this.activeType = s,
|
|
4012
|
+
await this.connectAllChannels(o), this.config.endpointSelector?.rememberWorkingType(s), this.config.onRememberWorkingType?.(s), this.activeType = s, B.debug(`Connected via ${y[s]} in ${Date.now() - a}ms`), this.setState("connected"), this.startStabilityTimer();
|
|
4013
4013
|
return;
|
|
4014
4014
|
} catch (c) {
|
|
4015
|
-
|
|
4015
|
+
B.warn(`Failed to connect using ${y[s]} after ${Date.now() - a}ms: ${c instanceof Error ? c.message : c}`);
|
|
4016
4016
|
const l = this.channels.size > 0;
|
|
4017
4017
|
if (this.disconnectAll(), c instanceof Ee)
|
|
4018
4018
|
throw c;
|
|
4019
4019
|
if (l && this.config.onRefreshEntrypoints)
|
|
4020
4020
|
try {
|
|
4021
|
-
|
|
4021
|
+
B.info("Partial connection detected, refreshing entrypoints");
|
|
4022
4022
|
const d = await this.config.onRefreshEntrypoints();
|
|
4023
4023
|
this.entrypoints = d.entrypoints, this.config.sessionId = d.sessionId;
|
|
4024
4024
|
const h = d.entrypoints.filter((p) => p.Type !== y.WebRTC), u = this.groupByType(h);
|
|
4025
4025
|
for (const [p, _] of u)
|
|
4026
4026
|
r.set(p, _);
|
|
4027
4027
|
} catch (d) {
|
|
4028
|
-
|
|
4028
|
+
B.warn(`Failed to refresh entrypoints: ${d}`);
|
|
4029
4029
|
}
|
|
4030
4030
|
}
|
|
4031
4031
|
}
|
|
@@ -4093,7 +4093,7 @@ class $p {
|
|
|
4093
4093
|
* dropped, and we reconnect.
|
|
4094
4094
|
*/
|
|
4095
4095
|
handleChannelClose(e, n, r) {
|
|
4096
|
-
this.state === "idle" || this.state === "stopped" || this.state === "offline" || this.channels.has(e) && this.state === "connected" && (
|
|
4096
|
+
this.state === "idle" || this.state === "stopped" || this.state === "offline" || this.channels.has(e) && this.state === "connected" && (B.warn("Channel closed unexpectedly, attempting reconnect"), this.disconnectAll(), this.attemptReconnect());
|
|
4097
4097
|
}
|
|
4098
4098
|
/**
|
|
4099
4099
|
* Attempt to reconnect with fixed-interval retry.
|
|
@@ -4102,19 +4102,19 @@ class $p {
|
|
|
4102
4102
|
async attemptReconnect() {
|
|
4103
4103
|
if (this.shouldReconnect) {
|
|
4104
4104
|
if (!ne()) {
|
|
4105
|
-
|
|
4105
|
+
B.warn("Retry disabled via ikon-retry=false, skipping reconnect"), this.setState("offline"), this.config.onError?.(new Gn(0));
|
|
4106
4106
|
return;
|
|
4107
4107
|
}
|
|
4108
4108
|
if (this.reconnectAttempts >= this.config.maxReconnectAttempts) {
|
|
4109
|
-
|
|
4109
|
+
B.warn(`Max reconnect attempts (${this.config.maxReconnectAttempts}) reached`), this.setState("offline"), this.config.onError?.(new Gn(this.config.maxReconnectAttempts));
|
|
4110
4110
|
return;
|
|
4111
4111
|
}
|
|
4112
|
-
if (this.setState("reconnecting"), this.reconnectAttempts++, this.reconnectAttempts > 1 ? (
|
|
4112
|
+
if (this.setState("reconnecting"), this.reconnectAttempts++, this.reconnectAttempts > 1 ? (B.info(`Reconnecting in ${this.config.reconnectBackoffMs}ms (attempt ${this.reconnectAttempts}/${this.config.maxReconnectAttempts})`), await Lo(this.config.reconnectBackoffMs, this.abortController?.signal)) : B.info(`Reconnecting immediately (attempt ${this.reconnectAttempts}/${this.config.maxReconnectAttempts})`), !!this.shouldReconnect)
|
|
4113
4113
|
try {
|
|
4114
4114
|
await this.connectInternal(!0);
|
|
4115
4115
|
} catch (e) {
|
|
4116
4116
|
if (e instanceof Ee) {
|
|
4117
|
-
|
|
4117
|
+
B.warn("Auth rejected during reconnect, stopping retries and signaling full re-auth"), this.config.onError?.(e), this.setState("offline");
|
|
4118
4118
|
return;
|
|
4119
4119
|
}
|
|
4120
4120
|
await this.attemptReconnect();
|
|
@@ -4144,7 +4144,7 @@ class $p {
|
|
|
4144
4144
|
this.stabilityTimer && (clearTimeout(this.stabilityTimer), this.stabilityTimer = null);
|
|
4145
4145
|
}
|
|
4146
4146
|
}
|
|
4147
|
-
const LI = "opus", MI = 48e3, PI = 2, FI = 64e3, Kp = 150, BI = "VP8", Yp = 5e6, xI = 30, jp = 0.05, zp = "max-bundle", Xp = "require", Jp = 16, Qp = 16, Zp = "ikon-data", qp = !1, eE = 0,
|
|
4147
|
+
const LI = "opus", MI = 48e3, PI = 2, FI = 64e3, Kp = 150, BI = "VP8", Yp = 5e6, xI = 30, jp = 0.05, zp = "max-bundle", Xp = "require", Jp = 16, Qp = 16, Zp = "ikon-data", qp = !1, eE = 0, H = M("WebRTCConnection");
|
|
4148
4148
|
class tE {
|
|
4149
4149
|
pc = null;
|
|
4150
4150
|
dataChannel = null;
|
|
@@ -4194,12 +4194,12 @@ class tE {
|
|
|
4194
4194
|
throw new Error("PeerConnection not initialized");
|
|
4195
4195
|
const r = { sdp: e, type: n };
|
|
4196
4196
|
if (await this.pc.setRemoteDescription(r), this.hasRemoteDescription = !0, this.pendingCandidates.length > 0) {
|
|
4197
|
-
|
|
4197
|
+
H.debug(`Flushing ${this.pendingCandidates.length} queued ICE candidates`);
|
|
4198
4198
|
for (const i of this.pendingCandidates)
|
|
4199
4199
|
try {
|
|
4200
4200
|
await this.pc.addIceCandidate(i);
|
|
4201
4201
|
} catch (s) {
|
|
4202
|
-
|
|
4202
|
+
H.warn("Failed to add queued ICE candidate:", s);
|
|
4203
4203
|
}
|
|
4204
4204
|
this.pendingCandidates = [];
|
|
4205
4205
|
}
|
|
@@ -4220,23 +4220,23 @@ class tE {
|
|
|
4220
4220
|
}
|
|
4221
4221
|
async replaceTrack(e, n, r) {
|
|
4222
4222
|
if (!this.pc)
|
|
4223
|
-
return
|
|
4223
|
+
return H.warn(`replaceTrack(${e}): no peer connection`), null;
|
|
4224
4224
|
const s = this.pc.getTransceivers().filter(
|
|
4225
4225
|
(a) => a.receiver.track?.kind === e
|
|
4226
4226
|
);
|
|
4227
4227
|
if (r !== void 0) {
|
|
4228
4228
|
const a = s[r];
|
|
4229
|
-
return a ? (await a.sender.replaceTrack(n), a.sender) : (
|
|
4229
|
+
return a ? (await a.sender.replaceTrack(n), a.sender) : (H.warn(`replaceTrack(${e}[${r}]): no transceiver at index`), null);
|
|
4230
4230
|
}
|
|
4231
4231
|
const o = s[0];
|
|
4232
|
-
return o ? (await o.sender.replaceTrack(n), o.sender) : (
|
|
4232
|
+
return o ? (await o.sender.replaceTrack(n), o.sender) : (H.warn(`replaceTrack(${e}): no matching transceiver found`), null);
|
|
4233
4233
|
}
|
|
4234
4234
|
removeTrack(e) {
|
|
4235
4235
|
this.pc && this.pc.removeTrack(e);
|
|
4236
4236
|
}
|
|
4237
4237
|
sendDataChannelMessage(e) {
|
|
4238
4238
|
if (!this.dataChannel || this.dataChannel.readyState !== "open") {
|
|
4239
|
-
|
|
4239
|
+
H.warn("DataChannel not open, cannot send message");
|
|
4240
4240
|
return;
|
|
4241
4241
|
}
|
|
4242
4242
|
this.dataChannel.send(e);
|
|
@@ -4270,7 +4270,7 @@ class tE {
|
|
|
4270
4270
|
try {
|
|
4271
4271
|
e.receiver.jitterBufferTarget = r;
|
|
4272
4272
|
} catch (o) {
|
|
4273
|
-
|
|
4273
|
+
H.warn("Failed to set jitterBufferTarget:", o);
|
|
4274
4274
|
}
|
|
4275
4275
|
const i = e.streams[0] ?? new MediaStream([n]), s = this.audioTrackCount++;
|
|
4276
4276
|
this.config.onAudioTrack?.(s, n, i);
|
|
@@ -4278,24 +4278,24 @@ class tE {
|
|
|
4278
4278
|
try {
|
|
4279
4279
|
e.receiver.playoutDelayHint = jp;
|
|
4280
4280
|
} catch (s) {
|
|
4281
|
-
|
|
4281
|
+
H.warn("Failed to set playoutDelayHint:", s);
|
|
4282
4282
|
}
|
|
4283
4283
|
const r = new MediaStream([n]), i = this.videoTrackCount;
|
|
4284
4284
|
this.videoTrackCount++, this.config.onVideoTrack?.(i, n, r);
|
|
4285
4285
|
}
|
|
4286
4286
|
}, this.pc.ondatachannel = (e) => {
|
|
4287
|
-
|
|
4287
|
+
H.debug("Received data channel:", e.channel.label), this.setupDataChannelHandlers(e.channel);
|
|
4288
4288
|
});
|
|
4289
4289
|
}
|
|
4290
4290
|
setupDataChannelHandlers(e) {
|
|
4291
4291
|
e.binaryType = "arraybuffer", e.onopen = () => {
|
|
4292
|
-
|
|
4292
|
+
H.debug("DataChannel opened"), this.config.onDataChannelOpen?.();
|
|
4293
4293
|
}, e.onclose = () => {
|
|
4294
|
-
|
|
4294
|
+
H.debug("DataChannel closed"), this.config.onDataChannelClose?.();
|
|
4295
4295
|
}, e.onmessage = (n) => {
|
|
4296
4296
|
n.data instanceof ArrayBuffer && this.config.onDataChannelMessage?.(n.data);
|
|
4297
4297
|
}, e.onerror = (n) => {
|
|
4298
|
-
|
|
4298
|
+
H.error("DataChannel error:", n);
|
|
4299
4299
|
};
|
|
4300
4300
|
}
|
|
4301
4301
|
setState(e) {
|
|
@@ -5300,7 +5300,7 @@ function jI() {
|
|
|
5300
5300
|
window.history.replaceState(null, "", r + window.location.search);
|
|
5301
5301
|
}
|
|
5302
5302
|
}
|
|
5303
|
-
const
|
|
5303
|
+
const F = M("Authenticator"), ge = S.GROUP_CORE | S.GROUP_KEEPALIVE | S.GROUP_EVENTS | S.GROUP_ACTIONS | S.GROUP_UI | S.GROUP_AUDIO | S.GROUP_VIDEO | S.GROUP_ANALYTICS | S.GROUP_APP_LOCAL, Im = 2, Tm = 6e4, wm = 2e3, Xo = 1e4, gm = 3e3, Sm = 3e3, Jo = 3, Dn = 4;
|
|
5304
5304
|
async function Cm(t, e, n, r) {
|
|
5305
5305
|
if (t)
|
|
5306
5306
|
try {
|
|
@@ -5310,14 +5310,24 @@ async function Cm(t, e, n, r) {
|
|
|
5310
5310
|
body: JSON.stringify({ deviceId: e, space: t }),
|
|
5311
5311
|
signal: r
|
|
5312
5312
|
});
|
|
5313
|
-
if (!i.ok)
|
|
5313
|
+
if (!i.ok) {
|
|
5314
|
+
const a = await i.text().catch(() => "");
|
|
5315
|
+
F.warn(`Anonymous auth failed: ${i.status} ${a}`.trim());
|
|
5314
5316
|
return;
|
|
5317
|
+
}
|
|
5315
5318
|
const s = await i.json();
|
|
5316
|
-
if (!s.token)
|
|
5319
|
+
if (!s.token) {
|
|
5320
|
+
F.warn("Anonymous auth returned no token");
|
|
5317
5321
|
return;
|
|
5322
|
+
}
|
|
5318
5323
|
const o = um(s.token);
|
|
5319
|
-
|
|
5320
|
-
|
|
5324
|
+
if (!o) {
|
|
5325
|
+
F.warn("Anonymous auth token had no extractable userId");
|
|
5326
|
+
return;
|
|
5327
|
+
}
|
|
5328
|
+
return { userId: o, token: s.token };
|
|
5329
|
+
} catch (i) {
|
|
5330
|
+
F.warn("Anonymous auth request failed:", i);
|
|
5321
5331
|
return;
|
|
5322
5332
|
}
|
|
5323
5333
|
}
|
|
@@ -5328,9 +5338,9 @@ async function Am(t, e, n, r) {
|
|
|
5328
5338
|
headers: { Authorization: `Bearer ${n}` },
|
|
5329
5339
|
signal: r
|
|
5330
5340
|
});
|
|
5331
|
-
i.ok ||
|
|
5341
|
+
i.ok || F.warn(`Failed to ensure profile: ${i.status}`);
|
|
5332
5342
|
} catch (i) {
|
|
5333
|
-
|
|
5343
|
+
F.warn("Failed to ensure profile:", i);
|
|
5334
5344
|
}
|
|
5335
5345
|
}
|
|
5336
5346
|
async function Qo(t) {
|
|
@@ -5375,7 +5385,7 @@ async function me(t, e, n) {
|
|
|
5375
5385
|
throw a.status === 429 ? new Ct(`Server is at capacity: ${h}`) : new L(`Failed to connect: ${a.status} ${h}`);
|
|
5376
5386
|
}
|
|
5377
5387
|
const c = await a.arrayBuffer(), l = new Uint8Array(c), d = await jc(l);
|
|
5378
|
-
return
|
|
5388
|
+
return F.debug(`Connect URL fetched in ${Date.now() - o}ms`), { authResponse: d };
|
|
5379
5389
|
}
|
|
5380
5390
|
async function bm(t, e) {
|
|
5381
5391
|
try {
|
|
@@ -5389,7 +5399,7 @@ async function qo(t, e, n, r, i) {
|
|
|
5389
5399
|
const s = [];
|
|
5390
5400
|
if (n === "force-proxy" ? e && s.push({ url: e, isProxy: !0 }) : n === "force-direct" ? s.push({ url: t, isProxy: !1 }) : r ? (e && s.push({ url: e, isProxy: !0 }), s.push({ url: t, isProxy: !1 })) : (s.push({ url: t, isProxy: !1 }), e && s.push({ url: e, isProxy: !0 })), s.length === 0)
|
|
5391
5401
|
throw new L("No connect URL available");
|
|
5392
|
-
|
|
5402
|
+
F.info(`Auth URL order: [${s.map((l) => l.isProxy ? "proxy" : "direct").join(", ")}], mode: ${n}, proxyPreferred: ${r}`);
|
|
5393
5403
|
const o = n === "auto" && s.length > 1 && !s[0].isProxy, a = Date.now();
|
|
5394
5404
|
let c = 0;
|
|
5395
5405
|
for (; c < Im || Date.now() - a < Tm; ) {
|
|
@@ -5397,11 +5407,11 @@ async function qo(t, e, n, r, i) {
|
|
|
5397
5407
|
const d = s[l], h = c === 0 && l === 0 && o ? gm : Xo;
|
|
5398
5408
|
try {
|
|
5399
5409
|
const u = await me(d.url, i, h);
|
|
5400
|
-
return u.usedProxyUrl = d.isProxy, u.directUrl = t,
|
|
5410
|
+
return u.usedProxyUrl = d.isProxy, u.directUrl = t, F.info(`Auth succeeded via ${d.isProxy ? "proxy" : "direct"} URL`), u;
|
|
5401
5411
|
} catch (u) {
|
|
5402
5412
|
if (i?.aborted || u instanceof Ct)
|
|
5403
5413
|
throw u;
|
|
5404
|
-
|
|
5414
|
+
F.warn(`Auth via ${d.isProxy ? "proxy" : "direct"} URL failed (round ${c + 1}, timeout ${h}ms): ${u}`);
|
|
5405
5415
|
}
|
|
5406
5416
|
}
|
|
5407
5417
|
c++, await Lo(wm, i);
|
|
@@ -5484,14 +5494,14 @@ function km(t) {
|
|
|
5484
5494
|
}
|
|
5485
5495
|
async function Dm(t, e) {
|
|
5486
5496
|
const n = `https://${t.host}:${t.httpsPort}`;
|
|
5487
|
-
|
|
5497
|
+
F.debug(`Authenticating with local server: ${n}`);
|
|
5488
5498
|
const i = { ...Nt(), ...t.parameters }, s = t.deviceId ?? bt();
|
|
5489
5499
|
let o = t.userId, a = t.token;
|
|
5490
5500
|
if (!o) {
|
|
5491
5501
|
const I = await Cm(t.spaceId, s, await mm(t.authUrl), e);
|
|
5492
5502
|
I && (o = I.userId, a = I.token);
|
|
5493
5503
|
}
|
|
5494
|
-
if (o || (o = s,
|
|
5504
|
+
if (o || (o = s, F.debug("Using deviceId as userId fallback")), t.spaceId && a)
|
|
5495
5505
|
if (t.token) {
|
|
5496
5506
|
const I = Pt(t.backendUrl), T = await fetch(`${I}/profiles/me?space=${encodeURIComponent(t.spaceId)}`, {
|
|
5497
5507
|
method: "GET",
|
|
@@ -5523,7 +5533,7 @@ async function vm(t, e, n = "auto", r = !1) {
|
|
|
5523
5533
|
if (t.sessionId && t.channelKey)
|
|
5524
5534
|
throw new L("Cannot specify both sessionId and channelKey. Use sessionId for precomputed sessions or channelKey to select a channel.");
|
|
5525
5535
|
const i = zo(t.backendType);
|
|
5526
|
-
|
|
5536
|
+
F.debug(`Authenticating with cloud server: ${i}, space ID: ${t.spaceId}`);
|
|
5527
5537
|
const s = await fetch(`${i}/auth/api-key`, {
|
|
5528
5538
|
method: "POST",
|
|
5529
5539
|
headers: {
|
|
@@ -5586,7 +5596,7 @@ async function vm(t, e, n = "auto", r = !1) {
|
|
|
5586
5596
|
} catch (_) {
|
|
5587
5597
|
if (_ instanceof St || _ instanceof Ct || p === u - 1)
|
|
5588
5598
|
throw _;
|
|
5589
|
-
|
|
5599
|
+
F.debug(`Init attempt ${p + 1}/${u} failed, retrying: ${_}`);
|
|
5590
5600
|
}
|
|
5591
5601
|
throw new L("Failed to init after all attempts");
|
|
5592
5602
|
}
|
|
@@ -5594,7 +5604,7 @@ async function Om(t, e, n = "auto", r = !1) {
|
|
|
5594
5604
|
if (t.sessionId && t.channelKey)
|
|
5595
5605
|
throw new L("Cannot specify both sessionId and channelKey. Use sessionId for precomputed sessions or channelKey to select a channel.");
|
|
5596
5606
|
const i = zo(t.backendType), s = t.token;
|
|
5597
|
-
|
|
5607
|
+
F.debug(`Authenticating with session token to: ${i}, space ID: ${t.spaceId}`);
|
|
5598
5608
|
const o = Nt(), a = t.provisioningTimeoutMs ?? Go, c = { ...o, ...t.parameters }, l = Cn(), d = ne() ? Jo : 1;
|
|
5599
5609
|
for (let h = 0; h < d; h++)
|
|
5600
5610
|
try {
|
|
@@ -5638,7 +5648,7 @@ async function Om(t, e, n = "auto", r = !1) {
|
|
|
5638
5648
|
} catch (u) {
|
|
5639
5649
|
if (u instanceof St || u instanceof Ct || h === d - 1)
|
|
5640
5650
|
throw u;
|
|
5641
|
-
|
|
5651
|
+
F.debug(`Init attempt ${h + 1}/${d} failed, retrying: ${u}`);
|
|
5642
5652
|
}
|
|
5643
5653
|
throw new L("Failed to init after all attempts");
|
|
5644
5654
|
}
|
|
@@ -8373,7 +8383,7 @@ function G_(t) {
|
|
|
8373
8383
|
}
|
|
8374
8384
|
);
|
|
8375
8385
|
}
|
|
8376
|
-
const ot = 48e3,
|
|
8386
|
+
const ot = 48e3, G = 2, pa = 1500, sr = 512, or = "playback", V_ = 120, H_ = 300, $_ = 4, K_ = 200, Y_ = 100, j_ = 8e3, z_ = 10, Ea = 100, rn = 50, ma = 128, X_ = 20, J_ = !0, oe = 1500, Q_ = -20, ar = -100, cr = 200, O = M("IkonAudioPlayback"), Z_ = () => {
|
|
8377
8387
|
if (typeof navigator > "u" || typeof window > "u")
|
|
8378
8388
|
return !1;
|
|
8379
8389
|
const t = navigator.userAgent, e = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(t), n = t.includes("Macintosh") && typeof navigator.maxTouchPoints == "number" && navigator.maxTouchPoints > 1;
|
|
@@ -9563,7 +9573,7 @@ class Ln {
|
|
|
9563
9573
|
const e = this.audioContext;
|
|
9564
9574
|
if (!e)
|
|
9565
9575
|
return null;
|
|
9566
|
-
const n = e.currentTime, r = e.sampleRate, i =
|
|
9576
|
+
const n = e.currentTime, r = e.sampleRate, i = G;
|
|
9567
9577
|
for (const s of this.visemeBuffers.values()) {
|
|
9568
9578
|
if (!s.timingEstablished || s.count === 0)
|
|
9569
9579
|
continue;
|
|
@@ -9789,14 +9799,14 @@ class Ln {
|
|
|
9789
9799
|
await this.resumeWithTimeout(e), this.getContextState(e) === "running" && this.removeUnlockHandler();
|
|
9790
9800
|
} catch {
|
|
9791
9801
|
}
|
|
9792
|
-
const s = `${this.outputSampleRateHz}_${
|
|
9802
|
+
const s = `${this.outputSampleRateHz}_${G}`;
|
|
9793
9803
|
if (!this.workletModuleUrl || this.workletModuleKey !== s) {
|
|
9794
9804
|
if (this.workletModuleUrl)
|
|
9795
9805
|
try {
|
|
9796
9806
|
URL.revokeObjectURL(this.workletModuleUrl);
|
|
9797
9807
|
} catch {
|
|
9798
9808
|
}
|
|
9799
|
-
this.workletModuleKey = s, this.workletReady = null, this.workletModuleUrl = URL.createObjectURL(new Blob([q_({ outputSampleRateHz: this.outputSampleRateHz, outputChannels:
|
|
9809
|
+
this.workletModuleKey = s, this.workletReady = null, this.workletModuleUrl = URL.createObjectURL(new Blob([q_({ outputSampleRateHz: this.outputSampleRateHz, outputChannels: G })], { type: "text/javascript" }));
|
|
9800
9810
|
}
|
|
9801
9811
|
this.workletReady || (this.workletReady = e.audioWorklet.addModule(this.workletModuleUrl).catch((d) => {
|
|
9802
9812
|
throw O.warn(`Failed to load AudioWorklet module, falling back: ${ae(d)}`), d;
|
|
@@ -9812,11 +9822,11 @@ class Ln {
|
|
|
9812
9822
|
this.audioWorkletNode = new AudioWorkletNode(e, "ikon-audio-player", {
|
|
9813
9823
|
numberOfInputs: 0,
|
|
9814
9824
|
numberOfOutputs: 1,
|
|
9815
|
-
outputChannelCount: [
|
|
9825
|
+
outputChannelCount: [G],
|
|
9816
9826
|
processorOptions: {
|
|
9817
9827
|
outputAudioConfig: { diagnostics: n },
|
|
9818
9828
|
useSharedArrayBuffer: a,
|
|
9819
|
-
outputChannels:
|
|
9829
|
+
outputChannels: G
|
|
9820
9830
|
}
|
|
9821
9831
|
}), this.audioWorkletNode.port.onmessage = (d) => {
|
|
9822
9832
|
const h = d.data;
|
|
@@ -9850,7 +9860,7 @@ class Ln {
|
|
|
9850
9860
|
if (this.scriptProcessorNode)
|
|
9851
9861
|
return;
|
|
9852
9862
|
this.stopAudioWorklet(), this.pendingWorkletMessages = [];
|
|
9853
|
-
const r = 1024, i = new Float32Array(r *
|
|
9863
|
+
const r = 1024, i = new Float32Array(r * G), s = Math.round(this.outputSampleRateHz * Ea / 1e3), o = Math.round(this.outputSampleRateHz * rn / 1e3), a = 1 / s, c = 1 / o, l = new Array(G), d = [], h = e.createScriptProcessor(r, 0, G);
|
|
9854
9864
|
h.onaudioprocess = (u) => {
|
|
9855
9865
|
const p = u.outputBuffer, _ = p.numberOfChannels, I = p.length;
|
|
9856
9866
|
for (let E = 0; E < _; E++) {
|
|
@@ -9926,7 +9936,7 @@ class Ln {
|
|
|
9926
9936
|
e.totalSamples < 0 && (e.totalSamples = 0), this.compactFallbackQueue(e);
|
|
9927
9937
|
}
|
|
9928
9938
|
trimFallbackQueue(e) {
|
|
9929
|
-
const n = Math.floor(this.outputSampleRateHz *
|
|
9939
|
+
const n = Math.floor(this.outputSampleRateHz * G * pa / 1e3), r = e.totalSamples - n;
|
|
9930
9940
|
r <= 0 || this.skipFromFallbackQueue(e, r);
|
|
9931
9941
|
}
|
|
9932
9942
|
stopScriptProcessorDiagnostics() {
|
|
@@ -9945,7 +9955,7 @@ class Ln {
|
|
|
9945
9955
|
for (const [r, i] of this.fallbackQueues.entries()) {
|
|
9946
9956
|
if (i.totalSamples <= 0)
|
|
9947
9957
|
continue;
|
|
9948
|
-
const o = i.totalSamples /
|
|
9958
|
+
const o = i.totalSamples / G * 1e3 / this.outputSampleRateHz;
|
|
9949
9959
|
O.debug(`[Audio] stream=${r.substring(0, 8)} buffer=${o.toFixed(0)}ms renderer=ScriptProcessor`);
|
|
9950
9960
|
}
|
|
9951
9961
|
}, n);
|
|
@@ -10028,7 +10038,7 @@ class Ln {
|
|
|
10028
10038
|
type: "rebind",
|
|
10029
10039
|
transport: i,
|
|
10030
10040
|
outputSampleRate: this.outputSampleRateHz,
|
|
10031
|
-
outputChannels:
|
|
10041
|
+
outputChannels: G
|
|
10032
10042
|
});
|
|
10033
10043
|
} catch {
|
|
10034
10044
|
}
|
|
@@ -10059,13 +10069,13 @@ class Ln {
|
|
|
10059
10069
|
type: "configure",
|
|
10060
10070
|
transport: i ? "sab" : "pcm",
|
|
10061
10071
|
outputSampleRate: this.outputSampleRateHz,
|
|
10062
|
-
outputChannels:
|
|
10072
|
+
outputChannels: G,
|
|
10063
10073
|
preferWebCodecs: s,
|
|
10064
10074
|
webRtcEnabled: o
|
|
10065
10075
|
};
|
|
10066
10076
|
n.postMessage(a), n.postMessage({ type: "attachProtocolPort", port: e.port }, [e.port]);
|
|
10067
10077
|
const c = this.audioWorkletNode ? "AudioWorklet" : "ScriptProcessor", l = i ? "SharedArrayBuffer" : "MessagePort", h = o ? "WebRTC (native)" : s && typeof AudioDecoder < "u" ? "WebCodecs" : "WASM Opus";
|
|
10068
|
-
O.debug(`Audio initialized: renderer=${c}, transport=${l}, decoder=${h}, output=${this.outputSampleRateHz}Hz/${
|
|
10078
|
+
O.debug(`Audio initialized: renderer=${c}, transport=${l}, decoder=${h}, output=${this.outputSampleRateHz}Hz/${G}ch`);
|
|
10069
10079
|
}
|
|
10070
10080
|
onAudioWorkerMessage(e) {
|
|
10071
10081
|
if (e.type === "streamBegin") {
|
|
@@ -11187,10 +11197,10 @@ class fI {
|
|
|
11187
11197
|
const b = await this.acquireMicrophoneStream(e);
|
|
11188
11198
|
a = b.stream, c = b.constraints, i.stream = a;
|
|
11189
11199
|
} catch (b) {
|
|
11190
|
-
const
|
|
11200
|
+
const W = b instanceof Error ? b : new Error(String(b)), z = W.captureReason ?? "unknown";
|
|
11191
11201
|
if (e.onError)
|
|
11192
11202
|
try {
|
|
11193
|
-
e.onError(
|
|
11203
|
+
e.onError(W, z, z !== "permission-denied" && z !== "no-device");
|
|
11194
11204
|
} catch {
|
|
11195
11205
|
}
|
|
11196
11206
|
throw b;
|
|
@@ -11227,9 +11237,9 @@ class fI {
|
|
|
11227
11237
|
transport: I,
|
|
11228
11238
|
sharedArrayBuffer: T,
|
|
11229
11239
|
correlationId: e.correlationId
|
|
11230
|
-
}), await new Promise((b,
|
|
11240
|
+
}), await new Promise((b, W) => {
|
|
11231
11241
|
const z = setTimeout(() => {
|
|
11232
|
-
f.removeEventListener("message", qe),
|
|
11242
|
+
f.removeEventListener("message", qe), W(new Error("Audio capture worker start timeout"));
|
|
11233
11243
|
}, 1e4), qe = (Ia) => {
|
|
11234
11244
|
const Ne = Ia.data;
|
|
11235
11245
|
if (Ne?.type === "started" && Ne.captureId === r)
|
|
@@ -11237,7 +11247,7 @@ class fI {
|
|
|
11237
11247
|
else if (Ne?.type === "error" && Ne.captureId === r) {
|
|
11238
11248
|
clearTimeout(z), f.removeEventListener("message", qe);
|
|
11239
11249
|
const Ta = Ne.error;
|
|
11240
|
-
|
|
11250
|
+
W(new Error(Ta?.message ?? "Audio capture failed to start"));
|
|
11241
11251
|
}
|
|
11242
11252
|
};
|
|
11243
11253
|
f.addEventListener("message", qe);
|
|
@@ -11253,9 +11263,9 @@ class fI {
|
|
|
11253
11263
|
}
|
|
11254
11264
|
});
|
|
11255
11265
|
i.worklet = A, h.connect(A), A.connect(u), I === "pcm" && (A.port.onmessage = (b) => {
|
|
11256
|
-
const
|
|
11257
|
-
if (!(!
|
|
11258
|
-
const z =
|
|
11266
|
+
const W = b.data;
|
|
11267
|
+
if (!(!W || typeof W != "object") && W.type === "pcm" && W.pcm instanceof Float32Array) {
|
|
11268
|
+
const z = W.pcm;
|
|
11259
11269
|
f.postMessage({ type: "pcm", captureId: r, pcm: z }, [z.buffer]);
|
|
11260
11270
|
}
|
|
11261
11271
|
});
|
|
@@ -11321,7 +11331,7 @@ class fI {
|
|
|
11321
11331
|
} catch {
|
|
11322
11332
|
}
|
|
11323
11333
|
try {
|
|
11324
|
-
a.getTracks().forEach((
|
|
11334
|
+
a.getTracks().forEach((W) => W.stop());
|
|
11325
11335
|
} catch {
|
|
11326
11336
|
}
|
|
11327
11337
|
if (f.postMessage({ type: "stop", captureId: r }), C)
|