logo
On this page

Real-time Messaging and Signaling

2024-01-02

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 TypeFunction DescriptionApplication ScenariosSending Frequency Limit
Broadcast MessageSend text messages to all users in the same room.Can be used for simple in-room chat room scenarios.Please refer to Restrictions.
Barrage MessageAudiences 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 SignalingSend 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:

Usage Steps

Send and Receive Broadcast Messages

  1. 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
    })
  2. 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

  1. 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
    })
  2. 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

  1. 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)
  2. 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")
        })

Previous

Multi-Source Capture

Next

Login to Multiple Rooms

On this page

Back to top