mirror of
https://github.com/fergalmoran/chrometophone.git
synced 2025-12-22 09:41:51 +00:00
Fixes to browser channel
This commit is contained in:
@@ -28,8 +28,6 @@ var STATUS_LOGIN_REQUIRED = 'login_required';
|
|||||||
var STATUS_DEVICE_NOT_REGISTERED = 'device_not_registered';
|
var STATUS_DEVICE_NOT_REGISTERED = 'device_not_registered';
|
||||||
var STATUS_GENERAL_ERROR = 'general_error';
|
var STATUS_GENERAL_ERROR = 'general_error';
|
||||||
|
|
||||||
var BROWSER_CHANNEL_RETRY_INTERVAL_MS = 10000 * (1 + Math.random() - 0.5);
|
|
||||||
|
|
||||||
var channel;
|
var channel;
|
||||||
var socket;
|
var socket;
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
@@ -85,12 +83,16 @@ function initializeBrowserChannel() {
|
|||||||
console.log('Browser channel initialized');
|
console.log('Browser channel initialized');
|
||||||
}
|
}
|
||||||
socket.onclose = function() {
|
socket.onclose = function() {
|
||||||
console.log('Browser channel closed. Restarting');
|
console.log('Browser channel closed');
|
||||||
setTimeout('initializeBrowserChannel()', 0);
|
setTimeout('initializeBrowserChannel()', 0);
|
||||||
}
|
}
|
||||||
socket.onerror = function() {
|
socket.onerror = function(error) {
|
||||||
console.log('Browser channel not initialized - retrying in ' + BROWSER_CHANNEL_RETRY_INTERVAL_MS + 'ms');
|
if (error.code == 401) { // token expiry
|
||||||
setTimeout('initializeBrowserChannel()', BROWSER_CHANNEL_RETRY_INTERVAL_MS);
|
console.log('Browser channel token expired - reconnecting');
|
||||||
|
} else {
|
||||||
|
console.log('Browser channel error');
|
||||||
|
// Automatically reconnects
|
||||||
|
}
|
||||||
}
|
}
|
||||||
socket.onmessage = function(evt) {
|
socket.onmessage = function(evt) {
|
||||||
var url = unescape(evt.data);
|
var url = unescape(evt.data);
|
||||||
@@ -105,8 +107,6 @@ function initializeBrowserChannel() {
|
|||||||
} else if (req.responseText.indexOf('NOT_ENABLED') == 0) {
|
} else if (req.responseText.indexOf('NOT_ENABLED') == 0) {
|
||||||
console.log('Not initializing browser channel because feature not enabled for user');
|
console.log('Not initializing browser channel because feature not enabled for user');
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
setTimeout('initializeBrowserChannel()', BROWSER_CHANNEL_RETRY_INTERVAL_MS);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user