getNextNegotiator method

  1. @visibleForTesting
XmppFeatureNegotiatorBase? getNextNegotiator(
  1. List<XMLNode> features,
  2. {bool log = true}
)

Returns the next negotiator that matches features. Returns null if none can be picked. If log is true, then the list of matching negotiators will be logged.

Implementation

@visibleForTesting
XmppFeatureNegotiatorBase? getNextNegotiator(
  List<XMLNode> features, {
  bool log = true,
}) {
  final matchingNegotiators =
      negotiators.values.where((XmppFeatureNegotiatorBase negotiator) {
    return negotiator.state == NegotiatorState.ready &&
        negotiator.matchesFeature(features);
  }).toList()
        ..sort((a, b) => b.priority.compareTo(a.priority));

  if (log) {
    this.log.finest(
          'List of matching negotiators: ${matchingNegotiators.map((a) => a.id)}',
        );
  }

  if (matchingNegotiators.isEmpty) return null;

  return matchingNegotiators.first;
}