Class: P2pStreamsChannel::SessionState
- Inherits:
-
Object
- Object
- P2pStreamsChannel::SessionState
- Defined in:
- lib/p2p_streams_channel/session_state.rb
Instance Attribute Summary collapse
-
#host_peer_id ⇒ Object
readonly
Returns the value of attribute host_peer_id.
-
#peers ⇒ Object
readonly
Returns the value of attribute peers.
Instance Method Summary collapse
- #add_peer(peer_id) ⇒ Object
- #host_ready? ⇒ Boolean
-
#initialize(host_peer_id = nil) ⇒ SessionState
constructor
A new instance of SessionState.
- #num_of_connected_peers ⇒ Object
- #remove_peer(peer_id) ⇒ Object
Constructor Details
#initialize(host_peer_id = nil) ⇒ SessionState
Returns a new instance of SessionState.
11 12 13 14 |
# File 'lib/p2p_streams_channel/session_state.rb', line 11 def initialize(host_peer_id = nil) @peers = {} @host_peer_id = host_peer_id end |
Instance Attribute Details
#host_peer_id ⇒ Object (readonly)
Returns the value of attribute host_peer_id.
9 10 11 |
# File 'lib/p2p_streams_channel/session_state.rb', line 9 def host_peer_id @host_peer_id end |
#peers ⇒ Object (readonly)
Returns the value of attribute peers.
9 10 11 |
# File 'lib/p2p_streams_channel/session_state.rb', line 9 def peers @peers end |
Instance Method Details
#add_peer(peer_id) ⇒ Object
16 17 18 19 |
# File 'lib/p2p_streams_channel/session_state.rb', line 16 def add_peer(peer_id) @peers[peer_id] = true @host_peer_id = peer_id if @host_peer_id.nil? end |
#host_ready? ⇒ Boolean
29 30 31 |
# File 'lib/p2p_streams_channel/session_state.rb', line 29 def host_ready? @peers[@host_peer_id] == true end |
#num_of_connected_peers ⇒ Object
25 26 27 |
# File 'lib/p2p_streams_channel/session_state.rb', line 25 def num_of_connected_peers @peers.count { |peer, connected| connected == true } end |
#remove_peer(peer_id) ⇒ Object
21 22 23 |
# File 'lib/p2p_streams_channel/session_state.rb', line 21 def remove_peer(peer_id) @peers[peer_id] = false end |