Updated on 2024-05-08 GMT+08:00

Client Object (HWLLSClient)

This section describes the HWLLSClient APIs of the LLL Web SDK.

Table 1 HRTC APIs

API

Description

startPlay

Starts playback. The client obtains the corresponding live stream from the server based on the entered URL.

switchPlay

Quickly switches to the next stream.

stopPlay

Stops the playback.

replay

Replays the video.

startPlayerCustomize

Customizes the playback.

resume

Resumes the playback.

pause

Pauses the playback.

pauseVideo

Pauses the video playback.

resumeVideo

Resumes the video playback.

pauseAudio

Pauses the audio playback.

resumeAudio

Resumes the audio playback.

setPlayoutVolume

Sets the playback volume.

getPlayoutVolume

Obtains the audio volume.

muteAudio

Mutes a site or all sites.

streamStatistic

Specifies whether to enable stream statistics.

enableStreamStateDetection

Enables or disables media stream status detection.

on

Registers the callback for a client object event.

off

Deregisters the callback for a client object event.

destoryClient

Destroys a client object.

fullScreenToggle

Enables/Disables full-screen display.

startPlay

startPlay(url: string, options: StartPlayOptions): Promise<void>

[Function Description]

Starts playback. The client obtains the corresponding live stream from the server based on the entered URL.

[Request Parameters]

  • url: (mandatory) String type. A streaming URL is in the format of webrtc://{domain}/{AppName}/{StreamName}.
    • webrtc://: The value is fixed, indicating that streams are pulled using WebRTC.
    • domain: indicates the streaming domain name. Use the streaming domain name registered with Huawei Cloud.
    • AppName: indicates the application name. Use the application name registered with Huawei Cloud.
    • StreamName: indicates the stream name, which must be the same as the pushed stream name.
  • options: (mandatory) Playback configuration parameter. The value is of StartPlayOptions type. The definition of StartPlayOptions is as follows: {
    • elementId: (mandatory) indicates the playback DOM ID.
    • objectFit: (optional) String type. Default value: cover. The following enumerated values are supported:
      • contain: preferentially ensures that all video content is displayed. The video is scaled proportionally until one side of the video window is aligned with the window border. If the video size is inconsistent with the display window size, when the aspect ratio is locked and the video is zoomed in or out to fill the window, a black bar is displayed around the zoomed-in or zoomed-out video.
      • cover: preferentially ensures that the window is filled. The video is scaled proportionally until the entire window is filled with video. If the video size is inconsistent with the display window size, the video stream will be cropped or the image will be stretched to fill the display window.
      • fill: The window is filled with video. If the aspect ratio of the video does not match the window, the video will be stretched to fit the window.
    • muted: (optional) Boolean type. true indicates muted; false indicates unmuted. The default value is false.
    • sessionId: (optional) String type. Indicates the unified ID of a complete session.
    • showLoading: (optional) Boolean type. Indicates whether to enable the loading display effect. true indicates that the loading display effect is enabled. The default value is false. When this parameter is set to true, the loading effect upon playback start will also be enabled. The loading effect upon buffering during playback needs to be set based on the LOADING_CONFIG in the setParameter API.
    • autoPlay: (optional) Boolean type. true indicates that the autoplay function is enabled. false indicates that the autoplay function needs to be manually triggered. The default value is true.
    • poster: (optional) The object definition is as follows: {
      • url: (optional) String type. Sets the complete address of the thumbnail image to be played. The image must be in JPG, PNG, or static GIF format, the size cannot exceed 1 MB, and the resolution cannot exceed 1920 x 1080. The file name cannot contain Chinese characters.
      • mode: (optional) String type. The default value is cover. The following enumerated values are supported: {
        • fill: The window is filled with video. If the aspect ratio of the video does not match the window, the video will be stretched to fit the window.
        • crop: original size of the thumbnail. If the poster exceeds the playback area, the excess part is cropped. Otherwise, the poster is displayed in the middle of the playback window.

        }

      • startEnable: (optional) Boolean type. Indicates whether to display the thumbnail when the playback starts. The options are true and false. The default value is false. This parameter takes effect only in non-autoplay scenarios.
      • pauseEnable: (optional) Boolean type. Indicates whether to display the thumbnail on the playback page when the video is paused. The options are true and false. The default value is false.

      }

    • webrtcConfig: (optional) WebRTCConfig type. Specifies parameters for pulling streams of a specified media type. WebRTCConfig is defined as follows: {
      • receiveVideo: (optional) Boolean type. Pulls a video for playback. true indicates that a video is pulled for playback, and false indicates that a video is not pulled for playback. The default value is true. This parameter and receiveAudio cannot be set to false at the same time.
      • receiveAudio: (optional) Boolean type. Indicates whether to pull an audio for playback. true indicates that an audio is pulled for playback, and false indicates that an audio is not pulled for playback. The default value is true. This parameter and receiveVideo cannot be set to false at the same time.

    }

    • schedulePolicy: (optional) SchedulePolicy type. Specifies the access scheduling policy. The definition of SchedulePolicy is as follows: {
      • DNS: (optional) String type. Indicates that the domain name is resolved by DNS for being accessed. The default value is DNS.
      • HTTPDNS: (optional) String type. Indicates that HTTPDNS is used for the access domain name.

      }

    • domainPolicy: (optional) DomainPolicy type. Specifies the policy of an access domain name. This setting takes effect only when schedulePolicy is set to DNS. DomainPolicy is defined as follows: {
      • 0: (optional) Number type. Indicates that the user-defined domain name is used. The default value is 0.
      • 1: (optional) Number type. Indicates that the public access domain name is used.

      }

    • downgradeUrl: (optional) The object definition is as follows: {
      • hlsUrl?: (optional) String type. Identifies the downgraded HLS streaming URL.
      • flvUrl?: (optional) String type. Identifies the downgraded FLV streaming URL.

      }

[Response Parameters]

Promise<void>: returns a Promise object.

When the LLL service is faulty, the error code HWLLS_BUSINESS_DOWNGRADE can be used to downgrade the playback. For details, see SDK Usage.

switchPlay

switchPlay(url: string, options: StartPlayOptions): Promise<void>

[Function Description]

After the playback has been started, the system quickly switches to the next stream.

[Request Parameters]

  • url: (mandatory) Ingest URL. A streaming URL is in the format of webrtc://{domain}/{AppName}/{StreamName}.
    • webrtc://: The value is fixed, indicating that streams are pulled using WebRTC.
    • domain: indicates the streaming domain name. Use the streaming domain name registered with Huawei Cloud.
    • AppName: indicates the application name. Use the application name registered with Huawei Cloud.
    • StreamName: indicates the stream name, which must be the same as the pushed stream name.
  • options: (optional) Playback configuration parameter. The value is of StartPlayOptions type. If this parameter is not carried, the options data carried in the first playback start request is reused. The definition of StartPlayOptions is as follows: {
    • elementId: (mandatory) indicates the playback DOM ID.
    • objectFit: (optional) String type. Default value: cover. The following enumerated values are supported:
      • contain: preferentially ensures that all video content is displayed. The video is scaled proportionally until one side of the video window is aligned with the window border. If the video size is inconsistent with the display window size, when the aspect ratio is locked and the video is zoomed in or out to fill the window, a black bar is displayed around the zoomed-in or zoomed-out video.
      • cover: preferentially ensures that the window is filled. The video is scaled proportionally until the entire window is filled with video. If the video size is inconsistent with the display window size, the video stream will be cropped or the image will be stretched to fill the display window.
      • fill: The window is filled with video. If the aspect ratio of the video does not match the window, the video will be stretched to fit the window.
    • muted: (optional) Boolean type. true indicates muted; false indicates unmuted. The default value is false.
    • sessionId: (optional) String type. Indicates the unified ID of a complete session.
    • showLoading: (optional) Boolean type. Indicates whether to enable the loading display effect. true indicates that the loading display effect is enabled. The default value is false. When this parameter is set to true, the loading effect upon playback start will also be enabled. The loading effect upon buffering during playback needs to be set based on the LOADING_CONFIG in the setParameter API.
    • autoPlay: (optional) Boolean type. true indicates that the autoplay function is enabled. false indicates that the autoplay function needs to be manually triggered. The default value is true.
    • poster: (optional) The object definition is as follows: {
      • url: (optional) String type. Sets the complete address of the thumbnail image to be played. The image must be in JPG, PNG, or static GIF format, the size cannot exceed 1 MB, and the resolution cannot exceed 1920 x 1080. The file name cannot contain Chinese characters.
      • mode: (optional) String type. The default value is cover. The following enumerated values are supported: {
        • fill: The window is filled with video. If the aspect ratio of the video does not match the window, the video will be stretched to fit the window.
        • crop: original size of the thumbnail. If the poster exceeds the playback area, the excess part is cropped. Otherwise, the poster is displayed in the middle of the playback window.

        }

      • startEnable: (optional) Boolean type. Indicates whether to display the thumbnail when the playback starts. The options are true and false. The default value is false. This parameter takes effect only in non-autoplay scenarios.
      • pauseEnable: (optional) Boolean type. Indicates whether to display the thumbnail on the playback page when the video is paused. The options are true and false. The default value is false.

      }

    • webrtcConfig: (optional) WebRTCConfig type. Specifies parameters for pulling streams of a specified media type. WebRTCConfig is defined as follows: {
      • receiveVideo: (optional) Boolean type. Pulls a video for playback. true indicates that a video is pulled for playback, and false indicates that a video is not pulled for playback. The default value is true. This parameter and receiveAudio cannot be set to false at the same time.
      • receiveAudio: (optional) Boolean type. Indicates whether to pull an audio for playback. true indicates that an audio is pulled for playback, and false indicates that an audio is not pulled for playback. The default value is true. This parameter and receiveVideo cannot be set to false at the same time.

    }

    • schedulePolicy: (optional) SchedulePolicy type. Specifies the access scheduling policy. The definition of SchedulePolicy is as follows: {
      • DNS: (optional) String type. Indicates that the domain name is resolved by DNS for being accessed. The default value is DNS.
      • HTTPDNS: (optional) String type. Indicates that HTTPDNS is used for the access domain name.

      }

    • domainPolicy: (optional) DomainPolicy type. Specifies the policy of an access domain name. This setting takes effect only when schedulePolicy is set to DNS. DomainPolicy is defined as follows: {
      • 0: (optional) Number type. Indicates that the user-defined domain name is used. The default value is 0.
      • 1: (optional) Number type. Indicates that the public access domain name is used.

      }

[Response Parameters]

Promise<void>: returns a Promise object.

When the LLL service is faulty, the error code HWLLS_BUSINESS_DOWNGRADE can be used to downgrade the playback. For details, see SDK Usage.

stopPlay

stopPlay(): boolean

[Function Description]

Stops the playback.

[Request Parameters]

None

[Response Parameters]

boolean: result of stopping playback. The options are true (success) and false (failure).

replay

replay(): Promise<boolean>

[Function Description]

Replays the video.

[Request Parameters]

None

[Response Parameters]

Promise<boolean>: replay result. The options are true (success) and false (failure).

startPlayerCustomize

startPlayerCustomize(url: strin): Promise<boolean>

[Function Description]

Customizes the playback.

[Request Parameters]

  • url: (mandatory) Ingest URL. Streaming URL, which is a customized URL for playback.
  • options: (optional) Playback configuration parameter. The value is of StartPlayOptions type. If this parameter is not carried, the options data carried in the first playback start request is reused. The definition of StartPlayOptions is as follows: {
    • elementId: (mandatory) indicates the playback DOM ID.
    • objectFit: (optional) String type. Default value: cover. The following enumerated values are supported:
      • contain: preferentially ensures that all video content is displayed. The video is scaled proportionally until one side of the video window is aligned with the window border. If the video size is inconsistent with the display window size, when the aspect ratio is locked and the video is zoomed in or out to fill the window, a black bar is displayed around the zoomed-in or zoomed-out video.
      • cover: preferentially ensures that the window is filled. The video is scaled proportionally until the entire window is filled with video. If the video size is inconsistent with the display window size, the video stream will be cropped or the image will be stretched to fill the display window.
      • fill: The window is filled with video. If the aspect ratio of the video does not match the window, the video will be stretched to fit the window.
    • muted: (optional) Boolean type. true indicates muted; false indicates unmuted. The default value is false.
    • sessionId: (optional) String type. Indicates the unified ID of a complete session.
    • showLoading: (optional) Boolean type. Indicates whether to enable the loading display effect. true indicates that the loading display effect is enabled. The default value is false. When this parameter is set to true, the loading effect upon playback start will also be enabled. The loading effect upon buffering during playback needs to be set based on the LOADING_CONFIG in the setParameter API.
    • autoPlay: (optional) Boolean type. true indicates that the autoplay function is enabled. false indicates that the autoplay function needs to be manually triggered. The default value is true.
    • poster: (optional) The object definition is as follows: {
      • url: (optional) String type. Sets the complete address of the thumbnail image to be played. The image must be in JPG, PNG, or static GIF format, the size cannot exceed 1 MB, and the resolution cannot exceed 1920 x 1080. The file name cannot contain Chinese characters.
      • mode: (optional) String type. The default value is cover. The following enumerated values are supported: {
        • fill: The window is filled with video. If the aspect ratio of the video does not match the window, the video will be stretched to fit the window.
        • crop: original size of the thumbnail. If the poster exceeds the playback area, the excess part is cropped. Otherwise, the poster is displayed in the middle of the playback window.

        }

      • startEnable: (optional) Boolean type. Indicates whether to display the thumbnail when the playback starts. The options are true and false. The default value is false. This parameter takes effect only in non-autoplay scenarios.
      • pauseEnable: (optional) Boolean type. Indicates whether to display the thumbnail on the playback page when the video is paused. The options are true and false. The default value is false.

      }

    • webrtcConfig: (optional) WebRTCConfig type. Specifies parameters for pulling streams of a specified media type. WebRTCConfig is defined as follows: {
      • receiveVideo: (optional) Boolean type. Pulls a video for playback. true indicates that a video is pulled for playback, and false indicates that a video is not pulled for playback. The default value is true. This parameter and receiveAudio cannot be set to false at the same time.
      • receiveAudio: (optional) Boolean type. Indicates whether to pull an audio for playback. true indicates that an audio is pulled for playback, and false indicates that an audio is not pulled for playback. The default value is true. This parameter and receiveVideo cannot be set to false at the same time.

    }

    • schedulePolicy: (optional) SchedulePolicy type. Specifies the access scheduling policy. The definition of SchedulePolicy is as follows: {
      • DNS: (optional) String type. Indicates that the domain name is resolved by DNS for being accessed. The default value is DNS.
      • HTTPDNS: (optional) String type. Indicates that HTTPDNS is used for the access domain name.

      }

    • domainPolicy: (optional) DomainPolicy type. Specifies the policy of an access domain name. This setting takes effect only when schedulePolicy is set to DNS. DomainPolicy is defined as follows: {
      • 0: (optional) Number type. Indicates that the user-defined domain name is used. The default value is 0.
      • 1: (optional) Number type. Indicates that the public access domain name is used.

      }

[Response Parameters]

Promise<void>: returns a Promise object.

resume

resume(): Promise<boolean>

[Function Description]

Resumes the playback.

[Request Parameters]

None

[Response Parameters]

Promise<boolean>: result of resuming the audio/video playback. The options are true (success) and false (failure).

pause

pause(): boolean

[Function Description]

Pauses the audio/video playback.

[Request Parameters]

None

[Response Parameters]

boolean: playback pause result. The options are true (success) and false (failure).

pauseVideo

pauseVideo(): boolean

[Function Description]

This parameter is used to pause a video. After the video is paused, it freezes.

[Request Parameters]

None

[Response Parameters]

boolean: result of pausing video playback. The options are true (success) and false (failure).

resumeVideo

resumeVideo(): Promise<boolean>

[Function Description]

Resumes the video playback.

[Request Parameters]

None

[Response Parameters]

Promise<boolean>: result of resuming the video playback. The options are true (success) and false (failure).

pauseAudio

pauseAudio(): boolean

[Function Description]

Pauses the audio playback.

[Request Parameters]

None

[Response Parameters]

boolean: result of pausing the audio playback. The options are true (success) and false (failure).

resumeAudio

resumeAudio(): Promise<boolean>

[Function Description]

Resumes the audio playback.

[Request Parameters]

None

[Response Parameters]

Promise<boolean>: result of resuming the audio playback. The options are true (success) and false (failure).

setPlayoutVolume

setPlayoutVolume(volume: number): boolean

[Function Description]

Sets the audio volume. This API is not supported on iOS.

[Request Parameters]

volume: (mandatory) audio volume. The value is a number ranging from 0 to 100.

[Response Parameters]

boolean: whether the operation is successful. The options are true (success) and false (failure).

getPlayoutVolume

 getPlayoutVolume(): number

[Function Description]

Obtains the audio volume.

[Request Parameters]

None

[Response Parameters]

number: volume value. The value ranges from 0 to 100.

muteAudio

muteAudio(isMute: boolean): void

[Function Description]

Mutes.

[Request Parameters]

  • isMute: (mandatory) indicates whether the device is muted. The value is of the Boolean type. true indicates that the device is muted, and false indicates that the device is unmuted.

[Response Parameters]

None

streamStatistic

streamStatistic(enable: boolean, interval: number): void

[Function Description]

Specifies whether to enable stream statistics.

[Request Parameters]

  • enable: (mandatory) Specifies whether to enable stream statistics. The value is of the Boolean type. The value true indicates that stream statistics are enabled.
  • interval: (mandatory) Specifies the statistics interval, in seconds. The value is a number ranging from 1 to 60. The default value is 1.

[Response Parameters]

None

enableStreamStateDetection

enableStreamStateDetection(enable: boolean, interval: number, interruptRetry:StreamInterruptRetry): boolean

[Function Description]

Enables or disables media stream status detection. After the function is enabled, the system can detect whether the stream has been interrupted at the stream push device.

[Request Parameters]

  • enable: (mandatory) whether to enable media stream status detection. The value is of the Boolean type. true indicates enabled; false (default value) indicates disabled.
  • interval: (mandatory) Specifies the interval in seconds. The value is a number ranging from 1 to 60. This parameter is used to determine when there is no media stream. The default value is 3 (recommended).
  • interruptRetry: (optional) Parameter for configuring playback retry upon stream interruption. The value is of StreamInterruptRetry type. The definition of StreamInterruptRetry is as follows: {

    enable: The value is of the Boolean type. Attempt for automatically resuming playback is enabled after stream interruption. The default value is false, indicating that attempt for automatically resuming playback is disabled.

    retryInterval: retry interval for stream pulling, in seconds. The value type is number. The value ranges from 10 to 60 and defaults to 30.

    retryTimes: maximum number of retry times for resuming playback. The value type is number. The minimum value is 1 and the default value is 30.

    }

[Response Parameters]

boolean: whether the operation is successful. The options are true (success) and false (failure).

on

on(event: string, handler: function, withTimeout?: boolean): void

[Function Description]

Registers the callback for a client object event.

[Request Parameters]
  • event: (mandatory) event name. The type is string. For details, see HWLLSClientEvent.
  • handler: (mandatory) event processing method. The type is function.
  • withTimeout: (optional) indicates whether a timeout error is reported. The value is of the Boolean type.

[Response Parameters]

None

off

off(event: string, handler: function): void

[Function Description]

Deregisters the callback for a client object event.

[Request Parameters]
  • event: (mandatory) event name. The type is string. For details, see HWLLSClientEvent.
  • handler: (mandatory) event processing method. The type is function.

[Response Parameters]

None

destoryClient

destoryClient(): void

[Function Description]

Destroys a client object.

[Request Parameters]

None

[Response Parameters]

None

fullScreenToggle

fullScreenToggle(isExit: boolean): void

[Function Description]

Enables/Disables full-screen display.

[Request Parameters]

isExit: (mandatory) Boolean type. The default value is false.

[Response Parameters]

None