2024-06-07 16:59:56 -04:00
|
|
|
/*
|
2024-09-06 10:22:13 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2024-06-07 16:59:56 -04:00
|
|
|
|
2024-09-06 10:22:13 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
Please see LICENSE in the repository root for full details.
|
2024-06-07 16:59:56 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { forwardRef, useCallback, useMemo } from "react";
|
|
|
|
|
import { useObservableEagerState } from "observable-hooks";
|
|
|
|
|
import classNames from "classnames";
|
|
|
|
|
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type OneOnOneLayout as OneOnOneLayoutModel } from "../state/CallViewModel";
|
|
|
|
|
import { type CallLayout, arrangeTiles } from "./CallLayout";
|
2024-06-07 16:59:56 -04:00
|
|
|
import styles from "./OneOnOneLayout.module.css";
|
2024-12-11 09:27:55 +00:00
|
|
|
import { type DragCallback, useUpdateLayout } from "./Grid";
|
2024-06-07 16:59:56 -04:00
|
|
|
|
2024-07-18 11:33:20 -04:00
|
|
|
/**
|
|
|
|
|
* An implementation of the "one-on-one" layout, in which the remote participant
|
|
|
|
|
* is shown at maximum size, overlaid by a small view of the local participant.
|
|
|
|
|
*/
|
2024-06-07 16:59:56 -04:00
|
|
|
export const makeOneOnOneLayout: CallLayout<OneOnOneLayoutModel> = ({
|
2024-12-17 04:01:56 +00:00
|
|
|
minBounds$,
|
|
|
|
|
pipAlignment$,
|
2024-06-07 16:59:56 -04:00
|
|
|
}) => ({
|
2024-07-03 15:08:30 -04:00
|
|
|
scrollingOnTop: false,
|
2024-06-07 16:59:56 -04:00
|
|
|
|
2024-07-03 15:08:30 -04:00
|
|
|
fixed: forwardRef(function OneOnOneLayoutFixed(_props, ref) {
|
2024-07-25 12:50:28 -04:00
|
|
|
useUpdateLayout();
|
2024-07-24 16:57:20 -04:00
|
|
|
return <div ref={ref} />;
|
2024-06-07 16:59:56 -04:00
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
scrolling: forwardRef(function OneOnOneLayoutScrolling({ model, Slot }, ref) {
|
2024-07-25 12:50:28 -04:00
|
|
|
useUpdateLayout();
|
2024-12-17 04:01:56 +00:00
|
|
|
const { width, height } = useObservableEagerState(minBounds$);
|
|
|
|
|
const pipAlignmentValue = useObservableEagerState(pipAlignment$);
|
2024-06-07 16:59:56 -04:00
|
|
|
const { tileWidth, tileHeight } = useMemo(
|
|
|
|
|
() => arrangeTiles(width, height, 1),
|
|
|
|
|
[width, height],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const onDragLocalTile: DragCallback = useCallback(
|
|
|
|
|
({ xRatio, yRatio }) =>
|
2024-12-17 04:01:56 +00:00
|
|
|
pipAlignment$.next({
|
2024-06-07 16:59:56 -04:00
|
|
|
block: yRatio < 0.5 ? "start" : "end",
|
|
|
|
|
inline: xRatio < 0.5 ? "start" : "end",
|
|
|
|
|
}),
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
2024-07-24 16:57:20 -04:00
|
|
|
<div ref={ref} className={styles.layer}>
|
2024-06-07 16:59:56 -04:00
|
|
|
<Slot
|
2024-11-06 04:36:48 -05:00
|
|
|
id={model.remote.id}
|
|
|
|
|
model={model.remote}
|
2024-06-07 16:59:56 -04:00
|
|
|
className={styles.container}
|
|
|
|
|
style={{ width: tileWidth, height: tileHeight }}
|
|
|
|
|
>
|
|
|
|
|
<Slot
|
|
|
|
|
className={classNames(styles.slot, styles.local)}
|
2024-11-06 04:36:48 -05:00
|
|
|
id={model.local.id}
|
|
|
|
|
model={model.local}
|
2024-06-07 16:59:56 -04:00
|
|
|
onDrag={onDragLocalTile}
|
|
|
|
|
data-block-alignment={pipAlignmentValue.block}
|
|
|
|
|
data-inline-alignment={pipAlignmentValue.inline}
|
|
|
|
|
/>
|
|
|
|
|
</Slot>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
});
|