2022-05-04 17:09:48 +01:00
|
|
|
/*
|
|
|
|
Copyright 2022 Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-04-07 14:22:36 -07:00
|
|
|
import { SDPStreamMetadataPurpose } from "matrix-js-sdk/src/webrtc/callEventTypes";
|
|
|
|
import React from "react";
|
2022-08-12 19:27:34 +02:00
|
|
|
import { useCallback } from "react";
|
2022-08-12 16:46:53 -04:00
|
|
|
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
2022-08-12 19:27:34 +02:00
|
|
|
|
2022-04-07 14:22:36 -07:00
|
|
|
import { useCallFeed } from "./useCallFeed";
|
2022-05-31 10:43:05 -04:00
|
|
|
import { useSpatialMediaStream } from "./useMediaStream";
|
2022-04-07 14:22:36 -07:00
|
|
|
import { useRoomMemberName } from "./useRoomMemberName";
|
|
|
|
import { VideoTile } from "./VideoTile";
|
2022-07-15 11:18:56 +02:00
|
|
|
import { VideoTileSettingsModal } from "./VideoTileSettingsModal";
|
|
|
|
import { useModalTriggerState } from "../Modal";
|
2022-12-16 17:12:17 +00:00
|
|
|
import { TileDescriptor } from "./TileDescriptor";
|
2022-07-15 11:18:56 +02:00
|
|
|
|
2022-08-12 19:27:34 +02:00
|
|
|
interface Props {
|
2022-10-21 17:24:56 +01:00
|
|
|
item: TileDescriptor;
|
2022-08-12 19:27:34 +02:00
|
|
|
width?: number;
|
|
|
|
height?: number;
|
|
|
|
getAvatar: (
|
|
|
|
roomMember: RoomMember,
|
|
|
|
width: number,
|
|
|
|
height: number
|
|
|
|
) => JSX.Element;
|
|
|
|
audioContext: AudioContext;
|
|
|
|
audioDestination: AudioNode;
|
|
|
|
disableSpeakingIndicator: boolean;
|
2022-09-14 19:05:05 -04:00
|
|
|
maximised: boolean;
|
|
|
|
fullscreen: boolean;
|
2022-10-21 17:24:56 +01:00
|
|
|
onFullscreen: (item: TileDescriptor) => void;
|
2022-08-12 19:27:34 +02:00
|
|
|
}
|
2022-09-14 19:05:05 -04:00
|
|
|
|
2022-04-07 14:22:36 -07:00
|
|
|
export function VideoTileContainer({
|
|
|
|
item,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
getAvatar,
|
2022-05-31 10:43:05 -04:00
|
|
|
audioContext,
|
2022-06-13 13:31:44 -04:00
|
|
|
audioDestination,
|
2022-04-07 14:22:36 -07:00
|
|
|
disableSpeakingIndicator,
|
2022-09-14 19:05:05 -04:00
|
|
|
maximised,
|
|
|
|
fullscreen,
|
2022-08-07 19:09:45 +02:00
|
|
|
onFullscreen,
|
2022-04-07 14:22:36 -07:00
|
|
|
...rest
|
2022-08-12 19:27:34 +02:00
|
|
|
}: Props) {
|
2022-04-07 14:22:36 -07:00
|
|
|
const {
|
|
|
|
isLocal,
|
|
|
|
audioMuted,
|
|
|
|
videoMuted,
|
2022-07-15 11:18:56 +02:00
|
|
|
localVolume,
|
2022-04-07 14:22:36 -07:00
|
|
|
speaking,
|
|
|
|
stream,
|
|
|
|
purpose,
|
|
|
|
} = useCallFeed(item.callFeed);
|
2022-10-21 17:24:56 +01:00
|
|
|
const { rawDisplayName } = useRoomMemberName(item.member);
|
2022-05-31 10:43:05 -04:00
|
|
|
const [tileRef, mediaRef] = useSpatialMediaStream(
|
2022-11-02 12:34:31 -04:00
|
|
|
stream ?? null,
|
2022-05-31 10:43:05 -04:00
|
|
|
audioContext,
|
2022-06-13 13:31:44 -04:00
|
|
|
audioDestination,
|
2022-11-07 11:41:49 -05:00
|
|
|
localVolume,
|
2022-12-19 15:10:25 +00:00
|
|
|
// The feed is muted if it's local audio (because we don't want our own audio,
|
|
|
|
// but it's a hook and we can't call it conditionally so we're stuck with it)
|
|
|
|
// or if there's a maximised feed in which case we always render audio via audio
|
|
|
|
// elements because we wire it up at the video tile container level and only one
|
|
|
|
// video tile container is displayed.
|
|
|
|
isLocal || maximised
|
2022-05-31 10:43:05 -04:00
|
|
|
);
|
2022-07-15 11:22:13 +02:00
|
|
|
const {
|
|
|
|
modalState: videoTileSettingsModalState,
|
|
|
|
modalProps: videoTileSettingsModalProps,
|
|
|
|
} = useModalTriggerState();
|
2022-07-15 11:18:56 +02:00
|
|
|
const onOptionsPress = () => {
|
|
|
|
videoTileSettingsModalState.open();
|
2022-07-15 11:22:13 +02:00
|
|
|
};
|
2022-04-07 14:22:36 -07:00
|
|
|
|
2022-08-08 20:05:44 +02:00
|
|
|
const onFullscreenCallback = useCallback(() => {
|
|
|
|
onFullscreen(item);
|
|
|
|
}, [onFullscreen, item]);
|
|
|
|
|
2022-04-07 14:22:36 -07:00
|
|
|
// Firefox doesn't respect the disablePictureInPicture attribute
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1611831
|
|
|
|
|
|
|
|
return (
|
2022-07-15 11:18:56 +02:00
|
|
|
<>
|
|
|
|
<VideoTile
|
|
|
|
isLocal={isLocal}
|
|
|
|
speaking={speaking && !disableSpeakingIndicator}
|
|
|
|
audioMuted={audioMuted}
|
|
|
|
videoMuted={videoMuted}
|
|
|
|
screenshare={purpose === SDPStreamMetadataPurpose.Screenshare}
|
|
|
|
name={rawDisplayName}
|
2022-11-15 16:13:33 +00:00
|
|
|
connectionState={item.connectionState}
|
2022-07-15 11:18:56 +02:00
|
|
|
ref={tileRef}
|
|
|
|
mediaRef={mediaRef}
|
2022-10-21 17:24:56 +01:00
|
|
|
avatar={getAvatar && getAvatar(item.member, width, height)}
|
2022-07-15 11:18:56 +02:00
|
|
|
onOptionsPress={onOptionsPress}
|
2022-08-02 14:30:12 +02:00
|
|
|
localVolume={localVolume}
|
2022-09-14 19:05:05 -04:00
|
|
|
maximised={maximised}
|
|
|
|
fullscreen={fullscreen}
|
2022-08-08 20:05:44 +02:00
|
|
|
onFullscreen={onFullscreenCallback}
|
2022-07-15 11:18:56 +02:00
|
|
|
{...rest}
|
|
|
|
/>
|
2022-11-02 12:34:31 -04:00
|
|
|
{videoTileSettingsModalState.isOpen && !maximised && item.callFeed && (
|
2022-07-15 11:22:13 +02:00
|
|
|
<VideoTileSettingsModal
|
|
|
|
{...videoTileSettingsModalProps}
|
|
|
|
feed={item.callFeed}
|
|
|
|
/>
|
|
|
|
)}
|
2022-07-15 11:18:56 +02:00
|
|
|
</>
|
2022-04-07 14:22:36 -07:00
|
|
|
);
|
|
|
|
}
|