Set the Publishing State
Overview
Your business scenarios might require you to set the publishing state of audio and video streams during real-time engagement.
This article describes how to the set the publishing state of local streams using C++. To use Java or Objective-C, see Corresponding methods in different programming languages.
API introduction
Agora provides the following methods to set the publishing state of local streams:
| Method | Description | 
|---|---|
| enableLocalAudioorenableLocalVideo | Sets whether to enable the local audio or video capture module: true: (Default) Enable the local audio or video capture module. After enabling a module, the SDK captures the local audio or video, and then users can choose whether to publish a local stream.false: Disable the local audio or video capture module. After disabling a module, the SDK does not capture the local audio or video, so no local stream can be published.If you only need to stop or resume publishing a local stream, Agora recommends callingmuteLocalAudioStreamormuteLocalVideoStream. | 
| muteLocalAudioStreamormuteLocalVideoStream | Sets whether to stop publishing a local stream: true: Stop publishing a local stream.false: Resume publishing a local stream. | 
| joinChannelwith theoptionsparameter | When joining a channel, you can use the publishLocalAudioorpublishLocalVideomember inChannelMediaOptionsto set the publishing state of local streams:true: (Default) Publish.false: Do not publish. | 
| setClientRole | Sets the user role in an interactive live streaming channel: CLIENT_ROLE_AUDIENCE: (Default) Audience.CLIENT_ROLE_BROADCASTER: Host, who publishes local streams by default. | 
joinChannel with the options parameter, muteLocalAudioStream or muteLocalVideoStream only takes effect when it is called after joinChannel.- If the user role is setClientRole(AUDIENCE), the user cannot publish local streams. No matter how you set thejoinChannelwith theoptionsparameter,muteLocalAudioStream, ormuteLocalVideoStream, the publishing state cannot be changed.
- If you call setClientRole(BROADCASTER),joinChannelwith theoptionsparameter,muteLocalAudioStream, ormuteLocalVideoStreamtogether, the method called later determines the publishing state.
API changes
As of v3.4.5, Agora adds the publishLocalAudio and publishLocalVideo members in ChannelMediaOptions. The default value is true. You can call joinChannel with the options parameter to join a channel and set the publishing state.
If you upgrade the SDK to v3.4.5 or later, to avoid affecting your service, take note of the following differences between versions and adjust your publishing settings accordingly.
Earlier than v3.4.5:
- None of the joinChannelmethods can set the publishing state of local streams.
- muteLocalAudioStreamand- muteLocalVideoStreamtake effect when they are called before or after a user joins a channel.
- Calling muteLocalAudioStream(true)ormuteLocalVideoStream(true)inIRtcEnginetakes effect in channels created by both theIRtcEngineandIChannelclasses.
As of v3.4.5:
- The joinChannelmethod with theoptionsparameter can set the publishing state of local streams.
- If a user joins a channel by calling joinChannelwith theoptionsparameter,muteLocalAudioStreamormuteLocalVideoStreamonly takes effect when it is called afterjoinChannel.
- muteLocalAudioStreamand- muteLocalVideoStreamin the- IRtcEngineand- IChannelclasses control the publishing state of each channel in their respective classes only.
Corresponding methods in different platforms
| Windows | Android/React Native/Flutter | iOS/macOS | 
|---|---|---|
| enableLocalAudio | enableLocalAudio | enableLocalAudio | 
| enableLocalVideo | enableLocalVideo | enableLocalVideo | 
| muteLocalAudioStream | muteLocalAudioStream | muteLocalAudioStream | 
| muteLocalVideoStream | muteLocalVideoStream | muteLocalVideoStream | 
| joinChannel | joinChannel | joinChannelByToken | 
| setClientRole | setClientRole | setClientRole | 
| setChannelProfile | setChannelProfile | setChannelProfile | 
| IRtcEngine | RtcEngine | AgoraRtcEngineKit | 
| IChannel | RtcChannel | AgoraRtcChannel | 
| Unity | Electron | 
|---|---|
| EnableLocalAudio | enableLocalAudio | 
| EnableLocalVideo | enableLocalVideo | 
| MuteLocalAudioStream | muteLocalAudioStream | 
| MuteLocalVideoStream | muteLocalVideoStream | 
| JoinChannel | joinChannel | 
| SetClientRole | setClientRole | 
| SetChannelProfile | setChannelProfile | 
| IRtcEngine | AgoraRtcEngine | 
| AgoraChannel | AgoraRtcChannel |