@@ -28,15 +28,16 @@ defmodule Membrane.RTSP.Server do
2828
2929 alias __MODULE__ . Conn
3030
31- @ type server_config :: [
32- handler: module ( ) ,
33- name: term ( ) ,
34- port: :inet . port_number ( ) ,
35- address: :inet . ip_address ( ) ,
36- udp_rtp_port: :inet . port_number ( ) ,
37- udp_rtcp_port: :inet . port_number ( ) ,
38- session_timeout: non_neg_integer ( )
39- ]
31+ @ type server_option ::
32+ { :handler , module ( ) }
33+ | { :handler_config , term ( ) }
34+ | { :name , term ( ) }
35+ | { :port , :inet . port_number ( ) }
36+ | { :address , :inet . ip_address ( ) }
37+ | { :udp_rtp_port , :inet . port_number ( ) }
38+ | { :udp_rtcp_port , :inet . port_number ( ) }
39+ | { :session_timeout , non_neg_integer ( ) }
40+ @ type server_config :: [ server_option ( ) ]
4041
4142 @ doc """
4243 Start an instance of the RTSP server.
@@ -54,6 +55,7 @@ defmodule Membrane.RTSP.Server do
5455 ## Options
5556 - `handler` - An implementation of the behaviour `Membrane.RTSP.Server.Handler`. Refer to the module
5657 documentation for more details. This field is required.
58+ - `handler_config` - Term that will be passed as an argument to `init/1` callback of the handler. Defaults to `nil`.
5759 - `name` - Used for name registration of the server. Defaults to `nil`.
5860 - `port` - The port where the server will listen for client connections. Defaults to: `554`
5961 - `address` - Specify the address where the `tcp` and `udp` sockets will be bound. Defaults to `:any`.
@@ -115,6 +117,7 @@ defmodule Membrane.RTSP.Server do
115117 state = % {
116118 socket: socket ,
117119 handler: config [ :handler ] ,
120+ handler_state: config [ :handler ] . init ( config [ :handler_config ] ) ,
118121 udp_rtp_socket: udp_rtp_socket ,
119122 udp_rtcp_socket: udp_rtcp_socket ,
120123 client_conns: % { } ,
@@ -136,7 +139,7 @@ defmodule Membrane.RTSP.Server do
136139 def handle_info ( { :new_connection , client_socket } , state ) do
137140 child_state =
138141 state
139- |> Map . take ( [ :handler , :session_timeout , :udp_rtp_socket , :udp_rtcp_socket ] )
142+ |> Map . take ( [ :handler , :handler_state , : session_timeout, :udp_rtp_socket , :udp_rtcp_socket ] )
140143 |> Map . put ( :socket , client_socket )
141144
142145 case Conn . start ( child_state ) do
0 commit comments