2017-09-01 21:03:28 +02:00
|
|
|
const createParentStream = require('iframe-stream').ParentStream
|
2018-03-29 06:33:04 +02:00
|
|
|
const SwController = require('sw-controller')
|
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
|
|
|
|
2018-03-29 06:33:04 +02:00
|
|
|
const keepAliveDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000
|
|
|
|
const background = new SwController({
|
2018-03-28 23:06:59 +02:00
|
|
|
fileName: './scripts/background.js',
|
2018-03-29 06:33:04 +02:00
|
|
|
keepAlive: true,
|
|
|
|
keepAliveInterval: 30000,
|
|
|
|
keepAliveDelay,
|
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()
|