callMethod<T> method

Future<T> callMethod<T>(
  1. String method, {
  2. Map<String, dynamic> params = const {},
})

Call a method via the forwarding server

@param method Method name @param params Method parameters @returns Future that resolves with the result

Implementation

Future<T> callMethod<T>(
  String method, {
  Map<String, dynamic> params = const {},
}) async {
  if (!_isConnected()) {
    throw Exception('Not connected to forwarding server');
  }

  final id = _generateId();
  final request = {
    'jsonrpc': '2.0',
    'id': id,
    'method': method,
    'params': params,
  };

  final completer = Completer<T>();
  _pendingRequests[id] = _PendingRequest(
    completer: completer,
    method: method,
  );

  _ws!.sink.add(json.encode(request));
  return completer.future;
}