From 45be19a17fae84c89aed07419c0c62056a6d1b3c Mon Sep 17 00:00:00 2001 From: balzack Date: Wed, 5 Feb 2025 22:16:24 -0800 Subject: [PATCH] render video call screen --- app/client/mobile/src/call/Call.styled.ts | 31 ++++++- app/client/mobile/src/call/Call.tsx | 80 +++++++++++++------ app/client/mobile/src/call/useCall.hook.ts | 9 ++- .../src/context/useDisplayContext.hook.ts | 4 +- app/client/mobile/src/ring/Ring.styled.ts | 1 - 5 files changed, 96 insertions(+), 29 deletions(-) diff --git a/app/client/mobile/src/call/Call.styled.ts b/app/client/mobile/src/call/Call.styled.ts index 6f8970cd..51def1a5 100644 --- a/app/client/mobile/src/call/Call.styled.ts +++ b/app/client/mobile/src/call/Call.styled.ts @@ -38,5 +38,34 @@ export const styles = StyleSheet.create({ right: '10%', width: '20%', height: '20%', - } + }, + titleView: { + position: 'absolute', + top: 0, + width: '100%', + height: '100%', + display: 'flex', + flexDirection: 'column', + alignItems: 'center', + paddingTop: 92, + }, + titleName: { + fontSize: 24, + paddingBottom: 32, + }, + titleImage: { + width: '80%', + height: 'auto', + aspectRatio: 1, + borderRadius: 8, + }, + duration: { + paddingTop: 16, + fontSize: 20, + }, + logoView: { + height: '100%', + width: 'auto', + aspectRatio: 1, + }, }); diff --git a/app/client/mobile/src/call/Call.tsx b/app/client/mobile/src/call/Call.tsx index b2916743..2eb2e897 100644 --- a/app/client/mobile/src/call/Call.tsx +++ b/app/client/mobile/src/call/Call.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react'; -import { View } from 'react-native'; +import { useWindowDimensions, Dimensions, Image, View } from 'react-native'; import { useCall } from './useCall.hook'; import { styles } from './Call.styled' import { Card as Contact } from '../card/Card'; @@ -17,6 +17,7 @@ export function Call() { const [accepting, setAccepting] = useState(null as null|string); const [ignoring, setIgnoring] = useState(null as null|string); const [declining, setDeclining] = useState(null as null|string); + const {height, width} = useWindowDimensions(); const toggleAudio = async () => { if (!applyingAudio) { @@ -76,36 +77,65 @@ export function Call() { }, }; + const showName = (state.height - (8 * state.width / 10)) > 256; + return ( - + { state.calling && ( + - { state.remoteVideo && ( - - )} + { !state.remoteVideo && !state.localVideo && showName && ( + + { state.calling.name && ( + { state.calling.name } + )} + { !state.calling.name && ( + { `${state.calling.handle}/${state.calling.node}` } + )} + + { `${Math.floor(state.duration/60)}:${(state.duration % 60).toString().padStart(2, '0')}` } + + )} - { state.localVideo && ( - - )} + { !state.remoteVideo && !state.localVideo && !showName && ( + + )} - - actions.setFullscreen(false)} /> - - - + { state.remoteVideo && ( + + )} + + { state.localVideo && ( + + )} + + + actions.setFullscreen(false)} /> + + + + - + )} ); diff --git a/app/client/mobile/src/call/useCall.hook.ts b/app/client/mobile/src/call/useCall.hook.ts index 8da7cb62..dd9a6be6 100644 --- a/app/client/mobile/src/call/useCall.hook.ts +++ b/app/client/mobile/src/call/useCall.hook.ts @@ -11,7 +11,7 @@ export function useCall() { const offset = useRef(false); const [state, setState] = useState({ - strings: display.state.strings, + strings: display.state.strings, calls: [] as { callId: string, card: Card }[], calling: null as null | Card, localStream: null as null|MediaStream, @@ -23,6 +23,8 @@ export function useCall() { connected: false, duration: 0, failed: false, + width: 0, + height: 0, }) // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -30,6 +32,11 @@ export function useCall() { setState((s) => ({ ...s, ...value })) } + useEffect(() => { + const { width, height, strings } = display.state; + updateState({ width, height, strings }); + }, [display.state]); + useEffect(() => { const interval = setInterval(() => { if (offset.current) { diff --git a/app/client/mobile/src/context/useDisplayContext.hook.ts b/app/client/mobile/src/context/useDisplayContext.hook.ts index 3637793d..f83cd526 100644 --- a/app/client/mobile/src/context/useDisplayContext.hook.ts +++ b/app/client/mobile/src/context/useDisplayContext.hook.ts @@ -7,6 +7,8 @@ export function useDisplayContext() { const [state, setState] = useState({ strings: getLanguageStrings(), layout: null, + width: 0, + height: 0, }); const SMALL_LARGE = 650; @@ -17,7 +19,7 @@ export function useDisplayContext() { useEffect(() => { const layout = dim.width < SMALL_LARGE ? 'small' : 'large'; - updateState({layout}); + updateState({layout, width: dim.width, height: dim.height}); }, [dim.width]); const actions = {}; diff --git a/app/client/mobile/src/ring/Ring.styled.ts b/app/client/mobile/src/ring/Ring.styled.ts index 5637b5c4..7e22337e 100644 --- a/app/client/mobile/src/ring/Ring.styled.ts +++ b/app/client/mobile/src/ring/Ring.styled.ts @@ -21,7 +21,6 @@ export const styles = StyleSheet.create({ width: '100%', height: '100%', borderRadius: 16, - overflow: 'hidden', paddingLeft: 16, paddingRight: 8, },