Skip to content

Commit

Permalink
Merge pull request #299 from Workiva/fix_sockjs_detection
Browse files Browse the repository at this point in the history
WP-5850 Use hasProperty to detect sockjs.js
  • Loading branch information
Rosie the Robot authored Jan 29, 2018
2 parents a7f187a + f11698a commit 82523b9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
26 changes: 19 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
# Changelog
## [3.2.1](https://github.com/Workiva/w_transport/compare/3.2.0...3.2.1)
_January 29th, 2018_

- **Bug Fix:** The `sockjs.js` detection now uses `context.hasProperty()`
instead of actually trying to access the `SockJS` object on the window. This
fixes an exception that was being thrown silently in certain situations.

## [3.2.0](https://github.com/Workiva/w_transport/compare/3.1.2...3.2.0)
_January 4th, 2017_
_January 4th, 2018_

- **Improvement:** Added support for the [`sockjs_client_wrapper` package](https://github.com/Workiva/sockjs_client_wrapper). This will eventually replace our usage of the [`sockjs_client` Dart port](https://github.com/Workiva/sockjs-dart-client) because the wrapper uses the actual JS library which is fully-featured and community supported.
- **Improvement:** Added support for the [`sockjs_client_wrapper` package](https://github.com/Workiva/sockjs_client_wrapper). This will eventually replace our usage of the [`sockjs_client` Dart port](https://github.com/Workiva/sockjs-dart-client)
because the wrapper uses the actual JS library which is fully-featured and community supported.

The SockJS wrapper requires that the JS library be included in the HTML page. To avoid a breaking change, it will only be used if the JS library is detected on the window.
The SockJS wrapper requires that the JS library be included in the HTML page.
To avoid a breaking change, it will only be used if the JS library is detected
on the window.

If you are using the SockJS configuration for `WebSocket` and wish to leverage this more fully-featured SockJS (which provides all of the SockJS protocols e.g. `xhr-polling`), all you need to do is add the JS script to your application page:
If you are using the SockJS configuration for `WebSocket` and wish to leverage
this more fully-featured SockJS (which provides all of the SockJS protocols
e.g. `xhr-polling`), all you need to do is add the JS script to your
application page:

https://github.com/workiva/sockjs_client_wrapper#usage
https://github.com/workiva/sockjs_client_wrapper#usage

If you don't change anything, the SockJS configuration for `WebSocket` will still behave exactly the same and you should see no difference.
If you don't change anything, the SockJS configuration for `WebSocket` will
still behave exactly the same and you should see no difference.

## [3.0.3](https://github.com/Workiva/w_transport/compare/3.0.2...3.0.3)
_March 15th, 2017_
Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ <h3>WebSocket</h3>
<script type="application/dart" src="index.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
</html>
9 changes: 7 additions & 2 deletions example/web_socket/echo/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ TextInputElement _prompt = querySelector('#prompt');
PreElement _logs = querySelector('#logs');
NumberInputElement _sockJSTimeout = querySelector('#sockjs-timeout');
CheckboxInputElement _sockJSWebSocket = querySelector('#sockjs-ws');
CheckboxInputElement _sockJSXhr = querySelector('#sockjs-xhr');
CheckboxInputElement _sockJSXhrStreaming =
querySelector('#sockjs-xhr-streaming');
CheckboxInputElement _sockJSXhrPolling = querySelector('#sockjs-xhr-polling');
CheckboxInputElement _useSockJS = querySelector('#sockjs');

Future<Null> main() async {
Expand All @@ -60,9 +62,12 @@ Future<Null> main() async {
if (_sockJSWebSocket.checked) {
protocols.add('websocket');
}
if (_sockJSXhr.checked) {
if (_sockJSXhrStreaming.checked) {
protocols.add('xhr-streaming');
}
if (_sockJSXhrPolling.checked) {
protocols.add('xhr-polling');
}
final uri = sockjs ? _sockJSServer : _wsServer;

try {
Expand Down
13 changes: 11 additions & 2 deletions example/web_socket/echo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ <h1>Echo</h1>

<br>

<label for="sockjs-xhr">
<input type="checkbox" id="sockjs-xhr">
<label for="sockjs-xhr-streaming">
<input type="checkbox" id="sockjs-xhr-streaming">
SockJS xhr-streaming
</label>

<br>

<label for="sockjs-xhr-polling">
<input type="checkbox" id="sockjs-xhr-polling">
SockJS xhr-polling
</label>

<br>

<label for="sockjs-timeout">SockJS Timeout (ms)</label>
<input type="number" id="sockjs-timeout">

Expand All @@ -67,6 +74,8 @@ <h1>Echo</h1>
<pre id="logs"></pre>
</div>

<!--<script src="packages/sockjs_client_wrapper/sockjs.js"></script>-->
<!--<script src="packages/sockjs_client_wrapper/sockjs_prod.js"></script>-->
<script src="packages/react/react.js"></script>
<script type="application/dart" src="client.dart"></script>
<script src="packages/browser/dart.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion lib/src/web_socket/browser/sockjs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class SockJSWebSocket extends CommonWebSocket implements WebSocket {
// which is community-supported and fully-featured. But, it requires that
// the sockjs.js file is included. We can check for that by checking for the
// existence of a `SockJS` object on the window.
if (js.context['SockJS'] != null && js.context['SockJS'] is js.JsFunction) {
if (js.context.hasProperty('SockJS')) {
return SockJSWrapperWebSocket.connect(uri,
debug: debug,
noCredentials: noCredentials,
Expand Down

0 comments on commit 82523b9

Please sign in to comment.