Class: Meshchat::Network::Remote::RelayPool
- Inherits:
-
Object
- Object
- Meshchat::Network::Remote::RelayPool
- Defined in:
- lib/meshchat/network/remote/relay_pool.rb
Constant Summary collapse
- CHANNEL =
This channel is determine by the server, see github.com/NullVoxPopuli/mesh-relay/blob/master/app/channels/mesh_relay_channel.rb
'MeshRelayChannel'
Instance Attribute Summary collapse
-
#_active_relay ⇒ Object
Returns the value of attribute _active_relay.
-
#_available_relays ⇒ Object
Returns the value of attribute _available_relays.
-
#_known_relays ⇒ Object
Returns the value of attribute _known_relays.
-
#_message_dispatcher ⇒ Object
Returns the value of attribute _message_dispatcher.
Instance Method Summary collapse
- #ensure_active_connection!(&block) ⇒ Object
-
#find_initial_relay(connected: nil) ⇒ Array
TODO: add logic for just selecting the first available relay.
-
#initialize(message_dispatcher) ⇒ RelayPool
constructor
A new instance of RelayPool.
- #send_payload(payload) ⇒ Object
Constructor Details
#initialize(message_dispatcher) ⇒ RelayPool
Returns a new instance of RelayPool.
14 15 16 17 18 19 20 |
# File 'lib/meshchat/network/remote/relay_pool.rb', line 14 def initialize() @_message_dispatcher = @_known_relays = APP_CONFIG.user['relays'] || [] @_available_relays = APP_CONFIG.user['relays'] || [] find_initial_relay if @_known_relays.present? end |
Instance Attribute Details
#_active_relay ⇒ Object
Returns the value of attribute _active_relay.
11 12 13 |
# File 'lib/meshchat/network/remote/relay_pool.rb', line 11 def _active_relay @_active_relay end |
#_available_relays ⇒ Object
Returns the value of attribute _available_relays.
12 13 14 |
# File 'lib/meshchat/network/remote/relay_pool.rb', line 12 def _available_relays @_available_relays end |
#_known_relays ⇒ Object
Returns the value of attribute _known_relays.
12 13 14 |
# File 'lib/meshchat/network/remote/relay_pool.rb', line 12 def _known_relays @_known_relays end |
#_message_dispatcher ⇒ Object
Returns the value of attribute _message_dispatcher.
10 11 12 |
# File 'lib/meshchat/network/remote/relay_pool.rb', line 10 def @_message_dispatcher end |
Instance Method Details
#ensure_active_connection!(&block) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/meshchat/network/remote/relay_pool.rb', line 41 def ensure_active_connection!(&block) # TODO: make action_cable_client return a boolean if !_active_relay.connected? find_initial_relay(connected: block) else yield end end |
#find_initial_relay(connected: nil) ⇒ Array
TODO: add logic for just selecting the first available relay.
we only need one connection.
25 26 27 28 29 30 |
# File 'lib/meshchat/network/remote/relay_pool.rb', line 25 def find_initial_relay(connected: nil) url = _known_relays.first @_active_relay = Relay.new( url, , connected: connected) end |
#send_payload(payload) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/meshchat/network/remote/relay_pool.rb', line 33 def send_payload(payload) return if _active_relay.blank? ensure_active_connection! do _active_relay.perform('chat', payload) end end |