Skip to content

Commit

Permalink
Releasing version 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LaunchDarklyCI committed Jan 26, 2021
1 parent 38e8b3b commit 50cb68f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this package will be documented in this file.

## [1.4.0] - 2021-01-25
### Added:
- Added `readTimeoutMillis` option for automatically dropping and restarting a connection if too much time has elapsed without receiving any data.

## [1.3.1] - 2020-06-29
### Fixed:
- Incorporated [a fix](https://github.com/EventSource/eventsource/pull/130) from the upstream repository that avoids unnecessary delays when parsing a long message that is received in multiple chunks.
Expand Down
51 changes: 45 additions & 6 deletions example/eventsource-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -3278,6 +3278,7 @@ function EventEmitter() {
EventEmitter.init.call(this);
}
module.exports = EventEmitter;
module.exports.once = once;

// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
Expand Down Expand Up @@ -3669,6 +3670,35 @@ function unwrapListeners(arr) {
return ret;
}

function once(emitter, name) {
return new Promise(function (resolve, reject) {
function eventListener() {
if (errorListener !== undefined) {
emitter.removeListener('error', errorListener);
}
resolve([].slice.call(arguments));
};
var errorListener;

// Adding an error listener is not optional because
// if an error is thrown on an event emitter we cannot
// guarantee that the actual event we are waiting will
// be fired. The result could be a silent way to create
// memory or file descriptor leaks, which is something
// we should avoid.
if (name !== 'error') {
errorListener = function errorListener(err) {
emitter.removeListener(name, eventListener);
reject(err);
};

emitter.once('error', errorListener);
}

emitter.once(name, eventListener);
});
}


/***/ }),
/* 10 */
Expand Down Expand Up @@ -6668,6 +6698,7 @@ function EventSource (url, eventSourceInitDict) {
var buf
var startingPos = 0
var startingFieldLength = -1

res.on('data', function (chunk) {
buf = buf ? Buffer.concat([buf, chunk]) : chunk
if (isFirst && hasBom(buf)) {
Expand Down Expand Up @@ -6726,6 +6757,10 @@ function EventSource (url, eventSourceInitDict) {
})
})

if (config.readTimeoutMillis) {
req.setTimeout(config.readTimeoutMillis)
}

if (config.body) {
req.write(config.body)
}
Expand All @@ -6734,6 +6769,11 @@ function EventSource (url, eventSourceInitDict) {
failed({ message: err.message })
})

req.on('timeout', function () {
failed({ message: 'Read timeout, received no data in ' + config.readTimeoutMillis +
'ms, assuming connection is dead' })
})

if (req.setNoDelay) req.setNoDelay(true)
req.end()
}
Expand Down Expand Up @@ -7100,9 +7140,7 @@ function fromByteArray (uint8) {

// go through the array every three bytes, we'll deal with trailing stuff later
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
parts.push(encodeChunk(
uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
))
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
}

// pad the end with zeros, but make sure to not forget the extra bytes
Expand Down Expand Up @@ -7131,6 +7169,7 @@ function fromByteArray (uint8) {
/* 24 */
/***/ (function(module, exports) {

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
var e, m
var eLen = (nBytes * 8) - mLen - 1
Expand Down Expand Up @@ -7882,7 +7921,7 @@ function encode(input) {
* @api public
*/
function querystring(query) {
var parser = /([^=?&]+)=?([^&]*)/g
var parser = /([^=?#&]+)=?([^&]*)/g
, result = {}
, part;

Expand Down Expand Up @@ -7937,8 +7976,8 @@ function querystringify(obj, prefix) {
value = '';
}

key = encodeURIComponent(key);
value = encodeURIComponent(value);
key = encode(key);
value = encode(value);

//
// If we failed to encode the strings, we should bail out as we don't
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "launchdarkly-eventsource",
"version": "1.3.1",
"version": "1.4.0",
"description": "Fork of eventsource package - W3C compliant EventSource client for Node.js and browser (polyfill)",
"keywords": [
"eventsource",
Expand Down

0 comments on commit 50cb68f

Please sign in to comment.