Skip to content

Instantly share code, notes, and snippets.

@voxxit
Created November 24, 2024 04:12
Show Gist options
  • Save voxxit/53d69f1ebcae42d7828242d1f15aa7bd to your computer and use it in GitHub Desktop.
Save voxxit/53d69f1ebcae42d7828242d1f15aa7bd to your computer and use it in GitHub Desktop.
// $ npm install obs-websocket-js
// $ node countdown-websocket.js
//
import OBSWebSocket from "obs-websocket-js";
async function testConnection() {
const obs = new OBSWebSocket();
try {
console.log("Connecting to OBS...");
await obs.connect("ws://localhost:4455", "test");
console.log("Successfully connected to OBS");
// Test vendor request
const response = await obs.call("CallVendorRequest", {
vendorName: "ashmanix-countdown-timer",
requestType: "get_timer_state",
});
console.log("Timer state:", response);
// Set up event listener
obs.on("VendorEvent", ({ vendorName, eventType, eventData }) => {
if (vendorName !== "ashmanix-countdown-timer") return;
console.log("Received vendor event:", { eventType, eventData });
});ts
// Try starting the timer
await obs.call("CallVendorRequest", {
vendorName: "ashmanix-countdown-timer",
requestType: "period_play",
});
console.log("Timer started");
// Keep the process running to receive events
await new Promise((resolve) => setTimeout(resolve, 10000));
} catch (error) {
console.error("Error:", error);
} finally {
await obs.disconnect();
console.log("Disconnected from OBS");
}
}
testConnection();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment