From 3cc9bda4fbc189cc931b9cfa2163c3ff212ce1fa Mon Sep 17 00:00:00 2001 From: Peter Grassberger Date: Mon, 27 Jun 2016 12:44:36 +0200 Subject: add socket reconnect diff --git a/www/js/importer.js b/www/js/importer.js index 6599c5b..1d99433 100644 --- a/www/js/importer.js +++ b/www/js/importer.js @@ -63,29 +63,59 @@ Rdxport.Importer.prototype.initListWebSocket = function() { }; this.listWebSocket.onopen = function() { - /*console.log('send list'); var sendOptions = { COMMAND: Rdxport.Importer.CMD_LIST, LOGIN_NAME: importer.username, PASSWORD: importer.token }; + this.send(JSON.stringify(sendOptions)); var self = this; setInterval(function() { - console.log(sendOptions); self.send(JSON.stringify(sendOptions)); - }, 10 * 1000);*/ + }, 3 * 1000); }; this.listWebSocket.onmessage = function(event) { - console.log('message'); - console.log(event.data); - var data = $.parseJSON(event.data); if (data.TYPE.toLowerCase() === Rdxport.Importer.TYPE_LIST) { $.each(data.SESSIONS, function(id, reference) { - //todo: set group, groupView, cart, cut - //todo: only open new socket if id/reference is new - var upload = new Rdxport.Upload(null, null, null, null, null, null); + if (importer.getUploadById(id) !== null) { + return true; //continue; + } + var reference = reference.split('/'); + var groupName = reference[0]; + var cartNumber = reference[1]; + var filename = reference[2]; + + var groupViews = null; + switch (router.activeRoute) { + default: + //fallthrough + case 'shows': + if (showListView) { + groupViews = showListView.showViews; + } + case 'jingles': + if (jingleGroupListView) { + groupViews = jingleGroupListView.jingleGroupViews; + } + case 'musicpools': + if (musicpoolsView) { + groupViews = musicpoolsView.musicpoolViews; + } + } + + var groupView = groupViews.find(function (element) { + return element.model.groupName === groupName; + }); + + if (!groupView) { + return true; //continue; + } + + var group = groupView.model; + + var upload = new Rdxport.Upload('/' + filename, group, groupView, cartNumber, cartNumber, null); upload.reconnect(id, reference); self.uploads.push(upload); }); @@ -173,7 +203,7 @@ Rdxport.Importer.prototype.isUploading = function() { $.each(this.uploads, function(index, upload) { if (upload && upload.isUploading()) { $result = true; - return false; + return false; //break; } }); return $result; @@ -192,7 +222,7 @@ Rdxport.Importer.prototype.removeUpload = function(upload) { $.each(this.uploads, function(index, currentUpload){ if(currentUpload === upload) { self.uploads.splice(index, 1); - return false; + return false; //break; } }); }; @@ -206,7 +236,21 @@ Rdxport.Importer.prototype.getUploadByCartNumber = function(cartNumber) { if (currentUpload.cartNumber === cartNumber || currentUpload.newCartNumber === cartNumber) { upload = currentUpload; - return false; + return false; //break; + } + }); + return upload; +}; + +Rdxport.Importer.prototype.getUploadById = function(uploadId) { + if (uploadId === null) { + return null; + } + var upload = null; + $.each(this.uploads, function(index, currentUpload) { + if (currentUpload.uploadId === uploadId ) { + upload = currentUpload; + return false; //break; } }); return upload; @@ -233,7 +277,7 @@ Rdxport.Importer.prototype.getUploadsByGroupName = function(groupName) { Rdxport.Upload = function(sourceUri, group, groupView, cartNumber, newCartNumber, useMetadata) { this.sourceUri = sourceUri; - this.filename = sourceUri.substr(sourceUri.lastIndexOf('/') + 1); + this.filename = sourceUri ? sourceUri.substr(sourceUri.lastIndexOf('/') + 1) : ''; this.group = group; this.groupView = groupView; this.cartNumber = cartNumber; @@ -314,13 +358,14 @@ Rdxport.Upload.prototype.import = function() { USE_METADATA: self.useMetadata }; if (self.cartNumber) { - sendOptions.REFERENCE_ID = self.group.groupName + '/' + self.cartNumber; + sendOptions.REFERENCE_ID = self.group.groupName + '/' + self.cartNumber + '/' + self.filename; sendOptions.CART_NUMBER = parseInt(self.cartNumber); } else { if (self.newCartNumber) { - sendOptions.REFERENCE_ID = self.group.groupName + '/' + self.newCartNumber; + sendOptions.REFERENCE_ID = self.group.groupName + '/' + self.newCartNumber + '/' + self.filename; sendOptions.CART_NUMBER = parseInt(self.newCartNumber); } else if (self.group instanceof Rdxport.Musicpool) { + sendOptions.REFERENCE_ID = self.group.groupName + '/' + '/' + self.filename; sendOptions.MUSIC_POOL_GROUP = self.group.groupName; } } @@ -332,6 +377,8 @@ Rdxport.Upload.prototype.import = function() { }; Rdxport.Upload.prototype.reconnect = function(id, reference) { + var self = this; + this.webSocket = new WebSocket(importer.rhimpordEndpoint); this.webSocket.onclose = function(code, reason) { self.onclose(code, reason) }; this.webSocket.onerror = function(error) { self.onerror(error); }; @@ -344,8 +391,9 @@ Rdxport.Upload.prototype.reconnect = function(id, reference) { PASSWORD: importer.token, ID: id }; - console.log(reconnectOptions); this.send(JSON.stringify(reconnectOptions)); + + self.group.fetchCarts(); }; }; diff --git a/www/js/router.js b/www/js/router.js index f442e9e..38e8033 100644 --- a/www/js/router.js +++ b/www/js/router.js @@ -39,6 +39,7 @@ $(document).ready(function() { Rdxport.Router = function(auth) { this.auth = auth; this.authView = new Rdxport.AuthView(this.auth); + this.activeRoute = null; }; Rdxport.Router.prototype.route = function(page, subpage) { @@ -117,6 +118,7 @@ Rdxport.Router.prototype.route = function(page, subpage) { this.logout(); break; } + this.activeRoute = page; href = locationHrefValue(); if (href[1] !== page && page !== 'logout' && (!href[2] || href[2] !== subpage)) { diff --git a/www/js/shows.js b/www/js/shows.js index f4cfbbd..640a8ee 100644 --- a/www/js/shows.js +++ b/www/js/shows.js @@ -215,12 +215,12 @@ Rdxport.ShowView.prototype.render = function() { for(var w = 0; w < 4; w++) { if(this.model.rhythm.charAt(w) == '1') { - var s = $('#show-rhythm-w' + (w+1)).attr('class', 'label') + var s = $('#show-rhythm-w' + (w+1)).attr('class', 'label'); switch(w+1) { - case 1: s.addClass('label-info'); break; - case 2: s.addClass('label-warning'); break; - case 3: s.addClass('label-success'); break; - case 4: s.addClass('label-danger'); break; + case 1: s.addClass('label-info'); break; + case 2: s.addClass('label-warning'); break; + case 3: s.addClass('label-success'); break; + case 4: s.addClass('label-danger'); break; } } else { $('#show-rhythm-w' + (w+1)).attr('class', 'label label-disabled') -- cgit v0.10.2