Class: Rack::WebSocket::Handler::Base::Connection
- Inherits:
-
EventMachine::WebSocket::Connection
- Object
- EventMachine::WebSocket::Connection
- Rack::WebSocket::Handler::Base::Connection
- Defined in:
- lib/rack/websocket/handler/base/connection.rb
Class Method Summary collapse
-
.new(*args) ⇒ Object
Overwrite new from EventMachine we need to skip standard procedure called when socket is created - this is just a stub.
Instance Method Summary collapse
-
#close_connection(*args) ⇒ Object
Overwrite close_connection from EventMachine delegate close_connection to rack server.
-
#dispatch(data) ⇒ Object
Overwrite dispath from em-websocket we already have request headers parsed so we can skip it and call build_with_request.
-
#initialize(app, socket, options = {}) ⇒ Connection
constructor
Overwrite initialize from em-websocket set all standard options and disable EM connection inactivity timeout.
-
#send_data(*args) ⇒ Object
Overwrite send_data from EventMachine delegate send_data to rack server.
- #trigger_on_close ⇒ Object
- #trigger_on_error(error) ⇒ Object
-
#trigger_on_message(msg) ⇒ Object
Overwrite triggers from em-websocket.
- #trigger_on_open ⇒ Object
Constructor Details
#initialize(app, socket, options = {}) ⇒ Connection
Overwrite initialize from em-websocket set all standard options and disable EM connection inactivity timeout
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rack/websocket/handler/base/connection.rb', line 51 def initialize(app, socket, = {}) @app = app @socket = socket @options = @debug = [:debug] || false @ssl = socket.backend.respond_to?(:ssl?) && socket.backend.ssl? socket.websocket = self socket.comm_inactivity_timeout = 0 debug [:initialize] end |
Class Method Details
.new(*args) ⇒ Object
Overwrite new from EventMachine we need to skip standard procedure called when socket is created - this is just a stub
16 17 18 19 20 |
# File 'lib/rack/websocket/handler/base/connection.rb', line 16 def self.new(*args) instance = allocate instance.__send__(:initialize, *args) instance end |
Instance Method Details
#close_connection(*args) ⇒ Object
Overwrite close_connection from EventMachine delegate close_connection to rack server
32 33 34 35 36 |
# File 'lib/rack/websocket/handler/base/connection.rb', line 32 def close_connection(*args) EM.next_tick do @socket.close_connection(*args) end end |
#dispatch(data) ⇒ Object
Overwrite dispath from em-websocket we already have request headers parsed so we can skip it and call build_with_request
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rack/websocket/handler/base/connection.rb', line 67 def dispatch(data) return false if data.nil? debug [:inbound_headers, data] @handler = EventMachine::WebSocket::HandlerFactory.build_with_request(self, data, data['Body'], @ssl, @debug) unless @handler # The whole header has not been received yet. return false end @handler.run return true end |
#send_data(*args) ⇒ Object
Overwrite send_data from EventMachine delegate send_data to rack server
24 25 26 27 28 |
# File 'lib/rack/websocket/handler/base/connection.rb', line 24 def send_data(*args) EM.next_tick do @socket.send_data(*args) end end |
#trigger_on_close ⇒ Object
45 |
# File 'lib/rack/websocket/handler/base/connection.rb', line 45 def trigger_on_close; @app.on_close; end |
#trigger_on_error(error) ⇒ Object
46 |
# File 'lib/rack/websocket/handler/base/connection.rb', line 46 def trigger_on_error(error); @app.on_error(error); true; end |
#trigger_on_message(msg) ⇒ Object
Overwrite triggers from em-websocket
43 |
# File 'lib/rack/websocket/handler/base/connection.rb', line 43 def (msg); @app.(msg); end |
#trigger_on_open ⇒ Object
44 |
# File 'lib/rack/websocket/handler/base/connection.rb', line 44 def trigger_on_open; @app.on_open; end |