eventsource
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -1,18 +0,14 @@ | ||
var express = require('express') | ||
var serveStatic = require('serve-static') | ||
var SSE = require('sse') | ||
const express = require('express') | ||
const serveStatic = require('serve-static') | ||
const SseStream = require('ssestream') | ||
var app = express() | ||
const app = express() | ||
app.use(serveStatic(__dirname)) | ||
app.get('/sse', (req, res) => { | ||
console.log('new connection') | ||
var server = app.listen(8080, function (err) { | ||
if (err) throw err | ||
console.log('server ready on http://localhost:8080') | ||
}) | ||
var sse = new SSE(server) | ||
sse.on('connection', function (connection) { | ||
console.log('new connection') | ||
var pusher = setInterval(function () { | ||
connection.send({ | ||
const sseStream = new SseStream(req) | ||
sseStream.pipe(res) | ||
const pusher = setInterval(() => { | ||
sseStream.write({ | ||
event: 'server-time', | ||
@@ -23,6 +19,12 @@ data: new Date().toTimeString() | ||
connection.on('close', function () { | ||
res.on('close', () => { | ||
console.log('lost connection') | ||
clearInterval(pusher) | ||
sseStream.unpipe(res) | ||
}) | ||
}) | ||
app.listen(8080, (err) => { | ||
if (err) throw err | ||
console.log('server ready on http://localhost:8080') | ||
}) |
@@ -0,1 +1,10 @@ | ||
# [1.0.6](https://github.com/EventSource/eventsource/compare/v1.0.5...v1.0.6) | ||
* Fix issue where a unicode sequence split in two chunks would lead to invalid messages ([#108](https://github.com/EventSource/eventsource/pull/108) Espen Hovlandsdal) | ||
* Change example to use `eventsource/ssestream` (Aslak Hellesøy) | ||
# [1.0.5](https://github.com/EventSource/eventsource/compare/v1.0.4...v1.0.5) | ||
* Check for `window` existing before polyfilling. ([#80](https://github.com/EventSource/eventsource/pull/80) Neftaly Hernandez) | ||
# [1.0.4](https://github.com/EventSource/eventsource/compare/v1.0.2...v1.0.4) | ||
@@ -2,0 +11,0 @@ |
@@ -13,2 +13,14 @@ var original = require('original') | ||
var bom = [239, 187, 191] | ||
var colon = 58 | ||
var space = 32 | ||
var lineFeed = 10 | ||
var carriageReturn = 13 | ||
function hasBom (buf) { | ||
return bom.every(function (charCode, index) { | ||
return buf[index] === charCode | ||
}) | ||
} | ||
/** | ||
@@ -164,6 +176,11 @@ * Creates a new EventSource object | ||
// Source/WebCore/page/EventSource.cpp | ||
var buf = '' | ||
var isFirst = true | ||
var buf | ||
res.on('data', function (chunk) { | ||
buf += chunk | ||
buf = buf ? Buffer.concat([buf, chunk]) : chunk | ||
if (isFirst && hasBom(buf)) { | ||
buf = buf.slice(bom.length) | ||
} | ||
isFirst = false | ||
var pos = 0 | ||
@@ -174,3 +191,3 @@ var length = buf.length | ||
if (discardTrailingNewline) { | ||
if (buf[pos] === '\n') { | ||
if (buf[pos] === lineFeed) { | ||
++pos | ||
@@ -187,10 +204,10 @@ } | ||
c = buf[i] | ||
if (c === ':') { | ||
if (c === colon) { | ||
if (fieldLength < 0) { | ||
fieldLength = i - pos | ||
} | ||
} else if (c === '\r') { | ||
} else if (c === carriageReturn) { | ||
discardTrailingNewline = true | ||
lineLength = i - pos | ||
} else if (c === '\n') { | ||
} else if (c === lineFeed) { | ||
lineLength = i - pos | ||
@@ -210,3 +227,3 @@ } | ||
if (pos === length) { | ||
buf = '' | ||
buf = void 0 | ||
} else if (pos > 0) { | ||
@@ -253,7 +270,7 @@ buf = buf.slice(pos) | ||
var step = 0 | ||
var field = buf.slice(pos, pos + (noValue ? lineLength : fieldLength)) | ||
var field = buf.slice(pos, pos + (noValue ? lineLength : fieldLength)).toString() | ||
if (noValue) { | ||
step = lineLength | ||
} else if (buf[pos + fieldLength + 1] !== ' ') { | ||
} else if (buf[pos + fieldLength + 1] !== space) { | ||
step = fieldLength + 1 | ||
@@ -266,3 +283,3 @@ } else { | ||
var valueLength = lineLength - step | ||
var value = buf.slice(pos, pos + valueLength) | ||
var value = buf.slice(pos, pos + valueLength).toString() | ||
@@ -269,0 +286,0 @@ if (field === 'data') { |
{ | ||
"name": "eventsource", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "W3C compliant EventSource client for Node.js and browser (polyfill)", | ||
@@ -33,9 +33,10 @@ "keywords": [ | ||
"devDependencies": { | ||
"buffer-from": "^1.1.1", | ||
"express": "^4.15.3", | ||
"mocha": "^3.4.2", | ||
"nyc": "^11.0.2", | ||
"mocha": "^3.5.3", | ||
"nyc": "^11.2.1", | ||
"serve-static": "^1.12.3", | ||
"sse": "^0.0.6", | ||
"ssestream": "^1.0.0", | ||
"standard": "^10.0.2", | ||
"webpack": "^3.0.0" | ||
"webpack": "^3.5.6" | ||
}, | ||
@@ -42,0 +43,0 @@ "scripts": { |
@@ -1,7 +0,7 @@ | ||
# EventSource [![Build Status](https://secure.travis-ci.org/EventSource/eventsource.svg)](http://travis-ci.org/EventSource/eventsource) [![NPM Downloads](https://img.shields.io/npm/dm/eventsource.svg?style=flat-square)](http://npm-stat.com/charts.html?package=eventsource&from=2015-09-01) [![Dependencies](https://david-dm.org/EventSource/eventsource.svg)](https://david-dm.org/EventSource/eventsource) | ||
# EventSource [![npm version](http://img.shields.io/npm/v/eventsource.svg?style=flat-square)](http://browsenpm.org/package/eventsource)[![Build Status](http://img.shields.io/travis/EventSource/eventsource/master.svg?style=flat-square)](https://travis-ci.org/EventSource/eventsource)[![NPM Downloads](https://img.shields.io/npm/dm/eventsource.svg?style=flat-square)](http://npm-stat.com/charts.html?package=eventsource&from=2015-09-01)[![Dependencies](https://img.shields.io/david/EventSource/eventsource.svg?style=flat-square)](https://david-dm.org/EventSource/eventsource) | ||
This library is a pure JavaScript implementation of the [EventSource](http://www.w3.org/TR/eventsource/) client. The API aims to be W3C compatible. | ||
This library is a pure JavaScript implementation of the [EventSource](https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events) client. The API aims to be W3C compatible. | ||
You can use it with Node.js or as a browser polyfill for | ||
[browsers that don't have native `EventSource` support](http://caniuse.com/#search=eventsource). | ||
[browsers that don't have native `EventSource` support](http://caniuse.com/#feat=eventsource). | ||
@@ -54,3 +54,3 @@ ## Install | ||
By default, https requests that cannot be authorized will cause connection to fail and an exception | ||
By default, https requests that cannot be authorized will cause the connection to fail and an exception | ||
to be emitted. You can override this behaviour, along with other https options: | ||
@@ -57,0 +57,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
443626
8
14
9000