-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdisplay1.html
262 lines (239 loc) · 11.5 KB
/
display1.html
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Streaming Status</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" integrity="sha512-Kc323vGBEqzTmouAECnVceyQqyqdsSiqLQISBL29aUW4U/M7pSPA/gEUZQqv1cwx4OnYxTxve5UMg5GT6L4JJg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
body{margin:0; padding:0;background-color:#000;color:#fff}
.wrapper{width:100%;height:100%;padding:1% 0 0%;}
.stream{width:100%;height:30%;}
.timecode{width:100%;height:15%;padding-bottom:4%}
.data{width:50%;height:45%;float:left;padding-right:0%}
.data2{width:40%;height:45%;float:right;padding-left:5%}
.destination{width:100%;height:5%;padding-top:2%}
.stext{font:bold 27vh/27vh Arial Black, sans-serif;text-align: center;text-transform:uppercase}
.smlstext{font:bold 18vh/27vh Arial Black, sans-serif !important}
.ttext{font:400 13vh/12vh Tahoma, sans-serif;text-align: center;text-transform:uppercase}
.d1text, .d2text{font:400 5vh/4vh Tahoma, sans-serif;margin:0;padding:0;text-transform:uppercase}
.d1btext, .d2btext{font:400 22vh/19vh Tahoma, sans-serif;text-transform:uppercase;margin:0;padding:0}
.d1text, .d1btext{text-align: right;}
.d2text, .d2btext{text-align: left;}
.destext{font:400 11vh/8vh Tahoma, sans-serif;text-align: center;text-transform:uppercase}
.glow{text-shadow: 0 0 10px #272727, 0 0 30px #fc4f4f;}
</style>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/obs-ws.global.min.js"></script>
<script src="common.js"></script>
<script>
var interval = null;
obs.on("Identified", async () => {
// Update the destination field
await updateStreamingDestination();
var lastStatus = "";
var DOMstreamstatus = document.getElementById("streamstatus");
async function updateStreamStatus() {
let response = await obs.call("GetStreamStatus");
if (response) {
setTimecode(response.outputTimecode);
setStreamDataRate(response);
calculateColorStatus(response.outputCongestion);
// Add reconnecting text
if (response.outputReconnecting && DOMstreamstatus.innerText.toLowerCase() != "reconnecting") {
lastStatus = DOMstreamstatus.innerText;
changeElementContent("streamstatus", "reconnecting");
}
// Get rid of reconnecting text
if (!response.outputReconnecting && DOMstreamstatus.innerText.toLowerCase() == "reconnecting") DOMstreamstatus.innerText = lastStatus;
// If offline but status out of sync because reload, update
if (response.outputActive && DOMstreamstatus.innerText.toLowerCase() == "off") {
setLiveTextFormating("red");
changeElementContent("streamstatus", "on air");
}
// Stop itself when stream no longer active
if (!response.outputActive) {
clearInterval(interval);
interval = null;
changeElementColor("streamhealth", "white");
console.log("Stopping timer because output is inactive");
}
}
}
async function startPollData() {
if (!interval) {
interval = setInterval(updateStreamStatus, 1000);
}
}
await startPollData();
// ProfileChanged event
obs.on("CurrentProfileChanged", data => {
setTimeout(updateStreamingDestination, 1000);
});
// StreamStateChanged event
obs.on("StreamStateChanged", async event => {
const { outputState } = event;
switch (outputState) {
case "OBS_WEBSOCKET_OUTPUT_STARTING":
setLiveTextFormating("red");
changeElementContent("streamstatus", "connecting");
await updateStreamingDestination();
break;
case "OBS_WEBSOCKET_OUTPUT_STARTED":
changeElementContent("streamstatus", "on air");
await startPollData();
break;
case "OBS_WEBSOCKET_OUTPUT_STOPPING":
changeElementContent("streamstatus", "disconnecting");
// prevent from polling garbage data from obs
clearInterval(interval);
interval = null;
break;
case "OBS_WEBSOCKET_OUTPUT_STOPPED":
// just in case obs skipped the stopping state
clearInterval(interval);
setLiveTextFormating("white");
changeElementContent("streamstatus", "off");
setTimeout( () => {
setTimecode("00:00:00.000");
setStreamDataRate(false);
changeElementColor("streamhealth", "white");
}, 300);
break;
default:
return;
}
});
});
obs.on("ConnectionClosed", () => {
clearInterval(interval);
interval = null;
changeElementContent("streamdestination", "NOT CONNECTED");
changeElementVisibility("streamdestination", true);
console.log("Connection Closed");
setTimeout(init, 2000);
});
// Stuff to make things easier
function setLiveTextFormating(color) {
const elem = document.getElementById("streamstatus");
elem.style.color = color;
if (color == "red") {
elem.classList.add("glow");
} else {
elem.classList.remove("glow");
}
}
var lastDataRateData = {
bytes: null,
time: null
};
var requestCount = 0;
function setStreamDataRate(res) {
if (!res) {
changeElementContent("streamdatarate", "0.00");
requestCount = 0;
return;
}
let bytes_now = res.outputBytes;
if (lastDataRateData.bytes === null) {
lastDataRateData.bytes = bytes_now;
return;
}
// Only run calculations on every 2nd update to make them more stable
requestCount++;
if (requestCount % 2) return;
let ts_now = TimecodeToTs(res.outputTimecode);
let time_delta = ts_now - lastDataRateData.time;
let byte_delta = bytes_now - lastDataRateData.bytes;
let throughput = ((byte_delta/time_delta)*1000)/125000;
lastDataRateData.bytes = bytes_now;
lastDataRateData.time = ts_now;
if (byte_delta == 0 || throughput < 0) {
changeElementContent("streamdatarate", "0.00");
return;
}
changeElementContent("streamdatarate", throughput.toFixed(2));
}
function setTimecode(tc) {
changeElementContent("streamtimecode", trimTimecode(tc));
}
async function updateStreamingDestination() {
// hide url if requested
if (urlParams.has("hidebottom")) {
changeElementVisibility("streamdestination", false);
return;
}
const elem = document.getElementById("streamdestination");
let { streamServiceType, streamServiceSettings } = await obs.call("GetStreamServiceSettings");
if (streamServiceType && streamServiceSettings) {
if (streamServiceType == "rtmp_common" && streamServiceSettings.service == "YouTube / YouTube Gaming") {
elem.innerText = "YouTube";
} else if (streamServiceType == "rtmp_common" && streamServiceSettings.hasOwnProperty("service")) {
elem.innerText = streamServiceSettings.service;
} else if (streamServiceType == "rtmp_custom" && streamServiceSettings.hasOwnProperty("server") && streamServiceSettings.server != "") {
elem.innerText = new URL(streamServiceSettings.server.replace("rtmp", "http").replace("srt", "http")).hostname;;
} else {
elem.innerText = "Nothing?";
}
}
}
// This congestion color calculation was directly translated into javascript from obs-studio source code
// https://github.com/obsproject/obs-studio/blob/master/UI/window-basic-status-bar.cpp#L327-L356
var lastCongestion = 0.0;
function calculateColorStatus(c) {
const EPSILON = 0.000100;
let congestion = c;
let avgCongestion = (congestion + lastCongestion) * 0.5;
if (avgCongestion < congestion) avgCongestion = congestion;
if (avgCongestion > 1.0) avgCongestion = 1.0;
lastCongestion = congestion;
if (avgCongestion < EPSILON) {
changeElementColor("streamhealth", "green");
} else if (Math.abs(avgCongestion - 1.0) < EPSILON) {
changeElementColor("streamhealth", "red");
} else {
let red = avgCongestion * 2.0;
if (red > 1.0) red = 1.0;
red *= 255.0;
let green = (1.0 - avgCongestion) * 2.0;
if (green > 1.0) green = 1.0;
green *= 255.0;
changeElementColor("streamhealth", `rgb(${Math.floor(red)}, ${Math.floor(green)}, 0)`);
}
}
// Utils
// Overwrite global one for now
function changeElementContent(id, newContent) {
document.getElementById(id).innerText = newContent;
if (id == "streamstatus") {
if ( ["connecting", "disconnecting", "reconnecting"].includes(newContent)) {
document.getElementById(id).classList.add("smlstext");
} else {
document.getElementById(id).classList.remove("smlstext");
}
}
}
</script>
</head>
<body>
<div class="wrapper">
<div class="stream stext" style="color:#ffffff" id="streamstatus">off</div><!--1st Tier-->
<div class="timecode ttext" id="streamtimecode">00:00:00</div><!--2nd Tier-->
<!--Start 3rd Tier, Data Stream Slots-->
<div class="data">
<p class="d1text">data rate <label style="text-transform:none">Mb/s</label> </p>
<p class="d1btext" id="streamdatarate">0.00</p>
</div>
<!--End 3rd Tier-->
<!--Start 3rd Tier, Health Slot right-->
<div class="data2">
<p class="d2text">Health</p>
<p class="d2btext">
<i class="fa-solid fa-chart-bar" style="font-size:18vh;color:white" id="streamhealth"></i><br />
</p>
</div>
<!-- End 3rd Tier right side-->
<br style="clear:right" />
<div class="destination destext" style="text-transform:none" id="streamdestination">NOT CONNECTED</div>
<!--5th Tier, destination streamed-->
</div>
</body>
</html>