New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sending userNameFragment in candidate ? Example 5 #237

Closed
Jxck opened this Issue Sep 14, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@Jxck
Copy link
Contributor

Jxck commented Sep 14, 2015

I have question about Example 5

https://github.com/openpeer/ortc/blob/master/ortc.html#L1523

  // Prepare to add ICE candidates signalled by the remote peer
  responseSignaller.onRemoteCandidate = function(remote) {
    // Locate the ICE transport that the signaled candidate relates to by matching the userNameFragment.
    var j = 0;
    for (j = 0; j < iceTransport.length; j++) {
      if (getRemoteParameters(iceTransport(j)).userNameFragment === remote.parameters.userNameFragment) {
        if (remote.component === RTCIceComponent.RTP) {
          iceRtpTransport[j].addRemoteCandidate(remote.candidate);
        } else {
          iceRtcpTransport[j].addRemoteCandidate(remote.candidate);
        }
      }
    }
  };

this code checked userNameFragment at each candidate from remote.params.
this means when local oncandidate happens, we need to send it to peer with userNameFragment like this ?

iceRtpGatherer.onlocalcandidate = function(event) {
  mySendLocalCandidate(event.candidate, RTCIceComponent.RTP, iceRtpGatherer.getLocalParameters());
}

in that case, we need to send getLocalParameter result twice ?
1 at send candidate, 2 at send parameters.

mySignaller.send({
  "icertp": iceRtpGatherer.getLocalParameters(), // same
  "icertcp": iceRtcpGatherer.getLocalParameters()
});

@aboba aboba added the 1.1 label Sep 15, 2015

@aboba

This comment has been minimized.

Copy link
Contributor

aboba commented Sep 18, 2015

Example 4 defines the mySendLocalCandidate method:

function mySendLocalCandidate(candidate, component, kind, parameters) {
  // Set default values
  kind = kind || "all";
  component = component || RTCIceComponent.RTP;
  parameters = parameters || null;
  // Signal the local candidate
  mySignaller.mySendLocalCandidate({
    "candidate": candidate,
    "component": component,
    "kind": kind,
    "parameters": parameters
  });
}

If we also send parameters, then Example 5 should look like this:

// Example to demonstrate forking when RTP and RTCP are not multiplexed,
// so that both RTP and RTCP IceGatherer and IceTransport objects are needed.
// Include some helper functions
import "helper.js";

// Create ICE gather options
var gatherOptions = new RTCIceGatherOptions();
gatherOptions.gatherPolicy = RTCIceGatherPolicy.relay;
gatherOptions.iceServers = [
  { urls: "stun:stun1.example.net" },
  { urls: "turn:turn.example.org", username: "user", credential: "myPassword" }
];

// Create ICE gatherer objects
var iceRtpGatherer = new RTCIceGatherer(gatherOptions);
var iceRtcpGatherer = iceRtpGatherer.createAssociatedGatherer();

// Prepare to signal local candidates
iceRtpGatherer.onlocalcandidate = function(event) {
  mySendLocalCandidate(event.candidate, RTCIceComponent.RTP, "audio", iceRtpGatherer.getLocalParameters());
};

iceRtcpGatherer.onlocalcandidate = function(event) {
  mySendLocalCandidate(event.candidate, RTCIceComponent.RTCP, "audio", iceRtpGatherer.getLocalParameters());
};

// Initialize the ICE transport arrays
var iceRtpTransports = [];
var iceRtcpTransports = [];

// Set up response function
mySignaller.onResponse = function(responseSignaller, response) {
  // We may get N responses

  // Create the ICE RTP and RTCP transports
  var iceRtpTransport = new RTCIceTransport(iceRtpGatherer);
  var iceRtcpTransport = iceRtpTransport.createAssociatedTransport();

  // Start the RTP and RTCP ICE transports so that outgoing ICE connectivity checks can begin
  // The RTP and RTCP ICE parameters are the same, so only the RTP parameters are used
  iceRtpTransport.start(iceRtpGatherer, response.icertp, RTCIceRole.controlling);
  iceRtcpTransport.start(iceRtcpGatherer, response.icertp, RTCIceRole.controlling);

  iceRtpTransports.push(iceRtpTransport);
  iceRtcpTransports.push(iceRtcpTransport);

  // Prepare to add ICE candidates signalled by the remote peer
  responseSignaller.onRemoteCandidate = function(remote) {
    // Locate the ICE transport that the signaled candidate relates to by matching the userNameFragment.
    var transports;
    if (remote.component === RTCIceComponent.RTP) {
      transports = iceRtpTransports;
    } else {
      transports = iceRtcpTransports;
    }

    for (var j = 0; j < iceTransport.length; j++) {
      var transport = transports[j];
      if (transport.getRemoteParameters().userNameFragment === remote.parameters.userNameFragment)
        transport.addRemoteCandidate(remote.candidate); 
      }
    }
  };
};

mySignaller.send({
  // The RTP and RTCP local parameters are the same so we do not need to send both
  "icertp": iceRtpGatherer.getLocalParameters()
});

@aboba aboba added the PR exists label Sep 18, 2015

@aboba aboba closed this Oct 6, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment