@defcomm/meetingsdk 0.4.4 → 0.4.5

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
@@ -1,8 +1,8 @@
1
1
  // src/react/useLocalParticipant.tsx
2
- import { useCallback, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
2
+ import { useCallback, useEffect as useEffect2, useRef as useRef2, useState as useState3 } from "react";
3
3
 
4
4
  // src/react/MeetingProvider.tsx
5
- import { createContext, useContext, useMemo, useRef } from "react";
5
+ import { createContext, useContext, useMemo, useRef, useState as useState2 } from "react";
6
6
 
7
7
  // src/config/ws.ts
8
8
  var SDK_CONFIG = {
@@ -2703,6 +2703,28 @@ var VideoSDKCore = class {
2703
2703
  }
2704
2704
  this.sfuClient.sendReaction(reaction);
2705
2705
  }
2706
+ /**
2707
+ * Generic PubSub publishing entry point.
2708
+ *
2709
+ * The public SDK exposes one PubSub API for all topics. The current SFU
2710
+ * protocol still has dedicated wire messages for chat and reactions, so
2711
+ * this method is the compatibility bridge. The application does not need
2712
+ * to know about those wire-level message types.
2713
+ */
2714
+ publishPubSub(topic, data) {
2715
+ switch (topic) {
2716
+ case "SECURE_CHAT":
2717
+ this.sendChatMessage(data);
2718
+ return;
2719
+ case "REACTION":
2720
+ this.sendReaction(data.emoji);
2721
+ return;
2722
+ default: {
2723
+ const exhaustive = topic;
2724
+ throw new Error(`Unsupported PubSub topic: ${exhaustive}`);
2725
+ }
2726
+ }
2727
+ }
2706
2728
  // CLEANUP
2707
2729
  cleanupRemoteParticipant(participantId) {
2708
2730
  this.activeSpeakerDetector.removeParticipant(participantId);
@@ -2793,6 +2815,7 @@ var MeetingProvider = ({
2793
2815
  const pubSubListeners = useRef(
2794
2816
  /* @__PURE__ */ new Map()
2795
2817
  );
2818
+ const [reactionPubSubMessages, setReactionPubSubMessages] = useState2([]);
2796
2819
  const activeSpeakerListeners = useRef(
2797
2820
  /* @__PURE__ */ new Set()
2798
2821
  );
@@ -2826,21 +2849,43 @@ var MeetingProvider = ({
2826
2849
  onRecordingStopped: (recording2) => {
2827
2850
  recordingStoppedListeners.current.forEach((fn) => fn(recording2));
2828
2851
  },
2852
+ onChatMessage: (message) => {
2853
+ const msg = {
2854
+ id: message.id,
2855
+ text: message.text,
2856
+ sender_id: message.sender_id,
2857
+ sender_name: message.sender_name,
2858
+ timestamp: Number(message.timestamp),
2859
+ reply_to: message.reply_to ?? null,
2860
+ target: message.target ?? null
2861
+ };
2862
+ const pubSubMessage = {
2863
+ id: msg.id,
2864
+ topic: "SECURE_CHAT",
2865
+ sender_id: msg.sender_id,
2866
+ sender_name: msg.sender_name,
2867
+ timestamp: msg.timestamp,
2868
+ data: msg
2869
+ };
2870
+ pubSubListeners.current.get("SECURE_CHAT")?.forEach((fn) => fn(pubSubMessage));
2871
+ },
2829
2872
  onReaction: (reaction) => {
2830
2873
  reactionListeners.current.forEach((fn) => fn(reaction));
2831
- const listeners = pubSubListeners.current.get("REACTION");
2832
- if (!listeners) return;
2874
+ const timestamp = typeof reaction.timestamp === "number" ? reaction.timestamp : Date.parse(reaction.timestamp);
2833
2875
  const message = {
2834
2876
  id: reaction.id,
2835
2877
  topic: "REACTION",
2836
2878
  sender_id: reaction.participant_id,
2837
2879
  sender_name: reaction.sender_name,
2838
- timestamp: typeof reaction.timestamp === "number" ? reaction.timestamp : Date.parse(reaction.timestamp),
2880
+ timestamp,
2839
2881
  data: {
2840
2882
  emoji: reaction.emoji
2841
2883
  }
2842
2884
  };
2843
- listeners.forEach((fn) => fn(message));
2885
+ setReactionPubSubMessages(
2886
+ (previous) => [...previous, message].slice(-50)
2887
+ );
2888
+ pubSubListeners.current.get("REACTION")?.forEach((fn) => fn(message));
2844
2889
  },
2845
2890
  onConnectionStateChanged: (state) => {
2846
2891
  connectionStateListeners.current.forEach(
@@ -2903,32 +2948,32 @@ var MeetingProvider = ({
2903
2948
  activeSpeakerIds,
2904
2949
  recording,
2905
2950
  usePubSub: (topic) => {
2951
+ if (topic === "SECURE_CHAT") {
2952
+ const chatMessages = messages.map((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
+ return {
2961
+ messages: chatMessages,
2962
+ publish: ((data) => {
2963
+ sdk.publishPubSub("SECURE_CHAT", data);
2964
+ })
2965
+ };
2966
+ }
2906
2967
  if (topic === "REACTION") {
2907
2968
  return {
2908
- messages: [],
2909
- publish: (data) => {
2910
- const reaction = data;
2911
- if (!reaction?.emoji) {
2969
+ messages: reactionPubSubMessages,
2970
+ publish: ((data) => {
2971
+ if (!data?.emoji) {
2912
2972
  console.warn("[PubSub] REACTION requires an emoji");
2913
2973
  return;
2914
2974
  }
2915
- sdk.sendReaction(reaction.emoji);
2916
- }
2917
- };
2918
- }
2919
- if (topic === "SECURE_CHAT") {
2920
- return {
2921
- messages: sdk.state.getChatMessages().map((message) => ({
2922
- id: message.id,
2923
- topic: "SECURE_CHAT",
2924
- sender_id: message.sender_id,
2925
- sender_name: message.sender_name,
2926
- timestamp: message.timestamp,
2927
- data: message
2928
- })),
2929
- publish: (data) => {
2930
- sdk.sendChatMessage(data);
2931
- }
2975
+ sdk.publishPubSub("REACTION", data);
2976
+ })
2932
2977
  };
2933
2978
  }
2934
2979
  throw new Error(`Unsupported PubSub topic: "${topic}"`);
@@ -3013,7 +3058,8 @@ var MeetingProvider = ({
3013
3058
  messages,
3014
3059
  presenterId,
3015
3060
  recording,
3016
- activeSpeakerIds
3061
+ activeSpeakerIds,
3062
+ reactionPubSubMessages
3017
3063
  ]);
3018
3064
  return /* @__PURE__ */ jsx(MeetingContext.Provider, { value, children });
3019
3065
  };
@@ -3027,7 +3073,7 @@ var useMeetingContext = () => {
3027
3073
  // src/react/useLocalParticipant.tsx
3028
3074
  var useLocalParticipant = () => {
3029
3075
  const { sdk } = useMeetingContext();
3030
- const [localParticipant, setLocalParticipant] = useState2(
3076
+ const [localParticipant, setLocalParticipant] = useState3(
3031
3077
  () => {
3032
3078
  const current = sdk.state.localParticipant;
3033
3079
  return current && current.id ? current : null;
@@ -3116,10 +3162,10 @@ var useMeeting = (handlers) => {
3116
3162
  };
3117
3163
 
3118
3164
  // src/react/useParticipants.ts
3119
- import { useEffect as useEffect4, useState as useState3 } from "react";
3165
+ import { useEffect as useEffect4, useState as useState4 } from "react";
3120
3166
  var useParticipants = () => {
3121
3167
  const { sdk } = useMeetingContext();
3122
- const [participants, setParticipants] = useState3(
3168
+ const [participants, setParticipants] = useState4(
3123
3169
  () => sdk.state.getParticipants()
3124
3170
  );
3125
3171
  useEffect4(() => {
@@ -3134,12 +3180,12 @@ var useParticipants = () => {
3134
3180
  };
3135
3181
 
3136
3182
  // src/react/useRemoteMedia.ts
3137
- import { useEffect as useEffect5, useRef as useRef3, useState as useState4 } from "react";
3183
+ import { useEffect as useEffect5, useRef as useRef3, useState as useState5 } from "react";
3138
3184
  var useRemoteMedia = (participantId) => {
3139
3185
  const { sdk } = useMeetingContext();
3140
3186
  const videoRef = useRef3(null);
3141
3187
  const audioRef = useRef3(null);
3142
- const [participant, setParticipant] = useState4(
3188
+ const [participant, setParticipant] = useState5(
3143
3189
  () => sdk.state.getParticipant(participantId) || null
3144
3190
  );
3145
3191
  useEffect5(() => {
@@ -3175,12 +3221,12 @@ var useRemoteMedia = (participantId) => {
3175
3221
  };
3176
3222
 
3177
3223
  // src/react/useMeetingPreview.ts
3178
- import { useEffect as useEffect6, useState as useState5 } from "react";
3224
+ import { useEffect as useEffect6, useState as useState6 } from "react";
3179
3225
  function useMeetingPreview(roomId, participantId) {
3180
- const [room, setRoom] = useState5(null);
3181
- const [error, setError] = useState5(null);
3182
- const [isConnected, setIsConnected] = useState5(false);
3183
- const [isLoading, setIsLoading] = useState5(true);
3226
+ const [room, setRoom] = useState6(null);
3227
+ const [error, setError] = useState6(null);
3228
+ const [isConnected, setIsConnected] = useState6(false);
3229
+ const [isLoading, setIsLoading] = useState6(true);
3184
3230
  useEffect6(() => {
3185
3231
  if (!roomId) {
3186
3232
  setIsLoading(false);
@@ -3250,7 +3296,10 @@ function usePubSub(topic, options) {
3250
3296
  const ctx = useMeetingContext();
3251
3297
  useEffect7(() => {
3252
3298
  if (!options?.onMessageReceived) return;
3253
- return ctx.onPubSubMessage(topic, options.onMessageReceived);
3299
+ return ctx.onPubSubMessage(
3300
+ topic,
3301
+ options.onMessageReceived
3302
+ );
3254
3303
  }, [ctx, topic, options?.onMessageReceived]);
3255
3304
  return ctx.usePubSub(topic);
3256
3305
  }