Real-time Messaging and Signaling
Overview
ZEGO provides various text message sending and receiving functions to implement sending in-room broadcast messages, barrage messages, simple IM text chat, likes, gifts, quizzes, and other functions.
| Message Type | Function Description | Application Scenarios | Sending Frequency Limit |
|---|---|---|---|
| Broadcast Message | Send text messages to all users in the same room. | Can be used for simple in-room chat room scenarios. | Please refer to Restrictions. |
| Barrage Message | Audiences can express their comments during the live streaming process, which are displayed as sliding subtitles, increasing the interactivity between audiences. | Generally used for scenarios with a large amount of message sending and receiving in the room and without the need to guarantee message reliability, such as live streaming barrage. | Please refer to Restrictions. |
| Custom Signaling | Send messages to single or multiple users in the same room. | Generally used for remote control signaling or simple text message sending. For example, in the online doll machine scenario, remotely control the movement of the doll machine clamp. | Please refer to Restrictions. |
In addition, ZEGO also provides a complete Instant Messaging ZIM SDK, providing developers with cross-platform interaction, massive concurrency, ultra-low latency, and guaranteed message delivery communication services. For details, please refer to In-app Chat.
Prerequisites
Before sending real-time messages, ensure:
- You have created a project in the ZEGOCLOUD Console and applied for a valid AppID and AppSign. For details, please refer to Console - Project Information.
- You have integrated ZEGO Express SDK into the project and implemented basic audio and video streaming functionality. For details, please refer to Quick Start - Integration and Quick Start - Implementation.
Usage Steps
Send and Receive Broadcast Messages
-
Send Broadcast Message
Call the sendBroadcastMessage interface to send broadcast messages to other users in the same room. The length cannot exceed 1024 bytes.
Get the message sending result through the return of the ZegoIMSendBroadcastMessageResult asynchronous result.
// Send broadcast message ZegoExpressEngine.instance().sendBroadcastMessage("ChatRoom-1", "This is a broadcast message").then((result) => { // Get message sending result }) -
Receive Broadcast Message
By calling ZegoExpressEngine's on method, set up to listen to the IMRecvBroadcastMessage event callback. After the sender successfully sends the broadcast message, other users in the same room receive relevant information through this callback, including message content, message ID, sending time, and sender information.
// Receive message sent by other users ZegoExpressEngine.instance().on('IMRecvBroadcastMessage', (roomID, messageList) => { console.log("received broadcast message") })
Send and Receive Barrage Messages
-
Send Barrage Message
Call the sendBarrageMessage interface to send barrage messages to other users in the same room. The length cannot exceed 1024 bytes.
Get the message sending result through the return of the ZegoIMSendBarrageMessageResult asynchronous result.
// Send room barrage message ZegoExpressEngine.instance(). sendBarrageMessage("ChatRoom-1", "This is a barrage message").then((result) => { // Get message sending result }) -
Receive Barrage Message
By calling ZegoExpressEngine's on method, set up to listen to the IMRecvBarrageMessage event callback. After the sender successfully sends the barrage message, other users in the same room receive relevant information through this callback, including message content, message ID, sending time, and sender information.
// Receive message sent by other users ZegoExpressEngine.instance().on('IMRecvBarrageMessage', (roomID, messageList) => { console.log("received barrage message") })
Send and Receive Custom Signaling
-
Send Custom Signaling
Call the sendCustomCommand interface to send custom signaling to users specified by "toUserList" in the same room. The length cannot exceed 1024 bytes.
Get the message sending result through the return of the ZegoIMSendCustomCommandResult asynchronous result.
// Send custom signaling, only users specified in `toUserList` can receive this signaling through the IMRecvCustomCommand event // If the `toUserList` parameter is passed as an empty array, the SDK will send this signaling to all users in the room ZegoExpressEngine.instance().sendCustomCommand("ChatRoom-1", "This is a custom command", toUserList) -
Receive Custom Signaling
By calling ZegoExpressEngine's on method, set up to listen to the IMRecvCustomCommand event callback. After the sender successfully sends the custom signaling, specified users in the same room receive relevant information through this callback, including message content and message sender information.
// Receive message sent by other users ZegoExpressEngine.instance().on('IMRecvCustomCommand', (roomID, fromUser, command) => { console.log("received custom command") })
