Class: EventMachine::WebSocket::Handler

Inherits:
Object
  • Object
show all
Includes:
Debugger
Defined in:
lib/em-websocket/handler.rb

Direct Known Subclasses

Handler03, Handler75, Handler76

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, request, debug = false) ⇒ Handler

Returns a new instance of Handler.



8
9
10
11
12
13
# File 'lib/em-websocket/handler.rb', line 8

def initialize(connection, request, debug = false)
  @connection, @request = connection, request
  @debug = debug
  @state = :handshake
  initialize_framing
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



6
7
8
# File 'lib/em-websocket/handler.rb', line 6

def request
  @request
end

#stateObject (readonly)

Returns the value of attribute state.



6
7
8
# File 'lib/em-websocket/handler.rb', line 6

def state
  @state
end

Instance Method Details

#close_websocketObject



31
32
33
34
35
# File 'lib/em-websocket/handler.rb', line 31

def close_websocket
  # Unless redefined in a subclass, just close the connection
  @state = :closed
  @connection.close_connection_after_writing
end

#handshakeObject

Handshake response



22
23
24
# File 'lib/em-websocket/handler.rb', line 22

def handshake
  # Implemented in subclass
end

#receive_data(data) ⇒ Object



26
27
28
29
# File 'lib/em-websocket/handler.rb', line 26

def receive_data(data)
  @data << data
  process_data(data)
end

#runObject



15
16
17
18
19
# File 'lib/em-websocket/handler.rb', line 15

def run
  @connection.send_data handshake
  @state = :connected
  @connection.trigger_on_open
end

#unbindObject



37
38
39
40
# File 'lib/em-websocket/handler.rb', line 37

def unbind
  @state = :closed
  @connection.trigger_on_close
end