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
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/em-websocket/message_processor_06.rb', line 4
def message(message_type, extension_data, application_data)
debug [:message_received, message_type, application_data]
case message_type
when :close
status_code = case application_data.length
when 0
nil
when 1
raise DataError, "Close frames with a body must contain a 2 byte status code"
else
application_data.slice!(0, 2).unpack('n').first
end
debug [:close_frame_received, status_code, application_data]
if @state == :closing
@connection.close_connection
@state = :closed
else
send_frame(:close, '')
@state = :closed
@connection.close_connection_after_writing
end
when :ping
send_frame(:pong, application_data)
when :pong
when :text, :binary
@connection.trigger_on_message(application_data)
end
end
|