2022-01-16 16:19:01 +00:00
|
|
|
import 'dart:async';
|
2022-01-29 18:23:10 +00:00
|
|
|
import 'dart:ffi';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
2022-01-16 16:19:01 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2022-01-29 18:23:10 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-01-28 03:02:16 +00:00
|
|
|
import 'package:veilid/bridge_generated.dart';
|
2022-01-16 16:19:01 +00:00
|
|
|
|
2022-01-29 18:23:10 +00:00
|
|
|
const base = 'veilid_flutter';
|
|
|
|
final path = Platform.isWindows
|
|
|
|
? '$base.dll'
|
|
|
|
: Platform.isMacOS
|
|
|
|
? 'lib$base.dylib'
|
|
|
|
: 'lib$base.so';
|
|
|
|
late final dylib = Platform.isIOS ? DynamicLibrary.process() : DynamicLibrary.open(path);
|
|
|
|
late final veilidApi = VeilidFlutterImpl(dylib);
|
|
|
|
|
2022-01-16 16:19:01 +00:00
|
|
|
class Veilid {
|
|
|
|
|
2022-01-29 18:23:10 +00:00
|
|
|
static VeilidFlutterImpl get api {
|
|
|
|
if (veilidApi == null) {
|
|
|
|
throw PlatformException(
|
|
|
|
code: 'Library missing',
|
|
|
|
details: 'veilid_core library could not be loaded dynamically',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return veilidApi;
|
2022-01-16 16:19:01 +00:00
|
|
|
}
|
2022-01-29 18:23:10 +00:00
|
|
|
|
2022-01-16 16:19:01 +00:00
|
|
|
}
|