Overview
This guide is designed to help developers understand how to allow users to join Agora channels without enabling their camera or microphone, suitable for applications that feature live events, webinars, or any scenario where users need to join as audience members. Additionally, it addresses a common issue where a user’s microphone is muted but they are not visible to others until unmuted.
Setting Up User Roles in Agora Channels
Understanding Channel Profiles:
- Live Channel Profile: Ideal for scenarios where the majority of participants are viewers. In this mode, users can join as an audience without transmitting audio or video.
- RTC (Real-Time Communication) Channel Profile: Best suited for interactive sessions, where all participants can share and receive audio and video streams.
Joining as an Audience Member (Live Channel Profile):
Initialize the Agora Client: Set the client’s channel profile to ‘live’.
const client = AgoraRTC.createClient({mode:"live", codec:"vp8"});
Set the User Role: Define the user’s role as ‘audience’. This setting prevents the transmission of audio and video from the user, making it perfect for viewers.
client.setClientRole("audience");
Handling Muted Microphones
Issue: Users with muted microphones do not appear to other users until they unmute.
- Root Cause: This behavior is influenced by the channel profile and user role. In a live broadcasting scenario (‘live’ profile), audience members cannot publish streams. If a user needs to share audio or video, their role must be switched to ‘broadcaster’, even if initially joining muted.
Solution
Switching Roles: To allow a muted user to be visible or audible when they decide to unmute, dynamically change their role from ‘audience’ to ‘broadcaster’.
client.setClientRole("broadcaster");
Muting and Unmuting: Use the setEnabled method on the local track to mute or unmute the user.
// Mute audio
localAudioTrack.setEnabled(false);
// Unmute audio
localAudioTrack.setEnabled(true);