Merge pull request #3585 from element-hq/toger5/add-log-screenshare

Add log to screenshare
This commit is contained in:
Timo
2025-11-21 16:58:04 +01:00
committed by GitHub

View File

@@ -10,6 +10,7 @@ import {
type Participant, type Participant,
ParticipantEvent, ParticipantEvent,
type LocalParticipant, type LocalParticipant,
type ScreenShareCaptureOptions,
} from "livekit-client"; } from "livekit-client";
import { observeParticipantEvents } from "@livekit/components-core"; import { observeParticipantEvents } from "@livekit/components-core";
import { import {
@@ -516,10 +517,24 @@ export const createLocalMembership$ = ({
), ),
); );
const toggleScreenSharing = let toggleScreenSharing = null;
if (
"getDisplayMedia" in (navigator.mediaDevices ?? {}) && "getDisplayMedia" in (navigator.mediaDevices ?? {}) &&
!getUrlParams().hideScreensharing !getUrlParams().hideScreensharing
? (): void => ) {
toggleScreenSharing = (): void => {
const screenshareSettings: ScreenShareCaptureOptions = {
audio: true,
selfBrowserSurface: "include",
surfaceSwitching: "include",
systemAudio: "include",
};
const targetScreenshareState = !sharingScreen$.value;
logger.info(
`toggleScreenSharing called. Switching ${
targetScreenshareState ? "On" : "Off"
}`,
);
// If a connection is ready, toggle screen sharing. // If a connection is ready, toggle screen sharing.
// We deliberately do nothing in the case of a null connection because // We deliberately do nothing in the case of a null connection because
// it looks nice for the call control buttons to all become available // it looks nice for the call control buttons to all become available
@@ -528,15 +543,11 @@ export const createLocalMembership$ = ({
// We also allow screen sharing to be toggled even if the connection // We also allow screen sharing to be toggled even if the connection
// is still initializing or publishing tracks, because there's no // is still initializing or publishing tracks, because there's no
// technical reason to disallow this. LiveKit will publish if it can. // technical reason to disallow this. LiveKit will publish if it can.
void localConnection$.value?.livekitRoom.localParticipant localConnection$.value?.livekitRoom.localParticipant
.setScreenShareEnabled(!sharingScreen$.value, { .setScreenShareEnabled(targetScreenshareState, screenshareSettings)
audio: true, .catch(logger.error);
selfBrowserSurface: "include", };
surfaceSwitching: "include", }
systemAudio: "include",
})
.catch(logger.error)
: null;
const participant$ = scope.behavior( const participant$ = scope.behavior(
localConnection$.pipe(map((c) => c?.livekitRoom.localParticipant ?? null)), localConnection$.pipe(map((c) => c?.livekitRoom.localParticipant ?? null)),