This commit is contained in:
parent
0a17c788a1
commit
1f0b990124
BIN
JS-SDK/bun.lockb
BIN
JS-SDK/bun.lockb
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "usetether",
|
||||
"version": "1.1.3",
|
||||
"version": "1.1.4",
|
||||
"author": "Braydon (Rainnny) <braydonrainnny@gmail.com>",
|
||||
"description": "An API designed to provide real-time access to a user's Discord data.",
|
||||
"keywords": [
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Snowflake } from "@/types/snowflake";
|
||||
import { TetherConfig } from "@/types/config";
|
||||
import { DiscordUser } from "@/types/user";
|
||||
|
||||
export const useTetherWS = (
|
||||
snowflake: Snowflake,
|
||||
@ -8,12 +9,42 @@ export const useTetherWS = (
|
||||
endpoint: "usetether.rest",
|
||||
secure: true,
|
||||
}
|
||||
): Snowflake => {
|
||||
const [user] = useState<Snowflake>(snowflake);
|
||||
): DiscordUser | undefined => {
|
||||
const [user] = useState<DiscordUser | undefined>();
|
||||
|
||||
const url: string = `ws${secure && "s"}://${endpoint}/gateway`;
|
||||
useEffect(() => {
|
||||
console.log("HELLO WORLD", endpoint, secure);
|
||||
}, [snowflake]);
|
||||
// Prevent from running on the server
|
||||
if (typeof window === "undefined") {
|
||||
return;
|
||||
}
|
||||
let socket: WebSocket; // The current WebSocket connection
|
||||
|
||||
/**
|
||||
* Establish a connection with the API.
|
||||
*/
|
||||
function connect() {
|
||||
console.log("[Tether] Connecting to the WebSocket server...");
|
||||
socket = new WebSocket(url); // Connect to the gateway
|
||||
socket.addEventListener("open", () => {
|
||||
console.log("[Tether] WebSocket connection established!");
|
||||
console.log("attempt to lsn to", snowflake);
|
||||
});
|
||||
// socket.addEventListener("close", connect);
|
||||
|
||||
socket.addEventListener("message", (event) => {
|
||||
console.log("data:", event.data);
|
||||
});
|
||||
}
|
||||
|
||||
connect();
|
||||
|
||||
// Cleanup
|
||||
return () => {
|
||||
socket.removeEventListener("close", connect);
|
||||
socket.close();
|
||||
};
|
||||
}, [url]);
|
||||
|
||||
return user;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user