@defcomm/meetingsdk 0.1.9 → 0.2.1
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/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +34 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -392,6 +392,7 @@ var SFUClient = class {
|
|
|
392
392
|
this.trackToSource = /* @__PURE__ */ new Map();
|
|
393
393
|
this.localTrackIds = /* @__PURE__ */ new Map();
|
|
394
394
|
this.subscriberStatsTimer = null;
|
|
395
|
+
this.heartbeatTimer = null;
|
|
395
396
|
this.apiBase = options.apiBase || "https://api.example.com/api";
|
|
396
397
|
this.wsBase = options.wsBase || "wss://api.example.com/ws";
|
|
397
398
|
this.participantId = options.participantId || this.createId();
|
|
@@ -436,6 +437,24 @@ var SFUClient = class {
|
|
|
436
437
|
this.onError = options.onError || console.error;
|
|
437
438
|
this.autoSubscribe = options.autoSubscribe !== false;
|
|
438
439
|
}
|
|
440
|
+
startHeartbeat() {
|
|
441
|
+
this.stopHeartbeat();
|
|
442
|
+
this.heartbeatTimer = setInterval(() => {
|
|
443
|
+
if (this.ws?.readyState !== WebSocket.OPEN) return;
|
|
444
|
+
this.send({
|
|
445
|
+
type: "ping",
|
|
446
|
+
payload: {
|
|
447
|
+
nonce: crypto.randomUUID()
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
}, 1e4);
|
|
451
|
+
}
|
|
452
|
+
stopHeartbeat() {
|
|
453
|
+
if (this.heartbeatTimer) {
|
|
454
|
+
clearInterval(this.heartbeatTimer);
|
|
455
|
+
this.heartbeatTimer = null;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
439
458
|
createId() {
|
|
440
459
|
return typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `id_${Math.random().toString(36).slice(2)}_${Date.now()}`;
|
|
441
460
|
}
|
|
@@ -596,6 +615,7 @@ var SFUClient = class {
|
|
|
596
615
|
);
|
|
597
616
|
this.ws = ws;
|
|
598
617
|
ws.onopen = () => {
|
|
618
|
+
this.startHeartbeat();
|
|
599
619
|
this.setState("joining");
|
|
600
620
|
this.joiningWithResume = Boolean(this.resumeToken);
|
|
601
621
|
const joinPayload = {
|
|
@@ -619,6 +639,7 @@ var SFUClient = class {
|
|
|
619
639
|
this.onError(event);
|
|
620
640
|
};
|
|
621
641
|
ws.onclose = () => {
|
|
642
|
+
this.stopHeartbeat();
|
|
622
643
|
if (this.ws !== ws) return;
|
|
623
644
|
this.ws = null;
|
|
624
645
|
if (this.intentionalClose || this.state === "leaving") {
|
|
@@ -900,11 +921,21 @@ var SFUClient = class {
|
|
|
900
921
|
break;
|
|
901
922
|
}
|
|
902
923
|
case "error": {
|
|
903
|
-
const
|
|
904
|
-
this.
|
|
924
|
+
const message2 = payload.message || "SFU signaling error";
|
|
925
|
+
if (this.state === "reconnecting" && message2.includes("participant session is stale")) {
|
|
926
|
+
console.debug(
|
|
927
|
+
"[SFU] Ignoring stale-session error during recovery",
|
|
928
|
+
message2
|
|
929
|
+
);
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
const error = new Error(message2);
|
|
905
933
|
if (this.state === "joining" || this.state === "waiting_approval") {
|
|
934
|
+
this.onError(error);
|
|
906
935
|
this.failJoin(error);
|
|
936
|
+
return;
|
|
907
937
|
}
|
|
938
|
+
this.onError(error);
|
|
908
939
|
break;
|
|
909
940
|
}
|
|
910
941
|
default:
|
|
@@ -992,18 +1023,6 @@ var SFUClient = class {
|
|
|
992
1023
|
signalingState: publisher.signalingState
|
|
993
1024
|
});
|
|
994
1025
|
if (state === "failed") {
|
|
995
|
-
const error = new Error("Publisher PeerConnection failed");
|
|
996
|
-
this.onError({
|
|
997
|
-
code: "SFU_ERROR",
|
|
998
|
-
message: error.message,
|
|
999
|
-
raw: error,
|
|
1000
|
-
recoverable: true,
|
|
1001
|
-
roomId: this.room,
|
|
1002
|
-
participantId: this.currentParticipantId,
|
|
1003
|
-
peer: "publisher",
|
|
1004
|
-
connectionState: publisher.connectionState,
|
|
1005
|
-
iceConnectionState: publisher.iceConnectionState
|
|
1006
|
-
});
|
|
1007
1026
|
this.recoverWebRTC("publisher_failed");
|
|
1008
1027
|
}
|
|
1009
1028
|
};
|
|
@@ -1018,18 +1037,6 @@ var SFUClient = class {
|
|
|
1018
1037
|
signalingState: subscriber.signalingState
|
|
1019
1038
|
});
|
|
1020
1039
|
if (state === "failed") {
|
|
1021
|
-
const error = new Error("Subscriber PeerConnection failed");
|
|
1022
|
-
this.onError({
|
|
1023
|
-
code: "SFU_ERROR",
|
|
1024
|
-
message: error.message,
|
|
1025
|
-
raw: error,
|
|
1026
|
-
recoverable: true,
|
|
1027
|
-
roomId: this.room,
|
|
1028
|
-
participantId: this.currentParticipantId,
|
|
1029
|
-
peer: "subscriber",
|
|
1030
|
-
connectionState: subscriber.connectionState,
|
|
1031
|
-
iceConnectionState: subscriber.iceConnectionState
|
|
1032
|
-
});
|
|
1033
1040
|
this.recoverWebRTC("subscriber_failed");
|
|
1034
1041
|
}
|
|
1035
1042
|
};
|
|
@@ -1519,6 +1526,7 @@ var SFUClient = class {
|
|
|
1519
1526
|
}
|
|
1520
1527
|
}
|
|
1521
1528
|
async leave() {
|
|
1529
|
+
this.stopHeartbeat();
|
|
1522
1530
|
this.intentionalClose = true;
|
|
1523
1531
|
this.setState("leaving");
|
|
1524
1532
|
if (this.reconnectTimer) {
|