StreamEvent

Stream Event List

Members

(static) PLAYER_STATE_CHANGED

Default Value:
  • 'player-state-changed'

Status change of the audio/video player. You can update the UI of your application based on these callbacks. For example, you can listen for the status change of the video player to show or hide masks.

  • 'PLAYING': Playback started.

  • 'PAUSED': Playback paused.

    • If event.reason is pause, the callback is triggered by the pause event of the
    • For the mute event (event.reason is mute), please see MediaStreamTrack.mute_event
      • If the callback is triggered for a local stream, it indicates that audio/video capturing has paused, usually due to a device error (for example, the device is occupied by another application). You need to guide the user to resume capturing on the UI.
      • If the callback is triggered for a remote stream, it indicates that insufficient audio/video data has been received for playback. This is usually a result of network jitter. No action is required in this case. The playback will resume automatically after sufficient data is received.
  • 'STOPPED':Playback stopped.

Reason for status change:

Example
stream.on('player-state-changed', event => {
  console.log(`${event.type} player is ${event.state} because of ${event.reason}`);
});

(static) SCREEN_SHARING_STOPPED

Default Value:
  • 'screen-sharing-stopped'

Callback for stopping screen sharing, which is triggered only for the local screen sharing stream

Example
stream.on('screen-sharing-stopped', () => {
  console.log('screen sharing was stopped');
});

(static) CONNECTION_STATE_CHANGED

Since:
  • v4.10.1
Default Value:
  • 'connection-state-changed'

Stream connection status change

  • 'DISCONNECTED': connecting
  • 'CONNECTING': connecting
  • 'RECONNECTING': automatically reconnecting
  • 'CONNECTED': connected

Note:

  • To listen for the connection status change of a stream, register this callback after the stream-added event and unregister it after the stream-removed event.
Example
stream.on('connection-state-changed', (event) => {
  console.log(`prevState: ${event.prevState}, state: ${event.state}`);
});

(static) DEVICE_AUTO_RECOVERED

Since:
  • v4.13.0
Default Value:
  • 'device-auto-recovered'

When the camera or microphone being used has an capture exception, SDK will try to automatically recover the capture. This event will be fired when the capture is recovered successfully. DEVICE_AUTO_RECOVER_FAILED.

Example
localStream.on('device-auto-recovered', (event) => {
 // Is the camera or microphone recovered.
 // isCamera and isMicrophone may both be true.
 console.warn(event.isCamera, event.isMicrophone);
 // current cameraId and microphoneId in use.
 console.warn(event.cameraId, event.microphoneId);
});

(static) ERROR

Default Value:
  • 'error'

Error event. This event is thrown when an unrecoverable error occurs.

Example
stream.on('error', error => {
  const errorCode = error.getCode();
  if (errorCode === 0x4043) {
    // Autoplay is blocked. Display a window on the UI and, in the callback for the window’s clicking event, call `stream.resume` to resume audio/video playback.
    // Reference: https://trtc-1252463788.file.myqcloud.com/web/docs/module-ErrorCode.html#.PLAY_NOT_ALLOWED
  } else if (errorCode === 0x4044) {
    // Failed to automatically resume capturing after the media device is unplugged. Reference: https://trtc-1252463788.file.myqcloud.com/web/docs/module-ErrorCode.html#.DEVICE_AUTO_RECOVER_FAILED
  }
});