diff --git a/.browserslistrc b/.browserslistrc deleted file mode 100644 index 8084853..0000000 --- a/.browserslistrc +++ /dev/null @@ -1,12 +0,0 @@ -# This file is used by the build system to adjust CSS and JS output to support the specified browsers below. -# For additional information regarding the format and rule options, please see: -# https://github.com/browserslist/browserslist#queries - -# You can see what browsers were selected by your queries by running: -# npx browserslist - -> 0.5% -last 2 versions -Firefox ESR -not dead -not IE 9-11 # For IE 9-11 support, remove 'not'. \ No newline at end of file diff --git a/angular.json b/angular.json index 856879d..fe0759b 100644 --- a/angular.json +++ b/angular.json @@ -11,12 +11,14 @@ "prefix": "ble", "architect": { "build": { - "builder": "@angular-devkit/build-angular:browser", + "builder": "@angular-devkit/build-angular:application", "options": { "outputPath": "dist/angular-web-bluetooth-starter", "index": "src/index.html", - "main": "src/main.ts", - "polyfills": "src/polyfills.ts", + "browser": "src/main.ts", + "polyfills": [ + "zone.js" + ], "tsConfig": "tsconfig.app.json", "assets": [ "src/favicon.ico", @@ -28,55 +30,43 @@ ], "scripts": [ "./node_modules/smoothie/smoothie.js" - ], - "vendorChunk": true, - "extractLicenses": false, - "buildOptimizer": false, - "sourceMap": true, - "optimization": false, - "namedChunks": true + ] }, "configurations": { "production": { - "fileReplacements": [ - { - "replace": "src/environments/environment.ts", - "with": "src/environments/environment.prod.ts" - } - ], - "optimization": true, - "outputHashing": "all", - "sourceMap": false, - "namedChunks": false, - "extractLicenses": true, - "vendorChunk": false, - "buildOptimizer": true, "budgets": [ { "type": "initial", - "maximumWarning": "2mb", - "maximumError": "5mb" + "maximumWarning": "500kb", + "maximumError": "1mb" }, { "type": "anyComponentStyle", - "maximumWarning": "6kb", - "maximumError": "10kb" + "maximumWarning": "2kb", + "maximumError": "4kb" } - ] + ], + "outputHashing": "all" + }, + "development": { + "optimization": false, + "extractLicenses": false, + "sourceMap": true } }, - "defaultConfiguration": "" + "defaultConfiguration": "production" }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", - "options": { - "buildTarget": "angular-web-bluetooth-starter:build" - }, "configurations": { "production": { "buildTarget": "angular-web-bluetooth-starter:build:production" + }, + "development": { + "buildTarget": "angular-web-bluetooth-starter:build:development" } - } + }, + "defaultConfiguration": "development" }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", @@ -114,14 +104,17 @@ "build": { "builder": "@angular-devkit/build-angular:ng-packagr", "options": { - "tsConfig": "projects/manekinekko/angular-web-bluetooth/tsconfig.lib.json", "project": "projects/manekinekko/angular-web-bluetooth/ng-package.json" }, "configurations": { "production": { "tsConfig": "projects/manekinekko/angular-web-bluetooth/tsconfig.lib.prod.json" + }, + "development": { + "tsConfig": "projects/manekinekko/angular-web-bluetooth/tsconfig.lib.json" } - } + }, + "defaultConfiguration": "production" }, "test": { "builder": "@angular-builders/jest:run", diff --git a/docs/classes/AppPage.html b/docs/classes/AppPage.html index 5f4c9ae..7e15bb2 100644 --- a/docs/classes/AppPage.html +++ b/docs/classes/AppPage.html @@ -13,8 +13,66 @@
- -
- Defined in e2e/src/app.po.ts:8
- |
-
+ Defined in e2e/src/app.po.ts:8
+ |
+
-
- Returns :
Promise<string>
+
+ Returns :
+ Promise<string>
- |
- Defined in e2e/src/app.po.ts:4
- |
-
+ Defined in e2e/src/app.po.ts:4
+ |
+
-
- Returns :
Promise<>
+
+ Returns :
+ Promise<>
- |
Name | -Type | -Optional | -
type | -
- string
- |
-
- - No - | - - -
listener | -
- EventListener
- |
-
- - No - | - - -
void
-
- Name | +Type | +Optional | +
type | +
+ string
+ |
+
+ + No + | + + +
listener | +
+ EventListener
+ |
+
+ + No + | + + +
void
+
+ export class FakeBluetoothDevice {
gatt: BluetoothRemoteGATTServer;
private listeners: {
diff --git a/docs/classes/FakeBluetoothRemoteGATTCharacteristic.html b/docs/classes/FakeBluetoothRemoteGATTCharacteristic.html
index 26940e7..f2e4b0f 100644
--- a/docs/classes/FakeBluetoothRemoteGATTCharacteristic.html
+++ b/docs/classes/FakeBluetoothRemoteGATTCharacteristic.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -44,21 +102,27 @@
- - Classes
- - FakeBluetoothRemoteGATTCharacteristic
+ - Classes
+ - FakeBluetoothRemoteGATTCharacteristic
-
+
File
@@ -71,7 +135,7 @@ File
-
+
Index
@@ -134,7 +198,7 @@ Methods
-
+
Constructor
@@ -195,7 +259,7 @@ Constructor
-
+
Properties
@@ -310,7 +374,7 @@
-
+
Methods
@@ -333,65 +397,63 @@
-
-
-
-
-
+
+
+
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- type
-
- string
-
-
-
- No
-
-
-
-
-
- listener
-
- EventListener
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ type
+
+ string
+
+
+
+ No
+
+
+
+
+
+ listener
+
+ EventListener
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
@@ -414,53 +476,51 @@
-
-
-
-
-
+
+
+
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- value
-
- DataView
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ value
+
+ DataView
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
@@ -483,21 +543,21 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -520,21 +580,21 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -548,7 +608,7 @@
-
+
export class FakeBluetoothDevice {
gatt: BluetoothRemoteGATTServer;
private listeners: {
diff --git a/docs/classes/FakeBluetoothRemoteGATTServer.html b/docs/classes/FakeBluetoothRemoteGATTServer.html
index b37573c..24d945c 100644
--- a/docs/classes/FakeBluetoothRemoteGATTServer.html
+++ b/docs/classes/FakeBluetoothRemoteGATTServer.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -44,21 +102,27 @@
- - Classes
- - FakeBluetoothRemoteGATTServer
+ - Classes
+ - FakeBluetoothRemoteGATTServer
-
+
File
@@ -71,7 +135,7 @@ File
-
+
Index
@@ -127,7 +191,7 @@ Methods
-
+
Constructor
@@ -187,7 +251,7 @@ Constructor
-
+
Properties
@@ -267,7 +331,7 @@
-
+
Methods
@@ -290,21 +354,21 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -327,21 +391,21 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -364,53 +428,51 @@
-
-
-
-
-
+
+
+
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- service
-
- BluetoothServiceUUID
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : any
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ service
+
+ BluetoothServiceUUID
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : any
+
+
+
+
+
@@ -424,7 +486,7 @@
-
+
export class FakeBluetoothDevice {
gatt: BluetoothRemoteGATTServer;
private listeners: {
diff --git a/docs/classes/FakeBluetoothRemoteGATTService.html b/docs/classes/FakeBluetoothRemoteGATTService.html
index f980986..1be6b51 100644
--- a/docs/classes/FakeBluetoothRemoteGATTService.html
+++ b/docs/classes/FakeBluetoothRemoteGATTService.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -44,21 +102,27 @@
- - Classes
- - FakeBluetoothRemoteGATTService
+ - Classes
+ - FakeBluetoothRemoteGATTService
-
+
File
@@ -71,7 +135,7 @@ File
-
+
Index
@@ -118,7 +182,7 @@ Methods
-
+
Constructor
@@ -172,7 +236,7 @@ Constructor
-
+
Properties
@@ -221,7 +285,7 @@
-
+
Methods
@@ -244,53 +308,51 @@
-
-
-
-
-
+
+
+
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- characteristic
-
- BluetoothCharacteristicUUID
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : any
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ characteristic
+
+ BluetoothCharacteristicUUID
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : any
+
+
+
+
+
@@ -304,7 +366,7 @@
-
+
export class FakeBluetoothDevice {
gatt: BluetoothRemoteGATTServer;
private listeners: {
diff --git a/docs/components/AppComponent.html b/docs/components/AppComponent.html
index 81f543c..5d72216 100644
--- a/docs/components/AppComponent.html
+++ b/docs/components/AppComponent.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -36,26 +94,29 @@
- - Components
- - Components
+ -
AppComponent
-
+
File
@@ -67,7 +128,7 @@
File
-
+
Metadata
@@ -82,6 +143,7 @@ Metadata
+
selector
ble-root
@@ -89,6 +151,8 @@ Metadata
+
+
template
<ble-dashboard></ble-dashboard>
@@ -118,7 +182,7 @@ Metadata
-
+
import { Component } from '@angular/core';
@Component({
@@ -133,7 +197,7 @@ Metadata
-
+
diff --git a/docs/components/BatteryLevelComponent.html b/docs/components/BatteryLevelComponent.html
index ce726c6..794b2a1 100644
--- a/docs/components/BatteryLevelComponent.html
+++ b/docs/components/BatteryLevelComponent.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -36,29 +94,33 @@
- - Components
- - Components
+ -
BatteryLevelComponent
-
+
File
@@ -72,12 +134,12 @@
File
Implements
- OnInit
- OnDestroy
+ OnInit
+ OnDestroy
-
+
Metadata
@@ -90,6 +152,7 @@ Metadata
+
providers
@@ -104,46 +167,49 @@ Metadata
+
+
styles
- :host {
- display: flex;
- justify-content: center;
- flex-direction: row;
- text-align: center;
- }
- span {
- font-size: 5em;
- position: absolute;
- top: 222px;
- width: 120px;
- display: block;
- text-align: center;
- }
- sup {
- font-size: 24px;
- }
- mat-progress-spinner {
- top: 90px;
- left: 5px;
- }
- mat-icon {
- position: absolute;
- bottom: 255px;
- }
-
+ :host {
+ display: flex;
+ justify-content: center;
+ flex-direction: row;
+ text-align: center;
+ }
+ span {
+ font-size: 5em;
+ position: absolute;
+ top: 222px;
+ width: 120px;
+ display: block;
+ text-align: center;
+ }
+ sup {
+ font-size: 24px;
+ }
+ mat-progress-spinner {
+ top: 90px;
+ left: 5px;
+ }
+ mat-icon {
+ position: absolute;
+ bottom: 255px;
+ }
+
template
- <span data-testid="value">{{ value || "000" }}<sup>%</sup></span>
+ <span data-testid="value">{{ value || '000' }}<sup>%</sup></span>
<mat-progress-spinner
- [color]="color"
- [mode]="mode"
- diameter="250"
- strokeWidth="2"
- [value]="value || 100">
+ [color]="color"
+ [mode]="mode"
+ diameter="250"
+ strokeWidth="2"
+ [value]="value || 100"
+>
</mat-progress-spinner>
<mat-icon>battery_charging_full</mat-icon>
@@ -161,7 +227,7 @@ Metadata
-
+
Index
@@ -262,7 +328,7 @@ Accessors
-
+
Constructor
@@ -273,7 +339,7 @@ Constructor
-
+
@@ -339,7 +405,7 @@ Constructor
-
+
Methods
@@ -362,21 +428,21 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -399,21 +465,21 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -436,53 +502,51 @@
-
-
-
-
-
+
+
+
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- error
-
- string
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ error
+
+ string
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
@@ -505,21 +569,21 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -542,21 +606,21 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -579,21 +643,21 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -611,64 +675,62 @@
-updateValue(value: number)
+updateValue(value: number | literal type)
-
-
-
-
-
+
+
+
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- value
-
- number
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ value
+
+ number | literal type
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
-
+
Properties
@@ -697,7 +759,7 @@
-
+
@@ -724,7 +786,7 @@
-
+
@@ -744,13 +806,18 @@
- Type : Subscription
+ Type : Subscription | null
+
+
+
+ Default value : null
+
-
+
@@ -770,7 +837,7 @@
- Type : string
+ Type : ProgressSpinnerMode
@@ -781,7 +848,7 @@
-
+
@@ -808,7 +875,7 @@
-
+
@@ -835,7 +902,7 @@
-
+
@@ -855,13 +922,18 @@
- Type : Subscription
+ Type : Subscription | null
+
+
+
+ Default value : null
+
-
+
@@ -881,18 +953,18 @@
- Type : null
+ Type : number
- Default value : null
+ Default value : 0
-
+
@@ -912,13 +984,18 @@
- Type : Subscription
+ Type : Subscription | null
+
+
+
+ Default value : null
+
-
+
@@ -927,7 +1004,7 @@
-
+
Accessors
@@ -947,7 +1024,7 @@
-
+
@@ -957,78 +1034,88 @@
-
+
import { Component, OnDestroy, OnInit } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
-import { BluetoothCore, BrowserWebBluetooth, ConsoleLoggerService } from '@manekinekko/angular-web-bluetooth';
+import {
+ BluetoothCore,
+ BrowserWebBluetooth,
+ ConsoleLoggerService,
+} from '@manekinekko/angular-web-bluetooth';
import { Subscription } from 'rxjs';
import { BleService } from '../ble.service';
+import { ProgressSpinnerMode } from '@angular/material/progress-spinner';
-export const bleCore = (b: BrowserWebBluetooth, l: ConsoleLoggerService) => new BluetoothCore(b, l);
+export const bleCore = (b: BrowserWebBluetooth, l: ConsoleLoggerService) =>
+ new BluetoothCore(b, l);
export const bleService = (b: BluetoothCore) => new BleService(b);
-
// make sure we get a singleton instance of each service
-const PROVIDERS = [{
- provide: BluetoothCore,
- useFactory: bleCore,
- deps: [BrowserWebBluetooth, ConsoleLoggerService]
-}, {
- provide: BleService,
- useFactory: bleService,
- deps: [BluetoothCore]
-}];
-
+const PROVIDERS = [
+ {
+ provide: BluetoothCore,
+ useFactory: bleCore,
+ deps: [BrowserWebBluetooth, ConsoleLoggerService],
+ },
+ {
+ provide: BleService,
+ useFactory: bleService,
+ deps: [BluetoothCore],
+ },
+];
@Component({
selector: 'ble-battery-level',
template: `
- <span data-testid="value">{{ value || "000" }}<sup>%</sup></span>
+ <span data-testid="value">{{ value || '000' }}<sup>%</sup></span>
<mat-progress-spinner
- [color]="color"
- [mode]="mode"
- diameter="250"
- strokeWidth="2"
- [value]="value || 100">
+ [color]="color"
+ [mode]="mode"
+ diameter="250"
+ strokeWidth="2"
+ [value]="value || 100"
+ >
</mat-progress-spinner>
<mat-icon>battery_charging_full</mat-icon>
`,
- styles: [`
- :host {
- display: flex;
- justify-content: center;
- flex-direction: row;
- text-align: center;
- }
- span {
- font-size: 5em;
- position: absolute;
- top: 222px;
- width: 120px;
- display: block;
- text-align: center;
- }
- sup {
- font-size: 24px;
- }
- mat-progress-spinner {
- top: 90px;
- left: 5px;
- }
- mat-icon {
- position: absolute;
- bottom: 255px;
- }
- `],
- providers: PROVIDERS
+ styles: [
+ `
+ :host {
+ display: flex;
+ justify-content: center;
+ flex-direction: row;
+ text-align: center;
+ }
+ span {
+ font-size: 5em;
+ position: absolute;
+ top: 222px;
+ width: 120px;
+ display: block;
+ text-align: center;
+ }
+ sup {
+ font-size: 24px;
+ }
+ mat-progress-spinner {
+ top: 90px;
+ left: 5px;
+ }
+ mat-icon {
+ position: absolute;
+ bottom: 255px;
+ }
+ `,
+ ],
+ providers: PROVIDERS,
})
export class BatteryLevelComponent implements OnInit, OnDestroy {
- value = null;
- mode = 'determinate';
+ value = 0;
+ mode: ProgressSpinnerMode = 'determinate';
color = 'primary';
- valuesSubscription: Subscription;
- streamSubscription: Subscription;
- deviceSubscription: Subscription;
+ valuesSubscription: Subscription | null = null;
+ streamSubscription: Subscription | null = null;
+ deviceSubscription: Subscription | null = null;
get device() {
return this.service.getDevice();
@@ -1037,59 +1124,82 @@
constructor(
public service: BleService,
public snackBar: MatSnackBar,
- public console: ConsoleLoggerService) {
-
+ public console: ConsoleLoggerService
+ ) {
service.config({
decoder: (value: DataView) => value.getInt8(0),
service: 'battery_service',
- characteristic: 'battery_level'
+ characteristic: 'battery_level',
});
}
ngOnInit() {
this.getDeviceStatus();
- this.streamSubscription = this.service.stream()
- .subscribe((value: number) => {
+ this.streamSubscription = this.service.stream().subscribe(
+ (
+ value:
+ | number
+ | {
+ [key: string]: number;
+ }
+ ) => {
this.updateValue(value);
- }, error => this.hasError(error));
-
+ },
+ (error) => this.hasError(error)
+ );
}
getDeviceStatus() {
- this.deviceSubscription = this.service.getDevice()
- .subscribe(device => {
- if (device) {
- this.color = 'warn';
- this.mode = 'indeterminate';
- this.value = null;
- } else {
- // device not connected or disconnected
- this.value = null;
- this.mode = 'determinate';
- this.color = 'primary';
- }
- }, this.hasError.bind(this));
+ this.deviceSubscription = this.service.getDevice().subscribe((device) => {
+ if (device) {
+ this.color = 'warn';
+ this.mode = 'indeterminate';
+ this.value = 0;
+ } else {
+ // device not connected or disconnected
+ this.value = 0;
+ this.mode = 'determinate';
+ this.color = 'primary';
+ }
+ }, this.hasError.bind(this));
}
requestValue() {
- this.valuesSubscription = this.service.value()
- .subscribe({
- next: (val: number) => this.updateValue(val),
- error: (err) => this.hasError(err)
- });
+ this.valuesSubscription = this.service.value().subscribe({
+ next: (
+ val:
+ | number
+ | {
+ [key: string]: number;
+ }
+ ) => this.updateValue(val),
+ error: (err) => this.hasError(err),
+ });
}
- updateValue(value: number) {
+ updateValue(
+ value:
+ | number
+ | {
+ [key: string]: number;
+ }
+ ) {
+
+ if (typeof value === 'number') {
+ this.value = value;
+ } else {
+ this.value = value[''];
+ }
+
this.console.log('Reading battery level %d', value);
- this.value = value;
this.mode = 'determinate';
}
disconnect() {
this.service.disconnectDevice();
- this.deviceSubscription.unsubscribe();
- this.valuesSubscription.unsubscribe();
+ this.deviceSubscription!.unsubscribe();
+ this.valuesSubscription!.unsubscribe();
}
hasError(error: string) {
@@ -1102,43 +1212,42 @@
this.streamSubscription?.unsubscribe();
}
}
-
-
+
- :host {
- display: flex;
- justify-content: center;
- flex-direction: row;
- text-align: center;
- }
- span {
- font-size: 5em;
- position: absolute;
- top: 222px;
- width: 120px;
- display: block;
- text-align: center;
- }
- sup {
- font-size: 24px;
- }
- mat-progress-spinner {
- top: 90px;
- left: 5px;
- }
- mat-icon {
- position: absolute;
- bottom: 255px;
- }
-
+ :host {
+ display: flex;
+ justify-content: center;
+ flex-direction: row;
+ text-align: center;
+ }
+ span {
+ font-size: 5em;
+ position: absolute;
+ top: 222px;
+ width: 120px;
+ display: block;
+ text-align: center;
+ }
+ sup {
+ font-size: 24px;
+ }
+ mat-progress-spinner {
+ top: 90px;
+ left: 5px;
+ }
+ mat-icon {
+ position: absolute;
+ bottom: 255px;
+ }
+
-
+
@@ -1163,7 +1272,7 @@
+
+
@@ -36,32 +94,37 @@
- - Components
- - Components
+ -
DashboardComponent
- -
- Info
+
-
+ Info
- -
- Source
+
-
+ Source
- -
- Template
+
-
+ Template
- -
- Styles
+
-
+ Styles
- -
- DOM Tree
+
-
+ DOM Tree
-
+
File
@@ -73,7 +136,7 @@
File
-
+
Metadata
@@ -88,11 +151,14 @@ Metadata
+
selector
ble-dashboard
+
+
styleUrls
./dashboard.component.css
@@ -117,7 +183,7 @@ Metadata
-
+
Constructor
@@ -145,7 +211,7 @@ Constructor
-
+
import { Component } from '@angular/core';
@Component({
@@ -160,7 +226,7 @@ Constructor
-
+
<mat-toolbar color="primary">
<img src="assets/angular-web-ble.png" />
<span>Angular Web BLE Demo</span>
@@ -298,7 +364,7 @@ Constructor
-
+
./dashboard.component.css
@@ -347,7 +413,7 @@ Constructor
}
-
+
diff --git a/docs/components/HumidityComponent.html b/docs/components/HumidityComponent.html
index a5ec2f7..c7472e5 100644
--- a/docs/components/HumidityComponent.html
+++ b/docs/components/HumidityComponent.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -36,29 +94,33 @@
- - Components
- - Components
+ -
HumidityComponent
-
+
File
@@ -72,12 +134,12 @@
File
Implements
- OnInit
- OnDestroy
+ OnInit
+ OnDestroy
-
+
Metadata
@@ -90,6 +152,7 @@ Metadata
+
providers
@@ -104,6 +167,8 @@ Metadata
+
+
styles
@@ -133,7 +198,7 @@ Metadata
-
+
Index
@@ -149,6 +214,7 @@ Properties
chart
+
chartRef
@@ -227,7 +293,7 @@ Accessors
-
+
Constructor
@@ -292,7 +358,7 @@ Constructor
-
+
Methods
@@ -315,21 +381,21 @@
-
-
- Defined in src/app/thingy52/humidity.component.ts:97
-
-
+
+
+ Defined in src/app/thingy52/humidity.component.ts:101
+
+
-
@@ -352,53 +418,51 @@
-
-
- Defined in src/app/thingy52/humidity.component.ts:104
-
-
+
+
+ Defined in src/app/thingy52/humidity.component.ts:108
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- error
-
- string
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ error
+
+ string
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
@@ -421,21 +485,21 @@
-
-
- Defined in src/app/thingy52/humidity.component.ts:71
-
-
+
+
+ Defined in src/app/thingy52/humidity.component.ts:71
+
+
-
@@ -458,21 +522,21 @@
-
-
- Defined in src/app/thingy52/humidity.component.ts:108
-
-
+
+
+ Defined in src/app/thingy52/humidity.component.ts:112
+
+
-
@@ -495,21 +559,21 @@
-
-
- Defined in src/app/thingy52/humidity.component.ts:61
-
-
+
+
+ Defined in src/app/thingy52/humidity.component.ts:61
+
+
-
@@ -532,21 +596,21 @@
-
-
- Defined in src/app/thingy52/humidity.component.ts:81
-
-
+
+
+ Defined in src/app/thingy52/humidity.component.ts:81
+
+
-
@@ -564,64 +628,62 @@
-updateValue(value: number)
+updateValue(value: number | literal type)
-
-
- Defined in src/app/thingy52/humidity.component.ts:90
-
-
+
+
+ Defined in src/app/thingy52/humidity.component.ts:90
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- value
-
- number
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ value
+
+ number | literal type
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
-
+
Properties
@@ -639,9 +701,14 @@
- Type : SmoothieChart
+ Type : SmoothieChart | null
+
+
+
+ Default value : null
+
@@ -658,6 +725,7 @@
+
chartRef
@@ -665,10 +733,15 @@
- Type : ElementRef<HTMLCanvasElement>
+ Type : ElementRef<HTMLCanvasElement> | null
+
+
+ Default value : null
+
+
Decorators :
@@ -700,9 +773,14 @@
- Type : TimeSeries
+ Type : TimeSeries | null
+
+
+
+ Default value : null
+
@@ -780,9 +858,14 @@
- Type : Subscription
+ Type : Subscription | null
+
+
+
+ Default value : null
+
@@ -806,9 +889,14 @@
- Type : Subscription
+ Type : Subscription | null
+
+
+
+ Default value : null
+
@@ -821,7 +909,7 @@
-
+
Accessors
@@ -851,7 +939,7 @@
-
+
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { BluetoothCore, BrowserWebBluetooth, ConsoleLoggerService } from '@manekinekko/angular-web-bluetooth';
@@ -889,13 +977,13 @@
providers: PROVIDERS
})
export class HumidityComponent implements OnInit, OnDestroy {
- series: TimeSeries;
- chart: SmoothieChart;
- valuesSubscription: Subscription;
- streamSubscription: Subscription;
+ series: TimeSeries | null = null;
+ chart: SmoothieChart | null = null;
+ valuesSubscription: Subscription | null = null;
+ streamSubscription: Subscription | null = null;
@ViewChild('chart', { static: true })
- chartRef: ElementRef<HTMLCanvasElement>;
+ chartRef: ElementRef<HTMLCanvasElement> | null = null;
get device() {
return this.service.getDevice();
@@ -917,19 +1005,19 @@
this.streamSubscription = this.service.stream()
.subscribe({
- next: (val: number) => this.updateValue(val),
+ next: (val: number | { [key: string]: number; }) => this.updateValue(val),
error: (err) => this.hasError(err)
});
}
initChart() {
this.series = new window.TimeSeries() as TimeSeries;
- const canvas = this.chartRef.nativeElement;
+ const canvas = this.chartRef!.nativeElement;
// tslint:disable-next-line: max-line-length
this.chart = new window.SmoothieChart({ interpolation: 'step', grid: { fillStyle: '#ffffff', strokeStyle: 'rgba(119,119,119,0.18)', borderVisible: false }, labels: { fillStyle: '#000000', fontSize: 17 }, tooltip: true });
- this.chart.addTimeSeries(this.series, { lineWidth: 1, strokeStyle: '#ff0000', fillStyle: 'rgba(255,161,161,0.30)' });
- this.chart.streamTo(canvas);
- this.chart.stop();
+ this.chart!.addTimeSeries(this.series, { lineWidth: 1, strokeStyle: '#ff0000', fillStyle: 'rgba(255,161,161,0.30)' });
+ this.chart!.streamTo(canvas);
+ this.chart!.stop();
}
requestValue() {
@@ -941,18 +1029,22 @@
}
- updateValue(value: number) {
+ updateValue(value: number | { [key: string]: number; }) {
console.log('Reading humidity %d', value);
- this.series.append(Date.now(), value);
- this.chart.start();
+
+ if (typeof value === 'number') {
+ this.series!.append(Date.now(), value);
+ this.chart!.start();
+ }
+
}
disconnect() {
this.service.disconnectDevice();
- this.series.clear();
- this.chart.stop();
- this.valuesSubscription.unsubscribe();
+ this.series!.clear();
+ this.chart!.stop();
+ this.valuesSubscription!.unsubscribe();
}
hasError(error: string) {
@@ -960,15 +1052,15 @@
}
ngOnDestroy() {
- this.valuesSubscription.unsubscribe();
- this.streamSubscription.unsubscribe();
+ this.valuesSubscription!.unsubscribe();
+ this.streamSubscription!.unsubscribe();
}
}
-
+
:host {
display: block;
@@ -979,7 +1071,7 @@
-
+
diff --git a/docs/components/StepCounterComponent.html b/docs/components/StepCounterComponent.html
index a95f74a..6fad5a9 100644
--- a/docs/components/StepCounterComponent.html
+++ b/docs/components/StepCounterComponent.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -36,29 +94,33 @@
- - Components
- - Components
+ -
StepCounterComponent
-
+
File
@@ -72,12 +134,12 @@
File
Implements
- OnInit
- OnDestroy
+ OnInit
+ OnDestroy
-
+
Metadata
@@ -90,6 +152,7 @@ Metadata
+
providers
@@ -104,6 +167,8 @@ Metadata
+
+
styles
@@ -145,7 +210,7 @@ Metadata
-
+
Index
@@ -230,7 +295,7 @@ Accessors
-
+
Constructor
@@ -295,7 +360,7 @@ Constructor
-
+
Methods
@@ -318,21 +383,21 @@
-
-
- Defined in src/app/thingy52/stepcounter.component.ts:92
-
-
+
+
+ Defined in src/app/thingy52/stepcounter.component.ts:90
+
+
-
@@ -355,53 +420,51 @@
-
-
- Defined in src/app/thingy52/stepcounter.component.ts:97
-
-
+
+
+ Defined in src/app/thingy52/stepcounter.component.ts:95
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- error
-
- string
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ error
+
+ string
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
@@ -424,21 +487,21 @@
-
-
-
-
-
+
+
+ Defined in src/app/thingy52/stepcounter.component.ts:99
+
+
-
@@ -461,21 +524,21 @@
-
-
- Defined in src/app/thingy52/stepcounter.component.ts:74
-
-
+
+
+ Defined in src/app/thingy52/stepcounter.component.ts:72
+
+
-
@@ -498,21 +561,21 @@
-
-
- Defined in src/app/thingy52/stepcounter.component.ts:82
-
-
+
+
+ Defined in src/app/thingy52/stepcounter.component.ts:80
+
+
-
@@ -530,64 +593,62 @@
-updateValue(value: literal type)
+updateValue(value: number)
-
-
- Defined in src/app/thingy52/stepcounter.component.ts:87
-
-
+
+
+ Defined in src/app/thingy52/stepcounter.component.ts:85
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- value
-
- literal type
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ value
+
+ number
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
-
+
Properties
@@ -659,9 +720,14 @@
- Type : Subscription
+ Type : Subscription | null
+
+
+
+ Default value : null
+
@@ -716,9 +782,14 @@
- Type : Subscription
+ Type : Subscription | null
+
+
+
+ Default value : null
+
@@ -731,7 +802,7 @@
-
+
Accessors
@@ -761,7 +832,7 @@
-
+
import { Component, OnDestroy, OnInit } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { BluetoothCore, BrowserWebBluetooth, ConsoleLoggerService } from '@manekinekko/angular-web-bluetooth';
@@ -810,8 +881,8 @@
providers: PROVIDERS
})
export class StepCounterComponent implements OnInit, OnDestroy {
- valuesSubscription: Subscription;
- streamSubscription: Subscription;
+ valuesSubscription: Subscription | null = null;
+ streamSubscription: Subscription | null = null;
value = 0;
get device() {
@@ -826,9 +897,7 @@
decoder: (value: DataView) => {
const count = value.getUint32(0, true);
const time = value.getUint32(4, true);
- return {
- count, time
- };
+ return count;
},
service: 'ef680400-9b35-4933-9b10-52ffa9740042',
characteristic: 'ef680405-9b35-4933-9b10-52ffa9740042'
@@ -838,7 +907,7 @@
ngOnInit() {
this.streamSubscription = this.service.stream()
.subscribe({
- next: (val: { time: number, count: number }) => this.updateValue(val),
+ next: (val: number) => this.updateValue(val),
error: (err) => this.hasError(err)
});
}
@@ -848,14 +917,14 @@
.subscribe(() => null, error => this.hasError.bind(this));
}
- updateValue(value: { time: number, count: number }) {
+ updateValue(value: number) {
console.log('Reading step counter %d', value);
- this.value = value.count;
+ this.value = value;
}
disconnect() {
this.service.disconnectDevice();
- this.valuesSubscription.unsubscribe();
+ this.valuesSubscription!.unsubscribe();
}
hasError(error: string) {
@@ -863,8 +932,8 @@
}
ngOnDestroy() {
- this.valuesSubscription.unsubscribe();
- this.streamSubscription.unsubscribe();
+ this.valuesSubscription!.unsubscribe();
+ this.streamSubscription!.unsubscribe();
}
}
@@ -873,7 +942,7 @@
-
+
:host {
display: block;
@@ -895,7 +964,7 @@
-
+
diff --git a/docs/components/TemperatureComponent.html b/docs/components/TemperatureComponent.html
index ebbcd4b..0ce1ed6 100644
--- a/docs/components/TemperatureComponent.html
+++ b/docs/components/TemperatureComponent.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -36,29 +94,33 @@
- - Components
- - Components
+ -
TemperatureComponent
-
+
File
@@ -72,12 +134,12 @@
File
Implements
- OnInit
- OnDestroy
+ OnInit
+ OnDestroy
-
+
Metadata
@@ -90,6 +152,7 @@ Metadata
+
providers
@@ -104,21 +167,23 @@ Metadata
+
+
styles
- :host {
- display: block;
- }
- canvas {
- margin-left: -16px;
- }
+ :host {
+ display: block;
+ }
+ canvas {
+ margin-left: -16px;
+ }
+
template
- <canvas #chart width="549" height="180"></canvas>
-
+ <canvas #chart width="549" height="180"></canvas>
@@ -133,7 +198,7 @@ Metadata
-
+
Index
@@ -149,6 +214,7 @@ Properties
chart
+
chartRef
@@ -227,7 +293,7 @@ Accessors
-
+
Constructor
@@ -238,7 +304,7 @@ Constructor
- Defined in src/app/thingy52/temperature.component.ts:48
+ Defined in src/app/thingy52/temperature.component.ts:62
@@ -292,7 +358,7 @@ Constructor
-
+
Methods
@@ -315,21 +381,21 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -352,53 +418,51 @@
-
-
-
-
-
+
+
+
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- error
-
- string
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ error
+
+ string
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
@@ -421,21 +485,21 @@
-
-
- Defined in src/app/thingy52/temperature.component.ts:76
-
-
+
+
+ Defined in src/app/thingy52/temperature.component.ts:85
+
+
-
@@ -458,21 +522,21 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -495,21 +559,21 @@
-
-
- Defined in src/app/thingy52/temperature.component.ts:66
-
-
+
+
+ Defined in src/app/thingy52/temperature.component.ts:76
+
+
-
@@ -532,21 +596,21 @@
-
-
- Defined in src/app/thingy52/temperature.component.ts:97
-
-
+
+
+
+
+
-
@@ -564,64 +628,62 @@
-updateValue(value: number)
+updateValue(value: number | literal type)
-
-
-
-
-
+
+
+
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- value
-
- number
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ value
+
+ number | literal type
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
-
+
Properties
@@ -639,13 +701,18 @@
- Type : SmoothieChart
+ Type : SmoothieChart | null
+
+
+
+ Default value : null
+
- Defined in src/app/thingy52/temperature.component.ts:39
+ Defined in src/app/thingy52/temperature.component.ts:53
@@ -658,6 +725,7 @@
+
chartRef
@@ -665,10 +733,15 @@
- Type : ElementRef<HTMLCanvasElement>
+ Type : ElementRef<HTMLCanvasElement> | null
+
+
+ Default value : null
+
+
Decorators :
@@ -680,7 +753,7 @@
- Defined in src/app/thingy52/temperature.component.ts:44
+ Defined in src/app/thingy52/temperature.component.ts:58
@@ -700,13 +773,18 @@
- Type : TimeSeries
+ Type : TimeSeries | null
+
+
+
+ Default value : null
+
- Defined in src/app/thingy52/temperature.component.ts:38
+ Defined in src/app/thingy52/temperature.component.ts:52
@@ -733,7 +811,7 @@
- Defined in src/app/thingy52/temperature.component.ts:51
+ Defined in src/app/thingy52/temperature.component.ts:64
@@ -760,7 +838,7 @@
- Defined in src/app/thingy52/temperature.component.ts:52
+ Defined in src/app/thingy52/temperature.component.ts:64
@@ -780,13 +858,18 @@
- Type : Subscription
+ Type : Subscription | null
+
+
+
+ Default value : null
+
- Defined in src/app/thingy52/temperature.component.ts:41
+ Defined in src/app/thingy52/temperature.component.ts:55
@@ -806,13 +889,18 @@
- Type : Subscription
+ Type : Subscription | null
+
+
+
+ Default value : null
+
- Defined in src/app/thingy52/temperature.component.ts:40
+ Defined in src/app/thingy52/temperature.component.ts:54
@@ -821,7 +909,7 @@
-
+
Accessors
@@ -841,7 +929,7 @@
- Defined in src/app/thingy52/temperature.component.ts:46
+ Defined in src/app/thingy52/temperature.component.ts:60
@@ -851,60 +939,71 @@
-
- import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
+
+ import {
+ Component,
+ ElementRef,
+ OnDestroy,
+ OnInit,
+ ViewChild,
+} from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
-import { BluetoothCore, BrowserWebBluetooth, ConsoleLoggerService } from '@manekinekko/angular-web-bluetooth';
+import {
+ BluetoothCore,
+ BrowserWebBluetooth,
+ ConsoleLoggerService,
+} from '@manekinekko/angular-web-bluetooth';
import { Subscription } from 'rxjs';
import { SmoothieChart, TimeSeries } from 'smoothie';
import { BleService } from '../ble.service';
-export const bleCore = (b: BrowserWebBluetooth, l: ConsoleLoggerService) => new BluetoothCore(b, l);
+export const bleCore = (b: BrowserWebBluetooth, l: ConsoleLoggerService) =>
+ new BluetoothCore(b, l);
export const bleService = (b: BluetoothCore) => new BleService(b);
-
// make sure we get a singleton instance of each service
-const PROVIDERS = [{
- provide: BluetoothCore,
- useFactory: bleCore,
- deps: [BrowserWebBluetooth, ConsoleLoggerService]
-}, {
- provide: BleService,
- useFactory: bleService,
- deps: [BluetoothCore]
-}];
+const PROVIDERS = [
+ {
+ provide: BluetoothCore,
+ useFactory: bleCore,
+ deps: [BrowserWebBluetooth, ConsoleLoggerService],
+ },
+ {
+ provide: BleService,
+ useFactory: bleService,
+ deps: [BluetoothCore],
+ },
+];
@Component({
selector: 'ble-temperature',
- template: `
- <canvas #chart width="549" height="180"></canvas>
- `,
- styles: [`
- :host {
- display: block;
- }
- canvas {
- margin-left: -16px;
- }`],
- providers: PROVIDERS
+ template: ` <canvas #chart width="549" height="180"></canvas> `,
+ styles: [
+ `
+ :host {
+ display: block;
+ }
+ canvas {
+ margin-left: -16px;
+ }
+ `,
+ ],
+ providers: PROVIDERS,
})
export class TemperatureComponent implements OnInit, OnDestroy {
- series: TimeSeries;
- chart: SmoothieChart;
- valuesSubscription: Subscription;
- streamSubscription: Subscription;
+ series: TimeSeries | null = null;
+ chart: SmoothieChart | null = null;
+ valuesSubscription: Subscription | null = null;
+ streamSubscription: Subscription | null = null;
@ViewChild('chart', { static: true })
- chartRef: ElementRef<HTMLCanvasElement>;
+ chartRef: ElementRef<HTMLCanvasElement> | null = null;
get device() {
return this.service.getDevice();
}
- constructor(
- public service: BleService,
- public snackBar: MatSnackBar) {
-
+ constructor(public service: BleService, public snackBar: MatSnackBar) {
service.config({
characteristic: 'ef680201-9b35-4933-9b10-52ffa9740042',
service: 'ef680200-9b35-4933-9b10-52ffa9740042',
@@ -912,58 +1011,65 @@
const integer = value.getInt8(0);
const decimal = value.getUint8(1);
return integer + decimal / 100;
- }
+ },
});
-
}
ngOnInit() {
this.initChart();
- this.streamSubscription = this.service.stream()
- .subscribe({
- next: (val: number) => this.updateValue(val),
- error: (err) => this.hasError(err)
- });
+ this.streamSubscription = this.service.stream().subscribe({
+ next: (val: number | { [key: string]: number; }) => this.updateValue(val),
+ error: (err) => this.hasError(err),
+ });
}
initChart() {
this.series = new window.TimeSeries() as TimeSeries;
- const canvas = this.chartRef.nativeElement;
+ const canvas = this.chartRef!.nativeElement;
this.chart = new window.SmoothieChart({
interpolation: 'step',
grid: {
fillStyle: '#ffffff',
strokeStyle: 'rgba(119,119,119,0.18)',
- borderVisible: false
+ borderVisible: false,
},
labels: {
fillStyle: '#000000',
- fontSize: 17
+ fontSize: 17,
},
- tooltip: true
+ tooltip: true,
});
- this.chart.addTimeSeries(this.series, { lineWidth: 1, strokeStyle: '#ff0000', fillStyle: 'rgba(255,161,161,0.30)' });
- this.chart.streamTo(canvas);
- this.chart.stop();
+ this.chart!.addTimeSeries(this.series, {
+ lineWidth: 1,
+ strokeStyle: '#ff0000',
+ fillStyle: 'rgba(255,161,161,0.30)',
+ });
+ this.chart!.streamTo(canvas);
+ this.chart!.stop();
}
requestValue() {
- this.valuesSubscription = this.service.value()
- .subscribe(() => null, error => this.hasError.bind(this));
+ this.valuesSubscription = this.service.value().subscribe(
+ () => null,
+ (error) => this.hasError.bind(this)
+ );
}
- updateValue(value: number) {
+ updateValue(value: number | { [key: string]: number; }) {
console.log('Reading temperature %d', value);
- this.series.append(Date.now(), value);
- this.chart.start();
+
+ if (typeof value === 'number') {
+ this.series!.append(Date.now(), value);
+ this.chart!.start();
+ }
}
disconnect() {
this.service.disconnectDevice();
- this.series.clear();
- this.chart.stop();
- this.valuesSubscription.unsubscribe();
+ this.series!.clear();
+ this.chart!.stop();
+ this.valuesSubscription!.unsubscribe();
}
hasError(error: string) {
@@ -971,28 +1077,27 @@
}
ngOnDestroy() {
- this.valuesSubscription.unsubscribe();
- this.streamSubscription.unsubscribe();
+ this.valuesSubscription!.unsubscribe();
+ this.streamSubscription!.unsubscribe();
}
}
-
-
-
+
- :host {
- display: block;
- }
- canvas {
- margin-left: -16px;
- }
+ :host {
+ display: block;
+ }
+ canvas {
+ margin-left: -16px;
+ }
+
-
+
diff --git a/docs/coverage.html b/docs/coverage.html
index f75a68f..145df4c 100644
--- a/docs/coverage.html
+++ b/docs/coverage.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -51,7 +109,7 @@
- - Documentation coverage
+ - Documentation coverage
diff --git a/docs/dependencies.html b/docs/dependencies.html
index 9675659..e3136d6 100644
--- a/docs/dependencies.html
+++ b/docs/dependencies.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -47,7 +105,7 @@
- - Dependencies
+ - Dependencies
-
@@ -71,7 +129,7 @@
-
@angular/router : ^17.1.3
-
- @release-it/conventional-changelog : ^5.1.1
+ @manekinekko/angular-web-bluetooth : file:../../@manekinekko/angular-web-bluetooth/dist/manekinekko/angular-web-bluetooth
-
@types/web-bluetooth : 0.0.6
-
diff --git a/docs/graph/dependencies.svg b/docs/graph/dependencies.svg
index 5d70839..1bb8609 100644
--- a/docs/graph/dependencies.svg
+++ b/docs/graph/dependencies.svg
@@ -1,132 +1,142 @@
-
-
+
+
+
+ Default value : {} as any
+
@@ -461,15 +528,15 @@
-
+
import { Injectable } from '@angular/core';
import { BluetoothCore } from '@manekinekko/angular-web-bluetooth';
-import { map } from 'rxjs/operators';
+import { map, tap } from 'rxjs/operators';
type ServiceOptions = {
characteristic: string;
service: string,
- decoder(value: DataView): number | {[key: string]: number}
+ decoder(value: DataView): number
};
@Injectable({
@@ -478,7 +545,7 @@
export class BleService {
// tslint:disable-next-line: variable-name
- private _config: ServiceOptions;
+ private _config: ServiceOptions = {} as any;
constructor(public ble: BluetoothCore) {}
@@ -492,6 +559,7 @@
stream() {
return this.ble.streamValues$().pipe(
+ tap(value => console.log(value)),
map(this._config.decoder)
);
}
diff --git a/docs/injectables/BluetoothCore.html b/docs/injectables/BluetoothCore.html
index 8d3e8be..5896bf9 100644
--- a/docs/injectables/BluetoothCore.html
+++ b/docs/injectables/BluetoothCore.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -40,21 +98,27 @@
- - Injectables
- - BluetoothCore
+ - Injectables
+ - BluetoothCore
-
- connectDevice(device: BluetoothDevice)
+
+ connectDevice(device: BluetoothDevice | null)
-
-
-
-
-
+
+
+
+
+
- Connect to current device.
+ Connect to current device.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- device
-
- BluetoothDevice
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : unknown
-
-
-
- Emites the gatt server instance of the requested device
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ device
+
+ BluetoothDevice | null
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : unknown
+
+
+
+ Emites the gatt server instance of the requested device
+
+
@@ -351,61 +413,59 @@
-connectDevice$(device: BluetoothDevice)
+connectDevice$(device: BluetoothDevice | null)
-
-
-
-
-
+
+
+
+
+
- Connect to current device.
+ Connect to current device.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- device
-
- BluetoothDevice
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : any
-
-
-
- Emites the gatt server instance of the requested device
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ device
+
+ BluetoothDevice | null
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : any
+
+
+
+ Emites the gatt server instance of the requested device
+
+
@@ -428,91 +488,89 @@
-
-
-
-
-
+
+
+
+
+
- Disables the specified characteristic of a given service.
+ Disables the specified characteristic of a given service.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- service
-
- BluetoothServiceUUID
-
-
-
- No
-
-
-
-
- The parent service of the characteristic.
-
-
-
-
- characteristic
-
- BluetoothCharacteristicUUID
-
-
-
- No
-
-
-
-
- The requested characteristic.
-
-
-
-
- state
-
- any
-
-
-
- Yes
-
-
-
-
-
-
-
-
-
-
-
-
- Returns : Observable<BluetoothRemoteGATTService>
-
-
-
- The primary service (useful for chaining).
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ service
+
+ BluetoothServiceUUID
+
+
+
+ No
+
+
+
+
+ The parent service of the characteristic.
+
+
+
+
+ characteristic
+
+ BluetoothCharacteristicUUID
+
+
+
+ No
+
+
+
+
+ The requested characteristic.
+
+
+
+
+ state
+
+ any
+
+
+
+ Yes
+
+
+
+
+
+
+
+
+
+
+ Returns : Observable<BluetoothRemoteGATTService>
+
+
+
+ The primary service (useful for chaining).
+
+
@@ -535,23 +593,23 @@
-
-
-
-
-
+
+
+
+
+
-
@@ -562,7 +620,7 @@
- Async
+ Async
discover
@@ -570,66 +628,64 @@
-
+
discover(options: RequestDeviceOptions)
-
-
-
-
-
+
+
+
+
+
- Run the discovery process.
+ Run the discovery process.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Default value
-
-
-
-
- options
-
- RequestDeviceOptions
-
-
-
- No
-
-
-
- {} as RequestDeviceOptions
-
-
-
-
-
-
-
-
-
- Returns : Promise<BluetoothDevice>
-
-
-
- The GATT server for the chosen device
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Default value
+
+
+
+
+ options
+
+ RequestDeviceOptions
+
+
+
+ No
+
+
+
+ {} as RequestDeviceOptions
+
+
+
+
+
+
+
+ Returns : Promise<BluetoothDevice | null>
+
+
+
+ The GATT server for the chosen device
+
+
@@ -652,56 +708,54 @@
-
-
-
-
-
+
+
+
+
+
- Run the discovery process.
+ Run the discovery process.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- options
-
- RequestDeviceOptions
-
-
-
- Yes
-
-
-
-
-
-
-
-
-
-
- Returns : Observable<void | BluetoothRemoteGATTServer>
-
-
-
- Emites the value of the requested service read from the device
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ options
+
+ RequestDeviceOptions
+
+
+
+ Yes
+
+
+
+
+
+
+
+
+ Returns : Observable<void | BluetoothRemoteGATTServer | null>
+
+
+
+ Emites the value of the requested service read from the device
+
+
@@ -724,91 +778,89 @@
-
-
-
-
-
+
+
+
+
+
- Enables the specified characteristic of a given service.
+ Enables the specified characteristic of a given service.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- service
-
- BluetoothServiceUUID
-
-
-
- No
-
-
-
-
- The parent service of the characteristic.
-
-
-
-
- characteristic
-
- BluetoothCharacteristicUUID
-
-
-
- No
-
-
-
-
- The requested characteristic
-
-
-
-
- state
-
- any
-
-
-
- Yes
-
-
-
-
-
-
-
-
-
-
-
-
- Returns : Observable<BluetoothRemoteGATTService>
-
-
-
- The primary service (useful for chaining).
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ service
+
+ BluetoothServiceUUID
+
+
+
+ No
+
+
+
+
+ The parent service of the characteristic.
+
+
+
+
+ characteristic
+
+ BluetoothCharacteristicUUID
+
+
+
+ No
+
+
+
+
+ The requested characteristic
+
+
+
+
+ state
+
+ any
+
+
+
+ Yes
+
+
+
+
+
+
+
+
+
+
+ Returns : Observable<BluetoothRemoteGATTService>
+
+
+
+ The primary service (useful for chaining).
+
+
@@ -831,56 +883,54 @@
-
-
-
-
-
+
+
+
+
+
- Sends random data (for testing purposes only).
+ Sends random data (for testing purposes only).
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- fakeValue
-
- function
-
-
-
- Yes
-
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
- Random unsigned 8-bit integer values.
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ fakeValue
+
+ function
+
+
+
+ Yes
+
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+ Random unsigned 8-bit integer values.
+
+
@@ -891,7 +941,7 @@
- Async
+ Async
getCharacteristic
@@ -899,83 +949,81 @@
-
+
getCharacteristic(primaryService: BluetoothRemoteGATTService, characteristic: BluetoothCharacteristicUUID)
-
-
-
-
-
+
+
+
+
+
- Requests a characteristic from the primary service.
+ Requests a characteristic from the primary service.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- primaryService
-
- BluetoothRemoteGATTService
-
-
-
- No
-
-
-
-
- The primary service.
-
-
-
-
- characteristic
-
- BluetoothCharacteristicUUID
-
-
-
- No
-
-
-
-
- The characteristic's UUID.
-
-
-
-
-
-
-
-
-
- Returns : Promise<BluetoothRemoteGATTCharacteristic | void>
-
-
-
- The characteristic description (as a Promise).
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ primaryService
+
+ BluetoothRemoteGATTService
+
+
+
+ No
+
+
+
+
+ The primary service.
+
+
+
+
+ characteristic
+
+ BluetoothCharacteristicUUID
+
+
+
+ No
+
+
+
+
+ The characteristic's UUID.
+
+
+
+
+
+
+
+ Returns : Promise<BluetoothRemoteGATTCharacteristic | null>
+
+
+
+ The characteristic description (as a Promise).
+
+
@@ -998,77 +1046,75 @@
-
-
-
-
-
+
+
+
+
+
- Requests a characteristic from the primary service.
+ Requests a characteristic from the primary service.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- primaryService
-
- BluetoothRemoteGATTService
-
-
-
- No
-
-
-
-
- The primary service.
-
-
-
-
- characteristic
-
- BluetoothCharacteristicUUID
-
-
-
- No
-
-
-
-
- The characteristic's UUID.
-
-
-
-
-
-
-
-
-
- Returns : Observable<void | BluetoothRemoteGATTCharacteristic>
-
-
-
- The characteristic description (as a Observable).
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ primaryService
+
+ BluetoothRemoteGATTService
+
+
+
+ No
+
+
+
+
+ The primary service.
+
+
+
+
+ characteristic
+
+ BluetoothCharacteristicUUID
+
+
+
+ No
+
+
+
+
+ The characteristic's UUID.
+
+
+
+
+
+
+
+ Returns : Observable<null | BluetoothRemoteGATTCharacteristic>
+
+
+
+ The characteristic description (as a Observable).
+
+
@@ -1091,21 +1137,21 @@
-
-
-
-
-
+
+
+
+
+
-
- Returns : Observable<BluetoothDevice>
+
+ Returns : Observable<BluetoothDevice>
-
+
@@ -1128,21 +1174,21 @@
-
-
-
-
-
+
+
+
+
+
-
- Returns : Observable<BluetoothRemoteGATTServer>
+
+ Returns : Observable<BluetoothRemoteGATTServer>
-
+
@@ -1153,7 +1199,7 @@
- Async
+ Async
getPrimaryService
@@ -1161,83 +1207,81 @@
-
- getPrimaryService(gatt: BluetoothRemoteGATTServer, service: BluetoothServiceUUID)
+
+ getPrimaryService(gatt: BluetoothRemoteGATTServer | null, service: BluetoothServiceUUID)
-
-
-
-
-
+
+
+
+
+
- Requests the primary service.
+ Requests the primary service.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- gatt
-
- BluetoothRemoteGATTServer
-
-
-
- No
-
-
-
-
- The BluetoothRemoteGATTServer sever
-
-
-
-
- service
-
- BluetoothServiceUUID
-
-
-
- No
-
-
-
-
- The UUID of the primary service
-
-
-
-
-
-
-
-
-
- Returns : Promise<BluetoothRemoteGATTService>
-
-
-
- The remote service (as a Promise)
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ gatt
+
+ BluetoothRemoteGATTServer | null
+
+
+
+ No
+
+
+
+
+ The BluetoothRemoteGATTServer sever
+
+
+
+
+ service
+
+ BluetoothServiceUUID
+
+
+
+ No
+
+
+
+
+ The UUID of the primary service
+
+
+
+
+
+
+
+ Returns : Promise<BluetoothRemoteGATTService>
+
+
+
+ The remote service (as a Promise)
+
+
@@ -1255,82 +1299,80 @@
-getPrimaryService$(gatt: BluetoothRemoteGATTServer, service: BluetoothServiceUUID)
+getPrimaryService$(gatt: BluetoothRemoteGATTServer | null, service: BluetoothServiceUUID)
-
-
-
-
-
+
+
+
+
+
- Requests the primary service.
+ Requests the primary service.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- gatt
-
- BluetoothRemoteGATTServer
-
-
-
- No
-
-
-
-
- The BluetoothRemoteGATTServer sever
-
-
-
-
- service
-
- BluetoothServiceUUID
-
-
-
- No
-
-
-
-
- The UUID of the primary service
-
-
-
-
-
-
-
-
-
- Returns : Observable<BluetoothRemoteGATTService>
-
-
-
- The remote service (as an observable).
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ gatt
+
+ BluetoothRemoteGATTServer | null
+
+
+
+ No
+
+
+
+
+ The BluetoothRemoteGATTServer sever
+
+
+
+
+ service
+
+ BluetoothServiceUUID
+
+
+
+ No
+
+
+
+
+ The UUID of the primary service
+
+
+
+
+
+
+
+ Returns : Observable<BluetoothRemoteGATTService>
+
+
+
+ The remote service (as an observable).
+
+
@@ -1353,77 +1395,75 @@
-
-
-
-
-
+
+
+
+
+
- A utility method to convert LE to an unsigned 16-bit integer values.
+ A utility method to convert LE to an unsigned 16-bit integer values.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- data
-
- any
-
-
-
- No
-
-
-
-
- The DataView binary data.
-
-
-
-
- byteOffset
-
- number
-
-
-
- No
-
-
-
-
- The offset, in byte, from the start of the view where to read the data.
-
-
-
-
-
-
-
-
-
- Returns : number
-
-
-
- An unsigned 16-bit integer number.
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ data
+
+ any
+
+
+
+ No
+
+
+
+
+ The DataView binary data.
+
+
+
+
+ byteOffset
+
+ number
+
+
+
+ No
+
+
+
+
+ The offset, in byte, from the start of the view where to read the data.
+
+
+
+
+
+
+
+ Returns : number
+
+
+
+ An unsigned 16-bit integer number.
+
+
@@ -1446,77 +1486,75 @@
-
-
-
-
-
+
+
+
+
+
- A utility method to convert LE to an unsigned 8-bit integer values.
+ A utility method to convert LE to an unsigned 8-bit integer values.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- data
-
- any
-
-
-
- No
-
-
-
-
- The DataView binary data.
-
-
-
-
- byteOffset
-
- number
-
-
-
- No
-
-
-
-
- The offset, in byte, from the start of the view where to read the data.
-
-
-
-
-
-
-
-
-
- Returns : number
-
-
-
- An unsigned 8-bit integer number.
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ data
+
+ any
+
+
+
+ No
+
+
+
+
+ The DataView binary data.
+
+
+
+
+ byteOffset
+
+ number
+
+
+
+ No
+
+
+
+
+ The offset, in byte, from the start of the view where to read the data.
+
+
+
+
+
+
+
+ Returns : number
+
+
+
+ An unsigned 8-bit integer number.
+
+
@@ -1539,61 +1577,59 @@
-
-
-
-
-
+
+
+
+
+
- A stream of DataView values emitted by the specified characteristic.
+ A stream of DataView values emitted by the specified characteristic.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- characteristic
-
- BluetoothRemoteGATTCharacteristic
-
-
-
- No
-
-
-
-
- The characteristic which value you want to observe
-
-
-
-
-
-
-
-
-
- Returns : Observable<DataView>
-
-
-
- The stream of DataView values.
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ characteristic
+
+ BluetoothRemoteGATTCharacteristic
+
+
+
+ No
+
+
+
+
+ The characteristic which value you want to observe
+
+
+
+
+
+
+
+ Returns : Observable<DataView>
+
+
+
+ The stream of DataView values.
+
+
@@ -1611,65 +1647,63 @@
-onCharacteristicChanged(event: Event)
+onCharacteristicChanged(event: Event)
-
-
-
-
-
+
+
+
+
+
- Dispatches new values emitted by a characteristic.
+ Dispatches new values emitted by a characteristic.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- event
-
- Event
-
-
-
- No
-
-
-
-
- the distpatched event.
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ event
+
+ Event
+
+
+
+ No
+
+
+
+
+ the distpatched event.
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
@@ -1687,65 +1721,63 @@
-onDeviceDisconnected(event: Event)
+onDeviceDisconnected(event: Event)
-
-
-
-
-
+
+
+
+
+
- This handler will trigger when the client disconnets from the server.
+ This handler will trigger when the client disconnets from the server.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- event
-
- Event
-
-
-
- No
-
-
-
-
- The onDeviceDisconnected event
-
-
-
-
-
-
-
-
-
- Returns : void
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ event
+
+ Event
+
+
+
+ No
+
+
+
+
+ The onDeviceDisconnected event
+
+
+
+
+
+
+
+ Returns : void
+
+
+
+
+
@@ -1768,61 +1800,59 @@
-
-
-
-
-
+
+
+
+
+
- Reads a value from the characteristics, as a DataView.
+ Reads a value from the characteristics, as a DataView.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- characteristic
-
- BluetoothRemoteGATTCharacteristic
-
-
-
- No
-
-
-
-
- The requested characteristic.
-
-
-
-
-
-
-
-
-
- Returns : Observable<DataView>
-
-
-
- the DataView value (as an Observable).
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ characteristic
+
+ BluetoothRemoteGATTCharacteristic
+
+
+
+ No
+
+
+
+
+ The requested characteristic.
+
+
+
+
+
+
+
+ Returns : Observable<DataView>
+
+
+
+ the DataView value (as an Observable).
+
+
@@ -1845,93 +1875,91 @@
-
-
-
-
-
+
+
+
+
+
- Sets the characteristic's state.
+ Sets the characteristic's state.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- service
-
- BluetoothServiceUUID
-
-
-
- No
-
-
-
-
- The parent service of the characteristic.
-
-
-
-
- characteristic
-
- BluetoothCharacteristicUUID
-
-
-
- No
-
-
-
-
- The requested characteristic
-
-
-
-
- state
-
- ArrayBuffer
-
-
-
- No
-
-
-
-
- An ArrayBuffer containing the value of the characteristic.
-
-
-
-
-
-
-
-
-
- Returns : Observable<BluetoothRemoteGATTService>
-
-
-
- The primary service (useful for chaining).
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ service
+
+ BluetoothServiceUUID
+
+
+
+ No
+
+
+
+
+ The parent service of the characteristic.
+
+
+
+
+ characteristic
+
+ BluetoothCharacteristicUUID
+
+
+
+ No
+
+
+
+
+ The requested characteristic
+
+
+
+
+ state
+
+ ArrayBuffer
+
+
+
+ No
+
+
+
+
+ An ArrayBuffer containing the value of the characteristic.
+
+
+
+
+
+
+
+ Returns : Observable<BluetoothRemoteGATTService>
+
+
+
+ The primary service (useful for chaining).
+
+
@@ -1954,21 +1982,21 @@
-
-
-
-
-
+
+
+
+
+
-
- Returns : Observable<DataView>
+
+ Returns : Observable<DataView>
-
+
@@ -1979,7 +2007,7 @@
- Async
+ Async
value
@@ -1987,66 +2015,64 @@
-
+
value(options: ReadValueOptions)
-
-
-
-
-
+
+
+
+
+
- Run the discovery process and read the value form the provided service and characteristic
+ Run the discovery process and read the value form the provided service and characteristic
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- options
-
- ReadValueOptions
-
-
-
- No
-
-
-
-
- the ReadValueOptions
-
-
-
-
-
-
-
-
-
- Returns : unknown
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ options
+
+ ReadValueOptions
+
+
+
+ No
+
+
+
+
+ the ReadValueOptions
+
+
+
+
+
+
+
+ Returns : unknown
+
+
+
+
+
@@ -2069,53 +2095,51 @@
-
-
-
-
-
+
+
+
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- options
-
- ReadValueOptions
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ options
+
+ ReadValueOptions
+
-
- No
-
+
+ No
+
-
-
-
-
-
-
-
- Returns : any
+
+
+
+
+
+ Returns : any
-
-
-
-
+
+
+
+
@@ -2133,88 +2157,86 @@
-writeValue$(characteristic: BluetoothRemoteGATTCharacteristic, value: ArrayBuffer | Uint8Array)
+writeValue$(characteristic: BluetoothRemoteGATTCharacteristic | null, value: ArrayBuffer | Uint8Array)
-
-
-
-
-
+
+
+
+
+
- Writes a value into the specified characteristic.
+ Writes a value into the specified characteristic.
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
- Description
-
-
-
-
- characteristic
-
- BluetoothRemoteGATTCharacteristic
-
-
-
- No
-
-
-
-
- The requested characteristic.
-
-
-
-
- value
-
- ArrayBuffer | Uint8Array
-
-
-
- No
-
-
-
-
- The value to be written (as an ArrayBuffer or Uint8Array).
-
-
-
-
-
-
-
-
-
- Returns : any
-
-
-
- an void Observable.
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+ Description
+
+
+
+
+ characteristic
+
+ BluetoothRemoteGATTCharacteristic | null
+
+
+
+ No
+
+
+
+
+ The requested characteristic.
+
+
+
+
+ value
+
+ ArrayBuffer | Uint8Array
+
+
+
+ No
+
+
+
+
+ The value to be written (as an ArrayBuffer or Uint8Array).
+
+
+
+
+
+
+
+ Returns : any
+
+
+
+ an void Observable.
+
+
-
+
Properties
@@ -2314,7 +2336,7 @@
- Type : BluetoothRemoteGATTServer
+ Type : BluetoothRemoteGATTServer | null
@@ -2332,9 +2354,9 @@
-
+
import { EventEmitter, Injectable } from '@angular/core';
-import { from, fromEvent, Observable, throwError } from 'rxjs';
+import { EMPTY, from, fromEvent, Observable, of, throwError } from 'rxjs';
import { filter, map, mergeMap, takeUntil } from 'rxjs/operators';
import { ConsoleLoggerService } from './logger.service';
import { BrowserWebBluetooth } from './platform/browser';
@@ -2353,7 +2375,7 @@
private device$: EventEmitter<BluetoothDevice>;
private gatt$: EventEmitter<BluetoothRemoteGATTServer>;
private characteristicValueChanges$: EventEmitter<DataView>;
- private gattServer: BluetoothRemoteGATTServer;
+ private gattServer: BluetoothRemoteGATTServer | null;
constructor(private readonly webBle: BrowserWebBluetooth, private readonly console: ConsoleLoggerService) {
@@ -2418,7 +2440,7 @@
return value;
}
catch (error) {
- throw new Error(error);
+ throw new Error(error as any);
}
}
@@ -2432,7 +2454,7 @@
* @param Options such as filters and optional services
* @return The GATT server for the chosen device
*/
- async discover(options: RequestDeviceOptions = {} as RequestDeviceOptions): Promise<BluetoothDevice> {
+ async discover(options: RequestDeviceOptions = {} as RequestDeviceOptions): Promise<BluetoothDevice | null> {
options.optionalServices = options.optionalServices || ['generic_access'];
this.console.log('[BLE::Info] Requesting devices with options %o', options);
@@ -2465,7 +2487,7 @@
const disconnectedDevice = event.target as BluetoothDevice;
this.console.log('[BLE::Info] disconnected device %o', disconnectedDevice);
- this.device$.emit(null);
+ this.device$.emit(undefined);
}
/**
@@ -2474,8 +2496,8 @@
* @param Options such as filters and optional services
* @return Emites the value of the requested service read from the device
*/
- discover$(options?: RequestDeviceOptions): Observable<void | BluetoothRemoteGATTServer> {
- return from(this.discover(options)).pipe(mergeMap((device: BluetoothDevice) => this.connectDevice$(device)));
+ discover$(options?: RequestDeviceOptions): Observable<void | BluetoothRemoteGATTServer | null> {
+ return from(this.discover(options)).pipe(mergeMap((device: BluetoothDevice|null) => this.connectDevice$(device)));
}
/**
@@ -2483,24 +2505,28 @@
*
* @return Emites the gatt server instance of the requested device
*/
- async connectDevice(device: BluetoothDevice) {
- if (device) {
- this.console.log('[BLE::Info] Connecting to Bluetooth Remote GATT Server of %o', device);
-
- try {
- const gattServer = await device.gatt.connect();
- this.gattServer = gattServer;
- this.gatt$.emit(gattServer);
- return gattServer;
- } catch (error) {
- // probably the user has canceled the discovery
- Promise.reject(`${error.message}`);
- this.gatt$.error(`${error.message}`);
- }
- } else {
+ async connectDevice(device: BluetoothDevice | null) {
+
+ if (device === null || typeof device.gatt === "undefined") {
this.console.error('[BLE::Error] Was not able to connect to Bluetooth Remote GATT Server');
this.gatt$.error(null);
+ return null;
+ }
+
+ this.console.log('[BLE::Info] Connecting to Bluetooth Remote GATT Server of %o', device);
+
+ try {
+ const gattServer = await device.gatt.connect();
+ this.gattServer = gattServer;
+ this.gatt$.emit(gattServer);
+ return gattServer;
+ } catch (error: any) {
+ // probably the user has canceled the discovery
+ Promise.reject(`${error.message}`);
+ this.gatt$.error(`${error.message}`);
}
+
+ return null;
}
/**
@@ -2508,7 +2534,7 @@
*
* @return Emites the gatt server instance of the requested device
*/
- connectDevice$(device: BluetoothDevice) {
+ connectDevice$(device: BluetoothDevice | null) {
return from(this.connectDevice(device));
}
@@ -2535,12 +2561,12 @@
* @param service The UUID of the primary service
* @return The remote service (as a Promise)
*/
- async getPrimaryService(gatt: BluetoothRemoteGATTServer, service: BluetoothServiceUUID): Promise<BluetoothRemoteGATTService> {
+ async getPrimaryService(gatt: BluetoothRemoteGATTServer | null, service: BluetoothServiceUUID): Promise<BluetoothRemoteGATTService> {
try {
- const remoteService = await gatt.getPrimaryService(service);
+ const remoteService = await gatt!.getPrimaryService(service);
return await Promise.resolve(remoteService);
}
- catch (error) {
+ catch (error: any) {
return await Promise.reject(`${error.message} (${service})`);
}
}
@@ -2552,7 +2578,7 @@
* @param service The UUID of the primary service
* @return The remote service (as an observable).
*/
- getPrimaryService$(gatt: BluetoothRemoteGATTServer, service: BluetoothServiceUUID): Observable<BluetoothRemoteGATTService> {
+ getPrimaryService$(gatt: BluetoothRemoteGATTServer | null, service: BluetoothServiceUUID): Observable<BluetoothRemoteGATTService> {
this.console.log('[BLE::Info] Getting primary service "%s" (if available) of %o', service, gatt);
@@ -2562,7 +2588,7 @@
);
}
else {
- return throwError(new Error('[BLE::Error] Was not able to connect to the Bluetooth Remote GATT Server'));
+ return throwError(() => new Error('[BLE::Error] Was not able to connect to the Bluetooth Remote GATT Server'));
}
}
@@ -2576,7 +2602,7 @@
async getCharacteristic(
primaryService: BluetoothRemoteGATTService,
characteristic: BluetoothCharacteristicUUID
- ): Promise<BluetoothRemoteGATTCharacteristic | void> {
+ ): Promise<BluetoothRemoteGATTCharacteristic | null> {
this.console.log('[BLE::Info] Getting Characteristic "%s" of %o', characteristic, primaryService);
try {
@@ -2596,8 +2622,10 @@
return char;
}
catch (rejectionError) {
- Promise.reject(`${rejectionError.message} (${characteristic})`);
+ Promise.reject(`${(rejectionError as any).message} (${characteristic})`);
}
+
+ return null;
}
/**
@@ -2610,7 +2638,7 @@
getCharacteristic$(
primaryService: BluetoothRemoteGATTService,
characteristic: BluetoothCharacteristicUUID
- ): Observable<void | BluetoothRemoteGATTCharacteristic> {
+ ): Observable<null | BluetoothRemoteGATTCharacteristic> {
this.console.log('[BLE::Info] Getting Characteristic "%s" of %o', characteristic, primaryService);
return from(this.getCharacteristic(primaryService, characteristic));
@@ -2628,10 +2656,8 @@
const primaryService = this.getPrimaryService$(this.gattServer, service);
primaryService
- // tslint:disable-next-line: variable-name
.pipe(mergeMap((_primaryService: BluetoothRemoteGATTService) => this.getCharacteristic$(_primaryService, characteristic)))
- // tslint:disable-next-line: no-shadowed-variable
- .subscribe((characteristic: BluetoothRemoteGATTCharacteristic) => this.writeValue$(characteristic, state));
+ .subscribe((characteristic: BluetoothRemoteGATTCharacteristic | null) => this.writeValue$(characteristic, state));
return primaryService;
}
@@ -2695,7 +2721,13 @@
* @param value The value to be written (as an ArrayBuffer or Uint8Array).
* @return an void Observable.
*/
- writeValue$(characteristic: BluetoothRemoteGATTCharacteristic, value: ArrayBuffer | Uint8Array) {
+ writeValue$(characteristic: BluetoothRemoteGATTCharacteristic | null, value: ArrayBuffer | Uint8Array) {
+
+ if (characteristic === null) {
+ this.console.error('[BLE::Error] Was not able to write characteristic');
+ return null;
+ }
+
this.console.log('[BLE::Info] Writing Characteristic %o', characteristic);
return from(characteristic.writeValue(value).then(_ => Promise.resolve(), (error: DOMException) => Promise.reject(`${error.message}`)));
@@ -2708,6 +2740,12 @@
* @return The stream of DataView values.
*/
observeValue$(characteristic: BluetoothRemoteGATTCharacteristic): Observable<DataView> {
+
+ if (characteristic === null || typeof characteristic.service === 'undefined') {
+ this.console.error('[BLE::Error] Was not able to read characteristic');
+ return EMPTY;
+ }
+
characteristic.startNotifications();
const disconnected = fromEvent(characteristic.service.device, 'gattserverdisconnected');
return fromEvent(characteristic, 'characteristicvaluechanged')
@@ -2725,7 +2763,6 @@
* @return An unsigned 16-bit integer number.
*/
littleEndianToUint16(data: any, byteOffset: number): number {
- // tslint:disable-next-line:no-bitwise
return (this.littleEndianToUint8(data, byteOffset + 1) << 8) + this.littleEndianToUint8(data, byteOffset);
}
@@ -2749,7 +2786,6 @@
if (fakeValue === undefined) {
fakeValue = () => {
const dv = new DataView(new ArrayBuffer(8));
- // tslint:disable-next-line:no-bitwise
dv.setUint8(0, (Math.random() * 110) | 0);
return dv;
};
diff --git a/docs/injectables/BrowserWebBluetooth.html b/docs/injectables/BrowserWebBluetooth.html
index 79fe8ef..af40905 100644
--- a/docs/injectables/BrowserWebBluetooth.html
+++ b/docs/injectables/BrowserWebBluetooth.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -40,21 +98,27 @@
- - Injectables
- - BrowserWebBluetooth
+ - Injectables
+ - BrowserWebBluetooth
-
+
File
@@ -66,7 +130,7 @@ File
-
+
Index
@@ -109,7 +173,7 @@ Methods
-
+
Constructor
@@ -128,7 +192,7 @@ Constructor
-
+
Methods
@@ -151,59 +215,57 @@
-
-
-
-
-
+
+
+
+
+
-
- Parameters :
-
-
-
-
- Name
- Type
- Optional
-
-
-
-
- options
-
- RequestDeviceOptions
-
-
-
- No
-
-
-
-
-
-
-
-
-
-
- Returns : Promise<BluetoothDevice>
-
-
-
-
-
+
+ Parameters :
+
+
+
+
+ Name
+ Type
+ Optional
+
+
+
+
+ options
+
+ RequestDeviceOptions
+
+
+
+ No
+
+
+
+
+
+
+
+
+ Returns : Promise<BluetoothDevice>
+
+
+
+
+
-
+
Properties
@@ -234,7 +296,7 @@
-
+
import { Injectable } from '@angular/core';
@Injectable()
diff --git a/docs/injectables/ConsoleLoggerService.html b/docs/injectables/ConsoleLoggerService.html
index 1051d0a..7a6f988 100644
--- a/docs/injectables/ConsoleLoggerService.html
+++ b/docs/injectables/ConsoleLoggerService.html
@@ -13,8 +13,66 @@
-
-
+
+
+
@@ -40,21 +98,27 @@
- - Injectables
- - ConsoleLoggerService
+ - Injectables
+ - ConsoleLoggerService
-
+
File
@@ -66,7 +130,7 @@ File
-
+
Index