diff --git a/JS-SDK/src/index.ts b/JS-SDK/src/index.ts index 5b6562a..93767e5 100644 --- a/JS-SDK/src/index.ts +++ b/JS-SDK/src/index.ts @@ -2,4 +2,4 @@ export * from "@/lib/tether"; // Types export * from "@/types/config"; -export * from "@/types/user"; \ No newline at end of file +export * from "@/types/user"; diff --git a/JS-SDK/src/lib/tether.ts b/JS-SDK/src/lib/tether.ts index 6c79e8a..1cd5dad 100644 --- a/JS-SDK/src/lib/tether.ts +++ b/JS-SDK/src/lib/tether.ts @@ -1,14 +1,15 @@ import TetherConfig from "@/types/config"; import DiscordUser from "@/types/user"; -import {useEffect, useState} from "react"; +import { useEffect, useState } from "react"; +import Snowflake from "@/types/snowflake"; -export const useTether = ( - snowflake: bigint | string, - {endpoint, secure, realtime}: TetherConfig = { +export const useTetherWS = ( + snowflake: Snowflake, + { endpoint, secure }: TetherConfig = { endpoint: "usetether.rest", secure: true, - realtime: false - }): DiscordUser | undefined => { + } +): DiscordUser | undefined => { const [user] = useState(); useEffect(() => { @@ -17,15 +18,17 @@ export const useTether = ( /** * Establish a connection with the API. */ - const connect = () => { + function connect() { socket = new WebSocket(`ws${secure && "s"}://${endpoint}/gateway`); // Connect to the gateway - socket.addEventListener("open", () => console.log("[Tether] WebSocket connection established!")); + socket.addEventListener("open", () => + console.log("[Tether] WebSocket connection established!") + ); socket.addEventListener("close", connect); - socket.addEventListener("message", event => { + socket.addEventListener("message", (event) => { console.log("data:", event.data); }); - }; + } connect(); // Cleanup @@ -36,4 +39,4 @@ export const useTether = ( }, [endpoint, secure]); return user; -} \ No newline at end of file +}; diff --git a/JS-SDK/src/types/config.ts b/JS-SDK/src/types/config.ts index 1ce1493..cc221e2 100644 --- a/JS-SDK/src/types/config.ts +++ b/JS-SDK/src/types/config.ts @@ -2,16 +2,11 @@ type TetherConfig = { /** * The API endpoint to connect to. */ - endpoint?: string, + endpoint?: string; /** * Whether the connection should be secure. */ - secure?: boolean, - - /** - * Whether the data should be fetched in real-time. - */ - realtime?: boolean, + secure?: boolean; }; -export default TetherConfig; \ No newline at end of file +export default TetherConfig; diff --git a/JS-SDK/src/types/snowflake.ts b/JS-SDK/src/types/snowflake.ts new file mode 100644 index 0000000..11ad6d4 --- /dev/null +++ b/JS-SDK/src/types/snowflake.ts @@ -0,0 +1,2 @@ +type Snowflake = `${bigint}`; +export default Snowflake; diff --git a/JS-SDK/src/types/socket.ts b/JS-SDK/src/types/socket.ts index 29f4633..45560f3 100644 --- a/JS-SDK/src/types/socket.ts +++ b/JS-SDK/src/types/socket.ts @@ -4,4 +4,4 @@ type SocketPacket = { */ op: number; }; -export default SocketPacket; \ No newline at end of file +export default SocketPacket; diff --git a/JS-SDK/src/types/user.ts b/JS-SDK/src/types/user.ts index 9dab9b2..e54ac88 100644 --- a/JS-SDK/src/types/user.ts +++ b/JS-SDK/src/types/user.ts @@ -37,7 +37,13 @@ type DiscordUser = { /** * The online status of this user, if known. */ - onlineStatus: "ONLINE" | "IDLE" | "DO_NOT_DISTURB" | "OFFLINE" | "UNKNOWN" | undefined; + onlineStatus: + | "ONLINE" + | "IDLE" + | "DO_NOT_DISTURB" + | "OFFLINE" + | "UNKNOWN" + | undefined; /** * The clients this user is active on, if known. @@ -67,13 +73,30 @@ type UserFlags = { /** * The list of flags the user has. */ - list: ("STAFF" | "PARTNER" | "HYPESQUAD" | "BUG_HUNTER_LEVEL_1" | "HYPESQUAD_BRAVERY" | "HYPESQUAD_BRILLIANCE" | "HYPESQUAD_BALANCE" | "EARLY_SUPPORTER" | "TEAM_USER" | "BUGHUNTER_LEVEL_2" | "VERIFIED_BOT" | "VERIFIED_DEVELOPER" | "CERTIFIED_MODERATOR" | "BOT_HTTP_INTERACTIONS" | "ACTIVE_DEVELOPER" | "UNKNOWN")[]; + list: ( + | "STAFF" + | "PARTNER" + | "HYPESQUAD" + | "BUG_HUNTER_LEVEL_1" + | "HYPESQUAD_BRAVERY" + | "HYPESQUAD_BRILLIANCE" + | "HYPESQUAD_BALANCE" + | "EARLY_SUPPORTER" + | "TEAM_USER" + | "BUGHUNTER_LEVEL_2" + | "VERIFIED_BOT" + | "VERIFIED_DEVELOPER" + | "CERTIFIED_MODERATOR" + | "BOT_HTTP_INTERACTIONS" + | "ACTIVE_DEVELOPER" + | "UNKNOWN" + )[]; /** * The raw flags the user has. */ raw: number; -} +}; /** * A user's avatar. @@ -145,4 +168,4 @@ type SpotifyActivity = { ends: number; }; -export default DiscordUser; \ No newline at end of file +export default DiscordUser;