connect static method

Future<void> connect(
  1. String address
)

connect will update a Stream of boolean getConnectionStream true if connected false if disconnected

Implementation

static Future<void> connect(String address) async {
  try {
    var result = await _channel.invokeMethod("connect", args: {
      "address": address.replaceAll(":", ""),
    });
    WinHelper.deviceMap[address] = result;
    // we have to perform an operation on device in order to make a connection
    var services = await discoverServices(address, forceRefresh: true);
    // A temporary way of detecting connection : if services are empty then connection is failed
    bool connectionFailed = services.isEmpty;
    _connectionStreamController.add({
      "device": address,
      "connected": !connectionFailed,
    });
  } catch (e) {
    rethrow;
  }
}