【问题标题】:How to call addIceCandidate in dart如何在飞镖中调用 addIceCandidate
【发布时间】:2013-12-05 15:43:55
【问题描述】:

我想用 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)    

如何在 dart 中设置 ICE 候选人而不出现问题?

信息:

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

【问题讨论】:

  • Dartium 版本不是很有帮助。 Darteditor>Help>About 菜单中的版本信息或dart --version的输出更好
  • 能否提供更多代码。什么是bobsRtcPeerConnection,什么是candidatefromAlice
  • 我添加了一些上下文。
  • 这不是stackoverflow.com/questions/19896137/… 与引用的代码示例相同的问题吗?
  • 我在旧版本中遇到了同样的错误。这个错误似乎是不同的(至少例外是)。

标签: exception dart webrtc dartium


【解决方案1】:

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

您要求的代码似乎是

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

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

【讨论】:

  • 它似乎是相似的,但不同的错误。我得到 "NotSupportedError: The implementation does not support the requested type of object or operation. (Dartium)" 而不是 "NotSupportedError: Internal Dartium Exception"
【解决方案2】:

我通过使用 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);

【讨论】:

    猜你喜欢
    • 2020-11-28
    • 2020-05-01
    • 2023-02-21
    • 1970-01-01
    • 2021-12-11
    • 2021-09-15
    • 2022-11-15
    • 2021-12-05
    • 2021-11-20
    相关资源
    最近更新 更多