sse implementation
parent
db6e3c4993
commit
4b000b30be
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>C&J</title>
|
<title>CnJ</title>
|
||||||
<script src="script.js"></script>
|
<script src="script.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
12
script.js
12
script.js
|
@ -41,9 +41,20 @@ window.onload = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
connectWS()
|
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() {
|
function connectWS() {
|
||||||
ws = new WebSocket(wsAddress + wsPort)
|
ws = new WebSocket(wsAddress + wsPort)
|
||||||
|
@ -58,6 +69,7 @@ function connectWS() {
|
||||||
|
|
||||||
let data = JSON.parse(msg.data)
|
let data = JSON.parse(msg.data)
|
||||||
|
|
||||||
|
// Only used here to test whether messages can be sent between the servers
|
||||||
if (data["Cmd"] == 99999) {
|
if (data["Cmd"] == 99999) {
|
||||||
document.getElementById("userid").innerHTML = data["Body"]
|
document.getElementById("userid").innerHTML = data["Body"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue