mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-29 21:15:19 +00:00
Tidy up ring sync and add comments.
This commit is contained in:
@@ -356,15 +356,24 @@ export const InCallView: FC<InCallViewProps> = ({
|
|||||||
const audioOutputSwitcher = useBehavior(vm.audioOutputSwitcher$);
|
const audioOutputSwitcher = useBehavior(vm.audioOutputSwitcher$);
|
||||||
useSubscription(vm.autoLeave$, onLeave);
|
useSubscription(vm.autoLeave$, onLeave);
|
||||||
|
|
||||||
const ringDelay = (pickupPhaseAudio?.soundDuration["waiting"] ?? 1) * 2;
|
// We need to set the proper timings on the animation based upon the sound length.
|
||||||
|
const ringDuration = pickupPhaseAudio?.soundDuration["waiting"] ?? 1;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// The CSS animation includes the delay, so we must double the length of the sound.
|
||||||
window.document.body.style.setProperty(
|
window.document.body.style.setProperty(
|
||||||
"--call-ring-duration-s",
|
"--call-ring-duration-s",
|
||||||
`${ringDelay}s`,
|
`${ringDuration * 2}s`,
|
||||||
);
|
);
|
||||||
window.document.body.style.setProperty("--call-ring-delay-s", `1s`);
|
window.document.body.style.setProperty(
|
||||||
}, [pickupPhaseAudio?.soundDuration, ringDelay]);
|
"--call-ring-delay-s",
|
||||||
|
`${ringDuration}s`,
|
||||||
|
);
|
||||||
|
// Remove properties when we unload.
|
||||||
|
return () => {
|
||||||
|
window.document.body.style.removeProperty("--call-ring-duration-s");
|
||||||
|
window.document.body.style.removeProperty("--call-ring-delay-s");
|
||||||
|
};
|
||||||
|
}, [pickupPhaseAudio?.soundDuration, ringDuration]);
|
||||||
|
|
||||||
// When we enter timeout or decline we will leave the call.
|
// When we enter timeout or decline we will leave the call.
|
||||||
useEffect((): void | (() => void) => {
|
useEffect((): void | (() => void) => {
|
||||||
@@ -394,16 +403,13 @@ export const InCallView: FC<InCallViewProps> = ({
|
|||||||
// When waiting for pickup, loop a waiting sound
|
// When waiting for pickup, loop a waiting sound
|
||||||
useEffect((): void | (() => void) => {
|
useEffect((): void | (() => void) => {
|
||||||
if (callPickupState !== "ringing" || !pickupPhaseAudio) return;
|
if (callPickupState !== "ringing" || !pickupPhaseAudio) return;
|
||||||
const endSound = pickupPhaseAudio.playSoundLooping(
|
const endSound = pickupPhaseAudio.playSoundLooping("waiting", ringDuration);
|
||||||
"waiting",
|
|
||||||
ringDelay / 2,
|
|
||||||
);
|
|
||||||
return () => {
|
return () => {
|
||||||
void endSound().catch((e) => {
|
void endSound().catch((e) => {
|
||||||
logger.error("Failed to stop ringing sound", e);
|
logger.error("Failed to stop ringing sound", e);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}, [callPickupState, pickupPhaseAudio, ringDelay]);
|
}, [callPickupState, pickupPhaseAudio, ringDuration]);
|
||||||
|
|
||||||
// Waiting UI overlay
|
// Waiting UI overlay
|
||||||
const waitingOverlay: JSX.Element | null = useMemo(() => {
|
const waitingOverlay: JSX.Element | null = useMemo(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user