connect on startup

This commit is contained in:
Sosthene00 2024-04-08 15:56:01 +02:00
parent 6128f826b1
commit 741b303348
2 changed files with 12 additions and 1 deletions

View File

@ -1,9 +1,11 @@
import Services from './services'; import Services from './services';
import IndexedDB from './database' import { WebSocketClient } from './websockets';
const wsurl = "ws://127.0.0.1:8090";
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
try { try {
const services = await Services.getInstance(); const services = await Services.getInstance();
await services.addWebsocketConnection(wsurl);
if ((await services.isNewUser())) { if ((await services.isNewUser())) {
await services.displayCreateId(); await services.displayCreateId();

View File

@ -6,6 +6,7 @@ class Services {
private static instance: Services; private static instance: Services;
private sdkClient: any; private sdkClient: any;
private current_process: string | null = null; private current_process: string | null = null;
private websocketConnection: WebSocketClient[] = [];
// Private constructor to prevent direct instantiation from outside // Private constructor to prevent direct instantiation from outside
private constructor() {} private constructor() {}
@ -44,6 +45,14 @@ class Services {
// } // }
public async addWebsocketConnection(url: string): Promise<void> {
const services = await Services.getInstance();
const newClient = new WebSocketClient(url, services);
if (!services.websocketConnection.includes(newClient)) {
services.websocketConnection.push(newClient);
}
}
public async isNewUser(): Promise<boolean> { public async isNewUser(): Promise<boolean> {
let isNew = false; let isNew = false;
try { try {