1 const http
= require('http');
2 const ws
= require('ws');
6 * this allows triggering runtime
7 * reloads when webpack's HMR server emits new data
9 const createReloadRuntimeServer
= ({ port
}) => {
10 const httpServer
= http
.createServer({});
12 console
.info('[ProtonPassExtensionReloader] - Setting runtime reloader server');
14 const server
= new ws
.Server({ server
: httpServer
, pingTimeout
: 10000 });
15 server
.on('pong', noop
);
17 const reloadClients
= () => {
18 console
.info('[ProtonPassExtensionReloader] - Reloading clients..');
19 server
.clients
.forEach((client
) => {
20 client
.send(JSON
.stringify({ reload
: true }));
24 process
.on('beforeExit', () => server
.close());
25 httpServer
.listen(port
);
27 return { reload
: reloadClients
};
30 module
.exports
= createReloadRuntimeServer
;