Leave a chat room

The chat.leave() method allows a user to leave a chat room and stop receiving events.

chat.leave();

Listen to $.offline Event

A $.offline.leave event is emitted when a user intentionally leaves a chat room. Other users in the chat room can listen to $.offline.* to receive all $.leave events and mark the user as offline.

chat.on('$.offline.*', (payload) => {
    console.log('User left the room:', payload.user);
});

Listen to $.disconnected Event

A $.disconnected event is emitted towards the user when they are successfully disconnected from the chat room. The user can listen to the event to execute additional business logic upon leave.

chat.on('$.disconnected', () => {
    done();
});