Writing plugins
A plugin is a TypeScript file that runs in Keyside's sandbox. It adds actions to the palette, reacts to key presses and can change how its keys look.
Start a plugin
npm create keyside-plugin my-plugin
cd my-plugin
npm install
npm run build # bundles src/main.ts into main.js
npm testYou get:
manifest.json what the plugin is and what it may do
src/main.ts the code
test/main.test.ts tests that run without KeysideThe manifest
{
"id": "com.example.counter",
"name": "Counter",
"version": "1.0.0",
"author": "You",
"prefix": "counter",
"host": "^1.0",
"entry": "main.js",
"permissions": { "net": ["{host}:{port}"] },
"connection": {
"type": "object",
"properties": {
"host": { "type": "string", "title": "Address", "default": "127.0.0.1" },
"port": { "type": "integer", "title": "Port", "default": 8080 },
"password": { "type": "string", "format": "secret", "title": "Password" }
}
},
"actions": [
{
"id": "add",
"name": "Add one",
"icon": "plus",
"settings": { "type": "object", "properties": { "step": { "type": "integer", "title": "Step", "default": 1 } } }
}
],
"variables": [{ "name": "count", "title": "Count", "type": "number" }]
}- id: reverse domain name you control.
- prefix: short name for your variables, so
countbecomes{counter.count}. - connection: settings for the whole plugin, shown in the Plugins panel.
"format": "secret"keeps a value in the system keychain."x-hidden": truehides a field you manage yourself, like a sign-in session. - setup: up to 8 numbered steps shown above the connection settings. Write
[text](https://…)for a link and`text`for something people should copy, like a redirect URL.{redirect}becomes the return addresshost.authorizeuses on this PC. Field descriptions andhost.statusdetails take the same markup. - actions: each has its own settings form. Use
"x-options": "dynamic"on a text field to fill a dropdown from your plugin."x-template": trueon a text or arguments field lets people use Keyside variables, like{obs.scene}. Keyside fills them in before your plugin sees the value."x-showWhen": { "mode": ["set", "add"] }shows a text field only while themodefield has one of those values.
- icon: any name from the editor's icon picker.
Permissions
Plugins get nothing by default. Ask for what you need:
| Permission | Allows |
|---|---|
"net": ["api.example.com"] |
Connections to that host |
"net": ["{host}:{port}"] |
Connections to the address in your connection settings |
"udp": true |
Sending UDP to hosts in net, through host.udp() |
"ipc": ["discord"] |
Talking to the Discord app through host.ipc |
"run": [["equibop", "--toggle-mic"]] |
Running those exact commands through host.run(). Only for plugins that ship with Keyside |
Wildcards aren't allowed. People see this list before installing, and again if an update asks for more.
The code
import { definePlugin, setting, type Host } from "@keyside/sdk";
let host: Host;
let count = 0;
export default definePlugin({
start(h) {
host = h;
host.status("connected");
host.setVar("count", count);
},
actions: {
add: {
press({ key, settings }) {
count += setting(settings, "step", 1);
key.set({ badge: String(count), tone: count > 9 ? "accent" : undefined });
host.setVar("count", count);
},
},
},
});Actions
| Handler | Called when |
|---|---|
press(step) |
The key is pressed |
release(step) |
The key is let go (push to talk) |
slide({ value }) |
A slider is let go, value is 0 to 1. The next value waits until this one is handled |
options(field, settings) |
The editor needs a dynamic dropdown |
appear(key) / disappear(key) |
A key using this action is added or removed |
Throw an error to show it as a toast on the phone.
Add batch(steps, phase) to the definition to handle several steps of one key in one go, like OBS does for "mute all".
Next to start(host), the definition can have connectionChanged(host) for when the connection settings were edited, and stop() for when Keyside stops the plugin. Close your sockets there.
Keys
host.keys(action?) lists your placed keys and host.key(id) finds one. key.set(view) changes how a key looks, key.clear() resets it. key.label and key.icon are what the person chose in the editor.
| Field | Shows |
|---|---|
label, sub |
Text lines |
icon |
Icon name |
badge, badgeTone |
Small tag, like ON AIR |
tone |
accent or danger outline, success, warning, info, muted |
meta |
Small text top right |
since |
A running clock from this time (ms) |
value, progress |
0 to 1, for sliders and bars |
image |
PNG, JPEG, WebP, GIF or SVG data URL, up to 350 KB |
disabled |
Greyed out and not pressable |
set replaces the whole view, so pass every field you want shown. Updates are batched, so calling it often is fine.
Host
| Call | Does |
|---|---|
host.connection |
Current connection settings, secrets included |
host.status(state, detail?, pills?) |
Connection state in the deck header, plus up to three pills like REC |
host.setVar(name, value) |
Publishes {prefix.name} |
host.feed(name, item) |
Adds a line to a feed declared in the manifest (chat, alerts) |
host.unfeed(name, match) |
Takes lines off a feed, such as deleted chat messages |
host.toast(text, tone?) |
Short message on every device |
host.saveConnection(values) |
Saves values like tokens into the connection settings |
host.openBrowser(url) |
Opens an https page on the PC |
host.authorize(url) |
Browser sign-in with a redirect back to Keyside. Returns the code and redirect URI |
host.udp(host, port, bytes) |
Sends a UDP datagram |
host.run(argv) |
Runs one of the commands listed under run |
host.ipc.open/send/on |
Talks to a local app through a bridge from ipc |
host.log.info(...) |
Writes to the Keyside log |
host.dataDir |
A folder only this plugin can read and write |
host.pluginId, host.prefix, host.locale |
Your id and prefix, and the language the editor uses |
console.log goes to the log too, since the plugin's output is reserved for talking to Keyside.
Chat and alerts
A feed item needs text and may have author and color (#rrggbb). Chat plugins should also say what the line is and who wrote it, so chat triggers work with them:
host.feed("chat", { author: "Moss", text: "!brb", kind: "chat", source: "twitch", roles: ["mod", "sub"] });
host.feed("events", { author: "Fern", text: "redeemed Hydrate", kind: "redeem", source: "twitch", reward: "Hydrate", input: "with ice" });| Field | Holds |
|---|---|
kind |
chat for messages, redeem for channel point redemptions. follow, sub, cheer, raid or alert for other lines |
source |
twitch, youtube or kick. Without it, your plugin prefix |
roles |
Any of broadcaster, mod, vip and sub (channel members count as sub) |
reward |
The reward title, for redemptions |
input |
What the viewer typed with a redemption |
Items without these fields still work: lines in a feed called chat count as chat from a viewer without roles.
When a moderator deletes a message, times someone out or clears chat, take the lines off again. Give chat lines an id (the message id from the service, up to 100 characters) and remove them by id, by author, or all at once:
host.feed("chat", { id: msg.id, author: "Moss", text: "hello", kind: "chat" });
host.unfeed("chat", { ids: [msg.id] });
host.unfeed("chat", { author: "Moss" }); // spelled the same as on the lines
host.unfeed("chat", { all: true });Ids stay on the PC; phones never see them. Plugins that use unfeed need "host": "^1.1" in the manifest.
Testing
@keyside/sdk/testing runs your plugin in memory:
import { createTestHost } from "@keyside/sdk/testing";
import plugin from "../src/main.ts";
const h = createTestHost(plugin);
await h.start();
await h.sync([{ id: "k1", action: "add", settings: { step: 2 } }]);
await h.press("k1", "add", { step: 2 });
await h.settle();
assert.equal(h.view("k1")?.badge, "2");Import the testing module before your plugin. For network plugins, start a fake server in the test, like the bundled plugins do.
Share it
keyside plugin keygen my-key.json # once; keep this file private
keyside plugin pack . --key my-key.jsonThat writes a signed .pdp file. Anyone can install it with Plugins > Install from file. Signed updates must use the same key.
To list it in the registry, open a pull request that adds an entry to registry/index.json with the download URL, SHA-256 and your public key.
Limits
- 192 MB memory, 200 messages a second.
- A plugin that crashes five times in five minutes is turned off.
- No file access outside its own data folder, no subprocesses, no native code.