SimulatedBleClientTransport constructor

SimulatedBleClientTransport(
  1. SimulatedBlePlatform server, {
  2. String clientId = 'client',
  3. int writeLimit = 20,
})

Implementation

SimulatedBleClientTransport(
  this.server, {
  this.clientId = 'client',
  this.writeLimit = 20,
}) {
  _subscriptions.add(
    server.notificationEvents.listen((event) {
      if (!_connected) return;
      final uuid = event['uuid'] as String;
      if ((event['clientId'] != null && event['clientId'] != clientId) ||
          server.subscribers[uuid]?.contains(clientId) != true) {
        return;
      }
      final profile = server.activeProfile!;
      for (final service in profile.services) {
        if (service.fields.any((f) => f.uuid == uuid)) {
          _notifications.add(
            BleRawNotification(
              '${service.uuid}/$uuid',
              event['value'] as List<int>,
            ),
          );
        }
      }
    }),
  );
  _subscriptions.add(
    server.events.listen((event) {
      if (event['type'] == 'disconnected' && event['clientId'] == clientId) {
        _connected = false;
        _disconnected.add(null);
      }
    }),
  );
}