const trtcA = TRTC.create();await trtcA.enterRoom({scene: 'rtc',sdkAppId: 140000000, // Fill in your sdkAppIduserId: 'userA', // Fill in your userIduserSig: 'userA_sig', // Fill in userSig corresponding to userIdroomId: 6969})await trtcA.startScreenShare();
const trtcB = TRTC.create();trtcB.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, ({ userId, streamType }) => {// Main video stream, generally the stream pushed by the cameraif (streamType === TRTC.TYPE.STREAM_TYPE_MAIN) {// 1. Place a div tag with an id of `${userId}_main` on the page to play the main stream in the div tag. The business side can customize the id of the div tag. This is just an example.// 2. Play the main video streamtrtcB.startRemoteVideo({ userId, streamType, view: `${userId}_main` });} else {// Sub video stream, generally the stream pushed by screen sharing.// 1. Place a div tag with an id of `${userId}_screen` on the page to play the screen sharing in the div tag. The business side can customize the id of the div tag. This is just an example.// 2. Play screen sharingtrtcB.startRemoteVideo({ userId, streamType, view: `${userId}_screen` });}});await trtcB.enterRoom({scene: 'rtc',sdkAppId: 140000000, // Fill in your sdkAppIduserId: 'userB', // Fill in your userIduserSig: 'userB_sig', // Fill in userSig corresponding to userIdroomId: 6969})
await trtcA.startLocalVideo();await trtcA.startScreenShare();
await trtcA.startScreenShare({ option: { systemAudio: true }});
Share sytem audio in the pop-up dialog box, and the system audio will be mixed with the local microphone and published. Other users in the room will receive the REMOTE_AUDIO_AVAILABLE event.
// Stop screen sharing collection and publishingawait trtcA.stopScreenShare();// Other users in the room will receive the TRTC.EVENT.REMOTE_VIDEO_UNAVAILABLE event, and streamType is TRTC.TYPE.STREAM_TYPE_SUB.trtcB.on(TRTC.EVENT.REMOTE_VIDEO_UNAVAILABLE, ({ userId, streamType }) => {if (streamType === TRTC.TYPE.STREAM_TYPE_SUB) {}})

// Listen for screen sharing stop eventtrtcA.on(TRTC.EVENT.SCREEN_SHARE_STOPPED, () => {console.log('screen sharing was stopped');});
1080p parameter configuration by default to collect screen sharing. For details, refer to the interface: startScreenSharegetDisplayMedia must be called from a user gesture handlergetDisplayMedia screen capture interface, which must be called within 1 second of the callback function of the user click event.// goodasync function onClick() {// It is recommended to execute the collection logic first when onClick is executedawait trtcA.startScreenShare();await trtcA.enterRoom({roomId: 123123,sdkAppId: 140000000, // Fill in your sdkAppIduserId: 'userA', // Fill in your userIduserSig: 'userA_sig', // Fill in userSig corresponding to userId});}// badasync function onClick() {await trtcA.enterRoom({roomId: 123123,sdkAppId: 140000000, // Fill in your sdkAppIduserId: 'userA', // Fill in your userIduserSig: 'userA_sig', // Fill in userSig corresponding to userId});// Entering the room may take more than 1s, and the collection may failawait trtcA.startScreenShare();}
Feedback