Added Websocket stuff
This commit is contained in:
31
www/scripts/web_sockets.js
Normal file
31
www/scripts/web_sockets.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const socket = new WebSocket("ws://localhost:8000/ws");
|
||||
let problemData = null;
|
||||
let stepIndex = 0;
|
||||
|
||||
socket.onopen = () => {
|
||||
console.log("Connected to server");
|
||||
|
||||
socket.send(JSON.stringify({
|
||||
type: "query_problem"
|
||||
}));
|
||||
};
|
||||
|
||||
socket.onmessage = (event) => {
|
||||
const msg = JSON.parse(event.data);
|
||||
|
||||
if (msg.type === "generated_problem") {
|
||||
problemData = msg.data;
|
||||
stepIndex = 0;
|
||||
|
||||
showProblem();
|
||||
|
||||
// start animation sequence
|
||||
startSequence();
|
||||
}
|
||||
};
|
||||
|
||||
function requestNextProblem() {
|
||||
socket.send(JSON.stringify({
|
||||
type: "query_problem"
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user