mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
tweak(server/calls): Tweaked call handling
Added Sanity checks Switched timestamp creation to server
This commit is contained in:
1 parent
bc8a89d825
commit
adf9758d9f
2 files changed
+21
-11
No files matched your search
@@ -6,8 +6,7 @@ const exp = (global as any).exports;
|
|||||||
|
|
||||||
RegisterNuiCallbackType(events.PHONE_INITIALIZE_CALL); // Fires when the call is started.
|
RegisterNuiCallbackType(events.PHONE_INITIALIZE_CALL); // Fires when the call is started.
|
||||||
on(`__cfx_nui:${events.PHONE_INITIALIZE_CALL}`, (data: any, cb: Function) => {
|
on(`__cfx_nui:${events.PHONE_INITIALIZE_CALL}`, (data: any, cb: Function) => {
|
||||||
const start = Date.now();
|
emitNet(events.PHONE_INITIALIZE_CALL, data.number);
|
||||||
emitNet(events.PHONE_INITIALIZE_CALL, data.number, start);
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -58,8 +57,7 @@ onNet(
|
|||||||
|
|
||||||
RegisterNuiCallbackType(events.PHONE_CALL_REJECTED); // Fires when cancelling and rejecting a call.
|
RegisterNuiCallbackType(events.PHONE_CALL_REJECTED); // Fires when cancelling and rejecting a call.
|
||||||
on(`__cfx_nui:${events.PHONE_CALL_REJECTED}`, (data: any, cb: Function) => {
|
on(`__cfx_nui:${events.PHONE_CALL_REJECTED}`, (data: any, cb: Function) => {
|
||||||
const end = Date.now();
|
emitNet(events.PHONE_CALL_REJECTED, data.phoneNumber);
|
||||||
emitNet(events.PHONE_CALL_REJECTED, data.phoneNumber, end);
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import events from '../utils/events';
|
import events from '../utils/events';
|
||||||
import { getIdentifierByPhoneNumber, getPlayer, getSource } from './functions';
|
import { getIdentifierByPhoneNumber, getPlayer, getSource } from './functions';
|
||||||
|
|
||||||
import { getPlayerFromIdentifier } from './functions';
|
import { getPlayerFromIdentifier } from './functions';
|
||||||
import { ICall } from '../../typings/call';
|
import { ICall } from '../../typings/call';
|
||||||
|
|
||||||
@@ -30,9 +29,11 @@ async function fetchCalls(phoneNumber: string): Promise<ICall[]> {
|
|||||||
|
|
||||||
let calls: Map<string, ICall> = new Map();
|
let calls: Map<string, ICall> = new Map();
|
||||||
|
|
||||||
onNet(events.PHONE_INITIALIZE_CALL, async (phoneNumber: string, timestamp: number) => {
|
onNet(events.PHONE_INITIALIZE_CALL, async (phoneNumber: string) => {
|
||||||
const _source = getSource();
|
const _source = getSource();
|
||||||
|
|
||||||
|
const startCallTimeUnix = new Date().getTime() / 1000;
|
||||||
|
|
||||||
const callIdentifier = uuidv4();
|
const callIdentifier = uuidv4();
|
||||||
|
|
||||||
// the client that is calling
|
// the client that is calling
|
||||||
@@ -60,7 +61,7 @@ onNet(events.PHONE_INITIALIZE_CALL, async (phoneNumber: string, timestamp: numbe
|
|||||||
transmitterSource: _source,
|
transmitterSource: _source,
|
||||||
receiver: receiverNumber,
|
receiver: receiverNumber,
|
||||||
receiverSource: xReceiver.source,
|
receiverSource: xReceiver.source,
|
||||||
start: timestamp / 1000,
|
start: Math.floor(startCallTimeUnix),
|
||||||
accepted: false,
|
accepted: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -81,6 +82,10 @@ onNet(events.PHONE_ACCEPT_CALL, async (transmitterNumber: string) => {
|
|||||||
const pSource = getSource();
|
const pSource = getSource();
|
||||||
try {
|
try {
|
||||||
const currentCall = calls.get(transmitterNumber);
|
const currentCall = calls.get(transmitterNumber);
|
||||||
|
|
||||||
|
// Sanity check if call exists in current set
|
||||||
|
if (!currentCall) new Error('Transmitter number does not exist in set.');
|
||||||
|
|
||||||
const channelId = pSource;
|
const channelId = pSource;
|
||||||
|
|
||||||
await updateCall(currentCall, true, null);
|
await updateCall(currentCall, true, null);
|
||||||
@@ -109,6 +114,9 @@ onNet(events.PHONE_CALL_REJECTED, async (transmitterNumber: string, timestamp: n
|
|||||||
const pSource = getSource();
|
const pSource = getSource();
|
||||||
try {
|
try {
|
||||||
const currentCall = calls.get(transmitterNumber);
|
const currentCall = calls.get(transmitterNumber);
|
||||||
|
|
||||||
|
// Sanity check if call exists in current set
|
||||||
|
if (!currentCall) new Error('Transmitter number does not exist in set.');
|
||||||
await updateCall(currentCall, false, timestamp);
|
await updateCall(currentCall, false, timestamp);
|
||||||
|
|
||||||
// player who is called and initiasted the rejection.
|
// player who is called and initiasted the rejection.
|
||||||
@@ -124,13 +132,17 @@ onNet(events.PHONE_CALL_REJECTED, async (transmitterNumber: string, timestamp: n
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onNet(events.PHONE_END_CALL, async (transmitterNumber: string, timestamp: number) => {
|
onNet(events.PHONE_END_CALL, async (transmitterNumber: string) => {
|
||||||
const pSource = getSource();
|
const pSource = getSource();
|
||||||
try {
|
try {
|
||||||
|
const currentTimeUnix = new Date().getTime() / 1000;
|
||||||
|
|
||||||
const currentCall = calls.get(transmitterNumber);
|
const currentCall = calls.get(transmitterNumber);
|
||||||
const endTime = timestamp / 1000;
|
|
||||||
await updateCall(currentCall, false, endTime);
|
// Sanity check if call exists in current set
|
||||||
const accepted = calls.get(pSource);
|
if (!currentCall) new Error('Transmitter number does not exist in set.');
|
||||||
|
|
||||||
|
await updateCall(currentCall, false, currentTimeUnix);
|
||||||
|
|
||||||
// player who is being called
|
// player who is being called
|
||||||
emitNet(events.PHONE_CALL_WAS_ENDED, currentCall.receiverSource);
|
emitNet(events.PHONE_CALL_WAS_ENDED, currentCall.receiverSource);
|
||||||
|
|||||||
Reference in new issue
Block a user