You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
729 B
25 lines
729 B
const createParentStream = require('iframe-stream').ParentStream
|
|
const SwController = require('sw-controller')
|
|
const SwStream = require('sw-stream/lib/sw-stream.js')
|
|
|
|
const keepAliveDelay = Math.floor(Math.random() * (30000 - 1000)) + 1000
|
|
const background = new SwController({
|
|
fileName: './scripts/background.js',
|
|
keepAlive: true,
|
|
keepAliveInterval: 30000,
|
|
keepAliveDelay,
|
|
})
|
|
|
|
const pageStream = createParentStream()
|
|
background.on('ready', () => {
|
|
const swStream = SwStream({
|
|
serviceWorker: background.controller,
|
|
context: 'dapp',
|
|
})
|
|
pageStream.pipe(swStream).pipe(pageStream)
|
|
|
|
})
|
|
background.on('updatefound', () => window.location.reload())
|
|
|
|
background.on('error', console.error)
|
|
background.startWorker()
|
|
|