2

我想用 RTCPeerConnections 连接两个对等点,但我无法将 Alice 的 IceCandidate 添加到 Bob。

例子:

var alice = new RtcPeerConnection(
   {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]}
);

var bob = new RtcPeerConnection(
    {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]}
);

alice.createDataChannel("somelablel", {});

alice.onNegotiationNeeded.listen((var data){
    alice.createOffer({}).then((var offer){
        //got offer
        alice.setLocalDescription(offer);
        bob.setRemoteDescription(offer);
    }); 
});

bob.onIceCandidate.listen((evt) {
    if (evt.candidate)
        print(evt.cancelable);
    });

alice.onIceCandidate.listen((evt) {
    if(evt.candidate != null)
        //TODO: add iceCandidate to Bob
});

第一个版本(似乎很旧,但在在线示例中大量使用):

bob.addIceCandidate(candidatefromAlice);

输出:

Class 'RtcPeerConnection' has no instance method 
'addIceCandidate' with matching arguments.

第二次尝试(带有 3 个参数的新版本):

bob.addIceCandidate(candidatefromAlice, (){}, (var error){
    print(error.toString());
}); 

输出:

NotSupportedError: The implementation did not support the 
requested type of object or operation. (Dartium)    

我怎样才能在飞镖中毫无问题地设置 ICE 候选人?

信息:

Dart VM 版本:0.1.2.0_r30864(2013 年 12 月 4 日星期三 11:03:45)在“linux_x64”
dartium 上:Chromium 31.0.1650.48

4

2 回答 2

1

我认为您将不得不等到修复此错误 https://code.google.com/p/dart/issues/detail?id=15008

您要求的代码似乎是

bob.addIceCandidate(evt.candidate, () => print('void: $evt'), (var x) => print('FailureCallback: $evt'));

对此问题的评论是否在 Dartium 中实现了 addIceCandidate?似乎表明它在 Dartium 中不起作用,但在将项目转换为 JavaScript 后在 Chrome 中起作用。

于 2013-12-06T17:01:19.327 回答
0

我通过使用 js-interop 库找到了一种解决方法。只需使用代理:

import 'package:js/js.dart' as js;

// ...

_rpc = new js.Proxy(js.context.webkitRTCPeerConnection, js.map(iceServers));

// ...

var iceCandidate = new js.Proxy(js.context.RTCIceCandidate, 
        js.context.JSON.parse(/*your icecandidate string*/)
      );

_rpc.addIceCandidate(iceCandidate);
于 2014-01-04T09:45:56.347 回答