react-broadcast-sync 1.2.1 → 1.4.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.
@@ -70,6 +70,11 @@ export interface ClearSentMessagesOptions extends ClearOptions {
70
70
  sync?: boolean;
71
71
  }
72
72
 
73
+ export interface GetLatestMessageOptions {
74
+ source?: string;
75
+ type?: string;
76
+ }
77
+
73
78
  /**
74
79
  * Actions and state provided by the broadcast channel hook
75
80
  */
@@ -83,6 +88,12 @@ export interface BroadcastActions {
83
88
  /** Array of sent messages */
84
89
  sentMessages: BroadcastMessage[];
85
90
 
91
+ /** Whether a ping operation is currently in progress */
92
+ isPingInProgress: boolean;
93
+
94
+ /** Function to ping the channel and get active sources */
95
+ ping: (timeoutMs?: number) => Promise<string[]>;
96
+
86
97
  /** Function to send a message */
87
98
  postMessage: (messageType: string, messageContent: any, options?: SendMessageOptions) => void;
88
99
 
@@ -92,8 +103,16 @@ export interface BroadcastActions {
92
103
  /** Function to clear sent messages */
93
104
  clearSentMessages: (options?: ClearSentMessagesOptions) => void;
94
105
 
106
+ /** Function to get the latest message by source and type */
107
+ getLatestMessage: (options?: GetLatestMessageOptions) => BroadcastMessage | null;
108
+
109
+ /** Explicitly close the broadcast channel and remove listeners */
110
+ closeChannel: () => void;
111
+
95
112
  /** Current error state */
96
113
  error: string | null;
97
114
  }
98
115
 
99
116
  export type ClearMessage = 'CLEAR_SENT_MESSAGES';
117
+
118
+ export type InternalMessage = ClearMessage | 'PING' | 'PONG';
@@ -40,6 +40,11 @@ export const debug = {
40
40
  duplicate: (messageId: string) => log('warn', 'Duplicate message ignored:', messageId),
41
41
  allSentCleared: () => log('info', 'All sent messages cleared'),
42
42
  allReceivedCleared: () => log('info', 'All received messages cleared'),
43
+ ignored: (messageType: string) =>
44
+ log('info', 'Message ignored due to type filter:', messageType),
45
+ },
46
+ ping: {
47
+ inProgress: () => log('warn', 'Ping already in progress. Skipping call.'),
43
48
  },
44
49
  cleanup: {
45
50
  started: () => log('info', 'Cleanup started'),
@@ -1,4 +1,4 @@
1
- import { ClearMessage } from '../types/types';
1
+ import { InternalMessage } from '../types/types';
2
2
 
3
3
  const INTERNAL_PREFIX = '__INTERNAL__';
4
4
  const SECRET = 'react-broadcast-sync';
@@ -46,7 +46,7 @@ export const createMessage = (
46
46
  };
47
47
 
48
48
  export const getInternalMessageType = (
49
- baseType: ClearMessage,
49
+ baseType: InternalMessage,
50
50
  channelName: string,
51
51
  namespace = ''
52
52
  ): string => {