mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
feat(calling/client|server): partical functions for calling
Should probably reuse data
This commit is contained in:
1 parent
c12b0ba126
commit
77c7cc303e
8 files changed
+133
-56
No files matched your search
+37
-22
@@ -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);
|
||||
});
|
||||
}); */
|
||||
@@ -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
@@ -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) {
|
||||
|
||||
}
|
||||
})
|
||||
@@ -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'
|
||||
};
|
||||
Reference in new issue
Block a user