on method

EventEmitterListener on(
  1. String type_update,
  2. FutureOr callback(
    1. UpdateTd update
    ), {
  3. Map? stateData,
  4. void onError(
    1. Object data
    )?,
})

receive all update data

Implementation

EventEmitterListener on(
  String type_update,
  FutureOr<dynamic> Function(UpdateTd update) callback, {
  final Map<dynamic, dynamic>? stateData,
  void Function(Object data)? onError,
}) {
  return event_emitter.on(
    eventName: type_update,
    stateData: stateData ?? {},
    onCallback: (listener, update) async {
      try {
        if (update is TdlibIsolateReceiveData) {
          // final TdlibIsolateReceiveData tdlibIsolateReceiveData = update;
          await callback(UpdateTd(
            update: update.updateData,
            client_id: update.clientId,
            client_option: () {
              try {
                final TdlibClient? tdlibClient = clients[update.clientId];
                if (tdlibClient != null) {
                  return tdlibClient.client_option;
                }
              } catch (e) {}
              return {};
            }(),
          ));
          return;
        }
      } catch (e) {
        if (onError != null) {
          return onError(e);
        }
      }
    },
  );
}