#javascript #webrtc #web-development-server
Вопрос:
Я создал предложение со стороны peer_a, а также ответ со стороны peer_b.В этой части кода все в порядке, но канал не открывается, я не знаю, в чем проблема, пожалуйста, помогите мне, я новичок в этом протоколе.
Peer_a()
function Peer_a(){
const iceConfiguration = { }
iceConfiguration.iceServers = [];
iceConfiguration.iceServers.push(
{url:'stun:stun01.sipphone.com'},
{url:'stun:stun.ekiga.net'},
{url:'stun:stun.fwdnet.net'},
{url:'stun:stun.ideasip.com'},
{url:'stun:stun.iptel.org'},
{url:'stun:stun.rixtelecom.se'},
{url:'stun:stun.schlund.de'},
{url:'stun:stun.l.google.com:19302'},
{url:'stun:stun1.l.google.com:19302'},
{url:'stun:stun2.l.google.com:19302'},
{url:'stun:stun3.l.google.com:19302'},
{url:'stun:stun4.l.google.com:19302'},
{url:'stun:stunserver.org'},
{url:'stun:stun.softjoys.com'},
{url:'stun:stun.voiparound.com'},
{url:'stun:stun.voipbuster.com'},
{url:'stun:stun.voipstunt.com'},
{url:'stun:stun.voxgratia.org'},
{url:'stun:stun.xten.com'},
)
const localConnection = new RTCPeerConnection(iceConfiguration)
lc = localConnection
lc.onicecandidate = e => {
obj = e;
console.log(" NEW ice candidnat!! on localconnection reprinting SDP " )
offer = JSON.stringify(lc.localDescription)
}
sendChannel = lc.createDataChannel("sendChannel");
sendChannel.onmessage =e => console.log("messsage received!!!" e.data )
sendChannel.onopen = e => console.log("open!!!!");
sendChannel.onclose =e => console.log("closed!!!!!!");
lc.createOffer().then(o => lc.setLocalDescription(o))
}
Peer_b()
async function peer_b(){
const offer = JSON.parse(document.querySelector('#frndid2').value)
const remoteConnection = new RTCPeerConnection()
rc = remoteConnection
rc.onicecandidate = e => {
console.log(" NEW ice candidnat!! on localconnection reprinting SDP " )
answer = JSON.stringify(rc.localDescription)
}
rc.ondatachannel= e => {
receiveChannel = e.channel;
receiveChannel.onmessage =e => console.log("messsage received!!!" e.data )
receiveChannel.onopen = e => console.log("open!!!!");
receiveChannel.onclose =e => console.log("closed!!!!!!");
rc.channel = receiveChannel;
}
rc.setRemoteDescription(offer).then(a=>console.log("done"))
//create answer
await rc.createAnswer().then(a => rc.setLocalDescription(a)).then(a=>
console.log(JSON.stringify(rc.localDescription)))
}
Когда peer_a нажимает кнопку далее
function next_page(){
const answer = JSON.parse(document.querySelector('#frndid').value)
console.log(answer);
lc.setRemoteDescription (answer).then(a=>console.log("done"))
sendChannel.onmessage =e => console.log("messsage received!!!" e.data )
sendChannel.onopen = e => console.log("open!!!!");
sendChannel.onclose =e => console.log("closed!!!!!!");
}
When peer_b clicks next button
function next_page_2(){
rc.ondatachannel= e => {
receiveChannel = e.channel;
receiveChannel.onmessage =e => console.log("messsage received!!!" e.data )
receiveChannel.onopen = e => console.log("open!!!!");
receiveChannel.onclose =e => console.log("closed!!!!!!");
rc.channel = receiveChannel;
}
}
when peer_a clicks the next button «done» was displayed on the console but «open!!!!» is not printing anywhere.