diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index a80f7f0..3cd8a1e 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -33,6 +33,7 @@ import WindowSnackbar from './ui/components/WindowSnackbar'; import { usePhone } from './os/phone/hooks/usePhone'; import { useTranslation } from 'react-i18next'; import { useSnackbar } from './ui/hooks/useSnackbar'; +import { PhoneEvents } from '../../typings/phone'; function Phone() { const { t, i18n } = useTranslation(); @@ -154,12 +155,12 @@ export default Phone; InjectDebugData([ { app: 'PHONE', - method: 'setVisibility', + method: PhoneEvents.SET_VISIBILITY, data: true, }, { app: 'PHONE', - method: 'setPhoneReady', + method: PhoneEvents.SET_PHONE_READY, data: true, }, ]); diff --git a/phone/src/os/phone/hooks/usePhoneService.ts b/phone/src/os/phone/hooks/usePhoneService.ts index 0500dfe..48cfcb9 100644 --- a/phone/src/os/phone/hooks/usePhoneService.ts +++ b/phone/src/os/phone/hooks/usePhoneService.ts @@ -1,14 +1,15 @@ import { useSetRecoilState } from 'recoil'; import { phoneState } from './state'; import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent'; +import { PhoneEvents } from '../../../../../typings/phone'; export const usePhoneService = () => { const setVisibility = useSetRecoilState(phoneState.visibility); const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig); const setPhoneReady = useSetRecoilState(phoneState.phoneReady); const setPhoneTime = useSetRecoilState(phoneState.phoneTime); - useNuiEvent('PHONE', 'setVisibility', setVisibility); - useNuiEvent('PHONE', 'setPhoneReady', setPhoneReady); - useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig); - useNuiEvent('PHONE', 'setTime', setPhoneTime); + useNuiEvent('PHONE', PhoneEvents.SET_VISIBILITY, setVisibility); + useNuiEvent('PHONE', PhoneEvents.SET_PHONE_READY, setPhoneReady); + useNuiEvent('PHONE', PhoneEvents.SET_CONFIG, setPhoneConfig); + useNuiEvent('PHONE', PhoneEvents.SET_TIME, setPhoneTime); }; diff --git a/phone/src/os/simcard/hooks/useSimcardService.ts b/phone/src/os/simcard/hooks/useSimcardService.ts index 32caba9..147f010 100644 --- a/phone/src/os/simcard/hooks/useSimcardService.ts +++ b/phone/src/os/simcard/hooks/useSimcardService.ts @@ -3,6 +3,7 @@ import { useSetRecoilState } from 'recoil'; import { simcardState } from './state'; import { useSimcard } from './useSimcard'; import InjectDebugData from '../../debug/InjectDebugData'; +import { PhoneEvents } from '../../../../../typings/phone'; InjectDebugData([ { @@ -14,6 +15,6 @@ InjectDebugData([ export const useSimcardService = () => { const setNumber = useSetRecoilState(simcardState.number); - useNuiEvent('SIMCARD', 'setNumber', setNumber); + useNuiEvent('SIMCARD', PhoneEvents.SET_NUMBER, setNumber); return useSimcard(); }; diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index 5d1080a..58b15ed 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -25,8 +25,8 @@ function fetchOnInitialize() { emitNet(ContactEvents.GET_CONTACTS); emitNet(MessageEvents.FETCH_MESSAGE_GROUPS); emitNet(TwitterEvents.GET_OR_CREATE_PROFILE); - sendMessage('PHONE', 'setPhoneReady', isPhoneReady); - sendMessage('PHONE', 'phoneConfig', config); + sendMessage('PHONE', PhoneEvents.SET_PHONE_READY, isPhoneReady); + sendMessage('PHONE', PhoneEvents.SET_CONFIG, config); } RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1'); @@ -55,14 +55,14 @@ const showPhone = async (): Promise => { await phoneOpenAnim(); // Animation starts before the phone is open emitNet('phone:getCredentials'); SetCursorLocation(0.9, 0.922); //Experimental - sendMessage('PHONE', 'setVisibility', true); - sendMessage('PHONE', 'setTime', time); + sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, true); + sendMessage('PHONE', PhoneEvents.SET_TIME, time); SetNuiFocus(true, true); }; const hidePhone = async (): Promise => { isPhoneOpen = false; - sendMessage('PHONE', 'setVisibility', false); + sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false); await phoneCloseAnim(); SetNuiFocus(false, false); }; @@ -115,15 +115,15 @@ onNet(PhoneEvents.PLAYER_IS_READY, fetchOnInitialize); AddEventHandler('onResourceStop', function (resource: string) { if (resource === GetCurrentResourceName()) { - sendMessage('PHONE', 'setVisibility', false); + sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false); SetNuiFocus(false, false); removePhoneProp(); //Deletes the phone incase it was attached. ClearPedTasks(PlayerPedId()); //Leave here until launch as it'll fix any stuck animations. } }); -onNet('phone:sendCredentials', (number: string) => { - sendMessage('SIMCARD', 'setNumber', number); +onNet(PhoneEvents.SEND_CREDENTIALS, (number: string) => { + sendMessage('SIMCARD', PhoneEvents.SET_NUMBER, number); }); // DO NOT CHANGE THIS EITHER, PLEASE - CHIP diff --git a/resources/client/cl_photo.ts b/resources/client/cl_photo.ts index dc9f8b9..64dbf99 100644 --- a/resources/client/cl_photo.ts +++ b/resources/client/cl_photo.ts @@ -1,6 +1,7 @@ import { PhotoEvents } from '../../typings/photo'; import { Delay } from '../utils/fivem'; import { sendMessage, sendCameraEvent } from '../utils/messages'; +import { PhoneEvents } from '../../typings/phone'; const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none'); const exp = (global as any).exports; @@ -9,12 +10,12 @@ let inCameraMode = false; function closePhoneTemp() { SetNuiFocus(false, false); - sendMessage('PHONE', 'setVisibility', false); + sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false); } function openPhoneTemp() { SetNuiFocus(true, true); - sendMessage('PHONE', 'setVisibility', true); + sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, true); } function CellFrontCamActivate(activate: boolean) { diff --git a/resources/server/sv_main.ts b/resources/server/sv_main.ts index 8f50896..80818ac 100644 --- a/resources/server/sv_main.ts +++ b/resources/server/sv_main.ts @@ -1,6 +1,7 @@ import { pool } from './db'; import { getIdentifier, getSource } from './functions'; import { mainLogger } from './sv_logger'; +import { PhoneEvents } from '../../typings/phone'; interface Credentials { phone_number: string; @@ -19,7 +20,7 @@ onNet('phone:getCredentials', async () => { try { const identifier = getIdentifier(_source); const number = await getCredentials(identifier); - emitNet('phone:sendCredentials', _source, number); + emitNet(PhoneEvents.SEND_CREDENTIALS, _source, number); } catch (e) { mainLogger.error(`Failed to get a number, ${e.message}`, { source: _source, diff --git a/typings/phone.ts b/typings/phone.ts index a547dfa..45d7cb4 100644 --- a/typings/phone.ts +++ b/typings/phone.ts @@ -11,5 +11,11 @@ export enum PhoneEvents { OPEN_PHONE = 'npwd:open', CLOSE_PHONE = 'npwd:close', SET_ALERT = 'npwd:setAlert', + SET_VISIBILITY = 'npwd:setVisibility', SET_NOTIFICATION = 'npwd:setNotification', + SET_NUMBER = 'npwd:setNumber', + SET_PHONE_READY = 'npwd:phoneReady', + SET_CONFIG = 'npwd:setPhoneConfig', + SET_TIME = 'npwd:setGameTime', + SEND_CREDENTIALS = 'npwd:sendCredentials', }