From fc0ba2a187da92cc49bd372b4f4824b64d9ffce9 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Thu, 6 Feb 2025 11:04:09 -0800 Subject: [PATCH] cleanup on calling --- app/client/mobile/src/call/Call.tsx | 2 +- .../mobile/src/calling/Calling.styled.ts | 128 --------- app/client/mobile/src/calling/Calling.tsx | 262 ------------------ .../mobile/src/calling/useCalling.hook.ts | 37 --- app/client/mobile/src/session/Session.tsx | 10 +- 5 files changed, 6 insertions(+), 433 deletions(-) delete mode 100644 app/client/mobile/src/calling/Calling.styled.ts delete mode 100644 app/client/mobile/src/calling/Calling.tsx delete mode 100644 app/client/mobile/src/calling/useCalling.hook.ts diff --git a/app/client/mobile/src/call/Call.tsx b/app/client/mobile/src/call/Call.tsx index 2eb2e897..e1a94793 100644 --- a/app/client/mobile/src/call/Call.tsx +++ b/app/client/mobile/src/call/Call.tsx @@ -129,7 +129,7 @@ export function Call() { )} - actions.setFullscreen(false)} /> + actions.setFullscreen(false)} /> diff --git a/app/client/mobile/src/calling/Calling.styled.ts b/app/client/mobile/src/calling/Calling.styled.ts deleted file mode 100644 index a71c4853..00000000 --- a/app/client/mobile/src/calling/Calling.styled.ts +++ /dev/null @@ -1,128 +0,0 @@ -import {StyleSheet} from 'react-native'; -import { Colors } from '../constants/Colors'; - -export const styles = StyleSheet.create({ - blur: { - position: 'absolute', - top: 0, - left: 0, - width: '100%', - height: '100%', - }, - active: { - display: 'flex', - width: '100%', - height: '100%', - position: 'absolute', - alignItems: 'center', - justifyContent: 'center', - }, - inactive: { - display: 'none', - width: '100%', - height: '100%', - position: 'absolute', - alignItems: 'center', - justifyContent: 'center', - }, - base: { - width: '100%', - height: '100%', - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - }, - container: { - width: '100%', - height: '100%', - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - }, - calls: { - borderRadius: 8, - overflow: 'hidden', - }, - call: { - width: '100%', - height: '100%', - display: 'flex', - }, - image: { - width: '100%', - height: '100%', - borderRadius: 8, - }, - canvas: { - position: 'absolute', - top: 0, - left: 0, - width: '100%', - height: '100%', - }, - frame: { - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - borderRadius: 8, - overflow: 'hidden', - padding: 2, - position: 'absolute', - }, - closeIcon: { - borderRadius: 8, - }, - circleIcon: { - }, - flipIcon: { - transform: [{ rotate: '135deg' }], - }, - name: { - fontSize: 28, - paddingLeft: 16, - paddingRight: 16, - width: '100%', - textAlign: 'center', - }, - connecting: { - fontSize: 12, - paddingLeft: 16, - paddingRight: 16, - paddingTop: 4, - paddingBottom: 4, - }, - overlap: { - display: 'flex', - flexDirection: 'row', - position: 'absolute', - alignItems: 'center', - justifyContent: 'center', - paddingBottom: 8, - paddingTop: 8, - gap: 32, - }, - box: { - position: 'absolute', - top: 0, - right: 16, - width: '20%', - height: '20%', - }, - full: { - width: '100%', - height: '100%', - }, - card: { - width: '100%', - height: 64, - paddingTop: 16, - paddingBottom: 16, - paddingLeft: 32, - paddingRight: 32, - borderBottomWidth: 1, - } - full: { - width: '100%', - height: '100%', - } -}); diff --git a/app/client/mobile/src/calling/Calling.tsx b/app/client/mobile/src/calling/Calling.tsx deleted file mode 100644 index f6e99530..00000000 --- a/app/client/mobile/src/calling/Calling.tsx +++ /dev/null @@ -1,262 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import { useWindowDimensions, Image, SafeAreaView, Modal, ScrollView, View } from 'react-native'; -import { Surface, Icon, Divider, Button, IconButton, Text, TextInput, useTheme} from 'react-native-paper'; -import {styles} from './Calling.styled'; -import {useCalling} from './useCalling.hook'; -import {BlurView} from '@react-native-community/blur'; -import { Confirm } from '../confirm/Confirm'; -import { ActivityIndicator } from 'react-native-paper'; -import FastImage from 'react-native-fast-image' -import { Colors } from '../constants/Colors'; -import { type Card } from 'databag-client-sdk'; -import { RTCView } from 'react-native-webrtc'; -import { Card as Contact } from '../card/Card'; -import { activateKeepAwake, deactivateKeepAwake} from "@sayem314/react-native-keep-awake"; - -export function Calling({ callCard }: { callCard: null|Card }) { - const { state, actions } = useCalling(); - const [alert, setAlert] = useState(false); - const [connecting, setConnecting] = useState(false); - const [ending, setEnding] = useState(false); - const {height, width} = useWindowDimensions(); - const [applyingVideo, setApplyingVideo] = useState(false); - const [applyingAudio, setApplyingAudio] = useState(false); - 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 theme = useTheme(); - - const surface = theme.dark ? { - base: 'rgba(16,16,16,1)', - blend: 'rgba(16,16,16,0)', - control: 'rgba(64,64,64,0.6)', - title: 'rgba(32,32,32,0.8)', - } : { - base: 'rgba(212,212,212,1)', - blend: 'rgba(212,212,212,0)', - control: 'rgba(128,128,128,0.6)', - title: 'rgba(192,192,192,0.8)', - }; - - const toggleVideo = async () => { - if (!applyingVideo) { - setApplyingVideo(true); - try { - if (state.videoEnabled) { - await actions.disableVideo(); - } else if (!state.videoEnabled) { - await actions.enableVideo(); - } - } catch (err) { - console.log(err); - setAlert(true); - } - setApplyingVideo(false); - } - } - - const toggleAudio = async () => { - if (!applyingAudio) { - setApplyingAudio(true); - try { - if (state.audioEnabled) { - await actions.disableAudio(); - } else if (!state.audioEnabled) { - await actions.enableAudio(); - } - } catch (err) { - console.log(err); - setAlert(true); - } - setApplyingAudio(false); - } - } - - const end = async () => { - if (!ending) { - setEnding(true); - try { - await actions.end(); - } catch (err) { - console.log(err); - setAlert(true); - } - setEnding(false); - } - } - - const call = async (card) => { - if (!connecting) { - setConnecting(true); - try { - await actions.call(card); - } catch (err) { - console.log(err); - setAlert(true); - } - setConnecting(false); - } - } - - const accept = async (callId, card) => { - if (!accepting) { - setAccepting(callId); - try { - await actions.accept(callId, card); - } catch (err) { - console.log(err); - setAlert(true); - } - setAccepting(null); - } - } - - const ignore = async (callId, card) => { - if (!ignoring) { - setIgnoring(callId); - try { - await actions.ignore(callId, card); - } catch (err) { - console.log(err); - setAlert(true); - } - setIgnoring(null); - } - } - - const decline = async (callId, card) => { - if (!declining) { - setDeclining(callId); - try { - await actions.decline(callId, card); - } catch (err) { - console.log(err); - setAlert(true); - } - setDeclining(null); - } - } - - const alertParams = { - title: state.strings.operationFailed, - prompt: state.strings.tryAgain, - cancel: { - label: state.strings.close, - action: () => { - setAlert(false); - }, - }, - }; - - useEffect(() => { - const { card } = callCard; - if (card) { - call(card); - } - }, [callCard]); - - useEffect(() => { - if (state.calling) { - activateKeepAwake(); - } else { - deactivateKeepAwake(); - } - }, [state.calling]); - - const calls = state.calls.map((contact, index) => { - const { callId, card } = contact; - const { name, handle, node, imageUrl } = card; - const ignoreButton = ignore(callId, card)} /> - const declineButton = decline(callId, card)} /> - const acceptButton = accept(callId, card)} /> - return ( - - - - ) - }); - - const overlap = (width + 128) > height; - const frameWidth = width > height ? height : width - 16; - const frameHeight = frameWidth; - const frameOffset = (height - frameHeight) / 3; - return ( - 0 || alert) ? styles.active : styles.inactive}> - { state.calls.length > 0 && !connecting && !state.calling && ( - - - - { calls } - - - )} - { connecting && !state.calling && ( - - - - )} - { state.calling && ( - - 400 ? 400 : frameWidth, height: frameHeight > 400 ? 400 : frameHeight }}> - - - - )} - { state.calling && ( - - - { state.calling.name && ( - { state.calling.name } - )} - { !state.calling.name && ( - { `${state.calling.handle}/${state.calling.node}` } - )} - - - )} - { state.calling && state.remoteStream && state.remoteVideo && ( - - - - )} - { state.calling && state.localStream && state.localVideo && ( - - - - )} - { state.calling && ( - - - - - - - - )} - { state.calling && !state.connected && ( - - - { state.strings.connecting } - - - )} - - - ); -} - diff --git a/app/client/mobile/src/calling/useCalling.hook.ts b/app/client/mobile/src/calling/useCalling.hook.ts deleted file mode 100644 index dcca9085..00000000 --- a/app/client/mobile/src/calling/useCalling.hook.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { useState, useContext, useEffect, useRef } from 'react' -import { RingContext } from '../context/RingContext' -import { DisplayContext } from '../context/DisplayContext' -import { ContextType } from '../context/ContextType' -import { Card } from 'databag-client-sdk'; - -export function useCalling() { - const ring = useContext(RingContext) as ContextType; - const display = useContext(DisplayContext) as ContextType; - - const [state, setState] = useState({ - strings: display.state.strings, - calls: [] as { callId: string, card: Card }[], - calling: null as null | Card, - localStream: null as null|MediaStream, - remoteStream: null as null|MediaStream, - localVideo: false, - remoteVideo: false, - audioEnabled: false, - videoEnabled: false, - connected: false, - failed: false, - }) - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const updateState = (value: any) => { - setState((s) => ({ ...s, ...value })) - } - - useEffect(() => { - const { calls, calling, localStream, remoteStream, localVideo, remoteVideo, audioEnabled, videoEnabled, connected, failed } = ring.state; - updateState({ calls, calling, localStream, remoteStream, localVideo, remoteVideo, audioEnabled, videoEnabled, connected, failed }); - }, [ring.state]); - - const actions = ring.actions; - return { state, actions }; -} diff --git a/app/client/mobile/src/session/Session.tsx b/app/client/mobile/src/session/Session.tsx index eb061342..caf6522a 100644 --- a/app/client/mobile/src/session/Session.tsx +++ b/app/client/mobile/src/session/Session.tsx @@ -288,7 +288,7 @@ function DetailsScreen({nav}) { const DetailsComponent = useCallback( (props) => ( - +
closeAll(props)} /> @@ -322,7 +322,7 @@ function ProfileScreen({nav}) { }; const ProfileComponent = useCallback(() => ( - + ), [contactParams]); @@ -346,7 +346,7 @@ function ProfileScreen({nav}) { function RegistryScreen({nav}) { const RegistryComponent = useCallback( () => ( - + { nav.openContact(params, nav.profile.openDrawer); @@ -376,7 +376,7 @@ function RegistryScreen({nav}) { function ContactsScreen({nav}) { const ContactsComponent = useCallback( () => ( - + { @@ -411,7 +411,7 @@ function ContactsScreen({nav}) { function SettingsScreen({nav}) { const SettingsComponent = useCallback( () => ( - +