this should work? (pls)
All checks were successful
Publish JS SDK / docker (push) Successful in 14s

This commit is contained in:
Braydon 2024-09-09 20:34:01 -04:00
parent 0a17c788a1
commit 1f0b990124
4 changed files with 78 additions and 47 deletions

@ -1,4 +1,4 @@
{
"trailingComma": "es5",
"tabWidth": 4
"trailingComma": "es5",
"tabWidth": 4
}

Binary file not shown.

@ -1,43 +1,43 @@
{
"name": "usetether",
"version": "1.1.3",
"author": "Braydon (Rainnny) <braydonrainnny@gmail.com>",
"description": "An API designed to provide real-time access to a user's Discord data.",
"keywords": [
"java",
"discord",
"api",
"restful",
"realtime"
],
"homepage": "https://usetether.rest",
"repository": {
"type": "git",
"url": "git+https://github.com/Rainnny7/Tether.git"
},
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsup",
"prepublishOnly": "bun run build"
},
"files": [
"dist"
],
"devDependencies": {
"@types/bun": "latest",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"react": "^18.3.1",
"react-dom": "18.3.1"
},
"peerDependencies": {
"typescript": "^5.0.0",
"react": "*",
"react-dom": "*"
},
"dependencies": {
"tsup": "^8.2.4"
}
"name": "usetether",
"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": [
"java",
"discord",
"api",
"restful",
"realtime"
],
"homepage": "https://usetether.rest",
"repository": {
"type": "git",
"url": "git+https://github.com/Rainnny7/Tether.git"
},
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsup",
"prepublishOnly": "bun run build"
},
"files": [
"dist"
],
"devDependencies": {
"@types/bun": "latest",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"react": "^18.3.1",
"react-dom": "18.3.1"
},
"peerDependencies": {
"typescript": "^5.0.0",
"react": "*",
"react-dom": "*"
},
"dependencies": {
"tsup": "^8.2.4"
}
}

@ -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;
};