我正在用node js的socket.io开发一个视频通话应用程序,但事实证明,它仅发出视频,而发出声音时,音频仅产生回声,以实现音频到达客户端?
(function(d, w, n, io) {
"use strict";
var io = io(),
startCamera = false,
video = d.querySelector("#video"),
canvas = d.querySelector("#canvas"),
context = canvas.getContext("2d");
n.streaming =
n.mediaDevices.getUserMedia ||
n.webkitGetUserMedia ||
n.mozGetUserMedia ||
n.msGetUserMedia;
n.streaming(
{
video: true,
audio: true
},
function(stream) {
startCamera = true;
video.src = w.URL.createObjectURL(stream);
},
function(err) {
alert("error al acceder a la camara web: " + err);
}
);
w.playVideo = (function(cb) {
return (
w.requestAnimationFrame ||
w.webkitRequestAnimationFrame ||
w.mozRequestAnimationFrame ||
w.msRequestAnimationFrame ||
function(cb) {
w.setTimeout(cb, 1000 / 100);
}
);
})();
function streamVideo(context, canvas, video) {
var outputStream = canvas.toDataURL("image/jpeg", 0.2);
context.drawImage(video, 0, 0);
if (startCamera) io.emit("streaming", outputStream);
playVideo(function() {
streamVideo(context, canvas, video);
});
}
w.addEventListener("load", function() {
video.autoplay = true;
video.style.display = "none";
streamVideo(context, canvas, video);
});
})(document, window, navigator, io);
答案 0 :(得分:0)
能否请您确认是否要在同一系统上使用两个浏览器测试视频通话应用?这可能就是为什么您收到回声的原因。