Markus Kuespert - 2015-02-18 09:38:53
Hi Andras,
thank you for this great package! It's really useful!
I've made an improvement I want to share with you. You can move the code for the camera selector to the MediaStreamTrack condition. This way you can also use the code on browsers that support "getUserMedia" but do not support "MediaStreamTrack.getSources" instead of showing the message "This browser does not support MediaStreamTrack":
Before:
var videoSelect = document.querySelector('select#cameraId');
$(videoSelect).change(function(event) {
if (typeof decoder.data().plugin_WebCodeCam == "undefined") return;
decoder.data().plugin_WebCodeCam.options.videoSource.id = $(this).val();
decoder.data().plugin_WebCodeCam.cameraStop();
decoder.data().plugin_WebCodeCam.init();
decoder.data().plugin_WebCodeCam.cameraPlay();
});
...
if (typeof MediaStreamTrack.getSources === 'undefined') {
alert('This browser does not support MediaStreamTrack.\n\nTry Chrome Canary.');
} else {
MediaStreamTrack.getSources(gotSources);
}
After:
if (typeof MediaStreamTrack.getSources !== 'undefined') {
var videoSelect = document.querySelector('select#cameraId');
$(videoSelect).change(function(event) {
if (typeof decoder.data().plugin_WebCodeCam === "undefined") return;
decoder.data().plugin_WebCodeCam.options.videoSource.id = $(this).val();
decoder.data().plugin_WebCodeCam.cameraStop();
decoder.data().plugin_WebCodeCam.init();
decoder.data().plugin_WebCodeCam.cameraPlay();
});
MediaStreamTrack.getSources(gotSources);
}