mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
refactor(calls): refactor of call architecture
This commit is contained in:
1 parent
92b687b130
commit
36d1e993bd
21 files changed
+361
-185
No files matched your search
@@ -1,64 +1,94 @@
|
||||
import { CallEvents } from '../../../typings/call';
|
||||
import { CallHistoryItem } from '../../../typings/call';
|
||||
import {
|
||||
CallEvents,
|
||||
CallWasAcceptedEvent,
|
||||
InitializeCallDTO,
|
||||
StartCallEventData,
|
||||
TransmitterNumDTO,
|
||||
} from '../../../typings/call';
|
||||
import { IAlertProps } from '../../../typings/alerts';
|
||||
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();
|
||||
|
||||
RegisterNuiCallbackType(CallEvents.INITIALIZE_CALL); // Fires when the call is started.
|
||||
on(`__cfx_nui:${CallEvents.INITIALIZE_CALL}`, (data: any, cb: Function) => {
|
||||
emitNet(CallEvents.INITIALIZE_CALL, data.number);
|
||||
cb();
|
||||
});
|
||||
RegisterNuiCB<InitializeCallDTO>(CallEvents.INITIALIZE_CALL, async (data, cb) => {
|
||||
try {
|
||||
const serverRes = await ClUtils.emitNetPromise<ServerPromiseResp<StartCallEventData>>(
|
||||
CallEvents.INITIALIZE_CALL,
|
||||
data,
|
||||
);
|
||||
if (serverRes.status !== 'ok') {
|
||||
cb(serverRes);
|
||||
}
|
||||
|
||||
onNet(CallEvents.START_CALL, (transmitter: string, receiver: string, isTransmitter: boolean) => {
|
||||
if(isTransmitter){
|
||||
animationService.startPhoneCall();
|
||||
const { transmitter, isTransmitter, receiver } = serverRes.data;
|
||||
|
||||
callService.handleStartCall(transmitter, receiver, isTransmitter);
|
||||
|
||||
cb({});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
cb({ status: 'error', errorMsg: 'CLIENT_TIMED_OUT' });
|
||||
}
|
||||
callService.handleStartCall(transmitter, receiver, isTransmitter)
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(CallEvents.ACCEPT_CALL); // Fires when the TARGET accepts.
|
||||
on(`__cfx_nui:${CallEvents.ACCEPT_CALL}`, (data: any, cb: Function) => {
|
||||
onNetTyped<StartCallEventData>(CallEvents.START_CALL, (data) => {
|
||||
const { transmitter, isTransmitter, receiver } = data;
|
||||
callService.handleStartCall(transmitter, receiver, isTransmitter);
|
||||
});
|
||||
|
||||
RegisterNuiCB<TransmitterNumDTO>(CallEvents.ACCEPT_CALL, (data, cb) => {
|
||||
animationService.startPhoneCall();
|
||||
emitNet(CallEvents.ACCEPT_CALL, data.transmitterNumber);
|
||||
cb();
|
||||
emitNetTyped<TransmitterNumDTO>(CallEvents.ACCEPT_CALL, data);
|
||||
cb({});
|
||||
});
|
||||
|
||||
onNet(CallEvents.WAS_ACCEPTED, (channelId: number, currentCall: CallHistoryItem, isTransmitter: boolean) => {
|
||||
callService.handleCallAccepted(channelId, currentCall, isTransmitter)
|
||||
onNetTyped<CallWasAcceptedEvent>(
|
||||
CallEvents.WAS_ACCEPTED,
|
||||
({ channelId, currentCall, isTransmitter }) => {
|
||||
callService.handleCallAccepted(channelId, currentCall, isTransmitter);
|
||||
},
|
||||
);
|
||||
|
||||
// Rejected call
|
||||
RegisterNuiCB<TransmitterNumDTO>(CallEvents.REJECTED, (data, cb: NuiCallbackFunc) => {
|
||||
emitNet(CallEvents.REJECTED, data.transmitterNumber);
|
||||
cb({});
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(CallEvents.REJECTED); // Fires when cancelling and rejecting a call.
|
||||
on(`__cfx_nui:${CallEvents.REJECTED}`, (data: any, cb: Function) => {
|
||||
console.log('rejected?')
|
||||
emitNet(CallEvents.REJECTED, data.phoneNumber);
|
||||
cb();
|
||||
onNet(CallEvents.WAS_REJECTED, async () => {
|
||||
callService.handleRejectCall();
|
||||
animationService.endPhoneCall();
|
||||
});
|
||||
|
||||
onNet(CallEvents.WAS_REJECTED, async() => {
|
||||
callService.handleRejectCall();
|
||||
animationService.endPhoneCall();
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(CallEvents.END_CALL); // Fires when ending an ACTIVE call
|
||||
on(`__cfx_nui:${CallEvents.END_CALL}`, (data: any, cb: Function) => {
|
||||
const end = Date.now();
|
||||
RegisterNuiCB<TransmitterNumDTO>(CallEvents.END_CALL, async (data, cb) => {
|
||||
try {
|
||||
const serverRes: ServerPromiseResp<void> = await ClUtils.emitNetPromise(
|
||||
CallEvents.END_CALL,
|
||||
data,
|
||||
);
|
||||
if (serverRes.status === 'error') return console.error(serverRes.errorMsg);
|
||||
callService.handleEndCall();
|
||||
cb({});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
cb({ status: 'error', errorMsg: 'CLIENT_TIMED_OUT' });
|
||||
}
|
||||
animationService.endPhoneCall();
|
||||
emitNet(CallEvents.END_CALL, data.transmitterNumber, end);
|
||||
cb();
|
||||
});
|
||||
|
||||
onNet(CallEvents.WAS_ENDED, () => {
|
||||
callService.handleEndCall();
|
||||
callService.handleEndCall();
|
||||
animationService.endPhoneCall();
|
||||
});
|
||||
|
||||
|
||||
onNet(CallEvents.FETCH_CALLS, (calls: CallHistoryItem[]) => {
|
||||
callService.handleFetchCalls(calls);
|
||||
});
|
||||
// Simple fetch so lets just proxy it
|
||||
RegisterNuiProxy(CallEvents.FETCH_CALLS);
|
||||
|
||||
onNet(CallEvents.SEND_ALERT, (alert: IAlertProps) => {
|
||||
callService.handleSendAlert(alert);
|
||||
|
||||
@@ -43,6 +43,7 @@ export class CallService {
|
||||
// If we're already in a call we want to automatically reject
|
||||
if (this.isInCall())
|
||||
return emitNet(CallEvents.REJECTED, transmitter, CallRejectReasons.BUSY_LINE);
|
||||
|
||||
this.openCallModal(true);
|
||||
|
||||
SendNUIMessage({
|
||||
|
||||
Reference in new issue
Block a user