add webworker workaround to readme

This commit is contained in:
Toshit Chawda 2024-07-09 11:29:51 -07:00
parent cb443135d9
commit 8015428b45
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D

View file

@ -55,3 +55,12 @@ const resp = await client.fetch("https://example.com");
// Create websocket
const ws = client.createWebSocket("wss://echo.websocket.events");
```
## WebWorker support
Due to limitations in browsers, there is no way for bare-mux to get a connection to the bare-mux SharedWorker while inside a WebWorker. Proxies that use bare-mux must manually pass in a MessagePort to the SharedWorker to be able to use BareClient in a WebWorker.
```js
const connection = new BareMuxConnection();
const port = await connection.getInnerPort();
// ... transfer it to worker ...
const client = new BareClient(port);
```