From 50a07ed203391281a94114d699e2cf9033c26439 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Mon, 16 Oct 2023 13:04:19 +0200 Subject: [PATCH] openvidu-browser: fix wrong screen audio track management --- openvidu-browser/src/OpenVidu/OpenVidu.ts | 17 +++++++++++++++++ openvidu-browser/src/OpenVidu/Publisher.ts | 1 + 2 files changed, 18 insertions(+) diff --git a/openvidu-browser/src/OpenVidu/OpenVidu.ts b/openvidu-browser/src/OpenVidu/OpenVidu.ts index fa7f61916f..7a5077101f 100644 --- a/openvidu-browser/src/OpenVidu/OpenVidu.ts +++ b/openvidu-browser/src/OpenVidu/OpenVidu.ts @@ -568,6 +568,7 @@ export class OpenVidu { // getDisplayMedia supported try { const mediaStream = await navigator.mediaDevices['getDisplayMedia']({ video: true, audio: options.audioSource === 'screen' }); + this.removeScreenAudioTrackIfNotAvailable(mediaStream); this.addAlreadyProvidedTracks(myConstraints, mediaStream); if (mustAskForAudioTrackLater) { return await askForAudioStreamOnly(mediaStream, myConstraints.constraints); @@ -1161,6 +1162,21 @@ export class OpenVidu { } } + /** + * @hidden + */ + removeScreenAudioTrackIfNotAvailable(mediaStream: MediaStream) { + const [screenVideoTrack] = mediaStream.getVideoTracks(); + const displaySurface = (screenVideoTrack.getSettings() as any).displaySurface; + if (displaySurface !== 'browser') { + // tab screen share. This is the only way in CHromium right now that is possible to share the audio of a screen + mediaStream.getAudioTracks().forEach((screenAudioTrack) => { + mediaStream.removeTrack(screenAudioTrack); + screenAudioTrack.stop(); + }); + } + } + /** * @hidden */ @@ -1298,4 +1314,5 @@ export class OpenVidu { private isScreenShare(videoSource: string) { return videoSource === 'screen' || videoSource === 'window' || (platform.isElectron() && videoSource.startsWith('screen:')); } + } diff --git a/openvidu-browser/src/OpenVidu/Publisher.ts b/openvidu-browser/src/OpenVidu/Publisher.ts index 4623cf7f4a..e2c4bfbc8c 100644 --- a/openvidu-browser/src/OpenVidu/Publisher.ts +++ b/openvidu-browser/src/OpenVidu/Publisher.ts @@ -645,6 +645,7 @@ export class Publisher extends StreamManager { try { if (this.stream.isSendScreen() && navigator.mediaDevices['getDisplayMedia'] && !platform.isElectron()) { const mediaStream = await navigator.mediaDevices['getDisplayMedia']({ video: true, audio: this.properties.audioSource === 'screen' }); + this.openvidu.removeScreenAudioTrackIfNotAvailable(mediaStream); this.openvidu.addAlreadyProvidedTracks(myConstraints, mediaStream); await getMediaSuccess(mediaStream, definedAudioConstraint); } else {