Skip to main content

You are looking at Video Calling v3.x Docs. The newest version is  Video Calling 4.x

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.

  • This page applies to the SDK v3.4.5 and later.
  • If you have upgraded the SDK from an earlier version to v3.4.5 or later, Agora recommends that you adjust your publishing settings by referring to API changes to avoid any impact on your business functions.
  • This page is applicable to single-channel scenarios. If you need to know how to set the publishing state in multichannel scenarios, see Join Multiple Channels.
  • API introduction

    Agora provides the following methods to set the publishing state of local streams:

    MethodDescription
    enableLocalAudio or enableLocalVideoSets 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 muteLocalVideoStreamSets whether to stop publishing a local stream:
  • true: Stop publishing a local stream.
  • false: Resume publishing a local stream.
  • joinChannel with the options parameterWhen 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.
  • setClientRoleSets the user role in an interactive live streaming channel:
  • CLIENT_ROLE_AUDIENCE: (Default) Audience.
  • CLIENT_ROLE_BROADCASTER: Host, who publishes local streams by default.
  • If a user joins a channel by calling joinChannel with the options parameter, muteLocalAudioStream or muteLocalVideoStream only takes effect when it is called after joinChannel.
  • In the interactive live streaming profile:
    • If the user role is setClientRole(AUDIENCE), the user cannot publish local streams. No matter how you set the joinChannel with the options parameter, muteLocalAudioStream, or muteLocalVideoStream, the publishing state cannot be changed.
    • If you call setClientRole(BROADCASTER), joinChannel with the options parameter, muteLocalAudioStream, or muteLocalVideoStream 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 and muteLocalVideoStream take effect when they are called before or after a user joins a channel.
    • Calling muteLocalAudioStream(true) or muteLocalVideoStream(true) in IRtcEngine takes effect in channels created by both the IRtcEngine and IChannel classes.

    As of v3.4.5:

    • The joinChannel method with the options parameter can set the publishing state of local streams.
    • If a user joins a channel by calling joinChannel with the options parameter, muteLocalAudioStream or muteLocalVideoStream only takes effect when it is called after joinChannel.
    • muteLocalAudioStream and muteLocalVideoStream in the IRtcEngine and IChannel classes control the publishing state of each channel in their respective classes only.

    Corresponding methods in different platforms

    WindowsAndroid/React Native/FlutteriOS/macOS
    enableLocalAudioenableLocalAudioenableLocalAudio
    enableLocalVideoenableLocalVideoenableLocalVideo
    muteLocalAudioStreammuteLocalAudioStreammuteLocalAudioStream
    muteLocalVideoStreammuteLocalVideoStreammuteLocalVideoStream
    joinChanneljoinChanneljoinChannelByToken
    setClientRolesetClientRolesetClientRole
    setChannelProfilesetChannelProfilesetChannelProfile
    IRtcEngineRtcEngineAgoraRtcEngineKit
    IChannelRtcChannelAgoraRtcChannel
    UnityElectron
    EnableLocalAudioenableLocalAudio
    EnableLocalVideoenableLocalVideo
    MuteLocalAudioStreammuteLocalAudioStream
    MuteLocalVideoStreammuteLocalVideoStream
    JoinChanneljoinChannel
    SetClientRolesetClientRole
    SetChannelProfilesetChannelProfile
    IRtcEngineAgoraRtcEngine
    AgoraChannelAgoraRtcChannel

    Video Calling