diff --git a/JitsiMeetJS.ts b/JitsiMeetJS.ts index ebe95d21932..e308b6a80e3 100644 --- a/JitsiMeetJS.ts +++ b/JitsiMeetJS.ts @@ -334,15 +334,6 @@ export default { } } - // set the contentHint to "detail" for desktop tracks - // eslint-disable-next-line prefer-const - for (const track of tracks) { - if (track.type === MediaType.VIDEO - && track.videoType === 'desktop') { - this.setVideoTrackContentHints(track.track, 'detail'); - } - } - return tracks; }) .catch(error => { @@ -531,24 +522,6 @@ export default { NetworkInfo.updateNetworkInfo({ isOnline }); }, - /** - * Set the contentHint on the transmitted stream track to indicate - * charaterstics in the video stream, which informs PeerConnection - * on how to encode the track (to prefer motion or individual frame detail) - * @param {MediaStreamTrack} track - the track that is transmitted - * @param {String} hint - contentHint value that needs to be set on the track - */ - setVideoTrackContentHints(track, hint) { - if ('contentHint' in track) { - track.contentHint = hint; - if (track.contentHint !== hint) { - logger.debug('Invalid video track contentHint'); - } - } else { - logger.debug('MediaStreamTrack contentHint attribute not supported'); - } - }, - precallTest, /* eslint-enable max-params */ diff --git a/modules/RTC/ScreenObtainer.js b/modules/RTC/ScreenObtainer.js index fb91a2718ce..df19bf418b1 100644 --- a/modules/RTC/ScreenObtainer.js +++ b/modules/RTC/ScreenObtainer.js @@ -180,11 +180,14 @@ const ScreenObtainer = { // We have to use the old API on Electron to get a desktop stream. navigator.mediaDevices.getUserMedia(constraints) - .then(stream => onSuccess({ - stream, - sourceId: streamId, - sourceType: streamType - }), onFailure); + .then(stream => () => { + this.setContentHint(stream); + onSuccess({ + stream, + sourceId: streamId, + sourceType: streamType + }); + }, onFailure); } else { // As noted in Chrome Desktop Capture API: // If user didn't select any source (i.e. canceled the prompt) @@ -257,6 +260,7 @@ const ScreenObtainer = { getDisplayMedia(constraints) .then(stream => { + this.setContentHint(stream); callback({ stream, sourceId: stream.id @@ -294,6 +298,7 @@ const ScreenObtainer = { navigator.mediaDevices.getDisplayMedia({ video: true }) .then(stream => { + this.setContentHint(stream); callback({ stream, sourceId: stream.id }); @@ -304,6 +309,24 @@ const ScreenObtainer = { }); }, + /** Sets the contentHint on the transmitted MediaStreamTrack to indicate charaterstics in the video stream, which + * informs RTCPeerConnection on how to encode the track (to prefer motion or individual frame detail). + * + * @param {MediaStream} stream - The captured desktop stream. + * @returns {void} + */ + setContentHint(stream) { + const { desktopSharingFrameRate } = this.options; + const desktopTrack = stream.getVideoTracks()[0]; + + // Set contentHint on the desktop track based on the fps requested. + if ('contentHint' in desktopTrack) { + desktopTrack.contentHint = desktopSharingFrameRate?.max > SS_DEFAULT_FRAME_RATE ? 'motion' : 'detail'; + } else { + logger.warn('MediaStreamTrack contentHint attribute not supported'); + } + }, + /** * Sets the max frame rate to be used for a desktop track capture. * diff --git a/types/hand-crafted/JitsiMeetJS.d.ts b/types/hand-crafted/JitsiMeetJS.d.ts index 25059cdbea1..e6d84f49817 100644 --- a/types/hand-crafted/JitsiMeetJS.d.ts +++ b/types/hand-crafted/JitsiMeetJS.d.ts @@ -137,8 +137,6 @@ export type JitsiMeetJSType = { setNetworkInfo: ( { isOnline: boolean } ) => void; - setVideoTrackContentHints: ( track: MediaStreamTrack, hint: string ) => void; - precallTest: PrecallTest; util: {