Socket
Socket
Sign inDemoInstall

eventsource

Package Overview
Dependencies
0
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.9 to 0.0.10

5

History.md

@@ -0,1 +1,6 @@

# [0.0.10](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.9...v0.0.10)
* Provide `Event` argument on `open` and `error` event ([#30](https://github.com/aslakhellesoy/eventsource-node/issues/30), [#31](https://github.com/aslakhellesoy/eventsource-node/pull/31) Donghwan Kim)
* Expose `lastEventId` on messages. ([#28](https://github.com/aslakhellesoy/eventsource-node/pull/28) mbieser)
# [0.0.9](https://github.com/aslakhellesoy/eventsource-node/compare/v0.0.8...v0.0.9)

@@ -2,0 +7,0 @@

40

lib/eventsource.js

@@ -40,3 +40,3 @@ var http = require('http')

readyState = EventSource.CONNECTING;
_emit('error', err);
_emit('error', new Event('error'));

@@ -88,3 +88,4 @@ // The url may have been changed by a temporary

if (!res.headers.location) {
_emit('error', 'Server sent redirect response without Location header.');
// Server sent redirect response without Location header.
_emit('error', new Event('error'));
return;

@@ -101,3 +102,4 @@ }

if (res.statusCode == 403) {
_emit('error', 'Access denied');
// 'Access denied'
_emit('error', new Event('error'));
return self.close();

@@ -109,3 +111,3 @@ }

res.on('end', onConnectionClosed);
_emit('open');
_emit('open', new Event('open'));

@@ -128,6 +130,10 @@ var buf = '';

if (message.id) lastEventId = message.id;
_emit(message.event || 'message', new MessageEvent(data));
var type = message.event || 'message';
_emit(type, new MessageEvent('message', {
data: data,
lastEventId: lastEventId
}));
});
} catch(e) {
_emit('error', e);
_emit('error', new Event('error'));
}

@@ -214,11 +220,25 @@ });

/**
* W3C Event
*
* @see http://www.w3.org/TR/DOM-Level-3-Events/#interface-Event
* @api private
*/
function Event(type) {
Object.defineProperty(this, 'type', { writable: false, value: type });
}
/**
* W3C MessageEvent
*
* @see http://www.w3.org/TR/html5/comms.html
* @see http://www.w3.org/TR/webmessaging/#event-definitions
* @api private
*/
function MessageEvent(dataArg) {
// Currently only the data attribute is implemented. More can be added later if needed.
Object.defineProperty(this, 'data', { writable: false, value: dataArg });
function MessageEvent(type, eventInitDict) {
Object.defineProperty(this, 'type', { writable: false, value: type });
for(var f in eventInitDict) {
if(eventInitDict.hasOwnProperty(f)) {
Object.defineProperty(this, f, { writable: false, value: eventInitDict[f] });
}
}
}
{
"name": "eventsource",
"version": "0.0.9",
"version": "0.0.10",
"description": "W3C compliant EventSource client for Node.js",

@@ -5,0 +5,0 @@ "keywords": [

@@ -1,3 +0,4 @@

# EventSource [![Build Status](https://secure.travis-ci.org/aslakhellesoy/eventsource-node.png)](http://travis-ci.org/aslakhellesoy/eventsource-node) [![Dependencies](https://david-dm.org/aslakhellesoy/eventsource-node.png)](https://david-dm.org/aslakhellesoy/eventsource-node)
# EventSource [![Build Status](https://secure.travis-ci.org/aslakhellesoy/eventsource-node.png)](http://travis-ci.org/aslakhellesoy/eventsource-node) [![Dependencies](https://david-dm.org/aslakhellesoy/eventsource-node.png)](https://david-dm.org/aslakhellesoy/eventsource-node) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/aslakhellesoy/eventsource-node/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
[![NPM](https://nodei.co/npm/eventsource.png?stars&downloads)](https://nodei.co/npm/eventsource/)

@@ -58,4 +59,1 @@ [![NPM](https://nodei.co/npm-dl/eventsource.png)](https://nodei.co/npm/eventsource/)

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/aslakhellesoy/eventsource-node/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

@@ -788,3 +788,4 @@ var EventSource = require('../lib/eventsource')

var es = new EventSource('http://localhost:' + port);
es.onopen = function() {
es.onopen = function(event) {
assert.equal(event.type, 'open');
es.close();

@@ -799,3 +800,4 @@ close(done);

var es = new EventSource('http://localhost:' + port);
es.addEventListener('open', function() {
es.addEventListener('open', function(event) {
assert.equal(event.type, 'open');
es.close();

@@ -821,2 +823,31 @@ close(done);

});
it('populates message\'s lastEventId correctly when the last event has an associated id', function(done) {
createServer(["id: 123\ndata: sample_data\n\n"], function(port, close) {
var es = new EventSource('http://localhost:' + port);
es.onmessage = function(m) {
assert.equal(m.lastEventId, "123");
es.close();
close(done);
};
});
});
it('populates message\'s lastEventId correctly when the last event doesn\'t have an associated id', function(done) {
createServer(["id: 123\ndata: Hello\n\n", "data: World\n\n"], function(port, close) {
var es = new EventSource('http://localhost:' + port);
es.onmessage = first;
function first(m) {
es.onmessage = second;
}
function second(m) {
assert.equal(m.data, "World");
assert.equal(m.lastEventId, "123"); //expect to get back the previous event id
es.close();
close(done);
}
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc