diff options
author | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2023-12-07 22:45:28 +0530 |
---|---|---|
committer | Ravi Pendurty <ravi.pendurty@highstreet-technologies.com> | 2023-12-07 22:46:39 +0530 |
commit | dfd91573b7567e1dab482f17111ab8f809553d99 (patch) | |
tree | 8368580d1b1add9cfef5e8354ccf1080f27109b0 /sdnr/wt-odlux/odlux/lib | |
parent | bf8d701f85d02a140a1290d288adc7f437c1cc90 (diff) |
Create wt-odlux directory
Include odlux apps, helpserver and readthedocs
Issue-ID: CCSDK-3970
Change-Id: I1aee1327e7da12e8f658185b9a985a5204ad6065
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt-odlux/odlux/lib')
-rw-r--r-- | sdnr/wt-odlux/odlux/lib/broadcast/mapChannel.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/sdnr/wt-odlux/odlux/lib/broadcast/mapChannel.ts b/sdnr/wt-odlux/odlux/lib/broadcast/mapChannel.ts new file mode 100644 index 000000000..efd76eb8c --- /dev/null +++ b/sdnr/wt-odlux/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); + } +}; + |