Skip to content

How to connect remote plugins?

This guide is for users who want to run the proxy plugin in Thymian and connect remote plugins via WebSocket.

The proxy plugin starts a WebSocket server that remote clients can connect to. After a short handshake, a remote plugin can:

  • send events to Thymian,
  • trigger actions in Thymian and receive results,
  • receive events from Thymian, and
  • handle actions requested by Thymian and reply.

For protocol details, see the Plugin Developers Guide.

Register the proxy plugin in your Thymian setup and configure the port and known remote plugins:

import { Thymian, TextLogger } from '@thymian/core';
import { websocketProxyPlugin } from '@thymian/plugin-websocket-proxy';
const thymian = new Thymian();
thymian.register(websocketProxyPlugin, {
port: 51234, // optional, default is 51234
plugins: [
{
name: 'remote-plugin',
token: 'secret-token', // optional
required: false, // optional, if set to true, Thymian waits for the plugin to connect before starting
options: {}, // options that are sent to the remote plugin during the handshake,
},
],
});
await thymian.ready();
// ... application is running, remote plugins can connect
// Shutdown
await thymian.close();

The plugin takes an option object with the following properties:

The port of the Websocket server.

List of known remote plugins. Each entry of this list is an object with the following properties:

Unique name of the remote plugin. Used to identify the plugin in the handshake.

If a token is set, it is checked during the handshake, if the corresponding remote plugins sends the same token.

If set to true, Thymian waits for the plugin to connect before starting.

Options that are sent to the remote plugin during the handshake.

clientTimeoutMs (optional) - Default: 4000

Section titled “clientTimeoutMs (optional) - Default: 4000”

Number of milliseconds to wait for a remote plugin to connect before throwing a timeout error.

Configuration via Thymian configuration file

Section titled “Configuration via Thymian configuration file”

The plugin can also be configured via the Thymian configuration file if Thymian is used via its CLI. Thereby all options described above can be used.