Interactive Live Streaming Premium
Console Community Submit ticket

How can a host change the role of a remote user?

Type: Integration issues    Platform: Android / iOS / macOS / Web / Windows / Linux / Unity / Cocos Creator / Electron / React Native / Flutter / Flutter2   Last Updated: 2021/12/28 23:13:58


In a live interactive streaming channel, the host can invite an audience to take on the role of co-host, or change role back to audience.

You can implement this function by combining the following features:

  • Real-time messaging and channel attributes using methods from the Agora RTM SDK.
  • Setting the user role using methods from the Agora RTC SDK.


Before proceeding, ensure that you have integrated both the Agora RTM SDK and RTC SDK in your project. For how to integrate these SDKs, see the following guides:

The basic API call sequence is as follows:

Refer to the detailed steps for implementation:

  1. The host calls sendMessageToPeer to send a peer-to-peer message that invites an audience to take on the role pf co-host.
  2. The audience receives the invitation message in the onMessageReceived callback.
  3. The audience calls setClientRole to change the user role to CLIENT_ROLE_BROADCASTER.
  4. After successfully changing the user role, the audience receives the onClientRoleChanged callback, and becomes a co-host.
  5. The new co-host calls addOrUpdateChannelAttributes to notify the role change to all users in the channel.
  6. The host receives the onAttributesUpdated callback, and starts co-hosting with the new co-host.

To change a co-host back to an audience, follow the same steps, except when calling setClientRole, set the user role as CLIENT_ROLE_AUDIENCE.

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 sendMessage sendMessage
onMessageReceived messageReceived MessageFromPeer
setClientRole setClientRole setClientRole
onClientRoleChanged didClientRoleChanged Client.on("client-role-changed")
addOrUpdateChannelAttributes addOrUpdateChannelAttributes addOrUpdateChannelAttributes
onAttributesUpdated attributeUpdate AttributesUpdated