*/
constexpr const char CB_INTERFACE_BASE[] =
R"__dart_cb(
+typedef OnDisconnected = Future<void> Function(PeerInfo);
+
/// [<INTERFACE_NAME>] class for Cion.
class <INTERFACE_NAME> {
/// Constructor for this class.
- <INTERFACE_NAME>(this.serverDisplayName) : _client = Client('<INTERFACE_NAME>');
+ <INTERFACE_NAME>(this.serverDisplayName, {SecurityInfo? security}) : _client = Client('<INTERFACE_NAME>', security: security);
final List<_Delegate> _delegates = <_Delegate>[];
Future<void> _onDisconnectedEvent(PeerInfo peer) async {
_isConnected = false;
+ _onDisconnected?.call(peer);
}
Future<void> _onDiscoveredEvent(PeerInfo peer) async {
}
/// Connects with the server.
- Future<bool> connect() async {
+ Future<bool> connect({required OnDisconnected onDisconnected}) async {
if (_isConnected) {
return true;
}
throw StateError('Already try to connect');
}
+ _onDisconnected = onDisconnected;
await _client.tryDiscovery(onDiscovered: _onDiscoveredEvent);
_connectCompleter = Completer<bool>();
return _connectCompleter!.future;
}
+ /// Disconnects with the server.
+ void disconnect() {
+ if (!_isConnected) {
+ return;
+ }
+
+ _client.disconnect();
+ }
+
/// Disposes of registered delegate interface.
void disposeCallback(Function callback) {
_delegates
final Client _client;
final String serverDisplayName;
bool _isConnected = false;
+ OnDisconnected? _onDisconnected;
Completer<bool>? _connectCompleter;
}
)__dart_cb";