+ getUrl() {
+ const url = window.location.href;
+ var href;
+
+ if (url.includes('://localhost')) {
+ // Vue + node debug...
+ href = 'http://localhost:3000/';
+ } else {
+ href = url;
+ }
+
+ return href;
+ },
+ startPolling() {
+ if (this.polling === null) {
+ this.polling = setInterval(() => {
+ const href = this.getUrl();
+
+ server.getList(href)
+ .then(result => {
+ this.updateList(href, result);
+ })
+ .catch(err => {
+ console.error('Error on getting the list:', err);
+ });
+ }, 5000);
+ }
+ },
+ stopPolling() {
+ clearInterval(this.polling);
+ this.polling = null;
+ },
+ updateList(href, result) {
+ this.list = new Array();
+ this.refresh = result.length * 2;
+
+ for (var i = 0; i < result.length; i++) {
+ this.list.push({});
+ this.list[i].image = result[i].image;
+ const token = result[i].title.split(' - ', 2);
+ if (typeof token[1] == 'undefined') {
+ this.list[i].title = result[i].title;
+ this.list[i].artist = ' ';
+ } else {
+ this.list[i].title = token[1];
+ this.list[i].artist = token[0];
+ }
+ if (result[i].video === null) {
+ this.list[i].videoLoading = true;
+ } else {
+ this.list[i].videoLoading = false;
+ this.list[i].videoUrl = href + 'downloads/' + result[i].video;
+ this.refresh--;
+ }
+ if (result[i].audio === null) {
+ this.list[i].audioLoading = true;
+ } else {
+ this.list[i].audioLoading = false;
+ this.list[i].audioUrl = href + 'downloads/' + result[i].audio;
+ this.refresh--;
+ }
+ }
+
+ if (this.refresh > 0) {
+ this.startPolling();
+ } else {
+ this.stopPolling();
+ }
+ },