var starttime; var updater; function updateChatMessages() { updater = $.periodic({ period: 1000, decay: 1.5, max_period: 1800000 }, function () { $.ajax({ periodic: this, url: baseURL + '/getChatMessages.view?' + baseParams + '&since=' + starttime, method: 'GET', dataType: protocol, timeout: 10000, success: function (data) { if (data["subsonic-response"].chatMessages.chatMessage === undefined) { if (debug) { console.log('ChatMessages Delay: ' + this.periodic.cur_period); } this.periodic.increment(); } else { var msgs = []; if (data["subsonic-response"].chatMessages.chatMessage.length > 0) { msgs = data["subsonic-response"].chatMessages.chatMessage; } else { msgs[0] = data["subsonic-response"].chatMessages.chatMessage; } this.periodic.reset(); var sorted = msgs.sort(function (a, b) { return a.time - b.time; }); var x = 1; $.each(sorted, function (i, msg) { var chathtml = '