# `Membrane.RTMPServer.ClientHandler`
[🔗](https://github.com/membraneframework/membrane_rtmp_plugin/blob/v0.29.5/lib/membrane_rtmp_plugin/rtmp_server/client_handler.ex#L1)

A behaviour describing the actions that might be taken by the client
handler in response to different events.

# `state`

```elixir
@type state() :: any()
```

Type representing the user defined state of the client handler.

# `t`

```elixir
@type t() :: module()
```

A type representing a module which implements `Membrane.RTMPServer.ClientHandler` behaviour.

# `handle_connection_closed`

```elixir
@callback handle_connection_closed(state :: state()) :: state()
```

Callback invoked when the socket connection is terminated. In normal
conditions, `handle_delete_stream` is called before this one. If delete_stream
is not called and connection_closed is, it might just mean that the
connection was lost (for instance when TCP socket is closed unexpectedly).

It is up to the users to determined how to handle it in their case.

# `handle_data_available`

```elixir
@callback handle_data_available(payload :: binary(), state :: state()) :: state()
```

The callback invoked when new piece of data is received from a given client.

# `handle_delete_stream`

```elixir
@callback handle_delete_stream(state :: state()) :: state()
```

Callback invoked when the RMTP stream is finished.

# `handle_info`

```elixir
@callback handle_info(msg :: term(), state()) :: state()
```

The callback invoked when the client handler receives a message
that is not recognized as an internal message of the client handler.

# `handle_init`

```elixir
@callback handle_init(any()) :: state()
```

The callback invoked once the client handler is created.
It should return the initial state of the client handler.

# `handle_metadata`
*optional* 

```elixir
@callback handle_metadata(
  {:metadata_message,
   Membrane.RTMP.Messages.OnMetaData.t()
   | Membrane.RTMP.Messages.SetDataFrame.t()},
  state()
) :: state()
```

The optional callback invoked when the client handler receives RTMP message with
metadata information (just like a resolution or a framerate of a video stream).
The following messages are considered the ones that contain metadata:
1) OnMetaData
2) SetDataFrame

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `demand_data`

```elixir
@spec demand_data(pid(), non_neg_integer()) :: :ok
```

Makes the client handler ask client for the desired number of buffers

---

*Consult [api-reference.md](api-reference.md) for complete listing*
