Class: Wamp::Client::Transport::FayeWebSocket
- Inherits:
-
EventMachineBase
- Object
- Base
- EventMachineBase
- Wamp::Client::Transport::FayeWebSocket
- Defined in:
- lib/wamp/client/transport/faye_web_socket.rb
Instance Attribute Summary collapse
-
#socket ⇒ Object
Returns the value of attribute socket.
Attributes inherited from Base
#connected, #headers, #protocol, #proxy, #serializer, #uri
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#initialize(options) ⇒ FayeWebSocket
constructor
A new instance of FayeWebSocket.
- #send_message(msg) ⇒ Object
Methods inherited from EventMachineBase
add_tick_loop, add_timer, start_event_machine, stop_event_machine
Methods inherited from Base
add_tick_loop, add_timer, #add_timer, #connected?, start_event_machine, stop_event_machine
Methods included from Event
Constructor Details
#initialize(options) ⇒ FayeWebSocket
Returns a new instance of FayeWebSocket.
10 11 12 13 14 15 16 |
# File 'lib/wamp/client/transport/faye_web_socket.rb', line 10 def initialize() super() self.socket = nil # Only make them include the gem if they are going to use it require 'faye/websocket' end |
Instance Attribute Details
#socket ⇒ Object
Returns the value of attribute socket.
8 9 10 |
# File 'lib/wamp/client/transport/faye_web_socket.rb', line 8 def socket @socket end |
Instance Method Details
#connect ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wamp/client/transport/faye_web_socket.rb', line 18 def connect = { :headers => self.headers } [:proxy] = self.proxy if self.proxy != nil self.socket = Faye::WebSocket::Client.new(self.uri, [self.protocol], ) self.socket.on(:open) do |event| self.connected = true trigger :open end self.socket.on(:message) do |event| trigger :message, self.serializer.deserialize(event.data) end self.socket.on(:close) do |event| self.connected = false trigger :close, event.reason end self.socket.on(:error) do |event| trigger :error, event. end end |
#disconnect ⇒ Object
42 43 44 45 |
# File 'lib/wamp/client/transport/faye_web_socket.rb', line 42 def disconnect self.socket.close self.connected = false end |
#send_message(msg) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/wamp/client/transport/faye_web_socket.rb', line 47 def (msg) if self.connected self.socket.send(self.serializer.serialize(msg)) else raise RuntimeError, "Socket must be open to call 'send_message'" end end |