首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在'RTCDataChannel‘simple-peer上执行'send’时出错

在'RTCDataChannel‘simple-peer上执行'send’时出错
EN

Stack Overflow用户
提问于 2020-04-21 13:01:57
回答 1查看 195关注 0票数 0

我正在使用这个库来试用webrtc,simple-peer。我在opera浏览器上遵循这个教程链接了here。当我发送一个很小的字符串‘hello’时,我遇到了这个错误:

代码语言:javascript
复制
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:

代码语言:javascript
复制
    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)不会给出任何错误,但也不会将数据发送到其他浏览器

我做错了什么?提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-23 12:48:19

我让它起作用了。如果对任何人有用的话:我正在使用opera浏览器,它阻止了我的IP地址“泄露”。切换到Chrome浏览器的效果很棒,看看你的浏览器是否通过这个链接屏蔽了你的IP地址: https://diafygi.github.io/webrtc-ips/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61336277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档