messageReceived method

Stream<WearOSMessage> messageReceived({
  1. Uri? pathURI,
  2. UriFilterType filterType = UriFilterType.literal,
})

Listen to message received events

Message events can either be listen in specific message path or globally.

Implementation

Stream<WearOSMessage> messageReceived(
    {Uri? pathURI, UriFilterType filterType = UriFilterType.literal}) async* {
  await removeMessageListener(pathURI: pathURI);
  await channel.invokeMethod(
      "addMessageListener",
      pathURI == null
          ? {"name": "global_message_channel"}
          : {"path": pathURI.toString(), "filterType": filterType.index});

  String key =
      pathURI == null ? "global_message_channel" : pathURI.toString();
  Map<String, StreamController<WearOSMessage>> _messageStreamControllers =
      _wearOSObserver.streamControllers[ObservableType.message]
          as Map<String, StreamController<WearOSMessage>>;
  _messageStreamControllers[key] = StreamController.broadcast();
  yield* _messageStreamControllers[key]!.stream;
}