Split API / Webpage
We use react as a webpage, so it can be served either on OBS or on the server.
This commit is contained in:
48
api/templates/index.html
Normal file
48
api/templates/index.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Hello Asso</title>
|
||||
<style>
|
||||
.notif {
|
||||
margin: 10px;
|
||||
padding: 5px;
|
||||
border-radius: 5px;
|
||||
border: 2px solid #1100ff;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="msg"></div>
|
||||
<script>
|
||||
function addNode(msg){
|
||||
let notifs = document.getElementsByClassName("notif");
|
||||
if(notifs.length > 5)
|
||||
{
|
||||
notifs.slice(0,notifs.length-5).forEach(e => e.remove());
|
||||
}
|
||||
console.log(msg);
|
||||
let ndiv = document.createElement('div');
|
||||
ndiv.className='notif';
|
||||
let data = document.createTextNode(msg);
|
||||
ndiv.appendChild(data);
|
||||
message = document.getElementById('msg');
|
||||
document.body.insertBefore(ndiv,message);
|
||||
}
|
||||
|
||||
const websocket = new WebSocket('ws://'+ location.host + '/notify');
|
||||
websocket.addEventListener('message', ev => {
|
||||
addNode(ev.data);
|
||||
});
|
||||
|
||||
websocket.addEventListener('error', ev => {
|
||||
let div = document.createTextNode(ev);
|
||||
document.body.append(div);
|
||||
});
|
||||
|
||||
websocket.addEventListener('close', ev => {
|
||||
let div = document.createTextNode(ev);
|
||||
document.body.append(div);
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user