sendCommandWith method

Future<Map<String, Object?>?> sendCommandWith(
  1. String method,
  2. Map<String, Object?>? params,
  3. CommandSender sendWith
)
inherited

Encodes a request for transmission and sends it as a utf8 encoded byte string with sendWith.

Implementation

Future<Map<String, Object?>?> sendCommandWith(
    String method, Map<String, Object?>? params, CommandSender sendWith) {
  var id = '${_nextId++}';
  var command = <String, dynamic>{Request.ID: id, Request.METHOD: method};
  if (params != null) {
    command[Request.PARAMS] = params;
  }
  final completer = Completer<Map<String, Object?>?>();
  _pendingCommands[id] = completer;
  var line = json.encode(command);
  listener?.requestSent(line);
  sendWith(utf8.encoder.convert('$line\n'));
  return completer.future;
}