summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-24 18:25:08 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-24 18:25:52 (GMT)
commit2af1536627036d0a329237b8ac61bfff16766aa2 (patch)
tree2493a7d27048d4fdf4e553c1fad40d40377cdd61
parent3c2a152af0d37fd687198f56819b05f389996bc1 (diff)
make list web socket connection resilient against connection problems
-rw-r--r--www/js/importer.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/www/js/importer.js b/www/js/importer.js
index 8bc525e..caac692 100644
--- a/www/js/importer.js
+++ b/www/js/importer.js
@@ -35,6 +35,7 @@ Rdxport.Importer = function(username, token, rhimpordEndpoint) {
this.uploads = [];
this.initListWebSocket();
+ setInterval(this.checkListWebSocket.bind(this), 5000);
};
Rdxport.Importer.CMD_LIST = 'list';
@@ -51,19 +52,29 @@ Rdxport.Importer.TYPE_DONE = 'done';
Rdxport.Importer.prototype.initListWebSocket = function() {
var self = this;
this.listWebSocket = new WebSocket(this.rhimpordEndpoint);
+ this.listWebSocket.connected = false;
this.listWebSocket.onclose = function(code, reason) {
- //console.log('close');
//console.log(code);
//console.log(reason);
+ if(this.connected) {
+ console.log('importer: list-socket closed, reconnect immediatly because it was connected before');
+ self.checkListWebSocket();
+ } else {
+ console.log('importer: list-socket closed, not reconnecting immediatly because it was never connected');
+ }
};
this.listWebSocket.onerror = function(error) {
//console.log('error');
- console.log(error);
+ if(this.connected) { // only print errors if we are connected
+ console.log(error);
+ }
};
this.listWebSocket.onopen = function() {
+ this.connected = true;
+ console.log('importer: list-socket is now connected');
var sendOptions = {
COMMAND: Rdxport.Importer.CMD_LIST,
LOGIN_NAME: importer.username,
@@ -90,6 +101,12 @@ Rdxport.Importer.prototype.initListWebSocket = function() {
};
};
+Rdxport.Importer.prototype.checkListWebSocket = function() {
+ if(!this.listWebSocket || this.listWebSocket.readyState == 3) {
+ this.initListWebSocket();
+ }
+}
+
Rdxport.Importer.prototype.syncUploads = function(route, groupView, done) {
var sessions = this.sessions.filter(function(session) {
var reference = session.reference.split('/');
@@ -344,8 +361,6 @@ Rdxport.Upload = function(fileOrsourceUri, group, groupView, cartNumber, useMeta
this.error = false;
this.errorStatus = '';
this.errorString = '';
-
- this.uploadInterval = null;
};
Rdxport.Upload.prototype.isUploading = function() {
@@ -496,7 +511,6 @@ Rdxport.Upload.prototype.close = function(silent) {
};
Rdxport.Upload.prototype.cancel = function() {
- clearInterval(this.uploadInterval);
this.webSocket.send(JSON.stringify({ COMMAND: 'cancel' }));
};