web_blue

Creator: coderz1093

Last updated:

0 purchases

web_blue Image
web_blue Images

Languages

Categories

Add to Cart

Description:

web blue

Dart wrapper via dart:js for https://webbluetoothcg.github.io/web-bluetooth/
Features #

canUseBlue
getAvailability
subscribeAvailabilitychanged/unsubscribeAvailabilitychanged
getDevices/requestDevice
connect/disconnect
getPrimaryService/getCharacteristic
startNotifications/stopNotifications
subscribeValueChanged/unsubscribeValueChanged
readValue/writeValueWithResponse

Usage #
canUseBlue #
bool canUse = canUseBlue();
print('canUse $canUse');
copied to clipboard
getAvailability #
https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getAvailability
bool availability = await blue.getAvailability();
print('availability $availability');
copied to clipboard
subscribeAvailabilitychanged/unsubscribeAvailabilitychanged #
https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/onavailabilitychanged
final EventListener _handleAvailabilitychanged = allowInterop((Event event) {}
...
blue.subscribeAvailabilitychanged(_handleAvailabilitychanged);
...
blue.unsubscribeAvailabilitychanged(_handleAvailabilitychanged);
copied to clipboard
getDevices/requestDevice #

https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/getDevices

List<BlueDevice> getDevices = await blue.getDevices();
_device = getDevices[0];
copied to clipboard

https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth/requestDevice

BlueDevice requestDevice = await blue.requestDevice(RequestOptions(
optionalServices: [BlueUUID.getService(WOODEMI_SERV__COMMAND)],
acceptAllDevices: true,
));
_device = requestDevice;
copied to clipboard
connect/disconnect #

https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTServer/connect

_device?.gatt.connect().then((value) {
print('device.gatt.connect success');
}).catchError((error) {
print('device.gatt.connect $error');
});
copied to clipboard

https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTServer/disconnect

_device?.gatt.disconnect();
copied to clipboard
getPrimaryService/getCharacteristic #

https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTServer/getPrimaryService

_service = await _device!.gatt.getPrimaryService(BlueUUID.getService(WOODEMI_SERV__COMMAND));
copied to clipboard

https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTService/getCharacteristic

_characteristic = await _service!.getCharacteristic(BlueUUID.getCharacteristic(WOODEMI_CHAR__COMMAND_REQUEST));
copied to clipboard
startNotifications/stopNotifications #

https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/startNotifications

await _characteristic!.startNotifications();
copied to clipboard

https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/stopNotifications

await _characteristic!.stopNotifications();
copied to clipboard
subscribeValueChanged/unsubscribeValueChanged #

https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/characteristicvaluechanged

final EventListener _handleValueChanged = allowInterop((event) {}
...
_characteristic!.subscribeValueChanged(_handleValueChanged);
...
_characteristic!.unsubscribeValueChanged(_handleValueChanged);
copied to clipboard
readValue/writeValueWithResponse #

https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/readValue

var byteData = await _characteristic!.readValue();
copied to clipboard

https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/writeValueWithResponse

_characteristic!.writeValueWithResponse(Uint8List.fromList([0x01, 0x0A, 0x00, 0x00, 0x00, 0x01]));
copied to clipboard
Additional information #
Status in Chromium: https://chromestatus.com/feature/5264933985976320

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.