一个简单的web RTC demo


使用HTML5新属性,访问摄像头

var getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);

getUserMedia.call(navigator, {
    video: true,
    audio: true
}, function(localMediaStream) {
    var video = document.getElementById('video');
    video.src = window.URL.createObjectURL(localMediaStream);
    video.onloadedmetadata = function(e) {
        console.log("Label: " + localMediaStream.label);
        console.log("AudioTracks" , localMediaStream.getAudioTracks());
        console.log("VideoTracks" , localMediaStream.getVideoTracks());
    };
}, function(e) {
    console.log('Reeeejected!', e);
});

效果如下:

webrtc demo


参考文档


Author: Itaken
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Itaken !
  TOC目录