SudoSOS Back-end API / service/websocket-service / WebSocketService
Class: WebSocketService ​
Constructors ​
Constructor ​
new WebSocketService(options): WebSocketService;Creates a new WebSocketService instance.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
options | WebSocketServiceOptions | The service options. |
Returns ​
WebSocketService
Properties ​
| Property | Modifier | Type |
|---|---|---|
io | readonly | Server<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any> |
logger | readonly | Logger |
server | readonly | Server<typeof IncomingMessage, typeof ServerResponse> |
Accessors ​
io ​
Get Signature ​
get static io(): Server;Static getter for backward compatibility with tests.
Throws ​
Error if WebSocketService has not been initialized.
Returns ​
Server
The Socket.IO server instance.
logger ​
Get Signature ​
get static logger(): Logger;Static getter for backward compatibility with tests.
Throws ​
Error if WebSocketService has not been initialized.
Returns ​
Logger
The logger instance.
server ​
Get Signature ​
get static server(): Server<typeof IncomingMessage>;Static getter for backward compatibility with tests.
Throws ​
Error if WebSocketService has not been initialized.
Returns ​
Server<typeof IncomingMessage>
The HTTP server instance.
Methods ​
close() ​
close(): Promise<void>;Closes the WebSocket server and cleans up resources.
Returns ​
Promise<void>
Promise that resolves when the server is closed.
emit() ​
emit<T>(eventType, eventData): Promise<void>;Emits an event to the appropriate rooms using the event registry.
Type Parameters ​
| Type Parameter |
|---|
T |
Parameters ​
| Parameter | Type | Description |
|---|---|---|
eventType | string | The event type (e.g., "transaction:created"). |
eventData | T | The event data to emit. |
Returns ​
Promise<void>
emitMaintenanceMode() ​
emitMaintenanceMode(enabled): void;Sends maintenance mode status to all clients in the system room.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
enabled | boolean | Whether maintenance mode is enabled. |
Returns ​
void
emitQRConfirmed() ​
emitQRConfirmed(qr, token): void;Emits a QR confirmation event to all clients subscribed to the QR session.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
qr | QRAuthenticator | The QR authenticator containing the session ID. |
token | AuthenticationResponse | The authentication response token to send. |
Returns ​
void
emitTransactionCreated() ​
emitTransactionCreated(transaction): Promise<void>;Emits a transaction created event to the appropriate rooms.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
transaction | TransactionResponse | The transaction response to emit. |
Returns ​
Promise<void>
initiateWebSocket() ​
initiateWebSocket(): void;Initializes the WebSocket server and sets up connection handlers.
Returns ​
void
registerRoom() ​
registerRoom(registration): void;Registers a room with its policy.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
registration | RoomRegistration | The room registration. |
Returns ​
void
close() ​
static close(): Promise<void>;Static method for backward compatibility. Delegates to the singleton instance.
Returns ​
Promise<void>
Throws ​
Error if WebSocketService has not been initialized.
emitMaintenanceMode() ​
static emitMaintenanceMode(enabled): void;Static method for backward compatibility. Delegates to the singleton instance.
Parameters ​
| Parameter | Type |
|---|---|
enabled | boolean |
Returns ​
void
Throws ​
Error if WebSocketService has not been initialized.
emitQRConfirmed() ​
static emitQRConfirmed(qr, token): void;Static method for backward compatibility. Delegates to the singleton instance.
Parameters ​
| Parameter | Type |
|---|---|
qr | QRAuthenticator |
token | AuthenticationResponse |
Returns ​
void
Throws ​
Error if WebSocketService has not been initialized.
emitTransactionCreated() ​
static emitTransactionCreated(transaction): Promise<void>;Static method for backward compatibility. Delegates to the singleton instance.
Parameters ​
| Parameter | Type |
|---|---|
transaction | TransactionResponse |
Returns ​
Promise<void>
Throws ​
Error if WebSocketService has not been initialized.
getInstance() ​
static getInstance(): WebSocketService;Gets the singleton instance of WebSocketService.
Returns ​
WebSocketService
The WebSocketService instance.
Throws ​
Error if WebSocketService has not been initialized.
initiateWebSocket() ​
static initiateWebSocket(): void;Static method for backward compatibility with tests. Delegates to the singleton instance.
Returns ​
void
Throws ​
Error if WebSocketService has not been initialized.