PluginSDK
The PluginSDK provides the core functionality for building plugins that communicate with the Logi Plugin Service. It handles WebSocket communication, action registration, message dispatching, and connection management.
Example
import { PluginSDK } from "@logitech/plugin-sdk";
import { MyCustomAction } from "./actions/my-custom-action";
const sdk = new PluginSDK();
// Register your custom actions
const myAction = new MyCustomAction();
sdk.registerAction(myAction);
// Connect to the Logi Plugin Service
await sdk.connect();
See
- CommandAction - For button-like actions
- AdjustmentAction - For rotary/slider actions
Constructors
Constructor
new PluginSDK(options: PluginSDKOptions): PluginSDK;
Creates a new PluginSDK instance with the specified configuration options.
Initializes the WebSocket client for communication with the Logi Plugin Service, sets up the message dispatcher for handling incoming messages, configures the logger with the specified log level, and establishes connection event handlers.
Parameters
options
PluginSDKOptions = ...
Configuration options for the SDK. If not provided, defaults to WARN log level.
Returns
PluginSDK
Example
import { PluginSDK, LoggerLevel } from "@logitech/plugin-sdk";
// Create SDK with default options (WARN log level)
const sdk = new PluginSDK();
// Create SDK with custom log level
const debugSdk = new PluginSDK({ logLevel: LoggerLevel.DEBUG });
// Create SDK with minimal logging
const quietSdk = new PluginSDK({ logLevel: LoggerLevel.ERROR });
See
- PluginSDKOptions - Available configuration options
- LoggerLevel - Available logging levels
Methods
connect()
connect(): Promise<void>;
Establishes connection to the Logi Plugin Service.
This method connects the plugin to the Logi Plugin Service via WebSocket, enables communication, and sets up graceful shutdown handling. Must be called after registering all actions.
Returns
Promise<void>
Promise that resolves when the connection is established
Throws
Will log errors if connection fails
Example
const sdk = new PluginSDK();
// Register actions first
sdk.registerAction(new MyAction());
// Then connect
try {
await sdk.connect();
console.log("Plugin connected successfully");
} catch (error) {
console.error("Failed to connect:", error);
}
registerAction()
registerAction(action: Action): void;
Registers an action with the plugin.
Actions must be registered before connecting to the Logi Plugin Service to be available for assignment to controls.
Parameters
action
The action instance to register
Returns
void
Example
import { CommandAction } from "@logitech/plugin-sdk";
class MyAction extends CommandAction {
readonly name = "my-action";
displayName = "My Action";
description = "Does something useful";
onKeyDown() {
console.log("Action executed!");
}
}
const myAction = new MyAction();
sdk.registerAction(myAction);
See
- Action - Base action class
- CommandAction - For button actions
- AdjustmentAction - For rotary/slider actions