Commit e5431df1 authored by Robert Knight's avatar Robert Knight

Log a useful hint if the WebSocket connection is rejected

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.
parent 9fa71fc2
...@@ -86,8 +86,19 @@ function connect($rootScope, annotationMapper, groups, session, settings) { ...@@ -86,8 +86,19 @@ function connect($rootScope, annotationMapper, groups, session, settings) {
sendClientConfig(); sendClientConfig();
}); });
socket.on('error', function (error) { socket.on('error', function (event) {
console.warn('Error connecting to H push notification service:', error); 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.origin);
}
}); });
socket.on('message', function (event) { socket.on('message', function (event) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment