setup websocket
parent
b074f548f4
commit
f99982251d
@ -1,3 +1,5 @@
|
||||
venv/
|
||||
__pycache__
|
||||
.env
|
||||
.vscode
|
||||
node_modules
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"python.formatting.provider": "black"
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
from flask import Blueprint, render_template
|
||||
from . import events
|
||||
|
||||
bp = Blueprint("handle", __name__)
|
||||
|
||||
|
||||
@bp.route("/handle/")
|
||||
def handle():
|
||||
return render_template("handle.html")
|
@ -0,0 +1,14 @@
|
||||
// NOT ELEGANT SOLUTION FOR LOCAL DEV
|
||||
let path = document.URL.startsWith("http://127.0.0.1") ? "" : "/soupboat/skimmer/socket.io";
|
||||
|
||||
let socket = io({
|
||||
path: path,
|
||||
});
|
||||
|
||||
socket.on("connect", function () {
|
||||
socket.emit("connect bowl", { id: socket.id });
|
||||
});
|
||||
|
||||
socket.on("disconnect", function () {
|
||||
socket.emit("disconnect bowl", { id: socket.it });
|
||||
});
|
@ -0,0 +1,27 @@
|
||||
// NOT ELEGANT SOLUTION FOR LOCAL DEV
|
||||
let path = document.URL.startsWith("http://127.0.0.1") ? "" : "/soupboat/skimmer/socket.io";
|
||||
|
||||
let socket = io("http://127.0.0.1:5000", {
|
||||
path: path,
|
||||
});
|
||||
|
||||
socket.on("connect", function () {
|
||||
socket.emit("handle", { id: socket.id });
|
||||
});
|
||||
|
||||
socket.on("add bowl", (data) => addBowl(data.id));
|
||||
socket.on("remove bowl", (data) => removeBowl(data.id));
|
||||
|
||||
const container = document.getElementById("container");
|
||||
|
||||
function addBowl(id) {
|
||||
let bowl = document.createElement("div");
|
||||
bowl.classList.add("bowl");
|
||||
bowl.innerHTML = id;
|
||||
bowl.dataset.bowl = id;
|
||||
container.appendChild(bowl);
|
||||
}
|
||||
|
||||
function removeBowl(id) {
|
||||
container.querySelector(`[data-bowl=${id}]`).remove();
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Document</title>
|
||||
|
||||
<script
|
||||
src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"
|
||||
integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA=="
|
||||
crossorigin="anonymous"
|
||||
></script>
|
||||
<script src="{{url_for('static', filename='js/handle.js')}}" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Handle</h1>
|
||||
<div id="container"></div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue