Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare 2.7.4 release #125

Merged
merged 15 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
All notable changes to the LaunchDarkly client-side JavaScript SDK will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org).

## [2.7.4] - 2018-11-21
### Fixed:
- When using the [`event-source-polyfill`](https://github.com/Yaffle/EventSource) package to allow streaming mode in browsers with no native EventSource support, the polyfill was using a default read timeout of 45 seconds, so if no updates arrived within 45 seconds it would log an error and reconnect the stream. The SDK now sets its own timeout (5 minutes) which will be used if this particular polyfill is active. LaunchDarkly normally sends a heartbeat every 3 minutes, so you should not see a timeout happen unless the connection has been lost.
- The SDK's use of the "Base64" package caused problems for build tools that strictly enforce the lowercase package name rule. It now uses the "base64-js" package instead. ([#124](https://github.com/launchdarkly/js-client/issues/124))

## [2.7.3] - 2018-11-09
### Fixed:
- The TypeScript definitions were incorrectly restricting the possible values for event types in `on()` and `off()`. Also, added documentation for event types which were not documented before. ([#122](https://github.com/launchdarkly/js-client/issues/122))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ when `client.on('change')` is called.

If you need streaming support, and you wish to support browsers that do not
support `EventSource` natively, you can install a polyfill such as
[EventSource](https://github.com/Yaffle/EventSource).
[event-source-polyfill](https://github.com/Yaffle/EventSource).

#### CDN

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ldclient-js",
"version": "2.7.3",
"version": "2.7.4",
"description": "LaunchDarkly SDK for JavaScript",
"author": "LaunchDarkly <[email protected]>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -78,7 +78,7 @@
"typescript": "3.0.1"
},
"dependencies": {
"Base64": "1.0.1",
"base64-js": "1.3.0",
"escape-string-regexp": "1.0.5"
},
"repository": {
Expand Down
13 changes: 12 additions & 1 deletion src/Stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default function Stream(baseUrl, environment, hash, config) {
const useReport = (config && config.useReport) || false;
const withReasons = (config && config.evaluationReasons) || false;
const streamReconnectDelay = (config && config.streamReconnectDelay) || 1000;
const timeoutMillis = 300000; // 5 minutes (same as other SDKs) - note, this only has an effect on polyfills
let es = null;
let reconnectTimeoutReference = null;
let user = null;
Expand Down Expand Up @@ -62,7 +63,17 @@ export default function Stream(baseUrl, environment, hash, config) {
url = url + (query ? '?' : '') + query;

closeConnection();
es = new window.EventSource(url);

// The standard EventSource constructor doesn't take any options, just a URL. However, some
// EventSource polyfills allow us to specify a timeout interval, and in some cases they will
// default to a too-short timeout if we don't specify one. So, here, we are setting the
// timeout properties that are used by several popular polyfills.
const options = {
heartbeatTimeout: timeoutMillis, // used by "event-source-polyfill" package
silentTimeout: timeoutMillis, // used by "eventsource-polyfill" package
};

es = new window.EventSource(url, options);
for (const key in handlers) {
if (handlers.hasOwnProperty(key)) {
es.addEventListener(key, handlers[key]);
Expand Down
6 changes: 4 additions & 2 deletions src/__tests__/EventSender-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base64 from 'Base64';
import * as base64 from 'base64-js';
import sinon from 'sinon';

import EventSender from '../EventSender';
Expand Down Expand Up @@ -44,7 +44,9 @@ describe('EventSender', () => {
s = s + '=';
}
s = s.replace(/_/g, '/').replace(/-/g, '+');
return decodeURIComponent(escape(Base64.atob(s)));
const decodedBytes = base64.toByteArray(s);
const decodedStr = String.fromCharCode.apply(String, decodedBytes);
return decodeURIComponent(escape(decodedStr));
}

function decodeOutputFromUrl(url) {
Expand Down
13 changes: 11 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import Base64 from 'Base64';
import * as base64 from 'base64-js';

// See http://ecmanaut.blogspot.com/2006/07/encoding-decoding-utf8-in-javascript.html
export function btoa(s) {
return Base64.btoa(unescape(encodeURIComponent(s)));
const escaped = unescape(encodeURIComponent(s));
return base64.fromByteArray(stringToBytes(escaped));
}

function stringToBytes(s) {
const b = [];
for (let i = 0; i < s.length; i++) {
b.push(s.charCodeAt(i));
}
return b;
}

export function base64URLEncode(s) {
Expand Down