Skip to content
Permalink
Browse files
Do no periodic events when the webchannel is busy
  • Loading branch information
Roland Tapken committed Feb 8, 2018
1 parent 0fd04b1 commit c6e5e1fe3286889fdb3d9f5a375b8d9bb9850dec
Showing with 24 additions and 13 deletions.
  1. +16 −12 ui/js/ViewModel.js
  2. +8 −1 ui/js/webchannel.js
@@ -101,25 +101,29 @@
webchannel.call(window.cp750bridge.getState).done(state);
window.setInterval(function() {
// Update state every 10 seconds
webchannel.call(window.cp750bridge.getState).done(state).error(function(message) {
state('disconnected');
error(message);
});
if (webchannel.idle()) {
webchannel.call(window.cp750bridge.getState).done(state).error(function(message) {
state('disconnected');
error(message);
});
}
}, 30000);

window.setInterval(function() {
// Update current time
currentTime(new Date());

// Check if we need to autoconnect
if (state() !== 'connected') {
if (autoconnectTimeout() === 0) {
connect();
if (webchannel.idle()) {
// Check if we need to autoconnect
if (state() !== 'connected') {
if (autoconnectTimeout() === 0) {
connect();
}
autoconnectTimeout(autoconnectTimeout() - 1);
} else {
// Upload values
loadValues();
}
autoconnectTimeout(autoconnectTimeout() - 1);
} else {
// Upload values
loadValues();
}
}, 1000);

@@ -10,14 +10,18 @@
var ERROR_PREFIX = '⚠';

define(function() {
var active_calls = 0;

function call(method) {
var args = [];
for (var i = 1; i < arguments.length; i+=1) {
args.push(arguments[i]);
}
var result, error;
var listeners = [], errListeners = [];
active_calls++;
args.push(function(value) {
active_calls--;
var i;
if (typeof value === 'string' && value !== '' && value.charAt(0) === ERROR_PREFIX) {
error = value.substring(1);
@@ -60,7 +64,10 @@
}

return {
call: call
call: call,
idle: function() {
return active_calls == 0;
}
};
});
})();

0 comments on commit c6e5e1f

Please sign in to comment.