UNPKG

@elgato/streamdeck

Version:

The official Node.js SDK for creating Stream Deck plugins.

69 lines (68 loc) 1.73 kB
import { deviceStore } from "../devices/store.js"; /** * Provides information about an instance of a Stream Deck action. */ export class ActionContext { /** * Device the action is associated with. */ #device; /** * Source of the action. */ #source; /** * Initializes a new instance of the {@link ActionContext} class. * @param source Source of the action. */ constructor(source) { this.#source = source; const device = deviceStore.getDeviceById(source.device); if (!device) { throw new Error(`Failed to initialize action; device ${source.device} not found`); } this.#device = device; } /** * Type of the action. * - `Keypad` is a key. * - `Encoder` is a dial and portion of the touch strip. * @returns Controller type. */ get controllerType() { return this.#source.payload.controller; } /** * Stream Deck device the action is positioned on. * @returns Stream Deck device. */ get device() { return this.#device; } /** * Action instance identifier. * @returns Identifier. */ get id() { return this.#source.context; } /** * Manifest identifier (UUID) for this action type. * @returns Manifest identifier. */ get manifestId() { return this.#source.action; } /** * Converts this instance to a serializable object. * @returns The serializable object. */ toJSON() { return { controllerType: this.controllerType, device: this.device, id: this.id, manifestId: this.manifestId, }; } }