mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
feat(calling/nui): Timer for calls
This commit is contained in:
1 parent
3063da94b2
commit
dd008775f9
3 files changed
+56
-5
No files matched your search
+3
-3
@@ -86,9 +86,9 @@ if (process.env.NODE_ENV === 'development') {
|
|||||||
method: 'setCaller',
|
method: 'setCaller',
|
||||||
data: {
|
data: {
|
||||||
accepted: false,
|
accepted: false,
|
||||||
transmitter: false,
|
isTransmitter: false,
|
||||||
caller: 'Chip',
|
transmitter: 'Chip',
|
||||||
target: 'Christian',
|
receiver: 'Taso',
|
||||||
phone_number: '860-4504',
|
phone_number: '860-4504',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import CallEndIcon from '@material-ui/icons/CallEnd';
|
|||||||
import useStyles from './modal.styles';
|
import useStyles from './modal.styles';
|
||||||
import { useModal } from '../hooks/useModal';
|
import { useModal } from '../hooks/useModal';
|
||||||
import Nui from '../../os/nui-events/utils/Nui';
|
import Nui from '../../os/nui-events/utils/Nui';
|
||||||
|
import CallTimer from './CallTimer';
|
||||||
|
|
||||||
export const CallModal = () => {
|
export const CallModal = () => {
|
||||||
const { call } = useCall();
|
const { call } = useCall();
|
||||||
@@ -20,7 +21,6 @@ export const CallModal = () => {
|
|||||||
Nui.send('phone:acceptCall', {
|
Nui.send('phone:acceptCall', {
|
||||||
transmitterNumber: call.transmitter,
|
transmitterNumber: call.transmitter,
|
||||||
});
|
});
|
||||||
console.log("NOW BEING TRANSMITTER", call.transmitter)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRejectCall = () => {
|
const handleRejectCall = () => {
|
||||||
@@ -41,7 +41,9 @@ export const CallModal = () => {
|
|||||||
return (
|
return (
|
||||||
<AppWrapper>
|
<AppWrapper>
|
||||||
<AppContent>
|
<AppContent>
|
||||||
|
|
||||||
<h1 style={{ textAlign: 'center' }}>{call.receiver}</h1>
|
<h1 style={{ textAlign: 'center' }}>{call.receiver}</h1>
|
||||||
|
<CallTimer isAccepted={call.accepted}/>
|
||||||
<div className={classes.actions}>
|
<div className={classes.actions}>
|
||||||
<Fab
|
<Fab
|
||||||
onClick={handleEndCall}
|
onClick={handleEndCall}
|
||||||
@@ -60,7 +62,7 @@ export const CallModal = () => {
|
|||||||
<AppWrapper>
|
<AppWrapper>
|
||||||
<AppContent>
|
<AppContent>
|
||||||
<h1 style={{ textAlign: 'center' }}>{call.transmitter}</h1>
|
<h1 style={{ textAlign: 'center' }}>{call.transmitter}</h1>
|
||||||
|
<CallTimer isAccepted={call.accepted}/>
|
||||||
<div className={classes.actions}>
|
<div className={classes.actions}>
|
||||||
{!call.accepted ? (
|
{!call.accepted ? (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -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> :
|
||||||
|
<span>{(time.m >= 10) ? time.m : '0'+time.m}</span> :
|
||||||
|
<span>{(time.s >= 10) ? time.s : '0'+time.s}</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CallTimer
|
||||||
Reference in new issue
Block a user