summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-04-10 00:50:04 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2012-04-10 00:50:04 +0200
commit0691218f525e2546448613863c8bd684f80c297f (patch)
treefc1000f671c53e5833c81e339a39c8ae53f5bb99 /static
parent09233b67b008c8bf829ab99827672c5947d72396 (diff)
Lafargue: Make live update script more resilient to network failures.
Diffstat (limited to 'static')
-rw-r--r--static/js/lafargue.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/static/js/lafargue.js b/static/js/lafargue.js
index 33c8e90..f1198cb 100644
--- a/static/js/lafargue.js
+++ b/static/js/lafargue.js
@@ -1,9 +1,19 @@
jQuery(function($) {
if (WebSocket) {
var websocket_base = $('head').attr('data-websocket-base');
- var socket = new WebSocket(websocket_base + '/lafargue/events');
- socket.onmessage = function(event) {
- $('.lafargue-list').prepend(event.data);
+ var open_socket = function() {
+ var socket = new WebSocket(websocket_base + '/lafargue/events');
+ socket.onmessage = function(event) {
+ $('.lafargue-list').prepend(event.data);
+ };
+ var reconnect = function() {
+ window.setTimeout(function() {
+ open_socket();
+ socket.close();
+ }, 2000);
+ };
+ socket.onclose = reconnect;
};
+ open_socket();
}
});