2021-05-20 21:54:03 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { useEffect } from 'react';
|
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;
|
|
|
|
uuid?: string;
|
|
|
|
};
|
|
|
|
|
2022-05-25 18:03:27 +00:00
|
|
|
export function useActivateSpeakerViewOnPresenting({
|
|
|
|
remoteParticipants,
|
|
|
|
switchToPresentationView,
|
|
|
|
switchFromPresentationView,
|
|
|
|
}: {
|
|
|
|
remoteParticipants: ReadonlyArray<RemoteParticipant>;
|
|
|
|
switchToPresentationView: () => void;
|
|
|
|
switchFromPresentationView: () => void;
|
|
|
|
}): void {
|
2021-05-20 21:54:03 +00:00
|
|
|
const presenterUuid = remoteParticipants.find(
|
|
|
|
participant => participant.presenting
|
|
|
|
)?.uuid;
|
|
|
|
const prevPresenterUuid = usePrevious(presenterUuid, presenterUuid);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-05-25 18:03:27 +00:00
|
|
|
if (prevPresenterUuid !== presenterUuid && presenterUuid) {
|
|
|
|
switchToPresentationView();
|
|
|
|
} else if (prevPresenterUuid && !presenterUuid) {
|
|
|
|
switchFromPresentationView();
|
2021-05-20 21:54:03 +00:00
|
|
|
}
|
2022-05-25 18:03:27 +00:00
|
|
|
}, [
|
|
|
|
presenterUuid,
|
|
|
|
prevPresenterUuid,
|
|
|
|
switchToPresentationView,
|
|
|
|
switchFromPresentationView,
|
|
|
|
]);
|
2021-05-20 21:54:03 +00:00
|
|
|
}
|