mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 00:01:20 +00:00
Merge pull request #1803 from rwixy/medal-lib
feat: integrate Medal.tv globally
This commit is contained in:
@@ -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'
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -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 () {});
|
||||
});
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user