-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to communicate using postMessage with ServiceWorkers #34
Comments
In order for this to work the var thread = threads.create({
target: myServiceWorker,
type: 'serviceworker'
});
var client = threads.client('render-cache', { thread: thread }); We will also have to make some changes in the |
Perhaps we could streamline the above code example to make it easier for the user. var client = threads.client('render-cache', { target: myServiceWorker }); |
At first glance, this is all do-able 😄 |
Getting a reference to the SW can be like:
Which means that reference can be obtained from a window object, no worker or sharedworkerd can get a reference to the active serviceworker. (As a document has a relation with a SW, since the scope of the serviceworker indicates which documents are handled by each sw). |
While testing integration of ServiceWokers with threads.js as a mechanism to communicate with SW (see: https://github.com/arcturus/sww-render-cache).
We realized that, following the spec, the UA can kill a SW at any moment. Which mean that the broadcast communication channel won't respond to any message (as the server side in the SW has been already killed).
Following the spec, we also see that a SW can be wake up again if we send a postMessage to it, so the communication mechanism that we should have for SW should be postMessage to be sure that the SW will be alive when we perform the communication.
Another point to take into account is that with a postMessage we will relaunch the sw, so if there was already some metadata set up, needed for the communication, some how we will need to reuse it.
The text was updated successfully, but these errors were encountered: