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