diff --git a/__resource.lua b/__resource.lua index 9dd1a91b..2040c72a 100644 --- a/__resource.lua +++ b/__resource.lua @@ -33,6 +33,7 @@ client_scripts { 'client/common.lua', 'client/entityiter.lua', 'client/functions.lua', + 'client/wrapper.lua', 'client/main.lua' } @@ -46,6 +47,7 @@ files { 'html/css/app.css', 'html/js/mustache.min.js', + 'html/js/wrapper.js', 'html/js/app.js', 'html/fonts/pdown.ttf', diff --git a/client/wrapper.lua b/client/wrapper.lua new file mode 100644 index 00000000..9ac13dcf --- /dev/null +++ b/client/wrapper.lua @@ -0,0 +1,16 @@ +local Chunks = {} + +RegisterNUICallback('__chunk', function(data, cb) + + Chunks[data.id] = Chunks[data.id] or '' + Chunks[data.id] = Chunks[data.id] .. data.chunk + + if data['end'] then + local msg = json.decode(Chunks[data.id]) + TriggerEvent(GetCurrentResourceName() .. ':message:' .. data.__type, msg) + Chunks[data.id] = nil + end + + cb('') + +end) diff --git a/html/js/wrapper.js b/html/js/wrapper.js new file mode 100644 index 00000000..054e8d06 --- /dev/null +++ b/html/js/wrapper.js @@ -0,0 +1,42 @@ +(() => { + + let ESXWrapper = {}; + ESXWrapper.MessageSize = 1024; + ESXWrapper.messageId = 0; + + window.SendMessage = function(namespace, type, msg) { + + ESXWrapper.messageId = (ESXWrapper.messageId < 65535) ? ESXWrapper.messageId + 1 : 0; + const str = JSON.stringify(msg); + + for(let i=0; i