Class: WebSocketMessageFormat
- Inherits:
-
Format
- Object
- Format
- WebSocketMessageFormat
- Defined in:
- lib/websocketmessageformat.rb
Overview
The WebSocketMessageFormat class is the format used to publish data to WebSocket clients connected to GRIP proxies.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
Instance Method Summary collapse
-
#export ⇒ Object
Exports the message in the required format depending on whether the message content is binary or not.
-
#initialize(content, binary = false) ⇒ WebSocketMessageFormat
constructor
Initialize with the message content and a flag indicating whether the message content should be sent as base64-encoded binary data.
-
#name ⇒ Object
The name used when publishing this format.
Constructor Details
#initialize(content, binary = false) ⇒ WebSocketMessageFormat
Initialize with the message content and a flag indicating whether the message content should be sent as base64-encoded binary data.
18 19 20 21 |
# File 'lib/websocketmessageformat.rb', line 18 def initialize(content, binary=false) @content = content @binary = binary end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
14 15 16 |
# File 'lib/websocketmessageformat.rb', line 14 def content @content end |
Instance Method Details
#export ⇒ Object
Exports the message in the required format depending on whether the message content is binary or not.
30 31 32 33 34 35 36 37 38 |
# File 'lib/websocketmessageformat.rb', line 30 def export out = Hash.new if @binary out['content-bin'] = Base64.encode64(@content) else out['content'] = @content end return out end |
#name ⇒ Object
The name used when publishing this format.
24 25 26 |
# File 'lib/websocketmessageformat.rb', line 24 def name return 'ws-message' end |