aboutsummaryrefslogtreecommitdiff
path: root/public/main.js
diff options
context:
space:
mode:
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);
+});
});