mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
feat(): add animation and call service & controllers (#259)
* feat(): add animation and call service & controllers - run animations on interval so we don't lose animations when walking through doors - move cl_call.ts to a class * fix(animation/service): make everything private except for open/closePhone and start/endPhoneCall
This commit is contained in:
1 parent
4ef89f679f
commit
398bfa2092
14 files changed
+412
-298
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { CallEvents } from '../../../typings/call';
|
||||
import { CallHistoryItem } from '../../../typings/call';
|
||||
import { IAlertProps } from '../../../typings/alerts';
|
||||
import { CallService } from './cl_calls.service';
|
||||
import { animationService } from '../animations/animation.controller';
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
onNet(CallEvents.START_CALL, (transmitter: string, receiver: string, isTransmitter: boolean) => {
|
||||
if(isTransmitter){
|
||||
animationService.startPhoneCall();
|
||||
}
|
||||
callService.handleStartCall(transmitter, receiver, isTransmitter)
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(CallEvents.ACCEPT_CALL); // Fires when the TARGET accepts.
|
||||
on(`__cfx_nui:${CallEvents.ACCEPT_CALL}`, (data: any, cb: Function) => {
|
||||
animationService.startPhoneCall();
|
||||
emitNet(CallEvents.ACCEPT_CALL, data.transmitterNumber);
|
||||
cb();
|
||||
});
|
||||
|
||||
onNet(CallEvents.WAS_ACCEPTED, (channelId: number, currentCall: CallHistoryItem, isTransmitter: boolean) => {
|
||||
callService.handleCallAccepted(channelId, currentCall, isTransmitter)
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(CallEvents.END_CALL); // Fires when ending an ACTIVE call
|
||||
on(`__cfx_nui:${CallEvents.END_CALL}`, (data: any, cb: Function) => {
|
||||
const end = Date.now();
|
||||
animationService.endPhoneCall();
|
||||
emitNet(CallEvents.END_CALL, data.transmitterNumber, end);
|
||||
cb();
|
||||
});
|
||||
|
||||
onNet(CallEvents.WAS_ENDED, () => {
|
||||
callService.handleEndCall();
|
||||
animationService.endPhoneCall();
|
||||
});
|
||||
|
||||
|
||||
onNet(CallEvents.FETCH_CALLS, (calls: CallHistoryItem[]) => {
|
||||
callService.handleFetchCalls(calls);
|
||||
});
|
||||
|
||||
onNet(CallEvents.SEND_ALERT, (alert: IAlertProps) => {
|
||||
callService.handleSendAlert(alert);
|
||||
});
|
||||
@@ -0,0 +1,108 @@
|
||||
import { IAlertProps } from "../../../typings/alerts";
|
||||
import { CallEvents, CallHistoryItem, CallRejectReasons } from "../../../typings/call";
|
||||
|
||||
const exp = (global as any).exports;
|
||||
|
||||
export class CallService {
|
||||
private currentCall: number = 0;
|
||||
|
||||
|
||||
isInCall() {
|
||||
return this.currentCall !== 0;
|
||||
}
|
||||
|
||||
openCallModal(show: boolean) {
|
||||
SendNUIMessage({
|
||||
app: 'CALL',
|
||||
method: CallEvents.SET_CALL_MODAL,
|
||||
data: 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,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
handleStartCall(transmitter: string, receiver: string, isTransmitter: boolean) {
|
||||
// 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({
|
||||
app: 'CALL',
|
||||
method: CallEvents.SET_CALLER,
|
||||
data: {
|
||||
active: true,
|
||||
transmitter: transmitter,
|
||||
receiver: receiver,
|
||||
isTransmitter: isTransmitter,
|
||||
accepted: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
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,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
handleEndCall() {
|
||||
this.currentCall = 0
|
||||
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,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
handleSendAlert(alert: IAlertProps) {
|
||||
SendNUIMessage({
|
||||
app: 'DIALER',
|
||||
method: CallEvents.SEND_ALERT,
|
||||
data: alert,
|
||||
});
|
||||
}
|
||||
|
||||
handleFetchCalls(calls: CallHistoryItem[]) {
|
||||
SendNUIMessage({
|
||||
app: 'DIALER',
|
||||
method: CallEvents.SET_CALL_HISTORY,
|
||||
data: calls,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user