obs-websocket-community-projects / obs-websocket-js

Consumes https://github.com/obsproject/obs-websocket
MIT License
680 stars 96 forks source link

How to close a connection (disconnect stop script working) #238

Closed Barabba11 closed 3 years ago

Barabba11 commented 3 years ago

Hi, I'm not an expert of HTML, I've managed to do what I need, simply change scene onclick event, but every time the click comes a new connection has been made to the port 4444, if I use the disconnection the script doesn't work more, how to solve it? Instead of open/close the connection on every click I would like to test if the connection is on already? Possibile? Even if the HTML page will change? (on every html page there is

<head>
    <script type="text/javascript" src="http://192.168.24.2/OBS-WebSocket.js"></script>
         ....

and I'm afraid the script will be "rebooted" every time, loosing the chance to know if it still connected or not.

Talking back about disconnect();

<script>
function setCurrentScene(scenename) {
const obs = new OBSWebSocket();
    obs.connect({address: '192.168.24.2:4444'
    });
    obs.on('ConnectionOpened', () => {
        obs.send('SetCurrentScene', {
                'scene-name': scenename
         });
    });
    //obs.disconnect();
    }
</script>

Works but if I uncomment the obs.disconnect(); it won't work never. Thank you