more app message call
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:change_case/change_case.dart';
|
||||
|
||||
@@ -1239,11 +1241,13 @@ abstract class VeilidUpdate {
|
||||
}
|
||||
case "AppMessage":
|
||||
{
|
||||
return VeilidAppMessage();
|
||||
return VeilidAppMessage(
|
||||
sender: json["sender"], message: json["message"]);
|
||||
}
|
||||
case "AppCall":
|
||||
{
|
||||
return VeilidAppCall();
|
||||
return VeilidAppCall(
|
||||
sender: json["sender"], message: json["message"], id: json["id"]);
|
||||
}
|
||||
case "Attachment":
|
||||
{
|
||||
@@ -1286,6 +1290,49 @@ class VeilidLog implements VeilidUpdate {
|
||||
}
|
||||
}
|
||||
|
||||
class VeilidAppMessage implements VeilidUpdate {
|
||||
final String? sender;
|
||||
final Uint8List message;
|
||||
|
||||
//
|
||||
VeilidAppMessage({
|
||||
required this.sender,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
@override
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'kind': "AppMessage",
|
||||
'sender': sender,
|
||||
'message': base64UrlEncode(message)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class VeilidAppCall implements VeilidUpdate {
|
||||
final String? sender;
|
||||
final Uint8List message;
|
||||
final String id;
|
||||
|
||||
//
|
||||
VeilidAppCall({
|
||||
required this.sender,
|
||||
required this.message,
|
||||
required this.id,
|
||||
});
|
||||
|
||||
@override
|
||||
Map<String, dynamic> get json {
|
||||
return {
|
||||
'kind': "AppMessage",
|
||||
'sender': sender,
|
||||
'message': base64UrlEncode(message),
|
||||
'id': id,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class VeilidUpdateAttachment implements VeilidUpdate {
|
||||
final VeilidStateAttachment state;
|
||||
//
|
||||
@@ -1580,6 +1627,7 @@ abstract class Veilid {
|
||||
Future<void> detach();
|
||||
Future<void> shutdownVeilidCore();
|
||||
Future<String> debug(String command);
|
||||
Future<void> appCallReply(String id, Uint8List message);
|
||||
String veilidVersionString();
|
||||
VeilidVersion veilidVersion();
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
@@ -50,6 +51,10 @@ typedef _DetachDart = void Function(int);
|
||||
// fn debug(port: i64, log_level: FfiStr)
|
||||
typedef _DebugC = Void Function(Int64, Pointer<Utf8>);
|
||||
typedef _DebugDart = void Function(int, Pointer<Utf8>);
|
||||
// fn app_call_reply(port: i64, id: FfiStr, message: FfiStr)
|
||||
typedef _AppCallReplyC = Void Function(Int64, Pointer<Utf8>, Pointer<Utf8>);
|
||||
typedef _AppCallReplyDart = void Function(int, Pointer<Utf8>, Pointer<Utf8>);
|
||||
|
||||
// fn shutdown_veilid_core(port: i64)
|
||||
typedef _ShutdownVeilidCoreC = Void Function(Int64);
|
||||
typedef _ShutdownVeilidCoreDart = void Function(int);
|
||||
@@ -304,6 +309,7 @@ class VeilidFFI implements Veilid {
|
||||
final _DetachDart _detach;
|
||||
final _ShutdownVeilidCoreDart _shutdownVeilidCore;
|
||||
final _DebugDart _debug;
|
||||
final _AppCallReplyDart _appCallReply;
|
||||
final _VeilidVersionStringDart _veilidVersionString;
|
||||
final _VeilidVersionDart _veilidVersion;
|
||||
|
||||
@@ -328,6 +334,8 @@ class VeilidFFI implements Veilid {
|
||||
dylib.lookupFunction<_ShutdownVeilidCoreC, _ShutdownVeilidCoreDart>(
|
||||
'shutdown_veilid_core'),
|
||||
_debug = dylib.lookupFunction<_DebugC, _DebugDart>('debug'),
|
||||
_appCallReply = dylib.lookupFunction<_AppCallReplyC, _AppCallReplyDart>(
|
||||
'app_call_reply'),
|
||||
_veilidVersionString = dylib.lookupFunction<_VeilidVersionStringC,
|
||||
_VeilidVersionStringDart>('veilid_version_string'),
|
||||
_veilidVersion =
|
||||
@@ -420,6 +428,16 @@ class VeilidFFI implements Veilid {
|
||||
return processFuturePlain(recvPort.first);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> appCallReply(String id, Uint8List message) async {
|
||||
var nativeId = id.toNativeUtf8();
|
||||
var nativeEncodedMessage = base64UrlEncode(message).toNativeUtf8();
|
||||
final recvPort = ReceivePort("app_call_reply");
|
||||
final sendPort = recvPort.sendPort;
|
||||
_appCallReply(sendPort.nativePort, nativeId, nativeEncodedMessage);
|
||||
return processFutureVoid(recvPort.first);
|
||||
}
|
||||
|
||||
@override
|
||||
String veilidVersionString() {
|
||||
final versionString = _veilidVersionString();
|
||||
|
@@ -5,6 +5,7 @@ import 'dart:js' as js;
|
||||
import 'dart:js_util' as js_util;
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
@@ -82,6 +83,13 @@ class VeilidJS implements Veilid {
|
||||
return _wrapApiPromise(js_util.callMethod(wasm, "debug", [command]));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> appCallReply(String id, Uint8List message) {
|
||||
var encodedMessage = base64UrlEncode(message);
|
||||
return _wrapApiPromise(
|
||||
js_util.callMethod(wasm, "app_call_reply", [id, encodedMessage]));
|
||||
}
|
||||
|
||||
@override
|
||||
String veilidVersionString() {
|
||||
return js_util.callMethod(wasm, "veilid_version_string", []);
|
||||
|
Reference in New Issue
Block a user