@defcomm/meetingsdk 0.6.1 → 0.6.3

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
@@ -286,6 +286,7 @@ var MeetingState = class {
286
286
  name: patch.name ?? "",
287
287
  isHost: patch.isHost ?? false,
288
288
  isModerator: patch.isModerator ?? false,
289
+ handRaised: patch.handRaised ?? false,
289
290
  permissions: patch.permissions,
290
291
  media: {
291
292
  stream: patch.media?.stream ?? null,
@@ -333,6 +334,21 @@ var MeetingState = class {
333
334
  };
334
335
  this.notify("localParticipant");
335
336
  }
337
+ setParticipantHandRaised(id, raised) {
338
+ const p = id === this.localParticipant?.id ? this.localParticipant : this.participants.get(id);
339
+ if (!p || p.handRaised === raised) return;
340
+ const updated = { ...p, handRaised: raised };
341
+ if (id === this.localParticipant?.id) {
342
+ this.localParticipant = updated;
343
+ this.notify("localParticipant");
344
+ } else {
345
+ const next = new Map(this.participants);
346
+ next.set(id, updated);
347
+ this.participants = next;
348
+ this.notify(`participant:${id}`);
349
+ this.notify("participants");
350
+ }
351
+ }
336
352
  // ---- chat ----
337
353
  addChatMessage(msg) {
338
354
  this.chatMessages.set(msg.id, msg);
@@ -481,6 +497,8 @@ var SFUClient = class {
481
497
  });
482
498
  this.onReaction = options.onReaction || (() => {
483
499
  });
500
+ this.onHandRaised = options.onHandRaised || (() => {
501
+ });
484
502
  this.onRoomUpdate = options.onRoomUpdate || (() => {
485
503
  });
486
504
  this.onNetworkQuality = options.onNetworkQuality || (() => {
@@ -1079,6 +1097,12 @@ var SFUClient = class {
1079
1097
  if (reaction?.id && reaction?.emoji) this.onReaction(reaction);
1080
1098
  break;
1081
1099
  }
1100
+ case "hand_raised": {
1101
+ const participantId = String(payload.participant_id ?? payload.participantId ?? "");
1102
+ const raised = Boolean(payload.raised);
1103
+ if (participantId) this.onHandRaised(participantId, raised);
1104
+ break;
1105
+ }
1082
1106
  case "network_quality": {
1083
1107
  const raw = payload.quality || payload;
1084
1108
  const quality = {
@@ -2004,6 +2028,14 @@ var SFUClient = class {
2004
2028
  }
2005
2029
  });
2006
2030
  }
2031
+ setHandRaised(raised) {
2032
+ this.send({
2033
+ type: "set_hand_raised",
2034
+ payload: {
2035
+ raised
2036
+ }
2037
+ });
2038
+ }
2007
2039
  removeRemoteParticipant(participantId) {
2008
2040
  const stream = this.remoteStreams.get(participantId);
2009
2041
  if (stream) {
@@ -2438,6 +2470,7 @@ var VideoSDKCore = class {
2438
2470
  isHost,
2439
2471
  isModerator,
2440
2472
  permissions,
2473
+ handRaised: Boolean(local?.hand_raised),
2441
2474
  media: {
2442
2475
  micEnabled: !Boolean(local?.audio_muted),
2443
2476
  camEnabled: !Boolean(local?.video_muted)
@@ -2465,6 +2498,7 @@ var VideoSDKCore = class {
2465
2498
  this.state.updateLocalParticipant({
2466
2499
  id: this.myId,
2467
2500
  name: this.participantName,
2501
+ handRaised: Boolean(local.hand_raised),
2468
2502
  media: {
2469
2503
  micEnabled: !Boolean(local.audio_muted),
2470
2504
  camEnabled: !Boolean(local.video_muted),
@@ -2543,6 +2577,10 @@ var VideoSDKCore = class {
2543
2577
  onReaction: (reaction) => {
2544
2578
  this.events.onReaction?.(reaction);
2545
2579
  },
2580
+ onHandRaised: (participantId, raised) => {
2581
+ this.state.setParticipantHandRaised(participantId, raised);
2582
+ this.events.onHandRaised?.(participantId, raised);
2583
+ },
2546
2584
  onJoinRequestCanceled: (requestId) => {
2547
2585
  this.events.onJoinRequestCanceled?.(requestId);
2548
2586
  },
@@ -2568,6 +2606,7 @@ var VideoSDKCore = class {
2568
2606
  id: this.myId,
2569
2607
  name: this.participantName,
2570
2608
  isHost: current?.isHost,
2609
+ handRaised: current?.handRaised,
2571
2610
  isModerator: Boolean(permissions?.moderate),
2572
2611
  permissions
2573
2612
  });
@@ -2597,6 +2636,7 @@ var VideoSDKCore = class {
2597
2636
  id: pid,
2598
2637
  name: pname,
2599
2638
  isModerator: Boolean(participant?.permissions?.moderate),
2639
+ handRaised: Boolean(participant?.hand_raised),
2600
2640
  permissions: participant?.permissions,
2601
2641
  connectionState: "connected",
2602
2642
  media: {
@@ -2606,10 +2646,12 @@ var VideoSDKCore = class {
2606
2646
  stream: null
2607
2647
  }
2608
2648
  });
2609
- this.events.onUserJoined?.({
2649
+ const joinedParticipant = this.state.getParticipant(pid) ?? {
2610
2650
  id: pid,
2611
2651
  name: pname
2612
- });
2652
+ };
2653
+ this.events.onUserJoined?.(joinedParticipant);
2654
+ this.events.onParticipantJoined?.(joinedParticipant);
2613
2655
  },
2614
2656
  onParticipantPresence: (participantId, presence) => {
2615
2657
  if (participantId === this.myId) {
@@ -2638,9 +2680,11 @@ var VideoSDKCore = class {
2638
2680
  return;
2639
2681
  }
2640
2682
  console.log("[SFU] Participant permanently left", pid);
2683
+ const leavingParticipant = this.state.getParticipant(pid) ?? { id: pid };
2641
2684
  this.cleanupRemoteParticipant(pid);
2642
2685
  this.state.removeParticipant(pid);
2643
2686
  this.events.onUserLeft?.(pid);
2687
+ this.events.onParticipantLeft?.(leavingParticipant);
2644
2688
  },
2645
2689
  // TRACKS
2646
2690
  onParticipantMediaState: (participantId, audioMuted, videoMuted) => {
@@ -3110,6 +3154,16 @@ var VideoSDKCore = class {
3110
3154
  }
3111
3155
  this.sfuClient.sendReaction(reaction);
3112
3156
  }
3157
+ setHandRaised(raised) {
3158
+ if (!this.sfuClient) {
3159
+ console.warn("SFU Client not connected");
3160
+ return;
3161
+ }
3162
+ this.sfuClient.setHandRaised(raised);
3163
+ }
3164
+ toggleHandRaised() {
3165
+ this.setHandRaised(!Boolean(this.state.localParticipant?.handRaised));
3166
+ }
3113
3167
  /**
3114
3168
  * Generic PubSub publishing entry point.
3115
3169
  *
@@ -3230,6 +3284,9 @@ var MeetingProvider = ({
3230
3284
  const recordingStartedListeners = useRef(/* @__PURE__ */ new Set());
3231
3285
  const recordingStoppedListeners = useRef(/* @__PURE__ */ new Set());
3232
3286
  const reactionListeners = useRef(/* @__PURE__ */ new Set());
3287
+ const handRaisedListeners = useRef(
3288
+ /* @__PURE__ */ new Set()
3289
+ );
3233
3290
  const pubSubListeners = useRef(
3234
3291
  /* @__PURE__ */ new Map()
3235
3292
  );
@@ -3243,6 +3300,15 @@ var MeetingProvider = ({
3243
3300
  const connectionStateListeners = useRef(
3244
3301
  /* @__PURE__ */ new Set()
3245
3302
  );
3303
+ const participantJoinedListeners = useRef(
3304
+ /* @__PURE__ */ new Set()
3305
+ );
3306
+ const participantLeftListeners = useRef(
3307
+ /* @__PURE__ */ new Set()
3308
+ );
3309
+ const chatMessageListeners = useRef(
3310
+ /* @__PURE__ */ new Set()
3311
+ );
3246
3312
  if (!sdkRef.current) {
3247
3313
  sdkRef.current = new VideoSDKCore(
3248
3314
  {
@@ -3303,6 +3369,7 @@ var MeetingProvider = ({
3303
3369
  data: msg
3304
3370
  };
3305
3371
  pubSubListeners.current.get("SECURE_CHAT")?.forEach((fn) => fn(pubSubMessage));
3372
+ chatMessageListeners.current.forEach((fn) => fn(msg));
3306
3373
  },
3307
3374
  onReaction: (reaction) => {
3308
3375
  reactionListeners.current.forEach((fn) => fn(reaction));
@@ -3323,6 +3390,9 @@ var MeetingProvider = ({
3323
3390
  );
3324
3391
  pubSubListeners.current.get("REACTION")?.forEach((fn) => fn(message));
3325
3392
  },
3393
+ onHandRaised: (participantId, raised) => {
3394
+ handRaisedListeners.current.forEach((fn) => fn(participantId, raised));
3395
+ },
3326
3396
  onNetworkQuality: (quality) => {
3327
3397
  networkQualityListeners.current.forEach((fn) => fn(quality));
3328
3398
  },
@@ -3330,6 +3400,12 @@ var MeetingProvider = ({
3330
3400
  connectionStateListeners.current.forEach(
3331
3401
  (fn) => fn(state)
3332
3402
  );
3403
+ },
3404
+ onParticipantJoined: (participant) => {
3405
+ participantJoinedListeners.current.forEach((fn) => fn(participant));
3406
+ },
3407
+ onParticipantLeft: (participant) => {
3408
+ participantLeftListeners.current.forEach((fn) => fn(participant));
3333
3409
  }
3334
3410
  }
3335
3411
  );
@@ -3389,6 +3465,8 @@ var MeetingProvider = ({
3389
3465
  stopScreenShare: sdk.stopScreenShare.bind(sdk),
3390
3466
  sendMessage: sdk.sendChatMessage.bind(sdk),
3391
3467
  sendReaction: sdk.sendReaction.bind(sdk),
3468
+ setHandRaised: sdk.setHandRaised.bind(sdk),
3469
+ toggleHandRaised: sdk.toggleHandRaised.bind(sdk),
3392
3470
  room: sdk.getMeeting(),
3393
3471
  localParticipant,
3394
3472
  participants,
@@ -3514,6 +3592,10 @@ var MeetingProvider = ({
3514
3592
  reactionListeners.current.add(cb);
3515
3593
  return () => reactionListeners.current.delete(cb);
3516
3594
  },
3595
+ onHandRaised: (cb) => {
3596
+ handRaisedListeners.current.add(cb);
3597
+ return () => handRaisedListeners.current.delete(cb);
3598
+ },
3517
3599
  onNetworkQuality: (cb) => {
3518
3600
  networkQualityListeners.current.add(cb);
3519
3601
  return () => networkQualityListeners.current.delete(cb);
@@ -3529,6 +3611,18 @@ var MeetingProvider = ({
3529
3611
  return () => {
3530
3612
  activeSpeakerListeners.current.delete(cb);
3531
3613
  };
3614
+ },
3615
+ onParticipantJoined: (cb) => {
3616
+ participantJoinedListeners.current.add(cb);
3617
+ return () => participantJoinedListeners.current.delete(cb);
3618
+ },
3619
+ onChatMessage: (cb) => {
3620
+ chatMessageListeners.current.add(cb);
3621
+ return () => chatMessageListeners.current.delete(cb);
3622
+ },
3623
+ onParticipantLeft: (cb) => {
3624
+ participantLeftListeners.current.add(cb);
3625
+ return () => participantLeftListeners.current.delete(cb);
3532
3626
  }
3533
3627
  };
3534
3628
  }, [
@@ -3653,10 +3747,26 @@ var useMeeting = (handlers) => {
3653
3747
  if (!handlers?.onNetworkQuality) return;
3654
3748
  return ctx.onNetworkQuality(handlers.onNetworkQuality);
3655
3749
  }, [handlers?.onNetworkQuality]);
3750
+ useEffect3(() => {
3751
+ if (!handlers?.onParticipantJoined) return;
3752
+ return ctx.onParticipantJoined(handlers.onParticipantJoined);
3753
+ }, [handlers?.onParticipantJoined]);
3754
+ useEffect3(() => {
3755
+ if (!handlers?.onParticipantLeft) return;
3756
+ return ctx.onParticipantLeft(handlers.onParticipantLeft);
3757
+ }, [handlers?.onParticipantLeft]);
3758
+ useEffect3(() => {
3759
+ if (!handlers?.onChatMessage) return;
3760
+ return ctx.onChatMessage(handlers.onChatMessage);
3761
+ }, [handlers?.onChatMessage]);
3656
3762
  useEffect3(() => {
3657
3763
  if (!handlers?.onReaction) return;
3658
3764
  return ctx.onReaction(handlers.onReaction);
3659
3765
  }, [handlers?.onReaction]);
3766
+ useEffect3(() => {
3767
+ if (!handlers?.onHandRaised) return;
3768
+ return ctx.onHandRaised(handlers.onHandRaised);
3769
+ }, [handlers?.onHandRaised]);
3660
3770
  const { sdk: _, ...publicApi } = ctx;
3661
3771
  return publicApi;
3662
3772
  };