Icontem

Optimization

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      WebCodeCam  >  All threads  >  Optimization  >  (Un) Subscribe thread alerts  
Subject:Optimization
Summary:Improvement for MediaStreamTrack condition
Messages:2
Author:Markus Kuespert
Date:2015-02-18 09:38:53
 

  1. Optimization   Reply   Report abuse  
Picture of Markus Kuespert 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);
}

  2. Re: Optimization   Reply   Report abuse  
Picture of Andras Toth Andras Toth - 2015-02-18 12:14:45 - In reply to message 1 from Markus Kuespert
Hi Markus!

Thank you very much!
This is a very good observation.
I will include it.

Regards,
András