New attempt to fix windows screenshare
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { ScreenShareQualityPreset, ScreenShareStartOptions } from '../screen-share.config';
|
import { ScreenShareQualityPreset, ScreenShareStartOptions } from '../screen-share.config';
|
||||||
import { WebRTCLogger } from '../webrtc-logger';
|
import { WebRTCLogger } from '../webrtc-logger';
|
||||||
|
import { ScreenShareWindow } from './shared';
|
||||||
|
|
||||||
export class BrowserScreenShareCapture {
|
export class BrowserScreenShareCapture {
|
||||||
constructor(private readonly logger: WebRTCLogger) {}
|
constructor(private readonly logger: WebRTCLogger) {}
|
||||||
@@ -16,7 +17,11 @@ export class BrowserScreenShareCapture {
|
|||||||
throw new Error('navigator.mediaDevices.getDisplayMedia is not available.');
|
throw new Error('navigator.mediaDevices.getDisplayMedia is not available.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return await navigator.mediaDevices.getDisplayMedia(displayConstraints);
|
const stream = await navigator.mediaDevices.getDisplayMedia(displayConstraints);
|
||||||
|
|
||||||
|
this.logAudioTrackSettings(stream);
|
||||||
|
|
||||||
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildDisplayMediaConstraints(
|
private buildDisplayMediaConstraints(
|
||||||
@@ -24,6 +29,7 @@ export class BrowserScreenShareCapture {
|
|||||||
preset: ScreenShareQualityPreset
|
preset: ScreenShareQualityPreset
|
||||||
): DisplayMediaStreamOptions {
|
): DisplayMediaStreamOptions {
|
||||||
const supportedConstraints = navigator.mediaDevices?.getSupportedConstraints?.() as Record<string, boolean> | undefined;
|
const supportedConstraints = navigator.mediaDevices?.getSupportedConstraints?.() as Record<string, boolean> | undefined;
|
||||||
|
const isWindowsElectron = this.isWindowsElectron();
|
||||||
const audioConstraints: Record<string, unknown> | false = options.includeSystemAudio
|
const audioConstraints: Record<string, unknown> | false = options.includeSystemAudio
|
||||||
? {
|
? {
|
||||||
echoCancellation: false,
|
echoCancellation: false,
|
||||||
@@ -37,7 +43,10 @@ export class BrowserScreenShareCapture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (audioConstraints && supportedConstraints?.['suppressLocalAudioPlayback']) {
|
if (audioConstraints && supportedConstraints?.['suppressLocalAudioPlayback']) {
|
||||||
audioConstraints['suppressLocalAudioPlayback'] = true;
|
// Windows Electron should keep voice playback audible to the sharer.
|
||||||
|
// Use own-audio restriction to keep the app's playback out of the
|
||||||
|
// captured stream instead of muting local playback.
|
||||||
|
audioConstraints['suppressLocalAudioPlayback'] = !isWindowsElectron;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -53,4 +62,31 @@ export class BrowserScreenShareCapture {
|
|||||||
systemAudio: options.includeSystemAudio ? 'include' : 'exclude'
|
systemAudio: options.includeSystemAudio ? 'include' : 'exclude'
|
||||||
} as DisplayMediaStreamOptions;
|
} as DisplayMediaStreamOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private logAudioTrackSettings(stream: MediaStream): void {
|
||||||
|
const audioTrack = stream.getAudioTracks()[0];
|
||||||
|
|
||||||
|
if (!audioTrack || typeof audioTrack.getSettings !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const settings = audioTrack.getSettings() as MediaTrackSettings & {
|
||||||
|
restrictOwnAudio?: boolean;
|
||||||
|
suppressLocalAudioPlayback?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.logger.info('getDisplayMedia audio track settings', {
|
||||||
|
restrictOwnAudio: settings.restrictOwnAudio ?? null,
|
||||||
|
suppressLocalAudioPlayback: settings.suppressLocalAudioPlayback ?? null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private isWindowsElectron(): boolean {
|
||||||
|
if (typeof window === 'undefined' || typeof navigator === 'undefined') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!(window as ScreenShareWindow).electronAPI
|
||||||
|
&& /win/i.test(`${navigator.userAgent} ${navigator.platform}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user