OBS Websocket Connect Webpage Example Needed

ashchopra

New Member
Hi,

I have OBS v29.1.3 installed. It already has websockets inbuilt, which I have configured. I also have a profile ready and working for recording.
I am not good at websocket programming, but I would like my webpage to have a button, that will record via the profile setup on my PC.
Assume Local Host at 192.168.1.10:4455 and password as 'XXX'
Can someone point me to the place where i can understand how to do this. Possibly a sample HTML/Javascript sample/example implementing this.

I got ChatGPT to give me something, as below, it just wont work, and it cant do any more :-(

Thanks in advance, The Code I am trying and wont work, Follows:
<!DOCTYPE html>
<html>
<head>
<title>OBS Recording Button</title>
</head>
<body>
<button id="recordButton">Start Recording</button>
<script>
// Create a new WebSocket connection to OBS with the server password
const obsSocket = new WebSocket('ws://192.168.1.10:4455', 'XXX');
// When the connection is established
obsSocket.onopen = () => {
console.log('Connected to OBS WebSocket');
// Retrieve the record button element
const recordButton = document.getElementById('recordButton');
// Add click event listener to the record button
recordButton.addEventListener('click', () => {
// Send the command to start recording using the "RTR" profile
obsSocket.send(JSON.stringify({
"request-type": "StartRecording",
"message-id": "start-recording",
"profile": "RTR"
}));
console.log('Recording started');
});
};
// When a message is received from OBS
obsSocket.onmessage = (event) => {
const message = JSON.parse(event.data);
console.log('Received message from OBS:', message);
};
// When an error occurs
obsSocket.onerror = (error) => {
console.error('OBS WebSocket error:', error);
};
// When the connection is closed
obsSocket.onclose = () => {
console.log('Disconnected from OBS WebSocket');
};
</script>
</body>
</html>
 

ashchopra

New Member
You can try to look at:
(compressed version of it was named "obs-web-gh-pages" as far as I remember)
Thanks a ton Suslik. I had checked that out sometime back, but internally it uses a whole lot of minified js, which i could not figure out. Its interface also appears to be with Js as I cant see any html in the page souece. I was wondering how to get the code to a single button to start and stop recording with a specified profile. Is there any error in my code above? I get no errors on the console or the browser debugger?
 

ashchopra

New Member
Hi suslik, I managed to get obs-websocket-js to work on a local html file and it records as i wanted. however, when i moved the code to my web app which is online, there is a new problem. The browser due to its security settings does not allow the websocket connection, saying its insecure. I tried changing the URL to http from https, but the problem remains. I believe there may be some way out using some sort of proxy and redirect the OBS given URL for the websocket connection to a local host connection. But i cant figure out how to do that, due to my limited knowledge. I have been researching on this for some time now. but no clue as of now. Any pointers?
 

upandcumming

New Member
Hi suslik, I managed to get obs-websocket-js to work on a local html file and it records as i wanted. however, when i moved the code to my web app which is online, there is a new problem. The browser due to its security settings does not allow the websocket connection, saying its insecure. I tried changing the URL to http from https, but the problem remains. I believe there may be some way out using some sort of proxy and redirect the OBS given URL for the websocket connection to a local host connection. But i cant figure out how to do that, due to my limited knowledge. I have been researching on this for some time now. but no clue as of now. Any pointers?
Any chance you could share your local HTML file please?
 

thasneem077

New Member
Hi suslik, I managed to get obs-websocket-js to work on a local html file and it records as i wanted. however, when i moved the code to my web app which is online, there is a new problem. The browser due to its security settings does not allow the websocket connection, saying its insecure. I tried changing the URL to http from https, but the problem remains. I believe there may be some way out using some sort of proxy and redirect the OBS given URL for the websocket connection to a local host connection. But i cant figure out how to do that, due to my limited knowledge. I have been researching on this for some time now. but no clue as of now. Any pointers?

Hi, can I have the source code please.
 
Top