1

当我尝试在 Javascript 上调用 RTCQuicTransport 的构造函数时,它会引发错误:未捕获的 TypeError:无法构造“RTCQuicTransport”:提供的值无法转换为序列。

假设构造函数需要两个参数,一个 RTCIceTransport 对象和一个使用 RTCPeerConnection.generateCertificate() 生成的证书,它应该以这种方式工作,但不是。

我尝试将“null”作为证书传递,但仍然抛出相同的错误消息。如果我只是传递 RTCIceTransport 对象,它会抛出该构造需要两个参数。

// Include some helper functions
//import {trace, errorHandler, mySendLocalCandidate, 
myIceGathererStateChange,
//  myIceTransportStateChange, myDtlsTransportStateChange} from 'helper';
//import 'helper.js';

function initiate(mySignaller) {
// Prepare the IceGatherer
var gatherOptions = {
  gatherPolicy: "all",
  iceServers: [
    { urls: "stun:stun1.example.net" },
    { urls: "turn:turn.example.org", username: "user", credential: 
    "myPassword",
      credentialType: "password" }
   ]
};

// Create the IceTransport
var ice = new RTCIceTransport();
ice.onstatechange = function(event) {
  myIceGathererStateChange("iceGatherer", event.state);
};
// Handle errors
// Prepare to signal local candidates
ice.onlocalcandidate = function(event) {
  mySignaller.mySendLocalCandidate(event.candidate);
};

// Start gathering
ice.gather(gatherOptions);

// Prepare to handle remote ICE candidates
console.log(ice);
mySignaller.onRemoteCandidate = function(remote) {
  ice.addRemoteCandidate(remote.candidate);
};

// Create the certificate
var certs = {};
var keygenAlgorithm = { name: "ECDSA", namedCurve: "P-256"};

RTCPeerConnection.generateCertificate(keygenAlgorithm).
then(function(certificate){
  certs[0] = certificate;
}, function(){
  trace('Certificate could not be created');
});
// Create the DtlsTransport and QuicTransport
var quic = new RTCQuicTransport(ice, certs[0]);
console.log(quic);
mySignaller.sendInitiate({
  ice: iceGatherer.getLocalParameters(),
  quic: quic.getLocalParameters(),
  // ... marshall RtpSender/RtpReceiver capabilities as in Section 6.6 
Examples 8 and 9.
}, function(remote) {
  // Start the IceTransport, DtlsTransport and QuicTransport
  ice.start(iceGatherer, remote.ice, RTCIceRole.controlling);
  dtls.start(remote.dtls);
  quic.start(remote.quic);
  // ... configure RtpSender/RtpReceiver objects as in Section 6.6 
Examples 8 and 9.
});}

我正在关注 ORTC quic 示例,并且希望获得一个 RTCQuicTransport 对象。

提前致谢

编辑

我意识到当我在 generateCertificate() 函数中打印我的证书时,它可以正常工作:

RTCCertificate {expires: 1552505428000}
expires: 1552505428000

但是,从那个功能中,我得到了这个:

console.log(certs);

结果:

{}
  [0] RTCCertificate
      expires: 1552505951000

然后我尝试:

console.log(certs[0]);

结果:

undefined
4

1 回答 1

0

与 RTCIceTransport 和 RTCQuic 传输兼容的 Web 浏览器是 73 Beta 版中的 Chrome,根据此:RTCQuicTransport over chrome 虽然我试图在带有--enable-blink-features=RTCQuicTransport,RTCIceTransportExtension标志的 chrome 72 中运行它,但这还不够。

在 chrome 73 beta 中,我可以通过null作为第二个参数传递并生成我自己的证书来创建 RTCQuicTransport。

于 2019-02-12T16:08:16.770 回答