Class: P2pStreamsChannel::Session
- Inherits:
-
Object
- Object
- P2pStreamsChannel::Session
- Defined in:
- lib/p2p_streams_channel/session.rb
Overview
TODO: support optional :db -> save session to db
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#negotiation ⇒ Object
readonly
Returns the value of attribute negotiation.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#session_state ⇒ Object
readonly
Returns the value of attribute session_state.
Instance Method Summary collapse
- #disconnect_peer(peer_id) ⇒ Object
-
#initialize(id, secret_key: "") ⇒ Session
constructor
A new instance of Session.
- #is_host_peer?(peer_id) ⇒ Boolean
- #join_peer(peer_id) ⇒ Object
- #reset_state ⇒ Object
- #save! ⇒ Object
- #signature ⇒ Object
- #to_json ⇒ Object
- #to_param ⇒ Object
Constructor Details
#initialize(id, secret_key: "") ⇒ Session
Returns a new instance of Session.
10 11 12 13 14 15 |
# File 'lib/p2p_streams_channel/session.rb', line 10 def initialize(id, secret_key: "") @id = id @secret_key = secret_key @negotiation = Negotiation.new @session_state = SessionState.new end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/p2p_streams_channel/session.rb', line 8 def id @id end |
#negotiation ⇒ Object (readonly)
Returns the value of attribute negotiation.
8 9 10 |
# File 'lib/p2p_streams_channel/session.rb', line 8 def negotiation @negotiation end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
8 9 10 |
# File 'lib/p2p_streams_channel/session.rb', line 8 def secret_key @secret_key end |
#session_state ⇒ Object (readonly)
Returns the value of attribute session_state.
8 9 10 |
# File 'lib/p2p_streams_channel/session.rb', line 8 def session_state @session_state end |
Instance Method Details
#disconnect_peer(peer_id) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/p2p_streams_channel/session.rb', line 35 def disconnect_peer(peer_id) if session_state.host_peer_id == peer_id reset_state else session_state.remove_peer(peer_id) save! end end |
#is_host_peer?(peer_id) ⇒ Boolean
44 45 46 |
# File 'lib/p2p_streams_channel/session.rb', line 44 def is_host_peer?(peer_id) session_state.host_peer_id == peer_id end |
#join_peer(peer_id) ⇒ Object
29 30 31 32 33 |
# File 'lib/p2p_streams_channel/session.rb', line 29 def join_peer(peer_id) @negotiation.join(peer_id, session_state).tap do |response| save! end end |
#reset_state ⇒ Object
48 49 50 51 |
# File 'lib/p2p_streams_channel/session.rb', line 48 def reset_state @session_state = SessionState.new save! end |
#save! ⇒ Object
53 54 55 |
# File 'lib/p2p_streams_channel/session.rb', line 53 def save! P2pStreamsChannel.save_session(self) end |
#signature ⇒ Object
17 18 19 |
# File 'lib/p2p_streams_channel/session.rb', line 17 def signature {id: @id} end |
#to_json ⇒ Object
25 26 27 |
# File 'lib/p2p_streams_channel/session.rb', line 25 def to_json signature.to_json end |
#to_param ⇒ Object
21 22 23 |
# File 'lib/p2p_streams_channel/session.rb', line 21 def to_param signature.to_param end |