feat: integrate Medal.tv globally

This commit is contained in:
Ihsan
2026-07-18 14:42:02 +05:30
parent 116d045b98
commit e7788b2bb4
6 changed files with 92 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
Config = {}
---@class MedalClipOptions
---@field duration integer
---@field captureDelayMs integer
---@field alertType 'Default'|'Disabled'|'SoundOnly'|'OverlayOnly'
---@class MedalConfig
---@field enabled boolean
---@field publicKey string
---@field eventName string
---@field clipOptions MedalClipOptions
---@type MedalConfig
Config.Medal = {
enabled = true,
publicKey = 'pub_82qkpMKV77AkpqLSgWsxLlDyfzpPI7Vw',
eventName = 'Death',
clipOptions = {
duration = 30,
captureDelayMs = 0,
alertType = 'Default'
}
}
+5
View File
@@ -8,13 +8,18 @@ author 'ESX Team'
version '0.01'
description 'Official ESX library'
ui_page 'html/medal.html'
files {
'imports.lua',
'imports/**/client.lua',
'imports/**/shared.lua',
'html/medal.html',
'html/medal.js',
}
shared_scripts {
'config.lua',
'resource/init.lua',
'resource/**/shared.lua',
}
+10
View File
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; connect-src http://localhost:12665 http://127.0.0.1:12665">
</head>
<body>
<script src="medal.js"></script>
</body>
</html>
+13
View File
@@ -0,0 +1,13 @@
window.addEventListener('message', function (event) {
var data = event.data;
if (!data || data.action !== 'medalClip') return;
fetch('http://localhost:12665/api/v1/event/invoke', {
method: 'POST',
headers: {
'publicKey': data.publicKey,
'Content-Type': 'application/json'
},
body: JSON.stringify(data.payload)
}).catch(function () {});
});
+18
View File
@@ -0,0 +1,18 @@
local medal = {}
function medal.getConfig()
return exports['esx_lib']:getMedalConfig()
end
function medal.triggerClip(publicKey, eventName, clipOptions)
local cfg = medal.getConfig()
if not cfg or not cfg.enabled then return end
exports['esx_lib']:triggerMedalClip(
publicKey or cfg.publicKey,
eventName or cfg.eventName,
clipOptions or cfg.clipOptions
)
end
return medal
+22
View File
@@ -0,0 +1,22 @@
xLib.getMedalConfig = function()
return Config.Medal
end
xLib.triggerMedalClip = function(publicKey, eventName, clipOptions)
if not publicKey or publicKey == '' then return end
SendNUIMessage({
action = 'medalClip',
publicKey = publicKey,
payload = {
eventId = ('esx-clip-%s-%s'):format(GetPlayerServerId(PlayerId()), GetGameTimer()),
eventName = eventName or 'Event',
triggerActions = { 'SaveClip' },
clipOptions = clipOptions or {
duration = 30,
captureDelayMs = 0,
alertType = 'Default'
}
}
})
end