- Complete Flask web application for digital signage management - Streaming channels for organized content delivery - User authentication with admin/user roles - Bootstrap UI with light/dark theme support - File upload and management system - Activity logging and monitoring - API endpoints for Info-Beamer device integration - Database models for channels, content, users, and activity logs
106 lines
3.3 KiB
Lua
106 lines
3.3 KiB
Lua
-- Info-Beamer script with scheduling support
|
|
gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)
|
|
|
|
local json = require "json"
|
|
local font = resource.load_font "roboto.ttf"
|
|
|
|
local server_url = CONFIG.server_url or "http://localhost:5000"
|
|
local refresh_interval = CONFIG.refresh_interval or 60
|
|
local default_duration = CONFIG.default_duration or 10
|
|
|
|
local playlist = {}
|
|
local current_item = 1
|
|
local item_start_time = 0
|
|
local last_update = 0
|
|
local schedule_info = {}
|
|
|
|
function update_playlist()
|
|
-- Fetch scheduled playlist from server
|
|
local url = server_url .. "/api/playlist"
|
|
util.post_and_wait(url, "", function(response)
|
|
if response.success then
|
|
local data = json.decode(response.content)
|
|
if data and data.items then
|
|
playlist = data.items
|
|
print("Updated playlist: " .. #playlist .. " items")
|
|
|
|
-- Load assets
|
|
for i, item in ipairs(playlist) do
|
|
if item.type == "image" then
|
|
item.resource = resource.load_image(server_url .. "/uploads/" .. item.asset)
|
|
elseif item.type == "video" then
|
|
item.resource = resource.load_video(server_url .. "/uploads/" .. item.asset)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
|
|
-- Also fetch schedule information
|
|
local schedule_url = server_url .. "/api/schedule"
|
|
util.post_and_wait(schedule_url, "", function(response)
|
|
if response.success then
|
|
schedule_info = json.decode(response.content) or {}
|
|
end
|
|
end)
|
|
|
|
last_update = sys.now()
|
|
end
|
|
|
|
function node.render()
|
|
-- Update playlist periodically
|
|
if sys.now() - last_update > refresh_interval then
|
|
update_playlist()
|
|
end
|
|
|
|
-- If no playlist items, show waiting message
|
|
if #playlist == 0 then
|
|
font:write(100, 100, "Waiting for scheduled content...", 50, 1, 1, 1, 1)
|
|
font:write(100, 200, "Server: " .. server_url, 30, 0.7, 0.7, 0.7, 1)
|
|
return
|
|
end
|
|
|
|
local item = playlist[current_item]
|
|
if not item then
|
|
current_item = 1
|
|
item = playlist[current_item]
|
|
if not item then return end
|
|
end
|
|
|
|
local duration = item.duration or default_duration
|
|
|
|
-- Check if it's time to move to next item
|
|
if sys.now() - item_start_time > duration then
|
|
current_item = current_item + 1
|
|
if current_item > #playlist then
|
|
current_item = 1
|
|
end
|
|
item_start_time = sys.now()
|
|
item = playlist[current_item]
|
|
end
|
|
|
|
-- Display current item
|
|
if item and item.resource then
|
|
if item.type == "image" then
|
|
item.resource:draw(0, 0, WIDTH, HEIGHT)
|
|
elseif item.type == "video" then
|
|
item.resource:draw(0, 0, WIDTH, HEIGHT)
|
|
end
|
|
|
|
-- Show schedule info overlay (optional)
|
|
if item.schedule_name then
|
|
font:write(10, HEIGHT - 60, "Schedule: " .. item.schedule_name, 20, 1, 1, 1, 0.8)
|
|
if item.priority then
|
|
font:write(10, HEIGHT - 30, "Priority: " .. item.priority, 20, 1, 1, 1, 0.8)
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Show current time
|
|
local current_time = schedule_info.current_time or "00:00"
|
|
font:write(WIDTH - 100, 20, current_time, 24, 1, 1, 1, 0.9)
|
|
end
|
|
|
|
-- Initial load
|
|
update_playlist()
|