From 84a92845c346a326f9df22e0ed475035a23f7251 Mon Sep 17 00:00:00 2001 From: Robin Townsend Date: Wed, 2 Nov 2022 12:34:31 -0400 Subject: [PATCH] Don't show toolbar buttons on connecting tiles Because connecting tiles don't have a feed, clicking the local volume button would cause a soft crash. This also fixes a few strict mode errors in the surrounding area while we're at it. --- src/video-grid/VideoTile.tsx | 2 +- src/video-grid/VideoTileContainer.tsx | 4 ++-- src/video-grid/useAudioOutputDevice.ts | 2 +- src/video-grid/useCallFeed.ts | 13 +++++++------ src/video-grid/useMediaStream.ts | 20 ++++++++++---------- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/video-grid/VideoTile.tsx b/src/video-grid/VideoTile.tsx index 1a6b230..708cb91 100644 --- a/src/video-grid/VideoTile.tsx +++ b/src/video-grid/VideoTile.tsx @@ -72,7 +72,7 @@ export const VideoTile = forwardRef( const { t } = useTranslation(); const toolbarButtons: JSX.Element[] = []; - if (!isLocal) { + if (hasFeed && !isLocal) { toolbarButtons.push( - {videoTileSettingsModalState.isOpen && !maximised && ( + {videoTileSettingsModalState.isOpen && !maximised && item.callFeed && ( , - audioOutputDevice: string + audioOutputDevice: string | undefined ): void { useEffect(() => { if ( diff --git a/src/video-grid/useCallFeed.ts b/src/video-grid/useCallFeed.ts index 7f66233..229df3c 100644 --- a/src/video-grid/useCallFeed.ts +++ b/src/video-grid/useCallFeed.ts @@ -19,17 +19,18 @@ import { CallFeed, CallFeedEvent } from "matrix-js-sdk/src/webrtc/callFeed"; import { SDPStreamMetadataPurpose } from "matrix-js-sdk/src/webrtc/callEventTypes"; interface CallFeedState { - callFeed: CallFeed; + callFeed: CallFeed | undefined; isLocal: boolean; speaking: boolean; videoMuted: boolean; audioMuted: boolean; localVolume: number; - disposed: boolean; - stream: MediaStream; - purpose: SDPStreamMetadataPurpose; + disposed: boolean | undefined; + stream: MediaStream | undefined; + purpose: SDPStreamMetadataPurpose | undefined; } -function getCallFeedState(callFeed: CallFeed): CallFeedState { + +function getCallFeedState(callFeed: CallFeed | undefined): CallFeedState { return { callFeed, isLocal: callFeed ? callFeed.isLocal() : false, @@ -43,7 +44,7 @@ function getCallFeedState(callFeed: CallFeed): CallFeedState { }; } -export function useCallFeed(callFeed: CallFeed): CallFeedState { +export function useCallFeed(callFeed: CallFeed | undefined): CallFeedState { const [state, setState] = useState(() => getCallFeedState(callFeed) ); diff --git a/src/video-grid/useMediaStream.ts b/src/video-grid/useMediaStream.ts index aae942d..61c6524 100644 --- a/src/video-grid/useMediaStream.ts +++ b/src/video-grid/useMediaStream.ts @@ -64,8 +64,8 @@ export const useMediaStreamTrackCount = ( }; export const useMediaStream = ( - stream: MediaStream, - audioOutputDevice: string, + stream: MediaStream | null, + audioOutputDevice: string | null, mute = false, localVolume?: number ): RefObject => { @@ -158,7 +158,7 @@ const createLoopback = async (stream: MediaStream): Promise => { await loopbackConn.setRemoteDescription(offer); const answer = await loopbackConn.createAnswer(); // Rewrite SDP to be stereo and (variable) max bitrate - const parsedSdp = parseSdp(answer.sdp); + const parsedSdp = parseSdp(answer.sdp!); parsedSdp.media.forEach((m) => m.fmtp.forEach( (f) => (f.config += `;stereo=1;cbr=0;maxaveragebitrate=510000;`) @@ -206,11 +206,11 @@ export const useAudioContext = (): [ } }, []); - return [context.current, destination.current, audioRef]; + return [context.current!, destination.current!, audioRef]; }; export const useSpatialMediaStream = ( - stream: MediaStream, + stream: MediaStream | null, audioContext: AudioContext, audioDestination: AudioNode, mute = false, @@ -219,7 +219,7 @@ export const useSpatialMediaStream = ( const tileRef = useRef(); const [spatialAudio] = useSpatialAudio(); // We always handle audio separately form the video element - const mediaRef = useMediaStream(stream, undefined, true, undefined); + const mediaRef = useMediaStream(stream, null, true); const [audioTrackCount] = useMediaStreamTrackCount(stream); const gainNodeRef = useRef(); @@ -240,7 +240,7 @@ export const useSpatialMediaStream = ( }); } if (!sourceRef.current) { - sourceRef.current = audioContext.createMediaStreamSource(stream); + sourceRef.current = audioContext.createMediaStreamSource(stream!); } const tile = tileRef.current; @@ -252,12 +252,12 @@ export const useSpatialMediaStream = ( const bounds = tile.getBoundingClientRect(); const windowSize = Math.max(window.innerWidth, window.innerHeight); // Position the source relative to its placement in the window - pannerNodeRef.current.positionX.value = + pannerNodeRef.current!.positionX.value = (bounds.x + bounds.width / 2) / windowSize - 0.5; - pannerNodeRef.current.positionY.value = + pannerNodeRef.current!.positionY.value = (bounds.y + bounds.height / 2) / windowSize - 0.5; // Put the source in front of the listener - pannerNodeRef.current.positionZ.value = -2; + pannerNodeRef.current!.positionZ.value = -2; }; gainNode.gain.value = localVolume;