Changed methods from app to api.js
This commit is contained in:
parent
348f3c3824
commit
990dcc4776
2 changed files with 52 additions and 52 deletions
52
js/api.js
52
js/api.js
|
@ -278,6 +278,58 @@ function getRandomSongList(action, appendto) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
var updaterNowPlaying;
|
||||||
|
var updaterNowPlayingData;
|
||||||
|
function updateNowPlaying() {
|
||||||
|
updaterNowPlaying = $.periodic({ period: 4000, decay: 1.5, max_period: 1800000 }, function () {
|
||||||
|
$.ajax({
|
||||||
|
periodic: this,
|
||||||
|
url: baseURL + '/getNowPlaying.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp',
|
||||||
|
method: 'GET',
|
||||||
|
dataType: 'jsonp',
|
||||||
|
timeout: 10000,
|
||||||
|
beforeSend: function (req) {
|
||||||
|
req.setRequestHeader('Authorization', auth);
|
||||||
|
},
|
||||||
|
success: function (data) {
|
||||||
|
if (data["subsonic-response"].nowPlaying.entry === undefined) {
|
||||||
|
this.periodic.increment();
|
||||||
|
$("#NowPlayingList").empty();
|
||||||
|
var chathtml = '<div class=\"msg\">';
|
||||||
|
chathtml += '<span class=\"user\">Nothing :(</span></br>';
|
||||||
|
chathtml += '</div>';
|
||||||
|
$(chathtml).appendTo("#NowPlayingList");
|
||||||
|
} else if (updaterNowPlayingData === $.param(data)) {
|
||||||
|
this.periodic.increment();
|
||||||
|
} else {
|
||||||
|
$("#NowPlayingList").empty();
|
||||||
|
var msgs = [];
|
||||||
|
if (data["subsonic-response"].nowPlaying.entry.length > 0) {
|
||||||
|
msgs = data["subsonic-response"].nowPlaying.entry;
|
||||||
|
} else {
|
||||||
|
msgs[0] = data["subsonic-response"].nowPlaying.entry;
|
||||||
|
}
|
||||||
|
this.periodic.reset();
|
||||||
|
var sorted = msgs.sort(function (a, b) {
|
||||||
|
return a.minutesAgo - b.minutesAgo;
|
||||||
|
});
|
||||||
|
$.each(sorted, function (i, msg) {
|
||||||
|
var chathtml = '<div class=\"msg\">';
|
||||||
|
chathtml += '<span class=\"user\">' + msg.username + '</span></br>';
|
||||||
|
chathtml += '<span class=\"artist\">' + msg.artist + '</span> - ';
|
||||||
|
chathtml += '<span class=\"title\">' + msg.title + '</span>';
|
||||||
|
chathtml += '</div>';
|
||||||
|
$(chathtml).appendTo("#NowPlayingList");
|
||||||
|
});
|
||||||
|
updaterNowPlayingData = $.param(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function stopUpdateNowPlaying() {
|
||||||
|
updaterNowPlaying.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
function search(type, query) {
|
function search(type, query) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|
52
js/app.js
52
js/app.js
|
@ -62,57 +62,5 @@ function loadTabContent(tab) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var updaterNowPlaying;
|
|
||||||
var updaterNowPlayingData;
|
|
||||||
function updateNowPlaying() {
|
|
||||||
updaterNowPlaying = $.periodic({ period: 4000, decay: 1.5, max_period: 1800000 }, function () {
|
|
||||||
$.ajax({
|
|
||||||
periodic: this,
|
|
||||||
url: baseURL + '/getNowPlaying.view?u=' + username + '&p=' + passwordenc + '&v=' + version + '&c=' + applicationName + '&f=jsonp',
|
|
||||||
method: 'GET',
|
|
||||||
dataType: 'jsonp',
|
|
||||||
timeout: 10000,
|
|
||||||
beforeSend: function (req) {
|
|
||||||
req.setRequestHeader('Authorization', auth);
|
|
||||||
},
|
|
||||||
success: function (data) {
|
|
||||||
if (data["subsonic-response"].nowPlaying.entry === undefined) {
|
|
||||||
this.periodic.increment();
|
|
||||||
$("#NowPlayingList").empty();
|
|
||||||
var chathtml = '<div class=\"msg\">';
|
|
||||||
chathtml += '<span class=\"user\">Nothing :(</span></br>';
|
|
||||||
chathtml += '</div>';
|
|
||||||
$(chathtml).appendTo("#NowPlayingList");
|
|
||||||
} else if (updaterNowPlayingData === $.param(data)) {
|
|
||||||
this.periodic.increment();
|
|
||||||
} else {
|
|
||||||
$("#NowPlayingList").empty();
|
|
||||||
var msgs = [];
|
|
||||||
if (data["subsonic-response"].nowPlaying.entry.length > 0) {
|
|
||||||
msgs = data["subsonic-response"].nowPlaying.entry;
|
|
||||||
} else {
|
|
||||||
msgs[0] = data["subsonic-response"].nowPlaying.entry;
|
|
||||||
}
|
|
||||||
this.periodic.reset();
|
|
||||||
var sorted = msgs.sort(function (a, b) {
|
|
||||||
return a.minutesAgo - b.minutesAgo;
|
|
||||||
});
|
|
||||||
$.each(sorted, function (i, msg) {
|
|
||||||
var chathtml = '<div class=\"msg\">';
|
|
||||||
chathtml += '<span class=\"user\">' + msg.username + '</span></br>';
|
|
||||||
chathtml += '<span class=\"artist\">' + msg.artist + '</span> - ';
|
|
||||||
chathtml += '<span class=\"title\">' + msg.title + '</span>';
|
|
||||||
chathtml += '</div>';
|
|
||||||
$(chathtml).appendTo("#NowPlayingList");
|
|
||||||
});
|
|
||||||
updaterNowPlayingData = $.param(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function stopUpdateNowPlaying() {
|
|
||||||
updaterNowPlaying.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue