switchRole abstract method
Switch role
This API is used to switch the user role between anchor
and audience
.
As video live rooms and audio chat rooms need to support an audience of up to 100,000 concurrent online users, the rule "only anchors can publish their audio/video streams" has been set. Therefore, when some users want to publish their streams (so that they can interact with anchors), they need to switch their role to "anchor" first.
You can use the role
field in TRTCParams during room entry to specify
the user role in advance or use the switchRole
API to switch roles after
room entry.
Parameters:
- role(TRTCRoleType): Role, which is
anchor
by default.- TRTCRoleType.anchor:
- Can publish audio/video streams.
- Up to 50 anchors can publish at the same time.
- TRTCRoleType.audience:
- Cannot publish streams, can only watch.
- Needs to switch to "anchor" role to publish.
- Supports up to 100,000 concurrent audience.
- TRTCRoleType.anchor:
Note
- This API is only applicable to two scenarios: live streaming (TRTCAppScene.live) and audio chat room (TRTCAppScene.voiceChatRoom).
- If the
scene
you specify in enterRoom is TRTCAppScene.videoCall or TRTCAppScene.audioCall, please do not call this API.
Implementation
void switchRole(TRTCRoleType role);