Example of an empty plugin.
'use strict';
/* eslint-disable no-empty-function, no-unused-vars */
/**
* @constructor
* @struct
* @param {!PluginContext} context
*/
function EmptyPlugin(context) {
this.onStart = () => {};
/**
* @param {!WebSocketConnection} connection
*/
this.onNewConnection = connection => {};
/**
* @param {!WebSocketMessage} message
* @param {!WebSocketConnection} connection
*/
this.onMessage = (message, connection) => {};
/**
* @param {!WebSocketMessage} message
* @param {!WebSocketConnection} connection
*/
this.onJsonMessage = (message, connection) => {};
/**
* @param {!WebSocketConnection} connection
*/
this.onConnectionClosed = connection => {};
this.onStop = () => {};
}
module.exports = {
name: 'empty',
description: 'This plugin does nothing.',
createWorker: context => new EmptyPlugin(context)
};
Parameter | Type | Description |
---|---|---|
name | string |
The unique name of the plugin. Prefer a URL safe name. |
description | string |
An optional information about the plugin. Will be displayed on the user interface. |
createWorker | function(context:PluginContext):PluginWorker |
The returned plugin worker will run in the context of one instance. |
Property | Type | Description |
---|---|---|
onStart | function() |
Optional. Called when the instance started. |
onNewConnection | function(connection:WebSocketConnection) |
Optional. Called whenever a client has an WebSocket connection established. |
onMessage | function(message:WebSocketMessage) |
Optional. Called when a client has send data over the WebSocket connection to the instance. |
onJsonMessage | function(message:WebSocketMessage) |
Optional. Like onMessage, but the WebSocketMessage provides an object (deserialized) instead of a string. |
onConnectionClosed | function(connection:WebSocketConnection) |
Optional. Called when a client closed the connection. |
onStop | function() |
Optional. Called when the instance stopped. |
A received message.
Property | Type | Description |
---|---|---|
data | string | object |
The message data. onJsonMessage provides an object when data was successfully parsed. |
Property | Type | Description |
---|---|---|
send | function(message:string) |
Sends a message on that connection. |
Property | Type | Description |
---|---|---|
instance | The WebSocket server instance that uses this plugin. |
|
log | A logger running in the context of this plugin. |
Property | Type | Description |
---|---|---|
id | string |
The WebSocket server instance ID. |
name | string |
The WebSocket server instance name. |
port | number |
The WebSocket server instance port. |
plugins | Array<string> |
The list of assigned plugins. |
state | string |
The WebSocket server instance state (starting, stopped, running, stopping, error). |
Property | Type | Description |
---|---|---|
info | function(message, [data]) |
Logs the message with optional data as INFO to the plugin log file. |
warn | function(message, [data]) |
Logs the message with optional data as WARN to the plugin log file. |
error | function(message, [data]) |
Logs the message with optional data as ERROR to the plugin log file. |
debug | function(message, [data]) |
Logs the message with optional data as DEBUG to the plugin log file. |