streamHotspotClientState method

  1. @override
Stream<HotspotClientState> streamHotspotClientState()
override

Provides a broadcast stream of HotspotClientState updates.

This stream emits events whenever the client's connection status to a Wi-Fi Direct hotspot changes (e.g., connected, disconnected, IP info updated). Being a broadcast stream, it supports multiple listeners simultaneously. Each listener will receive events emitted after it subscribes.

Returns a Stream of HotspotClientState.

Implementation

@override
Stream<HotspotClientState> streamHotspotClientState() {
  _clientStateStream ??=
      clientStateEventChannel.receiveBroadcastStream().map((dynamic event) {
    if (event is Map) {
      try {
        return HotspotClientState.fromMap(Map.from(event));
      } catch (e) {
        debugPrint(
            "[MethodChannelFlutterP2pConnection] Error parsing HotspotClientState: $e, Event: $event");
        rethrow;
      }
    } else {
      debugPrint(
          "[MethodChannelFlutterP2pConnection] Received non-map event on clientStateEventChannel: $event");
      throw FormatException(
          "Received unexpected data type on clientStateEventChannel: ${event.runtimeType}");
    }
  }).asBroadcastStream();
  return _clientStateStream!;
}