Skip to content

Commit 5fb7d70

Browse files
committed
feat: Added connection start time and connection termination
1 parent f48c6ef commit 5fb7d70

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/connect/socket-server.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class SocketServer {
2525

2626
private server: HttpServer;
2727
private connectionSecret: string;
28+
private startTimestamp = new Date();
2829
private mainConnections = new Map<string, WebSocket>(); // These are per webpage
2930
private sessions = new Map<string, Session>();
3031

@@ -124,7 +125,14 @@ export class SocketServer {
124125
private handleClientConnected = (ws: WebSocket) => {
125126
const clientId = uuid();
126127
this.mainConnections.set(clientId, ws);
127-
ws.send(JSON.stringify({ key: 'opened', data: { clientId } }))
128+
ws.send(JSON.stringify({ key: 'opened', data: { clientId, startTimestamp: this.startTimestamp.toISOString() } }));
129+
130+
ws.on('message', (message) => {
131+
const data = JSON.parse(message.toString('utf8'));
132+
if (data.key === 'terminate') {
133+
process.exit(0);
134+
}
135+
});
128136

129137
ws.on('close', () => {
130138
this.mainConnections.delete(clientId);

0 commit comments

Comments
 (0)