Add volume logic to RemoteScreenShareViewModel

Signed-off-by: Jake Janicke <jaketripplj@gmail.com>
This commit is contained in:
Jake Janicke
2026-03-03 16:47:41 -06:00
parent 00f880108e
commit 2cf4a38c17

View File

@@ -6,8 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details. Please see LICENSE in the repository root for full details.
*/ */
import { type RemoteParticipant } from "livekit-client"; import { Track, type RemoteParticipant } from "livekit-client";
import { map } from "rxjs"; import { map, of, switchMap } from "rxjs";
import { type Behavior } from "../Behavior"; import { type Behavior } from "../Behavior";
import { import {
@@ -16,13 +16,17 @@ import {
createBaseScreenShare, createBaseScreenShare,
} from "./ScreenShareViewModel"; } from "./ScreenShareViewModel";
import { type ObservableScope } from "../ObservableScope"; import { type ObservableScope } from "../ObservableScope";
import { createVolumeControls, type VolumeControls } from "../VolumeControls";
import { observeTrackReference$ } from "../observeTrackReference";
export interface RemoteScreenShareViewModel extends BaseScreenShareViewModel { export interface RemoteScreenShareViewModel
extends BaseScreenShareViewModel, VolumeControls {
local: false; local: false;
/** /**
* Whether this screen share's video should be displayed. * Whether this screen share's video should be displayed.
*/ */
videoEnabled$: Behavior<boolean>; videoEnabled$: Behavior<boolean>;
audioEnabled$: Behavior<boolean>;
} }
export interface RemoteScreenShareInputs extends BaseScreenShareInputs { export interface RemoteScreenShareInputs extends BaseScreenShareInputs {
@@ -36,9 +40,30 @@ export function createRemoteScreenShare(
): RemoteScreenShareViewModel { ): RemoteScreenShareViewModel {
return { return {
...createBaseScreenShare(scope, inputs), ...createBaseScreenShare(scope, inputs),
...createVolumeControls(scope, {
pretendToBeDisconnected$,
sink$: scope.behavior(
inputs.participant$.pipe(
map(
(p) => (volume) =>
p?.setVolume(volume, Track.Source.ScreenShareAudio),
),
),
),
}),
local: false, local: false,
videoEnabled$: scope.behavior( videoEnabled$: scope.behavior(
pretendToBeDisconnected$.pipe(map((disconnected) => !disconnected)), pretendToBeDisconnected$.pipe(map((disconnected) => !disconnected)),
), ),
audioEnabled$: scope.behavior(
inputs.participant$.pipe(
switchMap((p) =>
p
? observeTrackReference$(p, Track.Source.ScreenShareAudio)
: of(null),
),
map(Boolean),
),
),
}; };
} }