Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
infinite loop fixed
Browse files Browse the repository at this point in the history
bartkrak committed Jun 14, 2024
1 parent dd06232 commit 4cc62b6
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/source_with_standalone_server.exs
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ Logger.configure([{:level, :info}])

# Subscribe to receive client handler that connected to the
# server with given app id and stream key
# :ok = Membrane.RTMP.Server.subscribe(server, "app", "stream_key")
:ok = Membrane.RTMP.Server.subscribe(server, "app", "stream_key")

# Wait for the client handler
client_handler =
6 changes: 1 addition & 5 deletions lib/membrane_rtmp_plugin/rtmp_server.ex
Original file line number Diff line number Diff line change
@@ -111,10 +111,9 @@ defmodule Membrane.RTMP.Server do

@impl true
def handle_info({:client_register_attempt, app, stream_key, client_handler_pid}, state) do
IO.inspect("handle_info :client_register_attempt #{app} #{stream_key}")
IO.inspect("rtmp_server.ex handle_info :client_register_attempt #{app} #{stream_key}")
# check if anyone is subscribed to app and stream_key
if state.subscriptions[{app, stream_key}] != nil do
IO.inspect("sub exist")
# respond to client handler that subscription exist
send(client_handler_pid, :sub_exists)
end
@@ -132,9 +131,6 @@ defmodule Membrane.RTMP.Server do
defp maybe_send_subscription(app, stream_key, state) do
# IO.inspect(state, label: "maybe_send_subscription")
if state.subscriptions[{app, stream_key}] != nil and state.mapping[{app, stream_key}] != nil do

# send(state.mapping[{app, stream_key}], :subscribed)

send(
state.subscriptions[{app, stream_key}],
{:client_handler, state.mapping[{app, stream_key}]}
10 changes: 7 additions & 3 deletions lib/membrane_rtmp_plugin/rtmp_server/client_handler.ex
Original file line number Diff line number Diff line change
@@ -38,7 +38,8 @@ defmodule Membrane.RTMP.Server.ClientHandler do
stream_key: nil,
server: opts.server,
buffers_demanded: 0,
published?: false
published?: false,
client_register_attempt_made?: false
}}
end

@@ -104,11 +105,14 @@ defmodule Membrane.RTMP.Server.ClientHandler do
{message_handler_state, events} =
MessageHandler.handle_client_messages(messages, state.message_handler_state)

if message_handler_state.publish_msg != nil do
state = if message_handler_state.publish_msg != nil and not state.client_register_attempt_made? do
%{publish_msg: %Membrane.RTMP.Messages.Publish{stream_key: stream_key}} = message_handler_state
IO.inspect(stream_key, label: "stream_key")
IO.inspect(stream_key, label: "client_handler.ex stream_key")
# ask server if someone is subscribed to this
send(state.server, {:client_register_attempt, state.app, stream_key, self()})
%{state | client_register_attempt_made?: true}
else
state
end

state = Enum.reduce(events, state, &handle_event/2)

0 comments on commit 4cc62b6

Please sign in to comment.