feat: socket listener for getList

This commit is contained in:
karishmas6
2024-08-08 05:27:50 +05:30
parent c2285312c1
commit 9d53d033fb

View File

@@ -47,6 +47,8 @@ export class WorkflowGenerator {
*/ */
private socket: Socket; private socket: Socket;
private getList: boolean = false;
/** /**
* The public constructor of the WorkflowGenerator. * The public constructor of the WorkflowGenerator.
* Takes socket for communication as a parameter and registers some important events on it. * Takes socket for communication as a parameter and registers some important events on it.
@@ -56,6 +58,7 @@ export class WorkflowGenerator {
public constructor(socket: Socket) { public constructor(socket: Socket) {
this.socket = socket; this.socket = socket;
this.registerEventHandlers(socket); this.registerEventHandlers(socket);
this.initializeSocketListeners();
} }
/** /**
@@ -89,6 +92,13 @@ export class WorkflowGenerator {
lastAction: '', lastAction: '',
} }
private initializeSocketListeners() {
this.socket.on('setGetList', (data: { getList: boolean }) => {
this.getList = data.getList;
});
}
/** /**
* Registers the event handlers for all generator-related events on the socket. * Registers the event handlers for all generator-related events on the socket.
* @param socket The socket used to communicate with the client. * @param socket The socket used to communicate with the client.
@@ -458,13 +468,12 @@ export class WorkflowGenerator {
* @private * @private
* @returns {Promise<string|null>} * @returns {Promise<string|null>}
*/ */
private generateSelector = async (page: Page, coordinates: Coordinates, action: ActionType, getList: boolean) => { private generateSelector = async (page: Page, coordinates: Coordinates, action: ActionType, getList?: boolean) => {
const elementInfo = await getElementInformation(page, coordinates); const elementInfo = await getElementInformation(page, coordinates);
const selectorBasedOnCustomAction = (getList === true) const selectorBasedOnCustomAction = (getList === true)
? await getNonUniqueSelectors(page, coordinates) ? await getNonUniqueSelectors(page, coordinates)
: await getSelectors(page, coordinates); : await getSelectors(page, coordinates);
const bestSelector = getBestSelectorForAction( const bestSelector = getBestSelectorForAction(
{ {
type: action, type: action,
@@ -487,9 +496,9 @@ export class WorkflowGenerator {
* @param coordinates The coordinates of the element. * @param coordinates The coordinates of the element.
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public generateDataForHighlighter = async (page: Page, coordinates: Coordinates) => { public generateDataForHighlighter = async (page: Page, coordinates: Coordinates, getList?: boolean) => {
const rect = await getRect(page, coordinates); const rect = await getRect(page, coordinates);
const displaySelector = await this.generateSelector(page, coordinates, ActionType.Click); const displaySelector = await this.generateSelector(page, coordinates, ActionType.Click, getList);
const elementInfo = await getElementInformation(page, coordinates); const elementInfo = await getElementInformation(page, coordinates);
if (rect) { if (rect) {
this.socket.emit('highlighter', { rect, selector: displaySelector, elementInfo }); this.socket.emit('highlighter', { rect, selector: displaySelector, elementInfo });