@defcomm/meetingsdk 0.4.8 → 0.5.0

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.mjs CHANGED
@@ -446,6 +446,12 @@ var SFUClient = class {
446
446
  });
447
447
  this.onJoinRequested = options.onJoinRequested || (() => {
448
448
  });
449
+ this.onJoinRequestCanceled = options.onJoinRequestCanceled || (() => {
450
+ });
451
+ this.onParticipantRemoved = options.onParticipantRemoved || (() => {
452
+ });
453
+ this.onParticipantPermissionsChanged = options.onParticipantPermissionsChanged || (() => {
454
+ });
449
455
  this.onScreenShareStarted = options.onScreenShareStarted || (() => {
450
456
  });
451
457
  this.onScreenShareStopped = options.onScreenShareStopped || (() => {
@@ -813,6 +819,38 @@ var SFUClient = class {
813
819
  this.onJoinRequested(payload.request || payload);
814
820
  break;
815
821
  }
822
+ case "join_request_canceled": {
823
+ this.onJoinRequestCanceled(payload.request_id || message.request_id);
824
+ break;
825
+ }
826
+ case "participant_removed": {
827
+ const participantId = payload.participant_id;
828
+ if (!participantId) break;
829
+ const removedBy = payload.removed_by || "";
830
+ this.participants.delete(participantId);
831
+ this.removeRemoteParticipant(participantId);
832
+ if (participantId === this.currentParticipantId) {
833
+ this.intentionalClose = true;
834
+ this.pendingJoinRequestId = null;
835
+ this.setState("disconnected");
836
+ try {
837
+ this.ws?.close();
838
+ } catch {
839
+ }
840
+ }
841
+ this.onParticipantRemoved(participantId, removedBy);
842
+ break;
843
+ }
844
+ case "participant_permissions_changed": {
845
+ const participantId = payload.participant_id;
846
+ if (!participantId) break;
847
+ const participant = this.participants.get(participantId);
848
+ if (participant) {
849
+ this.participants.set(participantId, { ...participant, permissions: payload.permissions });
850
+ }
851
+ this.onParticipantPermissionsChanged(participantId, payload.permissions);
852
+ break;
853
+ }
816
854
  case "publish_answer": {
817
855
  if (!this.publisher) break;
818
856
  await this.publisher.setRemoteDescription({
@@ -1716,6 +1754,39 @@ var SFUClient = class {
1716
1754
  throw new Error("SFU signaling is not connected");
1717
1755
  }
1718
1756
  }
1757
+ async cancelJoinRequest(requestId) {
1758
+ if (!requestId) throw new Error("requestId is required");
1759
+ if (!this.send({ type: "cancel_join_request", payload: { request_id: requestId } })) {
1760
+ throw new Error("SFU signaling is not connected");
1761
+ }
1762
+ this.pendingJoinRequestId = null;
1763
+ }
1764
+ async muteAllAudio() {
1765
+ if (!this.send({ type: "mute_all_audio" })) throw new Error("SFU signaling is not connected");
1766
+ }
1767
+ async unmuteAllAudio() {
1768
+ if (!this.send({ type: "unmute_all_audio" })) throw new Error("SFU signaling is not connected");
1769
+ }
1770
+ async removeParticipant(participantId) {
1771
+ if (!participantId) throw new Error("participantId is required");
1772
+ if (!this.send({ type: "remove_participant", payload: { participant_id: participantId } })) {
1773
+ throw new Error("SFU signaling is not connected");
1774
+ }
1775
+ }
1776
+ async getModerators(roomCode) {
1777
+ return this.request(`${this.apiBase}/rooms/${encodeURIComponent(roomCode)}/moderators`);
1778
+ }
1779
+ async addModerator(roomCode, userId) {
1780
+ return this.request(`${this.apiBase}/rooms/${encodeURIComponent(roomCode)}/moderators`, {
1781
+ method: "POST",
1782
+ body: JSON.stringify({ user_id: userId })
1783
+ });
1784
+ }
1785
+ async removeModerator(roomCode, userId) {
1786
+ return this.request(`${this.apiBase}/rooms/${encodeURIComponent(roomCode)}/moderators/${encodeURIComponent(userId)}`, {
1787
+ method: "DELETE"
1788
+ });
1789
+ }
1719
1790
  isSocketOpen() {
1720
1791
  return this.ws?.readyState === WebSocket.OPEN;
1721
1792
  }
@@ -2237,6 +2308,33 @@ var VideoSDKCore = class {
2237
2308
  this.state.addChatMessage(msg);
2238
2309
  this.events.onChatMessage?.(msg);
2239
2310
  },
2311
+ onReaction: (reaction) => {
2312
+ this.events.onReaction?.(reaction);
2313
+ },
2314
+ onJoinRequestCanceled: (requestId) => {
2315
+ this.events.onJoinRequestCanceled?.(requestId);
2316
+ },
2317
+ onParticipantRemoved: (participantId, removedBy) => {
2318
+ if (participantId === this.myId) {
2319
+ this.intentionalDisconnect = true;
2320
+ this.events.onUserLeft?.(participantId);
2321
+ try {
2322
+ this.localStream?.getTracks().forEach((track) => track.enabled = false);
2323
+ } catch {
2324
+ }
2325
+ } else {
2326
+ this.cleanupRemoteParticipant(participantId);
2327
+ this.state.removeParticipant(participantId);
2328
+ this.events.onUserLeft?.(participantId);
2329
+ }
2330
+ this.events.onParticipantRemoved?.(participantId, removedBy);
2331
+ },
2332
+ onParticipantPermissionsChanged: (participantId, permissions) => {
2333
+ if (participantId === this.myId) {
2334
+ const current = this.state.localParticipant;
2335
+ this.state.updateLocalParticipant({ id: this.myId, name: this.participantName, isHost: Boolean(permissions?.moderate) && current?.isHost, isModerator: Boolean(permissions?.moderate), permissions });
2336
+ }
2337
+ },
2240
2338
  onJoinRequested: (request) => {
2241
2339
  const requestId = request?.request_id || request?.requestId;
2242
2340
  const participantId = request?.user_id || request?.participantId;
@@ -2260,6 +2358,8 @@ var VideoSDKCore = class {
2260
2358
  this.state.addParticipant({
2261
2359
  id: pid,
2262
2360
  name: pname,
2361
+ isModerator: Boolean(participant?.permissions?.moderate),
2362
+ permissions: participant?.permissions,
2263
2363
  connectionState: "connected",
2264
2364
  media: {
2265
2365
  micEnabled: true,
@@ -2306,7 +2406,18 @@ var VideoSDKCore = class {
2306
2406
  },
2307
2407
  // TRACKS
2308
2408
  onParticipantMediaState: (participantId, audioMuted, videoMuted) => {
2309
- if (participantId === this.myId) return;
2409
+ if (participantId === this.myId) {
2410
+ this.localStream?.getAudioTracks().forEach((track) => track.enabled = !audioMuted);
2411
+ this.localStream?.getVideoTracks().forEach((track) => track.enabled = !videoMuted);
2412
+ this.state.updateLocalParticipant({
2413
+ id: this.myId,
2414
+ name: this.participantName,
2415
+ media: { micEnabled: !audioMuted, camEnabled: !videoMuted }
2416
+ });
2417
+ this.events.onMuteStateChanged?.(participantId, "audio", audioMuted);
2418
+ this.events.onMuteStateChanged?.(participantId, "video", videoMuted);
2419
+ return;
2420
+ }
2310
2421
  const participant = this.state.getParticipant(participantId);
2311
2422
  if (!participant) return;
2312
2423
  this.state.updateParticipantMedia(participantId, {
@@ -2576,6 +2687,30 @@ var VideoSDKCore = class {
2576
2687
  }
2577
2688
  return this.sfuClient.rejectJoinRequest(requestId, reason);
2578
2689
  }
2690
+ async cancelJoinRequest(requestId) {
2691
+ return this.sfuClient?.cancelJoinRequest(requestId);
2692
+ }
2693
+ async muteAllAudio() {
2694
+ if (!this.sfuClient) throw new Error("SFU client is not connected");
2695
+ return this.sfuClient.muteAllAudio();
2696
+ }
2697
+ async unmuteAllAudio() {
2698
+ if (!this.sfuClient) throw new Error("SFU client is not connected");
2699
+ return this.sfuClient.unmuteAllAudio();
2700
+ }
2701
+ async removeParticipant(participantId) {
2702
+ if (!this.sfuClient) throw new Error("SFU client is not connected");
2703
+ return this.sfuClient.removeParticipant(participantId);
2704
+ }
2705
+ async getModerators(roomCode) {
2706
+ return this.sfuClient?.getModerators(roomCode);
2707
+ }
2708
+ async addModerator(roomCode, userId) {
2709
+ return this.sfuClient?.addModerator(roomCode, userId);
2710
+ }
2711
+ async removeModerator(roomCode, userId) {
2712
+ return this.sfuClient?.removeModerator(roomCode, userId);
2713
+ }
2579
2714
  // MEDIA CONTROL
2580
2715
  toggleMic() {
2581
2716
  const mediaState = this.state.localParticipant?.media;
@@ -2883,10 +3018,6 @@ var MeetingProvider = ({
2883
3018
  }
2884
3019
  };
2885
3020
  console.log("[MeetingProvider] PUBSUB REACTION", message);
2886
- pubSubListeners.current.get("REACTION")?.forEach((fn) => {
2887
- console.log("[MeetingProvider] DELIVERING REACTION");
2888
- fn(message);
2889
- });
2890
3021
  setReactionPubSubMessages(
2891
3022
  (previous) => [...previous, message].slice(-50)
2892
3023
  );
@@ -3001,6 +3132,13 @@ var MeetingProvider = ({
3001
3132
  },
3002
3133
  approveJoinRequest: sdk.approveJoinRequest.bind(sdk),
3003
3134
  rejectJoinRequest: sdk.rejectJoinRequest.bind(sdk),
3135
+ cancelJoinRequest: sdk.cancelJoinRequest.bind(sdk),
3136
+ muteAllAudio: sdk.muteAllAudio.bind(sdk),
3137
+ unmuteAllAudio: sdk.unmuteAllAudio.bind(sdk),
3138
+ removeParticipant: sdk.removeParticipant.bind(sdk),
3139
+ getModerators: sdk.getModerators.bind(sdk),
3140
+ addModerator: sdk.addModerator.bind(sdk),
3141
+ removeModerator: sdk.removeModerator.bind(sdk),
3004
3142
  startRecording: sdk.startRecording.bind(sdk),
3005
3143
  stopRecording: sdk.stopRecording.bind(sdk),
3006
3144
  getRecordingStatus: sdk.getRecordingStatus.bind(sdk),