summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/lib/broadcast/mapChannel.ts
diff options
context:
space:
mode:
authorsai-neetha <sai-neetha.phulmali@highstreet-technologies.com>2023-07-07 18:11:09 +0200
committersai-neetha <sai-neetha.phulmali@highstreet-technologies.com>2023-07-07 18:12:17 +0200
commitfad3167f42d585e3144547db4c6dd7d00ea7b18a (patch)
treed6578fd008c717748e6110c2072bbe65fcb91e2e /sdnr/wt/odlux/lib/broadcast/mapChannel.ts
parent8efd8356d7ea705e282a72aeb74d4199cdf21851 (diff)
Update ODLUX
node version yarn version update Issue-ID: CCSDK-3923 Signed-off-by: sai-neetha <sai-neetha.phulmali@highstreet-technologies.com> Change-Id: Ibd3d6a6f45a14be4f1d175cf6fc5c8738aa11dea
Diffstat (limited to 'sdnr/wt/odlux/lib/broadcast/mapChannel.ts')
-rw-r--r--sdnr/wt/odlux/lib/broadcast/mapChannel.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/sdnr/wt/odlux/lib/broadcast/mapChannel.ts b/sdnr/wt/odlux/lib/broadcast/mapChannel.ts
new file mode 100644
index 000000000..efd76eb8c
--- /dev/null
+++ b/sdnr/wt/odlux/lib/broadcast/mapChannel.ts
@@ -0,0 +1,29 @@
+
+const channel: BroadcastChannel = new BroadcastChannel("odlux_map");
+const listeners: { [key: string]: ((data: any) => void)[] } = {};
+
+channel.onmessage = (eventMessage: MessageEvent<any>) => {
+ const { key, data } = eventMessage.data;
+ if (listeners[key]) {
+ listeners[key].forEach(listener => listener(data));
+ }
+};
+
+export const sendMapMessage = (data: any, key: string) => {
+ channel.postMessage({ key, data });
+};
+
+export const addMapMessageListener = (key: string, listener: (data: any) => void) => {
+ if (!listeners[key]) {
+ listeners[key] = [];
+ }
+
+ if (!listeners[key].find(l => l === listener)) {
+ listeners[key].push(listener);
+ }
+
+ return () => {
+ listeners[key] = listeners[key].filter(l => l !== listener);
+ }
+};
+