我使用WebRTC连接了2个Chrome浏览器。我offer在第一个signalR客户端上创建并将其发送给第二个客户端,如下所示:
function initiate_call() {
callerPeerConn = new RTCPeerConnection(peerConnCfg);
callerPeerConn.ontrack = function (event) {
console.log('caller recived new stream');
remoteVideo.srcObject = event.streams[0];
console.log(event);
}
navigator.mediaDevices.getUserMedia({ audio: true, video: true })
.then(function (stream) {
localVideo.srcObject = stream;
for (const track of stream.getTracks()) {
callerPeerConn.addTrack(track, stream);
}
return callerPeerConn.createOffer();
})
.then(
function (offer) {
var off = new RTCSessionDescription(offer);
callerPeerConn.setLocalDescription(
new RTCSessionDescription(off),
function () {
// invite to video chat
console.log('send offer');
},
function (err) {
console.log(err.message);
}
)
});
}
当我使用第二个浏览器时,offer他使用setLocalDescription并尝试创建,而answer不是像这样将其发送给呼叫者:
function accept_send_answer(){
calleePeerConn = new RTCPeerConnection(peerConnCfg);
calleePeerConn.ontrack = function (event) {
console.log('callee accept offer and got streams');
remoteVideo.srcObject = event.streams[0];
}
calleePeerConn.setRemoteDescription(offer)
.then(function () {
return navigator.mediaDevices.getUserMedia({ audio: true, video: true });
})
.then(function (stream) {
localVideo.srcObject = stream;
for (const track of stream.getTracks()) {
calleePeerConn.addTrack(track, stream);
}
return calleePeerConn.createAnswer();
})
})
.catch(function (err) {
console.log(err.message);
});
}
白衣染霜花
相关分类