Class: WebSocketRb::Wrapper::FrameBase

Inherits:
Object
  • Object
show all
Defined in:
lib/web_socket_rb/wrapper/frame_base.rb

Overview

Class defines base frame structure.

Direct Known Subclasses

FrameOutgoing

Constant Summary collapse

CONTINUATION =

Constants represents type of frame

0x0.to_i
TEXT =
0x1.to_i
BINARY =
0x2.to_i
CLOSE =
0x8.to_i
PING =
0x9.to_i
PONG =
0xA.to_i

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#finObject

Returns the value of attribute fin.



13
14
15
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 13

def fin
  @fin
end

#maskObject

Returns the value of attribute mask.



13
14
15
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 13

def mask
  @mask
end

#masking_keyObject

Returns the value of attribute masking_key.



13
14
15
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 13

def masking_key
  @masking_key
end

#opcodeObject

Returns the value of attribute opcode.



13
14
15
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 13

def opcode
  @opcode
end

#payload_dataObject

Returns the value of attribute payload_data.



13
14
15
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 13

def payload_data
  @payload_data
end

#payload_lenObject

Returns the value of attribute payload_len.



13
14
15
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 13

def payload_len
  @payload_len
end

#rsv1Object

Returns the value of attribute rsv1.



13
14
15
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 13

def rsv1
  @rsv1
end

#rsv2Object

Returns the value of attribute rsv2.



13
14
15
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 13

def rsv2
  @rsv2
end

#rsv3Object

Returns the value of attribute rsv3.



13
14
15
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 13

def rsv3
  @rsv3
end

Instance Method Details

#destinationObject

Read destination from payload data



35
36
37
38
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 35

def destination
  json_payload_data = JSON.parse(payload_data)
  json_payload_data.is_a?(Hash) ? json_payload_data['destination'] : nil
end

#messageObject

Read message from payload data



41
42
43
44
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 41

def message
  json_payload_data = JSON.parse(payload_data)
  json_payload_data.is_a?(Hash) ? json_payload_data['message'] : nil
end

#to_bytesObject

Method converts frame to bytes representation.



17
18
19
20
21
22
23
24
25
# File 'lib/web_socket_rb/wrapper/frame_base.rb', line 17

def to_bytes
  bytes = ''
  bytes << fin_rsv_opcode_to_byte
  bytes << mask_payload_length_to_byte
  bytes << ext_payload_len_to_byte
  bytes << masking_key_to_byte
  bytes << payload_data_to_byte
  bytes
end