簡體   English   中英

在“RTCDataChannel”簡單對等點上執行“發送”時出錯

[英]Error in executing 'send' on 'RTCDataChannel' simple-peer

我正在使用庫 simple-peer 嘗試 webrtc。 我正在關注在 Opera 瀏覽器上鏈接本教程。 發送一小串“你好”時,我遇到了這個錯誤:

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

這是我的 index.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)確實會產生任何錯誤,但也不會將數據發送到其他瀏覽器

我究竟做錯了什么? 提前致謝

我讓它工作。 如果對任何人有用:我使用的是 Opera 瀏覽器,它阻止了我的 IP 地址“泄漏”。 切換到 Chrome 就像一個魅力使用此鏈接查看您的瀏覽器是否阻止了您的 IP 地址: https://diafygi.github.io/webrt

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM