ump-plugin-broadcast-channel
v0.0.1
Published
UMP BroadcastChannel Plugin — single-realm WHATWG BroadcastChannel polyfill
Readme
ump-plugin-broadcast-channel
Single-realm WHATWG BroadcastChannel polyfill for UMP apps.
Install
npm install ump-plugin-broadcast-channelPeer dependencies (must already be installed in your app):
ump-coreump-native
Usage
import { BroadcastChannel } from 'ump-plugin-broadcast-channel';
const a = new BroadcastChannel('room-1');
const b = new BroadcastChannel('room-1');
b.onmessage = (ev) => {
console.log('got:', ev.data);
};
a.postMessage({ hello: 'world' });
// cleanup
a.close();
b.close();Importing the module also installs globalThis.BroadcastChannel (only when
the host has not already provided one), so libraries that reach for the
bare global name (idb-keyval, tab-sync helpers, etc.) work without
explicit import.
Scope
This is the same-realm shim used inside ump-native. Two channels with
the same name running in the same JS realm exchange messages; cross-tab,
cross-iframe, or cross-process delivery is not implemented because
native UMP runs in a single JSEngine. Each Worker is its own realm with
its own registry — use the worker handle's postMessage / onmessage
for thread-to-thread comms.
On H5, the browser's built-in BroadcastChannel wins (full cross-tab
semantics).
Migration from ump-native
In ump-native 0.1.x, BroadcastChannel was bundled with the main package
as a side-effect global. Starting 0.2.x, it ships as this separate plugin.
- import 'ump-native'; // side-effect: globalThis.BroadcastChannel installed
+ import { BroadcastChannel } from 'ump-plugin-broadcast-channel';No API changes. Importing the plugin still installs the global as a side-effect (non-overwriting), so existing call-sites that use the bare global name continue to work.
