diff --git a/server/src/browser-management/classes/BrowserPool.ts b/server/src/browser-management/classes/BrowserPool.ts index c1f0f557..e97d9fc3 100644 --- a/server/src/browser-management/classes/BrowserPool.ts +++ b/server/src/browser-management/classes/BrowserPool.ts @@ -506,6 +506,29 @@ export class BrowserPool { return browserIds.length > 0 ? browserIds[0] : null; }; + /** + * Checks if there are available browser slots for a user. + * Returns true if user has available slots AND none of their active browsers are in "recording" state. + * @param userId the user ID to check browser slots for + * @returns {boolean} true if user has available slots and no recording browsers, false otherwise + */ + public hasAvailableBrowserSlots = (userId: string, state?: BrowserState): boolean => { + const userBrowserIds = this.userToBrowserMap.get(userId) || []; + + if (userBrowserIds.length >= 2) { + return false; + } + + if (state === "recording") { + const hasBrowserInState = userBrowserIds.some(browserId => + this.pool[browserId] && this.pool[browserId].state === "recording" + ); + return !hasBrowserInState; + } + + return true; + }; + /** * Returns the first active browser's instance id from the pool. * If there is no active browser, it returns null.