webrtc

Webrtc doesn't work on host


I have an application that has video and sound communication. I used Webrtc I created the connection like the following code

foundedPC.createOffer(function(desc) {
    foundedPC.setLocalDescription(desc, function() {
        console.log("Create offer" + callId);
        hub.invoke("sendSignal", JSON.stringify({
            "sdp": foundedPC.localDescription
        }), callId);
    });
}, function(error) {
    console.log('Error creating session description: ' + error);
});

then I created the answer and return the answer packet evrey thing works on the local system, I rent a stun server because I found the answer in this linkstack he said the problem is stun and turn server. but it didn't work for me. whenever I turn on my VPN and my client also turn on the VPN Webrtc work nicely. I don't know how the vpn effect on webrtc connection


Solution

  • I am pretty sure the problem is still the lack of a TURN server. I would guess the configuration to access the rented STUN/TURN server was not right.

    Maybe try something different, also a very cheap alternative, I use Digital Ocean and installed CoTurn as my STUN/TURN server on a Ubuntu droplet. You pay only $0.007 per hour for the droplet. If you don't use it anymore (I use it for testing at this moment) you just destroy the droplet and you don't pay anymore. If you make a snapshot of the droplet, you can easy reinstall the droplet when you want to use it again. Snapshots costs $0.05/GB/month.

    Installing CoTurn on a Ubuntu machine is very easy:

    Select Ubuntu 16.04.3 x64 or 17.10 x64 when creating a droplet.

    Installing:

    sudo apt-get update
    sudo apt-get install coturn
    

    Next, edit sudo vi /etc/turnserver.conf and change the following options:

    fingerprint
    lt-cred-mech
    realm=ip-address-public-droplet
    listening-ip=ip-address-public-droplet
    user=test:test
    

    Next, edit sudo vi /etc/default/coturn and add the following options:

    TURNSERVER_ENABLED=1
    

    Create or modify service package for our program:

    sudo vi /etc/systemd/system/coturn.service
    

    Then paste the content of this.

    After modifying a unit file, you should reload the systemd process itself to pick up your changes:

    sudo systemctl daemon-reload
    

    Now the installation is complete, we'll start the Coturn daemon:

    sudo systemctl start coturn
    

    Since systemctl doesn't provide output, we'll check the status to verify that the service has started properly:

    sudo systemctl status coturn
    

    Now that we've manually started the daemon and verified that it’s running, we'll ensure that it restarts automatically at boot:

    sudo systemctl enable coturn
    

    In your app you need something like:

    var pcConfig = {  
      'iceServers': [
        {'urls': 'stun:ip-address-public-droplet:5349'},
        {'urls': 'turn:ip-address-public-droplet:5349', 'username': 'test', 'credential': 'test'}
      ]
    };
    

    You can force your app using TURN by:

    var pcConfig = {  
      iceTransportPolicy: "relay",
      'iceServers': [
        {'urls': 'stun:ip-address-public-droplet:5349'},
        {'urls': 'turn:ip-address-public-droplet:5349', 'username': 'test', 'credential': 'test'}
      ]
    };
    

    When the connection is established you can check if TURN server (relay) is used by going through the stats page.

    Chrome address bar: chrome://webrtc-internals or Firefox address bar: about:webrtc.

    Look for the 'bold' header: Conn-audio-1-0 (googCandidatePair)

    Use Nothing: googRemoteCandidateType: local

    Use of STUN: googRemoteCandidateType: stun

    Use of TURN: googRemoteCandidateType: relay