Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
ryo33 authored Jun 11, 2024
1 parent b88eb7a commit 77a0a76
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions .public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,29 @@
} from './hug.js'
import { Socket } from "./phoenix.esm.js"

let socket;
let params = new URLSearchParams(window.location.search);
if (params.get("local")) {
socket = new Socket("ws://localhost:4000/socket", { params: {} })
} else {
socket = new Socket("wss://hug-server.ryo12redstone.workers.dev", { params: {} })
var socket;
let reconnect = () => {
if (socket) {
socket.disconnect();
}
let params = new URLSearchParams(window.location.search);
if (params.get("local")) {
socket = new Socket("ws://localhost:4000/socket", { params: {} })
} else {
socket = new Socket("wss://hug-server.ryo12redstone.workers.dev", { params: {} })
}
socket.connect();
let channel = socket.channel("player", {})
channel.join()
.receive("ok", resp => { console.log("Joined successfully", resp) })
.receive("error", resp => { console.log("Unable to join", resp) })

// register event handlers for input/output.
document.push = payload => channel.push("input", JSON.parse(payload));
channel.on("output", payload => {
on_output(JSON.stringify(payload))
});
}
let channel = socket.channel("player", {})
channel.join()
.receive("ok", resp => { console.log("Joined successfully", resp) })
.receive("error", resp => { console.log("Unable to join", resp) })

// register event handlers for input/output.
document.push = payload => channel.push("input", JSON.parse(payload));
channel.on("output", payload => {
on_output(JSON.stringify(payload))
});

// join room by key
if (params.get("key")) {
Expand All @@ -206,13 +212,11 @@
on_name_change(name)
}
document.querySelector("#random").onclick = () => {
socket.disconnect();
socket.connect();
reconnect();
on_click_random();
};
document.querySelector("#room").onclick = () => {
socket.disconnect();
socket.connect();
reconnect();
on_click_room();
};
document.querySelector("#share").onclick = () => on_click_share();
Expand Down

0 comments on commit 77a0a76

Please sign in to comment.