Pregunta

I want to connect two peers with RTCPeerConnections but I am not able to add the IceCandidate from Alice to Bob.

example:

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
});

First version (seems to be old but is heavily used in online examples):

bob.addIceCandidate(candidatefromAlice);

Output:

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

Second try (new version with 3 parameters):

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

Output:

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

How can I set the ICE candidates in dart without problems?

Info:

Dart VM version: 0.1.2.0_r30864 (Wed Dec 4 11:03:45 2013) on "linux_x64"
dartium : Chromium 31.0.1650.48

¿Fue útil?

Solución 2

I found a workaround by using the js-interop library. Just use proxies:

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);

Otros consejos

I think you will have to wait until this bug is fixed https://code.google.com/p/dart/issues/detail?id=15008

the code you are asking for seems to be

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

A comment on this question Is addIceCandidate implemented in Dartium? seems to indicate that it doesn't work in Dartium but works in Chrome after converting the project to JavaScript.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top