I am beginner in javascript. Sorry, If i asked silly question. This is the code which i am trying to get the list of media element.
function getCams(){
var media_list = [];
MediaStreamTrack.getSources(function(sourceInfos){
var i=0;
while(i!=sourceInfos.length){
if (sourceInfos[i].kind == 'video'){
var temp = [];
temp.push(sourceInfos[i].id);
temp.push(sourceInfos[i].label);
media_list.push(temp);
}
i++;
}
console.log(media_list);
});
return media_list
}
But when i am calling this function it return blank list, but in console.log(media_list) it logs the list with elements data. May be its running asynchronously, if this is the case then how to rewrite this function to run sychronously so that i am able to get the list of media elements?
if this is not the case then please guide how can i get that list.