Skip to content

Commit

Permalink
Moar debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Sep 23, 2024
1 parent 99ff427 commit a6a8f15
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions apps/web/src/pages/test.astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import Layout from "../layouts/Layout.astro";
<h3>Overlayed</h3>
<div id="overlayed">⌛ Connecting to Discord...</div>

<h3>Streamkit</h3>
<div id="streamkit">connecting...</div>
<div id="streamkit-wrapper" class="hidden">
<h3>Streamkit</h3>
<div id="streamkit">connecting...</div>
</div>

<pre id="socket-log"></pre>
</div>
Expand All @@ -30,9 +32,14 @@ import Layout from "../layouts/Layout.astro";
let connnected = false;
const overlayedDiv = document.getElementById("overlayed")!;
const socketLog = document.getElementById("socket-log")!;
const streamkitWrapperDiv = document.getElementById("streamkit-wrapper")!;
const streamkitDiv = document.getElementById("streamkit")!;

function connectToDiscord(url: string, domNode: HTMLElement) {
function connectToDiscord(
label: string,
url: string,
domNode: HTMLElement,
) {
const socket = new WebSocket(url);

const timeoutId = setTimeout(() => {
Expand All @@ -44,18 +51,22 @@ import Layout from "../layouts/Layout.astro";
socket.addEventListener("open", () => {
console.log("Connected to ws server");
domNode.innerHTML = "🌎 Connected to Discord";
clearTimeout(timeoutId);
connnected = true;
});

socket.addEventListener("message", (event) => {
const payload = JSON.parse(event.data);
console.log(payload);

socketLog.innerHTML = JSON.stringify(payload, null, 2);
socketLog.innerHTML =
socketLog.innerHTML +
`[${label}]\n` +
JSON.stringify(payload, null, 2) +
"\n";

if (payload.evt === "READY") {
domNode.innerHTML = "✅ Connected to Discord (READY)";
domNode.innerHTML = "✅ Received Discord READY Event";
clearTimeout(timeoutId);
}
});

Expand All @@ -69,13 +80,19 @@ import Layout from "../layouts/Layout.astro";
}

connectToDiscord(
"overlayed",
"ws://127.0.0.1:6463?v=1&encoding=json&client_id=905987126099836938",
overlayedDiv,
);

connectToDiscord(
"ws://127.0.0.1:6463?v=1&encoding=json&client_id=207646673902501888",
streamkitDiv,
);
console.log("window.location.origin", window.location.origin);
if (window.location.origin === "http://localhost:3000") {
streamkitWrapperDiv.classList.remove("hidden");
connectToDiscord(
"streamkit",
"ws://127.0.0.1:6463?v=1&encoding=json&client_id=207646673902501888",
streamkitDiv,
);
}
</script>
</Layout>

0 comments on commit a6a8f15

Please sign in to comment.