feat(calling/nui): Timer for calls

This commit is contained in:
Christopher committed 2021-02-01 19:44:00 +01:00
1 parent 3063da94b2
commit dd008775f9
3 files changed
+56 -5

No files matched your search

+3 -3
View File
@@ -86,9 +86,9 @@ if (process.env.NODE_ENV === 'development') {
method: 'setCaller',
data: {
accepted: false,
transmitter: false,
caller: 'Chip',
target: 'Christian',
isTransmitter: false,
transmitter: 'Chip',
receiver: 'Taso',
phone_number: '860-4504',
},
},
+4 -2
View File
@@ -9,6 +9,7 @@ import CallEndIcon from '@material-ui/icons/CallEnd';
import useStyles from './modal.styles';
import { useModal } from '../hooks/useModal';
import Nui from '../../os/nui-events/utils/Nui';
import CallTimer from './CallTimer';
export const CallModal = () => {
const { call } = useCall();
@@ -20,7 +21,6 @@ export const CallModal = () => {
Nui.send('phone:acceptCall', {
transmitterNumber: call.transmitter,
});
console.log("NOW BEING TRANSMITTER", call.transmitter)
};
const handleRejectCall = () => {
@@ -41,7 +41,9 @@ export const CallModal = () => {
return (
<AppWrapper>
<AppContent>
<h1 style={{ textAlign: 'center' }}>{call.receiver}</h1>
<CallTimer isAccepted={call.accepted}/>
<div className={classes.actions}>
<Fab
onClick={handleEndCall}
@@ -60,7 +62,7 @@ export const CallModal = () => {
<AppWrapper>
<AppContent>
<h1 style={{ textAlign: 'center' }}>{call.transmitter}</h1>
<CallTimer isAccepted={call.accepted}/>
<div className={classes.actions}>
{!call.accepted ? (
<>
+49
View File
@@ -0,0 +1,49 @@
import React, { useState, useCallback, useEffect } from 'react'
function CallTimer({ isAccepted }) {
const [time, setTime] = useState({ ms: 0, s: 0, m: 0, h: 0 })
useEffect(() => {
let timer = null
if (isAccepted) {
run()
timer = setInterval(run, 10)
}
return () => clearInterval(timer)
}, []);
let updatedMs = time.ms, updatedS = time.s, updatedM = time.m, updatedH = time.h;
const run = () => {
if (updatedM === 60) {
updatedH++;
updatedM = 0;
}
if (updatedS === 60) {
updatedM++;
updatedS = 0;
}
if (updatedMs === 100) {
updatedS++;
updatedMs = 0
}
updatedMs++;
return setTime({ ms: updatedMs, s: updatedS, m: updatedM, h: updatedH })
}
if (!isAccepted) return null;
return (
<div style={{
textAlign: 'center',
marginTop: '2em',
fontSize: 30
}}>
<span>{(time.h >= 10) ? time.h : '0'+time.h}</span>&nbsp;:&nbsp;
<span>{(time.m >= 10) ? time.m : '0'+time.m}</span>&nbsp;:&nbsp;
<span>{(time.s >= 10) ? time.s : '0'+time.s}</span>&nbsp;
</div>
)
}
export default CallTimer