How to detect “Under Expose” or “Over Expose” webcam video in real Time using Vanilla Javascript?

Currently I am working on a HTML page where we classify an image using a webcam or mobile camera, But before classifying an Image, I would love to give user a UI feedback where the border color will appear “Red” when it detects Under/Over Exposed Image/Video inputs.

I have no idea how to start with these!

PS: Please use only Pure JavaScript and no online libraries.