Domanda

In the standard specs it says you can set ENUM value to "relay" : http://dev.w3.org/2011/webrtc/editor/webrtc.html#idl-def-RTCIceServer

but, How do you set the enum to "relay" using Javascript of following? if (tmp.indexOf("typ relay ") >= 0) { never occur in my test. how can i force it to enum "relay"?

or

is it a BUG? https://code.google.com/p/webrtc/issues/detail?id=1179

Any idea.

function createPeerConnection() {
  try {
    // Create an RTCPeerConnection via the polyfill (adapter.js).
    pc = new RTCPeerConnection(pcConfig, pcConstraints);
    pc.onicecandidate = onIceCandidate;
    console.log('Created RTCPeerConnnection with:\n' +
                '  config: \'' + JSON.stringify(pcConfig) + '\';\n' +
                '  constraints: \'' + JSON.stringify(pcConstraints) + '\'.');
  } catch (e) {
    console.log('Failed to create PeerConnection, exception: ' + e.message);
    alert('Cannot create RTCPeerConnection object; \
          WebRTC is not supported by this browser.');
      return;
  }
  pc.onaddstream = onRemoteStreamAdded;
  pc.onremovestream = onRemoteStreamRemoved;
  pc.onsignalingstatechange = onSignalingStateChanged;
  pc.oniceconnectionstatechange = onIceConnectionStateChanged;
}

function onIceCandidate(event) {
  if (event.candidate) {
    var tmp = event.candidate.candidate;
    if (tmp.indexOf("typ relay ") >= 0) {
      /////////////////////////////////////////// NEVER happens
      sendMessage({type: 'candidate',
                   label: event.candidate.sdpMLineIndex,
                   id: event.candidate.sdpMid,        
                   candidate: tmp}); 
      noteIceCandidate("Local", iceCandidateType(tmp));   

    }    
  } else {
    console.log('End of candidates.');
  }
}
È stato utile?

Soluzione 3

To force the usage of a TURN server, you need to intercept the candidates found by the browser. Just like you are doing.

But if it never occurs in your testings, you may have some problems with your TURN server. If you have a working TURN server, you'll get the candidates with typ relay.

Remember that you need to configure TURN server with authentication. It is mandatory and the browser will only use the candidates "relay" if the request is authenticated. Your iceServers config for PeerConnection must have the credentials defined for TURN servers.

Altri suggerimenti

There is a Chrome extension, WebRTC Network Limiter, that Configures how WebRTC's network traffic is routed by changing Chrome's privacy settings. You can force traffic to go through TURN without having to do any SDP mangling.


EDIT 1

The point of making this available in extensions, is for users that are worried about their security. You can check this excellent post about WebRTC security. The same as this extension does, can also be done in FF, by changing the flag media.peerconnection.ice.relay_only. This can be found in about:config. Don't know about the other two, but I'd wager they do have something similar.

On the other hand, if you are distributing an app and want all your clients to go through TURN, you won't have access to their browsers, and can't expect them to change those flags or install any extension. In that case, you'll have to mangle your SDP. You can use this code

function onIceCandidate(event) {
  if (event.candidate) {
    var type = event.candidate.candidate.split(" ")[7];
    if (type != "relay") {
      trace("ICE  -  Created " + type + " candidate ignored: TURN only mode.");
      return;
    } else {
      sendCandidateMessage(candidate);
      trace("ICE  - Sending " + type + " candidate.");
    }
  } else {
    trace("ICE  - End of candidate generation.");
  }
}

That code is taken from the discuss-webrtc list.

If you never get those candidates, it might very well be that your TURN server is not correctly configured. You can check your TURN server in this page. Don't forget to remove the existing STUN server configured in that demo.


EDIT 2

Even simpler: set iceTransportPolicy: "relay" in your WebRtcPeer config to force TURN:

var options = {
    localVideo: videoInput, //if you want to see what you are sharing
    onicecandidate: onIceCandidate,
    mediaConstraints: constraints,
    sendSource: 'screen',
    iceTransportPolicy: 'relay',
    iceServers: [{ urls: 'turn:XX.XX.XX.XX', username:'user', credential:'pass' }]
}

webRtcPeerScreencast = kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(options, function(error) {
    if (error) return onError(error) //use whatever you use for handling errors

    this.generateOffer(onOffer)
});

This is working for me:

iceServers = [
     { "url": "turn:111.111.111.111:1234?transport=tcp",
       "username": "xxxx",
       "credential": "xxxxx"
     }
   ]

optionsForWebRtc = {
    remoteVideo : localVideoElement,
    mediaConstraints : videoParams,
    onicecandidate : onLocalIceCandidate,
    configuration: {
        iceServers: iceServers,
        iceTransportPolicy: 'relay'
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top