Skip to content

Commit 1aa1af2

Browse files
authored
Merge pull request #3585 from element-hq/toger5/add-log-screenshare
Add log to screenshare
2 parents f6ef872 + ccadc17 commit 1aa1af2

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

src/state/CallViewModel/localMember/LocalMembership.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
type Participant,
1111
ParticipantEvent,
1212
type LocalParticipant,
13+
type ScreenShareCaptureOptions,
1314
} from "livekit-client";
1415
import { observeParticipantEvents } from "@livekit/components-core";
1516
import {
@@ -516,27 +517,37 @@ export const createLocalMembership$ = ({
516517
),
517518
);
518519

519-
const toggleScreenSharing =
520+
let toggleScreenSharing = null;
521+
if (
520522
"getDisplayMedia" in (navigator.mediaDevices ?? {}) &&
521523
!getUrlParams().hideScreensharing
522-
? (): void =>
523-
// If a connection is ready, toggle screen sharing.
524-
// We deliberately do nothing in the case of a null connection because
525-
// it looks nice for the call control buttons to all become available
526-
// at once upon joining the call, rather than introducing a disabled
527-
// state. The user can just click again.
528-
// We also allow screen sharing to be toggled even if the connection
529-
// is still initializing or publishing tracks, because there's no
530-
// technical reason to disallow this. LiveKit will publish if it can.
531-
void localConnection$.value?.livekitRoom.localParticipant
532-
.setScreenShareEnabled(!sharingScreen$.value, {
533-
audio: true,
534-
selfBrowserSurface: "include",
535-
surfaceSwitching: "include",
536-
systemAudio: "include",
537-
})
538-
.catch(logger.error)
539-
: null;
524+
) {
525+
toggleScreenSharing = (): void => {
526+
const screenshareSettings: ScreenShareCaptureOptions = {
527+
audio: true,
528+
selfBrowserSurface: "include",
529+
surfaceSwitching: "include",
530+
systemAudio: "include",
531+
};
532+
const targetScreenshareState = !sharingScreen$.value;
533+
logger.info(
534+
`toggleScreenSharing called. Switching ${
535+
targetScreenshareState ? "On" : "Off"
536+
}`,
537+
);
538+
// If a connection is ready, toggle screen sharing.
539+
// We deliberately do nothing in the case of a null connection because
540+
// it looks nice for the call control buttons to all become available
541+
// at once upon joining the call, rather than introducing a disabled
542+
// state. The user can just click again.
543+
// We also allow screen sharing to be toggled even if the connection
544+
// is still initializing or publishing tracks, because there's no
545+
// technical reason to disallow this. LiveKit will publish if it can.
546+
localConnection$.value?.livekitRoom.localParticipant
547+
.setScreenShareEnabled(targetScreenshareState, screenshareSettings)
548+
.catch(logger.error);
549+
};
550+
}
540551

541552
const participant$ = scope.behavior(
542553
localConnection$.pipe(map((c) => c?.livekitRoom.localParticipant ?? null)),

0 commit comments

Comments
 (0)