Web

Updated at:

This topic describes how to use the screen sharing feature of the Web software development kit (SDK).

Implementation

The following methods are used for screen sharing. For more information, see DingRTC.

  • createScreenVideoTrack(): Creates a video track for screen sharing.

    const [screenTrack] = await createScreenVideoTrack(config: ScreenVideoTrackConfig);
  • ScreenVideoTrackConfig: A configuration object for creating a screen sharing stream. The following table describes its properties.

    Property

    Type

    Description

    dimension?

    VideoDimension

    (Optional) The video dimension.

    displaySurface?

    'browser' | 'window' | 'monitor'

    (Optional) The default content type to share. Supported types are browser tab, application window, and screen.

    frameRate?

    number

    (Optional) The frame rate.

  • publish(): Publishes the screen sharing stream. Remote users in the same channel receive the "user-published" event. You can subscribe to the stream in the event callback.

    // Local client
    localClient.publish(screenTrack)
    // Remote client
    remoteClient.on('user-published', (user: RemoteUser, mediaType, isAuxillary) => {
      if (mediaType === 'video' && isAuxillary) {
        // The remote user published a screen sharing stream.
      }
    })
  • When a user unpublishes a screen share, remote users in the same channel receive the "user-unpublished" event. You can then unsubscribe from the screen share in the callback for the "user-unpublished" event.

    // Local client
    localClient.unpublish(screenTrack)
    // Remote client
    remoteClient.on('user-unpublished', (user: RemoteUser, mediaType, isAuxillary) => {
      if (mediaType === 'video' && isAuxillary) {
        // The remote user stopped publishing the screen sharing stream.
      }
    })
  • subscribe(): Subscribes to a screen sharing stream. Set the third parameter to true to subscribe to the user's screen sharing track.

    client.subscribe(user.userId, 'video', true);
  • unsubscribe(): Unsubscribes from a screen sharing stream. Set the third parameter to true to unsubscribe from the user's screen sharing track.

    client.unsubscribe(user.userId, 'video', true);