2023-01-09 22:50:34 -05:00
|
|
|
import 'package:veilid/veilid.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'processor.dart';
|
2023-01-11 19:17:04 -05:00
|
|
|
import 'veilid_log.dart';
|
2023-01-09 22:50:34 -05:00
|
|
|
|
|
|
|
Future<String> getVeilidVersion() async {
|
|
|
|
String veilidVersion;
|
|
|
|
try {
|
|
|
|
veilidVersion = Veilid.instance.veilidVersionString();
|
|
|
|
} on Exception {
|
|
|
|
veilidVersion = 'Failed to get veilid version.';
|
|
|
|
}
|
|
|
|
return veilidVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize Veilid
|
|
|
|
// Call only once.
|
2023-01-10 21:04:18 -05:00
|
|
|
void _initVeilid() {
|
2023-01-09 22:50:34 -05:00
|
|
|
if (kIsWeb) {
|
|
|
|
var platformConfig = VeilidWASMConfig(
|
|
|
|
logging: VeilidWASMConfigLogging(
|
|
|
|
performance: VeilidWASMConfigLoggingPerformance(
|
|
|
|
enabled: true,
|
|
|
|
level: VeilidConfigLogLevel.debug,
|
|
|
|
logsInTimings: true,
|
|
|
|
logsInConsole: false),
|
|
|
|
api: VeilidWASMConfigLoggingApi(
|
|
|
|
enabled: true, level: VeilidConfigLogLevel.info)));
|
2023-07-02 11:31:40 -04:00
|
|
|
Veilid.instance.initializeVeilidCore(platformConfig.toJson());
|
2023-01-09 22:50:34 -05:00
|
|
|
} else {
|
|
|
|
var platformConfig = VeilidFFIConfig(
|
|
|
|
logging: VeilidFFIConfigLogging(
|
|
|
|
terminal: VeilidFFIConfigLoggingTerminal(
|
|
|
|
enabled: false,
|
|
|
|
level: VeilidConfigLogLevel.debug,
|
|
|
|
),
|
|
|
|
otlp: VeilidFFIConfigLoggingOtlp(
|
|
|
|
enabled: false,
|
|
|
|
level: VeilidConfigLogLevel.trace,
|
|
|
|
grpcEndpoint: "localhost:4317",
|
|
|
|
serviceName: "VeilidChat"),
|
|
|
|
api: VeilidFFIConfigLoggingApi(
|
|
|
|
enabled: true, level: VeilidConfigLogLevel.info)));
|
2023-07-02 11:31:40 -04:00
|
|
|
Veilid.instance.initializeVeilidCore(platformConfig.toJson());
|
2023-01-09 22:50:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool initialized = false;
|
|
|
|
Processor processor = Processor();
|
|
|
|
|
|
|
|
Future<void> initializeVeilid() async {
|
|
|
|
if (initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init Veilid
|
2023-01-10 21:04:18 -05:00
|
|
|
_initVeilid();
|
2023-01-09 22:50:34 -05:00
|
|
|
|
2023-01-11 19:17:04 -05:00
|
|
|
// Veilid logging
|
|
|
|
initVeilidLog();
|
|
|
|
|
2023-01-09 22:50:34 -05:00
|
|
|
// Startup Veilid
|
|
|
|
await processor.startup();
|
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
}
|