new SRTC(initParams).
The channel-level methods on this page (publishing, subscribing, user queries, leave, etc.) are equivalent to the methods of the same name on the Channel object returned by join, and act on the current (default) channel. When you join multiple channels at once, call them on each Channel object instead to specify the target. See Multi-channel.
constructor
buildInfo
Gets the SDK build information.getEnvInfo
Gets the WebRTC capability detection result for the current browser. We recommend calling it as early as possible after initialization.EnvWebInfo; see EnvWebInfo
networkCheck
Pre-call network check: call it before joining. It doesn’t require joining a channel and doesn’t use token authentication. It checks 5 items in order (network permission, network connection, MTU, DNS resolution, server connectivity), callsonItem each time an item completes, and finally returns a summary. Each item times out after 3 seconds by default (adjustable with timeoutMs). Within the server connectivity item, the SDK API is tested first, then signaling and media in parallel, so the whole check takes at most about 3 item timeouts (about 9 seconds by default).
Return value:
Promise<NetworkCheckResult>, always 5 items in a fixed order; see Pre-call network check types
- Web platform limitations: browsers have no queryable network permission, can’t access raw UDP, and can’t resolve domain names on their own, so the
permission,mtu, anddnsitems are alwaysunsupported(DNS resolution failures show up in the server connectivity item). Signaling is tested over WebSocket only. - When the server’s streaming media isn’t seastart, the media sub-check in the server connectivity item is
skipped(vendor_not_supported). - The server must provide the network check API. With an older server version that lacks it, the server connectivity item is
fail(api_unreachable, withdata.api.httpStatus404), and the signaling and media sub-checks areskipped. - An instance can run only one check at a time; calling it again while a check is in progress throws
106005. When canceled by cancelNetworkCheck, it throws106026. WhenappId/serverUrlis missing andtokencan’t be decoded, it throws106031.destroy()automatically cancels a check in progress.
cancelNetworkCheck
Cancels the network check in progress;networkCheck then ends with 106026 (Cancelled). Has no effect when no check is running.
onNotifyChannelEvent
In-channel event callback. We recommend registering it beforejoin.
onNotifyImEvent
Out-of-channel IM event callback.join
Joins a channel and returns that channel’s Channel object. Get the channel info withchannel.getInfo().
You can call it multiple times to join several channels at once. Single-channel apps can ignore the return value and keep using the channel-level methods on the
srtc instance (which act on the current channel). For the Channel object’s methods and multi-channel usage, see Multi-channel.
Migrating from older versions:joinused to returnChannelInfoand now returns a Channel object; the old return value is equivalent to(await srtc.join(token)).getInfo().
leave
Leaves the channel. For local tracks, the SDK automatically stops capture, stops playback, or removes play views after leaving.channel.leave(); to leave a specific channel, call leave() on its Channel object directly.
getChannelInfo
Gets the current channel info. Returnsnull when not in a channel.
getUserInfo
Gets the info of a given user in the channel.getUsersInfo
Gets the info of all users in the channel, as either an array or a map.getStreamMetric
Gets the current full media metric snapshot, including overall network statistics and aTrackMetric for each local/remote track.
Throws if called when not in a channel. For field details, see Network quality.
getNetworkStats
Gets the current overall network statistics. Use it when you only care about the network overview (bitrate, packet loss, RTT, available bandwidth); it’s lighter thangetStreamMetric.
Throws if called when not in a channel.
getConnectionQuality
Gets the current connection quality evaluation, returning the uplink/downlink levels, the overall level, MOS, and the triggering reasons. The SDK evaluates internally over a 2-second sliding window.
Throws if called when not in a channel. For apps, we recommend subscribing to the ChannelEventType.CONNECTION_QUALITY_CHANGED event to be notified of changes passively.
getDevices
Enumerates media devices.createLocalMicTrack
Creates a microphone audio track.createLocalCustomAudioTrack
Creates a local audio track from a customMediaStreamTrack.
createLocalCameraTrack
Creates a camera video track.createLocalScreenTrack
Creates a screen sharing video track.A system audio track is created as well by default. Whether system audio can actually be captured also depends on the browser’s capabilities and on whether the user checks “Share audio” in the system sharing dialog.
createLocalCustomVideoTrack
Creates a local video track from a customMediaStreamTrack.
createLocalCompositeRecorder
Creates a local composite recorder, used in the browser to composite the video tiles and audio tracks that the current page needs to record into a local recording file.LocalCompositeRecorder is only responsible for media compositing and the MediaRecorder lifecycle; your app computes the view—video grids, paging, speaker layout, screen sharing priority, and so on—and passes it in through videoItems and updateVideoItems(...).
For detailed usage, see Local recording.
publishLocalTrack
Publishes a local track to the channel; after publishing, remote users can subscribe to it.
Returns:
TrackInfo, a snapshot of this publication’s track description in the channel; to get the latest value later, use channel.getPublishInfo(track).
unpublishLocalTrack
Unpublishes a local track; remote users receive theUSER_TRACK_REMOVE event.
enableLocalTrack
Resumes sending data for a paused local track.Remote users receive theTRACK_UNMUTEDevent. For how it differs frompublishLocalTrack, see Mute vs. unpublish.
disableLocalTrack
Pauses sending data for a local track without unpublishing it.Remote users receive theTRACK_MUTEDevent. For how it differs fromunpublishLocalTrack, see Mute vs. unpublish.
subscribeRemoteAudioMixTrack
Subscribes to the channel-wide mixed audio track.subscribeRemoteAudioTrack
Subscribes to a single audio stream of a given user.subscribeRemoteVideoTrack
Subscribes to a given user’s video stream.subscribeRemoteVideoMcuTrack
Subscribes to the remote composite video stream.RemoteVideoMcuTrackextendsRemoteVideoTrackand can be used like a regular remote video track.
unsubscribeRemoteTrack
Unsubscribes from a remote stream.getRemoteTrack
Gets a subscribed remote track instance by user ID and either track ID or track description.You must pass at least one ofidanddesc; otherwise it throws.
setRemoteUserVolume
Sets the playback volume of a remote user. It only affects how loud you hear that user locally and does not affect other members. A typical use is simultaneous interpretation: lower the speaker’s original voice while the interpretation audio plays, and restore it afterward.
Return value: whether the setting took effect. Returns
false (with a warn log, no exception) when the channel uses server-side mixing or you have already left the channel.
- Applies to all audio tracks of the user (microphone + system audio from screen sharing), and audio tracks the user publishes later pick it up automatically. The setting is cleared when the user leaves the channel; the user has the original volume after joining again
- When playing through
subscribeRemoteAudioMixTrack, the volume is adjusted per user, with a ramp and no popping, and the setting survives resubscribing to the mixed audio track. When playing tracks individually throughsubscribeRemoteAudioTrack, it sets the playback volume of that track (no ramp) - Per-user adjustment isn’t possible with server-side mixing (only one mixed audio stream) or the composite video stream; in that case it returns
false - Parameters are validated before the checks above: invalid parameters always throw
Calling it on thesrtcinstance before joining a channel throwsNotInChannel.
getRemoteUserVolume
Gets the playback volume of a remote user.1 if never set (or the user has left).
playAudioClip
Plays an audio clip into your local audio output (such as interpretation audio for simultaneous interpretation). Only you hear it; it isn’t published to the channel.
Return value: a clip handle
AudioClipHandle, with duration (length in seconds), stop() (stops immediately; safe to call repeatedly), and ended (resolves when playback finishes or is stopped; never rejects).
- While the mixed audio track from
subscribeRemoteAudioMixTrackis playing, the clip is merged into the mix and comes out of the same speaker as remote voices (following the mix’s output device) - In other cases (server-side mixing, per-track playback, or the mixed audio track not yet started with
startPlay), the clip plays through a separate<audio>element. The output device isopt.deviceId; if not passed, it uses the device specified in the laststartPlayof the mixed audio track - When the browser blocks autoplay, the SDK’s built-in prompt dialog appears and playback starts after the user clicks. With
opt.disableAutoPlayDialog: true, no dialog appears and the call rejects withPlayFailed - No queuing: multiple calls play simultaneously on top of each other; queue or interrupt clips in your own code
- When you leave the channel, all clips in progress stop (and
endedresolves)
enableIm
Enables out-of-channel IM messages.
Returns:
Promise<string>, the IM session sid.
disableIm
Disables out-of-channel IM messages.destroy
Fully releases the SRTC instance: leaves all channels in turn, disables IM, and removes the listeners the instance registered on browser global objects (device plug/unplug, page visibility). It’s idempotent—repeated calls return immediately; calling the instance’s methods afterward throws.destroy(), the global listeners keep holding a reference to the instance so it can’t be garbage-collected. So you must call it before an SPA route navigates away from the audio/video page, before a component unmounts, or before you create a new SRTC instance; apps whose instance lives as long as the page don’t need to call it.
For everyday joining and leaving of channels, leave() (or channel.leave()) is enough, and the instance can be reused to join again.