node.jswebrtcturneasyrtc

TURN-Server with easyrtc doesn't work


I use easyrtc with node.js. The *****:8080/demos/demo_audio_video_simple.html work correct on the same network. But if i try it from 2 different networks i get only a black screen.

After some research I found out, i need a TURN Server, but it doesn't work.

// 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);

What have I done wrong?


Solution

  • First,

    Have you setup a proper Turn server?

    I suggest reading these to setup a Turn server with a REST Api:

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

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

    Also, if you want to specify the TCP protocol for the Turn server, you need to do it this way in your code using easyrtc (UDP is the preferred protocol by default):

    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*****"
      }
    ];
    

    Else, you could create your peerConnection with some "vanilla" 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*****"
      }
    ];
    

    I suggest using the setup with a REST Api if you want to limit the usage of your Turn server by unwanted users. Other than that, your question does not provide enough information to properly troubleshoot your problem.