ApsaraVideo Real-time Communication (ARTC) SDK for Web allows you to deliver different interactive experience by changing channel modes and user roles. This topic provides the sample code that is used to set the channel mode and user role.
Set the channel mode
ARTC SDK for Web provides two channel modes that can be used to optimize streaming performance in different scenarios.
To set the channel mode, you must call the setChannelProfile method before you join the channel. Channel mode settings after you join the channel do not take effect.
// Make sure that an AliRtcEngine instance is created.
// Call the method to set the channel mode.
aliRtcEngine.setChannelProfile('communication');Argument | Meaning | Description | Is default value |
communication | The communication mode. | In this mode, all users can have interactions. This mode is suitable for scenarios such as online conferencing and calling. | Yes |
interactive_live | The interactive mode. | In this mode, users are divided into two types: streamers and viewers. Streamers can publish and subscribe to audio and video streams, whereas viewers can only subscribe to audio and video streams. This mode is suitable for conferencing and real-time communication. | No |
Set the user role
If you select the interactive_live mode, you must call the setClientRole method to assign roles to users. The SDK provides two user roles: interactive and live.
User role settings in communication mode do not take effect.
// Make sure that you set the channel mode to interactive_live. User role settings in communication mode do not take effect.
// You can set the user role at any time. For example, when a viewer wants to talk with the streamer, you can set the user role to interactive.
aliRtcEngine.setClientRole('interactive');
// When the talk ends, set the user role to live.
aliRtcEngine.setClientRole('live');Argument | Meaning | Description | Is default value |
interactive | The streamer role. | A streamer can publish and subscribe to audio and video streams. | No |
live | The viewer role. | A viewer can only subscribe to audio and video streams. | Yes |