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
handshake_state() :: %Rtmp.Handshake.State{handshake_state: term, handshake_type: term, peer_start_timestamp: term, remaining_binary: term, status: term}
process_result :: {:success, start_time, binary_response, remaining_binary} | {:incomplete, binary_response} | :failure
Functions
get_handshake_result(handshake_state) :: {handshake_state, Rtmp.Handshake.HandshakeResult.t}
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(handshake_state, <<_::0>>) :: {handshake_state, Rtmp.Handshake.ParseResult.t}
Reads the passed in binary to proceed with the handshaking process
Callbacks
create_p0_and_p1_to_send(behaviour_state) :: {behaviour_state, binary}
process_bytes(behaviour_state, <<_::0>>) :: {behaviour_state, process_result}