2021-11-27 04:01:41 +08:00
|
|
|
const e = require('../core/elements');
|
|
|
|
const { sleep } = require('../core/helpers');
|
2021-12-02 12:12:14 +08:00
|
|
|
const { LOOP_INTERVAL, ELEMENT_WAIT_LONGER_TIME } = require('../core/constants');
|
2021-11-27 04:01:41 +08:00
|
|
|
|
|
|
|
async function webcamContentCheck(test) {
|
2022-02-03 08:05:26 +08:00
|
|
|
await test.waitForSelector(e.webcamVideoItem);
|
2021-11-27 04:01:41 +08:00
|
|
|
await test.wasRemoved(e.webcamConnecting, ELEMENT_WAIT_LONGER_TIME);
|
|
|
|
const repeats = 5;
|
|
|
|
let check;
|
|
|
|
for (let i = repeats; i >= 1; i--) {
|
|
|
|
console.log(`loop ${i}`);
|
2021-12-02 13:30:38 +08:00
|
|
|
const checkCameras = () => {
|
2021-11-27 04:01:41 +08:00
|
|
|
const videos = document.querySelectorAll('video');
|
|
|
|
const lastVideoColor = document.lastVideoColor || {};
|
|
|
|
document.lastVideoColor = lastVideoColor;
|
|
|
|
|
|
|
|
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);
|
|
|
|
const pixel = context.getImageData(0, 0, 1, 1).data;
|
|
|
|
const pixelString = new Array(pixel).join(' ').toString();
|
|
|
|
|
|
|
|
if (lastVideoColor[v]) {
|
|
|
|
if (lastVideoColor[v] == pixelString) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastVideoColor[v] = pixelString;
|
|
|
|
}
|
2021-12-08 21:09:58 +08:00
|
|
|
return true;
|
2021-11-27 04:01:41 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
check = await test.page.evaluate(checkCameras, i);
|
|
|
|
if (!check) return false;
|
|
|
|
await sleep(LOOP_INTERVAL);
|
|
|
|
}
|
|
|
|
return check === true;
|
|
|
|
}
|
|
|
|
|
2021-12-04 01:01:36 +08:00
|
|
|
exports.webcamContentCheck = webcamContentCheck;
|