This commit is contained in:
parent
0a17c788a1
commit
1f0b990124
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"tabWidth": 4
|
"tabWidth": 4
|
||||||
}
|
}
|
BIN
JS-SDK/bun.lockb
BIN
JS-SDK/bun.lockb
Binary file not shown.
@ -1,43 +1,43 @@
|
|||||||
{
|
{
|
||||||
"name": "usetether",
|
"name": "usetether",
|
||||||
"version": "1.1.3",
|
"version": "1.1.4",
|
||||||
"author": "Braydon (Rainnny) <braydonrainnny@gmail.com>",
|
"author": "Braydon (Rainnny) <braydonrainnny@gmail.com>",
|
||||||
"description": "An API designed to provide real-time access to a user's Discord data.",
|
"description": "An API designed to provide real-time access to a user's Discord data.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"java",
|
"java",
|
||||||
"discord",
|
"discord",
|
||||||
"api",
|
"api",
|
||||||
"restful",
|
"restful",
|
||||||
"realtime"
|
"realtime"
|
||||||
],
|
],
|
||||||
"homepage": "https://usetether.rest",
|
"homepage": "https://usetether.rest",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/Rainnny7/Tether.git"
|
"url": "git+https://github.com/Rainnny7/Tether.git"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsup",
|
"build": "tsup",
|
||||||
"prepublishOnly": "bun run build"
|
"prepublishOnly": "bun run build"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest",
|
||||||
"@types/react": "^18.3.5",
|
"@types/react": "^18.3.5",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "18.3.1"
|
"react-dom": "18.3.1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^5.0.0",
|
||||||
"react": "*",
|
"react": "*",
|
||||||
"react-dom": "*"
|
"react-dom": "*"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tsup": "^8.2.4"
|
"tsup": "^8.2.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Snowflake } from "@/types/snowflake";
|
import { Snowflake } from "@/types/snowflake";
|
||||||
import { TetherConfig } from "@/types/config";
|
import { TetherConfig } from "@/types/config";
|
||||||
|
import { DiscordUser } from "@/types/user";
|
||||||
|
|
||||||
export const useTetherWS = (
|
export const useTetherWS = (
|
||||||
snowflake: Snowflake,
|
snowflake: Snowflake,
|
||||||
@ -8,12 +9,42 @@ export const useTetherWS = (
|
|||||||
endpoint: "usetether.rest",
|
endpoint: "usetether.rest",
|
||||||
secure: true,
|
secure: true,
|
||||||
}
|
}
|
||||||
): Snowflake => {
|
): DiscordUser | undefined => {
|
||||||
const [user] = useState<Snowflake>(snowflake);
|
const [user] = useState<DiscordUser | undefined>();
|
||||||
|
|
||||||
|
const url: string = `ws${secure && "s"}://${endpoint}/gateway`;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("HELLO WORLD", endpoint, secure);
|
// Prevent from running on the server
|
||||||
}, [snowflake]);
|
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;
|
return user;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user