Class: P2pStreamsChannel::SessionState

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject (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

#peersObject (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

Returns:

  • (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_peersObject



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