diff --git a/js/api.js b/js/api.js
index b196d28..1e93b91 100644
--- a/js/api.js
+++ b/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 = '
';
+ chathtml += 'Nothing :(';
+ chathtml += '
';
+ $(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 = '';
+ chathtml += '' + msg.username + '';
+ chathtml += '' + msg.artist + ' - ';
+ chathtml += '' + msg.title + '';
+ chathtml += '
';
+ $(chathtml).appendTo("#NowPlayingList");
+ });
+ updaterNowPlayingData = $.param(data);
+ }
+ }
+ });
+ });
+}
+function stopUpdateNowPlaying() {
+ updaterNowPlaying.cancel();
+}
function search(type, query) {
$.ajax({
diff --git a/js/app.js b/js/app.js
index 25ddfd1..dd8e1dd 100644
--- a/js/app.js
+++ b/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 = '';
- chathtml += 'Nothing :(';
- chathtml += '
';
- $(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 = '';
- chathtml += '' + msg.username + '';
- chathtml += '' + msg.artist + ' - ';
- chathtml += '' + msg.title + '';
- chathtml += '
';
- $(chathtml).appendTo("#NowPlayingList");
- });
- updaterNowPlayingData = $.param(data);
- }
- }
- });
- });
-}
-function stopUpdateNowPlaying() {
- updaterNowPlaying.cancel();
-}