# `RTMP.ControlMessages`
[🔗](https://github.com/Adeyeye93/rtmp/blob/v0.1.0/lib/rtmp/control_messages.ex#L1)

Protocol control messages (message types 1–6) and User Control events.

`parse/2` decodes an incoming control message payload; the builder
functions return `{type_id, payload}` for outgoing ones, which are sent on
chunk stream 2, message stream 0.

Set Chunk Size (1) and Abort (2) affect chunk framing and are applied by
`RTMP.ChunkStream` itself as soon as they arrive; `parse/2` still
understands them for completeness.

## User Control events

| Event               | Id | Payload                    |
|---------------------|----|----------------------------|
| Stream Begin        | 0  | stream id                  |
| Stream EOF          | 1  | stream id                  |
| Stream Dry          | 2  | stream id                  |
| Set Buffer Length   | 3  | stream id, buffer ms       |
| Stream Is Recorded  | 4  | stream id                  |
| Ping Request        | 6  | timestamp                  |
| Ping Response       | 7  | timestamp                  |

# `limit_type`

```elixir
@type limit_type() :: :hard | :soft | :dynamic
```

# `t`

```elixir
@type t() ::
  {:set_chunk_size, pos_integer()}
  | {:abort, non_neg_integer()}
  | {:acknowledgement, non_neg_integer()}
  | {:user_control, user_control_event()}
  | {:window_ack_size, non_neg_integer()}
  | {:set_peer_bandwidth, non_neg_integer(), limit_type()}
```

# `user_control_event`

```elixir
@type user_control_event() ::
  {:stream_begin, non_neg_integer()}
  | {:stream_eof, non_neg_integer()}
  | {:stream_dry, non_neg_integer()}
  | {:set_buffer_length, non_neg_integer(), non_neg_integer()}
  | {:stream_is_recorded, non_neg_integer()}
  | {:ping_request, non_neg_integer()}
  | {:ping_response, non_neg_integer()}
  | {:unknown, non_neg_integer(), binary()}
```

# `acknowledgement`

```elixir
@spec acknowledgement(non_neg_integer()) :: {byte(), binary()}
```

# `is_control`
*macro* 

True for message type ids 1–6.

# `parse`

```elixir
@spec parse(byte(), binary()) :: {:ok, t()} | {:error, term()}
```

Decodes a protocol control message payload.

# `ping_request`

```elixir
@spec ping_request(non_neg_integer()) :: {byte(), binary()}
```

# `ping_response`

```elixir
@spec ping_response(non_neg_integer()) :: {byte(), binary()}
```

# `set_chunk_size`

```elixir
@spec set_chunk_size(pos_integer()) :: {byte(), binary()}
```

# `set_peer_bandwidth`

```elixir
@spec set_peer_bandwidth(non_neg_integer(), limit_type()) :: {byte(), binary()}
```

# `stream_begin`

```elixir
@spec stream_begin(non_neg_integer()) :: {byte(), binary()}
```

# `stream_eof`

```elixir
@spec stream_eof(non_neg_integer()) :: {byte(), binary()}
```

# `window_ack_size`

```elixir
@spec window_ack_size(non_neg_integer()) :: {byte(), binary()}
```

---

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