Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RtcChannel

The RtcChannel class.

Hierarchy

  • RtcChannel

Implements

  • RtcChannelInterface

Index

Properties

Readonly channelId

channelId: string

The ID of RtcChannel

Methods

addListener

  • addListener<EventType>(event: EventType, listener: RtcChannelEvents[EventType]): Subscription

addPublishStreamUrl

  • addPublishStreamUrl(url: string, transcodingEnabled: boolean): Promise<void>
  • Publishes the local stream to a specified CDN streaming URL.

    deprecated

    This method is deprecated as of v3.6.2. See Release Notes for an alternative solution.

    After calling this method, you can push media streams in RTMP or RTMPS protocol to the CDN.

    This method call triggers the RtmpStreamingStateChanged callback on the local client to report the state of adding a local stream to the CDN.

    Note

    • Ensure that you enable the RTMP Converter service before using this function. See Prerequisites in Push Streams to CDN.
    • Ensure that the user joins a channel before calling this method.
    • This method can only be called by a host in a LiveBroadcasting channel.
    • This method adds only one CDN streaming URL each time it is called.
    • Agora supports pushing media streams in RTMPS protocol to the CDN only when you enable transcoding.

    Parameters

    • url: string

      The CDN streaming URL in the RTMP or RTMPS format. The maximum length of this parameter is 1024 bytes. The URL address must not contain special characters, such as Chinese language characters.

    • transcodingEnabled: boolean

      Whether to enable transcoding. If you set this parameter as true, ensure that you call the setLiveTranscoding method before this method.

      • true: Enable transcoding. To transcode the audio or video streams when publishing them to CDN live, often used for combining the audio and video streams of multiple hosts in CDN live.
      • false: Disable transcoding.

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • 2(InvalidArgument): Invalid parameter, usually because the URL address is null or the string length is 0.
      • 7(NotInitialized): You have not initialized RtcEngine when publishing the stream.

adjustUserPlaybackSignalVolume

  • adjustUserPlaybackSignalVolume(uid: number, volume: number): Promise<void>
  • Adjusts the playback volume of a specified remote user.

    You can call this method as many times as necessary to adjust the playback volume of different remote users, or to repeatedly adjust the playback volume of the same remote user.

    Note

    • Call this method after joining a channel.
    • The playback volume here refers to the mixed volume of a specified remote user.
    • This method can only adjust the playback volume of one specified remote user at a time. To adjust the playback volume of different remote users, call the method as many times, once for each remote user.

    Parameters

    • uid: number

      ID of the remote user.

    • volume: number

      The playback volume of the specified remote user. The value ranges from 0 to 100:

      • 0: Mute.
      • 100: The original volume.

    Returns Promise<void>

createDataStream

  • createDataStream(reliable: boolean, ordered: boolean): Promise<number>
  • Creates a data stream.

    deprecated

    This method is deprecated from v3.3.1. Use the createDataStreamWithConfig method instead.

    Each user can create up to five data streams during the life cycle of the RtcChannel instance.

    Note

    Set both the reliable and ordered parameters to true or false. Do not set one as true and the other as false.

    Parameters

    • reliable: boolean

      Sets whether the recipients are guaranteed to receive the data stream from the sender within five seconds.

      • true: The recipients receive the data from the sender within five seconds. If the recipient does not receive the data within five seconds, the SDK triggers the StreamMessageError callback and returns an error code.
      • false: There is no guarantee that the recipients receive the data stream within five seconds and no error message is reported for any delay or missing data stream.
    • ordered: boolean

      Determines whether the recipients receive the data stream in the sent order.

      • true: The recipients receive the data in the sent order.
      • false: The recipients do not receive the data in the sent order.

    Returns Promise<number>

    • Returns the stream ID, if the method call is successful.
    • An error code if the method call fails.

createDataStreamWithConfig

  • Creates a data stream.

    since

    v3.3.1.

    Each user can create up to five data streams in a single channel.

    This method does not support data reliability. If the receiver receives a data packet five seconds or more after it was sent, the SDK directly discards the data.

    Parameters

    Returns Promise<number>

    • The stream ID if the method call succeeds.
    • An error code if the method call fails.

destroy

  • destroy(): Promise<void>
  • Destroys the RtcChannel instance.

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • 7(NotInitialized): The RtcChannel instance is not initialized before calling this method.

enableEncryption

  • Enables/Disables the built-in encryption.

    since

    v3.1.2.

    In scenarios requiring high security, Agora recommends calling enableEncryption to enable the built-in encryption before joining a channel.

    After a user leaves the channel, the SDK automatically disables the built-in encryption. To re-enable the built-in encryption, call this method before the user joins the channel again.

    As of v3.4.5, Agora recommends using either the AES128GCM2 or AES256GCM2 encryption mode, both of which support adding a salt and are more secure. For details, see Media Stream Encryption.

    Warning All users in the same channel must use the same encryption mode, encryption key, and salt; otherwise, users cannot communicate with each other.

    Note

    • If you enable the built-in encryption, you cannot use the RTMP or RTMPS streaming function.
    • To enhance security, Agora recommends using a new key and salt every time you enable the media stream encryption.

    Parameters

    • enabled: boolean

      Whether to enable the built-in encryption.

      • true: Enable the built-in encryption.
      • false: Disable the built-in encryption.
    • config: EncryptionConfig

      Configurations of built-in encryption schemas. See EncryptionConfig.

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • 2(InvalidArgument): An invalid parameter is used. Set the parameter with a valid value.
      • 4(NotSupported): The encryption mode is incorrect or the SDK fails to load the external encryption library. Check the enumeration or reload the external encryption library.
      • 7(NotInitialized): The SDK is not initialized. Initialize the RtcEngine instance before calling this method.

enableRemoteSuperResolution

  • enableRemoteSuperResolution(uid: number, enabled: boolean): Promise<void>
  • Enables/Disables the super-resolution algorithm for a remote user's video stream.

    since

    v3.5.2

    This feature effectively boosts the resolution of a remote user's video seen by the local user. If the original resolution of a remote user's video is a × b, the local user's device can render the remote video at a resolution of 2a × 2b after you enable this feature.

    After calling this method, the SDK triggers the UserSuperResolutionEnabled callback to report whether you have successfully enabled super resolution.

    Warning The original resolution of the remote user's video cannot exceed a certain range. If the local user use super resolution on Android, the original resolution of the remote user's video cannot exceed 640 × 360 pixels; if the local user use super resolution on iOS, the original resolution of the remote user's video cannot exceed 640 × 480 pixels.

    If you exceed these limitations, the SDK triggers the {@link IRtcEngineEventHandler#onWarning onWarning} callback and returns the corresponding warning codes:

    • SuperResolutionStreamOverLimitation(1610): The original resolution of the remote user's video is beyond the range where super resolution can be applied.
    • SuperResolutionUserCountOverLimitation(1611): Super resolution is already being used to boost another remote user's video.
    • SuperResolutionDeviceNotSupported(1612): The device does not support using super resolution.

    Note Because this method has certain system performance requirements, Agora recommends that you use the following devices or better:

    • Android:
      • VIVO: V1821A, NEX S, 1914A, 1916A, 1962A, 1824BA, X60, X60 Pro
      • OPPO: PCCM00, Find X3
      • OnePlus: A6000
      • Xiaomi: Mi 8, Mi 9, Mi 10, Mi 11, MIX3, Redmi K20 Pro
      • SAMSUNG: SM-G9600, SM-G9650, SM-N9600, SM-G9708, SM-G960U, SM-G9750, S20, S21
      • HUAWEI: SEA-AL00, ELE-AL00, VOG-AL00, YAL-AL10, HMA-AL00, EVR-AN00, nova 4, nova 5 Pro, nova 6 5G, nova 7 5G, Mate 30, Mate 30 Pro, Mate 40, Mate 40 Pro, P40 P40 Pro, HUAWEI MediaPad M6, MatePad 10.8
    • iOS (iOS 12.0 or later):
      • iPhone XR
      • iPhone XS
      • iPhone XS Max
      • iPhone 11
      • iPhone 11 Pro
      • iPhone 11 Pro Max
      • iPhone 12
      • iPhone 12 mini
      • iPhone 12 Pro
      • iPhone 12 Pro Max
      • iPhone 12 SE (2nd generation)
      • iPad Pro 11-inch (3rd generation)
      • iPad Pro 12.9-inch (3rd generation)
      • iPad Air (3rd generation)
      • iPad Air (4th generation)

    Parameters

    • uid: number

      The user ID of the remote user.

    • enabled: boolean

      Determines whether to enable super resolution for the remote user's video:

      • true: Enable super resolution.
      • false: Do not enable super resolution.

    Returns Promise<void>

getCallId

  • getCallId(): Promise<string>
  • Gets the current call ID.

    Returns Promise<string>

    • The current call ID, if the method call succeeds.
    • The empty string "", if the method call fails.

getConnectionState

joinChannel

  • joinChannel(token: string | undefined | null, optionalInfo: string | undefined | null, optionalUid: number, options: ChannelMediaOptions): Promise<void>
  • Joins the channel with a user ID.

    Note

    • If you are already in a channel, you cannot rejoin it with the same UID.
    • If you want to join the same channel from different devices, ensure that the UIDs in all devices are different.
    • Ensure that the app ID you use to generate the token is the same with the app ID used when creating the RtcEngine instance.

    Compared with the joinChannel method in the RtcEngine class, this method supports joining multiple channels at a time by creating multiple IChannel objects and then calling joinChannel in each RtcChannel object.

    Once the user joins the channel, the user publishes the local audio and video streams and automatically subscribes to the audio and video streams of all the other users in the channel. Subscribing incurs all associated usage costs. To unsubscribe, set the options parameter or call the mute methods accordingly.

    Parameters

    • token: string | undefined | null

      The token generated at your server. See Authenticate Your Users with Tokens.

    • optionalInfo: string | undefined | null

      Additional information about the channel. This parameter can be set as null. Other users in the channel do not receive this information.

    • optionalUid: number

      The user ID. A 32-bit unsigned integer with a value ranging from 1 to (232-1). This parameter must be unique. If uid is not assigned (or set as 0), the SDK assigns a uid and reports it in the JoinChannelSuccess callback. The app must maintain this user ID.

    • options: ChannelMediaOptions

      The channel media options.

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • 2(InvalidArgument): The parameter is invalid.
      • 3(NotReady): The SDK fails to be initialized. You can try re-initializing the SDK.
      • 5(Refused): The request is rejected. Possible reasons:
        • You have created an RtcChannel object with the same channel name.
        • You have joined and published a stream in a channel created by the RtcChannel object.
      • 7(NotInitialized): The SDK is not initialized.
      • 17(JoinChannelRejected): The request to join the channel is rejected. The SDK does not support joining the same RtcChannel channel repeatedly. Therefore, the SDK returns this error code when a user who has already joined an RtcChannel channel calls the joining channel method of this RtcChannel object.

joinChannelWithUserAccount

  • joinChannelWithUserAccount(token: string | undefined | null, userAccount: string, options: ChannelMediaOptions): Promise<void>
  • Joins a channel with the user account.

    Note

    • If you are already in a channel, you cannot rejoin it with the same user account.
    • If you want to join the same channel from different devices, ensure that the user accounts in all devices are different.
    • Ensure that the app ID you use to generate the token is the same with the app ID used when creating the RtcEngine instance.
    • Before using a String user name, ensure that you read How can I use string user names for getting details about the limitations and implementation steps.

    Compared with the [joinChannelWithUserAccount]{@link RtcEngine..joinChannelWithUserAccount} method in the RtcEngine class, this method supports joining multiple channels at a time by creating multiple RtcChannel objects and then calling joinChannelWithUserAccount in each RtcChannel object.

    Once the user joins the channel, the user publishes the local audio and video streams and automatically subscribes to the audio and video streams of all the other users in the channel. Subscribing incurs all associated usage costs. To unsubscribe, set the options parameter or call the mute methods accordingly.

    Parameters

    • token: string | undefined | null

      The token generated at your server. See Authenticate Your Users with Tokens.

    • userAccount: string

      The user account. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as null.

      • All lowercase English letters: a to z.
      • All uppercase English letters: A to Z.
      • All numeric characters: 0 to 9.
      • The space character.
      • Punctuation characters and other symbols, including: "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".
    • options: ChannelMediaOptions

      The channel media options.

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • 2(InvalidArgument): The parameter is invalid.
      • 3(NotReady): The SDK fails to be initialized. You can try re-initializing the SDK.
      • 5(Refused): The request is rejected.
      • 17(JoinChannelRejected): The request to join the channel is rejected. The SDK does not support joining the same RtcChannel channel repeatedly. Therefore, the SDK returns this error code when a user who has already joined an RtcChannel channel calls the joining channel method of this RtcChannel object.

leaveChannel

  • leaveChannel(): Promise<void>
  • Leaves the current channel.

    A successful call of this method triggers the following callbacks:

    • The local client: LeaveChannel.
    • The remote client: UserOffline, if the user leaving the channel is in a Communication channel, or is a host in a LiveBroadcasting channel.

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • 1(Failed): A general error occurs (no specified reason).
      • 2(InvalidArgument): The parameter is invalid.
      • 7(NotInitialized): The SDK is not initialized.

muteAllRemoteAudioStreams

  • muteAllRemoteAudioStreams(muted: boolean): Promise<void>
  • Stops or resumes subscribing to the audio streams of all remote users.

    After successfully calling this method, the local user stops or resumes subscribing to the audio streams of all remote users, including all subsequent users.

    Note

    • Call this method after joining a channel.
    • As of v3.3.1, this method contains the function of setDefaultMuteAllRemoteAudioStreams. Agora recommend not calling muteAllRemoteAudioStreams and setDefaultMuteAllRemoteAudioStreams together; otherwise, the settings may not take effect. See Set the Subscribing State.

    Parameters

    • muted: boolean

      Sets whether to stop subscribing to the audio streams of all remote users.

      • true: Stop subscribing to the audio streams of all remote users.
      • false: (Default) Resume subscribing to the audio streams of all remote users.

    Returns Promise<void>

muteAllRemoteVideoStreams

  • muteAllRemoteVideoStreams(muted: boolean): Promise<void>
  • Stops or resumes subscribing to the video streams of all remote users.

    After successfully calling this method, the local user stops or resumes subscribing to the video streams of all remote users, including all subsequent users.

    Note

    • Call this method after joining a channel.
    • As of v3.3.1, this method contains the function of setDefaultMuteAllRemoteVideoStreams. Agora recommend not calling muteAllRemoteVideoStreams and setDefaultMuteAllRemoteVideoStreams together; otherwise, the settings may not take effect. See Set the Subscribing State.

    Parameters

    • muted: boolean

      Sets whether to stop subscribing to the video streams of all remote users.

      • true: Stop subscribing to the video streams of all remote users.
      • false: (Default) Resume subscribing to the video streams of all remote users.

    Returns Promise<void>

muteLocalAudioStream

  • muteLocalAudioStream(muted: boolean): Promise<void>
  • Stops or resumes publishing the local audio stream.

    since

    v3.4.5

    This method only sets the publishing state of the audio stream in the channel of RtcChannel. A successful method call triggers the RemoteAudioStateChanged callback on the remote client.

    You can only publish the local stream in one channel at a time. If you create multiple channels, ensure that you only call muteLocalAudioStream(false) in one channel; otherwise, the method call fails, and the SDK returns -5 (ERR_REFUSED).

    Note

    • This method does not change the usage state of the audio-capturing device.
    • Whether this method call takes effect is affected by the joinChannel and setClientRole methods. For details, see Set the Publishing State.

    Parameters

    • muted: boolean

      Sets whether to stop publishing the local audio stream:

      • true: Stop publishing the local audio stream.
      • false: Resume publishing the local audio stream.

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • -5 (ERR_REFUSED): The request is rejected.

muteLocalVideoStream

  • muteLocalVideoStream(muted: boolean): Promise<void>
  • Stops or resumes publishing the local video stream.

    since

    v3.4.5

    This method only sets the publishing state of the video stream in the channel of RtcChannel.

    A successful method call triggers the RemoteVideoStateChanged callback on the remote client.

    You can only publish the local stream in one channel at a time. If you create multiple channels, ensure that you only call muteLocalVideoStream(false) in one channel; otherwise, the method call fails, and the SDK returns -5 (ERR_REFUSED).

    Note

    • This method does not change the usage state of the video-capturing device.
    • Whether this method call takes effect is affected by the joinChannel and setClientRole methods. For details, see Set the Publishing State.

    Parameters

    • muted: boolean

      Sets whether to stop publishing the local video stream:

      • true: Stop publishing the local video stream.
      • false: Resume publishing the local video stream.

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • -5 (ERR_REFUSED): The request is rejected.

muteRemoteAudioStream

  • muteRemoteAudioStream(uid: number, muted: boolean): Promise<void>
  • Stops/Resumes receiving the audio stream of the specified user.

    Parameters

    • uid: number

      ID of the remote user whose audio stream you want to mute.

    • muted: boolean

      Determines whether to receive/stop receiving the audio stream of the specified user:

      • true: Stop receiving the audio stream of the user.
      • false: (Default) Receive the audio stream of the user.

    Returns Promise<void>

muteRemoteVideoStream

  • muteRemoteVideoStream(uid: number, muted: boolean): Promise<void>
  • Stops/Resumes receiving the video stream of the specified user.

    Parameters

    • uid: number

      ID of the remote user whose video stream you want to mute.

    • muted: boolean

      Determines whether to receive/stop receiving the video stream of the specified user:

      • true: Stop receiving the video stream of the user.
      • false: (Default) Receive the video stream of the user.

    Returns Promise<void>

pauseAllChannelMediaRelay

  • pauseAllChannelMediaRelay(): Promise<void>
  • Pauses the media stream relay to all destination channels.

    since

    v3.5.2

    After the cross-channel media stream relay starts, you can call this method to pause relaying media streams to all destination channels; after the pause, if you want to resume the relay, call resumeAllChannelMediaRelay.

    After a successful method call, the SDK triggers the ChannelMediaRelayEvent callback to report whether the media stream relay is successfully paused.

    Note Call this method after the startChannelMediaRelay method.

    Returns Promise<void>

publish

  • publish(): Promise<void>
  • Publishes the local stream to the channel.

    deprecated

    This method is deprecated as of v3.4.5. Use muteLocalAudioStream(false) or muteLocalVideoStream(false) instead.

    You must keep the following restrictions in mind when calling this method. Otherwise, the SDK returns the Refused(-5):

    • This method publishes one stream only to the channel corresponding to the current RtcChannel instance.
    • In a LiveBroadcasting channel, only a host can call this method. To switch the client role, call setClientRole of the current RtcChannel instance.
    • You can publish a stream to only one channel at a time. For details, see the advanced guide Join Multiple Channels.

    Returns Promise<void>

registerMediaMetadataObserver

  • registerMediaMetadataObserver(): Promise<void>
  • Registers the metadata observer.

    A successful call of this method triggers the setMaxMetadataSize method.

    This method enables you to add synchronized metadata in the video stream for more diversified live streaming interactions, such as sending shopping links, digital coupons, and online quizzes.

    Note

    Returns Promise<void>

removeAllListeners

  • removeAllListeners<EventType>(event?: EventType): void

removeListener

  • removeListener<EventType>(event: EventType, listener: RtcChannelEvents[EventType], subscription?: EmitterSubscription): void
  • Removes the RtcChannelEvents handler.

    For callback events that you only want to listen for once, call this method to remove the specific RtcEngineEvents objects after you have received them.

    Type parameters

    Parameters

    • event: EventType

      The event type.

    • listener: RtcChannelEvents[EventType]

      The RtcChannelEvents handler.

    • Optional subscription: EmitterSubscription

    Returns void

removePublishStreamUrl

  • removePublishStreamUrl(url: string): Promise<void>
  • Removes an RTMP or RTMPS stream from the CDN.

    deprecated

    This method is deprecated as of v3.6.2. See Release Notes for an alternative solution.

    This method removes the CDN streaming URL (added by addPublishStreamUrl) from a CDN live stream. The SDK reports the result of this method call in the RtmpStreamingStateChanged callback.

    Note

    • Ensure that you enable the RTMP Converter service before using this function. See Prerequisites in Push Streams to CDN.
    • This method can only be called by a host in a LiveBroadcasting channel.
    • This method removes only one CDN streaming URL each time it is called.

    Parameters

    • url: string

      The CDN streaming URL to be removed. The maximum length of this parameter is 1024 bytes. The URL address must not contain special characters, such as Chinese language characters.

    Returns Promise<void>

renewToken

  • renewToken(token: string): Promise<void>
  • Renews the token when the current token expires.

    In the following situations, the SDK decides that the current token has expired:

    You should get a new token from your server and call this method to renew it. Failure to do so results in the SDK disconnecting from the Agora server.

    Parameters

    • token: string

      The new token.

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • 1(Failed): A general error occurs (no specified reason).
      • 2(InvalidArgument): The parameter is invalid.
      • 7(NotInitialized): The SDK is not initialized.

resumeAllChannelMediaRelay

  • resumeAllChannelMediaRelay(): Promise<void>
  • Resumes the media stream relay to all destination channels.

    since

    v3.5.2

    After calling the pauseAllChannelMediaRelay method, you can call this method to resume relaying media streams to all destination channels.

    After a successful method call, the SDK triggers the ChannelMediaRelayEvent callback to report whether the media stream relay is successfully resumed.

    Note Call this method after the pauseAllChannelMediaRelay method.

    Returns Promise<void>

sendMetadata

  • sendMetadata(metadata: string): Promise<void>
  • Sends the metadata.

    Parameters

    • metadata: string

      The metadata to be sent.

    Returns Promise<void>

sendStreamMessage

  • sendStreamMessage(streamId: number, message: string): Promise<void>
  • Sends the data stream message.

    The SDK has the following restrictions on this method:

    • Up to 30 packets can be sent per second in a channel with each packet having a maximum size of 1 KB.
    • Each client can send up to 6 KB of data per second.
    • Each user can have up to five data channels simultaneously.

    A successful call of this method triggers the StreamMessage callback on the remote client, from which the remote user gets the stream message.

    A failed call of this method triggers the StreamMessageError callback on the remote client.

    Parameters

    • streamId: number

      ID of the sent data stream returned by the createDataStream method.

    • message: string

      The message data.

    Returns Promise<void>

setClientRole

  • Sets the role of a user in live interactive streaming.

    In the LiveBroadcasting profile, the SDK sets the user role as audience by default. You can call setClientRole to set the user role as host.

    You can call this method either before or after joining a channel. If you call this method to switch the user role after joining a channel, the SDK automatically does the following:

    Note

    • This method applies to the LiveBroadcasting profile only (when the profile parameter in setChannelProfile is set as LiveBroadcasting).
    • As of v3.2.0, this method can set the user level in addition to the user role.
      • The user role determines the permissions that the SDK grants to a user, such as permission to send local streams, receive remote streams, and push streams to a CDN address.
      • The user level determines the level of services that a user can enjoy within the permissions of the user's role. For example, an audience member can choose to receive remote streams with low latency or ultra low latency. User level affects the pricing of services.

    Parameters

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • 1(Failed): A general error occurs (no specified reason).
      • 2(InvalidArgument): The parameter is invalid.
      • 5(Refused): The request is rejected. In multichannel scenarios, if you have set any of the following in one channel, the SDK returns this error code when the user switches the user role to host in another channel:
        • Call joinChannel with the options parameter and use the default settings publishLocalAudio = true or publishLocalVideo = true.
        • Call setClientRole to set the user role as host.
        • Call muteLocalAudioStream(false) or muteLocalVideoStream(false).
      • 7(NotInitialized): The SDK is not initialized.

setDefaultMuteAllRemoteAudioStreams

  • setDefaultMuteAllRemoteAudioStreams(muted: boolean): Promise<void>
  • Sets whether to receive all remote audio streams by default.

    deprecated

    This method is deprecated from v3.3.1.

    Stops or resumes subscribing to the audio streams of all remote users by default.

    Call this method after joining a channel. After successfully calling this method, the local user stops or resumes subscribing to the audio streams of all subsequent users.

    Note If you need to resume subscribing to the audio streams of remote users in the channel after calling setDefaultMuteAllRemoteAudioStreams(true), do the following:

    Parameters

    • muted: boolean

      Sets whether to stop subscribing to the audio streams of all remote users by default. - true: Stop subscribing to the audio streams of all remote users by default. - false: (Default) Resume subscribing to the audio streams of all remote users by default.

    Returns Promise<void>

setDefaultMuteAllRemoteVideoStreams

  • setDefaultMuteAllRemoteVideoStreams(muted: boolean): Promise<void>
  • Sets whether to receive all remote video streams by default.

    deprecated

    This method is deprecated from v3.3.1.

    Stops or resumes subscribing to the video streams of all remote users by default.

    Call this method after joining a channel. After successfully calling this method, the local user stops or resumes subscribing to the video streams of all subsequent users.

    Note If you need to resume subscribing to the video streams of remote users in the channel after calling setDefaultMuteAllRemoteVideoStreams(true), do the following:

    • If you need to resume subscribing to the video stream of a specified user, call muteRemoteVideoStream(false), and specify the user ID.
    • If you need to resume subscribing to the video streams of multiple remote users, call muteRemoteVideoStream(false) multiple times.

    Parameters

    • muted: boolean

      Sets whether to stop subscribing to the video streams of all remote users by default. - true: Stop subscribing to the video streams of all remote users by default. - false: (Default) Resume subscribing to the video streams of all remote users by default.

    Returns Promise<void>

setEncryptionMode

  • Sets the built-in encryption mode.

    deprecated

    Deprecated as of v3.1.2. Use enableEncryption instead.

    The Agora SDK supports built-in encryption, which is set to aes-128-xts mode by default. Call this method to set the encryption mode to use other encryption modes. All users in the same channel must use the same encryption mode and password. Refer to the information related to the AES encryption algorithm on the differences between the encryption modes.

    Note

    • Do not use this method for CDN streaming.
    • Before calling this method, ensure that you have called setEncryptionSecret to enable encryption.

    Parameters

    Returns Promise<void>

setEncryptionSecret

  • setEncryptionSecret(secret: string): Promise<void>
  • Enables built-in encryption with an encryption password before joining a channel.

    deprecated

    Deprecated as of v3.1.2. Use enableEncryption instead.

    All users in a channel must set the same encryption password. The encryption password is automatically cleared once a user leaves the channel. If the encryption password is not specified or set to empty, the encryption functionality is disabled.

    Note

    • For optimal transmission, ensure that the encrypted data size does not exceed the original data size + 16 bytes. 16 bytes is the maximum padding size for AES encryption.
    • Do not use this method for CDN live streaming.

    Parameters

    • secret: string

      The encryption password.

    Returns Promise<void>

setLiveTranscoding

  • Sets the video layout and audio settings for CDN live.

    deprecated

    This method is deprecated as of v3.6.2. See Release Notes for an alternative solution.

    The SDK triggers the TranscodingUpdated callback when you call this method to update the LiveTranscoding class. If you call this method to set the LiveTranscoding class for the first time, the SDK does not trigger the TranscodingUpdated callback.

    Note

    • Ensure that you enable the RTMP Converter service before using this function. See Prerequisites in Push Streams to CDN.
    • Ensure that the user joins a channel before calling this method.
    • This method can only be called by a host in a LiveBroadcasting channel.
    • Ensure that you call this method before calling the addPublishStreamUrl method.
    • Agora supports pushing media streams in RTMPS protocol to the CDN only when you enable transcoding.

    Parameters

    • transcoding: LiveTranscoding

      Sets the CDN live audio/video transcoding settings.

    Returns Promise<void>

setMaxMetadataSize

  • setMaxMetadataSize(size: number): Promise<void>
  • Sets the maximum size of the metadata.

    Parameters

    • size: number

      Buffer size of the sent or received metadata.

    Returns Promise<void>

setRemoteDefaultVideoStreamType

  • setRemoteDefaultVideoStreamType(streamType: VideoStreamType): Promise<void>
  • Sets the default video-stream type of the remotely subscribed video stream when the remote user sends dual streams.

    Note

    • This method can only be called before joining a channel. Agora does not support you to change the default subscribed video stream type after joining a channel.
    • If you call both this method and setRemoteVideoStreamType, the SDK applies the settings in the setRemoteVideoStreamType method.

    Parameters

    Returns Promise<void>

setRemoteUserPriority

  • setRemoteUserPriority(uid: number, userPriority: UserPriority): Promise<void>
  • Sets the priority of a remote user's media stream.

    Use this method with the setRemoteSubscribeFallbackOption method. If a remote video stream experiences the fallback, the SDK ensures the high-priority user gets the best possible stream quality.

    Note The Agora SDK supports setting userPriority as high for one user only.

    Parameters

    • uid: number

      The ID of the remote user.

    • userPriority: UserPriority

      The priority of the remote user.

    Returns Promise<void>

setRemoteVideoStreamType

  • setRemoteVideoStreamType(uid: number, streamType: VideoStreamType): Promise<void>
  • Sets the video stream type of the remote video stream when the remote user sends dual streams. This method allows the app to adjust the corresponding video-stream type based on the size of the video window to reduce the bandwidth and resources.

    • If the remote user enables the dual-stream mode by calling the enableDualStreamMode method, the SDK receives the high-video stream by default. You can use this method to switch to the low-video stream.
    • If dual-stream mode is not enabled, the SDK receives the high-stream video by default. By default, the aspect ratio of the low-video stream is the same as the high-video stream. Once the resolution of the high-video stream is set, the system automatically sets the resolution, frame rate, and bitrate of the low-video stream.

    Parameters

    • uid: number

      ID of the remote user sending the video stream.

    • streamType: VideoStreamType

      Sets the video-stream type.

    Returns Promise<void>

setRemoteVoicePosition

  • setRemoteVoicePosition(uid: number, pan: number, gain: number): Promise<void>
  • Sets the sound position of a remote user.

    When the local user calls this method to set the sound position of a remote user, the sound difference between the left and right channels allows the local user to track the real-time position of the remote user, creating a real sense of space. This method applies to massively multiplayer online games, such as Battle Royale games.

    Note

    • For this method to work, enable stereo panning for remote users by calling the enableSoundPositionIndication method before joining a channel.
    • This method requires hardware support. For the best sound positioning, we recommend using a stereo headset.

    Parameters

    • uid: number

      The ID of the remote user.

    • pan: number

      The sound position of the remote user. The value ranges from -1.0 to 1.0:

      • 0.0: (default) The remote sound comes from the front.
      • -1.0: The remote sound comes from the left.
      • 1.0: The remote sound comes from the right.
    • gain: number

      Gain of the remote user. The value ranges from 0.0 to 100.0. The default value is 100.0 (the original gain of the remote user). The smaller the value, the less the gain.

    Returns Promise<void>

startChannelMediaRelay

startRtmpStreamWithTranscoding

  • startRtmpStreamWithTranscoding(url: string, transcoding: LiveTranscoding): Promise<void>
  • Starts pushing media streams to a CDN and sets the transcoding configuration.

    since

    v3.6.2

    You can call this method to push a live audio-and-video stream to the specified CDN address and set the transcoding configuration. This method can push media streams to only one CDN address at a time, so if you need to push streams to multiple addresses, call this method multiple times.

    After you call this method, the SDK triggers the RtmpStreamingStateChanged callback on the local client to report the state of the streaming.

    Note

    • Ensure that you enable the RTMP Converter service before using this function. See Prerequisites in Media Push.
    • Call this method after joining a channel.
    • Only hosts in the LiveBroadcasting profile can call this method.
    • If you want to retry pushing streams after a failed push, make sure to call stopRtmpStream first, then call this method to retry pushing streams; otherwise, the SDK returns the same error code as the last failed push.

    Parameters

    • url: string

      The address of the CDN live streaming. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.

    • transcoding: LiveTranscoding

      The transcoding configuration for CDN live streaming. See LiveTranscoding.

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • 2(InvalidArgument): url is null or the string length is 0.
      • 7(NotInitialized): The SDK is not initialized before calling this method.

startRtmpStreamWithoutTranscoding

  • startRtmpStreamWithoutTranscoding(url: string): Promise<void>
  • Starts pushing media streams to a CDN without transcoding.

    since

    v3.6.2

    You can call this method to push a live audio-and-video stream to the specified CDN address. This method can push media streams to only one CDN address at a time, so if you need to push streams to multiple addresses, call this method multiple times.

    After you call this method, the SDK triggers the RtmpStreamingStateChanged callback on the local client to report the state of the streaming.

    Note

    • Ensure that you enable the RTMP Converter service before using this function. See Prerequisites in Media Push.
    • Call this method after joining a channel.
    • Only hosts in the LiveBroadcasting profile can call this method.
    • If you want to retry pushing streams after a failed push, make sure to call stopRtmpStream first, then call this method to retry pushing streams; otherwise, the SDK returns the same error code as the last failed push.

    Parameters

    • url: string

      The address of the CDN live streaming. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.

    Returns Promise<void>

    • Void if the method call succeeds.
    • An error code if the method call fails. Possible errors include:
      • 2(InvalidArgument): url is null or the string length is 0.
      • 7(NotInitialized): The SDK is not initialized before calling this method.

stopChannelMediaRelay

  • stopChannelMediaRelay(): Promise<void>

stopRtmpStream

  • stopRtmpStream(url: string): Promise<void>
  • Stops pushing media streams to a CDN.

    since

    v3.6.2

    You can call this method to stop the live stream on the specified CDN address. This method can stop pushing media streams to only one CDN address at a time, so if you need to stop pushing streams to multiple addresses, call this method multiple times.

    After you call this method, the SDK triggers the RtmpStreamingStateChanged callback on the local client to report the state of the streaming.

    Parameters

    • url: string

      The address of the CDN live streaming. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.

    Returns Promise<void>

unpublish

  • unpublish(): Promise<void>

unregisterMediaMetadataObserver

  • unregisterMediaMetadataObserver(): Promise<void>
  • Unregisters the metadata observer.

    Returns Promise<void>

updateChannelMediaRelay

  • Updates the channels for media relay.

    After the channel media relay starts, if you want to relay the media stream to more channels, or leave the current relay channel, you can call this method. After a successful method call, the SDK triggers the ChannelMediaRelayEvent callback with the UpdateDestinationChannel(7) state code.

    Note

    • Call this method after the startChannelMediaRelay method to update the destination channel.
    • This method supports adding at most four destination channels in the relay.

    Parameters

    Returns Promise<void>

updateRtmpTranscoding

  • Updates the transcoding configuration.

    since

    v3.6.2

    After you start pushing media streams to CDN with transcoding, you can dynamically update the transcoding configuration according to the scenario. The SDK triggers the TranscodingUpdated callback after the transcoding configuration is updated.

    Parameters

    Returns Promise<void>

Static create

  • Creates and gets an RtcChannel instance.

    To join more than one channel, call this method multiple times to create as many RtcChannel instances as needed, and call the joinChannel method of each created RtcChannel object.

    After joining multiple channels, you can simultaneously subscribe to streams of all the channels, but publish a stream in only one channel at one time.

    Parameters

    • channelId: string

      The unique channel name for the Agora RTC session in the string format. The string length must be less than 64 bytes. Supported character scopes are:

      • All lowercase English letters: a to z.
      • All uppercase English letters: A to Z.
      • All numeric characters: 0 to 9.
      • The space character.
      • Punctuation characters and other symbols, including: "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "=", ".", ">", "?", "@", "[", "]", "^", "_", " {", "}", "|", "~", ",".

      Note

      • This parameter does not have a default value. You must set it.
      • Do not set it as the empty string "". Otherwise, the SDK returns Refused(-5).

    Returns Promise<RtcChannel>

    • An RtcChannel instance, if the method call succeeds.
    • Null, if the method call fails.
    • Refused(-5), if you set channelId as the empty string "".

Static destroyAll

  • destroyAll(): void

Generated using TypeDoc