One-to-many
The parent opens several popups and fires
broadcast('INCREMENT_COUNTER') once. Every child that registered the procedure runs its handler. The sender does not receive its own broadcast.Children open0
Broadcasts sent0
Open several popups, arrange them so you can see all of them, and click Broadcast. Every child counter ticks up from the same call.
Code
One
broadcast() on the parent, same handler on every child.broadcast.tsx
// Parent
const iwpc = useIwpcWindow();
// Open several children — each registers the same handler.
for (let i = 0; i < 3; i++) {
await iwpc?.open('./child', { width: 480, height: 460 });
}
// One call fires INCREMENT_COUNTER on every other window
// on the same channelName + origin. Fire-and-forget — no return.
iwpc?.broadcast('INCREMENT_COUNTER');
// Child
useEffect(() => {
iwpc?.register('INCREMENT_COUNTER', () => setCount((c) => c + 1));
return () => iwpc?.unregister('INCREMENT_COUNTER');
}, [iwpc]);