使用easyrtc的TURN-Server不起作用

时间:2015-02-10 20:23:37

标签: node.js webrtc turn easyrtc

我在node.js中使用easyrtc。 *****:8080 / demos / demo_audio_video_simple.html在同一网络上正常工作。但如果我从2个不同的网络尝试它,我只得到一个黑屏。

经过一些研究后我发现,我需要一个TURN服务器,但它不起作用。

// Load required modules
var http    = require("http");              // http server core module
var express = require("express");           // web framework external module
var io      = require("socket.io");         // web socket external module
var easyrtc = require("easyrtc");           // EasyRTC external module

// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
var httpApp = express();

    httpApp.use(express.static(__dirname + "/static/"));


// Start Express http server on port 8080
var webServer = http.createServer(httpApp).listen(8080);

// Start Socket.io so it attaches itself to Express server
var socketServer = io.listen(webServer, {"log level":3});

var myIceServers = [
  {"url":"stun:anyfirewall.com:3478"},
  {
    "url":"turn:anyfirewall.com:443",
    "username":"flex*****",
    "credential":"32M3KsE*****"
  },
  {
    "url":"turn:anyfirewall.com:443[?transport=tcp]",
    "username":"flex*****",
    "credential":"32M3Ks*****"
  }
];

easyrtc.setOption("appIceServers", myIceServers);

easyrtc.on("getIceConfig", function(connectionObj, callback){
  callback(null, myIceServers);
})


// Start EasyRTC server
var rtc = easyrtc.listen(httpApp, socketServer);

我做错了什么?

1 个答案:

答案 0 :(得分:3)

首先,

您是否设置了正确的转弯服务器?

我建议阅读这些以设置带有REST Api的Turn服务器:

http://www.dialogic.com/den/developer_forums/f/71/t/10238.aspx

https://code.google.com/p/rfc5766-turn-server/wiki/turnserver

另外,如果要为Turn服务器指定TCP协议,则需要使用easyrtc在代码中这样做(默认情况下UDP是首选协议):

var myIceServers = [
  {
    "url":"stun:anyfirewall.com:3478"
  },
  {
    "url":"turn:anyfirewall.com:443",
    "username":"flex*****",
    "credential":"32M3KsE*****"
  },
  {
    "url":"turn:anyfirewall.com:443?transport=tcp",
    "username":"flex*****",
    "credential":"32M3Ks*****"
  }
];

否则,你可以用一些" vanilla"创建你的peerConnection。 webRTC JS:

var myIceServers = [
  {
    "urls":"stun:anyfirewall.com:3478"
  },
  {
    "url":"turn:anyfirewall.com:443?transport=udp",
    "username":"flex*****",
    "credential":"32M3KsE*****"
  },
  {
    "url":"turn:anyfirewall.com:443?transport=tcp",
    "username":"flex*****",
    "credential":"32M3Ks*****"
  }
];

如果您想限制不受欢迎的用户使用Turn服务器,我建议您使用REST Api进行设置。除此之外,您的问题没有提供足够的信息来正确解决您的问题。