Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 813 Bytes

README.md

File metadata and controls

30 lines (21 loc) · 813 Bytes

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) => {
  // ...
})