- From: Jake Archibald <notifications@github.com>
- Date: Wed, 16 Aug 2017 11:50:02 -0700
- To: w3c/ServiceWorker <ServiceWorker@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Wednesday, 16 August 2017 18:50:26 UTC
If we added multiple instances today, you could still ensure you were conversing with a specific service worker by either passing a message port with the initial message:
```js
// In the service worker:
const channel = new MessageChannel();
client.postMessage({useThisForReplies: channel.port2}, [channel.port2]);
// In the page:
navigator.serviceWorker.onmessage = event => {
if (event.data.useThisForReplies) {
event.data.useThisForReplies.postMessage(…);
}
};
```
Alternatively `useThisForReplies` could be a random broadcast channel ID.
(this doesn't mean we shouldn't do one of the things @wanderview suggests above, it just hadn't previously occurred to me that there are kinda solutions already)
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1185#issuecomment-322864908
Received on Wednesday, 16 August 2017 18:50:26 UTC