Class: EventMachine::WebSocket::Handler
- Inherits:
-
Object
- Object
- EventMachine::WebSocket::Handler
- Includes:
- Debugger
- Defined in:
- lib/em-websocket/handler.rb
Direct Known Subclasses
Handler03, Handler05, Handler06, Handler07, Handler08, Handler13, Handler75, Handler76
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Class Method Summary collapse
Instance Method Summary collapse
- #close_websocket(code, body) ⇒ Object
-
#initialize(connection, debug = false) ⇒ Handler
constructor
A new instance of Handler.
- #ping ⇒ Object
- #pingable? ⇒ Boolean
- #receive_data(data) ⇒ Object
- #unbind ⇒ Object
Constructor Details
#initialize(connection, debug = false) ⇒ Handler
Returns a new instance of Handler.
37 38 39 40 41 42 |
# File 'lib/em-websocket/handler.rb', line 37 def initialize(connection, debug = false) @connection = connection @debug = debug @state = :connected initialize_framing end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
35 36 37 |
# File 'lib/em-websocket/handler.rb', line 35 def request @request end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
35 36 37 |
# File 'lib/em-websocket/handler.rb', line 35 def state @state end |
Class Method Details
.klass_factory(version) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/em-websocket/handler.rb', line 4 def self.klass_factory(version) handler_klass = case version when 75 Handler75 when 76 Handler76 when 1..3 # We'll use handler03 - I believe they're all compatible Handler03 when 5 Handler05 when 6 Handler06 when 7 Handler07 when 8 # drafts 9, 10, 11 and 12 should never change the version # number as they are all the same as version 08. Handler08 when 13 # drafts 13 to 17 all identify as version 13 as they are # only minor changes or text changes. Handler13 else # According to spec should abort the connection raise HandshakeError, "Protocol version #{version} not supported" end end |
Instance Method Details
#close_websocket(code, body) ⇒ Object
49 50 51 |
# File 'lib/em-websocket/handler.rb', line 49 def close_websocket(code, body) # Implemented in subclass end |
#ping ⇒ Object
58 59 60 61 |
# File 'lib/em-websocket/handler.rb', line 58 def ping # Overridden in subclass false end |
#pingable? ⇒ Boolean
63 64 65 66 |
# File 'lib/em-websocket/handler.rb', line 63 def pingable? # Also Overridden false end |
#receive_data(data) ⇒ Object
44 45 46 47 |
# File 'lib/em-websocket/handler.rb', line 44 def receive_data(data) @data << data process_data(data) end |
#unbind ⇒ Object
53 54 55 56 |
# File 'lib/em-websocket/handler.rb', line 53 def unbind @state = :closed @connection.trigger_on_close end |