Created
November 5, 2019 03:10
-
-
Save kwindla/0abd3223dd076d2d80b64f552b5ffbce to your computer and use it in GitHub Desktop.
Function to loop forever while in a Daily.co call, drawing bounding boxes around faces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function checkForFaces() { | |
try { | |
if (callFrame.meetingState() !== 'joined-meeting') { | |
return; | |
} | |
// remove all bounding boxes | |
for (let el of document.getElementsByClassName('face-boxes')) { | |
el.remove(); | |
} | |
// detect faces | |
let msg = await callFrame.detectAllFaces(); | |
// add bounding boxes | |
iframeBounds = callFrame.iframe().getBoundingClientRect(); | |
for (let participant of Object.values(msg.faces)) { | |
for (let face of participant) { | |
let el = document.createElement('div'); | |
el.style.position = 'fixed'; | |
el.style.border = '2px dashed yellow'; | |
el.style.top = iframeBounds.top + face.viewportBox.top; | |
el.style.left = iframeBounds.left + face.viewportBox.left; | |
el.style.width = face.viewportBox.width; | |
el.style.height = face.viewportBox.height; | |
document.body.appendChild(el); | |
el.className = 'face-boxes'; | |
} | |
} | |
setTimeout(checkForFaces, 100); | |
} catch (e) { | |
console.error(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment