Message replay

更新时间:
复制 MD 格式

After a live stream ends, you can load content, such as interactive messages and live comments, from the live channel to display during the replay.

Message replay API

You can use this API to load content, such as live comments, from a live stream after it has ended.

Note
  1. You do not need to join the audience group to use this API. You only need to log on.

  2. A single client can call this API up to 2 times per second. Calls that exceed this limit are rejected. Each call can return a maximum of 100 messages, and the maximum value for the PageSize parameter is 100. You can only retrieve messages of the live comment type.

  3. To ensure stream performance and stability, avoid using this API during a live stream.

// This API is primarily for replaying historical messages after a live stream has ended. It allows users to query messages without joining the group. This operation can be time-consuming and is not recommended for use during a live stream. This API may be subject to charges in the future.
ImListHistoryMessageReq req = new ImListHistoryMessageReq();
req.groupId = "your-group-id";
req.nextPageToken = 231231;  // Leave empty for the first page. The server returns a token for the next page, which you should use in your next request.
req.type = 99999;            // Custom message type. Must be greater than 10000.
req.sortType = ImSortType.ASC;
req.pageSize = 20;
req.beginTime = 0; // Start of the time range for the query, in seconds. A value of 0 means the earliest time.
req.endTime = 0;   // End of the time range for the query, in seconds. A value of 0 means the latest time.
messageInterface.listHistoryMessage(req, new ImSdkValueCallback<ImListHistoryMessageRsp>() {
    @Override
    public void onSuccess(ImListHistoryMessageRsp rsp) {
    }
    @Override
    public void onFailure(Error error) {
    }
});

Typical scenario: Trigger events by timestamp during recorded playback

Combine the message replay API with player callbacks to trigger events, such as pop-ups, based on timestamps.

  1. When the streamer client sends a custom message, record the event timestamp in your business database.

  2. The player client calls the listHistoryMessage API with beginTime and endTime to query historical messages within a specific time range.

  3. The player client obtains the current playback progress through the onTimeUpdate callback of the player SDK.

  4. Compare the playback time with the timestamps of the queried messages, and trigger business logic, such as a pop-up, when they match.

Note

beginTime and endTime are in seconds. A value of 0 means the earliest or latest time, respectively, consistent with the parameter descriptions in the existing code examples.