【发布时间】:2022-01-24 11:44:07
【问题描述】:
当我运行这段代码时连接没有建立,
-
在 Firefox 控制台中出现错误“WebRTC: ICE failed, add a STUN server and 有关更多详细信息,请参见 about:webrtc”显示,并且 dataChannel.readyState 是 连接
-
在 Chrome 控制台中错误未出现但再次出现 dataChannel.readyState 正在连接
var localconn, remoteconn, dataChannel, recievedDataChannel; connect(); async function connect(){ localconn = new RTCPeerConnection(); remoteconn = new RTCPeerConnection(); dataChannel = localconn.createDataChannel("dataChannel"); dataChannel.onopen = e =>{ console.log("data channel is open"); } dataChannel.onmessage = e=>{ console.log("new message: " +e.data); } remoteconn.ondatachannel = e =>{ recievedDataChannel = e.channel; recievedDataChannel.onmessage = e=>{ console.log("new message from remote : " +e.data); } } var offer = await localconn.createOffer(); await localconn.setLocalDescription(offer); await remoteconn.setRemoteDescription(offer); var answer = await remoteconn.createAnswer(); await remoteconn.setLocalDescription(answer); await localconn.setRemoteDescription(answer);}
【问题讨论】:
标签: javascript webrtc p2p