# HG changeset patch # User neko259 # Date 2015-05-07 08:18:49 # Node ID 24687cf59aeb83e5b43e203d4cf06f16a5bdcdde # Parent 3a63bd27458ba78d0eea890cb289d69ae2770ed6 Disable websocket by default. Use JS thread update when websockets are disabled instead of throwing an error diff --git a/boards/default_settings.py b/boards/default_settings.py --- a/boards/default_settings.py +++ b/boards/default_settings.py @@ -20,4 +20,4 @@ ARCHIVE_THREADS = True # Limit posting speed LIMIT_POSTING_SPEED = False # Thread update -WEBSOCKETS_ENABLED = True +WEBSOCKETS_ENABLED = False diff --git a/boards/static/js/thread_update.js b/boards/static/js/thread_update.js --- a/boards/static/js/thread_update.js +++ b/boards/static/js/thread_update.js @@ -50,36 +50,39 @@ function connectWebsocket() { var wsHost = metapanel.getAttribute('data-ws-host'); var wsPort = metapanel.getAttribute('data-ws-port'); - if (wsHost.length > 0 && wsPort.length > 0) - var centrifuge = new Centrifuge({ - "url": 'ws://' + wsHost + ':' + wsPort + "/connection/websocket", - "project": metapanel.getAttribute('data-ws-project'), - "user": wsUser, - "timestamp": metapanel.getAttribute('data-ws-token-time'), - "token": metapanel.getAttribute('data-ws-token'), - "debug": false - }); + if (wsHost.length > 0 && wsPort.length > 0) { + var centrifuge = new Centrifuge({ + "url": 'ws://' + wsHost + ':' + wsPort + "/connection/websocket", + "project": metapanel.getAttribute('data-ws-project'), + "user": wsUser, + "timestamp": metapanel.getAttribute('data-ws-token-time'), + "token": metapanel.getAttribute('data-ws-token'), + "debug": false + }); - centrifuge.on('error', function(error_message) { - console.log("Error connecting to websocket server."); - console.log(error_message); - return false; - }); - - centrifuge.on('connect', function() { - var channelName = 'thread:' + threadId; - centrifuge.subscribe(channelName, function(message) { - getThreadDiff(); + centrifuge.on('error', function(error_message) { + console.log("Error connecting to websocket server."); + console.log(error_message); + return false; }); - // For the case we closed the browser and missed some updates - getThreadDiff(); - $('#autoupdate').hide(); - }); + centrifuge.on('connect', function() { + var channelName = 'thread:' + threadId; + centrifuge.subscribe(channelName, function(message) { + getThreadDiff(); + }); - centrifuge.connect(); + // For the case we closed the browser and missed some updates + getThreadDiff(); + $('#autoupdate').hide(); + }); - return true; + centrifuge.connect(); + + return true; + } else { + return false; + } } /** @@ -204,7 +207,11 @@ function initAutoupdate() { if (location.protocol === 'https:') { return enableJsUpdate(); } else { - return connectWebsocket(); + if (connectWebsocket()) { + return true; + } else { + return enableJsUpdate(); + } } }