diff --git a/phone/package.json b/phone/package.json
index 4021745..1e7ba82 100644
--- a/phone/package.json
+++ b/phone/package.json
@@ -20,6 +20,7 @@
"@testing-library/user-event": "^7.2.1",
"@types/jest": "^26.0.14",
"core-js": "^3.6.5",
+ "dayjs": "^1.10.4",
"emoji-mart": "^3.0.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5",
diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx
index 8b9d195..b507192 100644
--- a/phone/src/Phone.tsx
+++ b/phone/src/Phone.tsx
@@ -28,6 +28,9 @@ import { settingsState } from './apps/settings/hooks/useSettings';
import config from './config/default.json';
import { useRecoilState } from 'recoil';
+import { useCallService } from './modal/hooks/useCallService';
+import { useModal } from './modal/hooks/useModal';
+import { useDialService } from './apps/dialer/hooks/useDialService';
// Inject mock data when in development env.
if (process.env.NODE_ENV === 'development') {
@@ -52,6 +55,47 @@ if (process.env.NODE_ENV === 'development') {
);
}, 1000);
+ setTimeout(() => {
+ window.dispatchEvent(
+ new MessageEvent('message', {
+ data: {
+ app: 'DAILER',
+ method: 'setHistory',
+ data: [
+ {
+ id: 1,
+ transmitter: '636-6496',
+ start: 1612301545782,
+ },
+ {
+ id: 2,
+ transmitter: '777-7777',
+ start: 1612301545782,
+ },
+ ],
+ },
+ })
+ );
+ }, 1000);
+
+ setTimeout(() => {
+ window.dispatchEvent(
+ new MessageEvent('message', {
+ data: {
+ app: 'CALL',
+ method: 'setCaller',
+ data: {
+ accepted: true,
+ isTransmitter: true,
+ transmitter: 'Chip',
+ receiver: 'Taso',
+ phone_number: '860-4504',
+ },
+ },
+ })
+ );
+ }, 1000);
+
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
@@ -82,7 +126,7 @@ if (process.env.NODE_ENV === 'development') {
{
id: 1,
display: 'Taso',
- number: '43534444',
+ number: '456466',
},
],
},
@@ -258,6 +302,10 @@ function Phone() {
useMessagesService();
useNotesService();
usePhotoService();
+ useCallService();
+ useDialService();
+
+ const { modal } = useModal(); // the calling modal
const [settings] = useRecoilState(settingsState);
@@ -267,8 +315,6 @@ function Phone() {
const currentTheme = () => createMuiTheme(config.themes[settings.theme]);
- const calling = false;
-
document.onkeyup = function (data) {
if (data.which === 27) {
Nui.send('phone:close');
@@ -303,7 +349,7 @@ function Phone() {
]}
/>
- {calling ? (
+ {modal ? (
) : (
<>
diff --git a/phone/src/apps/contacts/components/ContactModal.tsx b/phone/src/apps/contacts/components/ContactModal.tsx
index 4b26d0a..ce8b8f3 100644
--- a/phone/src/apps/contacts/components/ContactModal.tsx
+++ b/phone/src/apps/contacts/components/ContactModal.tsx
@@ -31,7 +31,7 @@ export const AddContactModal = () => {
number,
avatar,
});
- console.log(name, number, avatar);
+ setShowModal(false)
}
};
diff --git a/phone/src/apps/contacts/components/List/ContactList.tsx b/phone/src/apps/contacts/components/List/ContactList.tsx
index 2b471a2..9c0553e 100644
--- a/phone/src/apps/contacts/components/List/ContactList.tsx
+++ b/phone/src/apps/contacts/components/List/ContactList.tsx
@@ -35,18 +35,19 @@ export const ContactList = () => {
};
const startCall = (number) => {
console.log(number);
- Nui.send('phone:startCall', {
+ Nui.send('phone:beginCall', {
number,
});
};
+ const filteredRegEx = new RegExp(filteredContacts, "gi")
+
return (
{contacts.contacts
.filter(
(contact) =>
- contact.display.includes(filteredContacts.toLowerCase()) ||
- contact.number.includes(filteredContacts.toLowerCase())
+ contact.display.match(filteredRegEx) || contact.number.match(filteredRegEx)
)
.map((contact) => (
<>
diff --git a/phone/src/apps/contacts/components/List/SearchContacts.tsx b/phone/src/apps/contacts/components/List/SearchContacts.tsx
index 49ffe3a..2fad490 100644
--- a/phone/src/apps/contacts/components/List/SearchContacts.tsx
+++ b/phone/src/apps/contacts/components/List/SearchContacts.tsx
@@ -68,15 +68,9 @@ const useStyles = makeStyles((theme: Theme) =>
export const SearchContacts = () => {
const { setFilteredContacts } = useFilteredContacts();
-
const classes = useStyles();
-
const { t } = useTranslation();
- const handleChange = (e) => {
- setFilteredContacts(e.target.value);
- };
-
return (
@@ -84,13 +78,13 @@ export const SearchContacts = () => {
setFilteredContacts(e.target.value)}
placeholder={t('APPS_CONTACT_PLACEHOLDER_SEARCH_CONTACTS')}
classes={{
root: classes.inputRoot,
input: classes.inputInput,
}}
- inputProps={{ 'aria-label': 'search' }}
+ inputProps={{ 'aria-label': 'search', 'autoFocus': true }}
/>
diff --git a/phone/src/apps/contacts/components/alert/ContactAlert.tsx b/phone/src/apps/contacts/components/alert/ContactAlert.tsx
index 8e50533..a0b467c 100644
--- a/phone/src/apps/contacts/components/alert/ContactAlert.tsx
+++ b/phone/src/apps/contacts/components/alert/ContactAlert.tsx
@@ -46,6 +46,7 @@ export const ContactAlert = () => {
break;
case 'CONTACT_UPDATE_SUCCESS':
setMessageAlert(alert, 'success');
+ break;
}
}, [alert, setMessageAlert]);
diff --git a/phone/src/apps/contacts/hooks/useContacts.ts b/phone/src/apps/contacts/hooks/useContacts.ts
index 471a3c5..15df383 100644
--- a/phone/src/apps/contacts/hooks/useContacts.ts
+++ b/phone/src/apps/contacts/hooks/useContacts.ts
@@ -2,13 +2,19 @@ import { useRecoilValue } from 'recoil';
import { contactsState } from './state';
import { ContactProps } from '../../../common/typings/contact';
+import { useCall } from '../../../modal/hooks/useCall';
+import { useCallback } from 'react';
interface IUseContacts {
contacts: ContactProps[]
-
+ getDisplayByNumber: (number: string) => string;
}
export const useContacts = (): IUseContacts => {
const contacts = useRecoilValue(contactsState.contacts);
- return { contacts };
+ const getDisplayByNumber = useCallback((number: string) => {
+ const found = contacts.find((contact) => contact.number === number)
+ return found ? found.display : number
+ }, [contacts])
+ return { contacts, getDisplayByNumber };
};
diff --git a/phone/src/apps/contacts/hooks/useFilteredContacts.ts b/phone/src/apps/contacts/hooks/useFilteredContacts.ts
index 97bb25e..b29b470 100644
--- a/phone/src/apps/contacts/hooks/useFilteredContacts.ts
+++ b/phone/src/apps/contacts/hooks/useFilteredContacts.ts
@@ -3,7 +3,7 @@ import { contactsState } from './state';
interface FilterdContactsProps {
filteredContacts: string;
- setFilteredContacts: (contact: string) => void;
+ setFilteredContacts: (contact: any) => void;
}
export const useFilteredContacts = (): FilterdContactsProps => {
diff --git a/phone/src/apps/dialer/components/ContactSearch.tsx b/phone/src/apps/dialer/components/ContactSearch.tsx
new file mode 100644
index 0000000..f5e1f02
--- /dev/null
+++ b/phone/src/apps/dialer/components/ContactSearch.tsx
@@ -0,0 +1,17 @@
+import React from 'react';
+import { Box } from '@material-ui/core';
+import { makeStyles, Theme } from '@material-ui/core/styles';
+
+const useStyles = makeStyles((theme: Theme) => ({
+ root: {
+ backgroundColor: '#e9e9e9',
+ },
+}));
+
+const ContactsSearch = () => {
+ const classes = useStyles();
+
+ return ;
+};
+
+export default ContactsSearch;
diff --git a/phone/src/apps/dialer/components/DialPadGrid.tsx b/phone/src/apps/dialer/components/DialPadGrid.tsx
new file mode 100644
index 0000000..daff0e6
--- /dev/null
+++ b/phone/src/apps/dialer/components/DialPadGrid.tsx
@@ -0,0 +1,53 @@
+import React, { useContext } from 'react';
+import { Box, Button, Grid } from '@material-ui/core';
+import { makeStyles, Theme } from '@material-ui/core/styles';
+import { DialInputCtx } from '../context/InputContext';
+
+const useStyles = makeStyles((theme: Theme) => ({
+ gridItem: {
+ fontSize: theme.typography.h5.fontSize,
+ padding: theme.spacing(2),
+ },
+}));
+
+interface IBtnItem {
+ onClick?: (...args: any) => void;
+ label: string | number;
+}
+
+const ButtonItem = ({ label, onClick }: IBtnItem) => {
+ const classes = useStyles();
+ return (
+
+
+
+ );
+};
+
+export const DialGrid = () => {
+ const { add, removeOne, clear} = useContext(DialInputCtx)
+
+ return (
+
+
+ add(1)} />
+ add(2)} />
+ add(3)} />
+ add(4)} />
+ add(5)} />
+ add(6)} />
+ add(7)} />
+ add(8)} />
+ add(9)} />
+
+ add(0)} />
+
+ add('-')} />
+
+
+ );
+};
+
+export default DialGrid;
diff --git a/phone/src/apps/dialer/components/DialerApp.tsx b/phone/src/apps/dialer/components/DialerApp.tsx
index 4aacf55..e45c72e 100644
--- a/phone/src/apps/dialer/components/DialerApp.tsx
+++ b/phone/src/apps/dialer/components/DialerApp.tsx
@@ -2,19 +2,32 @@ import React from 'react';
import { AppWrapper } from '../../../ui/components';
import { AppTitle } from '../../../ui/components/AppTitle';
import { AppContent } from '../../../ui/components/AppContent';
-import { DialerHistory } from './DialerHistory';
-import { useDialerHistory } from '../hooks/useDialerHistory';
+import { DialerHistory } from './views/DialerHistory';
import { useApp } from '../../../os/apps/hooks/useApps';
+import { Switch, Route } from 'react-router-dom';
+import DialPage from './views/DialPage';
+import DialerNavBar from './DialerNavBar';
+import { useDialHistory } from '../hooks/useDialHistory';
export const DialerApp = () => {
- const { history } = useDialerHistory();
+ const history = useDialHistory();
+
const dialer = useApp('DIALER');
return (
-
+
+
+
+
+
+
+
+ {/**/}
+
+
);
};
diff --git a/phone/src/apps/dialer/components/DialerHistory.tsx b/phone/src/apps/dialer/components/DialerHistory.tsx
deleted file mode 100644
index 4c73ab7..0000000
--- a/phone/src/apps/dialer/components/DialerHistory.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import React from 'react';
-import ListItemText from '@material-ui/core/ListItemText';
-import PhoneCallbackIcon from '@material-ui/icons/PhoneCallback';
-import PhoneForwardedIcon from '@material-ui/icons/PhoneForwarded';
-import { List } from '../../../ui/components/List';
-import { ListItem } from '../../../ui/components/ListItem';
-
-const CallTypeIcon = {
- incoming: ,
- outgoing: ,
-};
-
-export const DialerHistory = ({ calls }) => {
- return (
-
- {calls.map((call) => (
-
-
- {CallTypeIcon[call.type]}
-
- ))}
-
- );
-};
diff --git a/phone/src/apps/dialer/components/DialerInput.tsx b/phone/src/apps/dialer/components/DialerInput.tsx
new file mode 100644
index 0000000..4fe1822
--- /dev/null
+++ b/phone/src/apps/dialer/components/DialerInput.tsx
@@ -0,0 +1,50 @@
+import React, { useContext } from 'react';
+import { Box, IconButton, InputBase, Paper } from '@material-ui/core';
+import { makeStyles, Theme } from '@material-ui/core/styles';
+import PhoneIcon from '@material-ui/icons/Phone';
+import { DialInputCtx } from '../context/InputContext';
+import Nui from '../../../os/nui-events/utils/Nui';
+
+const useStyles = makeStyles((theme: Theme) => ({
+ root: {
+ textAlign: 'right',
+ paddingTop: theme.spacing(3),
+ paddingBottom: theme.spacing(3),
+ paddingLeft: theme.spacing(5),
+ paddingRight: theme.spacing(5),
+ display: 'flex',
+ height: 100,
+ },
+ input: {
+ flex: 1,
+ fontSize: theme.typography.h6.fontSize,
+ },
+ iconBtn: {
+ padding: 10,
+ },
+}));
+
+export const DialerInput = () => {
+ const classes = useStyles();
+
+ const { inputVal } = useContext(DialInputCtx)
+
+ const handleCall = (number: string) => {
+ Nui.send('phone:beginCall', {
+ number,
+ });
+ };
+
+ return (
+
+
+
+ handleCall(inputVal)} />
+
+
+ );
+};
diff --git a/phone/src/apps/dialer/components/DialerNavBar.tsx b/phone/src/apps/dialer/components/DialerNavBar.tsx
new file mode 100644
index 0000000..3da86d9
--- /dev/null
+++ b/phone/src/apps/dialer/components/DialerNavBar.tsx
@@ -0,0 +1,54 @@
+import React, { ChangeEvent, useState } from 'react';
+import { BottomNavigation, BottomNavigationAction } from '@material-ui/core';
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { faHome } from '@fortawesome/free-solid-svg-icons';
+import AddCircleIcon from '@material-ui/icons/AddCircle';
+import { Link } from 'react-router-dom';
+import { makeStyles, Theme } from '@material-ui/core/styles';
+import PhoneCallbackIcon from '@material-ui/icons/PhoneCallback';
+import PhoneIcon from '@material-ui/icons/Phone';
+import { History } from '@material-ui/icons';
+
+const useStyles = makeStyles((theme: Theme) => ({
+ root: {
+ width: '100%',
+ backgroundColor: theme.palette.background.default,
+ },
+ icon: {
+ color: '#43a047',
+ },
+}));
+
+const DialerNavBar = () => {
+ const classes = useStyles();
+
+ const [page, setPage] = useState(0);
+
+ const handleChange = (event: ChangeEvent<{}>, newPage) => {
+ setPage(newPage);
+ };
+
+ return (
+
+ }
+ to='/phone'
+ />
+ }
+ to='/phone/dial'
+ label='Call'
+ />
+
+ );
+};
+
+export default DialerNavBar;
diff --git a/phone/src/apps/dialer/components/views/DialPage.tsx b/phone/src/apps/dialer/components/views/DialPage.tsx
new file mode 100644
index 0000000..619a79c
--- /dev/null
+++ b/phone/src/apps/dialer/components/views/DialPage.tsx
@@ -0,0 +1,39 @@
+import React, { useState } from 'react';
+import { makeStyles, Theme } from '@material-ui/core/styles';
+import DialGrid from '../DialPadGrid';
+import { DialerInput } from '../DialerInput';
+import ContactSearch from '../ContactSearch';
+import { DialInputCtx } from '../../context/InputContext';
+
+const useStyles = makeStyles((theme: Theme) => ({
+ root: {
+ width: '100%',
+ minHeight: '100%',
+ display: 'flex',
+ flexDirection: 'column',
+ },
+}));
+
+const DialPage = () => {
+ const classes = useStyles();
+
+ const [inputVal, setInputVal] = useState('');
+
+ return (
+
+ setInputVal(inputVal + val),
+ removeOne: () => setInputVal(inputVal.slice(0, -1)),
+ clear: () => setInputVal(''),
+ }}
+ >
+
+
+
+
+
+ );
+};
+export default DialPage;
diff --git a/phone/src/apps/dialer/components/views/DialerHistory.tsx b/phone/src/apps/dialer/components/views/DialerHistory.tsx
new file mode 100644
index 0000000..4269fd8
--- /dev/null
+++ b/phone/src/apps/dialer/components/views/DialerHistory.tsx
@@ -0,0 +1,63 @@
+import React from 'react';
+import ListItemText from '@material-ui/core/ListItemText';
+import PhoneCallbackIcon from '@material-ui/icons/PhoneCallback';
+import PhoneForwardedIcon from '@material-ui/icons/PhoneForwarded';
+import { List } from '../../../../ui/components/List';
+import { ListItem } from '../../../../ui/components/ListItem';
+import Nui from '../../../../os/nui-events/utils/Nui';
+import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
+import { useContacts } from '../../../contacts/hooks/useContacts';
+import { ICall } from '../../../../common/typings/call';
+import dayjs from 'dayjs';
+import { useTranslation } from 'react-i18next';
+
+export const DialerHistory = ({ calls }) => {
+ const { number } = useSimcard();
+ const { getDisplayByNumber } = useContacts();
+
+ const { t } = useTranslation();
+
+ const handleCall = (phoneNumber) => {
+ Nui.send('phone:beginCall', {
+ number: phoneNumber,
+ });
+ };
+
+ if (!calls) {
+ return Things are loading or arent here at all
;
+ }
+
+ return (
+
+ {calls.map((call: ICall) =>
+ call.transmitter === number ? (
+ handleCall(call.receiver)}
+ >
+
+ {}
+
+ ) : (
+ handleCall(call.transmitter)}
+ >
+
+ {}
+
+ )
+ )}
+
+ );
+};
diff --git a/phone/src/apps/dialer/context/InputContext.tsx b/phone/src/apps/dialer/context/InputContext.tsx
new file mode 100644
index 0000000..1f3462c
--- /dev/null
+++ b/phone/src/apps/dialer/context/InputContext.tsx
@@ -0,0 +1,10 @@
+import { createContext } from 'react';
+
+export interface IDialInputCtx {
+ inputVal: string;
+ add: (char: string | number) => void;
+ removeOne: () => void;
+ clear: () => void;
+}
+
+export const DialInputCtx = createContext(null);
diff --git a/phone/src/apps/dialer/hooks/state.ts b/phone/src/apps/dialer/hooks/state.ts
new file mode 100644
index 0000000..e1c5751
--- /dev/null
+++ b/phone/src/apps/dialer/hooks/state.ts
@@ -0,0 +1,8 @@
+import { atom } from 'recoil';
+
+export const dialState = {
+ history: atom({
+ key: 'dialHistory',
+ default: null,
+ }),
+};
diff --git a/phone/src/apps/dialer/hooks/useDialHistory.ts b/phone/src/apps/dialer/hooks/useDialHistory.ts
new file mode 100644
index 0000000..c4503e3
--- /dev/null
+++ b/phone/src/apps/dialer/hooks/useDialHistory.ts
@@ -0,0 +1,11 @@
+import { useRecoilValue } from 'recoil';
+import { ICall } from '../../../common/typings/call';
+import { dialState } from './state';
+interface ICallUI {
+ history: ICall[];
+}
+
+export const useDialHistory = (): ICallUI => {
+ const history = useRecoilValue(dialState.history);
+ return history;
+};
diff --git a/phone/src/apps/dialer/hooks/useDialService.ts b/phone/src/apps/dialer/hooks/useDialService.ts
new file mode 100644
index 0000000..7b82ade
--- /dev/null
+++ b/phone/src/apps/dialer/hooks/useDialService.ts
@@ -0,0 +1,11 @@
+import { useSetRecoilState } from 'recoil';
+import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
+import { dialState } from './state';
+import { useDialHistory } from './useDialHistory';
+
+export const useDialService = () => {
+ const setHistory = useSetRecoilState(dialState.history);
+ useNuiEvent('DAILER', 'setHistory', setHistory);
+
+ return useDialHistory();
+};
diff --git a/phone/src/apps/dialer/hooks/useDialerHistory.ts b/phone/src/apps/dialer/hooks/useDialerHistory.ts
deleted file mode 100644
index 39e35ca..0000000
--- a/phone/src/apps/dialer/hooks/useDialerHistory.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { useRecoilState, atom } from 'recoil';
-
-const dialerHistoryState = atom({
- key: 'dialerHistory',
- default: [
- {
- id: 1,
- caller: 'ROCKY',
- phoneNumber: '000-1112',
- type: 'outgoing',
- },
- ],
-});
-
-export const useDialerHistory = () => {
- const [history, setHistory] = useRecoilState(dialerHistoryState);
- return { history, setHistory };
-};
diff --git a/phone/src/common/typings/call.ts b/phone/src/common/typings/call.ts
new file mode 100644
index 0000000..69ed355
--- /dev/null
+++ b/phone/src/common/typings/call.ts
@@ -0,0 +1,24 @@
+export interface CallProps {
+ accepted: boolean;
+ isTransmitter: boolean;
+ transmitter: string;
+ receiver: string;
+}
+
+export interface ICall {
+ id?: number;
+ identifier: string;
+ transmitter: string;
+ transmitterSource?: number;
+ receiver: string;
+ receiverSource?: number;
+ start: number;
+ end?: number;
+}
+
+export interface ICallDuration {
+ ms: number;
+ s: number;
+ m: number;
+ h: number;
+}
diff --git a/phone/src/config/default.json b/phone/src/config/default.json
index 3444360..e5e73cc 100644
--- a/phone/src/config/default.json
+++ b/phone/src/config/default.json
@@ -2,16 +2,15 @@
"cellProvider": "AT&T",
"language": "en",
"wallpapers": [
- "default.png",
- "dragon.jpg",
- "legacy.jpg",
"minimal.jpg",
"waves.jpg",
"surf.jpg",
- "beach.jpg"
+ "beach.jpg",
+ "weeb.png",
+ "weeb2.gif"
],
"defaultSettings": {
- "wallpaper": "default.png",
+ "wallpaper": "minimal.png",
"frame": "s10.png",
"theme": "taso-dark",
"zoom": "100%",
@@ -22,7 +21,7 @@
"printDebugLogs": true,
"logLevel": 1
},
- "frames": ["default.png", "s10.png", "tw.png", "samsung.png"],
+ "frames": ["s10.png"],
"zoomOptions": ["120%", "100%", "80%", "60%", "40%"],
"ringtones": ["marimba", "pixel"],
"themes": {
diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json
index 3a6b44e..9951d3a 100644
--- a/phone/src/locale/en.json
+++ b/phone/src/locale/en.json
@@ -1,5 +1,8 @@
{
"translation": {
+ "DATE_FORMAT": "MM/DD/YYYY",
+ "DATE_TIME_FORMAT": "MM/DD/YYYY hh:mm A",
+
"COMING_SOON": "Coming soon...",
"APPS_DIALER": "Phone",
"APPS_CONTACTS": "Contacts",
diff --git a/phone/src/modal/components/CallModal.tsx b/phone/src/modal/components/CallModal.tsx
index 7c7fe87..a1af711 100644
--- a/phone/src/modal/components/CallModal.tsx
+++ b/phone/src/modal/components/CallModal.tsx
@@ -1,29 +1,95 @@
-import React from 'react';
-import { green } from '@material-ui/core/colors';
+import React, { useState } from 'react';
+import { Button, Fab } from '@material-ui/core';
import { AppWrapper } from '../../ui/components/AppWrapper';
import { AppTitle } from '../../ui/components/AppTitle';
import { AppContent } from '../../ui/components/AppContent';
+import { useCall } from '../hooks/useCall';
+import CallIcon from '@material-ui/icons/Call';
+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();
+ const { setModal } = useModal();
+
+ const classes = useStyles();
+
+ const handleAcceptCall = () => {
+ Nui.send('phone:acceptCall', {
+ transmitterNumber: call.transmitter,
+ });
+ };
+
+ const handleRejectCall = () => {
+ setModal(false);
+ Nui.send('phone:rejectCall', {
+ phoneNumber: call.transmitter,
+ });
+ };
+
+ const handleEndCall = () => {
+ setModal(false);
+ Nui.send('phone:endCall', {
+ transmitterNumber: call.transmitter,
+ });
+ };
+
+ if (call.isTransmitter) {
+ return (
+
+
+ {call.receiver}
+
+
+
+
+
+
+
+
+ );
+ }
+
return (
-
-
- Call
-
+ {call.transmitter}
+
+
+ {!call.accepted ? (
+ <>
+
+
+
+
+
+
+ >
+ ) : (
+
+
+
+ )}
+
);
diff --git a/phone/src/modal/components/CallTimer.tsx b/phone/src/modal/components/CallTimer.tsx
new file mode 100644
index 0000000..ceea576
--- /dev/null
+++ b/phone/src/modal/components/CallTimer.tsx
@@ -0,0 +1,63 @@
+import React, { useState, useCallback, useEffect } from 'react';
+import { useDuration } from '../hooks/useDuration';
+
+function CallTimer({ isAccepted }) {
+ const { duration, setDuration } = useDuration();
+
+ useEffect(() => {
+ let timer;
+ if (isAccepted) {
+ run();
+ timer = setInterval(run, 10);
+ } else {
+ clearInterval(timer);
+ }
+ }, []);
+
+ let updatedMs = duration.ms,
+ updatedS = duration.s,
+ updatedM = duration.m,
+ updatedH = duration.h;
+
+ if (!duration) return null;
+
+ const run = () => {
+ if (updatedM === 60) {
+ updatedH++;
+ updatedM = 0;
+ }
+ if (updatedS === 60) {
+ updatedM++;
+ updatedS = 0;
+ }
+ if (updatedMs === 100) {
+ updatedS++;
+ updatedMs = 0;
+ }
+ updatedMs++;
+ return setDuration({
+ ms: updatedMs,
+ s: updatedS,
+ m: updatedM,
+ h: updatedH,
+ });
+ };
+
+ return (
+
+ {duration.h >= 10 ? duration.h : '0' + duration.h}
+ :
+ {duration.m >= 10 ? duration.m : '0' + duration.m}
+ :
+ {duration.s >= 10 ? duration.s : '0' + duration.s}
+
+ );
+}
+
+export default CallTimer;
diff --git a/phone/src/modal/components/modal.styles.ts b/phone/src/modal/components/modal.styles.ts
new file mode 100644
index 0000000..a8482dc
--- /dev/null
+++ b/phone/src/modal/components/modal.styles.ts
@@ -0,0 +1,18 @@
+import { makeStyles, Theme } from '@material-ui/core/styles';
+
+const useStyles = makeStyles((theme: Theme) => ({
+ actions: {
+ width: '100%',
+ margin: 'auto',
+ position: 'absolute',
+ display: 'flex',
+ alignContent: 'center',
+ justifyContent: 'center',
+ bottom: '10%',
+ },
+ actionButton: {
+ margin: 20,
+ },
+}));
+
+export default useStyles;
diff --git a/phone/src/modal/hooks/state.ts b/phone/src/modal/hooks/state.ts
index 5205d4a..ea43d96 100644
--- a/phone/src/modal/hooks/state.ts
+++ b/phone/src/modal/hooks/state.ts
@@ -1,8 +1,16 @@
import { atom } from 'recoil';
export const callerState = {
- caller: atom({
- key: 'callerList',
- default: [],
+ currentCall: atom({
+ key: 'currentCall',
+ default: null
}),
+ callModal: atom({
+ key: 'callingModal',
+ default: false
+ }),
+ callDuration: atom({
+ key: 'callDuration',
+ default: {ms: 0, s: 0, m: 0, h: 0}
+ })
};
diff --git a/phone/src/modal/hooks/useCall.ts b/phone/src/modal/hooks/useCall.ts
index ecf52d0..daf4da6 100644
--- a/phone/src/modal/hooks/useCall.ts
+++ b/phone/src/modal/hooks/useCall.ts
@@ -1,7 +1,13 @@
import { useRecoilState } from 'recoil';
+import { CallProps, ICallDuration } from '../../common/typings/call';
import { callerState } from './state';
-export const useCall = () => {
- const caller = useRecoilState(callerState.caller);
- return { caller };
+interface CallHook {
+ call: CallProps;
+ setCall: (details: any) => void;
+}
+
+export const useCall = (): CallHook => {
+ const [call, setCall] = useRecoilState(callerState.currentCall);
+ return { call, setCall };
};
diff --git a/phone/src/modal/hooks/useCallService.ts b/phone/src/modal/hooks/useCallService.ts
index 17fcabc..5345d0f 100644
--- a/phone/src/modal/hooks/useCallService.ts
+++ b/phone/src/modal/hooks/useCallService.ts
@@ -1,10 +1,15 @@
import { useNuiEvent } from '../../os/nui-events/hooks/useNuiEvent';
-import { useSetRecoilState } from 'recoil';
+import { useRecoilState, useSetRecoilState } from 'recoil';
import { callerState } from './state';
import { useCall } from './useCall';
+import { useModal } from './useModal';
export const useCallService = () => {
- const setCaller = useSetRecoilState(callerState.caller);
- useNuiEvent('CALL', 'setCaller', setCaller);
- return useCall();
+ const [caller, setCaller] = useRecoilState(callerState.currentCall);
+ const setModal = useSetRecoilState(callerState.callModal);
+
+ useNuiEvent('CALL', 'setCaller', setCaller, {}, caller);
+ useNuiEvent('CALL', 'callModal', setModal);
+ return { useCall, useModal };
};
+
\ No newline at end of file
diff --git a/phone/src/modal/hooks/useDuration.ts b/phone/src/modal/hooks/useDuration.ts
new file mode 100644
index 0000000..67a143a
--- /dev/null
+++ b/phone/src/modal/hooks/useDuration.ts
@@ -0,0 +1,7 @@
+import { useRecoilState } from 'recoil';
+import { callerState } from './state';
+
+export const useDuration = () => {
+ const [duration, setDuration] = useRecoilState(callerState.callDuration);
+ return { duration, setDuration}
+}
\ No newline at end of file
diff --git a/phone/src/modal/hooks/useModal.ts b/phone/src/modal/hooks/useModal.ts
new file mode 100644
index 0000000..3ac7069
--- /dev/null
+++ b/phone/src/modal/hooks/useModal.ts
@@ -0,0 +1,12 @@
+import { useRecoilState } from 'recoil';
+import { callerState } from './state';
+
+interface ModalProps {
+ modal: boolean;
+ setModal: (show: boolean) => void;
+}
+
+export const useModal = (): ModalProps => {
+ const [modal, setModal] = useRecoilState(callerState.callModal);
+ return { modal, setModal }
+}
\ No newline at end of file
diff --git a/phone/src/os/nui-events/hooks/useNuiEvent.ts b/phone/src/os/nui-events/hooks/useNuiEvent.ts
index 818ff8e..fa9b235 100644
--- a/phone/src/os/nui-events/hooks/useNuiEvent.ts
+++ b/phone/src/os/nui-events/hooks/useNuiEvent.ts
@@ -20,7 +20,8 @@ export const useNuiEvent = (
app: string,
method: string,
handler: Function,
- options: IOptions = {}
+ options: IOptions = {},
+ currentState?: Record
) => {
const savedHandler: MutableRefObject = useRef();
// Destructure passed options
@@ -42,7 +43,8 @@ export const useNuiEvent = (
data: event.data,
level: 1,
});
- savedHandler.current(data);
+ const newData = currentState ? { ...currentState, ...data } : data
+ savedHandler.current(newData)
}
};
// Why are destructing then restructuring option data?
diff --git a/phone/yarn.lock b/phone/yarn.lock
index 78f6c7d..b8f6449 100644
--- a/phone/yarn.lock
+++ b/phone/yarn.lock
@@ -4275,6 +4275,11 @@ data-urls@^1.0.0, data-urls@^1.1.0:
whatwg-mimetype "^2.2.0"
whatwg-url "^7.0.0"
+dayjs@^1.10.4:
+ version "1.10.4"
+ resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.4.tgz#8e544a9b8683f61783f570980a8a80eaf54ab1e2"
+ integrity sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw==
+
debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
diff --git a/resources/client/cl_call.ts b/resources/client/cl_call.ts
new file mode 100644
index 0000000..b066904
--- /dev/null
+++ b/resources/client/cl_call.ts
@@ -0,0 +1,124 @@
+import events from '../utils/events';
+import { ICall } from '../../phone/src/common/typings/call';
+
+const exp = (global as any).exports;
+
+RegisterNuiCallbackType(events.PHONE_INITIALIZE_CALL);
+on(`__cfx_nui:${events.PHONE_INITIALIZE_CALL}`, (data: any) => {
+ const start = Date.now();
+
+ emitNet(events.PHONE_INITIALIZE_CALL, data.number, start);
+});
+
+onNet(
+ events.PHONE_START_CALL,
+ (transmitter: string, receiver: string, isTransmitter: boolean) => {
+ openCallModal(true);
+
+ SendNuiMessage(
+ JSON.stringify({
+ app: 'CALL',
+ method: 'setCaller',
+ data: {
+ transmitter: transmitter,
+ receiver: receiver,
+ isTransmitter: isTransmitter,
+ accepted: false,
+ },
+ })
+ );
+ }
+);
+
+RegisterNuiCallbackType(events.PHONE_ACCEPT_CALL);
+on(`__cfx_nui:${events.PHONE_ACCEPT_CALL}`, (data: any) => {
+ emitNet(events.PHONE_ACCEPT_CALL, data.transmitterNumber);
+});
+
+onNet(
+ events.PHONE_CALL_WAS_ACCEPTED,
+ (channelId: number, currentCall: ICall, isTransmitter: boolean) => {
+ exp['mumble-voip'].SetCallChannel(channelId);
+
+ SendNuiMessage(
+ JSON.stringify({
+ app: 'CALL',
+ method: 'setCaller',
+ data: {
+ transmitter: currentCall.transmitter,
+ receiver: currentCall.receiver,
+ isTransmitter: isTransmitter,
+ accepted: true,
+ },
+ })
+ );
+ }
+);
+
+RegisterNuiCallbackType(events.PHONE_CALL_REJECTED);
+on(`__cfx_nui:${events.PHONE_CALL_REJECTED}`, (data: any) => {
+ const end = Date.now();
+ emitNet(events.PHONE_CALL_REJECTED, data.transmitterNumber, end);
+});
+
+onNet(events.PHONE_CALL_WAS_REJECTED, () => {
+ openCallModal(false);
+
+ SendNuiMessage(
+ JSON.stringify({
+ app: 'CALL',
+ method: 'setCaller',
+ data: {
+ transmitter: null,
+ receiver: null,
+ isTransmitter: null,
+ accepted: false,
+ },
+ })
+ );
+});
+
+RegisterNuiCallbackType(events.PHONE_END_CALL);
+on(`__cfx_nui:${events.PHONE_END_CALL}`, (data: any) => {
+ const end = Date.now();
+ emitNet(events.PHONE_END_CALL, data.transmitterNumber, end);
+});
+
+onNet(events.PHONE_CALL_WAS_ENDED, () => {
+ exp['mumble-voip'].SetCallChannel(0);
+
+ openCallModal(false);
+
+ SendNuiMessage(
+ JSON.stringify({
+ app: 'CALL',
+ method: 'setCaller',
+ data: {
+ transmitter: null,
+ receiver: null,
+ isTransmitter: null,
+ accepted: false,
+ },
+ })
+ );
+});
+
+function openCallModal(show: boolean) {
+ SendNuiMessage(
+ JSON.stringify({
+ app: 'CALL',
+ method: 'callModal',
+ data: show,
+ })
+ );
+}
+
+onNet(events.PHONE_CALL_SEND_HISTORY, (calls: ICall) => {
+ SendNuiMessage(
+ JSON.stringify({
+ app: 'DAILER',
+ method: 'setHistory',
+ data: calls,
+ })
+ );
+});
diff --git a/resources/client/cl_contacts.ts b/resources/client/cl_contacts.ts
index a746a60..5177bbd 100644
--- a/resources/client/cl_contacts.ts
+++ b/resources/client/cl_contacts.ts
@@ -30,6 +30,7 @@ on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any) => {
onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => {
emitNet(events.CONTACTS_GET_CONTACTS);
+ console.log("did you update the contact??????????????????");
});
RegisterNuiCallbackType(events.CONTACTS_DELETE_CONTACT);
diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts
index ab104d8..c99da94 100644
--- a/resources/client/cl_main.ts
+++ b/resources/client/cl_main.ts
@@ -351,6 +351,12 @@ on(`__cfx_nui:${events.OPEN_APP_CAMERA}`, () => {
emitNet(events.CAMERA_FETCH_PHOTOS);
});
+RegisterNuiCallbackType(events.OPEN_APP_DAILER);
+on(`__cfx_nui:${events.OPEN_APP_DAILER}`, () => {
+ emitNet(events.CONTACTS_GET_CONTACTS);
+ emitNet(events.PHONE_CALL_FETCH_CALLS);
+});
+
RegisterCommand(
'phone',
() => {
diff --git a/resources/client/client.ts b/resources/client/client.ts
index c6ebd75..460a4c4 100644
--- a/resources/client/client.ts
+++ b/resources/client/client.ts
@@ -8,6 +8,7 @@ import './cl_bank';
import './cl_notes';
import './cl_photo';
import './cl_messages';
+import './cl_call';
export let ESX: Client = null;
diff --git a/resources/import.sql b/resources/import.sql
index 441531e..25af076 100644
--- a/resources/import.sql
+++ b/resources/import.sql
@@ -142,3 +142,18 @@ CREATE TABLE IF NOT EXISTS `npwd_messages` (
CONSTRAINT `npwd_messages_group_id` FOREIGN KEY (`group_id`) REFERENCES `npwd_messages_groups` (`group_id`),
CONSTRAINT `npwd_messages_user_identifier` FOREIGN KEY (`user_identifier`) REFERENCES `users` (`identifier`)
);
+
+CREATE TABLE npwd_calls (
+ id int(11) NOT NULL AUTO_INCREMENT,
+ identifier varchar(255) DEFAULT NULL,
+ transmitter varchar(255) NOT NULL,
+ receiver varchar(255) NOT NULL,
+ is_accepted tinyint(4) DEFAULT 0,
+ start varchar(255) DEFAULT NULL,
+ end varchar(255) DEFAULT NULL,
+ PRIMARY KEY (id)
+)
+ENGINE = INNODB,
+AUTO_INCREMENT = 8,
+CHARACTER SET utf8mb4,
+COLLATE utf8mb4_general_ci;
\ No newline at end of file
diff --git a/resources/package.json b/resources/package.json
index b103e43..4b2138d 100644
--- a/resources/package.json
+++ b/resources/package.json
@@ -18,13 +18,16 @@
"@citizenfx/client": "^1.0.2792-1",
"@citizenfx/server": "^1.0.2792-1",
"@types/node": "^14.11.10",
+ "@types/uuid": "^8.3.0",
"axios": "^0.21.0",
"connection-string-parser": "^1.0.3",
+ "dayjs": "^1.10.4",
"esx.js": "^1.1.6",
"fivem-esx-js": "^0.1.12",
"fivem-js": "^1.3.1",
"md5": "^2.3.0",
- "mysql2": "^2.2.5"
+ "mysql2": "^2.2.5",
+ "uuid": "^8.3.2"
},
"devDependencies": {
"@babel/preset-env": "^7.12.1",
diff --git a/resources/server/functions.ts b/resources/server/functions.ts
index 6a7127b..0b0f24d 100644
--- a/resources/server/functions.ts
+++ b/resources/server/functions.ts
@@ -5,7 +5,7 @@ interface IPhoneNumber {
phone_number: string;
}
-interface Iidentifier {
+interface Identifier {
identifier: string;
}
@@ -27,6 +27,6 @@ export async function getIdentifierByPhoneNumber(
): Promise {
const query = 'SELECT identifier FROM users WHERE phone_number = ?';
const [results] = await pool.query(query, [phoneNumber]);
- const identifier = results;
+ const identifier = results;
return identifier[0].identifier;
}
diff --git a/resources/server/server.ts b/resources/server/server.ts
index f0279be..c6634c0 100644
--- a/resources/server/server.ts
+++ b/resources/server/server.ts
@@ -9,11 +9,10 @@ import './sv_bank';
import './sv_notes';
import './sv_photo';
import './sv_messages';
+import './sv_call';
export let ESX: Server = null;
export const getSource = () => (global as any).source;
-emit('esx:getSharedObject', (obj: Server) => (ESX = obj));
-
-// i llke t-notify
+emit('esx:getSharedObject', (obj: Server) => (ESX = obj));
\ No newline at end of file
diff --git a/resources/server/sv_call.lua b/resources/server/sv_call.lua
deleted file mode 100644
index 702400c..0000000
--- a/resources/server/sv_call.lua
+++ /dev/null
@@ -1,64 +0,0 @@
-ESX = nil
-
-TriggerEvent(
- "esx:getSharedObject",
- function(obj)
- ESX = obj
- end
-)
-
-function getIdentifierByNumber(phoneNumber)
- local result = MySQL.Sync.fetchAll("SELECT identifier FROM users WHERE phone_number = @phone_number", {
- ['@phone_number'] = phoneNumber
- })
- if result[1] ~= nil then
- return result[1].identifier
- end
- return nil
-end
-
-function getPhoneNumber(identifier)
- local result = MySQL.Sync.fetchAll("SELECT users.phone_number FROM users WHERE users.identifier = @identifier", {
- ['@identifier'] = identifier
- })
- if result[1] ~= nil then
- return result[1].phone_number
- end
- return nil
-end
-
-function getSourceFromIdentifier(identifier, cb)
- local xPlayers = ESX.GetPlayers()
- for i=1, #xPlayers, 1 do
- local xPlayer = ESX.GetPlayerFromId(xPlayers[i])
- if(xPlayer.identifier ~= nil and xPlayer.identifier == identifier) or (xPlayer.identifier == identifier) then
- cb(xPlayer.source)
- return
- end
- end
- cb(nil)
-end
-
-function getPlayerID(source)
- local identifiers = GetPlayerIdentifiers(source)
- local player = getIdentifiant(identifiers)
- return player
-end
-
-RegisterServerEvent('phone:beginCall')
-AddEventHandler('phone:beginCall', function(phoneNumber)
- local _source = source
- local xPlayer = ESX.GetPlayerFromId(_source)
- local _identifier = xPlayer.getIdentifier()
- local callerName = xPlayer.getName()
- local callerNumber = getPhoneNumber(_identifier);
-
-
- local targetIdentifier = getIdentifierByNumber(phoneNumber)
- getSourceFromIdentifier(targetIdentifier, function(target)
- local xTarget = ESX.GetPlayerFromId(target)
- local targetName = xTarget.getName()
- TriggerClientEvent('phone:startCall', target, callerName, callerNumber, _source)
- TriggerClientEvent('phone:startCall', _source, targetName, phoneNumber, target)
- end)
-end)
diff --git a/resources/server/sv_call.ts b/resources/server/sv_call.ts
new file mode 100644
index 0000000..ee2c683
--- /dev/null
+++ b/resources/server/sv_call.ts
@@ -0,0 +1,192 @@
+import { ESX } from './server';
+import events from '../utils/events';
+import {
+ getIdentifierByPhoneNumber,
+ usePhoneNumber,
+ useIdentifier,
+} from './functions';
+import { XPlayer } from 'esx.js/@types/server';
+import { ICall } from '../../phone/src/common/typings/call';
+
+import { pool } from './db';
+import { v4 as uuidv4 } from 'uuid';
+import { ConnectionStringParser } from 'connection-string-parser';
+import { time } from 'console';
+
+/**
+ * Returns the player phoneNumber for a passed identifier
+ * @param identifier The players phone number
+ */
+async function getPlayerFromIdentifier(identifier: string): Promise {
+ return new Promise((res, rej) => {
+ const xPlayers = ESX.GetPlayers();
+
+ for (const player of xPlayers) {
+ const xPlayer = ESX.GetPlayerFromId(player);
+ if (
+ xPlayer.getIdentifier() != null &&
+ xPlayer.getIdentifier() == identifier
+ ) {
+ res(xPlayer);
+ }
+ }
+
+ rej(new Error('Call Target Identifier was not found in xPlayers array'));
+ });
+}
+
+async function saveCall(call: ICall) {
+ const query =
+ 'INSERT INTO npwd_calls (transmitter, receiver, start) VALUES (?, ?, ?)';
+ await pool.query(query, [call.transmitter, call.receiver, call.start]);
+}
+
+async function updateCall(call: ICall, isAccepted: boolean, end?: number) {
+ const query =
+ 'UPDATE npwd_calls SET is_accepted, end (?, ?) WHERE identifier = ?';
+ await pool.query(query, [isAccepted, end, call.identifier]);
+}
+
+async function fetchCalls(phoneNumber: string): Promise {
+ const query =
+ 'SELECT * FROM npwd_calls WHERE receiver = ? OR transmitter = ?';
+ const [result] = await pool.query(query, [phoneNumber, phoneNumber]);
+ const calls = result;
+ return calls;
+}
+
+let calls: Map = new Map();
+
+onNet(
+ events.PHONE_INITIALIZE_CALL,
+ async (phoneNumber: string, timestamp: number) => {
+ const _source = (global as any).source;
+
+ const callIdentifier = uuidv4();
+
+ // the client that is calling
+ const xTransmitter = ESX.GetPlayerFromId(_source);
+ const transmitterNumber = await usePhoneNumber(
+ xTransmitter.getIdentifier()
+ );
+
+ // player who is being called
+ const receiverIdentifier = await getIdentifierByPhoneNumber(phoneNumber);
+ const xReceiver = await getPlayerFromIdentifier(receiverIdentifier);
+ const receiverNumber = phoneNumber;
+
+ calls.set(transmitterNumber, {
+ identifier: callIdentifier,
+ transmitter: transmitterNumber,
+ transmitterSource: _source,
+ receiver: receiverNumber,
+ receiverSource: xReceiver.source,
+ start: timestamp / 1000,
+ });
+
+ const currentCall = calls.get(transmitterNumber);
+ await saveCall(currentCall);
+
+ // events
+ // client that is calling
+ emitNet(
+ events.PHONE_START_CALL,
+ _source,
+ transmitterNumber,
+ receiverNumber,
+ true
+ );
+
+ // client that is being called
+ emitNet(
+ events.PHONE_START_CALL,
+ xReceiver.source,
+ transmitterNumber,
+ receiverNumber,
+ false
+ );
+ }
+);
+
+onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
+ try {
+ const pSource = (global as any).source;
+
+ const currentCall = calls.get(transmitterNumber);
+ const channelId = pSource;
+
+ await updateCall(currentCall, true);
+
+ // player who is being called
+ emitNet(
+ events.PHONE_CALL_WAS_ACCEPTED,
+ pSource,
+ channelId,
+ currentCall,
+ false
+ );
+
+ // player who is calling
+ emitNet(
+ events.PHONE_CALL_WAS_ACCEPTED,
+ currentCall.transmitterSource,
+ channelId,
+ currentCall,
+ true
+ );
+ } catch (error) {
+ console.log(error, error.message);
+ }
+});
+
+onNet(
+ events.PHONE_CALL_REJECTED,
+ async (transmitterNumber: string, timestamp: number) => {
+ try {
+ const pSource = (global as any).source;
+ const currentCall = calls.get(transmitterNumber);
+
+ await updateCall(currentCall, false, timestamp);
+ // player who is being called
+ emitNet(events.PHONE_CALL_WAS_REJECTED, pSource);
+
+ // player who is calling
+ emitNet(events.PHONE_CALL_WAS_REJECTED, currentCall.transmitterSource);
+ } catch (error) {
+ console.log(error, error.message);
+ }
+ }
+);
+
+onNet(
+ events.PHONE_END_CALL,
+ async (transmitterNumber: string, timestamp: number) => {
+ try {
+ const pSource = (global as any).source;
+ const currentCall = calls.get(transmitterNumber);
+
+ const endTime = timestamp / 1000;
+
+ await updateCall(currentCall, false, endTime);
+
+ // player who is being called
+ emitNet(events.PHONE_CALL_WAS_ENDED, currentCall.receiverSource);
+ // player who is calling
+ emitNet(events.PHONE_CALL_WAS_ENDED, currentCall.transmitterSource);
+
+ calls.delete(transmitterNumber);
+ } catch (error) {
+ console.log(error, error.message);
+ }
+ }
+);
+
+onNet(events.PHONE_CALL_FETCH_CALLS, async () => {
+ const _source = (global as any).source;
+ const identifier = await useIdentifier();
+ const phoneNumber = await usePhoneNumber(identifier);
+
+ const calls = await fetchCalls(phoneNumber);
+
+ emitNet(events.PHONE_CALL_SEND_HISTORY, _source, calls);
+});
diff --git a/resources/server/sv_contacts.ts b/resources/server/sv_contacts.ts
index 6be5e20..646fe6e 100644
--- a/resources/server/sv_contacts.ts
+++ b/resources/server/sv_contacts.ts
@@ -85,31 +85,40 @@ onNet(
emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source);
emitNet(
events.CONTACTS_ACTION_RESULT,
- getSource(),
- 'CONTACT_ADD_SUCCESS'
+ _source,
+ "CONTACT_ADD_SUCCESS"
);
} catch (error) {
- emitNet(events.CONTACTS_ACTION_RESULT, getSource(), 'CONTACT_ADD_FAILED');
+ const _source = (global as any).source;
+ emitNet(events.CONTACTS_ACTION_RESULT, _source, "CONTACT_ADD_FAILED");
}
}
);
onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
+ console.log('let me just log the contact first', contact);
try {
- const _source = (global as any)._source;
- const _identifier = await useIdentifier();
- updateContact(contact, _identifier);
+ const _source = (global as any).source;
+ const _identifier = ESX.GetPlayerFromId(_source).getIdentifier();
+ console.log('nice identifier bro', _identifier);
+ await updateContact(contact, _identifier);
+ console.log('i updated the contact server side!');
+
emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source);
+ console.log('ffs, didd it return successful');
+
emitNet(
events.CONTACTS_ACTION_RESULT,
- getSource(),
- 'CONTACT_UPDATE_SUCCESS'
+ _source,
+ "CONTACT_UPDATE_SUCCESS"
);
+ console.log("UPDATED CONTACT: ", contact);
} catch (error) {
+ const _source = (global as any).source;
emitNet(
events.CONTACTS_ACTION_RESULT,
- getSource(),
- 'CONTACT_UPDATE_FAILED'
+ _source,
+ "CONTACT_UPDATE_FAILED"
);
}
});
diff --git a/resources/utils/events.ts b/resources/utils/events.ts
index f5a0370..956b520 100644
--- a/resources/utils/events.ts
+++ b/resources/utils/events.ts
@@ -83,6 +83,7 @@ export default {
OPEN_APP_NOTES: 'phone:app:NOTES',
OPEN_APP_LISTINGS: 'phone:app:SELLOUT',
OPEN_APP_CAMERA: 'phone:app:CAMERA',
+ OPEN_APP_DAILER: 'phone:app:DIALER',
// camera
CAMERA_TAKE_PHOTO: 'phone:TakePhoto',
@@ -94,4 +95,16 @@ export default {
CONTACTS_ACTION_RESULT: 'phone:contactActionResult',
// copy
PHONE_USE_CLIPBOARD: 'phone:useClipboard',
+
+ // calling
+ PHONE_INITIALIZE_CALL: 'phone:beginCall',
+ PHONE_START_CALL: 'phone:startCall',
+ PHONE_ACCEPT_CALL: 'phone:acceptCall',
+ PHONE_END_CALL: 'phone:endCall',
+ PHONE_CALL_WAS_ENDED: 'phone:callEnded',
+ PHONE_CALL_WAS_ACCEPTED: 'phone:callAccepted',
+ PHONE_CALL_REJECTED: 'phone:rejectCall',
+ PHONE_CALL_WAS_REJECTED: 'phone:callRejected',
+ PHONE_CALL_FETCH_CALLS: 'phone:fetchCalls',
+ PHONE_CALL_SEND_HISTORY: 'phone:sendCallHistory',
};
diff --git a/resources/yarn.lock b/resources/yarn.lock
index d61fb87..d2f979a 100644
--- a/resources/yarn.lock
+++ b/resources/yarn.lock
@@ -1299,6 +1299,11 @@
dependencies:
source-map "^0.6.1"
+"@types/uuid@^8.3.0":
+ version "8.3.0"
+ resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f"
+ integrity sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==
+
"@types/webpack-sources@*":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/webpack-sources/-/webpack-sources-2.0.0.tgz#08216ab9be2be2e1499beaebc4d469cec81e82a7"
@@ -2608,6 +2613,11 @@ data-urls@^2.0.0:
whatwg-mimetype "^2.3.0"
whatwg-url "^8.0.0"
+dayjs@^1.10.4:
+ version "1.10.4"
+ resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.4.tgz#8e544a9b8683f61783f570980a8a80eaf54ab1e2"
+ integrity sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw==
+
debug@^2.2.0, debug@^2.3.3:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
@@ -7090,7 +7100,7 @@ uuid@^3.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
-uuid@^8.3.0:
+uuid@^8.3.0, uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==