Class: WampClient::Transport::FayeWebSocket
- Inherits:
-
EventMachineBase
- Object
- Base
- EventMachineBase
- WampClient::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_timer, start_event_machine, stop_event_machine
Methods inherited from Base
add_timer, #add_timer, #connected?, #on, #on_close, #on_error, #on_message, #on_open, start_event_machine, stop_event_machine
Constructor Details
#initialize(options) ⇒ FayeWebSocket
Returns a new instance of FayeWebSocket.
36 37 38 39 40 41 42 |
# File 'lib/wamp_client/transport/faye_web_socket.rb', line 36 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.
34 35 36 |
# File 'lib/wamp_client/transport/faye_web_socket.rb', line 34 def socket @socket end |
Instance Method Details
#connect ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wamp_client/transport/faye_web_socket.rb', line 44 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 @on_open.call if @on_open end self.socket.on(:message) do |event| .call(self.serializer.deserialize(event.data)) if end self.socket.on(:close) do |event| self.connected = false @on_close.call(event.reason) if @on_close end self.socket.on(:error) do |event| @on_error.call(event.) if @on_error end end |
#disconnect ⇒ Object
68 69 70 71 |
# File 'lib/wamp_client/transport/faye_web_socket.rb', line 68 def disconnect self.socket.close self.connected = false end |
#send_message(msg) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/wamp_client/transport/faye_web_socket.rb', line 73 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 |