From 0691218f525e2546448613863c8bd684f80c297f Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 10 Apr 2012 00:50:04 +0200 Subject: Lafargue: Make live update script more resilient to network failures. --- static/js/lafargue.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'static') 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(); } }); -- cgit v1.2.3