Skip to content

Commit 90797bf

Browse files
authored
Notify receiver on client disconnection (#9)
1 parent 47233fb commit 90797bf

4 files changed

Lines changed: 11 additions & 3 deletions

File tree

lib/ex_rtmp/client.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ defmodule ExRTMP.Client do
157157

158158
@impl true
159159
def handle_info({:tcp_closed, _port}, state) do
160-
Logger.info("RTMP connection closed")
160+
send(state.receiver, {:disconnected, self()})
161161
{:noreply, State.reset(state)}
162162
end
163163

lib/ex_rtmp/server.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ defmodule ExRTMP.Server do
109109

110110
@impl true
111111
def handle_call(:stop, _from, state) do
112-
Process.exit(state.listener, :normal)
112+
Process.exit(state.listener, :kill)
113113
{:stop, :normal, :ok, state}
114114
end
115115

@@ -136,7 +136,7 @@ defmodule ExRTMP.Server do
136136
Logger.debug("New client connected")
137137

138138
{:ok, pid} =
139-
ClientSession.start(
139+
ClientSession.start_link(
140140
socket: client_socket,
141141
handler: state.handler,
142142
handler_options: state.handler_options,

lib/ex_rtmp/server/client_session.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ defmodule ExRTMP.Server.ClientSession do
5050
GenServer.start(__MODULE__, opts)
5151
end
5252

53+
@spec start_link(keyword()) :: GenServer.on_start()
54+
def start_link(opts) do
55+
GenServer.start_link(__MODULE__, opts)
56+
end
57+
5358
@doc """
5459
Sends video data to the client.
5560
"""

test/ex_rtmp/client_test.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ defmodule ExRTMP.ClientTest do
5959

6060
assert expected_access_units == collected_access_units
6161

62+
ExRTMP.Server.stop(server)
63+
assert_receive {:disconnected, ^pid}, 2000
64+
6265
Client.stop(pid)
6366
end
6467
end

0 commit comments

Comments
 (0)