Method: FTW::WebSocket::Writer#write_text

Defined in:
lib/ftw/websocket/writer.rb

#write_text(connection, text, mode = :server) ⇒ Object

Write the given text in a websocket frame to the connection.

Valid ‘mode’ settings are :server or :client. If :client, the payload will be masked according to RFC6455 section 5.3: tools.ietf.org/html/rfc6455#section-5.3



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ftw/websocket/writer.rb', line 45

def write_text(connection, text, mode=:server)
  if !VALID_MODES.include?(mode)
    raise InvalidArgument.new("Invalid message mode: #{mode}, expected one of" \
                              "#{VALID_MODES.inspect}")
  end

  data = []
  pack = []

  # For now, assume single-fragment, text frames
  pack_opcode(data, pack, OPCODE_TEXT)
  pack_payload(data, pack, text, mode)
  connection.write(data.pack(pack.join("")))
end