@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.d.mts
CHANGED
|
@@ -123,7 +123,7 @@ type MeetingConfig = {
|
|
|
123
123
|
name: string;
|
|
124
124
|
audioMuted?: boolean;
|
|
125
125
|
videoMuted?: boolean;
|
|
126
|
-
token
|
|
126
|
+
token: string;
|
|
127
127
|
};
|
|
128
128
|
type RecordingInfo = {
|
|
129
129
|
recording_id: string;
|
|
@@ -160,6 +160,7 @@ interface Recording {
|
|
|
160
160
|
}
|
|
161
161
|
interface VideoSDKCoreOptions {
|
|
162
162
|
participantId: string;
|
|
163
|
+
token: string;
|
|
163
164
|
onError?: (error: any) => void;
|
|
164
165
|
onEntryRequested?: (request: any) => void;
|
|
165
166
|
onEntryResponded?: (payload: any, decision?: any) => void;
|
|
@@ -249,6 +250,7 @@ declare class VideoSDKCore {
|
|
|
249
250
|
deleteRoom(roomCode: string): Promise<any>;
|
|
250
251
|
joinMeeting(config: Omit<MeetingConfig, "participantId">): Promise<void>;
|
|
251
252
|
private connect;
|
|
253
|
+
private createSFUClient;
|
|
252
254
|
private handleSFUState;
|
|
253
255
|
private handleRemoteTrack;
|
|
254
256
|
getMeeting(): {
|
|
@@ -301,7 +303,7 @@ interface ParticipantInfo {
|
|
|
301
303
|
|
|
302
304
|
type MeetingContextValue = {
|
|
303
305
|
sdk: VideoSDKCore;
|
|
304
|
-
join: (config?: Omit<MeetingConfig, "participantId">) => Promise<void>;
|
|
306
|
+
join: (config?: Omit<MeetingConfig, "participantId" | "token">) => Promise<void>;
|
|
305
307
|
getJoinState: (roomCode: string) => Promise<JoinState>;
|
|
306
308
|
leave: () => void;
|
|
307
309
|
createRoom: (input: {
|
|
@@ -364,7 +366,7 @@ declare const useMeeting: (handlers?: {
|
|
|
364
366
|
onActiveSpeakersChanged?: (participantIds: string[]) => void;
|
|
365
367
|
onConnectionStateChanged?: (state: SFUConnectionState) => void;
|
|
366
368
|
}) => {
|
|
367
|
-
join: (config?: Omit<MeetingConfig, "participantId">) => Promise<void>;
|
|
369
|
+
join: (config?: Omit<MeetingConfig, "participantId" | "token">) => Promise<void>;
|
|
368
370
|
getJoinState: (roomCode: string) => Promise<JoinState>;
|
|
369
371
|
leave: () => void;
|
|
370
372
|
createRoom: (input: {
|
package/dist/index.d.ts
CHANGED
|
@@ -123,7 +123,7 @@ type MeetingConfig = {
|
|
|
123
123
|
name: string;
|
|
124
124
|
audioMuted?: boolean;
|
|
125
125
|
videoMuted?: boolean;
|
|
126
|
-
token
|
|
126
|
+
token: string;
|
|
127
127
|
};
|
|
128
128
|
type RecordingInfo = {
|
|
129
129
|
recording_id: string;
|
|
@@ -160,6 +160,7 @@ interface Recording {
|
|
|
160
160
|
}
|
|
161
161
|
interface VideoSDKCoreOptions {
|
|
162
162
|
participantId: string;
|
|
163
|
+
token: string;
|
|
163
164
|
onError?: (error: any) => void;
|
|
164
165
|
onEntryRequested?: (request: any) => void;
|
|
165
166
|
onEntryResponded?: (payload: any, decision?: any) => void;
|
|
@@ -249,6 +250,7 @@ declare class VideoSDKCore {
|
|
|
249
250
|
deleteRoom(roomCode: string): Promise<any>;
|
|
250
251
|
joinMeeting(config: Omit<MeetingConfig, "participantId">): Promise<void>;
|
|
251
252
|
private connect;
|
|
253
|
+
private createSFUClient;
|
|
252
254
|
private handleSFUState;
|
|
253
255
|
private handleRemoteTrack;
|
|
254
256
|
getMeeting(): {
|
|
@@ -301,7 +303,7 @@ interface ParticipantInfo {
|
|
|
301
303
|
|
|
302
304
|
type MeetingContextValue = {
|
|
303
305
|
sdk: VideoSDKCore;
|
|
304
|
-
join: (config?: Omit<MeetingConfig, "participantId">) => Promise<void>;
|
|
306
|
+
join: (config?: Omit<MeetingConfig, "participantId" | "token">) => Promise<void>;
|
|
305
307
|
getJoinState: (roomCode: string) => Promise<JoinState>;
|
|
306
308
|
leave: () => void;
|
|
307
309
|
createRoom: (input: {
|
|
@@ -364,7 +366,7 @@ declare const useMeeting: (handlers?: {
|
|
|
364
366
|
onActiveSpeakersChanged?: (participantIds: string[]) => void;
|
|
365
367
|
onConnectionStateChanged?: (state: SFUConnectionState) => void;
|
|
366
368
|
}) => {
|
|
367
|
-
join: (config?: Omit<MeetingConfig, "participantId">) => Promise<void>;
|
|
369
|
+
join: (config?: Omit<MeetingConfig, "participantId" | "token">) => Promise<void>;
|
|
368
370
|
getJoinState: (roomCode: string) => Promise<JoinState>;
|
|
369
371
|
leave: () => void;
|
|
370
372
|
createRoom: (input: {
|
package/dist/index.js
CHANGED
|
@@ -404,6 +404,9 @@ var SFUClient = class {
|
|
|
404
404
|
this.publisherRevision = 0;
|
|
405
405
|
this.screenShareGeneration = 0;
|
|
406
406
|
this.currentParticipantId = null;
|
|
407
|
+
// Provider/application token used for authenticated REST calls.
|
|
408
|
+
this.authToken = null;
|
|
409
|
+
// Room/SFU token returned by /token and used for the WebSocket.
|
|
407
410
|
this.token = null;
|
|
408
411
|
this.room = null;
|
|
409
412
|
this.resumeToken = null;
|
|
@@ -444,6 +447,7 @@ var SFUClient = class {
|
|
|
444
447
|
this.apiBase = options.apiBase || "https://api.example.com/api";
|
|
445
448
|
this.wsBase = options.wsBase || "wss://api.example.com/ws";
|
|
446
449
|
this.participantId = options.participantId || this.createId();
|
|
450
|
+
this.authToken = options.token ?? null;
|
|
447
451
|
this.onStateChange = options.onStateChange || (() => {
|
|
448
452
|
});
|
|
449
453
|
this.onParticipantJoined = options.onParticipantJoined || (() => {
|
|
@@ -567,9 +571,14 @@ var SFUClient = class {
|
|
|
567
571
|
return (++this.requestId).toString();
|
|
568
572
|
}
|
|
569
573
|
async request(url, options = {}) {
|
|
574
|
+
const headers = new Headers(options.headers);
|
|
575
|
+
headers.set("Content-Type", "application/json");
|
|
576
|
+
if (this.authToken) {
|
|
577
|
+
headers.set("Authorization", `Bearer ${this.authToken}`);
|
|
578
|
+
}
|
|
570
579
|
const res = await fetch(url, {
|
|
571
|
-
|
|
572
|
-
|
|
580
|
+
...options,
|
|
581
|
+
headers
|
|
573
582
|
});
|
|
574
583
|
if (!res.ok) {
|
|
575
584
|
let body = {};
|
|
@@ -577,7 +586,9 @@ var SFUClient = class {
|
|
|
577
586
|
body = await res.json();
|
|
578
587
|
} catch {
|
|
579
588
|
}
|
|
580
|
-
throw new Error(
|
|
589
|
+
throw new Error(
|
|
590
|
+
body.message || `Request failed: ${res.status} ${res.statusText}`
|
|
591
|
+
);
|
|
581
592
|
}
|
|
582
593
|
return res.json();
|
|
583
594
|
}
|
|
@@ -1981,6 +1992,7 @@ var VideoSDKCore = class {
|
|
|
1981
1992
|
}
|
|
1982
1993
|
});
|
|
1983
1994
|
this.myId = options.participantId;
|
|
1995
|
+
this.sfuClient = this.createSFUClient(options.token);
|
|
1984
1996
|
}
|
|
1985
1997
|
emitError(code, message, raw, recoverable = true) {
|
|
1986
1998
|
const err = {
|
|
@@ -2045,36 +2057,16 @@ var VideoSDKCore = class {
|
|
|
2045
2057
|
}
|
|
2046
2058
|
// ROOM MANAGEMENT
|
|
2047
2059
|
async createRoom(input) {
|
|
2048
|
-
|
|
2049
|
-
apiBase: this.apiBase,
|
|
2050
|
-
wsBase: this.wsBase,
|
|
2051
|
-
participantId: this.myId
|
|
2052
|
-
});
|
|
2053
|
-
return client.createRoom(input);
|
|
2060
|
+
return this.sfuClient.createRoom(input);
|
|
2054
2061
|
}
|
|
2055
2062
|
async getRoom(roomCode) {
|
|
2056
|
-
|
|
2057
|
-
apiBase: this.apiBase,
|
|
2058
|
-
wsBase: this.wsBase,
|
|
2059
|
-
participantId: this.myId
|
|
2060
|
-
});
|
|
2061
|
-
return client.getRoom(roomCode);
|
|
2063
|
+
return this.sfuClient.getRoom(roomCode);
|
|
2062
2064
|
}
|
|
2063
2065
|
async getJoinState(roomCode) {
|
|
2064
|
-
|
|
2065
|
-
apiBase: this.apiBase,
|
|
2066
|
-
wsBase: this.wsBase,
|
|
2067
|
-
participantId: this.myId
|
|
2068
|
-
});
|
|
2069
|
-
return client.getJoinState(roomCode);
|
|
2066
|
+
return this.sfuClient.getJoinState(roomCode);
|
|
2070
2067
|
}
|
|
2071
2068
|
async deleteRoom(roomCode) {
|
|
2072
|
-
|
|
2073
|
-
apiBase: this.apiBase,
|
|
2074
|
-
wsBase: this.wsBase,
|
|
2075
|
-
participantId: this.myId
|
|
2076
|
-
});
|
|
2077
|
-
return client.deleteRoom(roomCode);
|
|
2069
|
+
return this.sfuClient.deleteRoom(roomCode);
|
|
2078
2070
|
}
|
|
2079
2071
|
// JOIN
|
|
2080
2072
|
async joinMeeting(config) {
|
|
@@ -2140,26 +2132,36 @@ var VideoSDKCore = class {
|
|
|
2140
2132
|
}
|
|
2141
2133
|
// SFU CONNECTION
|
|
2142
2134
|
async connect(roomId, name) {
|
|
2143
|
-
if (this.sfuClient) {
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2135
|
+
if (!this.sfuClient) {
|
|
2136
|
+
throw new Error("SFU client is not initialized");
|
|
2137
|
+
}
|
|
2138
|
+
const state = this.sfuClient.getConnectionState();
|
|
2139
|
+
if (this.room.id === roomId && (state === "connecting" || state === "joining" || state === "waiting_approval" || state === "connected" || state === "reconnecting")) {
|
|
2140
|
+
console.info("[SDK] Existing SFU connection is active; connect ignored", {
|
|
2141
|
+
roomId,
|
|
2142
|
+
state
|
|
2143
|
+
});
|
|
2144
|
+
return;
|
|
2145
|
+
}
|
|
2146
|
+
if (state !== "idle" && state !== "disconnected") {
|
|
2155
2147
|
throw new Error(
|
|
2156
|
-
`SFU client already
|
|
2148
|
+
`SFU client is already active in state "${state}". Leave the current meeting before joining another room.`
|
|
2157
2149
|
);
|
|
2158
2150
|
}
|
|
2159
|
-
|
|
2151
|
+
this.sfuClient.setLocalStream(this.localStream);
|
|
2152
|
+
await this.sfuClient.getToken(roomId, {
|
|
2153
|
+
displayName: name,
|
|
2154
|
+
participantId: this.myId,
|
|
2155
|
+
audioMuted: !(this.localStream?.getAudioTracks()[0]?.enabled ?? true),
|
|
2156
|
+
videoMuted: !(this.localStream?.getVideoTracks()[0]?.enabled ?? true)
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
2159
|
+
createSFUClient(token) {
|
|
2160
|
+
return new SFUClient({
|
|
2160
2161
|
apiBase: this.apiBase,
|
|
2161
2162
|
wsBase: this.wsBase,
|
|
2162
2163
|
participantId: this.myId,
|
|
2164
|
+
token,
|
|
2163
2165
|
autoSubscribe: true,
|
|
2164
2166
|
// CONNECTION STATE
|
|
2165
2167
|
onStateChange: (state) => {
|
|
@@ -2498,14 +2500,6 @@ var VideoSDKCore = class {
|
|
|
2498
2500
|
);
|
|
2499
2501
|
}
|
|
2500
2502
|
});
|
|
2501
|
-
this.sfuClient = client;
|
|
2502
|
-
client.setLocalStream(this.localStream);
|
|
2503
|
-
await client.getToken(roomId, {
|
|
2504
|
-
displayName: name,
|
|
2505
|
-
participantId: this.myId,
|
|
2506
|
-
audioMuted: !(this.localStream?.getAudioTracks()[0]?.enabled ?? true),
|
|
2507
|
-
videoMuted: !(this.localStream?.getVideoTracks()[0]?.enabled ?? true)
|
|
2508
|
-
});
|
|
2509
2503
|
}
|
|
2510
2504
|
// SFU STATE
|
|
2511
2505
|
handleSFUState(state) {
|
|
@@ -2786,10 +2780,8 @@ var VideoSDKCore = class {
|
|
|
2786
2780
|
async performDisconnect() {
|
|
2787
2781
|
this.intentionalDisconnect = true;
|
|
2788
2782
|
this.joinPromise = null;
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
if (client) {
|
|
2792
|
-
await client.leave();
|
|
2783
|
+
if (this.sfuClient) {
|
|
2784
|
+
await this.sfuClient.leave();
|
|
2793
2785
|
}
|
|
2794
2786
|
if (this.localStream) {
|
|
2795
2787
|
this.localStream.getTracks().forEach((track) => track.stop());
|
|
@@ -2861,7 +2853,8 @@ var MeetingProvider = ({
|
|
|
2861
2853
|
if (!sdkRef.current) {
|
|
2862
2854
|
sdkRef.current = new VideoSDKCore(
|
|
2863
2855
|
{
|
|
2864
|
-
participantId: config.participantId
|
|
2856
|
+
participantId: config.participantId,
|
|
2857
|
+
token: config.token
|
|
2865
2858
|
},
|
|
2866
2859
|
{
|
|
2867
2860
|
onError: (err) => {
|
|
@@ -2985,14 +2978,16 @@ var MeetingProvider = ({
|
|
|
2985
2978
|
recording,
|
|
2986
2979
|
usePubSub: (topic) => {
|
|
2987
2980
|
if (topic === "SECURE_CHAT") {
|
|
2988
|
-
const chatMessages = messages.map(
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2981
|
+
const chatMessages = messages.map(
|
|
2982
|
+
(message) => ({
|
|
2983
|
+
id: message.id,
|
|
2984
|
+
topic: "SECURE_CHAT",
|
|
2985
|
+
sender_id: message.sender_id,
|
|
2986
|
+
sender_name: message.sender_name,
|
|
2987
|
+
timestamp: message.timestamp,
|
|
2988
|
+
data: message
|
|
2989
|
+
})
|
|
2990
|
+
);
|
|
2996
2991
|
return {
|
|
2997
2992
|
messages: chatMessages,
|
|
2998
2993
|
publish: ((data) => {
|