RTMP.Commands (rtmp v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

_error rejecting a connect.

_result for a successful connect.

_result for createStream, carrying the new message stream id.

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

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

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

onFCPublish, which some clients wait for after FCPublish.

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

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

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

A bare _result (used for releaseStream and FCPublish).

Functions

connect_rejected(transaction_id, description)

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

_error rejecting a connect.

connect_result(transaction_id, object_encoding \\ 0)

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

_result for a successful connect.

create_stream_result(transaction_id, stream_id)

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

_result for createStream, carrying the new message stream id.

error(transaction_id, code, description)

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

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

is_command(type_id)

(macro)

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

is_data(type_id)

(macro)

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

on_fc_publish(stream_key)

@spec on_fc_publish(binary()) :: binary()

onFCPublish, which some clients wait for after FCPublish.

on_status(level, code, description)

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

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

parse(type_id, payload)

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

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

parse_data(type_id, payload)

@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(transaction_id)

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

A bare _result (used for releaseStream and FCPublish).