feat: adding ws

This commit is contained in:
Chubby Granny Chaser
2025-04-29 10:05:27 +01:00
parent a21f2b9614
commit aa18b57ada
6 changed files with 48 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import { levelKeys, db } from "./level";
import type { UserPreferences } from "@types";
import { TorBoxClient } from "./services/download/torbox";
import { CommonRedistManager } from "./services/common-redist-manager";
import { WSManager } from "./services/ws-manager";
export const loadState = async () => {
const userPreferences = await db.get<string, UserPreferences | null>(
@@ -34,6 +35,7 @@ export const loadState = async () => {
await HydraApi.setupApi().then(() => {
uploadGamesBatch();
WSManager.connect();
});
const downloads = await downloadsSublevel

View File

@@ -0,0 +1,30 @@
import { WebSocket } from "ws";
import { HydraApi } from "./hydra-api";
export class WSManager {
private static ws: WebSocket;
static async connect() {
const { token } = await HydraApi.post<{ token: string }>("/auth/ws");
console.log("WS TOKEN", token);
this.ws = new WebSocket(import.meta.env.MAIN_VITE_WS_URL, {
headers: {
Authorization: `Bearer ${token}`,
},
});
this.ws.on("open", () => {
console.log("open");
});
this.ws.on("error", (error) => {
console.error(error);
});
this.ws.on("message", (message) => {
console.log(message);
});
}
}

View File

@@ -6,6 +6,7 @@ interface ImportMetaEnv {
readonly MAIN_VITE_AUTH_URL: string;
readonly MAIN_VITE_CHECKOUT_URL: string;
readonly MAIN_VITE_EXTERNAL_RESOURCES_URL: string;
readonly MAIN_VITE_WS_URL: string;
}
interface ImportMeta {