Я пробую webrt c, используя библиотеку, простой peer. Я следую этому уроку, связанному здесь в браузере Opera. Я сталкиваюсь с этой ошибкой при отправке небольшой строки 'hello':
Uncaught DOMException: Failed to execute 'send' on 'RTCDataChannel': RTCDataChannel.readyState is not 'open' at Peer.send (http://127.0.0.1:9966/bundle.js:7011:19) at HTMLButtonElement.<anonymous> (http://127.0.0.1:9966/bundle.js:22:14) send @ index.js:241 (anonymous) @ index.js:21
Вот мой индекс. js:
var Peer = require('simple-peer')
if (Peer.WEBRTC_SUPPORT) {
console.log("Support");
peer = new Peer({
initiator: location.hash === '#1',
trickle:true
})
peer.on('signal', function (data) {
document.getElementById('yourId').value = JSON.stringify(data)
})
document.getElementById("connect").addEventListener('click', function () {
var otherId = JSON.parse(document.getElementById('otherId').value)
peer.signal(otherId)
})
peer.on('connect', function () {
console.log("CONNECTED");
})
document.getElementById("send").addEventListener('click', function () {
var message = document.getElementById("message_to_send").value
peer.write(message)
})
peer.on("data", function (data) {
console.log(data)
document.getElementById("messages").textContent += data + "\n"
})
} else {
console.log("No Support, Sorry");
}
Изменение peer.send(data)
на peer.write(data)
выдает ошибку, но не отправляет данные в другой браузер
Что я делаю не так? Заранее спасибо