通知
RTM 1.x 将于近期下架,各版本退休日期和替代方案详见 退休政策
Documentation
Real-time Messaging
Console 官网 Community Technical support

How do I enable virtual gift sending in interactive live streaming using the Agora RTM SDK?

Type: Integration issues    Platform: Android / iOS / macOS / Windows / Web / Linux / RESTful   Last Updated: 2020/11/15 20:41:48

Introduction

To add more fun to interactive live streaming, you can enable virtual gift sending with the Agora RTM SDK. An audience member can send virtual gifts to the host. All members in the live streaming room can see the gift.

Implementation

Before proceeding, ensure that you have integrated the Agora RTM SDK into your project. To learn more about integration, refer to Agora RTM SDK Quickstart.

The basic API call sequence is as follows:

The steps are as follows:

  1. The client calls sendMessageToPeer to send a peer-to-peer message (gift type) to the server.
  2. The server checks the messages and calls sendMessageToPeer to send a peer-to-peer message (gift type) to the client.
  3. The client receives the peer-to-peer message and calls sendMessage to send a channel message to all members in the room as a gift. The client renders the gift per the channel message.
  4. The client calls sendMessageToPeer to notify the server that the channel message is sent after receiving onSuccess. You can add more code logic to ensure that the channel message is successfully sent. In the code logic, the server notifies the client to resend the channel message if the server did not receive onMessageReceived in time.
To ensure data security, Agora recommends that you encrypt all messages between the client and the server.

Relative methods in different programming languages

The methods mentioned in this article are in Java. Refer to the following table if you are programming in a different language:

Java C++ Objective-C JavaScript
sendMessageToPeer sendMessageToPeer sendMessage sendMessageToPeer
sendMessage sendMessage sendMessage sendMessage
onSuccess onSendMessageResult AgoraRtmSendPeerMessageBlock PeerMessageSendResult
onMessageReceived onMessageReceivedFromPeer messageReceived MessageFromPeer