Class: WAMP::Client
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
Returns the value of attribute callbacks.
-
#id ⇒ Object
Returns the value of attribute id.
-
#prefixes ⇒ Object
Returns the value of attribute prefixes.
-
#server_ident ⇒ Object
Returns the value of attribute server_ident.
-
#socket ⇒ Object
Returns the value of attribute socket.
-
#topics ⇒ Object
Returns the value of attribute topics.
-
#wamp_protocol ⇒ Object
Returns the value of attribute wamp_protocol.
-
#ws_server ⇒ Object
Returns the value of attribute ws_server.
Instance Method Summary collapse
- #available_bindings ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
WAMP Client Connects to WAMP server, after connection client should receve WELCOME message from server.
- #prefix(prefix, topic_uri) ⇒ Object
- #publish(topic_uri, payload, options = {}) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #subscribe(topic_uri) ⇒ Object
Methods included from Bindable
Constructor Details
#initialize(options = {}) ⇒ Client
WAMP Client
Connects to WAMP server, after connection client should receve WELCOME
from server.
Client can then register prefix, call, subscribe, unsubscribe, and publish
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wamp/client.rb', line 17 def initialize( = {}) @ws_server = [:host] || "ws://localhost:9000" @protocols = [:protocols] @headers = [:headers] @id = nil @socket = nil @wamp_protocol = nil @server_ident = nil @prefixes = {} @topics = [] @callbacks = {} end |
Instance Attribute Details
#callbacks ⇒ Object
Returns the value of attribute callbacks.
9 10 11 |
# File 'lib/wamp/client.rb', line 9 def callbacks @callbacks end |
#id ⇒ Object
Returns the value of attribute id.
9 10 11 |
# File 'lib/wamp/client.rb', line 9 def id @id end |
#prefixes ⇒ Object
Returns the value of attribute prefixes.
9 10 11 |
# File 'lib/wamp/client.rb', line 9 def prefixes @prefixes end |
#server_ident ⇒ Object
Returns the value of attribute server_ident.
9 10 11 |
# File 'lib/wamp/client.rb', line 9 def server_ident @server_ident end |
#socket ⇒ Object
Returns the value of attribute socket.
9 10 11 |
# File 'lib/wamp/client.rb', line 9 def socket @socket end |
#topics ⇒ Object
Returns the value of attribute topics.
9 10 11 |
# File 'lib/wamp/client.rb', line 9 def topics @topics end |
#wamp_protocol ⇒ Object
Returns the value of attribute wamp_protocol.
9 10 11 |
# File 'lib/wamp/client.rb', line 9 def wamp_protocol @wamp_protocol end |
#ws_server ⇒ Object
Returns the value of attribute ws_server.
9 10 11 |
# File 'lib/wamp/client.rb', line 9 def ws_server @ws_server end |
Instance Method Details
#available_bindings ⇒ Object
31 32 33 |
# File 'lib/wamp/client.rb', line 31 def available_bindings [:connect, :welcome, :call_result, :call_error, :event, :disconnect] end |
#prefix(prefix, topic_uri) ⇒ Object
45 46 47 48 49 |
# File 'lib/wamp/client.rb', line 45 def prefix(prefix, topic_uri) socket.send [WAMP::MessageType[:PREFIX], prefix, topic_uri].to_json prefixes[prefix] = topic_uri end |
#publish(topic_uri, payload, options = {}) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/wamp/client.rb', line 57 def publish(topic_uri, payload, = {}) exclude = .fetch(:exclude, nil) include = .fetch(:include, nil) socket.send [WAMP::MessageType[:PUBLISH], topic_uri, payload, exclude, include].to_json end |
#start ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/wamp/client.rb', line 35 def start EM.run do ws = Faye::WebSocket::Client.new(ws_server, @protocols, {:headers => @headers}) ws.onopen = lambda { |event| handle_open(ws, event) } ws. = lambda { |event| (event) } ws.onclose = lambda { |event| handle_close(event) } end end |
#stop ⇒ Object
64 65 66 |
# File 'lib/wamp/client.rb', line 64 def stop EM.stop end |
#subscribe(topic_uri) ⇒ Object
51 52 53 54 55 |
# File 'lib/wamp/client.rb', line 51 def subscribe(topic_uri) socket.send [WAMP::MessageType[:SUBSCRIBE], topic_uri].to_json topics << topic_uri end |