mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
fix(calls): Fix incorrect data type being sent over net
This commit is contained in:
1 parent
60b9e35ae8
commit
5263a83d1f
10 files changed
+99
-107
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
ActiveCall,
|
||||
CallEvents,
|
||||
CallWasAcceptedEvent,
|
||||
EndCallDTO,
|
||||
InitializeCallDTO,
|
||||
StartCallEventData,
|
||||
@@ -11,27 +11,32 @@ import { CallService } from './cl_calls.service';
|
||||
import { animationService } from '../animations/animation.controller';
|
||||
import { emitNetTyped, onNetTyped } from '../../server/utils/miscUtils';
|
||||
import { RegisterNuiCB, RegisterNuiProxy } from '../cl_utils';
|
||||
import { NuiCallbackFunc } from '@project-error/pe-utils';
|
||||
import { ClUtils } from '../client';
|
||||
import { ServerPromiseResp } from '../../../typings/common';
|
||||
|
||||
const callService = new CallService();
|
||||
|
||||
// Will trigger whenever somebody initializes a call to any number
|
||||
RegisterNuiCB<InitializeCallDTO>(CallEvents.INITIALIZE_CALL, async (data, cb) => {
|
||||
// If they are already in a call return without initializing a new one.
|
||||
if (callService.isInCall()) return;
|
||||
|
||||
try {
|
||||
const serverRes = await ClUtils.emitNetPromise<ServerPromiseResp<StartCallEventData>>(
|
||||
const serverRes = await ClUtils.emitNetPromise<ServerPromiseResp<ActiveCall>>(
|
||||
CallEvents.INITIALIZE_CALL,
|
||||
data,
|
||||
);
|
||||
|
||||
// If something went wrong lets inform the client
|
||||
if (serverRes.status !== 'ok') {
|
||||
cb(serverRes);
|
||||
return cb(serverRes);
|
||||
}
|
||||
|
||||
const { transmitter, isTransmitter, receiver } = serverRes.data;
|
||||
|
||||
// Start the process of giving NUI feedback by opening NUI modal
|
||||
callService.handleStartCall(transmitter, receiver, isTransmitter);
|
||||
|
||||
cb({});
|
||||
cb({ status: 'ok' });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
cb({ status: 'error', errorMsg: 'CLIENT_TIMED_OUT' });
|
||||
@@ -49,15 +54,12 @@ RegisterNuiCB<TransmitterNumDTO>(CallEvents.ACCEPT_CALL, (data, cb) => {
|
||||
cb({});
|
||||
});
|
||||
|
||||
onNetTyped<CallWasAcceptedEvent>(
|
||||
CallEvents.WAS_ACCEPTED,
|
||||
({ channelId, currentCall, isTransmitter }) => {
|
||||
callService.handleCallAccepted(channelId, currentCall, isTransmitter);
|
||||
},
|
||||
);
|
||||
onNetTyped<ActiveCall>(CallEvents.WAS_ACCEPTED, (callData) => {
|
||||
callService.handleCallAccepted(callData);
|
||||
});
|
||||
|
||||
// Rejected call
|
||||
RegisterNuiCB<TransmitterNumDTO>(CallEvents.REJECTED, (data, cb: NuiCallbackFunc) => {
|
||||
RegisterNuiCB<TransmitterNumDTO>(CallEvents.REJECTED, (data, cb) => {
|
||||
emitNetTyped<TransmitterNumDTO>(CallEvents.REJECTED, data);
|
||||
cb({});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IAlertProps } from '../../../typings/alerts';
|
||||
import { CallEvents, CallHistoryItem, CallRejectReasons } from '../../../typings/call';
|
||||
import { ActiveCall, CallEvents, CallRejectReasons } from '../../../typings/call';
|
||||
import { animationService } from '../animations/animation.controller';
|
||||
|
||||
const exp = (global as any).exports;
|
||||
@@ -11,33 +11,27 @@ export class CallService {
|
||||
this.currentCall = 0;
|
||||
}
|
||||
|
||||
static sendCallAction<T>(method: CallEvents, data: T): void {
|
||||
SendNUIMessage({
|
||||
app: 'CALL',
|
||||
method,
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
isInCall() {
|
||||
return this.currentCall !== 0;
|
||||
}
|
||||
|
||||
openCallModal(show: boolean) {
|
||||
SendNUIMessage({
|
||||
app: 'CALL',
|
||||
method: CallEvents.SET_CALL_MODAL,
|
||||
data: show,
|
||||
});
|
||||
CallService.sendCallAction<boolean>(CallEvents.SET_CALL_MODAL, show);
|
||||
}
|
||||
|
||||
handleRejectCall() {
|
||||
// we don't want to reset our UI if we're in a call already.
|
||||
if (this.isInCall()) return;
|
||||
this.openCallModal(false);
|
||||
SendNUIMessage({
|
||||
app: 'CALL',
|
||||
method: CallEvents.SET_CALLER,
|
||||
data: {
|
||||
transmitter: null,
|
||||
receiver: null,
|
||||
isTransmitter: null,
|
||||
accepted: false,
|
||||
active: false,
|
||||
},
|
||||
});
|
||||
CallService.sendCallAction(CallEvents.SET_CALLER, null);
|
||||
}
|
||||
|
||||
handleStartCall(transmitter: string, receiver: string, isTransmitter: boolean) {
|
||||
@@ -61,21 +55,10 @@ export class CallService {
|
||||
});
|
||||
}
|
||||
|
||||
handleCallAccepted(channelId: number, currentCall: CallHistoryItem, isTransmitter: boolean) {
|
||||
this.currentCall = channelId;
|
||||
exp['pma-voice'].setCallChannel(channelId);
|
||||
// phoneCallStartAnim(); // Trigger call animation only if the call was accepted.
|
||||
SendNUIMessage({
|
||||
app: 'CALL',
|
||||
method: CallEvents.SET_CALLER,
|
||||
data: {
|
||||
active: true,
|
||||
transmitter: currentCall.transmitter,
|
||||
receiver: currentCall.receiver,
|
||||
isTransmitter: isTransmitter,
|
||||
accepted: true,
|
||||
},
|
||||
});
|
||||
handleCallAccepted(callData: ActiveCall) {
|
||||
this.currentCall = callData.channelId;
|
||||
exp['pma-voice'].setCallChannel(callData.channelId);
|
||||
CallService.sendCallAction<ActiveCall>(CallEvents.SET_CALLER, callData);
|
||||
}
|
||||
|
||||
handleEndCall() {
|
||||
@@ -83,17 +66,7 @@ export class CallService {
|
||||
exp['pma-voice'].setCallChannel(0);
|
||||
this.openCallModal(false);
|
||||
|
||||
SendNUIMessage({
|
||||
app: 'CALL',
|
||||
method: CallEvents.SET_CALLER,
|
||||
data: {
|
||||
transmitter: null,
|
||||
receiver: null,
|
||||
isTransmitter: null,
|
||||
accepted: false,
|
||||
active: false,
|
||||
},
|
||||
});
|
||||
CallService.sendCallAction<null>(CallEvents.SET_CALLER, null);
|
||||
}
|
||||
|
||||
handleSendAlert(alert: IAlertProps) {
|
||||
@@ -103,12 +76,4 @@ export class CallService {
|
||||
data: alert,
|
||||
});
|
||||
}
|
||||
|
||||
handleFetchCalls(calls: CallHistoryItem[]) {
|
||||
SendNUIMessage({
|
||||
app: 'DIALER',
|
||||
method: CallEvents.SET_CALL_HISTORY,
|
||||
data: calls,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,14 @@ import {
|
||||
TransmitterNumDTO,
|
||||
EndCallDTO,
|
||||
InitializeCallDTO,
|
||||
StartCallEventData,
|
||||
ActiveCall,
|
||||
} from '../../../typings/call';
|
||||
import { getSource, onNetTyped } from '../utils/miscUtils';
|
||||
import CallService from './calls.service';
|
||||
import { callLogger } from './calls.utils';
|
||||
import { onNetPromise } from '../utils/PromiseNetEvents/onNetPromise';
|
||||
|
||||
onNetPromise<InitializeCallDTO, StartCallEventData>(CallEvents.INITIALIZE_CALL, (reqObj, resp) => {
|
||||
onNetPromise<InitializeCallDTO, ActiveCall>(CallEvents.INITIALIZE_CALL, (reqObj, resp) => {
|
||||
CallService.handleInitializeCall(reqObj, resp).catch((e) => {
|
||||
resp({ status: 'error', errorMsg: 'SERVER_ERROR' });
|
||||
callLogger.error(`Error occured handling init call: ${e.message}`);
|
||||
@@ -27,7 +27,7 @@ onNetTyped<TransmitterNumDTO>(CallEvents.ACCEPT_CALL, ({ transmitterNumber }) =>
|
||||
);
|
||||
});
|
||||
|
||||
// Fire and forget event, client doesn't care what response is we reject no matter what
|
||||
// Fire and forget event, client doesn't care what response is we reject no matter what.
|
||||
// thats the reason its not promise
|
||||
onNetTyped<TransmitterNumDTO>(CallEvents.REJECTED, (data) => {
|
||||
const src = getSource();
|
||||
|
||||
@@ -2,11 +2,10 @@ import Collection from '@discordjs/collection';
|
||||
import {
|
||||
CallEvents,
|
||||
CallHistoryItem,
|
||||
InitializeCallResp,
|
||||
InitializeCallDTO,
|
||||
EndCallDTO,
|
||||
StartCallEventData,
|
||||
CallWasAcceptedEvent,
|
||||
ActiveCall,
|
||||
ActiveCallRaw,
|
||||
} from '../../../typings/call';
|
||||
import CallsDB, { CallsRepo } from './calls.db';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
@@ -14,9 +13,10 @@ import PlayerService from '../players/player.service';
|
||||
import { callLogger } from './calls.utils';
|
||||
import { PromiseEventResp, PromiseRequest } from '../utils/PromiseNetEvents/promise.types';
|
||||
import { emitNetTyped } from '../utils/miscUtils';
|
||||
import { mainLogger } from '../sv_logger';
|
||||
|
||||
class CallsService {
|
||||
private callMap: Collection<string, CallHistoryItem>;
|
||||
private callMap: Collection<string, ActiveCallRaw>;
|
||||
private readonly callsDB: CallsRepo;
|
||||
|
||||
constructor() {
|
||||
@@ -25,7 +25,7 @@ class CallsService {
|
||||
callLogger.debug('Call service started');
|
||||
}
|
||||
|
||||
private setCallInMap(transmitterNumber: string, callObj: CallHistoryItem): void {
|
||||
private setCallInMap(transmitterNumber: string, callObj: ActiveCallRaw): void {
|
||||
this.callMap.set(transmitterNumber, callObj);
|
||||
callLogger.debug(`Call obj set with key ${transmitterNumber}, value:`);
|
||||
callLogger.debug(callObj);
|
||||
@@ -33,7 +33,7 @@ class CallsService {
|
||||
|
||||
async handleInitializeCall(
|
||||
reqObj: PromiseRequest<InitializeCallDTO>,
|
||||
resp: PromiseEventResp<StartCallEventData>,
|
||||
resp: PromiseEventResp<ActiveCall>,
|
||||
): Promise<void> {
|
||||
// Create initial call data
|
||||
const transmittingPlayer = PlayerService.getPlayer(reqObj.source);
|
||||
@@ -53,6 +53,7 @@ class CallsService {
|
||||
isTransmitter: true,
|
||||
receiver: reqObj.data.receiverNumber,
|
||||
isUnavailable: true,
|
||||
is_accepted: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -66,7 +67,7 @@ class CallsService {
|
||||
callLogger.debug(`Receiving Identifier: ${receiverIdentifier}`);
|
||||
callLogger.debug(`Receiving source: ${receivingPlayer.source} `);
|
||||
|
||||
const callObj: CallHistoryItem = {
|
||||
const callObj: ActiveCallRaw = {
|
||||
identifier: callIdentifier,
|
||||
transmitter: transmitterNumber,
|
||||
transmitterSource: transmittingPlayer.source,
|
||||
@@ -82,6 +83,7 @@ class CallsService {
|
||||
return resp({
|
||||
status: 'ok',
|
||||
data: {
|
||||
is_accepted: false,
|
||||
transmitter: transmitterNumber,
|
||||
isTransmitter: true,
|
||||
receiver: reqObj.data.receiverNumber,
|
||||
@@ -107,15 +109,17 @@ class CallsService {
|
||||
resp({
|
||||
status: 'ok',
|
||||
data: {
|
||||
is_accepted: false,
|
||||
transmitter: transmitterNumber,
|
||||
receiver: reqObj.data.receiverNumber,
|
||||
isTransmitter: true,
|
||||
},
|
||||
});
|
||||
|
||||
emitNetTyped<StartCallEventData>(
|
||||
emitNetTyped<ActiveCall>(
|
||||
CallEvents.START_CALL,
|
||||
{
|
||||
is_accepted: false,
|
||||
transmitter: transmitterNumber,
|
||||
receiver: reqObj.data.receiverNumber,
|
||||
isTransmitter: false,
|
||||
@@ -126,35 +130,41 @@ class CallsService {
|
||||
|
||||
async handleAcceptCall(src: number, transmitterNumber: string): Promise<void> {
|
||||
// We retrieve the call that was accepted from the current calls map
|
||||
const curCallAccepted = this.callMap.get(transmitterNumber);
|
||||
const targetCallItem = this.callMap.get(transmitterNumber);
|
||||
// We update its reference
|
||||
curCallAccepted.is_accepted = true;
|
||||
targetCallItem.is_accepted = true;
|
||||
|
||||
const channelId = src;
|
||||
|
||||
await this.callsDB.updateCall(curCallAccepted, true, null);
|
||||
await this.callsDB.updateCall(targetCallItem, true, null);
|
||||
callLogger.debug(`Call with key ${transmitterNumber} was updated to be accepted`);
|
||||
|
||||
// player who is being called
|
||||
emitNetTyped<CallWasAcceptedEvent>(
|
||||
emitNetTyped<ActiveCall>(
|
||||
CallEvents.WAS_ACCEPTED,
|
||||
{
|
||||
currentCall: curCallAccepted,
|
||||
is_accepted: true,
|
||||
transmitter: transmitterNumber,
|
||||
receiver: targetCallItem.receiver,
|
||||
isTransmitter: false,
|
||||
channelId,
|
||||
},
|
||||
curCallAccepted.receiverSource,
|
||||
targetCallItem.receiverSource,
|
||||
);
|
||||
|
||||
mainLogger.debug(targetCallItem);
|
||||
|
||||
// player who is calling
|
||||
emitNetTyped<CallWasAcceptedEvent>(
|
||||
emitNetTyped<ActiveCall>(
|
||||
CallEvents.WAS_ACCEPTED,
|
||||
{
|
||||
currentCall: curCallAccepted,
|
||||
is_accepted: true,
|
||||
transmitter: transmitterNumber,
|
||||
receiver: targetCallItem.receiver,
|
||||
isTransmitter: true,
|
||||
channelId,
|
||||
},
|
||||
curCallAccepted.transmitterSource,
|
||||
targetCallItem.transmitterSource,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user