Stop using Socket.io for one-way communication!
The W3C has created the Server-Sent Event specification for
doing "push notifications" in a very simple & http compatable way. (no need to
UPGRADE the connection)
Don't believe it is simple? Open litesocket.js and see for yourself!
var litesocket = ;var http = ;http;
A middleware function is returned when your call
require("litesocket"). The middleware sets up the plumbing
needed to send events to Node's response streams.
res.send function is overridden for sending SSE data.
data is any string you want to send.
options is an (optional) object you can provide with
retry message options.
var litesocket = ;var express = ;var app = ;app;app;
Gives you some syntatic sugar if you want it.
var express = ;var app = ;appsse = handler;app;app;
On establishing a connection, a welcome comment is sent.
default: "You are connected"
Allows you to override/customize the response headers that are sent.
They do what you would expect. See the Server-Sent Event spec for details #### sendId(stream, id) #### sendEvent(stream, name) #### sendRetry(stream, ms) #### sendComment(stream, comment) #### sendData(stream, data) #### send(stream, data, options) A helper function that allows you to combine several actions.
The MIT License (MIT)
Copyright (c) 2013 William Kapke
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.