Skip to content

Commit 50cb68f

Browse files
Releasing version 1.4.0
1 parent 38e8b3b commit 50cb68f

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
## [1.4.0] - 2021-01-25
6+
### Added:
7+
- Added `readTimeoutMillis` option for automatically dropping and restarting a connection if too much time has elapsed without receiving any data.
8+
59
## [1.3.1] - 2020-06-29
610
### Fixed:
711
- 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.

example/eventsource-polyfill.js

+45-6
Original file line numberDiff line numberDiff line change
@@ -3278,6 +3278,7 @@ function EventEmitter() {
32783278
EventEmitter.init.call(this);
32793279
}
32803280
module.exports = EventEmitter;
3281+
module.exports.once = once;
32813282

32823283
// Backwards-compat with node 0.10.x
32833284
EventEmitter.EventEmitter = EventEmitter;
@@ -3669,6 +3670,35 @@ function unwrapListeners(arr) {
36693670
return ret;
36703671
}
36713672

3673+
function once(emitter, name) {
3674+
return new Promise(function (resolve, reject) {
3675+
function eventListener() {
3676+
if (errorListener !== undefined) {
3677+
emitter.removeListener('error', errorListener);
3678+
}
3679+
resolve([].slice.call(arguments));
3680+
};
3681+
var errorListener;
3682+
3683+
// Adding an error listener is not optional because
3684+
// if an error is thrown on an event emitter we cannot
3685+
// guarantee that the actual event we are waiting will
3686+
// be fired. The result could be a silent way to create
3687+
// memory or file descriptor leaks, which is something
3688+
// we should avoid.
3689+
if (name !== 'error') {
3690+
errorListener = function errorListener(err) {
3691+
emitter.removeListener(name, eventListener);
3692+
reject(err);
3693+
};
3694+
3695+
emitter.once('error', errorListener);
3696+
}
3697+
3698+
emitter.once(name, eventListener);
3699+
});
3700+
}
3701+
36723702

36733703
/***/ }),
36743704
/* 10 */
@@ -6668,6 +6698,7 @@ function EventSource (url, eventSourceInitDict) {
66686698
var buf
66696699
var startingPos = 0
66706700
var startingFieldLength = -1
6701+
66716702
res.on('data', function (chunk) {
66726703
buf = buf ? Buffer.concat([buf, chunk]) : chunk
66736704
if (isFirst && hasBom(buf)) {
@@ -6726,6 +6757,10 @@ function EventSource (url, eventSourceInitDict) {
67266757
})
67276758
})
67286759

6760+
if (config.readTimeoutMillis) {
6761+
req.setTimeout(config.readTimeoutMillis)
6762+
}
6763+
67296764
if (config.body) {
67306765
req.write(config.body)
67316766
}
@@ -6734,6 +6769,11 @@ function EventSource (url, eventSourceInitDict) {
67346769
failed({ message: err.message })
67356770
})
67366771

6772+
req.on('timeout', function () {
6773+
failed({ message: 'Read timeout, received no data in ' + config.readTimeoutMillis +
6774+
'ms, assuming connection is dead' })
6775+
})
6776+
67376777
if (req.setNoDelay) req.setNoDelay(true)
67386778
req.end()
67396779
}
@@ -7100,9 +7140,7 @@ function fromByteArray (uint8) {
71007140

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

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

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

@@ -7937,8 +7976,8 @@ function querystringify(obj, prefix) {
79377976
value = '';
79387977
}
79397978

7940-
key = encodeURIComponent(key);
7941-
value = encodeURIComponent(value);
7979+
key = encode(key);
7980+
value = encode(value);
79427981

79437982
//
79447983
// If we failed to encode the strings, we should bail out as we don't

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "launchdarkly-eventsource",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"description": "Fork of eventsource package - W3C compliant EventSource client for Node.js and browser (polyfill)",
55
"keywords": [
66
"eventsource",

0 commit comments

Comments
 (0)