signal-desktop/ts/hooks/useActivateSpeakerViewOnPresenting.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { useEffect } from 'react';
2023-08-16 20:54:39 +00:00
import type { AciString } from '../types/ServiceId';
2021-09-17 22:24:21 +00:00
import { usePrevious } from './usePrevious';
type RemoteParticipant = {
hasRemoteVideo: boolean;
presenting: boolean;
title: string;
2023-08-16 20:54:39 +00:00
aci?: AciString;
};
export function useActivateSpeakerViewOnPresenting({
remoteParticipants,
switchToPresentationView,
switchFromPresentationView,
}: {
remoteParticipants: ReadonlyArray<RemoteParticipant>;
switchToPresentationView: () => void;
switchFromPresentationView: () => void;
}): void {
2023-08-16 20:54:39 +00:00
const presenterAci = remoteParticipants.find(
participant => participant.presenting
2023-08-16 20:54:39 +00:00
)?.aci;
const prevPresenterAci = usePrevious(presenterAci, presenterAci);
useEffect(() => {
2023-08-16 20:54:39 +00:00
if (prevPresenterAci !== presenterAci && presenterAci) {
switchToPresentationView();
2023-08-16 20:54:39 +00:00
} else if (prevPresenterAci && !presenterAci) {
switchFromPresentationView();
}
}, [
2023-08-16 20:54:39 +00:00
presenterAci,
prevPresenterAci,
switchToPresentationView,
switchFromPresentationView,
]);
}