我正在尝试学习 WebRTC 。我复制了一些代码,我得到了这个错误:
未能在“RTCDataChannel”上执行“发送”:RTCDataChannel.readyState 不是“打开”
任何人都可以帮忙吗?
代码分数:http ://www.tutorialspoint.com/webrtc/webrtc_text_demo.htm
我正在尝试学习 WebRTC 。我复制了一些代码,我得到了这个错误:
未能在“RTCDataChannel”上执行“发送”:RTCDataChannel.readyState 不是“打开”
任何人都可以帮忙吗?
代码分数:http ://www.tutorialspoint.com/webrtc/webrtc_text_demo.htm
ondatachannel
删除后添加处理{optional: [{RtpDataChannels: true}]}
:
myConnection.onicecandidate = function (event) {
if (event.candidate) {
send({
type: "candidate",
candidate: event.candidate
});
}
};
myConnection.ondatachannel = function(event) {
var receiveChannel = event.channel;
receiveChannel.onmessage = function(event) {
console.log("ondatachannel message:", event.data);
};
};
openDataChannel();
The same error was thrown to me .This is because your peers are not connected and you are sending data.This was solved by this:
peer.on('connect', () => {
console.log('I am connected now')
peer.send('sending data blah blah')
})