diff --git a/use-tether/src/hook/websocket.ts b/use-tether/src/hook/websocket.ts index 35613b8..4e59f97 100644 --- a/use-tether/src/hook/websocket.ts +++ b/use-tether/src/hook/websocket.ts @@ -1,6 +1,6 @@ import { useEffect, useState } from "react"; import { Snowflake } from "@/types/snowflake"; -import { TetherConfig } from "@/types/config"; +import { defaultConfig, TetherConfig } from "@/types/config"; import { UserStatusPacket } from "@/types/socket"; import { DiscordUser } from "@/types/user/discord-user"; @@ -10,17 +10,13 @@ import { DiscordUser } from "@/types/user/discord-user"; * the given snowflake. * * @param snowflake the user's snowflake - * @param config the Tether config + * @param config the optional Tether config */ export const useTetherWS = ( snowflake: Snowflake, - config: TetherConfig = { - endpoint: "api.usetether.rest", - secure: true, - debug: false, - } + config?: TetherConfig | undefined ): DiscordUser | undefined => { - const { endpoint, secure, debug } = config; + const { endpoint, secure, debug } = { ...defaultConfig, ...config }; const url: string = `ws${secure && "s"}://${endpoint}/gateway`; const [user, setUser] = useState(); diff --git a/use-tether/src/types/config.ts b/use-tether/src/types/config.ts index 7f22c76..481d575 100644 --- a/use-tether/src/types/config.ts +++ b/use-tether/src/types/config.ts @@ -1,3 +1,9 @@ +export const defaultConfig: TetherConfig = { + endpoint: "api.usetether.rest", + secure: true, + debug: false, +}; + export type TetherConfig = { /** * The API endpoint to connect to.