Class: EventMachine::WebSocket::Handler

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

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_websocket(code, body) ⇒ Object



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

def close_websocket(code, body)
  # Implemented in subclass
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



35
36
37
38
# File 'lib/em-websocket/handler.rb', line 35

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