From fb5ad5106ed8eb07e096d95f3cf9dadfa0554693 Mon Sep 17 00:00:00 2001 From: Tomas Valenta Date: Sun, 30 Jul 2023 15:22:43 +0200 Subject: [PATCH] Modify session cache to handle findOrStartSession correctly --- src/sessions/session.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/sessions/session.ts b/src/sessions/session.ts index 85954b8..9a45502 100644 --- a/src/sessions/session.ts +++ b/src/sessions/session.ts @@ -27,6 +27,7 @@ export class CachedSession { ports: OpenPort[] = [] id?: string + cacheID?: string session: Session /** @@ -54,15 +55,20 @@ export class CachedSession { }) } - async init() { + /** + * @param customCacheID If you want to use a custom cache ID instead of the default one + */ + async init(customCacheID?: string) { await this.session.open() - + const url = this.session.getHostname() if (!url) throw new Error('Cannot start session') + console.log('Opened session', url) const [id] = url.split('.') this.id = id - sessionCache.set(id, this) + this.cacheID = customCacheID || id + sessionCache.set(this.cacheID, this) return this } @@ -108,7 +114,7 @@ export class CachedSession { return CachedSession.findSession(sessionID) } catch { const cachedSession = new CachedSession(envID) - await cachedSession.init() + await cachedSession.init(sessionID) return cachedSession } }