import Signaler from "./Signaler.js"; import SkribblContainer from "./SkribblContainer.js"; document.addEventListener("DOMContentLoaded",async()=>{ if (document.location.hash){ document.body.innerHTML = ""; const gameID = document.location.hash.substring(1); const dataChannel = await Signaler.join(gameID); console.group("Joined game "+gameID+"!"); console.log("dataChannel:",dataChannel); console.groupEnd(); dataChannel.onMessage(message=>{ console.log("Message through DataChannel:",message); dataChannel.send("Got ya message, many thanks <3"); }); }else{ /** @type {HTMLButtonElement} *///@ts-ignore const button = document.getElementById("button"); await new Promise(resolve=>{button.addEventListener("click",async e=>{ button.disabled = true; resolve(); })}); let id = await Signaler.host(async dataChannel=>{ console.group("New connection!"); console.log("dataChannel:",dataChannel); console.groupEnd(); dataChannel.onMessage(message=>{ console.log("Message through DataChannel:",message); }); await dataChannel.waitUntilReady(); dataChannel.send("Oh hello there :3"); }); alert(document.location.host+document.location.pathname+"#"+id); } const game = new SkribblContainer(); document.body.innerHTML = ""; document.body.appendChild(game); });