track the user when the WS is connected
All checks were successful
Publish JS SDK / docker (push) Successful in 14s

This commit is contained in:
Braydon 2024-09-09 20:43:39 -04:00
parent 1d34348daf
commit 0da130995c
3 changed files with 6 additions and 7 deletions

Binary file not shown.

@ -1,6 +1,6 @@
{
"name": "usetether",
"version": "1.1.5",
"version": "1.1.6",
"author": "Braydon (Rainnny) <braydonrainnny@gmail.com>",
"description": "An API designed to provide real-time access to a user's Discord data.",
"keywords": [
@ -29,13 +29,11 @@
"@types/bun": "latest",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"react": "^18.3.1",
"react-dom": "18.3.1"
"react": "^18.3.1"
},
"peerDependencies": {
"typescript": "^5.0.0",
"react": "*",
"react-dom": "*"
"typescript": "^5.0.0"
},
"dependencies": {
"tsup": "^8.2.4"

@ -10,9 +10,9 @@ export const useTetherWS = (
secure: true,
}
): DiscordUser | undefined => {
const url: string = `ws${secure && "s"}://${endpoint}/gateway`;
const [user] = useState<DiscordUser | undefined>();
const url: string = `ws${secure && "s"}://${endpoint}/gateway`;
useEffect(() => {
// Prevent from running on the server
if (typeof window === "undefined") {
@ -27,12 +27,13 @@ export const useTetherWS = (
console.log("[Tether] Connecting to the WebSocket server...");
socket = new WebSocket(url); // Connect to the gateway
socket.addEventListener("open", () => {
socket.send(JSON.stringify({ op: 0, snowflake: snowflake })); // Track the user
console.log(
"[Tether] WebSocket connection established!",
snowflake
);
});
socket.addEventListener("close", connect);
socket.addEventListener("close", connect); // Reconnect on close
socket.addEventListener("message", (event) => {
console.log("data:", event.data);