Companion lib is the JavaScript client layer used to talk to Companion over WebSocket.
The client exposes:
CompanionClientIt is also attached to the browser window as window.CompanionClient.
Create a client and connect to the Companion WebSocket endpoint:
const client = new CompanionClient();
client.Core.connect("ws://localhost:19135");
Port must match your WebSocket server setting.
client.Core.on("connected", () => {
console.log("Connected to Companion");
});
client.Core.on("disconnected", () => {
console.log("Disconnected from Companion");
});
client.TTS.speak("Hello stream");
client.TTS.setVolume(0.8);
client.TTS.setRate(1.0);
client.Memory.set("score", 10, "SHORT");
client.Memory.get("score", "SHORT");
client.Core.on("memory_update", (payload) => {
console.log(payload);
});
client.Core.on("keypress", (data) => {
console.log("Key pressed", data);
});
Incoming packets are dispatched by packet type.
Use client.Core.on(type, callback) for both module events and trigger-style events.
Examples:
tts_statusstt_resultmemory_updatesongreco_detailstwitch_chat_messageDesigner preview loads companion-lib.js automatically from Companion preload assets.
That is why Designer components can directly use this API in browser-side scripts.
See Designer System for component workflow.
off when no longer needed.