Skip to content

Commit

Permalink
Send RTMP messages to client handler
Browse files Browse the repository at this point in the history
Add optional callback `handle_rtmp_message/2` to ClientHandlerBehaviour
  • Loading branch information
lastcanal committed Oct 29, 2024
1 parent 39f8186 commit f150283
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/membrane_rtmp_plugin/rtmp_server/client_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,19 @@ defmodule Membrane.RTMPServer.ClientHandler do
"""
@callback handle_connection_closed(state :: state()) :: state()

@doc """
The optional callback invoked when the client handler receives a RTMP message.
"""
@callback handle_rtmp_message(msg :: term(), state()) :: state()

@doc """
The callback invoked when the client handler receives a message
that is not recognized as an internal message of the client handler.
"""
@callback handle_info(msg :: term(), state()) :: state()

@optional_callbacks handle_rtmp_message: 2

@doc """
Makes the client handler ask client for the desired number of buffers
"""
Expand Down Expand Up @@ -185,6 +192,25 @@ defmodule Membrane.RTMPServer.ClientHandler do

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

state =
if state.handler
&& state.handler_state
&& Kernel.function_exported?(state.handler, :handle_rtmp_message, 2) do

new_handler_state =
Enum.reduce(messages, state.handler_state, fn
({%Membrane.RTMP.Header{}, message}, handler_state) when is_map(message) ->
state.handler.handle_rtmp_message(message, handler_state)
(message, handler_state) when is_map(message) ->
state.handler.handle_rtmp_message(message, handler_state)
(_, handler_state) -> handler_state
end)

%{state | handler_state: new_handler_state}
else
state
end

request_data(state)

{:noreply,
Expand Down

0 comments on commit f150283

Please sign in to comment.