Class: WebSocketMessageFormat

Inherits:
Format
  • Object
show all
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

Instance Method Summary collapse

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

#contentObject

Returns the value of attribute content.



14
15
16
# File 'lib/websocketmessageformat.rb', line 14

def content
  @content
end

Instance Method Details

#exportObject

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

#nameObject

The name used when publishing this format.



24
25
26
# File 'lib/websocketmessageformat.rb', line 24

def name
  return 'ws-message'
end