【webrtc】webrtc中音视频设备管理(9)


//index.html中
<!DOCTYPE html>
<html>
<head>
  <title>webrtc test</title>
</head>
<body>
  <script src="./js/client.js"></script>  
</body>
</html>



//client.js中
'use strict';

if( !navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices ){
    console.log('enumerateDevices is not support!')
}else{
    navigator.mediaDevices.enumerateDevices()
    .then(gotDevices)
    .catch(handleError);
}

function gotDevices(deviceInfos) {
    deviceInfos.forEach((deviceInfo) => {
        console.log(deviceInfo.kind + ':label = ' + deviceInfo.label + ':id = ' + deviceInfo.deviceId + ':groupId = ' + deviceInfo.groupId);
    });
}

function handleError (err){
    console.log(err);
}

目录结构

示例github地址
原文地址:https://www.cnblogs.com/smileyqp/p/12675307.html