Re: Issue 207: RTCIceCandidateComplete dictionary

Robin Raymond said:

"Sample code please (in RTCIceGatherer)..."

[BA] How about this for an example in Section 2.9?

EXAMPLE 1

// Example to demonstrate use of RTCIceCandidateComplete
// 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 iceGatherer = new RTCIceGatherer(gatherOptions);
// Handle state changes
iceGatherer.ongathererstatechange = function (event) {
  myIceGathererStateChange('iceGatherer', event.state);
};
// Prepare to signal local candidates
iceGatherer.onlocalcandidate = function (event) {
  mySendLocalCandidate(event.candidate);
};
// Set up response function
mySignaller.onResponse = function(responseSignaller,response) {
// We may get N responses
//
// Create the ICE transport
var iceTransport = new RTCIceTransport(iceGatherer);
iceTransport.onicestatechange = function(event){
   myIceTransportStateChange('iceTransport', event.state);
};
 // Start the ICE transport so that outgoing ICE connectivity checks can begin
iceTransport.start(iceGatherer, response.ice, RTCIceRole.controlling);
// Prepare to add ICE candidates signalled by the remote peer
responseSignaller.onRemoteCandidate = function(remote) {
   iceTransport.addRemoteCandidate(remote.candidate);
};
};

mySignaller.send({
   "ice": iceGatherer.getLocalParameters(),
});
// ... setup DTLS, RTP, SCTP, etc.
EXAMPLE 2

// Helper functions (helper.js)
function trace(text) {
  // This function is used for logging.
  if (text[text.length - 1] === '\n') {
    text = text.substring(0, text.length - 1);
  }
  if (window.performance) {
    var now = (window.performance.now() / 1000).toFixed(3);
    console.log(now + ': ' + text);
  } else {
   console.log(text);
  }
}

function errorHandler (error) {
  trace('Error encountered: ' + error.name);
}

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

function myIceGathererStateChange(name, state){
  switch(state){
  case RTCIceGathererState.new:
     trace('IceGatherer: ' + name + ' Has been created');
     break;
  case RTCIceGathererState.gathering:
     trace('IceGatherer: ' + name + ' Is gathering candidates');
     break;
  case RTCIceGathererState.complete:
     trace('IceGatherer: ' + name + ' Has finished gathering (for now)');
     break;
  case RTCIceGathererState.closed:
     trace('IceGatherer: ' + name + ' Is closed');
     break;
  default:
     trace('IceGatherer: ' + name + ' Invalid state');
  }
}

function myIceTransportStateChange(name, state){
  switch(state){
  case RTCIceTransportState.new:
     trace('IceTransport: ' + name + ' Has been created');
     break;
  case RTCIceTransportState.checking:
     trace('IceTransport: ' + name + ' Is checking');
     break;
  case RTCIceTransportState.connected:
     trace('IceTransport: ' + name + ' Is connected');
     break;
  case RTCIceTransportState.disconnected:
     trace('IceTransport: ' + name + ' Is disconnected');
     break;
  case RTCIceTransportState.completed:
     trace('IceTransport: ' + name + ' Has finished checking (for now)');
     break;
  case RTCIceTransportState.failed:
     trace('IceTransport: ' + name + ' Has failed');
     break;
  case RTCIceTransportState.closed:
     trace('IceTransport: ' + name + ' Is closed');
     break;
  default:
     trace('IceTransport: ' + name + ' Invalid state');
  }
}

Received on Friday, 12 June 2015 22:02:52 UTC