Hullo JS
Search…
ofMessagePort
import { ofMessagePort } from '@hullo/browser'
Adapter for MessagePort, a communication endpoint of MessageChannel.
1
import { ofMessagePort } from './ofMessagePort';
2
​
3
const messageChannel = new MessageChannel();
4
​
5
window.open("/").postMessage("mch", "*", [messageChannel.port2]);
6
​
7
// listening setup
8
const port1 = ofMessagePort(messageChannel.port1);
9
port1.subscribe({
10
next(v) {
11
console.log("received", v);
12
}
13
});
14
​
15
// sending setup
16
port1.next({ message: "hello πŸ‘‹" });
Copied!
Copy link