Skip to content

SudoSOS Back-end API / service/websocket-service / WebSocketService

Class: WebSocketService ​

Constructors ​

Constructor ​

ts
new WebSocketService(options): WebSocketService;

Creates a new WebSocketService instance.

Parameters ​

ParameterTypeDescription
optionsWebSocketServiceOptionsThe service options.

Returns ​

WebSocketService

Properties ​

PropertyModifierType
ioreadonlyServer<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any>
loggerreadonlyLogger
serverreadonlyServer<typeof IncomingMessage, typeof ServerResponse>

Accessors ​

io ​

Get Signature ​

ts
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 ​

ts
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 ​

ts
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() ​

ts
close(): Promise<void>;

Closes the WebSocket server and cleans up resources.

Returns ​

Promise<void>

Promise that resolves when the server is closed.


emit() ​

ts
emit<T>(eventType, eventData): Promise<void>;

Emits an event to the appropriate rooms using the event registry.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
eventTypestringThe event type (e.g., "transaction:created").
eventDataTThe event data to emit.

Returns ​

Promise<void>


emitMaintenanceMode() ​

ts
emitMaintenanceMode(enabled): void;

Sends maintenance mode status to all clients in the system room.

Parameters ​

ParameterTypeDescription
enabledbooleanWhether maintenance mode is enabled.

Returns ​

void


emitQRConfirmed() ​

ts
emitQRConfirmed(qr, token): void;

Emits a QR confirmation event to all clients subscribed to the QR session.

Parameters ​

ParameterTypeDescription
qrQRAuthenticatorThe QR authenticator containing the session ID.
tokenAuthenticationResponseThe authentication response token to send.

Returns ​

void


emitTransactionCreated() ​

ts
emitTransactionCreated(transaction): Promise<void>;

Emits a transaction created event to the appropriate rooms.

Parameters ​

ParameterTypeDescription
transactionTransactionResponseThe transaction response to emit.

Returns ​

Promise<void>


initiateWebSocket() ​

ts
initiateWebSocket(): void;

Initializes the WebSocket server and sets up connection handlers.

Returns ​

void


registerRoom() ​

ts
registerRoom(registration): void;

Registers a room with its policy.

Parameters ​

ParameterTypeDescription
registrationRoomRegistrationThe room registration.

Returns ​

void


close() ​

ts
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() ​

ts
static emitMaintenanceMode(enabled): void;

Static method for backward compatibility. Delegates to the singleton instance.

Parameters ​

ParameterType
enabledboolean

Returns ​

void

Throws ​

Error if WebSocketService has not been initialized.


emitQRConfirmed() ​

ts
static emitQRConfirmed(qr, token): void;

Static method for backward compatibility. Delegates to the singleton instance.

Parameters ​

ParameterType
qrQRAuthenticator
tokenAuthenticationResponse

Returns ​

void

Throws ​

Error if WebSocketService has not been initialized.


emitTransactionCreated() ​

ts
static emitTransactionCreated(transaction): Promise<void>;

Static method for backward compatibility. Delegates to the singleton instance.

Parameters ​

ParameterType
transactionTransactionResponse

Returns ​

Promise<void>

Throws ​

Error if WebSocketService has not been initialized.


getInstance() ​

ts
static getInstance(): WebSocketService;

Gets the singleton instance of WebSocketService.

Returns ​

WebSocketService

The WebSocketService instance.

Throws ​

Error if WebSocketService has not been initialized.


initiateWebSocket() ​

ts
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.