diff --git a/packages/lib/plugin.js b/packages/lib/plugin.js index 74a27960..a45bb7c9 100644 --- a/packages/lib/plugin.js +++ b/packages/lib/plugin.js @@ -329,6 +329,43 @@ class BaseMasterPlugin { */ onSlaveConnectionEvent(connection, event) { } + /** + * Called when an avent on a control connection happens + * + * The event param may be one of connect, drop, resume and close and has + * the following meaning: + * + * ##### connect + * + * Invoked when a new connection to the control has been established. + * + * ##### drop + * + * Invoked when a connection loss is detected between the master and a + * control. Plugins should respond to this event by throtteling + * messages it is sending to the given control connection to an absolute + * minimum. + * + * Messages sent over a dropped control connection will get queued up in + * memory on the master and sent all in one go when the connection is + * re-established again. + * + * ##### resume + * + * Invoked when a connection that had previously been dropped is + * re-established. + * + * ##### close + * + * Invoked when the connection to the control has been closed. + * + * @param {module:master/master~ControlConnection} connection - + * The connection the event occured on. + * @param {string} event - one of connect, drop, resume, and close. + */ + onControlConnectionEvent(connection, event) { } + + /** * Called when a slave is preparing to disconnect from the master * @@ -505,6 +542,42 @@ class BaseWebPlugin { * Called immediately after the class is instantiated. */ async init() { } + + /** + * Called when an event on the master connection happens + * + * The event param may be one of connect, drop, resume and close and has + * the following meaning: + * + * ##### connect + * + * Invoked when a new connection to the master has been established. + * + * ##### drop + * + * Invoked when a connection loss is detected between the control link + * and the master. Plugins should respond to this event by throtteling + * messages it is sending to the master to an absolute minimum. + * + * Messages sent over a dropped master connection will get queued up in + * memory in the browser and sent all in one go when the connection is + * re-established again. + * + * ##### resume + * + * Invoked when the connection that had previously dropped is + * re-established. + * + * ##### close + * + * Invoked when the connection to the master has been closed. This + * typically means the master server has shut down. Plugins should not + * send any messages that goes to or via the master server after the + * connection has been closed and before a new one is established. + * + * @param {string} event - one of connect, drop, resume and close + */ + onMasterConnectionEvent(event) { } } /** diff --git a/packages/master/master.js b/packages/master/master.js index 4f2e6ee6..e70b488b 100755 --- a/packages/master/master.js +++ b/packages/master/master.js @@ -696,6 +696,14 @@ class ControlConnection extends BaseConnection { debugEvents.off("message", this.ws_dumper); } }); + + for (let event of ["connect", "drop", "resume", "close"]) { + this.connector.on(event, () => { + for (let masterPlugin of masterPlugins.values()) { + masterPlugin.onControlConnectionEvent(this, event); + } + }); + } } async getMasterConfigRequestHandler() { diff --git a/packages/web_ui/src/util/websocket.jsx b/packages/web_ui/src/util/websocket.jsx index dd93c94a..1faeb891 100644 --- a/packages/web_ui/src/util/websocket.jsx +++ b/packages/web_ui/src/util/websocket.jsx @@ -73,6 +73,14 @@ export class Control extends libLink.Link { this.connector.on("close", () => { this.accountName = null; }); + + for (let event of ["connect", "drop", "resume", "close"]) { + this.connector.on(event, () => { + for (let plugin of this.plugins.values()) { + plugin.onMasterConnectionEvent(event); + } + }); + } } async logMessageEventHandler(message) {