Update Websocket + README.md
This commit is contained in:
1 parent
efc70ca5aa
commit
706515bc84
10 files changed
+188
-311
No files matched your search
+1
-18
@@ -27,7 +27,7 @@ export default class WebSocketClient {
|
||||
let method = 'dispatch'
|
||||
let target = eventName
|
||||
let msg = event
|
||||
if (event.data) {
|
||||
if (event && event.data) {
|
||||
msg = JSON.parse(event.data)
|
||||
}
|
||||
this.store[method](target, msg)
|
||||
@@ -38,13 +38,11 @@ export default class WebSocketClient {
|
||||
|
||||
this.instance.onopen = () => {
|
||||
if (this.store) this.passToStore('socket_on_open', event);
|
||||
this.keepAlive();
|
||||
};
|
||||
|
||||
this.instance.onclose = (e) => {
|
||||
window.console.log("Websocket Closed, reconnecting in "+this.reconnectInterval+"ms: ", e.reason);
|
||||
this.passToStore('socket_on_close', e);
|
||||
this.cancelKeepAlive();
|
||||
|
||||
setTimeout(() => {
|
||||
this.connect();
|
||||
@@ -70,21 +68,6 @@ export default class WebSocketClient {
|
||||
};
|
||||
}
|
||||
|
||||
keepAlive() {
|
||||
window.console.log('keepAlive start');
|
||||
window.console.log(this.instance);
|
||||
if (this.instance.readyState === this.instance.OPEN) {
|
||||
window.console.log('keepAlive send');
|
||||
this.sendObj('get_printer_info', {}, 'getKlipperInfo');
|
||||
}
|
||||
|
||||
this.timerId = setTimeout(this.keepAlive, this.keepAliveTimeout);
|
||||
}
|
||||
|
||||
cancelKeepAlive() {
|
||||
if (this.timerId) clearTimeout(this.timerId);
|
||||
}
|
||||
|
||||
sendObj (method, params, action = '') {
|
||||
let id = Math.floor(Math.random() * 10000) + 1
|
||||
this.wsData.push({
|
||||
|
||||
Reference in new issue
Block a user