From 458839488e908b474d590d4db13776e54f34702f Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 15 Mar 2021 10:53:02 +0100 Subject: [PATCH] tweak(resources): use 'custom appMessageEvent' --- resources/client/cl_contacts.ts | 17 ++--------- resources/client/cl_main.ts | 50 +++++---------------------------- resources/client/cl_photo.ts | 28 +++--------------- resources/client/cl_sellout.ts | 17 ++--------- 4 files changed, 17 insertions(+), 95 deletions(-) diff --git a/resources/client/cl_contacts.ts b/resources/client/cl_contacts.ts index f3fcca5..943bd50 100644 --- a/resources/client/cl_contacts.ts +++ b/resources/client/cl_contacts.ts @@ -1,13 +1,8 @@ import events from '../utils/events'; +import { sendContactsEvent } from '../utils/messages'; onNet(events.CONTACTS_SEND_CONTACTS, (contacts: any) => { - SendNuiMessage( - JSON.stringify({ - app: 'CONTACTS', - method: 'setContacts', - data: contacts, - }), - ); + sendContactsEvent('setContacts', contacts); }); RegisterNuiCallbackType(events.CONTACTS_ADD_CONTACT); @@ -41,11 +36,5 @@ onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => { }); onNet(events.CONTACTS_ACTION_RESULT, (alert: any) => { - SendNuiMessage( - JSON.stringify({ - app: 'CONTACTS', - method: 'setAlert', - data: alert, - }), - ); + sendContactsEvent('setAlert', alert); }); diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index d68139c..0d26289 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -1,5 +1,6 @@ import config from '../utils/config'; import events from '../utils/events'; +import { sendMessage } from '../utils/messages'; import { phoneCloseAnim, phoneOpenAnim, removePhoneProp } from './functions'; let isPhoneOpen = false; @@ -15,13 +16,7 @@ function fetchOnInitialize() { emitNet(events.CONTACTS_GET_CONTACTS); emitNet(events.MESSAGES_FETCH_MESSAGE_GROUPS); emitNet(events.TWITTER_GET_OR_CREATE_PROFILE); - SendNuiMessage( - JSON.stringify({ - app: 'PHONE', - method: 'setPhoneReady', - data: isPhoneReady, - }), - ); + sendMessage('PHONE', 'setPhoneReady', isPhoneReady); } RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1'); @@ -37,26 +32,13 @@ const showPhone = async (): Promise => { await phoneOpenAnim(); // Animation starts before the phone is open emitNet('phone:getCredentials'); SetCursorLocation(0.9, 0.922); //Experimental - SendNuiMessage( - JSON.stringify({ - app: 'PHONE', - method: 'setVisibility', - data: true, - }), - ); + sendMessage('PHONE', 'setVisibility', true); SetNuiFocus(true, true); }; const hidePhone = async (): Promise => { isPhoneOpen = false; - SendNuiMessage( - //Hides phone - JSON.stringify({ - app: 'PHONE', - method: 'setVisibility', - data: false, - }), - ); + sendMessage('PHONE', 'setVisibility', false); await phoneCloseAnim(); SetNuiFocus(false, false); }; @@ -79,13 +61,7 @@ RegisterCommand( 'phone:restart', async () => { await hidePhone(); - SendNuiMessage( - JSON.stringify({ - app: 'PHONE', - method: 'startRestart', - data: {}, - }), - ); + sendMessage('PHONE', 'phoneRestart', {}); }, false, ); @@ -115,13 +91,7 @@ onNet(events.PLAYER_IS_READY, fetchOnInitialize); AddEventHandler('onResourceStop', function (resource: string) { if (resource === GetCurrentResourceName()) { - SendNuiMessage( - JSON.stringify({ - app: 'PHONE', - method: 'setVisibility', - data: false, - }), - ); + sendMessage('PHONE', 'setVisibility', 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. @@ -129,13 +99,7 @@ AddEventHandler('onResourceStop', function (resource: string) { }); onNet('phone:sendCredentials', (number: string) => { - SendNuiMessage( - JSON.stringify({ - app: 'SIMCARD', - method: 'setNumber', - data: number, - }), - ); + sendMessage('SIMCARD', 'setNumber', number); }); // DO NOT CHANGE THIS EITHER, PLEASE - CHIP diff --git a/resources/client/cl_photo.ts b/resources/client/cl_photo.ts index 81a34c5..d9de44c 100644 --- a/resources/client/cl_photo.ts +++ b/resources/client/cl_photo.ts @@ -1,5 +1,6 @@ import events from '../utils/events'; import { Delay } from '../utils/fivem'; +import { sendMessage, sendCameraEvent } from '../utils/messages'; const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none'); const exp = (global as any).exports; @@ -8,26 +9,12 @@ let inCameraMode = false; function closePhoneTemp() { SetNuiFocus(false, false); - SendNuiMessage( - //Hides phone - JSON.stringify({ - app: 'PHONE', - method: 'setVisibility', - data: false, - }), - ); + sendMessage('PHONE', 'setVisibility', false); } function openPhoneTemp() { SetNuiFocus(true, true); - SendNuiMessage( - //Opens phone - JSON.stringify({ - app: 'PHONE', - method: 'setVisibility', - data: true, - }), - ); + sendMessage('PHONE', 'setVisibility', true); } function CellFrontCamActivate(activate: boolean) { @@ -89,14 +76,7 @@ const handleCameraExit = () => { }; onNet(events.CAMERA_SEND_PHOTOS, (photos: string[]) => { - // console.log(photos); - SendNuiMessage( - JSON.stringify({ - app: 'CAMERA', - method: 'setPhotos', - data: photos, - }), - ); + sendCameraEvent('setPhotos', photos); }); function takePhoto() { diff --git a/resources/client/cl_sellout.ts b/resources/client/cl_sellout.ts index 566a396..9b079c3 100644 --- a/resources/client/cl_sellout.ts +++ b/resources/client/cl_sellout.ts @@ -1,15 +1,10 @@ import events from '../utils/events'; import { MarketplaceListing } from '../../typings/marketplace'; import { IAlertProps } from '../../typings/alerts'; +import { sendMarketplaceEvent } from '../utils/messages'; onNet(events.SELLOUT_SEND_LISTING, (listing: MarketplaceListing) => { - SendNuiMessage( - JSON.stringify({ - app: 'SELLOUT', - method: 'setListings', - data: listing, - }), - ); + sendMarketplaceEvent('setListing', listing); }); RegisterNuiCallbackType(events.SELLOUT_ADD_LISTING); @@ -39,11 +34,5 @@ onNet(events.SELLOUT_DELETE_LISTING_SUCCESS, () => { }); onNet(events.SELLOUT_ACTION_RESULT, (alert: IAlertProps) => { - SendNuiMessage( - JSON.stringify({ - app: 'SELLOUT', - method: 'setAlert', - data: alert, - }), - ); + sendMarketplaceEvent('setAlert', alert); });