MulticastProbe.windows constructor

MulticastProbe.windows(
  1. {int? timeout,
  2. bool? releaseMode}
)

Constructor for Windows OS builds, we need the kReleaseMode flag from Flutter to determine if we are running in debug or release mode so that the appropriate path to the discovery.dll file can be used. The default assumes the application is running as a cli app and will look for the DLL in the same folder as the executable. For cli the path to the DLL can be overwritten with the ONVIF_DISCOVERY_DLL environment variable.

Implementation

MulticastProbe.windows({int? timeout, bool? releaseMode}) {
  final env = Platform.environment;

  var discoveryDllPath = env.containsKey('ONVIF_DISCOVERY_DLL')
      ? env['ONVIF_DISCOVERY_DLL']!
      : join(Directory.current.path, 'bin', 'discovery.dll');

  if (releaseMode != null) {
    discoveryDllPath =
        join(Directory.current.path, 'assets', 'discovery.dll');

    if (releaseMode) {
      final String localLib =
          join('data', 'flutter_assets', 'assets', 'discovery.dll');

      discoveryDllPath =
          join(Directory(Platform.resolvedExecutable).parent.path, localLib);
    }
  }

  final Pointer<T> Function<T extends NativeType>(String symbolName) lookup =
      () {
    return DynamicLibrary.open(discoveryDllPath).lookup;
  }();

  final discoveryPtr = lookup<
      NativeFunction<
          Int32 Function(
            Pointer<NativeType>,
            Pointer<NativeType>,
            Int32,
          )>>('discovery');

  _discovery = discoveryPtr.asFunction<
      int Function(
        Pointer<NativeType>,
        Pointer<NativeType>,
        int,
      )>();

  probeTimeout = timeout ?? defaultTimeout;
}