Methods
(static) connect() → {object}
Handles mock WebSocket connection lifecycle:
- Initializes connection if not exists
- Triggers asynchronous opening process
- Returns connection instance
Handles mock WebSocket connection lifecycle:
- Initializes connection if not exists
- Triggers asynchronous opening process
- Returns connection instance
Returns:
Active WebSocket connection instance
- Type
- object
Example
// Establish connection
const connection = connect();
(static) validateConnection(connection, user) → {boolean}
Verifies preconditions for chat operations:
- Active WebSocket connection must exist
- User must be authenticated
- Shows appropriate error messages if validation fails
Verifies preconditions for chat operations:
- Active WebSocket connection must exist
- User must be authenticated
- Shows appropriate error messages if validation fails
Parameters:
Name | Type | Description |
---|---|---|
connection |
object | WebSocket connection to validate |
user |
string | null | Current username if authenticated |
Returns:
True if connection is valid and user is authenticated
- Type
- boolean
Example
// Check before sending message
if (validateConnection(ws, currentUser)) {
// Safe to proceed
}