Sha256: 32e208fb260d1888579479bf4263742fbda688df26a319b3ec022d5674417ce4

Contents?: true

Size: 759 Bytes

Versions: 3

Compression:

Stored size: 759 Bytes

Contents

##
# This class provides methods for EventSource connection instance.
# @attr [Midori::Connection] connection the connection instance of EventMachine
class Midori::EventSource
  attr_accessor :connection

  # Init a EventSource instance with a connection
  # @param [Midori::Connection] connection the connection instance of EventMachine
  def initialize(connection)
    @connection = connection
  end

  # Send data and close the connection
  # @param [String] data data to be sent
  def send(data)
    raise Midori::Exception::EventSourceTypeError unless data.is_a? String
    # TODO: implement envents by standard
    @connection.send_data(data.split("\n").map {|str| "data: #{str}\n"}.join + "\n")
    @connection.close_connection_after_writing
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
midori.rb-0.9.0 lib/midori/eventsource.rb
midori.rb-0.8.0 lib/midori/eventsource.rb
midori.rb-0.7.1 lib/midori/eventsource.rb