Feature/floating notifications calling and twitter (#112)

* Add floating notifications :O

* Add phone notifications and refactor calling ui

* This is unsafe

* Fix controls null check

* Remove go to alert

* Fix phone stuck after call

* Remove lazy mount for Phone

* Fix open/close cl_main

* Use effect for notification visibility

* Remove all alerts when phone closes

* Avoid re-render useNuiEvent

* It works now :c
This commit is contained in:
J Francisco Rader authored and GitHub committed 2021-02-23 13:19:10 -05:00
1 parent 4633146d40
commit f6d7a3dbe1
42 files changed
+869 -679

No files matched your search

+7 -3
View File
@@ -1,6 +1,6 @@
import events from '../utils/events';
import { ICall } from '../../phone/src/common/typings/call';
import {phoneCallStartAnim, phoneCallEndAnim} from './functions';
import { phoneCallStartAnim, phoneCallEndAnim } from './functions';
const exp = (global as any).exports;
@@ -21,6 +21,7 @@ onNet(
app: 'CALL',
method: 'setCaller',
data: {
active: true,
transmitter: transmitter,
receiver: receiver,
isTransmitter: isTransmitter,
@@ -41,12 +42,13 @@ onNet(
events.PHONE_CALL_WAS_ACCEPTED,
(channelId: number, currentCall: ICall, isTransmitter: boolean) => {
exp['mumble-voip'].SetCallChannel(channelId);
phoneCallStartAnim() // Trigger call animation only if the call was accepted.
phoneCallStartAnim(); // Trigger call animation only if the call was accepted.
SendNuiMessage(
JSON.stringify({
app: 'CALL',
method: 'setCaller',
data: {
active: true,
transmitter: currentCall.transmitter,
receiver: currentCall.receiver,
isTransmitter: isTransmitter,
@@ -75,13 +77,14 @@ onNet(events.PHONE_CALL_WAS_REJECTED, () => {
receiver: null,
isTransmitter: null,
accepted: false,
active: false,
},
})
);
});
onNet(events.PHONE_CALL_SEND_HANGUP_ANIM, () => {
phoneCallEndAnim()
phoneCallEndAnim();
});
RegisterNuiCallbackType(events.PHONE_END_CALL); // Fires when ending an ACTIVE call
@@ -104,6 +107,7 @@ onNet(events.PHONE_CALL_WAS_ENDED, () => {
receiver: null,
isTransmitter: null,
accepted: false,
active: false,
},
})
);
+36 -62
View File
@@ -1,51 +1,12 @@
import config from '../utils/config';
import events from '../utils/events';
import {phoneCloseAnim, phoneOpenAnim, removePhoneProp} from './functions';
import { phoneCloseAnim, phoneOpenAnim, removePhoneProp } from './functions';
let prop = 0;
let isPhoneOpen = false;
let propCreated = false;
let phoneModel = 'prop_amb_phone'; // Refered to in newphoneProp function. Requires custom phone being streamed.
/* * * * * * * * * * * * *
*
* Register Command and Keybinding
*
* * * * * * * * * * * * */
RegisterCommand(
'phone:close',
async (source: any, args: string[], raw: any) => {
await phoneCloseAnim();
SetNuiFocus(false, false);
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'setVisibility',
data: false,
})
);
},
false
);
RegisterCommand(
'phone',
async () => {
//-- Toggles Phone
await Phone();
},
false
);
RegisterCommand(
'phone:open',
async () => {
await Phone();
},
false
);
RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
/* * * * * * * * * * * * *
@@ -66,7 +27,6 @@ const showPhone = async (): Promise<void> => {
data: true,
})
);
sendPhoneConfig();
SetNuiFocus(true, true);
};
@@ -84,13 +44,36 @@ const hidePhone = async (): Promise<void> => {
SetNuiFocus(false, false);
};
const togglePhoneVisible = async (): Promise<void> => {
if (isPhoneOpen) {
/* * * * * * * * * * * * *
*
* Register Command and Keybinding
*
* * * * * * * * * * * * */
RegisterCommand(
'phone:close',
async () => {
await hidePhone();
} else {
},
false
);
RegisterCommand(
'phone',
async () => {
//-- Toggles Phone
await Phone();
},
false
);
RegisterCommand(
'phone:open',
async () => {
await showPhone();
}
};
},
false
);
/* * * * * * * * * * * * *
*
@@ -99,24 +82,17 @@ const togglePhoneVisible = async (): Promise<void> => {
* * * * * * * * * * * * */
async function Phone(): Promise<void> {
fetchOnInitialize()
fetchOnInitialize();
if (config.PhoneAsItem) {
// TODO: Do promise callback here
// const hasPhoneItem = await emitNetPromise('phone:hasPhoneItem')
// if (!hasPhoneItem) return
return await togglePhoneVisible();
}
await togglePhoneVisible();
}
function sendPhoneConfig() {
SendNuiMessage(
JSON.stringify({
app: 'PHONE',
method: 'phoneConfig',
data: config,
})
);
if (isPhoneOpen) {
await hidePhone();
} else {
await showPhone();
}
}
AddEventHandler('onResourceStop', function (resource: string) {
@@ -144,7 +120,6 @@ onNet('phone:sendCredentials', (number: string) => {
);
});
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
/* * * * * * * * * * * * *
@@ -157,7 +132,6 @@ function fetchOnInitialize() {
emitNet(events.CONTACTS_GET_CONTACTS);
}
RegisterNuiCallbackType(events.OPEN_APP_LISTINGS);
on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => {
emitNet(events.SELLOUT_FETCH_LISTING);
@@ -191,7 +165,7 @@ on(`__cfx_nui:${events.OPEN_APP_DAILER}`, (data: any, cb: Function) => {
RegisterNuiCallbackType('phone:close');
on(`__cfx_nui:phone:close`, async (data: any, cb: Function) => {
await Phone();
await hidePhone();
cb();
}); // Called for when the phone is closed via the UI.