2021-05-20 21:54:03 +00:00
|
|
|
// 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';
|
2021-05-20 21:54:03 +00:00
|
|
|
|
|
|
|
type RemoteParticipant = {
|
|
|
|
hasRemoteVideo: boolean;
|
|
|
|
presenting: boolean;
|
|
|
|
title: string;
|
2023-08-16 20:54:39 +00:00
|
|
|
aci?: AciString;
|
2021-05-20 21:54:03 +00:00
|
|
|
};
|
|
|
|
|
2022-05-25 18:03:27 +00:00
|
|
|
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(
|
2021-05-20 21:54:03 +00:00
|
|
|
participant => participant.presenting
|
2023-08-16 20:54:39 +00:00
|
|
|
)?.aci;
|
|
|
|
const prevPresenterAci = usePrevious(presenterAci, presenterAci);
|
2021-05-20 21:54:03 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2023-08-16 20:54:39 +00:00
|
|
|
if (prevPresenterAci !== presenterAci && presenterAci) {
|
2022-05-25 18:03:27 +00:00
|
|
|
switchToPresentationView();
|
2023-08-16 20:54:39 +00:00
|
|
|
} else if (prevPresenterAci && !presenterAci) {
|
2022-05-25 18:03:27 +00:00
|
|
|
switchFromPresentationView();
|
2021-05-20 21:54:03 +00:00
|
|
|
}
|
2022-05-25 18:03:27 +00:00
|
|
|
}, [
|
2023-08-16 20:54:39 +00:00
|
|
|
presenterAci,
|
|
|
|
prevPresenterAci,
|
2022-05-25 18:03:27 +00:00
|
|
|
switchToPresentationView,
|
|
|
|
switchFromPresentationView,
|
|
|
|
]);
|
2021-05-20 21:54:03 +00:00
|
|
|
}
|