Skip to main content

userMessageListener

codebolt.chat.userMessageListener(): void

Sets up a listener for incoming WebSocket messages and emits a custom event when a message is received.

Response Structure​

This method returns an event emitter that can be used to listen for incoming WebSocket messages. The emitter allows you to set up custom event handlers for processing messages.

Example​

// Set up a user message listener
const emitter = codebolt.chat.userMessageListener();

// Listen for custom events
emitter.on('message', (message) => {
console.log('Received message:', message);
});

Explanation​

This function sets up a listener for incoming WebSocket messages and returns an event emitter for handling custom events when messages are received.