@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 CHANGED
@@ -123,7 +123,7 @@ type MeetingConfig = {
123
123
  name: string;
124
124
  audioMuted?: boolean;
125
125
  videoMuted?: boolean;
126
- token?: string;
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(): {
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?: string;
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(): {
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
- headers: { "Content-Type": "application/json" },
572
- ...options
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(body.message || res.statusText);
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
- const client = this.sfuClient ?? new SFUClient({
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
- const client = this.sfuClient ?? new SFUClient({
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
- const client = this.sfuClient ?? new SFUClient({
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
- const client = this.sfuClient ?? new SFUClient({
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
- const state = this.sfuClient.getConnectionState();
2145
- if (this.room.id === roomId && (state === "connecting" || state === "connected" || state === "reconnecting")) {
2146
- console.info(
2147
- "[SDK] Existing SFU connection is active; connect ignored",
2148
- {
2149
- roomId,
2150
- state
2151
- }
2152
- );
2153
- return;
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 exists in state "${state}". Disconnect explicitly before creating another connection.`
2148
+ `SFU client is already active in state "${state}". Leave the current meeting before joining another room.`
2157
2149
  );
2158
2150
  }
2159
- const client = new SFUClient({
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
- const client = this.sfuClient;
2790
- this.sfuClient = null;
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) => {