2017-09-01 21:03:28 +02:00
|
|
|
const createParentStream = require('iframe-stream').ParentStream
|
2017-04-03 07:01:44 +02:00
|
|
|
const SWcontroller = require('client-sw-ready-event/lib/sw-client.js')
|
2017-03-29 03:02:08 +02:00
|
|
|
const SwStream = require('sw-stream/lib/sw-stream.js')
|
2017-04-03 07:01:44 +02:00
|
|
|
|
2017-10-05 08:03:47 +02:00
|
|
|
const intervalDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000
|
2017-03-29 03:02:08 +02:00
|
|
|
const background = new SWcontroller({
|
2017-04-05 07:45:39 +02:00
|
|
|
fileName: '/background.js',
|
2017-04-06 18:56:13 +02:00
|
|
|
letBeIdle: false,
|
2017-04-06 21:57:02 +02:00
|
|
|
wakeUpInterval: 30000,
|
2017-04-06 18:56:13 +02:00
|
|
|
intervalDelay,
|
2017-03-29 03:02:08 +02:00
|
|
|
})
|
2017-04-06 18:58:41 +02:00
|
|
|
|
2017-09-01 21:03:28 +02:00
|
|
|
const pageStream = createParentStream()
|
2017-09-15 22:13:13 +02:00
|
|
|
background.on('ready', () => {
|
2017-10-05 08:03:47 +02:00
|
|
|
const swStream = SwStream({
|
2017-03-30 00:19:46 +02:00
|
|
|
serviceWorker: background.controller,
|
|
|
|
context: 'dapp',
|
|
|
|
})
|
2017-03-29 03:02:08 +02:00
|
|
|
pageStream.pipe(swStream).pipe(pageStream)
|
2017-03-30 20:28:22 +02:00
|
|
|
|
2017-03-29 03:02:08 +02:00
|
|
|
})
|
2017-04-28 14:05:10 +02:00
|
|
|
background.on('updatefound', () => window.location.reload())
|
2017-03-29 03:02:08 +02:00
|
|
|
|
|
|
|
background.on('error', console.error)
|
|
|
|
background.startWorker()
|