Skip to content

Commit c6e5e1f

Browse files
author
Roland Tapken
committed
Do no periodic events when the webchannel is busy
1 parent 0fd04b1 commit c6e5e1f

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

ui/js/ViewModel.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,25 +101,29 @@
101101
webchannel.call(window.cp750bridge.getState).done(state);
102102
window.setInterval(function() {
103103
// Update state every 10 seconds
104-
webchannel.call(window.cp750bridge.getState).done(state).error(function(message) {
105-
state('disconnected');
106-
error(message);
107-
});
104+
if (webchannel.idle()) {
105+
webchannel.call(window.cp750bridge.getState).done(state).error(function(message) {
106+
state('disconnected');
107+
error(message);
108+
});
109+
}
108110
}, 30000);
109111

110112
window.setInterval(function() {
111113
// Update current time
112114
currentTime(new Date());
113115

114-
// Check if we need to autoconnect
115-
if (state() !== 'connected') {
116-
if (autoconnectTimeout() === 0) {
117-
connect();
116+
if (webchannel.idle()) {
117+
// Check if we need to autoconnect
118+
if (state() !== 'connected') {
119+
if (autoconnectTimeout() === 0) {
120+
connect();
121+
}
122+
autoconnectTimeout(autoconnectTimeout() - 1);
123+
} else {
124+
// Upload values
125+
loadValues();
118126
}
119-
autoconnectTimeout(autoconnectTimeout() - 1);
120-
} else {
121-
// Upload values
122-
loadValues();
123127
}
124128
}, 1000);
125129

ui/js/webchannel.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010
var ERROR_PREFIX = '⚠';
1111

1212
define(function() {
13+
var active_calls = 0;
14+
1315
function call(method) {
1416
var args = [];
1517
for (var i = 1; i < arguments.length; i+=1) {
1618
args.push(arguments[i]);
1719
}
1820
var result, error;
1921
var listeners = [], errListeners = [];
22+
active_calls++;
2023
args.push(function(value) {
24+
active_calls--;
2125
var i;
2226
if (typeof value === 'string' && value !== '' && value.charAt(0) === ERROR_PREFIX) {
2327
error = value.substring(1);
@@ -60,7 +64,10 @@
6064
}
6165

6266
return {
63-
call: call
67+
call: call,
68+
idle: function() {
69+
return active_calls == 0;
70+
}
6471
};
6572
});
6673
})();

0 commit comments

Comments
 (0)