summaryrefslogtreecommitdiffstats
path: root/static/script.js
diff options
context:
space:
mode:
authorraylu <raylu@mixpanel.com>2011-08-08 23:39:37 -0700
committerraylu <raylu@mixpanel.com>2011-08-08 23:39:37 -0700
commit1cae243a08909eb3f0b1a8b3ffcf2f0769ab438f (patch)
tree305d9262f011a832fb3665a91bb6a8a3a31927d9 /static/script.js
parent977e1512414fd547379ee23c02be165890a9284e (diff)
downloadaudioaxis-1cae243a08909eb3f0b1a8b3ffcf2f0769ab438f.tar.xz
suddenly, long polling works. no more web worker
Diffstat (limited to 'static/script.js')
-rw-r--r--static/script.js57
1 files changed, 38 insertions, 19 deletions
diff --git a/static/script.js b/static/script.js
index d6cad6e..d96650c 100644
--- a/static/script.js
+++ b/static/script.js
@@ -2,26 +2,9 @@ var player;
var litColor = '#eee';
var dimmedColor = '#555';
var interval;
+var timestamp = '0';
+
$(document).ready(function () {
- var poller = new Worker('/static/poller.js');
- poller.onmessage = function (e) {
- for (var i = 0; i < e.data.updates.length; i++) {
- update = e.data.updates[i];
- switch (update.action) {
- case 0: // see updates.go:addAction
- drawAdd(update);
- break;
- case 1:
- drawRemove(update.yid);
- break;
- case 2:
- case 3:
- drawMove(update.yid, update.action);
- break;
- }
- }
- }
- poller.postMessage({pid: pid});
$('body').click(function (e) {
if (e.target.id !== 'results') {
$('#results').slideUp(100);
@@ -36,8 +19,44 @@ $(document).ready(function () {
for (var i = 0; i < ids.length; i++) {
drawBar(ids[i]);
}
+ getUpdates();
});
+function getUpdates() {
+ $.ajax({
+ url: '/poll/',
+ dataType: 'json',
+ data: {pid: pid, timestamp: timestamp},
+ success: handleUpdates,
+ complete: getUpdates
+ });
+}
+
+function handleUpdates(data) {
+ var updates = [];
+ for (var i = 0; i < data.length; i++) {
+ timestamp = data[i].Timestamp;
+ var update = {
+ 'action': data[i].Action,
+ 'yid': data[i].Song.Yid,
+ 'title': data[i].Song.Title,
+ 'user': data[i].Song.User
+ }
+ switch (update.action) {
+ case 0: // see updates.go:addAction
+ drawAdd(update);
+ break;
+ case 1:
+ drawRemove(update.yid);
+ break;
+ case 2:
+ case 3:
+ drawMove(update.yid, update.action);
+ break;
+ }
+ }
+}
+
function drawBar(id) {
var canvas = document.getElementById('c_' + id);
if (!canvas) return;