-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcommon.js
54 lines (44 loc) · 1.74 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Shared code sits in here
window.addEventListener("load", init, false);
var obsHost = "127.0.0.1:4455"; // Change the server IP/port here
var obsPassword = "YourPasswordHERE"; // Set password here
var obsProtocol = "ws"; // change protocol here (if you know what you are doing)
const obs = new OBSWebSocket();
const urlParams = new URLSearchParams(window.location.search);
async function init() {
console.log("Trying to connect to obs...");
await attemptConnection();
}
// Handle websocket connection stuff
async function attemptConnection() {
// Read url, password and protocol from url params if set
obsProtocol = urlParams.has("secure") ? "wss" : obsProtocol;
obsHost = urlParams.get("host") ?? obsHost;
obsPassword = urlParams.get("password") ?? obsPassword;
// Try to connect to obs
try {
const {
obsWebSocketVersion,
negotiatedRpcVersion
} = await obs.connect(`${obsProtocol}://${obsHost}`, obsPassword, {rpcVersion: 1});
console.log(`Connected to obs-websocket ${obsWebSocketVersion} (using RPC ${negotiatedRpcVersion})`);
} catch (error) {
console.error("Failed to connect", error.code, error.message);
}
}
function changeElementColor(id, color) {
document.getElementById(id).style.color = color;
}
function changeElementVisibility(id, visibility) {
document.getElementById(id).style.visibility = visibility ? "":"hidden";
}
function changeElementContent(id, newContent) {
document.getElementById(id).innerText = newContent;
}
function TimecodeToTs(tc) {
parts = tc.split(":").map(x => parseFloat(x));
return parts[2]*1000 + parts[1]*60000 + parts[0]*3600000;
}
function trimTimecode(tc) {
return tc.split(".")[0];
}