class Wamp::Client::Transport::WebSocketEventMachine
Attributes
socket[RW]
Public Class Methods
new(options)
click to toggle source
Calls superclass method
Wamp::Client::Transport::Base::new
# File lib/wamp/client/transport/web_socket_event_machine.rb, line 11 def initialize(options) super(options) self.socket = nil # Only make them include the gem if they are going to use it require 'websocket-eventmachine-client' # Raise an exception if proxy was included (not supported) if self.proxy != nil raise RuntimeError, "The WebSocketEventMachine transport does not support 'proxy'. Try using 'faye-websocket' transport instead" end end
Public Instance Methods
connect()
click to toggle source
# File lib/wamp/client/transport/web_socket_event_machine.rb, line 24 def connect self.socket = WebSocket::EventMachine::Client.connect( :uri => self.uri, :headers => self.headers ) self.socket.onopen do self.connected = true trigger :open end self.socket.onmessage do |msg, type| trigger :message, self.serializer.deserialize(msg) end self.socket.onclose do |code, reason| self.connected = false trigger :close, reason end end
disconnect()
click to toggle source
# File lib/wamp/client/transport/web_socket_event_machine.rb, line 45 def disconnect self.connected = !self.socket.close # close returns 'true' if the connection was closed immediately end
send_message(msg)
click to toggle source
# File lib/wamp/client/transport/web_socket_event_machine.rb, line 49 def send_message(msg) if self.connected self.socket.send(self.serializer.serialize(msg), {type: 'text'}) else raise RuntimeError, "Socket must be open to call 'send_message'" end end