aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ui/js/socket.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/ui/js/socket.js b/ui/js/socket.js
index bb739d5..ec4fe53 100644
--- a/ui/js/socket.js
+++ b/ui/js/socket.js
@@ -1,5 +1,7 @@
import api from './api.js';
+const msgTypeKey = "functie";
+
var ws = new WebSocket('ws://localhost:8081/');
export default ws;
@@ -7,14 +9,14 @@ ws.addEventListener("message", ev => {
// this will already throw an error if the message doesn't contain valid JSON
const msg = JSON.parse(ev.data);
- // check if api.msg.handle has a handler for msg.type
- if (!api.msg.handle.hasOwnProperty(msg.type)) {
- console.warn(`No message handler for type ${msg.type}`, msg);
+ // check if api.msg.handle has a handler for message type
+ if (!api.msg.handle.hasOwnProperty(msg[msgTypeKey])) {
+ console.warn(`No message handler for type ${msg[msgTypeKey]}`, msg);
return;
}
// run the appropriate message handler
- api.msg.handle[msg.type](msg);
+ api.msg.handle[msg[msgTypeKey]](msg);
});
ws.addEventListener("close", () => {