feat(core): Add support for WebSockets as an alternative to Server-Sent Events (#5443)

Co-authored-by: Matthijs Knigge <matthijs@volcano.nl>
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-02-10 15:02:47 +01:00
committed by GitHub
parent 5194513850
commit 538984dc2f
23 changed files with 457 additions and 400 deletions

View File

@@ -0,0 +1,19 @@
import type WebSocket from 'ws';
import { AbstractPush } from './abstract.push';
export class WebSocketPush extends AbstractPush<WebSocket> {
add(sessionId: string, connection: WebSocket) {
super.add(sessionId, connection);
// Makes sure to remove the session if the connection is closed
connection.once('close', () => this.remove(sessionId));
}
protected close(connection: WebSocket): void {
connection.close();
}
protected sendToOne(connection: WebSocket, data: string): void {
connection.send(data);
}
}