Class: Meshchat::Network::Local::Connection
- Inherits:
-
Object
- Object
- Meshchat::Network::Local::Connection
- Defined in:
- lib/meshchat/network/local/connection.rb
Instance Attribute Summary collapse
-
#_message_dispatcher ⇒ Object
readonly
Returns the value of attribute _message_dispatcher.
-
#_message_factory ⇒ Object
readonly
Returns the value of attribute _message_factory.
Instance Method Summary collapse
- #create_http_request(location, payload, &error_callback) ⇒ Object
-
#initialize(dispatcher, message_factory) ⇒ Connection
constructor
A new instance of Connection.
- #payload_for(encrypted_message) ⇒ Object
- #send_message(node, encrypted_message, &error_callback) ⇒ Object
- #start_server ⇒ Object
Constructor Details
#initialize(dispatcher, message_factory) ⇒ Connection
Returns a new instance of Connection.
10 11 12 13 14 15 16 |
# File 'lib/meshchat/network/local/connection.rb', line 10 def initialize(dispatcher, ) @_message_factory = @_message_dispatcher = dispatcher # async, won't prevent us from sending start_server end |
Instance Attribute Details
#_message_dispatcher ⇒ Object (readonly)
Returns the value of attribute _message_dispatcher.
8 9 10 |
# File 'lib/meshchat/network/local/connection.rb', line 8 def @_message_dispatcher end |
#_message_factory ⇒ Object (readonly)
Returns the value of attribute _message_factory.
8 9 10 |
# File 'lib/meshchat/network/local/connection.rb', line 8 def @_message_factory end |
Instance Method Details
#create_http_request(location, payload, &error_callback) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/meshchat/network/local/connection.rb', line 33 def create_http_request(location, payload, &error_callback) # TODO: what about https? # maybe do the regex match: /https?:\/\// location = 'http://' + location unless location.include?('http://') http = EventMachine::HttpRequest.new(location).post( body: payload, head: { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } ) http.errback &error_callback # example things available in the callback # p http.response_header.status # p http.response_header # p http.response http.callback { Display.debug http.response_header.status } end |
#payload_for(encrypted_message) ⇒ Object
53 54 55 |
# File 'lib/meshchat/network/local/connection.rb', line 53 def payload_for() { message: }.to_json end |
#send_message(node, encrypted_message, &error_callback) ⇒ Object
28 29 30 31 |
# File 'lib/meshchat/network/local/connection.rb', line 28 def (node, , &error_callback) payload = payload_for() create_http_request(node.location_on_network, payload, &error_callback) end |