feat(calling/client|server): partical functions for calling

Should probably reuse data
This commit is contained in:
Christopher committed 2021-01-17 22:03:52 +01:00
1 parent c12b0ba126
commit 77c7cc303e
8 files changed
+133 -56

No files matched your search

+24 -3
View File
@@ -28,6 +28,8 @@ 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';
// Inject mock data when in development env.
if (process.env.NODE_ENV === 'development') {
@@ -52,6 +54,24 @@ if (process.env.NODE_ENV === 'development') {
);
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
data: {
app: 'CALL',
method: 'setCaller',
data: {
accepted: false,
transmitter: false,
caller: 'Chip',
target: 'Christian',
phone_number: '860-4504',
}
},
})
);
}, 1000);
setTimeout(() => {
window.dispatchEvent(
new MessageEvent('message', {
@@ -258,6 +278,9 @@ function Phone() {
useMessagesService();
useNotesService();
usePhotoService();
useCallService();
const { modal } = useModal(); // the calling modal
const [settings] = useRecoilState(settingsState);
@@ -267,8 +290,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 +324,7 @@ function Phone() {
]}
/>
<div className='PhoneAppContainer'>
{calling ? (
{modal ? (
<CallModal />
) : (
<>
@@ -14,7 +14,7 @@ export const DialerHistory = ({ calls }) => {
return (
<List disablePadding>
{calls.map((call) => (
<ListItem key={call.id} divider>
<ListItem key={call.id} divider button>
<ListItemText primary={call.caller} secondary={call.phoneNumber} />
{CallTypeIcon[call.type]}
</ListItem>
+7
View File
@@ -0,0 +1,7 @@
export interface CallProps {
accepted: boolean;
transmitter: boolean;
caller: string;
target: string;
phone_number: string;
}
+7 -8
View File
@@ -5,39 +5,38 @@ 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 PhoneDisabledIcon from '@material-ui/icons/PhoneDisabled';
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';
export const CallModal = () => {
const { call, setCall } = useCall();
const { call } = useCall();
const { setModal } = useModal()
const [accepted, setAccepted] = useState(false)
const classes = useStyles()
const handleAcceptCall = () => {
setAccepted(true)
Nui.send('phone:acceptCall', {
phoneNumber: call.phone_number
})
}
const handleRejectCall = () => {
setModal(false)
setCall(null)
}
const handleEndCall = () => {
setModal(false)
setCall(null)
}
return (
<AppWrapper>
<AppContent>
<h1 style={{ textAlign: 'center' }}>{call.target}</h1>
<h1 style={{ textAlign: 'center' }}>{call.transmitter ? call.target : call.caller}</h1>
<div className={classes.actions}>
{!accepted ? (
{!call.accepted ? (
<>
<Fab
onClick={handleRejectCall}
+37 -22
View File
@@ -3,35 +3,50 @@ import events from "../utils/events";
const exp = (global as any).exports;
RegisterCommand(
"call",
(source: number, args: string[], raw: any) => {
emitNet(events.PHONE_BEGIN_CALL, args[0]);
},
false
);
setImmediate(() => {
emit("chat:addSuggestion", "/call", "Call a player", [
{
name: "Phone Number",
help: "The phone number to call",
},
]);
});
RegisterNuiCallbackType(events.PHONE_BEGIN_CALL);
on(`__cfx_nui:${events.PHONE_BEGIN_CALL}`, (data: any) => {
console.log('PHONE NUMBER YOU ARE TRYING TO CALL', data.number);
emitNet(events.PHONE_BEGIN_CALL, data.number);
});
onNet(events.PHONE_START_CALL, (target: string, phoneNumber: string) => {
onNet(events.PHONE_START_CALL, (target: string, phoneNumber: string, isTransmitter: boolean, id: any) => {
console.log(`You are talking to ${target} who has the number ${phoneNumber}`);
// Temporary for testing
exp["mumble-voip"].SetCallChannel(1);
exp["mumble-voip"].SetCallChannel(id+1);
SendNuiMessage(
JSON.stringify({
app: "CALL",
method: "callModal",
data: true
})
)
SendNuiMessage(
JSON.stringify({
app: "CALL",
method: "setCaller",
data: {
target: target,
caller: phoneNumber,
transmitter: isTransmitter,
accepted: false
}
})
)
});
onNet(events.PHONE_CALL_WAS_ENDED, () => {
RegisterNuiCallbackType(events.PHONE_ACCEPT_CALL);
on(`__cfx_nui:${events.PHONE_ACCEPT_CALL}`, (data: any) => {
emitNet(events.PHONE_ACCEPT_CALL, data.phoneNumber)
})
onNet('phone:callAccepted', (id: number) => {
exp["mumble-voip"].SetRadioChannel(id);
})
/* onNet(events.PHONE_CALL_WAS_ENDED, () => {
console.log("Call ended");
exp["mumble-voip"].SetCallChannel(0);
});
}); */
+2 -2
View File
@@ -5,7 +5,7 @@ interface IPhoneNumber {
phone_number: string;
}
interface Iidentifier {
interface Identifier {
identifier: string;
}
@@ -27,6 +27,6 @@ export async function getIdentifierByPhoneNumber(
): Promise<string> {
const query = 'SELECT identifier FROM users WHERE phone_number = ?';
const [results] = await pool.query(query, [phoneNumber]);
const identifier = <Iidentifier[]>results;
const identifier = <Identifier[]>results;
return identifier[0].identifier;
}
+48 -19
View File
@@ -1,12 +1,12 @@
import { ESX } from "./server";
import events from "../utils/events";
import { getIdentifierByPhoneNumber, getPhoneNumberFromID } from "./functions";
import { getIdentifierByPhoneNumber, usePhoneNumber } from "./functions";
import { XPlayer } from "esx.js/@types/server";
/**
* Returns the player phoneNumber for a passed identifier
* @param identifier The players phone number
*/
function getPlayerFromIdentifier(identifier: string): Promise<XPlayer> {
async function getPlayerFromIdentifier(identifier: string): Promise<XPlayer> {
return new Promise((res, rej) => {
const xPlayers = ESX.GetPlayers();
@@ -25,26 +25,55 @@ function getPlayerFromIdentifier(identifier: string): Promise<XPlayer> {
}
onNet(events.PHONE_BEGIN_CALL, async (phoneNumber: string) => {
const callSource = (global as any).source;
const xPlayer = ESX.GetPlayerFromId(callSource);
const _identifier = xPlayer.getIdentifier();
const callerName = xPlayer.getName();
const callerNumber = getPhoneNumberFromID(_identifier);
try {
const targetPlayer = await getPlayerFromIdentifier(phoneNumber);
const targetName = xPlayer.getName();
const pSource = (global as any).source;
const xPlayer = ESX.GetPlayerFromId(pSource);
const _identifier = xPlayer.getIdentifier();
const callerName = xPlayer.getName();
const callerNumber = await usePhoneNumber(_identifier);
const targetIdentifier = await getIdentifierByPhoneNumber(phoneNumber)
const targetPlayer = await getPlayerFromIdentifier(targetIdentifier);
console.log('got the targetPlayer')
const targetName = targetPlayer.getName()
console.log('got the target name: ', targetName)
// target
// Sends information to the client: sourec, playerName, number, isTransmitter
emitNet(events.PHONE_START_CALL, targetPlayer.source, callerName, phoneNumber, false, pSource);
// source
// Sends information to the client: sourec, playerName, number, isTransmitter
emitNet(events.PHONE_START_CALL, pSource, targetName, callerNumber, true, targetPlayer.source);
emitNet(
events.PHONE_START_CALL,
targetPlayer.source,
callerName,
phoneNumber
);
emitNet(events.PHONE_START_CALL, targetName, callerNumber);
} catch (e) {
console.error(e);
emit(events.PHONE_CALL_ERORR, callSource);
console.log('Failed to call monkaS');
//emit(events.PHONE_CALL_ERROR, callSource);
}
});
// phoneNumber is the number you're calling
onNet(events.PHONE_ACCEPT_CALL, async (phoneNumber: string) => {
try {
const pSource = (global as any).source
// target
const targetIdentifier = await getIdentifierByPhoneNumber(phoneNumber)
const targetPlayer = await getPlayerFromIdentifier(targetIdentifier);
// client that is calling
emitNet('phone:callAccepted', pSource, targetPlayer.source)
// client that is being called
emitNet('phone:callAccepted', targetPlayer.source, pSource)
} catch (error) {
}
})
+7 -1
View File
@@ -93,5 +93,11 @@ export default {
CAMERA_DELETE_PHOTO_SUCCESS: 'phone:deletePhotoSuccess',
CONTACTS_ACTION_RESULT: 'phone:contactActionResult',
// copy
PHONE_USE_CLIPBOARD: 'phone:useClipboard',
PHONE_USE_CLIPBOARD: "phone:useClipboard",
// calling
PHONE_BEGIN_CALL: "phone:beginCall",
PHONE_START_CALL: "phone:startCall",
PHONE_ACCEPT_CALL: 'phone:acceptCall',
PHONE_END_CALL: 'phone:endCall'
};