Skip to content

Commit f551189

Browse files
committed
web: add a button to reconnect to OBS
1 parent 4d7ba66 commit f551189

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

web/annunciators.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
</div>
3434

3535
<!--<div class="status">Status is updated here</div>-->
36+
<button class="reconnect-button" style="display: none" onclick="obs_init()">Reconnect</button>
3637
<!--<span class="synced" syncwith="scene">Scene</span>-->
3738
<!--<span class="synced" syncwith="ss_resolution">Resolution</span>-->
3839

web/director.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!DOCTYPE html>
22
<head>
3-
<title>OBS CR control</title>
3+
<title>OBS CR control (director)</title>
44
<meta charset="UTF-8">
55
<script src="https://cdn.jsdelivr.net/npm/obs-websocket-js"></script>
66
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js"></script>
@@ -33,6 +33,7 @@
3333
</div>
3434

3535
<div class="status">Status is updated here</div>
36+
<button class="reconnect-button" style="display: none" onclick="obs_init()">Reconnect</button>
3637
<!--<span class="synced" syncwith="scene">Scene</span>-->
3738
<!--<span class="synced" syncwith="ss_resolution">Resolution</span>-->
3839

web/small.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
</div>
3434

3535
<!--<div class="status">Status is updated here</div>-->
36+
<button class="reconnect-button" style="display: none" onclick="obs_init()">Reconnect</button>
3637
<!--<span class="synced" syncwith="scene">Scene</span>-->
3738
<!--<span class="synced" syncwith="ss_resolution">Resolution</span>-->
3839

web/tablet.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!DOCTYPE html>
22
<head>
3-
<title>OBS CR control (small)</title>
3+
<title>OBS CR control (tablet)</title>
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
66
<!-- boostrap -->
@@ -73,6 +73,9 @@
7373
<div>Playfile timer:</div>
7474
<span class="playfile timer centered" title="Timer for ongoing playback">-</span>
7575
</div>
76+
<div class="reconnect-button" style="display: none">
77+
<button class="centered" onclick="obs_init()">Reconnect</button>
78+
</div>
7679
<div style="font-size: 75%;">
7780
<div>Status:</div>
7881
<span class="status">Status</span>

web/util.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ async function obs_init () {
326326
}
327327

328328
// Create a new OBS WebSocket instance
329-
globalThis.obs = new OBSWebSocket();
329+
if (globalThis.obs === undefined) {
330+
globalThis.obs = new OBSWebSocket();
331+
}
330332
update_status(`Trying to connect to ${url}`)
331333

332334
try {
@@ -341,17 +343,22 @@ async function obs_init () {
341343
forEach('.ssl-warning', div => {
342344
div.style['display'] = 'none'
343345
})
346+
forEach('.reconnect-button', x => {x.style.display = 'none'})
344347
// Poll to keep the connection alive
345348
globalThis.obs_pinger = setInterval(async function() {console.log("Connection ping: ", (await obs.call('GetVersion')).obsVersion)},
346349
60000);
347-
obs.on('ConnectionClosed', e => { update_status(`OBS Disconnected (closed)!: ${e}`); obs_reconnect(); } )
348-
obs.on('ConnectionError', e => { update_status(`OBS Disconnected (error)!: ${e}`); obs_reconnect(); } )
350+
obs.on('ConnectionClosed', e => { obs_disconnected(e) } )
351+
obs.on('ConnectionError', e => { obs_disconnected(e) } )
349352
}
350353

351-
async function obs_reconnect(n) {
354+
async function obs_disconnected(e) {
352355
if (obs_pinger) {
353356
clearInterval(obs_pinger)
354357
}
358+
update_status(`OBS Disconnected (closed)!: ${e}`)
359+
forEach('.reconnect-button', x => {x.style.display = ''})
360+
}
361+
async function obs_reconnect(n) {
355362
return // disabled
356363
append_status("Reconnecting in 5s...")
357364
setTimeout(obs_init, 5000)

0 commit comments

Comments
 (0)