A CHICKEN Scheme module for Awful web framework that provides Server-Sent Events according to [[http://dev.w3.org/html5/eventsource/]] specification.
=== Author
[[/users/arthurmaciel|Arthur Maciel]]
=== Requirements
Requires [[awful]], [[spiffy]] and [[intarweb]] eggs.
=== Documentation
From Wikipedia:
"Server-sent events (SSE) is a technology for where a browser gets automatic updates from a server via HTTP connection. The Server-Sent Events EventSource API is standardized as part of HTML5 by the W3C. [It] is a standard describing how servers can initiate data transmission towards clients once an initial client connection has been established. They are commonly used to send message updates or continuous data streams to a browser client and designed to enhance native, cross-browser streaming through a JavaScript API called EventSource, through which a client requests a particular URL in order to receive an event stream." ([[http://en.wikipedia.org/wiki/Server-sent_events]])
'''Note''': if you need a full-duplex communication channel over a single TCP connection, please consider using [[http://en.wikipedia.org/wiki/WebSocket|Websockets]].
To see the magic happening with SSE, try the [[#examples|examples]].
* The "client page" that is accessed via {{path}} and presents {{contents}}. It is a "normal" awful page and should be used as the link presented to the client;
* The "server page" that should be accessed by the "client page" via {{sse-path}} using the appropiate Javascript code (see [[#examples|Examples]] section). This page will run {{sse-proc}}.
'''Note''' that {{sse-proc}} should keep the connection open, so usually it is an infinite loop. In order to avoid CPU consumption this loop should sleep some seconds and, for that, be sure to use SRFI-18 [[http://api.call-cc.org/doc/srfi-18/thread-sleep!|thread-sleep!]] instead of blocking {{sleep}} procedure.
<procedure>(send-sse-data data #!key event id)</procedure>
Send data from server to the client using the current HTTP connection. {{event}} and {{id}} keywords are used to set the data type and unique id respectively. When there is no {{event}} field set, the client understands the data type is "message". {{id}} is also optional.