Javascript 未捕获类型错误:peerConnection.addstream不是函数?
我正在尝试附加使用Javascript 未捕获类型错误:peerConnection.addstream不是函数?,javascript,webrtc,Javascript,Webrtc,我正在尝试附加使用startPeerConnection(stream)上的getusermedia()捕获的流。我尝试用以下方式添加流 function startPeerConnection(stream) { var configuration = { // Uncomment this code to add custom iceServers // "iceServers": [{ "u
startPeerConnection(stream)
上的getusermedia()
捕获的流。我尝试用以下方式添加流
function startPeerConnection(stream) {
var configuration = {
// Uncomment this code to add custom iceServers //
"iceServers": [{ "url": "stun:stun.1.google.com:19302" }]
};
yourConnection = new RTCPeerConnection(configuration);
theirConnection = new RTCPeerConnection(configuration);
// Setup stream listening
yourConnection.addStream(stream);//***getting the error on this line***
theirConnection.onaddstream = function (e) {
theirVideo.srcObject = e.stream;
theirVideo.play();
};
// Setup ice handling
yourConnection.onicecandidate = function (event) {
if (event.candidate) {
theirConnection.addIceCandidate(new RTCIceCandidate(event.candidate));
}
};
theirConnection.onicecandidate = function (event) {
if (event.candidate) {
yourConnection.addIceCandidate(new RTCIceCandidate(event.candidate));
}
};
// Begin the offer
yourConnection.createOffer(function (offer) {
yourConnection.setLocalDescription(offer);
theirConnection.setRemoteDescription(offer);
theirConnection.createAnswer(function (offer) {
theirConnection.setLocalDescription(offer);
yourConnection.setRemoteDescription(offer);
});
});
};
RTPeerConnection如下所示:
var RTCPeerConnection = function(options) {
var iceServers = options.iceServers || defaults.iceServers;
var constraints = options.constraints || defaults.constraints;
var peerConnection = new PeerConnection(iceServers);
peerConnection.onicecandidate = onicecandidate;
peerConnection.onaddstream = onaddstream;
peerConnection.addStream(options.stream);//***getting error on here ***
function onicecandidate(event) {
if (!event.candidate || !peerConnection) return;
if (options.getice) options.getice(event.candidate);
}
function onaddstream(event) {
options.gotstream && options.gotstream(event);
}
addStream是一个已从标准中删除的方法,Safari没有实现它。 通过替换来切换到addTrack方法
peerConnection.addStream(options.stream);
与
或者在您的项目中包括哪个polyfills addStreamPeerConnection来自哪里?它不在浏览器标准中。我在这里使用了js文件:嗯。。。您正在用一个同名函数覆盖“像这样”中的RTPeerConnection对象。这是个坏主意……依赖标记为“实验”的github repo(已经6年没有涉及过)对WebRTC来说不是个好主意。它有几个问题,我在本期中也列举了这些问题。hye@jib谢谢你的建议,我在这里尝试了你的演示:它看起来很酷。我只是想知道我们如何为此设置远程连接。如果您能提供帮助,我将不胜感激
options.stream.getTracks().forEach(track => peerConnection.addTrack(track, options.stream))