Class: WebSocket::Frame::Handler::Handler03
- Defined in:
- lib/websocket/frame/handler/handler03.rb
Direct Known Subclasses
Constant Summary collapse
- FRAME_TYPES =
Hash of frame names and it’s opcodes
{ continuation: 0, close: 1, ping: 2, pong: 3, text: 4, binary: 5 }.freeze
- FRAME_TYPES_INVERSE =
Hash of frame opcodes and it’s names
FRAME_TYPES.invert.freeze
Instance Method Summary collapse
- #decode_frame ⇒ Object
- #encode_frame ⇒ Object
-
#masking? ⇒ Boolean
Allow turning on or off masking.
- #supported_frames ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from WebSocket::Frame::Handler::Base
Instance Method Details
#decode_frame ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/websocket/frame/handler/handler03.rb', line 43 def decode_frame while @frame.data.size > 1 valid_header, more, frame_type, mask, payload_length = decode_header return unless valid_header application_data = decode_payload(payload_length, mask) if more decode_continuation_frame(application_data, frame_type) elsif frame_type == :continuation return decode_finish_continuation_frame(application_data) else raise(WebSocket::Error::Frame::InvalidPayloadEncoding) if frame_type == :text && !application_data.valid_encoding? return @frame.class.new(version: @frame.version, type: frame_type, data: application_data, decoded: true) end end nil end |
#encode_frame ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/websocket/frame/handler/handler03.rb', line 29 def encode_frame frame = if @frame.outgoing_masking? masking_key = SecureRandom.random_bytes(4) tmp_data = Data.new(masking_key + @frame.data) tmp_data.set_mask masking_key + tmp_data.getbytes(4, tmp_data.size) else @frame.data end encode_header + frame end |
#masking? ⇒ Boolean
Allow turning on or off masking
63 64 65 |
# File 'lib/websocket/frame/handler/handler03.rb', line 63 def masking? false end |
#supported_frames ⇒ Object
24 25 26 |
# File 'lib/websocket/frame/handler/handler03.rb', line 24 def supported_frames i[text binary close ping pong] end |