httpRequest method

  1. @override
Future<Map> httpRequest(
  1. Uri? uri,
  2. Map<String, dynamic> request
)
override

Processes the HTTP request returning the HTTP response as a map

Implementation

@override
Future<Map<dynamic, dynamic>> httpRequest(
    Uri? uri, Map<String, dynamic> request) {
  final completer = Completer<Map<String, dynamic>>();
  final webSocket = WebSocket(uri.toString());
  final message = json.encode(request);
  webSocket.onOpen.listen((Event e) {
    webSocket.sendString(message);
  });
  webSocket.onError.listen((Event e) {
    print('EthereumBrowserWSAdapter::WebSocket error, message not sent, '
        'state is ${webSocket.readyState.toString()}');
    webSocket.close();
    completer.complete(<String, dynamic>{});
  });
  webSocket.onMessage.listen((MessageEvent e) {
    final String ret = e.data;
    webSocket.close();
    completer.complete(json.decode(ret));
  });
  return completer.future;
}