This topic describes the main calling interfaces of the audio and video call Application Programming Interface (API) for web clients.
Connect
Establishes a call connection. The config_param parameter is a struct that contains the following fields.
Parameters:
Request parameter
Type
Required
Description
uid
int
Required
The unique user identifier (UID), passed through from the client.
NoteCurrently, the UID supports only a combination of letters, digits, and underscores. The length cannot exceed 128 characters.
room_server_url
String
Required
The channel server address. The channel server addresses for the Gold and non-Gold environments in the public cloud are different. Select the channel server address based on your current environment.
Non-Gold: wss://mrtc.mpaas.cn-hangzhou.aliyuncs.com/ws
Gold: wss://room.mrtc-fin.cn-shanghai.aliyuncs.com/ws
biz_name
String
Required
The business identifier.
sub_biz
String
Required
The business identifier. This is the corresponding appId in mPaaS. You can obtain it from the mPaaS console.
sign
String
Required
The signature for validation.
Asynchronous callback:
Connection successful:
OnConnectOK()Connection failed:
OnConnectFailed(err_code, err_msg)Callback parameter
Type
Description
err_code
int
Error code:
-101: Initialization timeout.
-102: Initialization failed.
err_msg
String
The status message.
Disconnect
Disconnects the connection. If you are in a call, calling the Disconnect() interface triggers the closing of published and subscribed streams and leaving the channel. The sequence is: Close all streams in the channel > Leave the channel > Disconnect the signaling connection.
Parameters: None.
Asynchronous callback: Connection closed
OnConnectClose()
InitRoomConfig
Initializes the channel.
Parameters:
Request parameter
Type
Description
config_param
{}
The config_param is a struct that contains the fields described in the following table.
config_param parameters:
Request parameter
Type
Required
Description
auto_publish_subscribe
int
Required
The publish and subscribe mode:
1: Auto-subscribe.
2: Auto-publish.
3: Auto-subscribe and auto-publish.
4: Manually operated by the business.
5: Auto-subscribe and auto-publish when other users are in the channel.
engine
int
Optional
The engine type:
0: ALIPAY (default)
1: ALIYUN
2: P2P
third_id
String
-
The business-associated ID. The default is empty.
need_volume_analyser
boolean
-
Specifies whether to obtain real-time volume levels. The default is false.
liveUrl
String
Optional
The streaming URL. This is required when you use the live streaming mode.
publish_type
int
Optional
The stream ingest mode. This is required when you use the live streaming mode.
2: RTC mode
3: Live streaming mode
defaultRecord
boolean
Optional
Specifies whether to enable server-side recording by default. The default is false.
recordStrongDepend
boolean
-
Specifies whether the call strongly depends on recording. The default is true. If this is set to true and the recording fails to start, the audio and video call also fails to connect.
record_third_id
String
-
The third-party ID for the recording. This ID is used by your business to distinguish between call batches and is returned in the callbacks for successful or failed startups. This parameter is optional.
recordParam
JSON
Optional
For more information about the parameters, see the appendix recordParam.
filePath
String
Optional
The server-side recording path. If you specify `filePath`, you must set `defaultRecord` to true.
enableAudio
boolean
Optional
If enableVideo is also unspecified, both default to true.
enableVideo
boolean
Optional
If enableAudio is not specified either, both default to true.
enableDataChannel
boolean
Optional
Specifies whether to use a data channel. This can be used only when `engine` is set to 2. The default is false.
If `auto_publish_subscribe` is 1, the following parameters are required.
Request parameter
Type
Description
initSubscribe
Array
The subscription parameters.
subscribe_video_id
-
Used to display the video stream.
subscribe_audio_id
-
Used to display the subscribed audio stream.
subscribe_streamId_id
-
A label tag used to display the streamId.
feedId_id
-
A label tag used to display the feedId.
Example:
// initSubscribe: An array of subscription parameters. initSubscribe = [ { subscribe_video_id: "video1", subscribe_audio_id: "audio1", subscribe_streamId_id: "streamId", feedId_id: "feedId" },{},{}];If `auto_publish_subscribe` is 2, configure the following parameters:
Request parameter
Type
Required
Description
media_type
int
Required
The audio and video type:
1: Audio and video
2: Audio-only
3: Video-only
publish_bitrate
int
Optional
The maximum bitrate for publishing. The default is 600 Kbps.
publish_device
int
Required
The publishing type:
1: Camera
2: Desktop sharing
3: Publish a file (image or video)
4: Publish a custom page area
5: Publish a custom stream
If `auto_publish_subscribe` is 3 or 5, configure the following parameters:
Request parameter
Type
Required
Description
media_type
int
Required
The audio and video type:
1: Audio and video
2: Audio-only
3: Video-only
publish_bitrate
int
Optional
The maximum bitrate for publishing. The default is 600 Kbps.
publish_device
int
(Required)
The publishing type:
1: Camera
2: Desktop sharing
3: Publish a file (image or video)
4: Publish a custom page area
5: Publish a custom stream
initSubscribe
Array
-
The following parameters are required for subscription initialization:
subscribe_video_id: Used to display the video stream.
subscribe_audio_id: Used to display the subscribed audio stream.
feedId_id: A label tag used to display the feedId.
subscribe_streamId_id: A label tag used to display the streamId.
Example:
// initSubscribe: An array of subscription parameters. initSubscribe = [ { subscribe_video_id: "video1", subscribe_audio_id: "audio1", subscribe_streamId_id: "subscribe_streamId1", feedId_id: "feedId1" },{},{}];If `publish_device` is 1, configure the following parameters:
Request parameter
Type
Required
Description
videoSource
String
Optional
The device ID of the camera, used to publish from a specific camera.
audioSource
String
Optional
The device ID of the microphone, used to publish from a specific microphone.
aspectRatioStrongDepend
boolean
-
Specifies whether to enforce a specific video aspect ratio. The default is false.
aspectRatio
String
Optional
This is required when `aspectRatioStrongDepend` is true.
Video aspect ratio:
1 indicates the 4:3 aspect ratio.
2 represents the 16:9 aspect ratio.
degradationType
int
Optional
Prioritize low definition or high definition:
1. Fluency Priority (default)
2: Prioritize high definition
video_profile_type
int
Optional
The definition level of the local video:
1: 720P, 1280 × 720, 16:9
2: VGA, 640 × 480, 4:3
3: 360P, 640 × 360, 16:9
4: 720P (portrait), 720 × 1280, 9:16
5: 360P (portrait), 360 × 640, 9:16
6: 1080P, 1920 × 1080, 16:9
7: 1080P (portrait), 1080 × 1920, 9:16
8: 90P (portrait), 90 × 160, 9:16
9: 540P, 960 × 540, 16:9
10: 540P (portrait), 540 × 960, 9:16
100: Custom
video_profile_diy
Object
Optional
Custom video width, height, frame rate, and bitrate.
When `video_profile_type` is 100, you must include the `video_profile_diy` parameter and pass in the video width, height, frame rate, and bitrate. Format:
video_profile_diy: {width,height,frameRate,bitrate}.enableDesktopAudio
boolean
Optional
Specifies whether to also cast the audio when screen sharing (only for shared tabs). A value of true indicates that audio is cast.
This is valid only when `publishDevice` is 2.
initPublish
Array
Required
The publishing initialization parameters.
publish_video_id
-
Optional
Used to display the published video stream. This is optional depending on the `media_type`.
publish_streamId_id
-
-
A label tag used to display the streamId.
publish_tag
-
-
Business customization
Example:
// initPublish: An array of publishing parameters. Required. initPublish = [ {publish_video_id: "publish_video1", publish_streamId_id: "publish_streamId1", publish_tag: "tag1"}, {publish_video_id: "publish_video2", publish_streamId_id: "publish_streamId2", publish_tag: "tag2"}, {publish_video_id: "publish_video3", publish_streamId_id: "publish_streamId3", publish_tag: "tag3"} ];
Asynchronous callback:
Channel initialization successful:
OnInitRoomConfigOK()Channel initialization failed:
OnInitRoomConfigFail(err_code, err_msg)Callback parameter
Type
Description
err_code
int
Returned if channel initialization fails:
-201: Incorrect channel state.
-202: Invalid parameters.
-204: E2EE_ikm is empty.
-205: Custom resolution, frame rate, and bitrate parameters are not provided.
err_msg
String
The status message.
CreateRoom
Creates a channel.
Parameters:
Request parameter
Type
Description
sign
String
Signature validation
Asynchronous callback:
Channel created successfully:
OnCreateRoomSucc(room_id, rtoken)Callback parameter
Type
Description
room_id
String
The channel ID.
rtoken
String
The channel token, which is like a channel password.
Channel creation failed:
OnCreateRoomFailed(err_code, err_msg)Callback parameter
Type
Description
err_code
int
Returned if channel creation fails:
-301: Channel not initialized.
-302: Server error.
-303: Channel creation timed out.
-304: Media initialization timed out.
err_msg
String
The status message.
JoinRoom
Joins a channel.
Parameters:
Request parameter
Type
Description
room_id
String
The channel ID.
rtoken
String
The channel token, which is like a channel password.
sign
String
Signature verification
Asynchronous callback:
Joined channel successfully:
OnJoinRoomSucc()Indicates a failure to join the channel:
OnJoinRoomFailed(err_code, err_msg)Callback parameter
Type
Description
err_code
int
Returned if joining the channel fails:
-401: Channel not initialized.
-402: Invalid parameters.
-403: Server error.
-404: Timed out when joining the channel.
err_msg
String
The status message.
Invite to a channel
Invites a user to join the channel.
Parameters:
Request parameter
Type
Description
invitee
String
The UID of the invitee.
channelType
int
The push channel:
0: WEB
1: ALIPAY
extra
String
The business pass-through field.
Asynchronous callback:
Invitation sent successfully:
OnInviteOK()Failed to send invitation:
OnInviteFail(err_code, err_msg)Callback parameter
Type
Description
err_code
int
Returned if sending the invitation fails:
-501: Incorrect channel state.
-502: Server error.
-503: Invalid parameters.
err_msg
String
The status message.
Reply to an invitation
Respond to a channel invitation.
Parameters:
Request parameter
Type
Description
roomId
String
The channel ID.
inviter
String
The UID of the inviter.
reply
int
The invitation reply:
0: Accept
2: Reject
Asynchronous callback:
Reply sent successfully:
OnReplyInviteOK()Failed to send reply:
OnReplyInviteFail(err_code, err_msg)Callback parameter
Type
Description
err_code
int
Failed to send a reply to the invitation to join the channel:
-601: Incorrect channel state.
-602: Server error.
err_msg
String
The status message.
LeaveRoom
Leaves the channel.
Parameters: None.
Asynchronous callback:
OnLeaveRoom(leaveType)Callback parameter
Type
Description
leaveType
int
The type of exit:
1: Normal exit
2: Abnormal exit
3: Kicked from the channel
Publish
Manually publishes a media stream.
Parameters:
Request parameter
Type
Required
Description
media_type
int
Required
The audio and video type:
1: Audio and video
2: Audio-only
3: Video-only
publish_bitrate
int
Optional
The maximum bitrate for publishing. The default is 600 Kbps.
publish_device
int
Required
The publishing type:
1: Camera
2: Desktop sharing
3: Publish a file (image or video)
4: Publish a custom page area
5: Publish a custom stream
video_profile_type
int
Optional
The definition level of the local video:
1: 720P, 1280 × 720, 16:9
2: VGA, 640 × 480, 4:3
3: 360P, 640 × 360, 16:9
4: 720P (portrait), 720 × 1280, 9:16
5: 360P (portrait), 360 × 640, 9:16
6: 1080P, 1920 × 1080, 16:9
7: 1080P (portrait), 1080 × 1920, 9:16
8: 90P (portrait), 90 × 160, 9:16
9: 540P, 960 × 540, 16:9
10: 540P (portrait), 540 × 960, 9:16
100: Custom
video_profile_diy
Object
Optional
Custom video width, height, frame rate, and bitrate.
When `video_profile_type` is 100, you must include the `video_profile_diy` parameter and pass in the video width, height, frame rate, and bitrate. Format:
video_profile_diy: {width,height,frameRate,bitrate}.publish_video_id
-
Optional
Used to display the published video stream. This is optional depending on the `media_type`.
publish_streamId_id
-
-
Used to display the stream ID.
publish_tag
String
-
The business-specified tag.
need_volume_analyser
boolean
-
Specifies whether to obtain real-time volume levels. The default is false.
enableDesktopAudio
boolean
Optional
Specifies whether to also cast the audio when screen sharing (only for shared tabs). A value of true indicates that audio is cast.
This is valid only when `publishDevice` is 2.
file
file
Optional
An image or video file. Example:
let file = document.getElementById('file').files[0];This is required when `publish_device` is 3.
part_of_screen_id
String
Optional
The ID of the div for the area to be shared. Example:
<div id="part_of_screen_id"></div>This is required when `publish_device` is 4.
stream
String
Optional
The media stream. This is required when `publish_device` is 5.
If `publish_device` is 1, configure the following parameters:
Request parameter
Type
Required
Description
videoSource
String
Optional
The device ID of the camera, used to publish from a specific camera.
audioSource
String
Optional
The device ID of the microphone, used to publish from a specific microphone.
aspectRatioStrongDepend
boolean
-
Specifies whether to enforce a specific video aspect ratio. The default is false.
aspectRatio
String
Optional
Video aspect ratio:
A value of 1 represents 4:3.
The value 2 specifies a 16:9 aspect ratio.
ImportantThis is required when `aspectRatioStrongDepend` is true.
degradationType
int
Optional
Prioritize low definition or high definition:
1. Smoothness priority (default)
2: Prioritize high definition
publish_bitrate
int
Optional
The maximum bitrate for publishing the media stream. The default is 600 Kbps.
enableAudio
boolean
Optional
If `enableVideo` is also unspecified, both default to `true`.
enableVideo
boolean
Optional
If `enableAudio` is not specified either, both default to `true`.
Asynchronous callback:
Media stream published successfully:
OnPublishSucc(sid)Callback parameter
Type
Description
sid
int
The ID of the published media stream.
Failed to publish media stream:
OnPublishFailed(sid,err_code, err_msg)Callback parameter
Type
Description
sid
int
The stream ID.
err_code
int
Returned if publishing the media stream fails:
-1071: Server error.
-1072: Video tag not set.
-1073: Publish limit exceeded.
-1074: Timed out when establishing the media link for publishing.
err_msg
String
The status message.
Subscribe
Subscribes to a media stream. The config_param parameter is a struct that contains the following fields:
Parameters:
Field name
Type
Description
subscribe_video_id
String
Used to display the subscribed video stream.
subscribe_audio_id
String
Used to display the subscribed audio stream.
subscribe_streamId_id
String
Used to display the subscribed stream.
feedId_id
String
Used to display the feedId.
feedId
String
The ID of the stream to subscribe to.
need_volume_analyser
boolean
Specifies whether to obtain real-time volume levels. The default is false.
Asynchronous callback:
Subscribed to media stream successfully:
OnSubscribeSucc(feedId,sid)Callback parameter
Type
Description
sid
String
The stream ID.
feedId
String
The stream information.
Example of feedId stream information:
{ "feedId": ["xxx","xxx"], "strategy": 1 } // feedId: list, the ID of the subscribed stream. // strategy: int, the policy.Failed to subscribe to media stream:
OnSubscribeFailed(sid,err_code, err_msg)Callback parameter
Type
Description
sid
String
The stream ID.
err_code
int
Returned if subscribing to the media stream fails:
-1081: Server error.
-1082: The `subscribe_video_id` of the video window is already in use.
-1083: Subscription limit exceeded.
-1084: Failed to establish the media link for subscription.
-1085: The `subscribe_video_id` of the subscription window is empty.
err_msg
String
The status message.
SetLocalAudioEnable
Enables or disables the local microphone.
Parameters:
Request parameter | Type | Description |
enabled | int | Enable or disable the local microphone:
|
sid | int | The stream ID. |
SetLocalVideoEnable
Enables or disables the local camera.
Parameters:
Request parameter | Type | Description |
enabled | int | Enable or disable the local camera:
|
sid | int | The stream ID. |
SetLocalCodecType
Sets the video encoding format.
Parameters:
Request parameter | Type | Description |
type | String | The video encoding format:
|
Take a picture
Takes a screenshot.
Parameters:
Request parameter | Type | Description |
type | int | The screenshot type:
|
width | int | The image width. |
height | int | The image height. |
sid | int | The stream ID. |
picture_type | int | The output image format:
|
Start browser recording
Starts browser recording (client-side recording). This feature uses the browser's native recording capabilities. Currently, this feature supports recording up to two streams and does not support recording video-on-demand robots.
Parameters:
Request parameter
Type
Description
clientRecordId
String
The browser recording ID.
stream_list
Array
The stream IDs (sid).
The recording configuration parameter `record_config` uses JSON-formatted data. The following table describes the parameters.
Request parameter
Type
Description
media_type
int
The recording options:
1: Audio and video
2: Audio-only
3: Video-only
time_slice
int
The interval for BLOB notification during recording. The default is 30. Unit: minutes.
video_profile
JSON
-
videoCodec
String
Supports H264, VP8, and VP9 video encoding formats.
frameRate
int
The frame rate.
record_resolution
String
The following video recording sizes are supported:
1920 × 1080
1280 × 720
640 × 360
overlaps
Array
Supports timestamp, text, and image watermarks. The following describes the video-related watermark parameters:
Timestamp watermark
enable: Specifies whether to add a watermark.
type: 1 watermark type.
id: The watermark ID.
xPosition: The starting position of the watermark on the X-axis.
yPosition: The starting position of the watermark on the Y-axis.
Text watermark
enable: Specifies whether to add a watermark.
type: 2 watermark types.
id: The watermark ID.
text: The watermark text.
fontSize: The font size of the watermark text.
xPosition: The starting position of the watermark on the X-axis.
yPosition: The starting position of the watermark on the Y-axis.
Image watermark
enable: Specifies whether to add a watermark.
type: 3 watermark types.
id: The watermark ID.
img: The image element for the watermark to be added. `new image()`.
xPosition: The starting position of the watermark on the X-axis.
yPosition: The starting position of the watermark on the Y-axis.
Asynchronous callback:
Browser recording started successfully:
OnClientStartRecordSuccess(clientRecordId)Callback parameter
Type
Description
clientRecordId
String
The browser recording ID.
Failed to start browser recording:
OnClientStartRecordFailed(clientRecordId, code, msg)Callback parameter
Type
Description
clientRecordId
String
The browser recording ID.
code
int
Returned if starting browser recording fails:
-20301: Incorrect channel state.
-20302: Recording is already in progress.
-20303: The clientRecordId is already in use.
-20304: Not published or not subscribed.
-20305: Invalid `media_type` parameter.
-20306: Incorrect `stream_list` length.
-20307: No video or audio stream is requested for recording.
-20308: Incorrect `record_resolution`.
msg
String
The status message.
StopRecord
Stops browser recording. Use this interface with the StartBrowserRecord interface. You must call this interface before you leave the channel. Otherwise, you cannot retrieve the BLOB data.
Parameters:
Request parameter
Type
Description
clientRecordId
String
The browser recording ID.
Asynchronous callback:
Browser recording stopped successfully:
OnClientStopRecordSuccess(videoURL, clientRecordBlob, clientRecordId)Callback parameter
Type
Description
videoURL
String
The URL of the video file.
clientRecordBlob
blob
The recorded file.
clientRecordId
String
The browser recording ID.
Failed to stop browser recording:
OnClientStopRecordFailed(clientRecordId, code, msg)Callback parameter
Type
Description
clientRecordId
String
The browser recording ID.
code
int
Error code. -20331 indicates an incorrect channel state.
msg
String
The status message.
PauseRecord
Pauses browser recording. Use this interface with the ResumeRecord interface.
Parameters:
Request parameter
Type
Description
clientRecordId
String
The browser recording ID.
Asynchronous callback:
Browser recording paused successfully:
OnClientPauseRecordSuccess(clientRecordId)Callback parameter
Type
Description
clientRecordId
String
The browser recording ID.
Failed to pause browser recording:
OnClientPauseRecordFailed(clientRecordId, code, msg)Callback parameter
Type
Description
clientRecordId
String
The browser recording ID.
code
int
Returned if pausing browser recording fails:
-20371: Incorrect channel state.
-20372: Browser recording is not started.
msg
String
The status message.
ResumeRecord
Resumes browser recording. Use this interface with the PauseRecord interface.
Parameters:
Request parameter
Type
Description
clientRecordId
String
The browser recording ID.
Asynchronous callback:
Browser recording resumed successfully:
OnClientResumeRecordSuccess(clientRecordId)Callback parameter
Type
Description
clientRecordId
String
The browser recording ID.
Failed to resume browser recording:
OnClientResumeRecordFailed(clientRecordId, code, msg)Callback parameter
Type
Description
clientRecordId
String
The browser recording ID.
code
int
Returned if resuming browser recording fails:
-20391: Incorrect channel state.
-20392: Browser recording is not started.
msg
String
The status message.
DownloadRecord
Downloads the audio and video recorded by the browser. You must download the recording before you leave the channel.
Parameters:
Request parameter
Type
Description
clientRecordId
String
The browser recording ID.
fileName
String
Specify the file name.
Asynchronous callback:
Browser recording downloaded successfully:
OnClientDownloadRecordSuccess(clientRecordId)Callback parameter
Type
Description
clientRecordId
String
The browser recording ID.
Failed to download browser recording:
OnClientDownloadRecordFailed(clientRecordId, code, msg)Callback parameter
Type
Description
clientRecordId
String
The browser recording ID.
code
int
Returned if downloading the browser recording fails:
-20351: Incorrect channel state.
-20352: Browser recording is not started.
-20353: Browser recording is not stopped.
msg
String
The status message.
StartRemoteRecord
Starts server-side recording (remote recording on the media server). Use this interface with the StopRemoteRecord interface.
Parameters:
Request parameter
Type
Optional
Description
file_path
String
Optional
The server-side recording path.
record_param
JSON
Optional
Recording parameters. For more information, see the appendix recordParam.
record_third_id
String
-
The third-party ID for the recording. This ID is used by your business to distinguish between call batches and is returned in the callbacks for successful or failed startups. This parameter is optional.
Asynchronous callback:
Server-side recording initialized successfully:
OnInitRemoteRecordSucc(record_id, record_third_id)Callback parameter
Type
Description
recordId
String
The recording ID.
record_third_id
String
The ID passed in when starting the recording, used to distinguish call batches.
Server-side recording started successfully:
OnStartRemoteRecordSucc(record_id, record_third_id). This callback is returned later thanOnInitRemoteRecordSucc.Callback parameter
Type
Description
record_id
String
The server-side recording ID.
record_third_id
String
The ID passed in when starting the recording, used to distinguish call batches.
Failed to start server-side recording:
OnStartRemoteRecordFailed(record_id, err_code, err_msg, record_third_id)Callback parameter
Type
Description
record_id
String
The server-side recording ID.
err_code
int
Returned if starting server-side recording fails:
-10311: The server returned an error indicating that starting the recording failed.
-10312: Starting the recording timed out.
-10313: Failed to push the start recording notification. The eventCode is 1.
-10314: Failed to push the start recording notification. The eventCode is 2.
err_msg
String
The status message.
record_third_id
String
The ID passed in when starting the recording, used to distinguish call batches.
Stop server-side recording
Stops server-side recording. Use this interface with the StartRemoteRecord interface.
Parameters:
Request parameter
Type
Description
record_id
String
The server-side recording ID.
Asynchronous callback:
Server-side recording stopped successfully:
OnStopRecordSucc(recordId)Callback parameter
Type
Description
record_id
String
The server-side recording ID.
Failed to stop server-side recording:
OnStopRecordFailed(recordId,err_code, err_msg)Callback parameter
Type
Description
record_id
String
The server-side recording ID.
err_code
String
10331 (error code): The server returned an error indicating that stopping the recording failed.
err_msg
String
The status message.
GetRecordInfo
Retrieves the result of a server-side recording.
Parameters:
Request parameter
Type
Description
record_id
String
The server-side recording ID.
room_id
String
The channel ID.
media_type
int
The file content type:
0: Audio and video (default)
1: Audio-only
2: Video-only
sign
String
The service validates signatures.
Asynchronous callback:
Successfully retrieved server-side recording result:
OnRemoteRecordInfoSucc(recordInfo)Note`fileType` and `filePath` are returned only when `status` is 2.
Callback parameter
Type
Description
recordInfo
JSON
The result of the server-side recording.
recordId: The server-side recording ID.
status: The recording status.
0: Recording
1: Uploading
2: Recording successful
3: Recording failed
fileType: The file type.
1: Local file
2: OSS
3: AFTS
filePath: The file path.
Failed to retrieve server-side recording result:
OnRemoteRecordInfoFailed(record_id, err_code, err_msg)Callback parameter
Type
Description
record_id
String
The server-side recording ID.
err_code
int
Returned if getting the server-side recording result fails:
-10351: Incorrect connection state.
-10352: Server error.
-10353: Invalid request parameters.
err_msg
String
The status message.
Unpublish
Unpublishes a media stream.
Parameters:
Request parameter
Type
Description
sid
int
The ID of the published media stream.
Asynchronous callback:
Media stream unpublished successfully:
OnUnPublishSucc(sid)Callback parameter
Type
Description
sid
String
The stream ID.
Unsubscribe
Unsubscribes from a media stream.
Parameters:
Request parameter
Type
Description
sid
int
The media stream ID to subscribe to.
Asynchronous callback:
Unsubscribed from media stream successfully:
OnUnSubscribeSucc(sid)Callback parameter
Type
Description
sid
String
The stream ID.
SendTextMsg
Sends a text message.
Parameters:
Request parameter
Type
Description
msg
String
The message text.
participants
Array
The IDs of the recipients. If this is empty, the message is sent to all other participants in the call.
Asynchronous callback:
Text message sent successfully:
OnSendTextMsgSucc(msgId)Callback parameter
Type
Description
msgId
int
The message ID.
Failed to send text message:
OnSendTextMsgFailed(msgId, code, msg)Callback parameter
Type
Description
msgId
int
The message ID.
code
int
10291 (error code): Server error.
msg
String
The message text.
Set the low bitrate alert threshold for publishing
Sets the lower limit for the low bitrate alert when publishing. You can call this interface during initialization (InitRoomConfig).
Parameters:
Request parameter | Type | Description |
weak_bitrate | int | The lower limit for the low-bitrate alert when publishing:
|
Set the low bitrate alert threshold for subscribing
Sets the lower limit for the low bitrate alert when subscribing. You can call this interface during initialization (InitRoomConfig).
Parameters:
Request parameter | Type | Description |
weak_bitrate | int | The lower limit for the low-bitrate alert when subscribing:
|
StartVod()
Starts the voice on-demand feature, which is only available on the primary site.
Parameters:
Request parameter
Type
Description
vodParams
JSON
vodFile: The name of the on-demand file.
vodStartTimeout: The timeout period for starting the on-demand playback. Unit: seconds. The default is 5 seconds.
Asynchronous callback:
Video-on-demand started successfully:
OnStartVodSuccess(file, vod_id)Callback parameter
Type
Description
file
String
The on-demand file.
vod_id
String
The video-on-demand ID.
Failed to start video-on-demand:
OnStartVodFail(file, vod_id, err_code, err_msg)Callback parameter
Type
Description
file
String
The on-demand file.
vod_id
String
The video-on-demand ID.
err_code
int
Returned if starting audio-on-demand fails:
-10371: Server error.
-10372: Incorrect channel state.
-10373: The server failed to send the start notification.
-10374: Invalid video-on-demand parameters.
-10375: Starting video-on-demand timed out.
err_msg
String
The status message.
StopVod()
Stops video-on-demand. This feature is supported only on the primary site.
Parameters:
Request parameter
Type
Description
vod_id
String
The video-on-demand ID.
Asynchronous callback:
Video-on-demand stopped successfully:
OnStopVodSuccess(vod_id)Callback parameter
Type
Description
vod_id
String
The video-on-demand ID.
Failed to stop video-on-demand:
OnStopVodFail(vod_id, err_code, err_msg)Callback parameter
Type
Description
vod_id
String
The video-on-demand ID.
err_code
int
Returned if stopping audio-on-demand fails:
-10391: The server returned a failure.
-10392: Incorrect channel state.
-10393: Invalid video-on-demand ID.
err_msg
String
The error message.
DownloadLog()
Reports logs. You can call this interface to download console logs to your local computer. By default, a maximum of 10,000 log entries are downloaded.
Parameters: None.
ChangeMediaStream()
Switches to a custom stream. The `record_config` parameter uses the JSON data type and contains the parameters that are described in the following table.
Parameters:
Request parameter
Type
Required
Description
publish_device
-
Required
The publishing type:
1: Camera
2: Desktop sharing
3: Publish an image or video file
4: Publish a custom page area
5: Publish a custom stream
publish_bitrate
int
Optional
The maximum bitrate for publishing. The default is 600 Kbps.
media_type
-
Required
The audio and video type.
sid
-
Required
The ID of the published stream.
video_profile_type
-
Optional
The resolution. This is required when `publish_device` is 1.
videoSource
String
Optional
The device ID of the camera, used to switch to a specific camera.
This is required when `publish_device` is 1.
audioSource
String
Optional
The device ID of the microphone, used to switch to a specific microphone.
This is required when `publish_device` is 1.
aspectRatioStrongDepend
boolean
Optional
Specifies whether to enforce a specific aspect ratio. The default is false.
This is required when `publish_device` is 1.
file
-
Optional
The image or video file.
This is required when `publish_device` is 3.
part_of_screen_id
-
Optional
The custom area to publish.
This is required when `publish_device` is 4.
stream
-
Optional
The custom stream to publish.
This is required when `publish_device` is 5.
video_profile_type
int
Optional
The definition level of the local video:
1: 720P, 1280 × 720, 16:9
2: VGA, 640 × 480, 4:3
3: 360P, 640 × 360, 16:9
4: 720P (portrait), 720 × 1280, 9:16
5: 360P (portrait), 360 × 640, 9:16
6: 1080P, 1920 × 1080, 16:9
7: 1080P (portrait), 1080 × 1920, 9:16
8: 90P (portrait), 90 × 160, 9:16
9: 540P, 960 × 540, 16:9
10: 540P (portrait), 540 × 960, 9:16
100: Custom
video_profile_diy
Object
Optional
Custom video width, height, frame rate, and bitrate.
When `video_profile_type` is 100, you must include the `video_profile_diy` parameter and pass in the video width, height, frame rate, and bitrate. Format:
video_profile_diy: {width,height,frameRate,bitrate}.enableAudio
boolean
Optional
If
enableVideois not provided either, both default totrue.enableVideo
boolean
Optional
If `enableAudio` is also left unspecified, both default to `true`.
Asynchronous callback:
Stream switched successfully:
OnChangeMediaStreamSuccess(sid)Callback parameter
Type
Description
sid
int
The stream ID.
Failed to switch stream:
OnChangeMediaStreamFailed(sid,code, msg)Callback parameter
Type
Description
sid
int
The stream ID.
code
int
Returned if switching the stream fails:
-1101: The current sid is not published.
-1102: Invalid stream switching parameters.
-1104: Failed to get audio and video.
-1105: The screen sharing stream is empty.
-1106: Failed to get video.
-1107: Failed to get the file stream.
-1108: Failed to get audio.
-1109: The browser does not support audio and video.
-1110: No custom stream is provided.
-1111: Custom resolution and other parameters are not provided.
msg
String
The status message.
ChangeProfile()
Dynamically switches the resolution, camera, microphone, or aspect ratio. The `record_config` parameter uses JSON-formatted data, as described in the following table.
Parameters:
Request parameter
Type
Required
Description
sid
-
Required
The ID of the published stream.
video_profile_type
-
Optional
The video resolution.
local_video_width
-
Optional
The video width.
local_video_height
-
Optional
The video height.
videoSource
String
Optional
The device ID of the camera, used to switch to a specific camera.
audioSource
String
Optional
The device ID of the microphone, used to switch to a specific microphone.
aspectRatioStrongDepend
boolean
-
Specifies whether to enforce a specific video aspect ratio. The default is false.
aspectRatio
String
Optional
Video aspect ratio:
1 indicates 4:3.
2: 16:9
This is required when `aspectRatioStrongDepend` is true.
video_profile_type
int
Optional
The definition level of the local video:
1: 720p, 1280 × 720, 16:9
2: VGA, 640 × 480, 4:3
3: 360P, 640 × 360, 16:9
4: 720P (portrait), 720 × 1280, 9:16
5: 360P (portrait), 360 × 640, 9:16
6: 1080P, 1920 × 1080, 16:9
7: 1080P (portrait), 1080 × 1920, 9:16
8: 90P (portrait), 90 × 160, 9:16
9: 540P, 960 × 540, 16:9
10: 540P (portrait), 540 × 960, 9:16
100: Custom
video_profile_diy
-
Optional
Custom video width, height, frame rate, and bitrate.
When `video_profile_type` is 100, you must include the `video_profile_diy` parameter and pass in the video width, height, frame rate, and bitrate. Format:
video_profile_diy: {width,height,frameRate,bitrate}.Asynchronous callback:
Stream switched successfully:
OnChangeMediaStreamSuccess(sid)Callback parameter
Type
Description
sid
int
The stream ID.
Failed to switch stream:
OnChangeMediaStreamFailed(sid,code, msg)Callback parameter
Type
Description
sid
int
The stream ID.
code
int
Returned if switching the stream fails:
-1101: The current sid is not published.
-1102: Invalid stream switching parameters.
-1104: Failed to get audio and video.
-1105: The screen sharing stream is empty.
-1106: Failed to get video.
-1107: Failed to get the file stream.
-1108: Failed to get audio.
-1109: The browser does not support audio and video.
-1110: No custom stream is provided.
-1111: Custom resolution and other parameters are not provided.
msg
String
The status message.
GetDevices()
Retrieves device information.
Parameters: None.
Asynchronous callback:
Device information retrieved successfully:
OnGetDevicesSuccess(devicesInfo)Callback parameter
Type
Description
devicesInfo
JSON
The device information.
Failed to retrieve device information:
OnGetDevicesFailed(code, msg)Callback parameter
Type
Description
code
int
Returned if getting device information fails:
-30101: The browser does not support audio and video.
-30102: Error getting media.
msg
String
The status message.
PauseRemoteRecord
Pauses server-side recording. Use this interface with the ResumeRemoteRecord interface.
Parameters:
Request parameter
Type
Description
record_id
String
The server-side recording ID.
Asynchronous callback:
Server-side recording paused successfully:
OnPauseRemoteRecordSucc(record_id)Callback parameter
Type
Description
record_id
String
The server-side recording ID.
Failed to pause server-side recording:
OnPauseRemoteRecordFailed(record_id, err_code, err_msg)Callback parameter
Type
Description
record_id
String
The server-side recording ID.
err_code
int
Returned if pausing server-side recording fails:
-10341: Incorrect channel state.
-10342: Incorrect recording state.
-10343: Server error.
err_msg
String
The status message.
ResumeRemoteRecord
Resumes server-side recording. Use this interface with the PauseRemoteRecord interface.
Parameters:
Request parameter
Type
Description
record_id
String
The server-side recording ID.
Asynchronous callback:
Server-side recording resumed successfully:
OnResumeRemoteRecordSucc(record_id)Callback parameter
Type
Description
record_id
String
The server-side recording ID.
Failed to resume server-side recording:
OnResumeRemoteRecordFailed(record_id, err_code, err_msg)Callback parameter
Type
Description
record_id
String
The server-side recording ID.
err_code
int
Returned if resuming server-side recording fails:
-10361: Incorrect channel state.
-10362: Incorrect recording state.
-10363: Server error.
err_msg
String
The status message.
Change the server-side recording watermark
Changes the watermark for server-side recording.
Parameters:
Request parameter
Type
Description
record_id
String
The server-side recording ID.
overlaps
Jsonarray
For a description of the
overlapsparameter of recordParam, see the Appendix.Asynchronous callback:
Server-side recording watermark changed successfully:
OnChangeRemoteRecordWatermarkSucc(record_id)Callback parameter
Type
Description
record_id
String
The server-side recording ID.
Failed to change server-side recording watermark:
OnChangeRemoteRecordWatermarkFailed(record_id, err_code, err_msg)Callback parameter
Type
Description
record_id
String
The server-side recording ID.
err_code
int
The status code.
err_msg
String
The status message.
Pause file playback
Pauses the playback of a shared audio or video file.
Parameters:
Request parameter
Type
Description
sid
int
The stream ID.
Asynchronous callback:
Shared file playback paused successfully:
OnPauseFileSuccessCallback parameters: None.
Failed to pause shared file playback:
OnPauseFileFailCallback parameters: None.
PlayFile
Resumes the playback of a shared audio or video file.
Parameters:
Request parameter
Type
Description
sid
int
The stream ID.
Asynchronous callback:
Shared file playback resumed successfully:
OnPlayFileSuccessCallback parameters: None.
Failed to resume shared file playback:
OnPlayFileFailCallback parameters: None.
ChangeStreamSize
Dynamically changes the video size.
Parameters:
Request parameter
Type
Required
Description
sid
int
-
The stream ID.
video_profile_type
String
Optional
The definition level of the local video:
1: 720P, 1280 × 720, 16:9
2: VGA, 640 × 480, 4:3
3: 360P, 640 × 360, 16:9
4: 720P (portrait), 720 × 1280, 9:16
5: 360P (portrait), 360 × 640, 9:16
6: 1080P, 1920 × 1080, 16:9
7: 1080P (portrait), 1080 × 1920, 9:16
8: 90P (portrait), 90 × 160, 9:16
9: 540P, 960 × 540, 16:9
10: 540P (portrait), 540 × 960, 9:16
100: Custom
Asynchronous callback:
Video size changed successfully:
OnChangeStreamSizeSuccess(sid, localVideoWidth, localVideoHeight)Request parameter
Type
Description
sid
int
The stream ID.
localVideoWidth
int
The video width after the switch.
localVideoHeight
int
The video height after the switch.
Failed to change video size:
OnChangeStreamSizeFail(sid, localVideoWidth, localVideoHeight, errCode, errMsg)Request parameter
Type
Description
sid
int
The stream ID.
localVideoWidth
int
The video width after the switch.
localVideoHeight
int
The video height after the switch.
err_code
int
The status code.
err_msg
String
The status message.
SendData
Sends information through a DataChannel.
Parameters:
Request parameter | Type | Description |
data | String (currently only text is supported) | Send a text message |