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();// Setting a view if you need to preview local screen sharing.await trtcA.startScreenShare({ view: 'local-screen-sharing-element-id' });
const trtcB = TRTC.create();trtcB.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, ({ userId, streamType }) => {// Main video streamif (streamType === TRTC.TYPE.STREAM_TYPE_MAIN) {trtcB.startRemoteVideo({ userId, streamType, view: `${userId}_main` });} else {// Sub video stream, it's remote screen sharing.// 'view' is the element id of a div for video playback.trtcB.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.startScreenShare({ option: { systemAudio: true }});
OS | System Audio | Tab Audio |
Windows | Yes | Yes |
MacOS | No | Yes |
Linux | No | Yes |
Non-Chromium based browser, such as Safari, Firefox | No | No |
// Stop screen sharingawait trtcA.stopScreenShare();trtcB.on(TRTC.EVENT.REMOTE_VIDEO_UNAVAILABLE, ({ userId, streamType }) => {// Remote user stopped the screen sharing.if (streamType === TRTC.TYPE.STREAM_TYPE_SUB) {}})
// Listen for local screen sharing stop eventtrtcA.on(TRTC.EVENT.SCREEN_SHARE_STOPPED, () => {console.log('screen sharing was stopped');});
// 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();}
Was this page helpful?