Merge branch 'INDA-330-pii-update' into 'main'
[ProtonMail-WebClient.git] / applications / pass-extension / tools / reload-runtime.js
blob6173bf486b7194ebcd65296b6d3b038c83a84ca0
1 const http = require('http');
2 const ws = require('ws');
3 const noop = () => {};
5 /**
6 * this allows triggering runtime
7 * reloads when webpack's HMR server emits new data
8 */
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 }));
21 });
24 process.on('beforeExit', () => server.close());
25 httpServer.listen(port);
27 return { reload: reloadClients };
30 module.exports = createReloadRuntimeServer;