Class: Grenache::Ws
- Inherits:
-
Base
- Object
- Base
- Grenache::Ws
- Defined in:
- lib/grenache/ws.rb
Instance Method Summary collapse
Instance Method Details
#listen(key, port, opts = {}, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/grenache/ws.rb', line 5 def listen(key, port, opts={}, &block) EM.defer { @ws = WebsocketServer.new port, &block @ws.start_server } announce(key, port, opts) do |res| puts "#{key} announced #{res}" end end |
#request(key, payload, &cb) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/grenache/ws.rb', line 16 def request(key, payload, &cb) lookup key do |services| if services.length > 0 json = Message.req(payload).to_json service = services.sample ws = WebsocketClient.new(service, &cb) ws.send json else cb.call ["NoServiceFound", nil] end end end |