@elgato/streamdeck
Version:
The official Node.js SDK for creating Stream Deck plugins.
70 lines (69 loc) • 3.1 kB
JavaScript
import { connection } from "./connection.js";
import { ApplicationEvent } from "./events/application-event.js";
import { Event } from "./events/event.js";
import { DidReceiveDeepLinkEvent, } from "./events/index.js";
import { requiresSDKVersion, requiresVersion } from "./validation.js";
/**
* Occurs when a monitored application is launched. Monitored applications can be defined in the manifest via the {@link Manifest.ApplicationsToMonitor} property.
* See also {@link onApplicationDidTerminate}.
* @param listener Function to be invoked when the event occurs.
* @returns A disposable that, when disposed, removes the listener.
*/
export function onApplicationDidLaunch(listener) {
return connection.disposableOn("applicationDidLaunch", (ev) => listener(new ApplicationEvent(ev)));
}
/**
* Occurs when a monitored application terminates. Monitored applications can be defined in the manifest via the {@link Manifest.ApplicationsToMonitor} property.
* See also {@link onApplicationDidLaunch}.
* @param listener Function to be invoked when the event occurs.
* @returns A disposable that, when disposed, removes the listener.
*/
export function onApplicationDidTerminate(listener) {
return connection.disposableOn("applicationDidTerminate", (ev) => listener(new ApplicationEvent(ev)));
}
/**
* Occurs when a deep-link message is routed to the plugin from Stream Deck. One-way deep-link messages can be sent to plugins from external applications using the URL format
* `streamdeck://plugins/message/<PLUGIN_UUID>/{MESSAGE}`.
* @param listener Function to be invoked when the event occurs.
* @returns A disposable that, when disposed, removes the listener.
*/
export function onDidReceiveDeepLink(listener) {
requiresVersion(6.5, connection.version, "Receiving deep-link messages");
return connection.disposableOn("didReceiveDeepLink", (ev) => listener(new DidReceiveDeepLinkEvent(ev)));
}
/**
* Occurs when the computer wakes up.
* @param listener Function to be invoked when the event occurs.
* @returns A disposable that, when disposed, removes the listener.
*/
export function onSystemDidWakeUp(listener) {
return connection.disposableOn("systemDidWakeUp", (ev) => listener(new Event(ev)));
}
/**
* Opens the specified `url` in the user's default browser.
* @param url URL to open.
* @returns `Promise` resolved when the request to open the `url` has been sent to Stream Deck.
*/
export function openUrl(url) {
return connection.send({
event: "openUrl",
payload: {
url,
},
});
}
/**
* Gets the secrets associated with the plugin.
* @returns `Promise` resolved with the secrets associated with the plugin.
*/
export function getSecrets() {
requiresVersion(6.9, connection.version, "Secrets");
requiresSDKVersion(3, "Secrets");
return new Promise((resolve) => {
connection.once("didReceiveSecrets", (ev) => resolve(ev.payload.secrets));
connection.send({
event: "getSecrets",
context: connection.registrationParameters.pluginUUID,
});
});
}