Skip to content

Add advertising support#224

Open
fotiDim wants to merge 23 commits intomainfrom
Add-advertising-support
Open

Add advertising support#224
fotiDim wants to merge 23 commits intomainfrom
Add-advertising-support

Conversation

@fotiDim
Copy link
Copy Markdown
Contributor

@fotiDim fotiDim commented Mar 27, 2026

Addresses #169

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces version 2.0.0 of the universal_ble plugin, adding comprehensive support for BLE peripheral mode on Android, iOS, macOS, and Windows. Key changes include the new UniversalBlePeripheral API, Pigeon-based platform hooks, and a revamped example app. Feedback identifies several areas for improvement: the Android implementation should dynamically choose between notifications and indications in updateCharacteristic based on characteristic properties; the Darwin implementation currently ignores manufacturer data during advertising; and the Windows implementation is limited by the GattServiceProvider API, suggesting a move to BluetoothLEAdvertisementPublisher for better payload customization.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds BLE peripheral/advertising support to the universal_ble Flutter plugin by introducing a new Pigeon-based peripheral API (UniversalBlePeripheral) and implementing it across Android/iOS/macOS/Windows, with example app + docs updates.

Changes:

  • Add UniversalBlePeripheral Pigeon channels + generated bindings (Dart/Android/Swift/C++), and wire them into each platform plugin.
  • Implement peripheral lifecycle: add/remove services, start/stop advertising, handle read/write requests, subscription + MTU/bond/connection callbacks.
  • Update public exports, models, documentation, example app, and bump package version to 2.0.0.

Reviewed changes

Copilot reviewed 36 out of 41 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
windows/src/universal_ble_plugin.h Adds peripheral channel inheritance and peripheral runtime state/helpers.
windows/src/universal_ble_plugin.cpp Implements Windows peripheral APIs (services, advertising, read/write, subscriptions).
windows/src/generated/universal_ble_peripheral.g.h Generated C++ Pigeon header for peripheral API.
windows/src/generated/universal_ble_peripheral.g.cpp Generated C++ Pigeon source for peripheral API.
windows/CMakeLists.txt Includes new generated peripheral C++ sources in build.
test/universal_ble_peripheral_test.dart Adds basic Dart unit tests for peripheral request result models and shared types.
pubspec.yaml Bumps package version to 2.0.0.
pigeon/universal_ble_peripheral.dart Defines peripheral Pigeon schema and host/flutter APIs.
lib/universal_ble_peripheral.dart Adds top-level library export for peripheral API.
lib/universal_ble.dart Exposes peripheral APIs via main package export surface.
lib/src/universal_ble_peripheral/universal_ble_peripheral_platform_interface.dart Introduces peripheral platform interface + unsupported implementation.
lib/src/universal_ble_peripheral/universal_ble_peripheral_pigeon.dart Implements platform interface using Pigeon + callback plumbing.
lib/src/universal_ble_peripheral/universal_ble_peripheral_mapper.dart Maps shared models to peripheral Pigeon types.
lib/src/universal_ble_peripheral/universal_ble_peripheral.dart Public static API wrapper around the platform interface.
lib/src/universal_ble_peripheral/generated/universal_ble_peripheral.g.dart Generated Dart Pigeon bindings for peripheral API.
lib/src/models/peripheral/peripheral_request_result.dart Adds shared peripheral read/write request result models.
lib/src/models/peripheral/peripheral_exports.dart Exports peripheral model types.
lib/src/models/peripheral/attribute_permissions.dart Adds attribute permission enum.
lib/src/models/model_exports.dart Includes peripheral exports in model barrel.
example/macos/Podfile.lock Example dependency updates (adds ble_peripheral).
example/macos/Flutter/GeneratedPluginRegistrant.swift Registers ble_peripheral in macOS example.
example/lib/peripheral/peripheral_home.dart Adds peripheral demo UI + callbacks and operations.
example/lib/main.dart Switches example to a tabbed Central/Peripheral UI.
example/lib/home/home.dart Renames/refactors central home to support tabbed layout.
example/ios/Runner/Info.plist Adds/moves Bluetooth permission keys + scene/flags adjustments.
example/ios/Runner/AppDelegate.swift Updates app delegate to register plugins via implicit engine delegate.
example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme Adds pre-build “prepare” script action.
example/ios/Runner.xcodeproj/project.pbxproj Adds Swift package reference for generated plugins package.
example/ios/Podfile.lock Example dependency updates (adds ble_peripheral).
example/ios/Flutter/AppFrameworkInfo.plist Removes MinimumOSVersion entry.
darwin/Classes/UniversalBlePlugin.swift Wires up peripheral Pigeon setup on iOS/macOS.
darwin/Classes/UniversalBlePeripheralPlugin.swift Adds CoreBluetooth peripheral manager implementation.
darwin/Classes/UniversalBlePeripheralExtensions.swift Adds CB* mapping helpers and caches for peripheral types.
darwin/Classes/UniversalBlePeripheral.g.swift Generated Swift Pigeon bindings for peripheral API.
build_pigeon.sh Generates + formats new peripheral Pigeon outputs.
android/src/main/kotlin/com/navideck/universal_ble/UniversalBlePlugin.kt Wires Android peripheral plugin into engine/activity lifecycle.
android/src/main/kotlin/com/navideck/universal_ble/UniversalBlePeripheralPlugin.kt Adds Android GATT server + advertiser implementation.
android/src/main/kotlin/com/navideck/universal_ble/UniversalBlePeripheralExtensions.kt Adds Android mapping/helpers (services/chars/descriptors, perms, CCCD).
android/src/main/kotlin/com/navideck/universal_ble/UniversalBlePeripheral.g.kt Generated Kotlin Pigeon bindings for peripheral API.
README.md Documents Peripheral Mode API support table and usage.
CHANGELOG.md Adds 2.0.0 changelog entry describing peripheral mode addition.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fotiDim fotiDim force-pushed the Add-advertising-support branch 4 times, most recently from f666f29 to 6aa94fe Compare April 1, 2026 19:59
@fotiDim fotiDim marked this pull request as ready for review April 1, 2026 20:42
@navidecklabs navidecklabs requested a review from Copilot April 1, 2026 20:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 44 out of 52 changed files in this pull request and generated 10 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fotiDim fotiDim requested a review from rohitsangwan01 April 2, 2026 12:15
fotiDim added 17 commits April 2, 2026 14:18
…or shared collections to prevent concurrent modification issues
…ndling. Update Android receiver registration to use RECEIVER_NOT_EXPORTED, enhance service and characteristic mapping in tests, and add error checks for unsupported features in Windows advertising.
…ude company ID followed by payload, ensuring compatibility with CoreBluetooth requirements.
…very

Expose Host API to list GATT central device ids currently subscribed to a
characteristic (Darwin/Android/Windows). Used by apps to restore in-memory
state after process restart when subscription callbacks are not replayed.

- Pigeon: UniversalBlePeripheralChannel.getSubscribedCentrals
- Darwin: filter centralCharacteristicSubscriptions
- Android: filter subscribedCharDevicesMap
- Windows: GattLocalCharacteristic.SubscribedClients()
- Dart: UniversalBlePeripheral.getSubscribedCentrals

Made-with: Cursor
BleDescriptor gains optional initial value (e.g. HID Report Reference 0x2908).
UniversalBlePeripheralMapper passes it through to PeripheralDescriptor so
Android/Darwin can expose static descriptor bytes for HID clients.

Made-with: Cursor
Set SwiftOptions(includeErrorClass: false) for universal_ble_peripheral
pigeon so UniversalBlePeripheral.g.swift shares PigeonError from
UniversalBle.g.swift within the same module.

Made-with: Cursor
- Replaced `isSupported()` with `isFeatureSupported()` and `isAdvertising()` with `getAdvertisingState()`.
- Introduced new methods for managing peripheral readiness and advertising states.
- Updated event handling to use a stream for peripheral events, replacing static callback setters.
- Added enums for `PeripheralReadinessState` and `PeripheralAdvertisingState` to standardize state management across platforms.
- Adjusted documentation and example usage to reflect API changes.
- Renamed `getBluetoothAvailabilityState()` to `getAvailabilityState()` across all relevant files for uniformity.
- Updated method calls in documentation and example code to reflect the new naming convention.
- Adjusted permission checking method from `hasPermissions()` to `isPermissionGranted()` for improved readability.
- Changed `receivesAdvertisements()` to `isReceivingAdvertisements()` to enhance clarity in intent.
fotiDim added 6 commits April 2, 2026 14:18
- Replaced `isFeatureSupported()` with `getCapabilities().supportsPeripheralMode()` for better clarity in feature checks.
- Renamed `getSubscribedCentrals()` to `getSubscribedClients()` to accurately reflect the terminology used in BLE communication.
- Updated documentation and example code to align with the new method names and capabilities structure.
- Enhanced the capabilities API to provide detailed support information for peripheral mode and advertising features.
- Introduced `getMaximumNotifyLength()` to retrieve the maximum characteristic notify payload length for connected clients.
- Added support for descriptor read and write requests through `onDescriptorReadRequest()` and `onDescriptorWriteRequest()` methods.
- Updated existing methods to use `PeripheralCharacteristicId` and `PeripheralDescriptorId` for better type safety and clarity.
- Refactored request handler setup to accommodate new descriptor request handlers.
- Adjusted documentation and example code to reflect the new API capabilities and changes.
- Updated setup instructions to include new methods for service management and advertising.
- Added examples for characteristic updates, subscribed clients, and event stream handling.
- Improved clarity and organization of sections to better guide users through the API functionalities.
- Included breaking changes related to the `isSupported()` method replacement.
… methods

- Enhanced CHANGELOG for version 2.0.0 with details on the new `UniversalBlePeripheralClient` API and breaking changes.
- Added CONTRIBUTING.md to outline contribution guidelines, issue reporting, and pull request processes.
- Refactored permission-related methods: renamed `isPermissionGranted()` to `hasPermissions()` and `isReceivingAdvertisements()` to `receivesAdvertisements()` for improved clarity and consistency across the codebase.
- Updated README to clarify advertising behavior on Android and Windows, including handling of `localName` and manufacturer data.
- Modified advertising logic to conditionally set parameters based on the platform.
- Improved string comparison in Swift for peripheral characteristics and services to be case-insensitive.
- Enhanced error handling in the Windows plugin for advertising and characteristic updates.
- Refactored BLE service equality checks to use list comparison for better accuracy.
- Created Podfile for both iOS and macOS to manage dependencies and build settings.
- Updated Debug and Release xcconfig files to include necessary Pod support files.
- Ensured compatibility with Flutter's pod installation process and project structure.
@fotiDim fotiDim force-pushed the Add-advertising-support branch from ea9f24f to 3289158 Compare April 2, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants