rtmp v0.2.0 Rtmp.Handshake behaviour

Provides functionality to handle the RTMP handshake process.

Examples

The following is an example of handling a handshake as a server:

# Since we are a server we don't know what handshake type
# the client will send
{handshake, %RtmpHandshake.ParseResult{}} = RtmpHandshake.new(:unknown)

c0_and_c1 = get_packets_0_and_1_from_client()
{handshake, %RtmpHandshake.ParseResult{
  bytes_to_send: bytes,
  current_state: :waiting_for_data
}} = RtmpHandshake.process_bytes(handshake, c0_and_c1)

send_bytes_to_client(bytes)
c2 = get_packet_c2_from_client()

{handshake, %RtmpHandshake.ParseResult{
  current_state: :success
}} = RtmpHandshake.process_bytes(handshake, c2)

Summary

Functions

After a handshake has been successfully completed this is called to retrieve the peer’s starting timestamp and any left over binary that may need to be parsed later (not part of the handshake but instead the beginning of the rtmp protocol)

Creates a new finite state machine to handle the handshake process, and preliminary parse results

Reads the passed in binary to proceed with the handshaking process

Types

behaviour_state()
behaviour_state() :: any
binary_response()
binary_response() :: <<_::0>>
handshake_state()
handshake_state() :: %Rtmp.Handshake.State{handshake_state: term, handshake_type: term, peer_start_timestamp: term, remaining_binary: term, status: term}
handshake_type()
handshake_type() :: :unknown | :old | :digest
is_valid_format_result()
is_valid_format_result() :: :yes | :no | :unknown
process_result()
process_result ::
  {:success, start_time, binary_response, remaining_binary} |
  {:incomplete, binary_response} |
  :failure
remaining_binary()
remaining_binary() :: <<_::0>>
start_time()
start_time() :: non_neg_integer

Functions

get_handshake_result(state)

After a handshake has been successfully completed this is called to retrieve the peer’s starting timestamp and any left over binary that may need to be parsed later (not part of the handshake but instead the beginning of the rtmp protocol).

Creates a new finite state machine to handle the handshake process, and preliminary parse results.

If a handshake type is specified we assume we are acting as a client (since a server won’t know what type of handshake to use until it receives packets c0 and c1).

process_bytes(state, binary)

Reads the passed in binary to proceed with the handshaking process

Callbacks

create_p0_and_p1_to_send(behaviour_state)
create_p0_and_p1_to_send(behaviour_state) :: {behaviour_state, binary}
is_valid_format(<<>>)
is_valid_format(<<_::0>>) :: is_valid_format_result
process_bytes(behaviour_state, <<>>)
process_bytes(behaviour_state, <<_::0>>) :: {behaviour_state, process_result}