mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-18 16:53:57 +00:00
feat: adding ws
This commit is contained in:
@@ -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
|
||||
|
||||
30
src/main/services/ws-manager.ts
Normal file
30
src/main/services/ws-manager.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
1
src/main/vite-env.d.ts
vendored
1
src/main/vite-env.d.ts
vendored
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user