send method

  1. @override
Future<ByteData?>? send(
  1. String channel,
  2. ByteData? message
)
override

Send a binary message to the platform plugins on the given channel.

Returns a Future which completes to the received response, undecoded, in binary form.

Implementation

@override
Future<ByteData?>? send(String channel, ByteData? message) {
  final Future<ByteData?>? resultFuture;
  final MessageHandler? handler = _outboundHandlers[channel];
  if (allMessagesHandler != null) {
    resultFuture = allMessagesHandler!(channel, handler, message);
  } else if (handler != null) {
    resultFuture = handler(message);
  } else {
    resultFuture = delegate.send(channel, message);
  }
  if (resultFuture != null) {
    _pendingMessages.add(resultFuture);
    resultFuture
      // TODO(srawlins): Fix this static issue,
      // https://github.com/flutter/flutter/issues/105750.
      // ignore: body_might_complete_normally_catch_error
      .catchError((Object error) { /* errors are the responsibility of the caller */ })
      .whenComplete(() => _pendingMessages.remove(resultFuture));
  }
  return resultFuture;
}