Realtime server events for Node.JS, using Server Sent Events (SSE)
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 = require"litesocket";var http = require'http';httpcreateServerlitesocketreq resressend"Hello World";//DO NOT CALL res.end()!listen3000;
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 = require"litesocket";var express = require'express';var app = express;appget'/' litesocketressend"Hello World"event: "shout";;applisten3000;
Gives you some syntatic sugar if you want it.
var express = require'express';var app = express;appsse = require"litesocket"handler;appsse'/'ressend"Hello World";;applisten3000;
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
A helper function that allows you to combine several actions.
The MIT License (MIT)
Copyright (c) 2013 William Wicks
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.