This commit is contained in:
parent
4010b141f5
commit
45e017d840
@ -1,6 +1,6 @@
|
|||||||
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 { defaultConfig, TetherConfig } from "@/types/config";
|
||||||
import { UserStatusPacket } from "@/types/socket";
|
import { UserStatusPacket } from "@/types/socket";
|
||||||
import { DiscordUser } from "@/types/user/discord-user";
|
import { DiscordUser } from "@/types/user/discord-user";
|
||||||
|
|
||||||
@ -10,17 +10,13 @@ import { DiscordUser } from "@/types/user/discord-user";
|
|||||||
* the given snowflake.
|
* the given snowflake.
|
||||||
*
|
*
|
||||||
* @param snowflake the user's snowflake
|
* @param snowflake the user's snowflake
|
||||||
* @param config the Tether config
|
* @param config the optional Tether config
|
||||||
*/
|
*/
|
||||||
export const useTetherWS = (
|
export const useTetherWS = (
|
||||||
snowflake: Snowflake,
|
snowflake: Snowflake,
|
||||||
config: TetherConfig = {
|
config?: TetherConfig | undefined
|
||||||
endpoint: "api.usetether.rest",
|
|
||||||
secure: true,
|
|
||||||
debug: false,
|
|
||||||
}
|
|
||||||
): DiscordUser | undefined => {
|
): DiscordUser | undefined => {
|
||||||
const { endpoint, secure, debug } = config;
|
const { endpoint, secure, debug } = { ...defaultConfig, ...config };
|
||||||
const url: string = `ws${secure && "s"}://${endpoint}/gateway`;
|
const url: string = `ws${secure && "s"}://${endpoint}/gateway`;
|
||||||
const [user, setUser] = useState<DiscordUser | undefined>();
|
const [user, setUser] = useState<DiscordUser | undefined>();
|
||||||
|
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
export const defaultConfig: TetherConfig = {
|
||||||
|
endpoint: "api.usetether.rest",
|
||||||
|
secure: true,
|
||||||
|
debug: false,
|
||||||
|
};
|
||||||
|
|
||||||
export type TetherConfig = {
|
export type TetherConfig = {
|
||||||
/**
|
/**
|
||||||
* The API endpoint to connect to.
|
* The API endpoint to connect to.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user