Created
November 24, 2024 04:12
-
-
Save voxxit/53d69f1ebcae42d7828242d1f15aa7bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ 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