Skip to content

Commit 0095ac8

Browse files
authored
Merge pull request #18 from nickpresta/add-ie-edge-support
Add guard around EventSource for browsers without support
2 parents 5b137d8 + f43f842 commit 0095ac8

File tree

5 files changed

+55
-11
lines changed

5 files changed

+55
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
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).
44

5+
## [1.0.6] - 2016-08-23
6+
### Changed
7+
- Added check for EventSource before trying to connect Stream.
8+
59
## [1.0.5] - 2016-08-22
610
### Changed
711
- Fixed an error that occurred on `hashchage`/`popstate` if the account had no goals.

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ This is the official LaunchDarkly client-side JavaScript SDK. This SDK does two
77
* Makes feature flags available to your client-side (front-end) JavaScript code.
88
* Sends click, pageview, and custom events from your front-end for A/B tests and analytics.
99

10+
## Browser Support
11+
12+
The LaunchDarkly client-side JavaScript SDK supports the following browsers:
13+
14+
* Chrome (any recent)
15+
* Firefox (any recent)
16+
* Safari (any recent)*
17+
* Internet Explorer (IE10+)*
18+
* Edge (any recent)*
19+
* Opera (any recent)*
20+
21+
\* These browsers do not support streaming new flags to connected clients, even when `client.on('change')` is called.
22+
1023
## Installation
1124

1225
There are two ways to install the client-side SDK:
@@ -51,7 +64,7 @@ Out of the box, initializing the client will make a remote request to LaunchDark
5164

5265
Bootstrapping refers to providing the LaunchDarkly client object with an initial, immediately available set of feature flag values so that on page load `variation` can be called with no delay.
5366

54-
#### From the server-side SDK
67+
#### From the server-side SDK
5568

5669
The preferred approach to bootstrapping is to populate the bootstrap values (a map of feature flag keys to flag values) from your backend. LaunchDarkly's server-side SDKs have a function called `all_flags`-- this function provides the initial set of bootstrap values. You can then provide these values to your front-end as a template. Depending on your templating language, this might look something like this:
5770

@@ -66,15 +79,15 @@ If you bootstrap from the server-side, feature flags will be ready immediately,
6679

6780
#### From Local Storage
6881

69-
Alternatively, you can bootstrap feature flags from local storage.
82+
Alternatively, you can bootstrap feature flags from local storage.
7083

7184
var client = LDClient.initialize('YOUR_ENVIRONMENT_ID', user, options = {
7285
bootstrap: 'localStorage'
7386
});
7487

75-
When using local storage, the client will store the latest flag settings in local storage. On page load, the previous settings will be used and the 'ready' event will be emitted immediately. This means that on page load, the user may see cached flag values until the next page load.
88+
When using local storage, the client will store the latest flag settings in local storage. On page load, the previous settings will be used and the 'ready' event will be emitted immediately. This means that on page load, the user may see cached flag values until the next page load.
7689

77-
You can still subscribe to flag changes if you're using local storage.
90+
You can still subscribe to flag changes if you're using local storage.
7891

7992

8093
### Secure mode

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ldclient-js",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "LaunchDarkly SDK for JavaScript",
55
"author": "LaunchDarkly <[email protected]>",
66
"license": "Apache-2.0",

src/Stream.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ function Stream(url, environment) {
22
var stream = {};
33
var url = url + '/ping/' + environment;
44
var es = null;
5-
5+
66
stream.connect = function(onPing) {
7-
es = new EventSource(url);
8-
es.addEventListener('ping', onPing);
7+
if (typeof EventSource !== 'undefined') {
8+
es = new window.EventSource(url);
9+
es.addEventListener('ping', onPing);
10+
}
911
}
1012

1113
stream.disconnect = function() {
12-
es.close();
14+
es && es.close();
1315
}
14-
16+
1517
stream.isConnected = function() {
1618
return es && (es.readyState === EventSource.OPEN || es.readyState === EventSource.CONNECTING);
1719
}
18-
20+
1921
return stream;
2022
}
2123

src/__tests__/Stream-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var Stream = require('../Stream');
2+
3+
var noop = function() {};
4+
5+
describe('Stream', function() {
6+
it('should not throw on EventSource when it does not exist', function() {
7+
window.EventSource = undefined;
8+
var stream = new Stream('https://example.com', 'test');
9+
10+
var connect = function() {
11+
stream.connect(noop);
12+
}
13+
14+
expect(connect).to.not.throw(TypeError);
15+
});
16+
it('should not throw when calling disconnect without first calling connect', function() {
17+
var stream = new Stream('https://example.com', 'test');
18+
19+
var disconnect = function() {
20+
stream.disconnect(noop);
21+
}
22+
23+
expect(disconnect).to.not.throw(TypeError);
24+
})
25+
});

0 commit comments

Comments
 (0)