I am trying to make this code work and don\'t know why is it not working locally. I tried the same on CodePen.io and it works.
Detailed discussion why camera (and microphone are not working on localhost here):
How to allow Chrome to access my camera on localhost?
In short, it is explicitly blocked.