class WebSocketMessageFormat

The WebSocketMessageFormat class is the format used to publish data to WebSocket clients connected to GRIP proxies.

Attributes

content[RW]

Public Class Methods

new(content, binary=false) click to toggle source

Initialize with the message content and a flag indicating whether the message content should be sent as base64-encoded binary data.

# File lib/websocketmessageformat.rb, line 18
def initialize(content, binary=false)
  @content = content
  @binary = binary
end

Public Instance Methods

export() click to toggle source

Exports the message in the required format depending on whether the message content is binary or not.

# 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() click to toggle source

The name used when publishing this format.

# File lib/websocketmessageformat.rb, line 24
def name
  return 'ws-message'
end