event-source-writer
create a server-sent events (EventSource) compatible stream
Unlike some other modules, this doesn't do anything with HTTP or any other transport. Rather, it lets you serialize events to a Readable stream. For example, you might choose to pipe it to logs or HTTP or what have you.
install
$ npm install event-source-writer
usage
var EventSourceWriter = var source = source sourcesource
outputs the events serialized as specified in the Server-Sent Events spec
event: keypressdata: {"keyCode":72} event: keypressdata: {"keyCode":73} event: keypressdata: {"keyCode":13} :end
notes
event-source-writer
will emit a keepalive to the stream every 10 seconds.
This helps prevent some systems from closing connections before the stream
has ended.
Static functions
EventSourceWriter.serialize(eventName?: String, data?: Object) => String
Both eventName
and data
are optional. In a common case, you'll supply both a string for the name of the event and an object for any event properties.
Example:
EventSourceWriter// => // event: coffeeready// data: {"time":"now"}//
EventSourceWriter.comment(String) => String
Creates a comment (line starting with :
) and ensures there are no
extraneous linefeeds.
License
Copyright © MMXIV Jason Denizac jason@denizac.org jden Licensed under the MIT license (see LICENSE.md)