Created
December 24, 2024 09:18
-
-
Save kaineer/3a38f109161136ef2d3599561bc602e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<style> | |
p { font-size: 24px; } | |
</style> | |
</head> | |
<body> | |
<script> | |
const host = "10.1.0.213:8080"; | |
const node = "62e060b2-cc85-43a0-a34c-e5adb231b8c9"; | |
const input = document.querySelector("input"); | |
const log = (message) => { | |
const p = document.createElement("p") | |
p.textContent = message; | |
document.body.append(p); | |
} | |
let ws;; | |
const auth = async (login, password) => { | |
log("Making auth"); | |
const resp = await fetch("http://" + host + "/authorization-server-service/api/v1/jwt/login/", { | |
method: "POST", | |
headers: { | |
"accept": "*/*", | |
"Content-Type": "application/json", | |
}, | |
body: JSON.stringify({ | |
login, | |
password | |
}) | |
}) | |
const { data: { accessToken } } = await resp.json(); | |
log("Got token"); | |
return accessToken; | |
} | |
const createWebsocket = (token) => { | |
const url = "ws://" + host + "/game-engine/web-socket/node?root-id=" + node + "&token=" + token; | |
const ws = new WebSocket(url); | |
Object.assign(ws, { | |
onopen() { log("Socket open: "), log(url) }, | |
onclose() { log("Socket closed") }, | |
onmessage(message) { | |
log("Socket got message"); | |
log(message); | |
} | |
}); | |
return ws; | |
} | |
auth("su", "admin") | |
.then(createWebsocket); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment