Sha256: 82e12bd096a4408034c2e2979ad75c126ce04d3940298d880d65a388f4088858

Contents?: true

Size: 675 Bytes

Versions: 5

Compression:

Stored size: 675 Bytes

Contents

module Grenache
  class NoPeerFoundError < Exception; end

  class Ws < Grenache::Base
    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

    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

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grenache-ruby-ws-0.1.7 lib/grenache/ws.rb
grenache-ruby-ws-0.1.6 lib/grenache/ws.rb
grenache-ruby-ws-0.1.5 lib/grenache/ws.rb
grenache-ruby-ws-0.1.4 lib/grenache/ws.rb
grenache-ruby-ws-0.1.3 lib/grenache/ws.rb