diff --git a/fivem_script/tokovoip_script/nui/script.js b/fivem_script/tokovoip_script/nui/script.js index e5c6258..d06c760 100644 --- a/fivem_script/tokovoip_script/nui/script.js +++ b/fivem_script/tokovoip_script/nui/script.js @@ -180,14 +180,13 @@ function receivedClientCall (event) { // Start with a status OK by default, and change the status if issues are encountered voipStatus = OK; - if (eventName == 'updateConfig') { updateConfig(payload); } else if (voip) { if (eventName == 'initializeSocket') { + $.post(`http://${scriptName}/nuiLoaded`) init(payload); - } else if (eventName == 'updateTokovoipInfo') { if (connected) updateTokovoipInfo(payload, 1); diff --git a/fivem_script/tokovoip_script/src/c_main.lua b/fivem_script/tokovoip_script/src/c_main.lua index 550d423..906501c 100644 --- a/fivem_script/tokovoip_script/src/c_main.lua +++ b/fivem_script/tokovoip_script/src/c_main.lua @@ -22,6 +22,7 @@ local animStates = {} local displayingPluginScreen = false; local HeadBone = 0x796e; local radioVolume = 0; +local nuiLoaded = false -------------------------------------------------------------------------------- -- Plugin functions @@ -256,7 +257,10 @@ AddEventHandler("initializeVoip", function() print("TokoVoip: FiveM Server ID is " .. voip.fivemServerId); voip.processFunction = clientProcessing; -- Link the processing function that will be looped - voip:initialize(); -- Initialize the websocket and controls + while not nuiLoaded do + voip:initialize(); -- Initialize the websocket and controls + Citizen.Wait(5000) + end voip:loop(); -- Start TokoVoip's loop end); @@ -406,6 +410,12 @@ AddEventHandler("updateVoipTargetPed", function(newTargetPed, useLocal) useLocalPed = useLocal end) +-- Used to prevent bad nui loading +RegisterNUICallback("nuiLoaded", function(data, cb) + nuiLoaded = true + cb("ok") +end) + -- Make exports available on first tick exports("addPlayerToRadio", addPlayerToRadio); exports("removePlayerFromRadio", removePlayerFromRadio); diff --git a/ws_server/index.js b/ws_server/index.js index 2a1f575..8e408fd 100644 --- a/ws_server/index.js +++ b/ws_server/index.js @@ -98,12 +98,12 @@ app.get('/playerbyip', (req, res) => { return res.status(204).send(); }); -app.get('getmyip', (req, res) => { +app.get('/getmyip', (req, res) => { const ip = (lodash.get(req, `headers.['x-forwarded-for']`) || lodash.get(req, `headers.['x-real-ip']`) || lodash.get(req, 'connection.remoteAddress')).replace('::ffff:', ''); res.send(ip); }); -http.on('upgrade', (req, socket) => { +http.on('/upgrade', (req, socket) => { if (!req._query || !req._query.from) return socket.destroy(); if (req._query.from === 'ts3' && !req._query.uuid) return socket.destroy(); });