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 IndexedDB from './database'
import { WebSocketClient } from './websockets';
const wsurl = "ws://127.0.0.1:8090";
document.addEventListener('DOMContentLoaded', async () => {
try {
const services = await Services.getInstance();
await services.addWebsocketConnection(wsurl);
if ((await services.isNewUser())) {
await services.displayCreateId();

View File

@ -6,6 +6,7 @@ class Services {
private static instance: Services;
private sdkClient: any;
private current_process: string | null = null;
private websocketConnection: WebSocketClient[] = [];
// Private constructor to prevent direct instantiation from outside
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> {
let isNew = false;
try {