Skip to content

Commit e8c9705

Browse files
authored
Handle send errors gracefully (#18)
1 parent 398cd80 commit e8c9705

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

lib/ex_rtmp/server/client_session.ex

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,18 @@ defmodule ExRTMP.Server.ClientSession do
116116

117117
@impl true
118118
def handle_cast({:video_data, timestamp, data}, state) do
119-
send_media(:video, state.socket, state.stream_id, timestamp, data)
120-
{:noreply, state}
119+
case send_media(:video, state.socket, state.stream_id, timestamp, data) do
120+
:ok -> {:noreply, state}
121+
{:error, reason} -> {:stop, reason, state}
122+
end
121123
end
122124

123125
@impl true
124126
def handle_cast({:audio_data, timestamp, data}, state) do
125-
send_media(:audio, state.socket, state.stream_id, timestamp, data)
126-
{:noreply, state}
127+
case send_media(:audio, state.socket, state.stream_id, timestamp, data) do
128+
:ok -> {:noreply, state}
129+
{:error, reason} -> {:stop, reason, state}
130+
end
127131
end
128132

129133
@impl true
@@ -385,7 +389,7 @@ defmodule ExRTMP.Server.ClientSession do
385389
payload: data
386390
}
387391

388-
:ok = :gen_tcp.send(socket, Message.serialize(message, chunk_stream_id: chunk_stream_id))
392+
:gen_tcp.send(socket, Message.serialize(message, chunk_stream_id: chunk_stream_id))
389393
end
390394

391395
defp send_messages(state, []), do: state

0 commit comments

Comments
 (0)