Javascript MediaStream摄像头和麦克风标签是否在获得许可之前?
让这种方式起作用是很简单的: 在选择设备之前呢Javascript MediaStream摄像头和麦克风标签是否在获得许可之前?,javascript,ecmascript-6,webrtc,webcam-capture,mediastream,Javascript,Ecmascript 6,Webrtc,Webcam Capture,Mediastream,让这种方式起作用是很简单的: 在选择设备之前呢 navigator.mediaDevices .enumerateDevices() .then(this.gotDevices.bind(this)) .catch(this.alertsService.add.bind(this.alertsService)); } gotDevices(deviceInfos: MediaDeviceInfo[]) { this.mediaDeviceInfos = de
navigator.mediaDevices
.enumerateDevices()
.then(this.gotDevices.bind(this))
.catch(this.alertsService.add.bind(this.alertsService));
}
gotDevices(deviceInfos: MediaDeviceInfo[]) {
this.mediaDeviceInfos = deviceInfos;
this.mediaDeviceInfos.forEach(device => {
if (device.kind === 'audioinput')
this.mics.push(device);
else if (device.kind === 'videoinput')
this.cams.push(device);
else
console.warn(`Unexpected: ${JSON.stringify(device)}`);
});
}
this.mediadeviceinfo.somedev=>dev.label为false。因此,我必须在输入中使用dev.deviceId,这很难看:
我需要这里选择的特定设备,因为我这样使用它,以支持多个摄像头和麦克风:
const constraints: MediaStreamConstraints = {
audio: { advanced: [{ deviceId: mic.deviceId, groupId: mic.groupId }] },
video: { advanced: [{ deviceId: cam.deviceId, groupId: cam.groupId }] }
};
如何获取相机和麦克风的标签,以便用户可以在主题中选择它们?您可以在中调用navigator.mediaDevices.enumerateDevices。然后链接到navigator.mediaDevices.getUserMedia。当协议为https:且向一个或多个设备授予权限时,MediaDeviceInfo对象标签属性应设置为可用的媒体设备
navigator.mediaDevices.getUserMedia(/* {video:true, audio:true} */)
.then(stream =>
navigator.mediaDevices
.enumerateDevices()
.then(devices => {
return devices
})
.catch(err => {throw err})
)
.then(devices => {
console.log(devices);
for (const mediaDeviceInfo of devices) {
const {deviceId, kind, label} = mediaDeviceInfo;
console.log(deviceId, kind, label);
}
})
.catch(err => console.error(err))
是否在此位置未获取具有label属性的对象。MediaDeviceInfo=DeviceInfo;?是的,但标签总是在Firefox 57.0b6和57.0b7 64位上。等等,刚刚检查了Chrome,它在那里工作。嗯…Firefox 56.0.1 64位alsoFirefox上的确认标签尚未请求https协议,但是的,为了安全措施避免指纹,您需要获得用户许可,才能获得标签,并且确实需要通过gUM请求,你的函数可以在你访问标签后关闭gUM请求,我写了这篇文章,但我仍然不理解你的答案,答案几乎是一样的:@SamuelMarks你也可以在FF中使用deviceId,你甚至可以访问所有可用设备的列表。你不能做的是,得到他们的标签,即制造商名称,这是为了避免随机网站通过这些个人信息识别你。要获取此信息,在FF中,您需要获得用户的批准才能使用这些设备中的至少一个。因此,如果您真的想显示这些标签,您可以执行第一个请求,仅用于访问设备标签。或者你也可以使用通用名称:Chrome有同样严格的政策,在用户允许访问之前不显示设备标签。但它更积极地坚持许可,这可能使它看起来行为有所不同。@PhilippHancke说得对。你知道工作组中是否讨论过一种方法,让我们的web开发人员在不进行gUM请求的情况下请求用户权限,这本身可能是有用的,例如,对于这个确切的案例,它涵盖了这个主题。这似乎不太可能改变,但请随意在此处提出一个问题:
navigator.mediaDevices.getUserMedia(/* {video:true, audio:true} */)
.then(stream =>
navigator.mediaDevices
.enumerateDevices()
.then(devices => {
return devices
})
.catch(err => {throw err})
)
.then(devices => {
console.log(devices);
for (const mediaDeviceInfo of devices) {
const {deviceId, kind, label} = mediaDeviceInfo;
console.log(deviceId, kind, label);
}
})
.catch(err => console.error(err))