Live SDKs Android v1
Live SDKs Android
Live SDKs
Android
Version 1

Add reactions to a live event

Copy link

When participating in a live event, adding the reactions function can help users be more engaged with the event and provide feedback from each other. This function is similar to the reactions you might have seen in Instagram or YouTube live streams.


Add reaction keys

Copy link

To use reactions, the host first needs to specify the types of reactions they want to allow during the live event. These reactions are represented by reactionKeys which are labels for reactions like a heart or a thumbs up.

Refer to the following lines of code to add your reaction keys to the live event.

class LiveEventCreateParams {
    var reactionKeys: List<String> // other attributes
}

val reactionKeys = listOf("heart", "thumbs_up", "laugh")

val params = LiveEventCreateParams(userIdsForHost) {
    this.reactionKeys = reactionKeys
}
SendbirdLive.createLiveEvent(params) { liveEvent, e ->
    ...
}

Send reactions to others

Copy link

During the live event, the host and participants can use reaction keys to express their feelings.

The increaseReactionCount method is called to increase the count of a particular reaction key. For example, to send a heart, call the method with "heart" as the parameter.

liveEvent.increaseReactionCount("heart") { metaCounterMap, e ->
    if(e != null) {
        // Error occurred while increasing the reaction count.
        return
    }
    // Reaction count successfully increased.
}

The increaseReactionCount method internally uses the openChannel object to increase the meta counter for the specified reaction key.


Show reaction counts

Copy link

Users in the live event will receive update on the reaction counts as it updates through the LiveEventListener interface. You can apply special effects to show reaction counts such as animated hearts flying across the screen.

interface LiveEventListener { fun onReactionCountUpdated(liveEvent: LiveEvent, key: String, count: Int) }

class MyLiveEventListener : LiveEventListener {
    override fun onReactionCountUpdated(liveEvent: LiveEvent, key: String, count: Int) {
        // update the UI to reflect the new count for the specified reaction key
    }
}