Using the SDK

The sample plugin will already have the following code added to the index.js file. Here we will describe the functionality of the SDK class, but it is not required to run the sample plugin.

The SDK is available as a class called PluginSDK. It is imported through the @logitech/plugin-sdk library:

import { PluginSDK } from '@logitech/plugin-sdk';

Create an instance of the PluginSDK class:

const pluginSDK = new PluginSDK();

Register actions in the plugin using:

pluginSDK.registerAction(new MyTestAction());

All actions must be registered before connecting to LPS:

pluginSDK.registerAction(new MyTestAction());
pluginSDK.registerAction(new MyTestAction2());

await pluginSDK.connect();

The connect function will open a WebSocket client and connect to the Logi Plugin Service WebSocket server. The connect function is awaitable. If you wish to execute any code after the WebSocket has connected, you can await the function call:

await pluginSDK.connect();

myFunctionToRunAfterConnection();