-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnode.lua
More file actions
72 lines (62 loc) · 1.7 KB
/
node.lua
File metadata and controls
72 lines (62 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)
node.alias "videowall"
local json = require 'json'
local raw = sys.get_ext "raw_video"
local player = (function()
local res, old_res, next_res, master
node.event("connect", function(new_master)
if master then node.client_disconnect(master) end
master = new_master
print("master connected")
end)
node.event("disconnect", function(client)
assert(client == master)
print("master disconnected")
master = nil
end)
-- {"cmd": "load", "filename": "optical.mp4"}
-- {"cmd": "start"}
node.event("input", function(pkt, client)
assert(client == master)
pkt = json.decode(pkt)
pp(pkt)
if pkt.cmd == "load" then
if next_res then next_res:dispose() end
next_res = raw.load_video{
file = pkt.filename,
audio = false, -- switch to true, if you want audio
paused = true
}
elseif pkt.cmd == "start" then
old_res = res
res = next_res
next_res = nil
res:start()
end
end)
local function send_state(state)
if master then
node.client_write(master, state)
end
end
local function tick()
if next_res then
send_state(next_res:state())
elseif res then
res:target(0, 0, NATIVE_WIDTH, NATIVE_HEIGHT)
send_state(res:state())
else
send_state("none")
end
if old_res then
old_res:dispose()
end
end
return {
tick = tick;
}
end)()
function node.render()
gl.clear(0,0,0,0)
player.tick()
end