test client: support "disconnect" notification
The webhooks module may now be used to retreive "ready" and "shutdown" state Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
279d53afde
commit
a17e1d4056
|
@ -218,6 +218,28 @@ function update_error(cmd, msg) {
|
||||||
update_term("Command [" + cmd + "] resulted in an error: " + msg);
|
update_term("Command [" + cmd + "] resulted in an error: " + msg);
|
||||||
console.log("Error processing " + cmd +": " + msg);
|
console.log("Error processing " + cmd +": " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handle_klippy_state(state) {
|
||||||
|
// Klippy state can be "ready", "disconnect", and "shutdown". This
|
||||||
|
// differs from Printer State in that it represents the status of
|
||||||
|
// the Host software
|
||||||
|
switch(state) {
|
||||||
|
case "ready":
|
||||||
|
// It would be possible to use this event to notify the
|
||||||
|
// client that the printer has started, however the server
|
||||||
|
// may not start in time for clients to receive this event.
|
||||||
|
// It is being kept in case
|
||||||
|
if (!klippy_ready)
|
||||||
|
update_term("Klippy Ready");
|
||||||
|
break;
|
||||||
|
case "shutdown":
|
||||||
|
// Either M112 was entered or there was a printer error. We
|
||||||
|
// probably want to notify the user and disable certain controls.
|
||||||
|
klippy_ready = false;
|
||||||
|
update_term("Klipper has shutdown, check klippy.log for info");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
//***********End UI Update Functions****************/
|
//***********End UI Update Functions****************/
|
||||||
|
|
||||||
//***********Websocket-Klipper API Functions (JSON-RPC)************/
|
//***********Websocket-Klipper API Functions (JSON-RPC)************/
|
||||||
|
@ -553,6 +575,8 @@ function handle_status_update(status) {
|
||||||
update_streamdiv(name, attr, val);
|
update_streamdiv(name, attr, val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "webhooks.state":
|
||||||
|
handle_klippy_state(val);
|
||||||
default:
|
default:
|
||||||
update_streamdiv(name, attr, val);
|
update_streamdiv(name, attr, val);
|
||||||
|
|
||||||
|
@ -562,19 +586,7 @@ function handle_status_update(status) {
|
||||||
}
|
}
|
||||||
json_rpc.register_method("notify_status_update", handle_status_update);
|
json_rpc.register_method("notify_status_update", handle_status_update);
|
||||||
|
|
||||||
function handle_klippy_state(state) {
|
function handle_klippy_disconnected() {
|
||||||
// Klippy state can be "ready", "disconnect", and "shutdown". This
|
|
||||||
// differs from Printer State in that it represents the status of
|
|
||||||
// the Host software
|
|
||||||
switch(state) {
|
|
||||||
case "ready":
|
|
||||||
// It would be possible to use this event to notify the
|
|
||||||
// client that the printer has started, however the server
|
|
||||||
// may not start in time for clients to receive this event.
|
|
||||||
// It is being kept in case
|
|
||||||
update_term("Klippy Ready");
|
|
||||||
break;
|
|
||||||
case "disconnect":
|
|
||||||
// Klippy has disconnected from the MCU and is prepping to
|
// Klippy has disconnected from the MCU and is prepping to
|
||||||
// restart. The client will receive this signal right before
|
// restart. The client will receive this signal right before
|
||||||
// the websocket disconnects. If we need to do any kind of
|
// the websocket disconnects. If we need to do any kind of
|
||||||
|
@ -585,16 +597,8 @@ function handle_klippy_state(state) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
get_klippy_info();
|
get_klippy_info();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
break;
|
|
||||||
case "shutdown":
|
|
||||||
// Either M112 was entered or there was a printer error. We
|
|
||||||
// probably want to notify the user and disable certain controls.
|
|
||||||
klippy_ready = false;
|
|
||||||
update_term("Klipper has shutdown, check klippy.log for info");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
json_rpc.register_method("notify_klippy_disconnected", handle_klippy_disconnected);
|
||||||
json_rpc.register_method("notify_klippy_state_changed", handle_klippy_state);
|
|
||||||
|
|
||||||
function handle_file_list_changed(file_info) {
|
function handle_file_list_changed(file_info) {
|
||||||
// This event fires when a client has either added or removed
|
// This event fires when a client has either added or removed
|
||||||
|
|
Loading…
Reference in New Issue