首页 > 其他分享 >【WebRtc】获取媒体设备信息

【WebRtc】获取媒体设备信息

时间:2023-03-10 16:24:09浏览次数:45  
标签:mediaDevices kind obj 媒体 id 获取 deviceId device WebRtc

加载设备信息页面

image.png

加载完设备信息页面

image.png

Code

 /**
     * 加载当前设备的音视频信息
     */
    initInnerLocalDevice() {
      let that = this;
      // 判断是否支持
      if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
        that.$notify({
          title: '警告',
          message: '浏览器不支持获取媒体设备',
          type: 'warning'
        });
        return;
      }
      this.loading = true
      navigator.mediaDevices.enumerateDevices()
          .then(devices => {
            devices.forEach(function (device) {
              let obj = {id: device.deviceId, kind: device.kind, label: device.label}
              if (device.kind === 'audioinput') {
                if (that.audioInArray.filter(e => e.id === device.deviceId).length === 0) {
                  that.audioInArray.push(obj)
                }
              } else if (device.kind === 'audiooutput') {
                if (that.audioOutArray.filter(e => e.id === device.deviceId).length === 0) {
                  that.audioOutArray.push(obj)
                }
              } else if (device.kind === 'videoinput') {
                if (that.videoOutArray.filter(e => e.id === device.deviceId).length === 0) {
                  that.videoOutArray.push(obj)
                }
              }
            });
            this.loading = false
          }).catch(this.handleError);
    }

标签:mediaDevices,kind,obj,媒体,id,获取,deviceId,device,WebRtc
From: https://www.cnblogs.com/HelloWxl/p/17203772.html

相关文章