2.0.2 • Published 8 years ago
sw-stream v2.0.2
ServiceWorkerStream and ServiceWorkerGlobalListener
This a utility for creating streams between the page and a servive worker.
usage
in page
pass the registered service worker to create a duplex stream.
const duplex = SwStream({ serviceWorker: this.serviceWorker.controller })There is an optional context property that will be passed along on the initial handshake and
retreivable from the messageEvent.data.context received from the SwGlobalListener.
const duplex = SwStream({ serviceWorker, context })in ServiceWorker
listen for client connections
const connectionListener = new SwGlobalListener(self)
connectionListener.on('remote', (portStream, messageEvent) => {
// ...
})