aboutsummaryrefslogtreecommitdiffstats
path: root/mascara/src/proxy.js
blob: 80b4dc516c1b832888f50a72350a57ab862df135 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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()