Skip to content

Commit

Permalink
Log a useful hint if the WebSocket connection is rejected
Browse files Browse the repository at this point in the history
The WebSocket only accepts connections from a whitelist of
origins. When connecting to a local H service, provide
a useful hint when connections (eg. from a local Chrome
extension build with bundled assets) are rejected due
to the H service not having the sidebar app's origin
whitelisted.
  • Loading branch information
robertknight committed Feb 1, 2016
1 parent 37196fc commit b786f67
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions h/static/scripts/streamer.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,19 @@ function connect($rootScope, annotationMapper, groups, session, settings) {
sendClientConfig();
});

socket.on('error', function (error) {
console.warn('Error connecting to H push notification service:', error);
socket.on('error', function (event) {
console.warn('Error connecting to H push notification service:', event);

// In development, warn if the connection failure might be due to
// the app's origin not having been whitelisted in the H service's config.
//
// Unfortunately the error event does not provide a way to get at the
// HTTP status code for HTTP -> WS upgrade requests.
var websocketHost = new URL(url).hostname;
if (['localhost', '127.0.0.1'].indexOf(websocketHost) !== -1) {
console.warn('Check that your H service is configured to allow ' +
'WebSocket connections from ' + window.location.host);
}
});

socket.on('message', function (event) {
Expand Down

0 comments on commit b786f67

Please sign in to comment.