@defcomm/meetingsdk 0.4.5 → 0.4.6
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 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +47 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -368,6 +368,9 @@ var SFUClient = class {
|
|
|
368
368
|
this.publisherRevision = 0;
|
|
369
369
|
this.screenShareGeneration = 0;
|
|
370
370
|
this.currentParticipantId = null;
|
|
371
|
+
// Provider/application token used for authenticated REST calls.
|
|
372
|
+
this.authToken = null;
|
|
373
|
+
// Room/SFU token returned by /token and used for the WebSocket.
|
|
371
374
|
this.token = null;
|
|
372
375
|
this.room = null;
|
|
373
376
|
this.resumeToken = null;
|
|
@@ -408,6 +411,7 @@ var SFUClient = class {
|
|
|
408
411
|
this.apiBase = options.apiBase || "https://api.example.com/api";
|
|
409
412
|
this.wsBase = options.wsBase || "wss://api.example.com/ws";
|
|
410
413
|
this.participantId = options.participantId || this.createId();
|
|
414
|
+
this.authToken = options.token ?? null;
|
|
411
415
|
this.onStateChange = options.onStateChange || (() => {
|
|
412
416
|
});
|
|
413
417
|
this.onParticipantJoined = options.onParticipantJoined || (() => {
|
|
@@ -531,9 +535,14 @@ var SFUClient = class {
|
|
|
531
535
|
return (++this.requestId).toString();
|
|
532
536
|
}
|
|
533
537
|
async request(url, options = {}) {
|
|
538
|
+
const headers = new Headers(options.headers);
|
|
539
|
+
headers.set("Content-Type", "application/json");
|
|
540
|
+
if (this.authToken) {
|
|
541
|
+
headers.set("Authorization", `Bearer ${this.authToken}`);
|
|
542
|
+
}
|
|
534
543
|
const res = await fetch(url, {
|
|
535
|
-
|
|
536
|
-
|
|
544
|
+
...options,
|
|
545
|
+
headers
|
|
537
546
|
});
|
|
538
547
|
if (!res.ok) {
|
|
539
548
|
let body = {};
|
|
@@ -541,7 +550,9 @@ var SFUClient = class {
|
|
|
541
550
|
body = await res.json();
|
|
542
551
|
} catch {
|
|
543
552
|
}
|
|
544
|
-
throw new Error(
|
|
553
|
+
throw new Error(
|
|
554
|
+
body.message || `Request failed: ${res.status} ${res.statusText}`
|
|
555
|
+
);
|
|
545
556
|
}
|
|
546
557
|
return res.json();
|
|
547
558
|
}
|
|
@@ -1945,6 +1956,7 @@ var VideoSDKCore = class {
|
|
|
1945
1956
|
}
|
|
1946
1957
|
});
|
|
1947
1958
|
this.myId = options.participantId;
|
|
1959
|
+
this.sfuClient = this.createSFUClient(options.token);
|
|
1948
1960
|
}
|
|
1949
1961
|
emitError(code, message, raw, recoverable = true) {
|
|
1950
1962
|
const err = {
|
|
@@ -2009,36 +2021,16 @@ var VideoSDKCore = class {
|
|
|
2009
2021
|
}
|
|
2010
2022
|
// ROOM MANAGEMENT
|
|
2011
2023
|
async createRoom(input) {
|
|
2012
|
-
|
|
2013
|
-
apiBase: this.apiBase,
|
|
2014
|
-
wsBase: this.wsBase,
|
|
2015
|
-
participantId: this.myId
|
|
2016
|
-
});
|
|
2017
|
-
return client.createRoom(input);
|
|
2024
|
+
return this.sfuClient.createRoom(input);
|
|
2018
2025
|
}
|
|
2019
2026
|
async getRoom(roomCode) {
|
|
2020
|
-
|
|
2021
|
-
apiBase: this.apiBase,
|
|
2022
|
-
wsBase: this.wsBase,
|
|
2023
|
-
participantId: this.myId
|
|
2024
|
-
});
|
|
2025
|
-
return client.getRoom(roomCode);
|
|
2027
|
+
return this.sfuClient.getRoom(roomCode);
|
|
2026
2028
|
}
|
|
2027
2029
|
async getJoinState(roomCode) {
|
|
2028
|
-
|
|
2029
|
-
apiBase: this.apiBase,
|
|
2030
|
-
wsBase: this.wsBase,
|
|
2031
|
-
participantId: this.myId
|
|
2032
|
-
});
|
|
2033
|
-
return client.getJoinState(roomCode);
|
|
2030
|
+
return this.sfuClient.getJoinState(roomCode);
|
|
2034
2031
|
}
|
|
2035
2032
|
async deleteRoom(roomCode) {
|
|
2036
|
-
|
|
2037
|
-
apiBase: this.apiBase,
|
|
2038
|
-
wsBase: this.wsBase,
|
|
2039
|
-
participantId: this.myId
|
|
2040
|
-
});
|
|
2041
|
-
return client.deleteRoom(roomCode);
|
|
2033
|
+
return this.sfuClient.deleteRoom(roomCode);
|
|
2042
2034
|
}
|
|
2043
2035
|
// JOIN
|
|
2044
2036
|
async joinMeeting(config) {
|
|
@@ -2104,26 +2096,36 @@ var VideoSDKCore = class {
|
|
|
2104
2096
|
}
|
|
2105
2097
|
// SFU CONNECTION
|
|
2106
2098
|
async connect(roomId, name) {
|
|
2107
|
-
if (this.sfuClient) {
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2099
|
+
if (!this.sfuClient) {
|
|
2100
|
+
throw new Error("SFU client is not initialized");
|
|
2101
|
+
}
|
|
2102
|
+
const state = this.sfuClient.getConnectionState();
|
|
2103
|
+
if (this.room.id === roomId && (state === "connecting" || state === "joining" || state === "waiting_approval" || state === "connected" || state === "reconnecting")) {
|
|
2104
|
+
console.info("[SDK] Existing SFU connection is active; connect ignored", {
|
|
2105
|
+
roomId,
|
|
2106
|
+
state
|
|
2107
|
+
});
|
|
2108
|
+
return;
|
|
2109
|
+
}
|
|
2110
|
+
if (state !== "idle" && state !== "disconnected") {
|
|
2119
2111
|
throw new Error(
|
|
2120
|
-
`SFU client already
|
|
2112
|
+
`SFU client is already active in state "${state}". Leave the current meeting before joining another room.`
|
|
2121
2113
|
);
|
|
2122
2114
|
}
|
|
2123
|
-
|
|
2115
|
+
this.sfuClient.setLocalStream(this.localStream);
|
|
2116
|
+
await this.sfuClient.getToken(roomId, {
|
|
2117
|
+
displayName: name,
|
|
2118
|
+
participantId: this.myId,
|
|
2119
|
+
audioMuted: !(this.localStream?.getAudioTracks()[0]?.enabled ?? true),
|
|
2120
|
+
videoMuted: !(this.localStream?.getVideoTracks()[0]?.enabled ?? true)
|
|
2121
|
+
});
|
|
2122
|
+
}
|
|
2123
|
+
createSFUClient(token) {
|
|
2124
|
+
return new SFUClient({
|
|
2124
2125
|
apiBase: this.apiBase,
|
|
2125
2126
|
wsBase: this.wsBase,
|
|
2126
2127
|
participantId: this.myId,
|
|
2128
|
+
token,
|
|
2127
2129
|
autoSubscribe: true,
|
|
2128
2130
|
// CONNECTION STATE
|
|
2129
2131
|
onStateChange: (state) => {
|
|
@@ -2462,14 +2464,6 @@ var VideoSDKCore = class {
|
|
|
2462
2464
|
);
|
|
2463
2465
|
}
|
|
2464
2466
|
});
|
|
2465
|
-
this.sfuClient = client;
|
|
2466
|
-
client.setLocalStream(this.localStream);
|
|
2467
|
-
await client.getToken(roomId, {
|
|
2468
|
-
displayName: name,
|
|
2469
|
-
participantId: this.myId,
|
|
2470
|
-
audioMuted: !(this.localStream?.getAudioTracks()[0]?.enabled ?? true),
|
|
2471
|
-
videoMuted: !(this.localStream?.getVideoTracks()[0]?.enabled ?? true)
|
|
2472
|
-
});
|
|
2473
2467
|
}
|
|
2474
2468
|
// SFU STATE
|
|
2475
2469
|
handleSFUState(state) {
|
|
@@ -2750,10 +2744,8 @@ var VideoSDKCore = class {
|
|
|
2750
2744
|
async performDisconnect() {
|
|
2751
2745
|
this.intentionalDisconnect = true;
|
|
2752
2746
|
this.joinPromise = null;
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
if (client) {
|
|
2756
|
-
await client.leave();
|
|
2747
|
+
if (this.sfuClient) {
|
|
2748
|
+
await this.sfuClient.leave();
|
|
2757
2749
|
}
|
|
2758
2750
|
if (this.localStream) {
|
|
2759
2751
|
this.localStream.getTracks().forEach((track) => track.stop());
|
|
@@ -2825,7 +2817,8 @@ var MeetingProvider = ({
|
|
|
2825
2817
|
if (!sdkRef.current) {
|
|
2826
2818
|
sdkRef.current = new VideoSDKCore(
|
|
2827
2819
|
{
|
|
2828
|
-
participantId: config.participantId
|
|
2820
|
+
participantId: config.participantId,
|
|
2821
|
+
token: config.token
|
|
2829
2822
|
},
|
|
2830
2823
|
{
|
|
2831
2824
|
onError: (err) => {
|