sw-stream

2.0.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i sw-stream

Weekly Downloads

6

Version

2.0.2

License

ISC

Last publish

Collaborators

  • kumavis