From 741b303348de12bd1f659f4c5f6c3f213698e1fd Mon Sep 17 00:00:00 2001 From: Sosthene00 <674694@protonmail.ch> Date: Mon, 8 Apr 2024 15:56:01 +0200 Subject: [PATCH] connect on startup --- src/index.ts | 4 +++- src/services.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 4327e11..bdb0bbb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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(); diff --git a/src/services.ts b/src/services.ts index cc8ab92..920e915 100644 --- a/src/services.ts +++ b/src/services.ts @@ -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 { + const services = await Services.getInstance(); + const newClient = new WebSocketClient(url, services); + if (!services.websocketConnection.includes(newClient)) { + services.websocketConnection.push(newClient); + } + } + public async isNewUser(): Promise { let isNew = false; try {