Module: Redisse::ServerSentEvents

Included in:
RedisPublisher
Defined in:
lib/redisse/server_sent_events.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) server_sent_event(data, type: nil, id: nil, **options)



6
7
8
9
10
11
12
13
14
# File 'lib/redisse/server_sent_events.rb', line 6

def server_sent_event(data, type: nil, id: nil, **options)
  data = String(data)
  str = ''
  str << "retry: #{options[:retry]}\n" if options[:retry]
  str << "id: #{id}\n" if id
  str << "event: #{type}\n" if type
  str << "data: " + data.gsub("\n", "\ndata: ") + "\n"
  str << "\n"
end