Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,34 @@ if (process.env.ARRPC_BRIDGE_PORT) {
throw new Error('invalid port');
}
}
if (process.env.LISTEN_FDS) { // Socket activation
const fds = parseInt(process.env.LISTEN_FDS);
if (fds !== 1) {
throw new Error(`got ${fds} LISTEN_FDS, expecting 1`);
}
port = { fd: 3 };
}
const wss = new WebSocketServer({ port });
let quitTimer;

wss.on('connection', socket => {
log('web connected');
if (quitTimer) {
log('client reconnected, not deactivating')
clearTimeout(quitTimer);
quitTimer = undefined;
}

for (const id in lastMsg) { // catch up newly connected
if (lastMsg[id].activity != null) send(lastMsg[id]);
}

socket.on('close', () => {
log('web disconnected');
if (process.env.LISTEN_FDS && wss.clients.size === 0) {
log('last client disconnected, will deactivate in 30s');
quitTimer = setTimeout(() => process.exit(0), 30000);
}
});
});

Expand Down