Being a real-time client, you will use event listeners to respond to events sent from the Coronium Chatterbox instance. You can learn more about the events received in Client Events.
Rooms
Coronium Chatterbox allows you to group clients into "rooms" of your choosing. Using the joinRoom action you can switch between rooms. By default, the client is connected to the "Lobby" room. If you want to join a different room when connecting, supply the room parameter to the cs:connect method (see Connecting The Client).
When a client joins a new room, they are automatically removed from the previous room they were in. A client can only be a member of one room at any given time.
At anytime a client joins a room , a OnJoined event will be triggered in the room with the newly joined members information. The joining client also receives this message.
If a user leaves a room, the OnLeft event is triggered in the room. The leaving client will not receive this message.
Tip
Whenever a client joins or leaves a room (or changes their name), an OnClientList event will be triggered. This is a good time to store and update your client display list.
To retrieve a list of the active rooms on your Coronium Chatterbox instance use the getRooms action along with the OnRoomList event.
Client List
The client list is broadcast to the room on any OnJoined, OnLeft, or OnNameChange event. You can use this list to create a user display component, and to also gather the ID needed for the sendWhisper action. To listen for the client list use the OnClientList event.
Messages
The client can send (and receive) three different types of messages; a "room" message, a "private" message, and a "system" message.
Room Message
A room message is sent using the sendMessage action. This message type is broadcast to all members of the current room the client is in. You can receive this message type using the OnMessage event. This message type works well for chat messaging.
Important
All clients in the room receive this message type, including the client sending the message.
Private Message
You can send a message directly to any user in the room using the sendWhisper action. This message type is sent directly to the recipient. It is not broadcast into the room. To send a "whisper" you need to supply the recipient ID. You can get ahold of these ids within the OnClientList event.
System Message
To send control type messages within the room, you can use a "system" message. This message type is broadcast to the room, and can be captured outside of your "chat" layer. To receive these use the OnSystemMessage event.
System messages can be used for controlling aspects of your application state. For example, opening a webview with a passed url.
Important
All clients in the room receive this message type, including the client sending the message.
Status Events
To listen for error events from both the Coronium Chatterbox instance, as well as, the local client use the OnError event.
To listen for client timeout (if any) use the OnTimeout event.
To listen for the client disconnecting from the instance, use the OnClosed event.