Skip to content

Instantly share code, notes, and snippets.

@CezaryDanielNowak
Last active May 29, 2024 11:28
Show Gist options
  • Save CezaryDanielNowak/1afedcd47f4bc5f093e08329b7ca7dbe to your computer and use it in GitHub Desktop.
Save CezaryDanielNowak/1afedcd47f4bc5f093e08329b7ca7dbe to your computer and use it in GitHub Desktop.
(function() {
const realGetUserMedia = navigator.mediaDevices.getUserMedia;
const realApplyConstraints = MediaStreamTrack.prototype.applyConstraints;
function successHandler(...args) {
try {
const track = args[0].getVideoTracks()[0];
console.log('πŸ’₯πŸ’₯πŸ’₯', track.label, 'camera access granted.\n', track.getSettings());
} catch(err) {
console.warn('πŸ’₯πŸ’₯πŸ’₯ error', err);
}
}
function failHandler(...args) {
console.warn('πŸ’₯πŸ’₯πŸ’₯ fail handler', args);
}
navigator.mediaDevices.getUserMedia = function (...args) {
console.log('πŸ’₯πŸ’₯πŸ’₯ getUserMedia', ...args);
const result = realGetUserMedia.apply(this, args);
result.then(successHandler, failHandler);
return result;
};
MediaStreamTrack.prototype.applyConstraints = function(...args) {
console.log('πŸ’₯πŸ’₯πŸ’₯ applyConstraints', ...args);
return realApplyConstraints.apply(this, args);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment