Skip to content

Commit

Permalink
WebSocket auto-reconnect fix
Browse files Browse the repository at this point in the history
  • Loading branch information
forkineye committed Nov 20, 2017
1 parent 391f0ec commit 0815721
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
7 changes: 2 additions & 5 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<tr><td width="33%">Total Packets</td><td><span id="pkts"></span></td></tr>
<tr><td width="33%">Sequence Errors</td><td><span id="serr"></span></td></tr>
<tr><td width="33%">Packet Errors</td><td><span id="perr"></span></td></tr>
<tr><td width="33%">Last Client IP</td><td><span id="clientip"></span></td></tr>
<tr><td width="33%">Source IP</td><td><span id="clientip"></span></td></tr>
</table>
</fieldset>
</div>
Expand Down Expand Up @@ -380,10 +380,7 @@ <h4 class="modal-title">Firmware Updating</h4>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">WebSocket Error</h4>
</div>
<div class="modal-body">
<p>WebSocket connection lost, attempting to reconnect...</p>
<h4 class="modal-title">WebSocket connection lost, attempting to reconnect...</h4>
<div class="bar"></div>
</div>
</div>
Expand Down
34 changes: 12 additions & 22 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ var wsTimerId;

var testing_modes = [ "t_disabled", "t_static", "t_chase", "t_rainbow", "t_view" ];

// Default modal properties
$.fn.modal.Constructor.DEFAULTS.backdrop = 'static';
$.fn.modal.Constructor.DEFAULTS.keyboard = false;

// jQuery doc ready
$(function() {
// Menu navigation for single page layout

$('ul.navbar-nav li a').click(function() {
// Highlight proper navbar item
$('.nav li').removeClass('active');
Expand All @@ -22,14 +25,10 @@ $(function() {
$('#navbar').removeClass('in').attr('aria-expanded', 'false');
$('.navbar-toggle').attr('aria-expanded', 'false');

$('#wserror').on('hidden.bs.modal', function() {
location.reload(true);
});

// Firmware selection and upload
$('#efu').change(function () {
$('#updatefw').submit();
$('#update').modal({backdrop: 'static', keyboard: false});
$('#update').modal();
});

// Color Picker
Expand Down Expand Up @@ -313,13 +312,11 @@ function wsConnect() {
wsReadyToSend();
};

ws.onerror = function() {
wsReconnect();
};

ws.onclose = function() {
wsReconnect();
$('#wserror').modal();
wsConnect();
};

} else {
alert('WebSockets is NOT supported by your Browser! You will need to upgrade your browser or downgrade to v2.0 of the ESPixelStick firmware.');
}
Expand All @@ -346,7 +343,7 @@ function wsCheckQueue(value) {
function wsProcessQueue() {
//check if currently waiting for a response
if(wsBusy) {
console.log('WS queue busy : ' + wsQueue);
//console.log('WS queue busy : ' + wsQueue);
} else {
//set wsBusy flag that we are waiting for a response
wsBusy=true;
Expand All @@ -360,7 +357,7 @@ function wsProcessQueue() {
}
wsTimerId=setTimeout(wsReadyToSend,timeout);
//send it.
console.log('WS sending ' + message);
//console.log('WS sending ' + message);
ws.send(message);
}
}
Expand All @@ -372,7 +369,7 @@ function wsReadyToSend() {
//send next message
wsProcessQueue();
} else {
console.log('WS queue empty');
//console.log('WS queue empty');
}
}

Expand Down Expand Up @@ -744,16 +741,9 @@ function test() {
}
}

function wsReconnect() {
$('#wserror').modal({backdrop: 'static', keyboard: false});
setTimeout(function() {
wsConnect();
}, 1000);
}

function showReboot() {
$('#update').modal('hide');
$('#reboot').modal({backdrop: 'static', keyboard: false});
$('#reboot').modal();
setTimeout(function() {
if($('#dhcp').prop('checked')) {
window.location.assign("/");
Expand Down

0 comments on commit 0815721

Please sign in to comment.