Skip to content
Snippets Groups Projects
Commit f8b007fa authored by Falk Rehse's avatar Falk Rehse
Browse files

Moved player and frontend to submodules

parent 63b8cd43
No related branches found
No related tags found
No related merge requests found
Pipeline #118089 failed
[submodule "cc-player"]
path = cc-player
url = git@gitlab.fachschaften.org:spoccify/spoccify-cc-player.git
[submodule "frontend"]
path = frontend
url = git@gitlab.fachschaften.org:spoccify/spoccify-frontend.git
Subproject commit 53617a52534ccd8795277408c0892bda190481f6
local speaker = peripheral.find("speaker")
local monitor = peripheral.find("monitor")
local args = {...}
tobool={ ["true"]=true, ["false"]=false }
local paused = false
if #args < 2 or #args > 3 then
error("audio-receiver <websocket_url> <authentication_token> [headless]")
end -- if
local headless = true
if #args == 3 then
headless = tobool[args[3]]
end -- if
function eprint(message)
if headless then
print(message)
else
term.redirect(term.native())
print(message)
term.redirect(monitor)
end -- if
end -- eprint
function resetMonitor()
term.redirect(monitor)
term.setBackgroundColour(colours.black)
term.clear()
monitor.setTextScale(0.5)
end --setupMonitor
function inputButton(x1, y1, x2, y2, colour_border, colour_normal, colour_pressed, button_id, togglebutton)
paintutils.drawBox(x1, y1, x2, y2, colour_border)
paintutils.drawFilledBox(x1 + 1, y1 + 1, x2 - 1, y2 - 1, colour_normal)
while true
do
local eventData = {os.pullEvent()}
local event = eventData[1]
if event == "monitor_touch" then
local x = eventData[3]
local y = eventData[4]
if x >= x1 and x <= x2 and y >= y1 and y <= y2
then
os.queueEvent("button_touch", button_id)
if not togglebutton then
paintutils.drawFilledBox(x1 + 1, y1 + 1, x2 - 1, y2 - 1, colour_pressed)
sleep(0.5)
paintutils.drawFilledBox(x1 + 1, y1 + 1, x2 - 1, y2 - 1, colour_normal)
end -- if
end -- if
end -- if
end -- while
end -- monitorInput
local function handle_websocket_audio()
eprint("Trying to connect to websocket server!")
local websocket, error = http.websocket(args[1])
if websocket == false then
eprint(error)
return
end -- if
websocket.send(args[2])
eprint("Connected to websocket server!")
while true do
data, binary = websocket.receive()
if (not binary) then
eprint(data)
break
end -- if
eprint("Playing Sample!")
buffer = {}
for i = 1, string.len(data) do
buffer[i] = string.byte(data, i) - 128
end -- for
if paused then
os.pullEvent("unpause")
end -- if
while not speaker.playAudio(buffer) do
os.pullEvent("speaker_audio_empty")
end -- while
websocket.send("next")
end -- while
eprint("Shutting down!")
os.pullEvent("speaker_audio_empty")
end -- handle_websocket_audio
local function handle_screen()
while true do
local event, button_id = os.pullEvent("button_touch")
if button_id == "play_pause" then
if paused then
eprint("Playing!")
paused = false
os.queueEvent("unpause")
paintutils.drawFilledBox(3 + 1, 2 + 1, 34 - 1, 12 - 1, colours.green)
else
eprint("Stopping!")
paused = true
-- speaker.stop()
paintutils.drawFilledBox(3 + 1, 2 + 1, 34 - 1, 12 - 1, colours.red)
end -- if
elseif button_id == "skip" then
eprint("Skipping!")
end -- if
end -- while
end -- handle_screen
local function button_play_pause()
inputButton(3, 2, 34, 12, colours.white, colours.green, colours.red, "play_pause", true)
end -- button_play_pause
local function button_skip()
inputButton(3, 14, 34, 23, colours.white, colours.yellow, colours.orange, "skip", false)
end -- button_skip
if headless then
eprint("Running headless!")
handle_websocket_audio()
else
eprint("Using 2x2 advanced monitor!")
resetMonitor()
parallel.waitForAny(handle_websocket_audio, handle_screen, button_play_pause, button_skip)
end -- if
eprint("Done!")
Subproject commit e9fda016e59626cd189f7b479838fd722d362550
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment