Class: WAMP::Client
- Inherits:
-
Object
- Object
- WAMP::Client
- Defined in:
- lib/wamp/client.rb,
lib/wamp/client/version.rb
Constant Summary collapse
- TYPEID_WELCOME =
0
- TYPEID_PREFIX =
1
- TYPEID_CALL =
2
- TYPEID_CALLRESULT =
3
- TYPEID_CALLERROR =
4
- TYPEID_SUBSCRIBE =
5
- TYPEID_UNSUBSCRIBE =
6
- TYPEID_PUBLISH =
7
- TYPEID_EVENT =
8
- VERSION =
"0.0.5"
Instance Method Summary collapse
- #check(timeout = 5) ⇒ Object
- #close ⇒ Object
- #handle_message ⇒ Object
-
#initialize(uri, options = {}) ⇒ Client
constructor
A new instance of Client.
- #open(request_uri = "/") ⇒ Object
-
#prefix(prefix, uri) ⇒ Object
FIXME: this doesn’t seem to be working yet…
- #publish(uri_or_curie, data) ⇒ Object
- #subscribe(uri_or_curie, cb) ⇒ Object
- #to_io ⇒ Object
Constructor Details
#initialize(uri, options = {}) ⇒ Client
Returns a new instance of Client.
21 22 23 24 25 26 |
# File 'lib/wamp/client.rb', line 21 def initialize(uri, ={}) = {:subprotocols => ["wamp"]}.merge() @session_id = nil @ws = Net::WS.new(uri, ) @subscriptions = {} end |
Instance Method Details
#check(timeout = 5) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/wamp/client.rb', line 64 def check(timeout=5) Timeout.timeout(timeout) do loop {} end rescue Timeout::Error # noop end |
#close ⇒ Object
33 34 35 |
# File 'lib/wamp/client.rb', line 33 def close @ws.close end |
#handle_message ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/wamp/client.rb', line 53 def payload = case payload[0] when TYPEID_EVENT handle_event(payload) else $stderr.puts "Unhandled message type id: #{payload[0].pretty_inspect}" end end |
#open(request_uri = "/") ⇒ Object
28 29 30 31 |
# File 'lib/wamp/client.rb', line 28 def open(request_uri="/") @ws.open(request_uri) end |
#prefix(prefix, uri) ⇒ Object
FIXME: this doesn’t seem to be working yet… I’ve no idea why
38 39 40 41 |
# File 'lib/wamp/client.rb', line 38 def prefix(prefix, uri) payload = [TYPEID_PREFIX, prefix, uri] @ws.send_text(JSON.dump(payload)) end |
#publish(uri_or_curie, data) ⇒ Object
72 73 74 75 |
# File 'lib/wamp/client.rb', line 72 def publish(uri_or_curie, data) payload = [TYPEID_PUBLISH, uri_or_curie, data] @ws.send_text(JSON.dump(payload).force_encoding("utf-8")) end |
#subscribe(uri_or_curie, cb) ⇒ Object
43 44 45 46 47 |
# File 'lib/wamp/client.rb', line 43 def subscribe(uri_or_curie, cb) payload = [TYPEID_SUBSCRIBE, uri_or_curie] @ws.send_text(JSON.dump(payload)) @subscriptions[uri_or_curie] = @subscriptions.fetch(uri_or_curie, []) << cb end |
#to_io ⇒ Object
49 50 51 |
# File 'lib/wamp/client.rb', line 49 def to_io @ws.to_io end |