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.
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:
sendMessageToPeer
to send a peer-to-peer message (gift type) to the server.sendMessageToPeer
to send a peer-to-peer message (gift type) to the client.sendMessage
to send a channel message to all members in the room as a gift. The client renders the gift per the channel message.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.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 |