【发布时间】:2015-12-10 10:28:11
【问题描述】:
chrome 是否支持基于 Promise 的 WebRTC API?我无法让基于 getUserMedia() 承诺的 API 在 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>
在控制台上,我看到以下错误
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.
我想使用基于 Promise 的 API。我错过了什么吗?
【问题讨论】:
-
在提供上述代码时(使用适配器 shim),我在 Firefox 上也遇到了同样的错误。 Firefox 表示它支持基于 Promise 的 API here
-
@Kevin 我正在使用垫片/适配器。而且我认为它利用了 Navigator.MediaDevices.getUserMedia
-
@Kevin - 你指的是正确的问题。如果我不使用 getUserMedia(),而是使用 navigator.mediaDevices.getUserMedia(),那么基于 Promise 的 API 就可以工作。我假设适配器/垫片层将处理此类问题,并将别名为适当的 API(在本例中为 navigator.mediaDevices.getUserMedia())。你能把它作为答案,以便我接受吗?
-
我不确定你的问题是什么,所以我无法制定一个有利于未来用户的正确答案。但是你可以回答你自己的问题并接受它,你可以准确地解释你做了什么来使它起作用。
标签: google-chrome webrtc getusermedia