aboutsummaryrefslogtreecommitdiff
path: root/public/main.js
diff options
context:
space:
mode:
authorAdam Hovorka <[email protected]>2019-07-17 23:23:52 -0600
committerAdam Hovorka <[email protected]>2019-07-17 23:23:52 -0600
commit1216a517b7f725c787609db453eaa48f99c92918 (patch)
tree16c53c5c008d94217d35306891dcb0634c0b63b5 /public/main.js
parent4f858ebf3206431447177c977533d18dbea6dca9 (diff)
Flesh out the WebSocket system with some amenities
Diffstat (limited to 'public/main.js')
-rw-r--r--public/main.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/public/main.js b/public/main.js
index b3c7986..46d5432 100644
--- a/public/main.js
+++ b/public/main.js
@@ -2,9 +2,15 @@ document.addEventListener("DOMContentLoaded", async () => { "use strict"
const $ = s => document.querySelector(s);
const secure = location.protocol === "https:";
-const sock = new WebSocket(`ws${secure?"s":""}://${location.host}/ws`);
+sock.init(`ws${secure?"s":""}://${location.host}/ws`);
-sock.onmessage = e => console.log("sock", e);
-sock.onopen = () => sock.send("yay");
+sock.on("hello", e => {
+ console.log("hello", e);
+ sock.send("world", {foo:"bar"});
+});
+
+sock.on("yay", e => {
+ console.log("yay", e);
+});
});