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 |
---|---|
enableLocalAudio or enableLocalVideo | 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 calling muteLocalAudioStream or muteLocalVideoStream . |
muteLocalAudioStream or muteLocalVideoStream | Sets whether to stop publishing a local stream:true : Stop publishing a local stream.false : Resume publishing a local stream. |
joinChannel with the options parameter | When joining a channel, you can use the publishLocalAudio or publishLocalVideo member in ChannelMediaOptions to 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 thejoinChannel
with theoptions
parameter,muteLocalAudioStream
, ormuteLocalVideoStream
, the publishing state cannot be changed. - If you call
setClientRole(BROADCASTER)
,joinChannel
with theoptions
parameter,muteLocalAudioStream
, ormuteLocalVideoStream
together, 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
joinChannel
methods can set the publishing state of local streams. muteLocalAudioStream
andmuteLocalVideoStream
take effect when they are called before or after a user joins a channel.- Calling
muteLocalAudioStream(true)
ormuteLocalVideoStream(true)
inIRtcEngine
takes effect in channels created by both theIRtcEngine
andIChannel
classes.
As of v3.4.5:
- The
joinChannel
method with theoptions
parameter can set the publishing state of local streams. - If a user joins a channel by calling
joinChannel
with theoptions
parameter,muteLocalAudioStream
ormuteLocalVideoStream
only takes effect when it is called afterjoinChannel
. muteLocalAudioStream
andmuteLocalVideoStream
in theIRtcEngine
andIChannel
classes 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 |