Class: WebSocket::Frame::Handler::Handler07

Inherits:
Handler05 show all
Defined in:
lib/websocket/frame/handler/handler07.rb

Constant Summary collapse

FRAME_TYPES =

Hash of frame names and it’s opcodes

{
  continuation: 0,
  text: 1,
  binary: 2,
  close: 8,
  ping: 9,
  pong: 10
}.freeze
FRAME_TYPES_INVERSE =

Hash of frame opcodes and it’s names

FRAME_TYPES.invert.freeze

Instance Method Summary collapse

Methods inherited from Handler05

#masking?

Methods inherited from Handler03

#initialize, #masking?, #supported_frames

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from WebSocket::Frame::Handler::Handler03

Instance Method Details

#decode_frameObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/websocket/frame/handler/handler07.rb', line 31

def decode_frame
  result = super
  if close_code?(result)
    code = result.data.slice!(0..1)
    result.code = code.unpack('n').first
    raise WebSocket::Error::Frame::UnknownCloseCode unless valid_code?(result.code)
    raise WebSocket::Error::Frame::InvalidPayloadEncoding unless valid_encoding?(result.data)
  end
  result
end

#encode_frameObject



21
22
23
24
25
26
27
28
29
# File 'lib/websocket/frame/handler/handler07.rb', line 21

def encode_frame
  if @frame.type == :close
    code = @frame.code || 1000
    raise WebSocket::Error::Frame::UnknownCloseCode unless valid_code?(code)
    @frame.data = Data.new([code].pack('n') + @frame.data.to_s)
    @frame.code = nil
  end
  super
end