fix: improve camera toggle detection with better logging and state verification
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
50f1f1977e
commit
06ff78d2f8
1 changed files with 57 additions and 18 deletions
|
|
@ -318,28 +318,67 @@ export class BotOrchestrator {
|
||||||
*/
|
*/
|
||||||
private async _ensureCameraOn(): Promise<void> {
|
private async _ensureCameraOn(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
// Look for camera toggle button
|
// Try multiple selectors for the camera toggle
|
||||||
const cameraBtn = await this._page!.$('button[data-tid="toggle-video"], button[aria-label*="camera" i], button[aria-label*="Camera" i], button[aria-label*="Video" i]');
|
const cameraSelectors = [
|
||||||
if (cameraBtn) {
|
'button[data-tid="toggle-video"]',
|
||||||
// Check if camera is currently off (aria-pressed="false" or similar)
|
'button[aria-label*="camera" i]',
|
||||||
const isOff = await cameraBtn.evaluate((el) => {
|
'button[aria-label*="Camera" i]',
|
||||||
return el.getAttribute('aria-pressed') === 'false' ||
|
'button[aria-label*="Video" i]',
|
||||||
el.getAttribute('aria-checked') === 'false' ||
|
'#video-toggle-button',
|
||||||
el.classList.contains('is-off') ||
|
'[data-tid="prejoin-camera-toggle"]',
|
||||||
el.querySelector('.fui-Icon-regular') !== null;
|
];
|
||||||
});
|
|
||||||
if (isOff) {
|
let cameraBtn = null;
|
||||||
await cameraBtn.click();
|
let matchedSelector = '';
|
||||||
this._logger.info('Camera toggled ON');
|
for (const sel of cameraSelectors) {
|
||||||
await this._page!.waitForTimeout(1000);
|
cameraBtn = await this._page!.$(sel);
|
||||||
} else {
|
if (cameraBtn) {
|
||||||
this._logger.info('Camera already ON');
|
matchedSelector = sel;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cameraBtn) {
|
||||||
|
this._logger.warn('Camera toggle button not found with any selector');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log button details for debugging
|
||||||
|
const btnInfo = await cameraBtn.evaluate((el) => {
|
||||||
|
return {
|
||||||
|
ariaLabel: el.getAttribute('aria-label') || '',
|
||||||
|
ariaPressed: el.getAttribute('aria-pressed'),
|
||||||
|
ariaChecked: el.getAttribute('aria-checked'),
|
||||||
|
dataTid: el.getAttribute('data-tid') || '',
|
||||||
|
className: el.className?.substring(0, 80) || '',
|
||||||
|
title: el.getAttribute('title') || '',
|
||||||
|
innerText: el.innerText?.trim()?.substring(0, 30) || '',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
this._logger.info(`Camera button found: ${matchedSelector} | aria-label="${btnInfo.ariaLabel}" | aria-pressed=${btnInfo.ariaPressed} | title="${btnInfo.title}"`);
|
||||||
|
|
||||||
|
// Determine if camera is off — click to turn it ON
|
||||||
|
// In Teams pre-join: aria-pressed="false" means camera is OFF
|
||||||
|
const shouldClick = btnInfo.ariaPressed === 'false' || btnInfo.ariaChecked === 'false';
|
||||||
|
|
||||||
|
if (shouldClick) {
|
||||||
|
await cameraBtn.click();
|
||||||
|
this._logger.info('Camera toggled ON (was off)');
|
||||||
|
await this._page!.waitForTimeout(2000);
|
||||||
|
|
||||||
|
// Verify the toggle worked
|
||||||
|
const afterState = await cameraBtn.evaluate((el) => el.getAttribute('aria-pressed'));
|
||||||
|
this._logger.info(`Camera state after toggle: aria-pressed=${afterState}`);
|
||||||
|
} else if (btnInfo.ariaPressed === null && btnInfo.ariaChecked === null) {
|
||||||
|
// No aria state — click anyway to turn camera on (safe default)
|
||||||
|
await cameraBtn.click();
|
||||||
|
this._logger.info('Camera clicked (no aria state detected, assuming toggle)');
|
||||||
|
await this._page!.waitForTimeout(2000);
|
||||||
} else {
|
} else {
|
||||||
this._logger.warn('Camera toggle button not found');
|
this._logger.info('Camera already ON (aria-pressed=true)');
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._logger.warn('Could not toggle camera:', err);
|
this._logger.warn(`Could not toggle camera: ${err}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue