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

RTMP command messages (`connect`, `createStream`, `publish`, ...) and data
messages (`@setDataFrame` / `onMetaData`).

A command message is a sequence of AMF0 values: the command name, a
transaction id, a command object (or null), then command-specific
arguments. `parse/2` decodes one into a `RTMP.Commands.Command`; the
builder functions return AMF0 payloads for the responses a server sends.

Message types 17 (AMF3 command) and 15 (AMF3 data) are accepted when their
body is the common "format byte 0x00, then AMF0" layout some clients use.
Real AMF3-encoded values are not supported.

The response shapes follow what Flash Media Server, nginx-rtmp and SRS
send, since that's what OBS and FFmpeg are tested against.

# `connect_rejected`

```elixir
@spec connect_rejected(number(), binary()) :: binary()
```

`_error` rejecting a `connect`.

# `connect_result`

```elixir
@spec connect_result(number(), number()) :: binary()
```

`_result` for a successful `connect`.

# `create_stream_result`

```elixir
@spec create_stream_result(number(), non_neg_integer()) :: binary()
```

`_result` for `createStream`, carrying the new message stream id.

# `error`

```elixir
@spec error(number(), binary(), binary()) :: binary()
```

A bare `_error` for a command the server won't perform.

# `is_command`
*macro* 

True for message type ids that carry commands (17, 20).

# `is_data`
*macro* 

True for message type ids that carry data messages (15, 18).

# `on_fc_publish`

```elixir
@spec on_fc_publish(binary()) :: binary()
```

`onFCPublish`, which some clients wait for after `FCPublish`.

# `on_status`

```elixir
@spec on_status(binary(), binary(), binary()) :: binary()
```

`onStatus` on a message stream, e.g.
`on_status("status", "NetStream.Publish.Start", "Publishing live.")`.

# `parse`

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

Decodes a command message payload (message type 17 or 20).

# `parse_data`

```elixir
@spec parse_data(byte(), binary()) ::
  {:ok, binary(), [RTMP.AMF0.value()]} | {:error, term()}
```

Decodes a data message payload (message type 15 or 18) into its name and
values, unwrapping `@setDataFrame`:

    @setDataFrame("onMetaData", {...})  ->  {:ok, "onMetaData", [%{...}]}
    onMetaData({...})                   ->  {:ok, "onMetaData", [%{...}]}

# `result`

```elixir
@spec result(number()) :: binary()
```

A bare `_result` (used for `releaseStream` and `FCPublish`).

---

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