MessageChannelAdapter
is a small utility function that turns string-based
communication channels – like a WebSocket, RTCDataChannel or
PresentationConnection – into a Comlink-compatible postMessage
-based API
that can transfer MessagePorts
.
See the examples, specifically WebRTC and Presentation API.
wrap
returns a MessagePort
that serializes messages using JSON.stringify
and handles transferred MessagePort
s automatically. endpoint
is expected to
have send
and addEventListener
.