sse implementation

main
alex 2022-12-21 19:15:51 +01:00
parent db6e3c4993
commit 4b000b30be
2 changed files with 13 additions and 1 deletions

View File

@ -4,7 +4,7 @@
<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>C&J</title>
<title>CnJ</title>
<script src="script.js"></script>
</head>
<body>

View File

@ -41,9 +41,20 @@ window.onload = () => {
}
connectWS()
connectSSE()
}
function connectSSE() {
var source = new EventSource("http://127.0.0.1:3005/sse")
source.onmessage = (e) => {
console.log(e.data)
let obj = JSON.parse(e.data)
console.log(obj.Body)
}
}
function connectWS() {
ws = new WebSocket(wsAddress + wsPort)
@ -58,6 +69,7 @@ function connectWS() {
let data = JSON.parse(msg.data)
// Only used here to test whether messages can be sent between the servers
if (data["Cmd"] == 99999) {
document.getElementById("userid").innerHTML = data["Body"]
}