@defcomm/meetingsdk 0.4.5 → 0.4.7
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 +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +57 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -63
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
import { useCallback, useEffect as useEffect2, useRef as useRef2, useState as useState3 } from "react";
|
|
3
3
|
|
|
4
4
|
// src/react/MeetingProvider.tsx
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
createContext,
|
|
7
|
+
useContext,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState as useState2
|
|
11
|
+
} from "react";
|
|
6
12
|
|
|
7
13
|
// src/config/ws.ts
|
|
8
14
|
var SDK_CONFIG = {
|
|
@@ -368,6 +374,9 @@ var SFUClient = class {
|
|
|
368
374
|
this.publisherRevision = 0;
|
|
369
375
|
this.screenShareGeneration = 0;
|
|
370
376
|
this.currentParticipantId = null;
|
|
377
|
+
// Provider/application token used for authenticated REST calls.
|
|
378
|
+
this.authToken = null;
|
|
379
|
+
// Room/SFU token returned by /token and used for the WebSocket.
|
|
371
380
|
this.token = null;
|
|
372
381
|
this.room = null;
|
|
373
382
|
this.resumeToken = null;
|
|
@@ -408,6 +417,7 @@ var SFUClient = class {
|
|
|
408
417
|
this.apiBase = options.apiBase || "https://api.example.com/api";
|
|
409
418
|
this.wsBase = options.wsBase || "wss://api.example.com/ws";
|
|
410
419
|
this.participantId = options.participantId || this.createId();
|
|
420
|
+
this.authToken = options.token ?? null;
|
|
411
421
|
this.onStateChange = options.onStateChange || (() => {
|
|
412
422
|
});
|
|
413
423
|
this.onParticipantJoined = options.onParticipantJoined || (() => {
|
|
@@ -531,9 +541,14 @@ var SFUClient = class {
|
|
|
531
541
|
return (++this.requestId).toString();
|
|
532
542
|
}
|
|
533
543
|
async request(url, options = {}) {
|
|
544
|
+
const headers = new Headers(options.headers);
|
|
545
|
+
headers.set("Content-Type", "application/json");
|
|
546
|
+
if (this.authToken) {
|
|
547
|
+
headers.set("Authorization", `Bearer ${this.authToken}`);
|
|
548
|
+
}
|
|
534
549
|
const res = await fetch(url, {
|
|
535
|
-
|
|
536
|
-
|
|
550
|
+
...options,
|
|
551
|
+
headers
|
|
537
552
|
});
|
|
538
553
|
if (!res.ok) {
|
|
539
554
|
let body = {};
|
|
@@ -541,7 +556,9 @@ var SFUClient = class {
|
|
|
541
556
|
body = await res.json();
|
|
542
557
|
} catch {
|
|
543
558
|
}
|
|
544
|
-
throw new Error(
|
|
559
|
+
throw new Error(
|
|
560
|
+
body.message || `Request failed: ${res.status} ${res.statusText}`
|
|
561
|
+
);
|
|
545
562
|
}
|
|
546
563
|
return res.json();
|
|
547
564
|
}
|
|
@@ -1945,6 +1962,7 @@ var VideoSDKCore = class {
|
|
|
1945
1962
|
}
|
|
1946
1963
|
});
|
|
1947
1964
|
this.myId = options.participantId;
|
|
1965
|
+
this.sfuClient = this.createSFUClient(options.token);
|
|
1948
1966
|
}
|
|
1949
1967
|
emitError(code, message, raw, recoverable = true) {
|
|
1950
1968
|
const err = {
|
|
@@ -2009,36 +2027,16 @@ var VideoSDKCore = class {
|
|
|
2009
2027
|
}
|
|
2010
2028
|
// ROOM MANAGEMENT
|
|
2011
2029
|
async createRoom(input) {
|
|
2012
|
-
|
|
2013
|
-
apiBase: this.apiBase,
|
|
2014
|
-
wsBase: this.wsBase,
|
|
2015
|
-
participantId: this.myId
|
|
2016
|
-
});
|
|
2017
|
-
return client.createRoom(input);
|
|
2030
|
+
return this.sfuClient.createRoom(input);
|
|
2018
2031
|
}
|
|
2019
2032
|
async getRoom(roomCode) {
|
|
2020
|
-
|
|
2021
|
-
apiBase: this.apiBase,
|
|
2022
|
-
wsBase: this.wsBase,
|
|
2023
|
-
participantId: this.myId
|
|
2024
|
-
});
|
|
2025
|
-
return client.getRoom(roomCode);
|
|
2033
|
+
return this.sfuClient.getRoom(roomCode);
|
|
2026
2034
|
}
|
|
2027
2035
|
async getJoinState(roomCode) {
|
|
2028
|
-
|
|
2029
|
-
apiBase: this.apiBase,
|
|
2030
|
-
wsBase: this.wsBase,
|
|
2031
|
-
participantId: this.myId
|
|
2032
|
-
});
|
|
2033
|
-
return client.getJoinState(roomCode);
|
|
2036
|
+
return this.sfuClient.getJoinState(roomCode);
|
|
2034
2037
|
}
|
|
2035
2038
|
async deleteRoom(roomCode) {
|
|
2036
|
-
|
|
2037
|
-
apiBase: this.apiBase,
|
|
2038
|
-
wsBase: this.wsBase,
|
|
2039
|
-
participantId: this.myId
|
|
2040
|
-
});
|
|
2041
|
-
return client.deleteRoom(roomCode);
|
|
2039
|
+
return this.sfuClient.deleteRoom(roomCode);
|
|
2042
2040
|
}
|
|
2043
2041
|
// JOIN
|
|
2044
2042
|
async joinMeeting(config) {
|
|
@@ -2104,26 +2102,36 @@ var VideoSDKCore = class {
|
|
|
2104
2102
|
}
|
|
2105
2103
|
// SFU CONNECTION
|
|
2106
2104
|
async connect(roomId, name) {
|
|
2107
|
-
if (this.sfuClient) {
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2105
|
+
if (!this.sfuClient) {
|
|
2106
|
+
throw new Error("SFU client is not initialized");
|
|
2107
|
+
}
|
|
2108
|
+
const state = this.sfuClient.getConnectionState();
|
|
2109
|
+
if (this.room.id === roomId && (state === "connecting" || state === "joining" || state === "waiting_approval" || state === "connected" || state === "reconnecting")) {
|
|
2110
|
+
console.info("[SDK] Existing SFU connection is active; connect ignored", {
|
|
2111
|
+
roomId,
|
|
2112
|
+
state
|
|
2113
|
+
});
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
if (state !== "idle" && state !== "disconnected") {
|
|
2119
2117
|
throw new Error(
|
|
2120
|
-
`SFU client already
|
|
2118
|
+
`SFU client is already active in state "${state}". Leave the current meeting before joining another room.`
|
|
2121
2119
|
);
|
|
2122
2120
|
}
|
|
2123
|
-
|
|
2121
|
+
this.sfuClient.setLocalStream(this.localStream);
|
|
2122
|
+
await this.sfuClient.getToken(roomId, {
|
|
2123
|
+
displayName: name,
|
|
2124
|
+
participantId: this.myId,
|
|
2125
|
+
audioMuted: !(this.localStream?.getAudioTracks()[0]?.enabled ?? true),
|
|
2126
|
+
videoMuted: !(this.localStream?.getVideoTracks()[0]?.enabled ?? true)
|
|
2127
|
+
});
|
|
2128
|
+
}
|
|
2129
|
+
createSFUClient(token) {
|
|
2130
|
+
return new SFUClient({
|
|
2124
2131
|
apiBase: this.apiBase,
|
|
2125
2132
|
wsBase: this.wsBase,
|
|
2126
2133
|
participantId: this.myId,
|
|
2134
|
+
token,
|
|
2127
2135
|
autoSubscribe: true,
|
|
2128
2136
|
// CONNECTION STATE
|
|
2129
2137
|
onStateChange: (state) => {
|
|
@@ -2462,14 +2470,6 @@ var VideoSDKCore = class {
|
|
|
2462
2470
|
);
|
|
2463
2471
|
}
|
|
2464
2472
|
});
|
|
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
2473
|
}
|
|
2474
2474
|
// SFU STATE
|
|
2475
2475
|
handleSFUState(state) {
|
|
@@ -2750,10 +2750,8 @@ var VideoSDKCore = class {
|
|
|
2750
2750
|
async performDisconnect() {
|
|
2751
2751
|
this.intentionalDisconnect = true;
|
|
2752
2752
|
this.joinPromise = null;
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
if (client) {
|
|
2756
|
-
await client.leave();
|
|
2753
|
+
if (this.sfuClient) {
|
|
2754
|
+
await this.sfuClient.leave();
|
|
2757
2755
|
}
|
|
2758
2756
|
if (this.localStream) {
|
|
2759
2757
|
this.localStream.getTracks().forEach((track) => track.stop());
|
|
@@ -2825,7 +2823,8 @@ var MeetingProvider = ({
|
|
|
2825
2823
|
if (!sdkRef.current) {
|
|
2826
2824
|
sdkRef.current = new VideoSDKCore(
|
|
2827
2825
|
{
|
|
2828
|
-
participantId: config.participantId
|
|
2826
|
+
participantId: config.participantId,
|
|
2827
|
+
token: config.token
|
|
2829
2828
|
},
|
|
2830
2829
|
{
|
|
2831
2830
|
onError: (err) => {
|
|
@@ -2949,14 +2948,16 @@ var MeetingProvider = ({
|
|
|
2949
2948
|
recording,
|
|
2950
2949
|
usePubSub: (topic) => {
|
|
2951
2950
|
if (topic === "SECURE_CHAT") {
|
|
2952
|
-
const chatMessages = messages.map(
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2951
|
+
const chatMessages = messages.map(
|
|
2952
|
+
(message) => ({
|
|
2953
|
+
id: message.id,
|
|
2954
|
+
topic: "SECURE_CHAT",
|
|
2955
|
+
sender_id: message.sender_id,
|
|
2956
|
+
sender_name: message.sender_name,
|
|
2957
|
+
timestamp: message.timestamp,
|
|
2958
|
+
data: message
|
|
2959
|
+
})
|
|
2960
|
+
);
|
|
2960
2961
|
return {
|
|
2961
2962
|
messages: chatMessages,
|
|
2962
2963
|
publish: ((data) => {
|