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(); RegisterNuiCB(CallEvents.INITIALIZE_CALL, async (data, cb) => { try { const serverRes = await ClUtils.emitNetPromise>( CallEvents.INITIALIZE_CALL, data, ); if (serverRes.status !== 'ok') { cb(serverRes); } const { transmitter, isTransmitter, receiver } = serverRes.data; callService.handleStartCall(transmitter, receiver, isTransmitter); cb({}); } catch (e) { console.error(e); cb({ status: 'error', errorMsg: 'CLIENT_TIMED_OUT' }); } }); onNetTyped(CallEvents.START_CALL, (data) => { const { transmitter, isTransmitter, receiver } = data; callService.handleStartCall(transmitter, receiver, isTransmitter); }); RegisterNuiCB(CallEvents.ACCEPT_CALL, (data, cb) => { animationService.startPhoneCall(); emitNetTyped(CallEvents.ACCEPT_CALL, data); cb({}); }); onNetTyped( CallEvents.WAS_ACCEPTED, ({ channelId, currentCall, isTransmitter }) => { callService.handleCallAccepted(channelId, currentCall, isTransmitter); }, ); // Rejected call RegisterNuiCB(CallEvents.REJECTED, (data, cb: NuiCallbackFunc) => { emitNet(CallEvents.REJECTED, data.transmitterNumber); cb({}); }); onNet(CallEvents.WAS_REJECTED, async () => { callService.handleRejectCall(); animationService.endPhoneCall(); }); RegisterNuiCB(CallEvents.END_CALL, async (data, cb) => { try { const serverRes: ServerPromiseResp = 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(); }); onNet(CallEvents.WAS_ENDED, () => { callService.handleEndCall(); animationService.endPhoneCall(); }); // Simple fetch so lets just proxy it RegisterNuiProxy(CallEvents.FETCH_CALLS); onNet(CallEvents.SEND_ALERT, (alert: IAlertProps) => { callService.handleSendAlert(alert); });