Class: P2pStreamsChannel::Negotiation

Inherits:
Object
  • Object
show all
Defined in:
lib/p2p_streams_channel/negotiation.rb

Instance Method Summary collapse

Instance Method Details

#error_response(err, session_state) ⇒ Object



21
22
23
# File 'lib/p2p_streams_channel/negotiation.rb', line 21

def error_response(err, session_state)
    # TODO:
end

#join(peer_id, session_state) ⇒ Object



5
6
7
8
9
10
# File 'lib/p2p_streams_channel/negotiation.rb', line 5

def join(peer_id, session_state)
    session_state.add_peer(peer_id)
    session_state.host_ready? ? ready_response(peer_id, session_state) : nil
rescue => e
    error_response(e, session_state)
end

#ready_response(peer_id, session_state) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/p2p_streams_channel/negotiation.rb', line 12

def ready_response(peer_id, session_state)
    {
        "type": P2pStreamsChannel::CONNECTION_MESSAGE_TYPE,
        "state": P2pStreamsChannel::STATE_SESSION_READY,
        "host_peer_id": session_state.host_peer_id,
        "peer_id": peer_id
    }
end