Updated on 2023-11-01 GMT+08:00

Main Entry (HRTC)

This section describes the HRTC APIs of the Web SDK.

Table 1 HRTC APIs

API

Description

checkSystemRequirements

Checks whether the browser is compatible with the SparkRTC Web SDK.

NOTICE:

If the Web SDK version is between 2.0.2 and 2.0.9.300, you need to update it to 2.0.9.301 or later before October 29, 2023. Otherwise, the checkSystemRequirements API will be unavailable. Users of WeChat browsers need to update the SDK version.

VERSION

Obtains the SparkRTC Web SDK version.

getDevices

Obtains the list of media input and output devices.

getCameras

Obtains the camera list.

getMicrophones

Obtains the microphone list.

getSpeakers

Obtains the speaker list.

isScreenShareSupported

Checks whether screen sharing is supported.

createClient

Creates a client object for real-time audio and video calls. One Client object indicates one room.

createStream

Creates a local stream object. Streams are classified into video and presentation. Video refers to streams collected by cameras and microphones. Presentation refers to streams collected from shared screens.

setLogLevel

Sets the log level.

checkSystemRequirements

If the Web SDK version is between 2.0.2 and 2.0.9.300, you need to update it to 2.0.9.301 or later before October 29, 2023. Otherwise, the checkSystemRequirements API will be unavailable. Users of WeChat browsers need to update the SDK version.

(static) checkSystemRequirements(strictCheckBrowser: boolean): Promise<boolean>

[Function Description]

Checks whether the browser is compatible with the SparkRTC Web SDK.

[Request Parameters]

strictCheckBrowser: (optional) Boolean type. Default value: true. The value true indicates that the mobile browser in the whitelist configured and managed by Huawei is used. The value false indicates that the whitelist is not used. This parameter is added in version 2.0.2.

[Response Parameters]

Promise<boolean>: A Promise object is returned. The value true indicates that the browser is compatible with the SparkRTC Web SDK. If the browser is incompatible with the SparkRTC Web SDK, the corresponding error is returned.

VERSION

VERSION

[Function Description]

Obtains the SparkRTC Web SDK version.

[Request Parameters]

None

[Response Parameters]

string: current SDK version number.

getDevices

(static) getDevices(): Promise<MediaDeviceInfo[]>

[Function Description]

Obtains the list of media input and output devices. The label and deviceId parameters may be empty if the browser is not allowed to access cameras or microphones. It is recommended that you call this API after the browser is allowed to access the devices.

For details about how to grant the permission for accessing cameras or microphones to a browser, see Granting the Permissions of Accessing Cameras or Microphones to a Browser.

[Request Parameters]

None

[Response Parameters]

Promise<MediaDeviceInfo[]>: list of media input and output devices. MediaDeviceInfo is a basic web API.

getCameras

(static) getCameras(): Promise<MediaDeviceInfo[]>

[Function Description]

Obtains the camera list. The label and deviceId parameters may be empty if the browser is not allowed to access cameras. It is recommended that you call this API after the browser is allowed to access the devices.

For details about how to grant the permission for accessing cameras or microphones to a browser, see Granting the Permissions of Accessing Cameras or Microphones to a Browser.

[Request Parameters]

None

[Response Parameters]

Promise<MediaDeviceInfo[]>: camera list. MediaDeviceInfo is a basic web API.

getMicrophones

(static) getMicrophones(): Promise<MediaDeviceInfo[]>

[Function Description]

Obtains the microphone list. The label and deviceId parameters may be empty if the browser is not allowed to access microphones. It is recommended that you call this API after the browser is allowed to access the devices.

For details about how to grant the permission for accessing cameras or microphones to a browser, see Granting the Permissions of Accessing Cameras or Microphones to a Browser.

[Request Parameters]

None

[Response Parameters]

Promise<MediaDeviceInfo[]>: microphone list. MediaDeviceInfo is a basic web API.

getSpeakers

(static) getSpeakers(): Promise<MediaDeviceInfo[]>

[Function Description]

Obtains the speaker list.

[Request Parameters]

None

[Response Parameters]

Promise<MediaDeviceInfo[]>: speaker list. MediaDeviceInfo is a basic web API.

isScreenShareSupported

(static) isScreenShareSupported(): boolean

[Function Description]

Checks whether screen sharing is supported.

[Request Parameters]

None

[Response Parameters]

boolean: true indicates that the function is supported, and false indicates that the function is not supported.

createClient

(static)createClient(config: ClientConfig): Client

[Function Description]

Creates a client object for real-time audio and video calls. A client object can be added to only one room. You can create multiple client objects and add them to multiple rooms respectively.

[Request Parameters]

config: (mandatory) client object configuration. The type is ClientConfig.

ClientConfig is defined as: {
  • appId: (mandatory) app ID. The type is string[128]. Only apps with the same ID can enter the same room for interaction. For details about how to obtain the value of appId, submit a service ticket.
  • domain: (optional) domain name of the server. The type is string[128]. The value must be the same as the valid enterprise domain name registered with the SparkRTC platform. This parameter is mandatory in SDK 1.0+ and is optional in SDK 2.0+.
  • countryCode: (optional) country or region code. The type is string[2]. The value must be an alpha-2 code specified in the ISO 3166-1 standard. This parameter indicates the country or region code of the service access point of the SDK. For example, CN indicates the Chinese mainland, US indicates the United States, and HK indicates Hong Kong, China. For details about how to configure countryCode, see GRS Country Codes. This parameter was added in version 2.0.3 and was mandatory. It has become an optional parameter in version 2.0.7 or later.

}

[Response Parameters]

Client: client object.

createStream

(static) createStream(config: StreamConfig): Stream

[Function Description]

Creates a local stream object.

[Request Parameters]

config: (mandatory) parameters for creating a stream. The type is StreamConfig.

StreamConfig is defined as: {
  • screen: (optional) The type is Boolean. If the value is true, the stream object collects presentation audio and video. Presentation refers to screen sharing streams. The default value is false, indicating that the stream object collects audio and video collected by microphones and cameras.
  • video: (optional) whether to collect video from cameras. The type is Boolean. The default value is false.
  • audio: (optional) whether to collect audio from microphones. The type is Boolean. The default value is false. This parameter is valid only when screen is set to false.
  • microphoneId: (optional) ID of the microphone for audio collection. This parameter is valid only when audio is set to true. The type is string. If this parameter is not passed, the system automatically uses the default value.
  • cameraId: (optional) ID of the camera for video collection. This parameter is valid only when video is set to true. The type is string. If this parameter is not passed, the system automatically uses the default value.
  • facingMode: (optional) This parameter is valid only when video is set to true. user indicates the front-facing camera; environment indicates the rear-facing camera. The type is string.
  • screenAudio: (optional) whether the screen sharing background sound is included. The type is Boolean. The default value is false. This function applies only to Chrome 74 and later versions on Windows. This parameter is added in version 1.4.0.
  • audioSource: (optional) input audio track object. The type is MediaStreamTrack. Specify a sound track. MediaStreamTrack is a basic web API.
  • videoSource: (optional) input video track object. The type is MediaStreamTrack. Specify a video track. MediaStreamTrack is a basic web API.
  • mirror: (optional) whether the local video collected by cameras is mirrored. The type is Boolean. The default value is false.
  • userId: (optional) ID of the user to which the stream belongs. The type is string.

}

[Response Parameters]

Stream: stream object.

  • There are two methods of capturing video streams:
    • Configure audioSource and videoSource to capture audio and video, respectively. This method does not support high-quality and low-quality streams.
    • Configure audio/microphoneId and video/cameraId/facingMode to capture audio and video, respectively.
  • If no audio or video source is specified, the created stream object does not include audio or video streams and cannot be played.
  • A stream can be either a video stream or presentation stream.
  • If screen sharing background audio is required, set screen and screenAudio to true. This parameter takes effect only in 1.4.0 and later versions.

setLogLevel

(static) setLogLevel(level: LogLevel): void

[Function Description]

Sets the log output level. Logs of the info level are generated by default.

[Request Parameters]

level: (mandatory) log level. The type is LogLevel.

LogLevel indicates the log level. The enumerated values are as follows:

  • none: disabling SDK log print. The type is string.
  • error: enabling the SDK error log level. The type is string.
  • warn: enabling the SDK warning log level. The type is string.
  • info: enabling the SDK information log level. The type is string.
  • debug: enabling the SDK debug log level. The type is string.

[Response Parameters]

None