I am trying to port the Twilio Conversations Javascript SDK to Dart/Flutter using package:js.
The twilio SDK: http://media.twiliocdn.com/sdk/js/conversations/releases/2.0.1/docs/classes/Client.html
In Javascript, CDN script allows access to global Twilio.Conversations. You then call Twilio.Conversations.Client(token), which returns a ReplayEventEmitter, their extension of an EventEmitter. You then listen to the events coming out to know first when initialization/connection is complete and then when messages or conversations are coming through.
Using package:js, I start with barebones:
@JS('Twilio.Conversations')
library twilio_conversations;
import 'package:js/js.dart';
external TwilClient get client;
@JS('Client')
Class TwilClient {
external TwilClient(String token)
}
And this is easy to conceptualize adding methods to, but is there a straightforward way to turn the event emitter into a Dart class? Or would it be better to try to import the JS ReplayEventEmitter class, have 'Client' returned as the javascript object, then have the events coming out of it channeled into Dart code?