RED.runtime = (function() { let state = "" let settings = {ui: false, enabled: false}; const STOPPED = "stopped" const STARTED = "started" return { init: function() { // refresh the current runtime status from server settings = Object.assign({}, settings, RED.settings.runtimeState); RED.runtime.requestState() // {id:"flows-run-state", started: false, state: "stopped", retain:true} RED.comms.subscribe("notification/flows-run-state",function(topic,msg) { RED.events.emit("flows-run-state",msg); RED.runtime.updateState(msg.state); }); }, get state() { return state }, get started() { return state === STARTED }, get states() { return { STOPPED, STARTED } }, updateState: function(newState) { state = newState; // disable pointer events on node buttons (e.g. inject/debug nodes) $(".red-ui-flow-node-button").toggleClass("red-ui-flow-node-button-stopped", state === STOPPED) // show/hide Start/Stop based on current state if(settings.enabled === true && settings.ui === true) { RED.menu.setVisible("deploymenu-item-runtime-stop", state === STARTED) RED.menu.setVisible("deploymenu-item-runtime-start", state === STOPPED) } }, requestState: function(callback) { $.ajax({ headers: { "Accept":"application/json" }, cache: false, url: 'flows/state', success: function(data) { RED.runtime.updateState(data.state) if(callback) { callback(data.state) } } }); } } })()