webrtc配置返回空值
我正在为peerconnection实现webrtc,但不起作用。当我调试这段代码时,我看到它没有出现webrtc配置返回空值,webrtc,Webrtc,我正在为peerconnection实现webrtc,但不起作用。当我调试这段代码时,我看到它没有出现 theirConnection.onaddstream = function (e) { theirVideo.src = window.URL.createObjectURL(e.stream); }; 街区。请告诉我哪里做错了?我在本地系统上使用它,并且只有一个网络摄像头 function startPeerConnection(stream) {
theirConnection.onaddstream = function (e) {
theirVideo.src = window.URL.createObjectURL(e.stream);
};
街区。请告诉我哪里做错了?我在本地系统上使用它,并且只有一个网络摄像头
function startPeerConnection(stream) {
var configuration = {
"iceServers": [{ "url": "stun:127.0.0.1:8080" }]
};
yourConnection = new mozRTCPeerConnection(configuration);
theirConnection = new mozRTCPeerConnection(configuration);
// Setup stream listening
theirConnection.onaddstream = function (e) {
theirVideo.src = window.URL.createObjectURL(e.stream);
};
// 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);
});
});
}
你把承诺称为方法。问题是你没有检查错误 具体地说:您寻求的参数至少需要两个参数:成功回调和失败回调 在没有失败回调的情况下,WebIDL名称重载反而调用,它不接受回调,而是返回承诺 在任何地方传入所需的错误回调,例如:
yourConnection.createOffer(offer => { ... }, err => console.log(err));
或者更好,完全避免使用遗留方法:
功能启动对等连接(流){
var-config={iceServers:[{URL:“stun:127.0.0.1:8080”}];
您的=新的RTPeerConnection(配置);
他们的=新的RTPeerConnection(配置);
theirs.onaddstream=e=>theirVideo.srcObject=e.stream;
yours.onicecandidate=e=>他们的.addIceCandidate(e.candidate);
theates.onicecandidate=e=>yours.addIceCandidate(e.candidate);
addStream(stream);//您正在调用promise方法。问题是您没有检查错误
具体地说:您寻求的参数至少需要两个参数:成功回调和失败回调
在没有失败回调的情况下,WebIDL名称重载反而调用,它不接受回调,而是返回承诺
在任何地方传入所需的错误回调,例如:
yourConnection.createOffer(offer => { ... }, err => console.log(err));
或者更好,完全避免使用遗留方法:
功能启动对等连接(流){
var-config={iceServers:[{URL:“stun:127.0.0.1:8080”}];
您的=新的RTPeerConnection(配置);
他们的=新的RTPeerConnection(配置);
theirs.onaddstream=e=>theirVideo.srcObject=e.stream;
yours.onicecandidate=e=>他们的.addIceCandidate(e.candidate);
theates.onicecandidate=e=>yours.addIceCandidate(e.candidate);
你的.addStream(stream)//