2021-09-22 11:51:29 +08:00
|
|
|
const e = require('../core/elements');
|
2021-02-26 23:52:17 +08:00
|
|
|
const { sleep } = require('../core/helper');
|
2021-10-07 22:29:18 +08:00
|
|
|
const { checkElement } = require('../core/util');
|
2021-02-26 23:52:17 +08:00
|
|
|
const {
|
2021-08-21 04:33:57 +08:00
|
|
|
LOOP_INTERVAL,
|
|
|
|
ELEMENT_WAIT_LONGER_TIME,
|
2021-02-26 23:52:17 +08:00
|
|
|
} = require('../core/constants');
|
2020-03-05 03:00:45 +08:00
|
|
|
|
2020-03-05 01:44:05 +08:00
|
|
|
async function evaluateCheck(test) {
|
2021-09-22 21:11:56 +08:00
|
|
|
await test.waitForSelector(e.videoContainer);
|
2021-09-22 11:51:29 +08:00
|
|
|
return test.page.evaluate(checkElement, e.presentationFullscreenButton, 1);
|
2020-03-05 01:44:05 +08:00
|
|
|
}
|
|
|
|
|
2020-03-10 23:20:48 +08:00
|
|
|
async function startAndCheckForWebcams(test) {
|
|
|
|
await enableWebcam(test);
|
|
|
|
const response = await evaluateCheck(test);
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2020-03-27 02:52:15 +08:00
|
|
|
async function webcamContentCheck(test) {
|
2021-09-22 21:11:56 +08:00
|
|
|
await test.waitForSelector(e.videoContainer);
|
2021-09-22 11:51:29 +08:00
|
|
|
await test.waitForElementHandleToBeRemoved(e.webcamConnecting, ELEMENT_WAIT_LONGER_TIME);
|
2020-03-27 02:52:15 +08:00
|
|
|
const repeats = 5;
|
|
|
|
let check;
|
|
|
|
for (let i = repeats; i >= 1; i--) {
|
2021-08-14 04:26:47 +08:00
|
|
|
test.logger(`loop ${i}`);
|
2020-03-27 02:52:15 +08:00
|
|
|
const checkCameras = function (i) {
|
|
|
|
const videos = document.querySelectorAll('video');
|
|
|
|
const lastVideoColor = document.lastVideoColor || {};
|
|
|
|
document.lastVideoColor = lastVideoColor;
|
2020-03-12 00:07:16 +08:00
|
|
|
|
2020-03-27 02:52:15 +08:00
|
|
|
for (let v = 0; v < videos.length; v++) {
|
|
|
|
const video = videos[v];
|
|
|
|
const canvas = document.createElement('canvas');
|
|
|
|
const context = canvas.getContext('2d');
|
|
|
|
context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
|
2021-08-18 00:33:41 +08:00
|
|
|
const pixel = context.getImageData(0, 0, 1, 1).data;
|
2020-09-22 02:22:11 +08:00
|
|
|
const pixelString = new Array(pixel).join(' ').toString();
|
|
|
|
|
|
|
|
if (lastVideoColor[v]) {
|
|
|
|
if (lastVideoColor[v] == pixelString) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastVideoColor[v] = pixelString;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
check = await test.page.evaluate(checkCameras, i);
|
2021-08-18 00:33:41 +08:00
|
|
|
if (!check) return false;
|
2021-02-26 23:52:17 +08:00
|
|
|
await sleep(LOOP_INTERVAL);
|
2020-09-22 02:22:11 +08:00
|
|
|
}
|
|
|
|
return check === true;
|
|
|
|
}
|
|
|
|
|
2020-03-10 23:20:48 +08:00
|
|
|
exports.startAndCheckForWebcams = startAndCheckForWebcams;
|
|
|
|
exports.webcamContentCheck = webcamContentCheck;
|
2020-03-05 01:44:05 +08:00
|
|
|
exports.evaluateCheck = evaluateCheck;
|