1
0
Fork 0
livestream-tools/icedreammusic/liquidsoap/stream_api.liq

40 lines
1.4 KiB
Plaintext

stream_api_port=21336
interactive.harbor(port=stream_api_port, uri="/interactive") # expose through stream API port
def setup_harbor_stream_api(s) =
def on_start(~protocol, ~data, ~headers, uri) =
s.start()
http.response(protocol=protocol, code=200, headers=[
("content-type","application/json"),
], data=json.stringify([]))
end
def on_stop(~protocol, ~data, ~headers, uri) =
s.stop()
http.response(protocol=protocol, code=200, headers=[
("content-type","application/json"),
], data=json.stringify([]))
end
def on_info(~protocol, ~data, ~headers, uri) =
data = [
("id", s.id()),
("last_metadata", json.stringify(s.last_metadata())),
("is_up", json.stringify(s.is_up())),
("is_started", json.stringify(s.is_started())),
("is_ready", json.stringify(s.is_ready())),
("is_active", json.stringify(s.is_active())),
]
http.response(protocol=protocol, code=200, headers=[
("content-type","application/json"),
], data=json.stringify(data))
end
harbor.http.register(port=stream_api_port, method="POST", "/streams/#{s.id()}/start", on_start)
harbor.http.register(port=stream_api_port, method="POST", "/streams/#{s.id()}/stop", on_stop)
harbor.http.register(port=stream_api_port, method="GET", "/streams/#{s.id()}", on_info)
s
end