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:
committed by
GitHub
parent
5194513850
commit
538984dc2f
19
packages/cli/src/push/websocket.push.ts
Normal file
19
packages/cli/src/push/websocket.push.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user