WebRTC getUserMedia承诺在Chrome中支持API [英] WebRTC getUserMedia promise api support in Chrome
问题描述
Chrome支持基于WebRTC的API吗?我无法获得在Chrome中使用getUserMedia()承诺的API。
<!DOCTYPE html>
< html>
< head>
< title> Mitel WebRTC客户端< / title>
< script src =https://webrtc.github.io/adapter/adapter-latest.js>< / script>
< script src ='dist / webrtc.min.js'>< / script>
< script type =text / javascript>
函数startUp(){
var options = {
audio:true,
video:true
};
if(getUserMedia){
getUserMedia(options)
.then(function(stream){
console.log(Acquired audio and video!);
})
.catch(function(err){
console.log(err.name +:+ err.message);
});
} else {
alert(这个浏览器不支持WebRTC);
}
}
< / script>
< / head>
< body onload =startUp();>
< h1> WebRTC Promise API客户端应用程序< / h1>
< / body>
< / html>
在控制台上,我看到以下错误:
这似乎是Chrome
adapter-latest.js:32 chrome:{audio:true,video:true}
adapter-latest .js:410 Uncaught TypeError:未能在'Navigator'上执行'webkitGetUserMedia':作为参数2提供的回调不是函数。
我想使用基于promise的API。我错过了什么?
它尚未在Chrome中实现,但它在那里工作,如果您使用官方 adapter.js WebRTC填充: https://jsfiddle.net/srn9db4h/
var constraints = {video:true,audio :true};
navigator.mediaDevices.getUserMedia(constraints)
.then(stream => video.srcObject = stream)
.catch(e => console.error(e) );
Firefox和Edge本身支持FWIW。
更新: Chrome(50)现在似乎支持此功能。 Chrome 52甚至支持 srcObject
。
Does chrome support promise based APIs for WebRTC? I am not able to get the getUserMedia() promised based API working in Chrome.
<!DOCTYPE html>
<html>
<head>
<title> Mitel WebRTC client </title>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script src='dist/webrtc.min.js'></script>
<script type="text/javascript">
function startUp() {
var options = {
audio: true,
video: true
};
if (getUserMedia) {
getUserMedia(options)
.then(function (stream) {
console.log("Acquired audio and video!");
})
.catch(function (err) {
console.log(err.name + ": " + err.message);
});
} else {
alert("WebRTC not supported on this browser");
}
}
</script>
</head>
<body onload="startUp();">
<h1>WebRTC Promise API Client Application</h1>
</body>
</html>
On the console, I see the following error
This appears to be Chrome
adapter-latest.js:32 chrome: {"audio":true,"video":true}
adapter-latest.js:410 Uncaught TypeError: Failed to execute 'webkitGetUserMedia' on 'Navigator': The callback provided as parameter 2 is not a function.
I want to make use of promise based API. Am I missing something?
It is not implemented yet in Chrome, but it works there if you use the official adapter.js WebRTC polyfill: https://jsfiddle.net/srn9db4h/
var constraints = { video: true, audio: true };
navigator.mediaDevices.getUserMedia(constraints)
.then(stream => video.srcObject = stream)
.catch(e => console.error(e));
Firefox and Edge support it natively FWIW.
Update: Chrome (50) appears to support this now. And Chrome 52 even supports srcObject
.
这篇关于WebRTC getUserMedia承诺在Chrome中支持API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!