0

As an experiment, I'm trying some stuff out with dart and easyrtc. I started at porting this (it is normally served through a nodejs server, found here) to a dart version and this is what I made from it

EDIT: I found out which part of the code is causing the error. It is the data object proxy which the for loop is unable to run through. Normally, the setRoomOccupantListener function gives as parameters the name of the room and an object with all the peers connected to the room. I have made a screenshot of the object layout in normal javascript as how it looks when I debug in chrome, found here.

function connect() {
  easyrtc.setRoomOccupantListener(convertListToButtons);
 }

function convertListToButtons (roomName, data, isPrimary) {
  clearConnectList();
  var otherClientDiv = document.getElementById("otherClients");
  for(var easyrtcid in data) {
    var button = document.createElement("button");
    button.onclick = function(easyrtcid) {
      return function() {
        performCall(easyrtcid);
      };
    }(easyrtcid);

    var label = document.createTextNode(easyrtc.idToName(easyrtcid));
    button.appendChild(label);
    otherClientDiv.appendChild(button);
  }
}

And here is the screenshot when i debug the dart code in chromium

void connect() {
  easyrtc.setRoomOccupantListener(convertListToButtons);
  } 

void convertListToButtons(roomName, data, isPrimary) {
  clearConnectList();
  var otherClientDiv = querySelector("#otherClients");
  for (var easyrtcid in data) {
    var button = document.createElement("button");
    button.onClick.listen((event) {
      performCall(easyrtcid);
    });

    button.appendText(easyrtc.idToName(easyrtcid));
    otherClientDiv.append(button);
  }
}

This is the error I get:

Class 'Proxy' has no instance getter 'iterator'.

NoSuchMethodError: method not found: 'iterator' Receiver: Instance of 'Proxy' Arguments: []
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1      P...<omitted>...7)

Am I missing something simple here or is this some kind of incompatibility? Thank you.

XD face me
  • 578
  • 1
  • 3
  • 12
  • Please use dart:js instead of package:js – Justin Fagnani May 20 '14 at 15:29
  • following https://pub.dartlang.org/packages/js, there is no difference between the two other then performance and syntax, so why should I switch if I dont give that much about performance? – XD face me May 20 '14 at 16:11
  • Code size and the fact that we're probably going to discontinue package:js as it is now in favor of a code-generation approach. When packages:js is used together with any other library that uses mirrors, very bad things happen. – Justin Fagnani May 20 '14 at 18:12
  • That's bad, and I actually dislike the way dart:js works. the callmMethod with it's parameters results in just gorgeous code – XD face me May 20 '14 at 21:04
  • It's worse that package:js can severely bloat dart2js output, when all it gives is slightly nicer syntax. It's not worth it. – Justin Fagnani May 20 '14 at 21:27
  • More than slightly in my opinion, are there any plans on improving the syntax later on? – XD face me May 21 '14 at 06:25

2 Answers2

1

I see you can use import package:js/js.dart'; too. I don't know how to use it

You could try

import 'dart:js' as js;

https://www.dartlang.org/articles/js-dart-interop/

This looks weird too

easyrtc = js.context.easyrtc; // <== here you have context 'easyrtc'

easyrtc.easyApp('easyrtc.audioVideo', 'selfVideo', new js.JsObject.jsify(['callerVideo']), loginSuccess, loginFailure); 
// and here again 'easyrtc.audioVideo', I guess this is one to much

try

easyrtc.easyApp.callMethod('audioVideo', ['selfVideo', js.JsObject.jsify(['callerVideo']), loginSuccess, loginFailure]); 

where 'audioVideo' is the called method and the rest are arguments

easyrtc.callMethod('easyApp', ['audioVideo', 'selfVideo', js.JsObject.jsify(['callerVideo']), loginSuccess, loginFailure]); 

where 'easyApp' is the called method and the rest are arguments.

If you can add how the code would look in JavaScript I could create better examples.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • in the first sentence there is a link pointing to a jsfiddle page with the javascript in it. Because there it is not served through nodejs it will not work though – XD face me May 18 '14 at 13:13
1

Like dart:js package:js doesn't handle directly Dart List. So the following line :

  easyrtc.easyApp('easyrtc.audioVideo', 'selfVideo', 
      ['callerVideo'], loginSuccess, loginFailure);

should be :

  easyrtc.easyApp('easyrtc.audioVideo', 'selfVideo', 
      js.array(['callerVideo']), loginSuccess, loginFailure);

See also What is a difference between dart:js and js package?

Community
  • 1
  • 1
Alexandre Ardhuin
  • 71,959
  • 15
  • 151
  • 132