I\'m trying to implement a radio server in Elixir
One process is always working and reading a file (mp3) and publish to topic \":radio\", currently for test purpose when
After a quick look I think there are 2 things you should fix:
PlugTest
is a Plug
so call/2
should return conn
(that's not your issue though). It should also blocks while waiting for events (receive
):
def call(conn, _opts) do
conn = conn
|> send_chunked(200)
|> put_resp_content_type("audio/mpeg")
:ok = PubSub.subscribe(self(), :radio)
send_chunk_to_connection(conn)
end
In send_chunk_to_connection
you should do:
defp send_chunk_to_connection(conn) do
receive do
{:radio_data, data} ->
case chunk(conn, data) do
{:ok, conn} -> send_chunk_to_connection(conn)
{:error, err} -> IO.puts err; conn # do nothing, as something went wrong (client disconnection or something else...)
end
end
end