listen method

  1. @override
Future listen ()
override

Starts listening to the underlying stream.

Returns a Future that will complete when the connection is closed or when it has an error. This is the same as done.

listen may only be called once.

Implementation

@override
Future listen() {
  _client.listen();
  _server.listen();
  _channel.stream.listen((message) {
    if (message is Map) {
      if (message.containsKey('result') || message.containsKey('error')) {
        _clientIncomingForwarder.add(message);
      } else {
        _serverIncomingForwarder.add(message);
      }
    } else if (message is List &&
        message.isNotEmpty &&
        message.first is Map) {
      if (message.first.containsKey('result') ||
          message.first.containsKey('error')) {
        _clientIncomingForwarder.add(message);
      } else {
        _serverIncomingForwarder.add(message);
      }
    } else {
      // Non-Map and -List messages are ill-formed, so we pass them to the
      // server since it knows how to send error responses.
      _serverIncomingForwarder.add(message);
    }
  }, onError: (error, stackTrace) {
    _serverIncomingForwarder.addError(error, stackTrace);
  }, onDone: close);
  return done;
}