[ortc] Example 6 is wrong

ibc has just created a new issue for https://github.com/openpeer/ortc:

== Example 6 is wrong ==
```js
  
RTCCertificate.generateCertificate(keygenAlgorithm).then(function(certificate){
    var cert = certificate;
    // Obtain the fingerprint of the created certificate
    dtlsParameters.fingerprints[0] = cert.fingerprint;
  }, function(){
    trace('Certificate could not be created');
  });
  // Prepare to handle remote ICE candidates
  mySignaller.onRemoteCandidate = function(remote) {
    // Figure out which IceTranport a remote candidate relates to by 
matching the userNameFragment/password
    var j = 0;
    for (j = 0; j < iceTransport.length; j++) {
      var transport = iceTransports[j];
      if (transport.getRemoteParameters().userNameFragment === 
remote.parameters.userNameFragment)
        transport.addRemoteCandidate(remote.candidate);
      }
    }  };
  // ... create RtpSender/RtpReceiver objects as illustrated in 
Section 6.5 Example 9.

  mySignaller.mySendInitiate({
    "ice": iceGatherer.getLocalParameters(),
    "dtls": dtlsParameters,
    // ... marshall RtpSender/RtpReceiver capabilities as illustrated 
in Section 6.5 Example 9.
  }, function(remote) {
    // Create the ICE and DTLS transports
    var iceTransport = new RTCIceTransport(iceGatherer);
    iceTransport.start(iceGatherer, remote.ice, 
RTCIceRole.controlling);
    iceTransports.push(iceTransport);
    // Construct a RTCDtlsTransport object with the same certificate 
and fingerprint as in the Offer
    // so that the remote peer can verify it.
    var dtlsTransport = new RTCDtlsTransport(iceTransport, cert);     
// <---- There is no `cert` var
    dtlsTransport.start(remote.dtls);
    dtlsTransports.push(dtlsTransport);

    // ... configure RtpSender/RtpReceiver objects as illustrated in 
Section 6.5 Example 9.
  });
```

In `var dtlsTransport = new RTCDtlsTransport(iceTransport, cert);` 
such a `cert` variable does not exist in that scope. It was defined in
 the `resolve` function of the `RTCCertificate.generateCertificate()` 
returned Promise.

For this to be valid, `var cert` should be declared above the 
`RTCCertificate.generateCertificate()` call.

Please view or discuss this issue at 
https://github.com/openpeer/ortc/issues/310 using your GitHub account

Received on Saturday, 26 December 2015 13:36:59 UTC