Skip to content

Commit

Permalink
🍱 realtime javascript assets
Browse files Browse the repository at this point in the history
  • Loading branch information
WillForan committed Nov 3, 2024
1 parent 4458daa commit d207ebe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions servers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
"""
Broadcast filesystem updates (via inotify) over websockets.
Serve javascript over HTTP for recieving websocket messages in a browser.
"""

import asyncio
Expand Down
30 changes: 30 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head><title>MRQART</title>
<link rel="stylesheet" type="text/css" href="static/main.css" />
</head>
<script>
/* TODO: move into own file. run tests? */
function receivedMessage(msg) {
console.log("new message!", msg);
//TODO: msg as json; parse alert
let el = document.createElement("p");
el.textContent = msg.data;
document.getElementById("sequences").appendChild(el);
}

function update_via_ws() {
const ws = new WebSocket("ws://127.0.0.1:5000/");
ws.addEventListener('message', receivedMessage);
}
window.onload = update_via_ws;

</script>

<body>
<div id="alert"></div>
<div id="project"></div>
<div id="sequence number"></div>
<ul id="sequences">waiting for scanner</ul>
</body>
</html>
7 changes: 7 additions & 0 deletions static/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
html {
max-width: 70ch;
padding: 3em 1em;
margin: auto;
line-height: 1.75;
font-size: 1.25em;
}

0 comments on commit d207ebe

Please sign in to comment.