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
-
#initialize(frame) ⇒ Handler03
constructor
A new instance of Handler03.
-
#masking? ⇒ Boolean
Allow turning on or off masking.
- #supported_frames ⇒ Object
Constructor Details
#initialize(frame) ⇒ Handler03
Returns a new instance of Handler03.
23 24 25 26 |
# File 'lib/websocket/frame/handler/handler03.rb', line 23 def initialize(frame) super @application_data_buffer = nil end |
Instance Method Details
#decode_frame ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/websocket/frame/handler/handler03.rb', line 48 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
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/websocket/frame/handler/handler03.rb', line 34 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
68 69 70 |
# File 'lib/websocket/frame/handler/handler03.rb', line 68 def masking? false end |
#supported_frames ⇒ Object
29 30 31 |
# File 'lib/websocket/frame/handler/handler03.rb', line 29 def supported_frames %i[text binary close ping pong] end |