Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var ids = [];
            var counter = 0;
            MediaStreamTrack.getSources( onStreamSources );
            function onStreamSources( sources ){
                var i = -1;
                var len = sources.length;
                var ids = [];
                while( ++i < len ){
                    if( sources[ i ].kind === "audio" ){
                        getAudioSource( sources[i].id );
                    } else {
                        getVideoSouce( sources[i].id );
                    }
                }
            }
            function getAudioSource( id ){
                counter++;
                navigator.webkitGetUserMedia({
                    "audio": {
                        "optional": [{
                            "sourceId": id
                        }]
                    },
                    "video": false
                }, onGetUserMedia("audio"), onGetUserMediaFail);
            }
            function getVideoSouce( id ){
                counter++;
                navigator.webkitGetUserMedia({
                    "video": {
                        "optional": [{
                            "sourceId": id
                        }]
                    },
                    "audio": false
                }, onGetUserMedia("video"), onGetUserMediaFail);
            }
            function onGetUserMedia( _type ){
                var type = _type === "audio" ? "getAudioTracks" : "getVideoTracks";
                return function( stream ){
                    var track = stream[type]()[0];
                    ids.push({
                        "label": track.label,
                        "sourceId": track.id
                    });
                    stream.stop();
                    counter--;
                    if( counter === 0 ){
                        console.log( ids );
                    }
                };
            }
            function onGetUserMediaFail(){
                console.log("error");
                counter--;
            }
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
DanElliottPalmerpro
0viewers