WebRTC,STUN / TURN无法在LAN外工作 [英] WebRTC, STUN/TURN not working outside LAN

查看:199
本文介绍了WebRTC,STUN / TURN无法在LAN外工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

index.html( Offerer

index.html (Offerer)

var socket = io.connect('http://127.0.0.1:80'); //socket.io
socket.emit("player 1");

var iceServers = {
    iceServers: [
        {"url":"stun:turn1.xirsys.com"},
        {"username":"myusername","url":"turn:turn1.xirsys.com:443?transport=udp","credential":"mycredential"},
        {"username":"myusername","url":"turn:turn1.xirsys.com:443?transport=tcp","credential":"mycredential"}
    ]
};

var offererDataChannel, answererDataChannel;

var Offerer = {
    createOffer: function () {
        var peer = new PeerConnection(iceServers);
        var dataChannelOptions = {
            reliable: true,
            ordered: false
        };
        offererDataChannel = peer.createDataChannel('channel', dataChannelOptions);
        setChannelEvents(offererDataChannel);
        peer.onicecandidate = function (event) {
            if (event.candidate) {
            socket.emit("candidate", event.candidate);
        }
        };
        peer.createOffer(function (sdp) {
            peer.setLocalDescription(sdp);
            socket.emit("sdp", sdp);
        }, function (err) { peer.close(); });
        this.peer = peer;
        return this;
    },
    setRemoteDescription: function (sdp) {
        this.peer.setRemoteDescription(new SessionDescription(sdp));
    },
    addIceCandidate: function (candidate) {
        this.peer.addIceCandidate(new IceCandidate({
            sdpMLineIndex: candidate.sdpMLineIndex,
            candidate: candidate.candidate
        }));
    }
};

var Answerer = {
    createAnswer: function (offerSDP) {
        var peer = new PeerConnection(iceServers);
        peer.ondatachannel = function (event) {
            answererDataChannel = event.channel;
            setChannelEvents(answererDataChannel);
        };
        peer.onicecandidate = function (event) {
            if (event.candidate) {
                socket.emit("candidate", event.candidate);
            }
        };
        peer.setRemoteDescription(new SessionDescription(offerSDP));
        peer.createAnswer(function (sdp) {
            peer.setLocalDescription(sdp);
            socket.emit("sdp", sdp);
        }, function (err) { peer.close(); });
        this.peer = peer;
        return this;
    },
    addIceCandidate: function (candidate) {
        this.peer.addIceCandidate(new IceCandidate({
            sdpMLineIndex: candidate.sdpMLineIndex,
            candidate: candidate.candidate
        }));
    }
};

var peer = null;

socket.on("client is connected", function () {
    peer = Offerer.createOffer();
    socket.on("candidate", function (candidate) {
        peer.addIceCandidate(candidate);
    });
    socket.on("sdp", function (sdp) {
        peer.setRemoteDescription(sdp);
    });
});

我有另一个文件 stream.html 那个为 Answerer 做类似的事情。

I have another file stream.html that does a similar thing for the Answerer.

setChannelEvents 函数中,有一个信道onmessage的实现。

On the setChannelEvents function there is the implementation of the channel onmessage.

这在我家的局域网上运行完美。

This works perfectly on my LAN at home.

我用过ngrok这是在网上尝试在我的本地网络之外进行的服务,但无法正常工作。

I have used the ngrok service for put this online for trying outside my local network, and is not working.

我正在使用谷歌浏览器(更新到最新版本,目前为35.0.1916.153) 。

I'm using Google Chrome (updated to the last version, currently 35.0.1916.153).

有什么东西我不见了吗?是否有可以尝试使用TURN的WebRTC的工作示例?

Is there something that I'm missing? Is there a working example of WebRTC with TURN that I can try?

如果需要,我可以添加剩余代码加上候选者的一些输出 sdp

If needed, I can add the remaining code plus some output of the candidate and sdp.

注意:当我启动时,套接字上的IP被修改ngrok。

note: the IP on the socket is modified when I start ngrok.

推荐答案

XirSys在这里。 [=

XirSys guy here. [=

我不太确定你的错误是什么,除了它不起作用。如果错误仅仅是视频没有流动,您应该知道TURN将无法正常工作,因为您已经嵌入了TURN的凭据,而现在已经过期了。使用XirSys时,您必须调用 / getIceServers 来获取与您的帐户关联的新STUN和TURN服务器集。必须发出此POST请求,并且每次发起呼叫时结果都会放入 iceServers 变量

I'm not quite sure what your error is, other than it's just not working. If the error is simply that video isn't flowing, you should know that TURN won't work because you've embedded credentials for TURN that would have expired by now. When using XirSys, you have to call /getIceServers to get a "fresh" set of STUN and TURN servers that are associated with your account. This POST request must be made and the results placed into your iceServers variable each time you initiate a call.

为了快速了解我们的平台,我建议您阅读以下指南:

In order to gain a quick understanding of our platform, I'd suggest reading the following guides:

  • Introduction
  • Quick start guide
  • We also have easy-to-follow guides on hooking other WebRTC APIs, including SimpleWebRTC and EasyRTC, into our STUN and TURN servers.

非常感谢您对我们的服务感兴趣,请让我们如果您有任何问题或意见,我知道。

Thanks so much for showing interest in our service, and please let me know if you have anymore questions or comments.

这篇关于WebRTC,STUN / TURN无法在LAN外工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆