summaryrefslogtreecommitdiff
path: root/www/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/js')
-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' }));
};