feat: register browser user context
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
import { Socket } from "socket.io";
|
import { Socket } from "socket.io";
|
||||||
import { uuid } from 'uuidv4';
|
import { uuid } from 'uuidv4';
|
||||||
|
|
||||||
import { createSocketConnection, createSocketConnectionForRun } from "../socket-connection/connection";
|
import { createSocketConnection, createSocketConnectionForRun, registerBrowserUserContext } from "../socket-connection/connection";
|
||||||
import { io, browserPool } from "../server";
|
import { io, browserPool } from "../server";
|
||||||
import { RemoteBrowser } from "./classes/RemoteBrowser";
|
import { RemoteBrowser } from "./classes/RemoteBrowser";
|
||||||
import { RemoteBrowserOptions } from "../types";
|
import { RemoteBrowserOptions } from "../types";
|
||||||
@@ -48,19 +48,27 @@ export const initializeRemoteBrowserForRecording = (userId: string): string => {
|
|||||||
* Starts and initializes a {@link RemoteBrowser} instance for interpretation.
|
* Starts and initializes a {@link RemoteBrowser} instance for interpretation.
|
||||||
* Creates a new {@link Socket} connection over a dedicated namespace.
|
* Creates a new {@link Socket} connection over a dedicated namespace.
|
||||||
* Returns the new remote browser's generated id.
|
* Returns the new remote browser's generated id.
|
||||||
* @param options {@link RemoteBrowserOptions} to be used when launching the browser
|
* @param userId User ID for browser ownership
|
||||||
* @returns string
|
* @returns string Browser ID
|
||||||
* @category BrowserManagement-Controller
|
* @category BrowserManagement-Controller
|
||||||
*/
|
*/
|
||||||
export const createRemoteBrowserForRun = (userId: string): string => {
|
export const createRemoteBrowserForRun = (userId: string): string => {
|
||||||
const id = uuid();
|
const id = uuid();
|
||||||
|
|
||||||
|
registerBrowserUserContext(id, userId);
|
||||||
|
logger.log('debug', `Created new browser for run: ${id} for user: ${userId}`);
|
||||||
|
|
||||||
createSocketConnectionForRun(
|
createSocketConnectionForRun(
|
||||||
io.of(id),
|
io.of(`/${id}`),
|
||||||
async (socket: Socket) => {
|
async (socket: Socket) => {
|
||||||
const browserSession = new RemoteBrowser(socket, userId);
|
try {
|
||||||
await browserSession.initialize(userId);
|
const browserSession = new RemoteBrowser(socket, userId);
|
||||||
browserPool.addRemoteBrowser(id, browserSession, userId, false, "run");
|
await browserSession.initialize(userId);
|
||||||
socket.emit('ready-for-run');
|
browserPool.addRemoteBrowser(id, browserSession, userId, false, "run");
|
||||||
|
socket.emit('ready-for-run');
|
||||||
|
} catch (error: any) {
|
||||||
|
logger.error(`Error initializing browser: ${error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user