Class: WampClient::Transport::Base
- Inherits:
-
Object
- Object
- WampClient::Transport::Base
- Defined in:
- lib/wamp_client/transport/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#connected ⇒ Object
Returns the value of attribute connected.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#serializer ⇒ Object
Returns the value of attribute serializer.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
-
.add_timer(milliseconds, &callback) ⇒ Object
Process the callback when the timer expires.
-
.start_event_machine(&block) ⇒ Object
Method to start the event machine for the socket.
-
.stop_event_machine ⇒ Object
Method to stop the vent machine.
Instance Method Summary collapse
-
#add_timer(milliseconds, &callback) ⇒ Object
Implement in subclass.
-
#connect ⇒ Object
Connects to the WAMP Server using the transport.
-
#connected? ⇒ Boolean
Returns true if the transport it connected.
-
#disconnect ⇒ Object
Disconnects from the WAMP Server.
-
#initialize(options) ⇒ Base
constructor
Constructor for the transport.
-
#on(event, &callback) ⇒ Object
Simple setter for callbacks.
- #on_close(&on_close) ⇒ Object
- #on_error(&on_error) ⇒ Object
- #on_message(&on_message) ⇒ Object
- #on_open(&on_open) ⇒ Object
-
#send_message(msg) ⇒ Object
Sends a Message.
Constructor Details
#initialize(options) ⇒ Base
Constructor for the transport
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/wamp_client/transport/base.rb', line 86 def initialize() # Initialize the parameters self.connected = false self.uri = [:uri] self.proxy = [:proxy] self.headers = [:headers] || {} self.protocol = [:protocol] || 'wamp.2.json' self.serializer = [:serializer] || WampClient::Serializer::JSONSerializer.new # Add the wamp.2.json protocol header self.headers['Sec-WebSocket-Protocol'] = self.protocol # Initialize callbacks @on_open = nil @on_close = nil @on_message = nil @on_error = nil end |
Instance Attribute Details
#connected ⇒ Object
Returns the value of attribute connected.
77 78 79 |
# File 'lib/wamp_client/transport/base.rb', line 77 def connected @connected end |
#headers ⇒ Object
Returns the value of attribute headers.
77 78 79 |
# File 'lib/wamp_client/transport/base.rb', line 77 def headers @headers end |
#protocol ⇒ Object
Returns the value of attribute protocol.
77 78 79 |
# File 'lib/wamp_client/transport/base.rb', line 77 def protocol @protocol end |
#proxy ⇒ Object
Returns the value of attribute proxy.
77 78 79 |
# File 'lib/wamp_client/transport/base.rb', line 77 def proxy @proxy end |
#serializer ⇒ Object
Returns the value of attribute serializer.
77 78 79 |
# File 'lib/wamp_client/transport/base.rb', line 77 def serializer @serializer end |
#uri ⇒ Object
Returns the value of attribute uri.
77 78 79 |
# File 'lib/wamp_client/transport/base.rb', line 77 def uri @uri end |
Class Method Details
.add_timer(milliseconds, &callback) ⇒ Object
Process the callback when the timer expires
131 132 133 |
# File 'lib/wamp_client/transport/base.rb', line 131 def self.add_timer(milliseconds, &callback) # Implement in subclass end |
.start_event_machine(&block) ⇒ Object
Method to start the event machine for the socket
139 140 141 |
# File 'lib/wamp_client/transport/base.rb', line 139 def self.start_event_machine(&block) # Implement in subclass end |
.stop_event_machine ⇒ Object
Method to stop the vent machine
144 145 146 |
# File 'lib/wamp_client/transport/base.rb', line 144 def self.stop_event_machine # Implement in subclass end |
Instance Method Details
#add_timer(milliseconds, &callback) ⇒ Object
Implement in subclass
134 135 136 |
# File 'lib/wamp_client/transport/base.rb', line 134 def add_timer(milliseconds, &callback) self.class.add_timer(milliseconds, &callback) end |
#connect ⇒ Object
Connects to the WAMP Server using the transport
108 109 110 |
# File 'lib/wamp_client/transport/base.rb', line 108 def connect # Implement in subclass end |
#connected? ⇒ Boolean
Returns true if the transport it connected
118 119 120 |
# File 'lib/wamp_client/transport/base.rb', line 118 def connected? self.connected end |
#disconnect ⇒ Object
Disconnects from the WAMP Server
113 114 115 |
# File 'lib/wamp_client/transport/base.rb', line 113 def disconnect # Implement in subclass end |
#on(event, &callback) ⇒ Object
Simple setter for callbacks
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/wamp_client/transport/base.rb', line 62 def on(event, &callback) case event when :open self.on_open(&callback) when :close self.on_close(&callback) when :message self.(&callback) when :error self.on_error(&callback) else raise RuntimeError, "Unknown on(event) '#{event}'" end end |
#on_close(&on_close) ⇒ Object
43 44 45 |
# File 'lib/wamp_client/transport/base.rb', line 43 def on_close(&on_close) @on_close = on_close end |
#on_error(&on_error) ⇒ Object
57 58 59 |
# File 'lib/wamp_client/transport/base.rb', line 57 def on_error(&on_error) @on_error = on_error end |
#on_message(&on_message) ⇒ Object
50 51 52 |
# File 'lib/wamp_client/transport/base.rb', line 50 def (&) @on_message = end |
#on_open(&on_open) ⇒ Object
36 37 38 |
# File 'lib/wamp_client/transport/base.rb', line 36 def on_open(&on_open) @on_open = on_open end |
#send_message(msg) ⇒ Object
Sends a Message
124 125 126 |
# File 'lib/wamp_client/transport/base.rb', line 124 def (msg) # Implement in subclass end |