wot-ble-client-factory 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,21 +12,35 @@ npm install wot-ble-client-factory @node-wot/core
12
12
  ```
13
13
 
14
14
  ## Minimal Setup
15
+
16
+ #### GATT
17
+ ```js
18
+ const { Servient } = require("@node-wot/core");
19
+ const { BluetoothGATTClientFactory } = require("wot-ble-client-factory");
20
+
21
+ const servient = new Servient();
22
+ servient.addClientFactory(new BluetoothGATTClientFactory());
23
+ ```
24
+
25
+ #### GAP
15
26
  ```js
16
27
  const { Servient } = require("@node-wot/core");
17
- const { BluetoothClientFactory } = require("wot-ble-client-factory");
28
+ const { BluetoothGapClientFactory } = require("wot-ble-client-factory");
18
29
 
19
30
  const servient = new Servient();
20
- servient.addClientFactory(new BluetoothClientFactory());
31
+ servient.addClientFactory(new BluetoothGapClientFactory());
21
32
  ```
22
33
 
23
34
  Check the `examples` folder for more complete Thing Descriptions.
24
35
 
25
- ## Protocol specifier
36
+ To enable debug logs run with this command:
37
+ ```bash
38
+ DEBUG=binding-Bluetooth node example.js
39
+ ```
26
40
 
27
- The protocol prefix handled by this binding is <code>gatt://</code>.
41
+ ## Protocol Specifier
28
42
 
29
- A planned protocol prefix is <code>gap://</code>.
43
+ The protocol prefix handled by this binding is <code>gatt://</code> and <code>gap://</code>.
30
44
 
31
45
  ## Getting Started
32
46
  If you want to build this package locally:
@@ -35,8 +49,19 @@ git clone git@github.com:wintechis/Bluetooth-Bindings.git
35
49
  cd Bluetooth-Bindings
36
50
  npm install
37
51
  npm run build
52
+ ```
53
+
54
+ For local development you can use yalc:
55
+ ```
56
+ npm install -g yalc
57
+ ./publish_yalc.sh
58
+ ```
38
59
 
60
+ If the library code has been updated run:
39
61
  ```
62
+ ./update_yalc.sh
63
+ ```
64
+
40
65
  Then you can run the examples:
41
66
 
42
67
  ```
@@ -49,7 +74,7 @@ node examples/govee_lamp.js
49
74
  In order to align a new protocol into the WoT context, the required abstract WoT operations must first be mapped to the concrete operations of the new protocol.
50
75
  A distinction must be made between the two GATT methods write and write-without-response. Both are capable of writing WoT resources, but the two methods differ in that write expects a confirmation message from the server after a write operation, while write-without-response requires no such confirmation. Thus the GATT method chosen depends on the implementation of the attribute in the GATT server.
51
76
 
52
- | WoT Operation | BLE GATT Method |
77
+ | WoT Operation | BLE GATT Method |
53
78
  | -------------- | -------------------------- |
54
79
  | readproperty | read |
55
80
  | writeproperty | write / write-w/o-response |
@@ -64,9 +89,13 @@ It has the following structure:
64
89
  ```
65
90
  gatt://<MAC>/<service>/<characteristic>
66
91
  ```
92
+ or
93
+ ```
94
+ gap://<MAC>
95
+ ```
67
96
 
68
97
  with the following meaning:
69
- - `gatt` Identification of the transfer protocol
98
+ - `gatt` or `gap` Identification of the transfer protocol
70
99
  - `<MAC>` MAC address of the Bluetooth device
71
100
  - `<service>` GATT service containing the characteristic
72
101
  - `<characteristic>` GATT characteristic to interact with
@@ -80,15 +109,16 @@ For the Bluetooth LE bindings, we chose the new, non-standard subtype `x.binary-
80
109
  The Binary Data Ontology (bdo) is intended to provide maximum flexibility and describe all kinds of binary data.
81
110
  We want to use the bdo ontology to describe the data transmitted by Bluetooth LE devices, even those that do not comply with the Bluetooth standard. The terms of the vocabulary are in our use case only useful within the properties, actions, or events parts of a Thing Description because they contain information about the data that is needed in the codec associated with application/x.binary-data-stream.
82
111
 
83
- | Vocabulary term | Description | Assignment | Type | Default Value |
84
- | --------------- | ------------------------------------------- | ------------------------------- | ------- | ---------------- |
85
- | bdo:bytelength | Number of octets in the data | required | integer | None |
86
- | bdo:signed | Indicates if the data is signed | required | boolean | false |
87
- | bdo:endianess | Byte order of the binary data | required | string | bdo:littleEndian |
88
- | bdo:scale | Scale of received integer value | optional | float | 1.0 |
89
- | bdo:offset | Offset in number of octets | optional | integer | 0 |
90
- | bdo:pattern | The byte pattern of the binary data | optional | string | None |
91
- | bdo:variable | Description of the variables in bdo:pattern | required if bdo:pattern is used | --- | None |
112
+ | Vocabulary term | Description | Assignment | Type | Default Value |
113
+ | --------------- | ------------------------------------------------ | ------------------------------- | ------- | ---------------- |
114
+ | bdo:bytelength | Number of octets in the data | required | integer | None |
115
+ | bdo:signed | Indicates if the data is signed | required | boolean | false |
116
+ | bdo:byteOrder | Byte order of the binary data | required | string | bdo:littleEndian |
117
+ | bdo:scale | Scale of received integer value (multiplicaiton) | optional | float | 1.0 |
118
+ | bdo:valueAdd | Scale of received integer value (addition) | optional | float | 0 |
119
+ | bdo:offset | Offset in number of octets | optional | integer | 0 |
120
+ | bdo:pattern | The byte pattern of the binary data | optional | string | None |
121
+ | bdo:variables | Description of the variables in bdo:pattern | required if bdo:pattern is used | --- | None |
92
122
 
93
123
  ### Simple Bluetooth Ontology
94
124
  The communication and metadata of a Bluetooth Low Energy device is described using the Simple Bluetooth Ontology with preferred prefix sbo.
@@ -1,11 +1,16 @@
1
- /**
2
- * Bluetooth protocol binding
3
- */
4
- import { ProtocolClientFactory, ProtocolClient, ContentSerdes } from '@node-wot/core';
5
- export default class BluetoothClientFactory implements ProtocolClientFactory {
1
+ import { ProtocolClientFactory, ProtocolClient } from '@node-wot/core';
2
+ export declare class BluetoothGATTClientFactory implements ProtocolClientFactory {
6
3
  readonly scheme: string;
7
- contentSerdes: ContentSerdes;
8
4
  constructor();
5
+ private registerCodec;
6
+ getClient(): ProtocolClient;
7
+ init: () => boolean;
8
+ destroy: () => boolean;
9
+ }
10
+ export declare class BluetoothGapClientFactory implements ProtocolClientFactory {
11
+ readonly scheme: string;
12
+ constructor();
13
+ private registerCodec;
9
14
  getClient(): ProtocolClient;
10
15
  init: () => boolean;
11
16
  destroy: () => boolean;
@@ -3,24 +3,49 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- /**
7
- * Bluetooth protocol binding
8
- */
6
+ exports.BluetoothGapClientFactory = exports.BluetoothGATTClientFactory = void 0;
9
7
  const core_1 = require("@node-wot/core");
10
- const Bluetooth_client_js_1 = __importDefault(require("./Bluetooth-client.js"));
8
+ const Bluetooth_gatt_client_js_1 = __importDefault(require("./Bluetooth-gatt-client.js"));
9
+ const Bluetooth_gap_client_js_1 = __importDefault(require("./Bluetooth-gap-client.js"));
11
10
  const codec_js_1 = require("./codec.js");
12
- class BluetoothClientFactory {
11
+ const debug_1 = __importDefault(require("debug"));
12
+ const log = (0, debug_1.default)('binding-Bluetooth');
13
+ class BluetoothGATTClientFactory {
13
14
  scheme = 'gatt';
14
- contentSerdes = core_1.ContentSerdes.get();
15
15
  constructor() {
16
- this.contentSerdes.addCodec(new codec_js_1.BLEBinaryCodec());
16
+ this.registerCodec();
17
+ }
18
+ registerCodec() {
19
+ const cs = core_1.ContentSerdes.get();
20
+ if (!cs.getSupportedMediaTypes().includes('application/x.binary-data-stream')) {
21
+ cs.addCodec(new codec_js_1.BLEBinaryCodec());
22
+ log('Registered BLEBinaryCodec for "application/x.binary-data-stream"');
23
+ }
24
+ }
25
+ getClient() {
26
+ return new Bluetooth_gatt_client_js_1.default();
27
+ }
28
+ init = () => true;
29
+ destroy = () => true;
30
+ }
31
+ exports.BluetoothGATTClientFactory = BluetoothGATTClientFactory;
32
+ class BluetoothGapClientFactory {
33
+ scheme = 'gap';
34
+ constructor() {
35
+ this.registerCodec();
36
+ }
37
+ registerCodec() {
38
+ const cs = core_1.ContentSerdes.get();
39
+ if (!cs.getSupportedMediaTypes().includes('application/x.binary-data-stream')) {
40
+ cs.addCodec(new codec_js_1.BLEBinaryCodec());
41
+ log('Registered BLEBinaryCodec for "application/x.binary-data-stream"');
42
+ }
17
43
  }
18
44
  getClient() {
19
- console.debug('[binding-Bluetooth]', `BluetoothClientFactory creating client for ${this.scheme}`);
20
- return new Bluetooth_client_js_1.default();
45
+ return new Bluetooth_gap_client_js_1.default();
21
46
  }
22
47
  init = () => true;
23
48
  destroy = () => true;
24
49
  }
25
- exports.default = BluetoothClientFactory;
50
+ exports.BluetoothGapClientFactory = BluetoothGapClientFactory;
26
51
  //# sourceMappingURL=Bluetooth-client-factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Bluetooth-client-factory.js","sourceRoot":"","sources":["../src/Bluetooth-client-factory.ts"],"names":[],"mappings":";;;;;AAAA;;GAEG;AACH,yCAIwB;AACxB,gFAAoD;AACpD,yCAA0C;AAE1C,MAAqB,sBAAsB;IACzB,MAAM,GAAW,MAAM,CAAC;IAEjC,aAAa,GAAkB,oBAAa,CAAC,GAAG,EAAE,CAAC;IAE1D;QACE,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,yBAAc,EAAE,CAAC,CAAC;IACpD,CAAC;IAEM,SAAS;QACd,OAAO,CAAC,KAAK,CACX,qBAAqB,EACrB,8CAA8C,IAAI,CAAC,MAAM,EAAE,CAC5D,CAAC;QACF,OAAO,IAAI,6BAAe,EAAE,CAAC;IAC/B,CAAC;IAEM,IAAI,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC;IAC3B,OAAO,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC;CACtC;AAnBD,yCAmBC"}
1
+ {"version":3,"file":"Bluetooth-client-factory.js","sourceRoot":"","sources":["../src/Bluetooth-client-factory.ts"],"names":[],"mappings":";;;;;;AAAA,yCAIwB;AACxB,0FAAyD;AACzD,wFAA2D;AAC3D,yCAA4C;AAC5C,kDAA0B;AAE1B,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,mBAAmB,CAAC,CAAC;AAEvC,MAAa,0BAA0B;IACrB,MAAM,GAAW,MAAM,CAAC;IAExC;QACE,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAEO,aAAa;QACnB,MAAM,EAAE,GAAG,oBAAa,CAAC,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC,sBAAsB,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC,EAAE,CAAC;YAC7E,EAAE,CAAC,QAAQ,CAAC,IAAI,yBAAc,EAAE,CAAC,CAAC;YAClC,GAAG,CAAC,kEAAkE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,kCAAe,EAAE,CAAC;IAC/B,CAAC;IAEM,IAAI,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC;IAC3B,OAAO,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC;CACtC;AArBD,gEAqBC;AAED,MAAa,yBAAyB;IACpB,MAAM,GAAW,KAAK,CAAC;IAEvC;QACE,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IACO,aAAa;QACnB,MAAM,EAAE,GAAG,oBAAa,CAAC,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,EAAE,CAAC,sBAAsB,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC,EAAE,CAAC;YAC7E,EAAE,CAAC,QAAQ,CAAC,IAAI,yBAAc,EAAE,CAAC,CAAC;YAClC,GAAG,CAAC,kEAAkE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,iCAAkB,EAAE,CAAC;IAClC,CAAC;IAEM,IAAI,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC;IAC3B,OAAO,GAAG,GAAY,EAAE,CAAC,IAAI,CAAC;CACtC;AApBD,8DAoBC"}
@@ -0,0 +1,14 @@
1
+ import { Content, ProtocolClient } from '@node-wot/core';
2
+ import type { Form, SecurityScheme } from 'wot-thing-description-types';
3
+ export default class BluetoothGapClient implements ProtocolClient {
4
+ toString(): string;
5
+ readResource(form: Form): Promise<Content>;
6
+ writeResource(form: Form, content?: Content): Promise<void>;
7
+ invokeResource(form: Form, content?: Content): Promise<Content>;
8
+ unlinkResource(form: Form): Promise<void>;
9
+ subscribeResource(form: Form, next: (content: Content) => void, error?: (error: Error) => void, complete?: () => void): Promise<any>;
10
+ start(): Promise<void>;
11
+ stop(): Promise<void>;
12
+ setSecurity(_metadata: SecurityScheme[], _credentials?: unknown): boolean;
13
+ requestThingDescription(uri: string): Promise<Content>;
14
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const stream_1 = require("stream");
40
+ const debug_1 = __importDefault(require("debug"));
41
+ const BLELibCore = __importStar(require("./bluetooth/Bluetooth_lib"));
42
+ const log = (0, debug_1.default)('binding-Bluetooth-GAP');
43
+ // --- Helper Functions ---
44
+ function fromObject(data) {
45
+ const json = JSON.stringify(data);
46
+ return {
47
+ type: 'application/json',
48
+ body: stream_1.Readable.from(json),
49
+ async toBuffer() {
50
+ return Buffer.from(json);
51
+ },
52
+ };
53
+ }
54
+ // Add this function here:
55
+ function fromBuffer(type, buf) {
56
+ return {
57
+ type,
58
+ body: stream_1.Readable.from(buf),
59
+ async toBuffer() {
60
+ return buf;
61
+ },
62
+ };
63
+ }
64
+ // --- Class Definition ---
65
+ class BluetoothGapClient {
66
+ toString() {
67
+ return '[BluetoothGapClient]';
68
+ }
69
+ async readResource(form) {
70
+ // Parse URL
71
+ // Expected formats:
72
+ // - gap://<mac>
73
+ // - gap://<mac>/manufacturerData (Auto-select first)
74
+ // - gap://<mac>/manufacturerData/<id> (Select specific)
75
+ const path = form.href.split('//')[1];
76
+ const parts = path.split('/');
77
+ let deviceId = parts[0];
78
+ let resource = parts[1] ?? "manufacturerData";
79
+ const companyIdStr = parts[2]; // Optional
80
+ deviceId = deviceId.toUpperCase().replaceAll('-', ':');
81
+ if (resource !== 'manufacturerData') {
82
+ throw new Error(`[BluetoothGapClient] Only 'manufacturerData' is supported.`);
83
+ }
84
+ log(`invoke read GAP on ${deviceId}`);
85
+ // Fetch all data
86
+ const dataEntries = await BLELibCore.getDeviceManufacturerData(deviceId);
87
+ if (dataEntries.length === 0) {
88
+ throw new Error(`No manufacturer data found on ${deviceId}`);
89
+ }
90
+ // LOGIC: Auto-select or Specific Select
91
+ let selectedEntry;
92
+ if (companyIdStr) {
93
+ // Case A: ID specified in URL (e.g. 0x0499)
94
+ const companyId = companyIdStr.startsWith('0x')
95
+ ? parseInt(companyIdStr, 16)
96
+ : parseInt(companyIdStr, 10);
97
+ selectedEntry = dataEntries.find(e => e.companyId === companyId);
98
+ if (!selectedEntry) {
99
+ throw new Error(`Company ID ${companyIdStr} not found in advertisements.`);
100
+ }
101
+ }
102
+ else {
103
+ // Case B: No ID specified -> Auto-select the first one
104
+ selectedEntry = dataEntries[0];
105
+ log(`Auto-selected Manufacturer ID: 0x${selectedEntry.companyId.toString(16)}`);
106
+ }
107
+ // Return Data based on Content-Type
108
+ // If the TD expects binary (for the Codec), return the Buffer directly.
109
+ // If the TD expects JSON (debugging), return the simplified object.
110
+ if (form.contentType === 'application/json') {
111
+ // Return the simplified object info if JSON is requested
112
+ return fromObject(selectedEntry);
113
+ }
114
+ else {
115
+ // Default / Binary: Return the RAW BUFFER so the Codec can parse it
116
+ return fromBuffer(form.contentType || 'application/x.binary-data-stream', selectedEntry.data);
117
+ }
118
+ }
119
+ async writeResource(form, content) {
120
+ throw new Error('Method not implemented for GAP.');
121
+ }
122
+ async invokeResource(form, content) {
123
+ throw new Error('Method not implemented for GAP.');
124
+ }
125
+ async unlinkResource(form) {
126
+ throw new Error('Method not implemented for GAP.');
127
+ }
128
+ async subscribeResource(form, next, error, complete) {
129
+ throw new Error('Subscribe not yet implemented for GAP.');
130
+ }
131
+ async start() {
132
+ // no-op
133
+ }
134
+ async stop() {
135
+ // no-op
136
+ }
137
+ setSecurity(_metadata, _credentials) {
138
+ return false;
139
+ }
140
+ // --- ADDED THIS METHOD TO FIX ERROR 1 & 2 ---
141
+ async requestThingDescription(uri) {
142
+ throw new Error('requestThingDescription not supported by BluetoothGapClient');
143
+ }
144
+ }
145
+ exports.default = BluetoothGapClient;
146
+ //# sourceMappingURL=Bluetooth-gap-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Bluetooth-gap-client.js","sourceRoot":"","sources":["../src/Bluetooth-gap-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,mCAAkC;AAClC,kDAA0B;AAC1B,sEAAwD;AAExD,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,uBAAuB,CAAC,CAAC;AAE3C,2BAA2B;AAE3B,SAAS,UAAU,CAAC,IAAS;IAC3B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAClC,OAAO;QACL,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U,EAAE,OAAiB;QACtD,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,IAAU,EAAE,OAAiB;QACvD,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,IAAU;QACpC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IAEM,KAAK,CAAC,iBAAiB,CAC5B,IAAU,EACV,IAAgC,EAChC,KAA8B,EAC9B,QAAqB;QAErB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,QAAQ;IACV,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,QAAQ;IACV,CAAC;IAEM,WAAW,CAAC,SAA2B,EAAE,YAAsB;QACpE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,+CAA+C;IACxC,KAAK,CAAC,uBAAuB,CAAC,GAAW;QAC7C,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IAClF,CAAC;CACF;AAzGD,qCAyGC"}
@@ -1,6 +1,8 @@
1
1
  import { Content, ProtocolClient } from '@node-wot/core';
2
2
  import { Subscription } from 'rxjs/Subscription';
3
3
  import type { Form, SecurityScheme } from 'wot-thing-description-types';
4
+ export declare function enableAutoDisconnect(): void;
5
+ export declare function disableAutoDisconnect(): void;
4
6
  export declare const deconstructForm: (form: Form) => Record<string, any>;
5
7
  export default class BluetoothClient implements ProtocolClient {
6
8
  toString(): string;
@@ -32,12 +32,28 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
39
  exports.deconstructForm = void 0;
40
+ exports.enableAutoDisconnect = enableAutoDisconnect;
41
+ exports.disableAutoDisconnect = disableAutoDisconnect;
37
42
  const core_1 = require("@node-wot/core");
38
43
  const Subscription_1 = require("rxjs/Subscription");
39
44
  const stream_1 = require("stream");
45
+ const debug_1 = __importDefault(require("debug"));
40
46
  const BLELibCore = __importStar(require("./bluetooth/Bluetooth_lib"));
47
+ // If conenction should be closed automatically
48
+ let autoDisconnect = true;
49
+ function enableAutoDisconnect() {
50
+ autoDisconnect = true;
51
+ }
52
+ function disableAutoDisconnect() {
53
+ autoDisconnect = false;
54
+ }
55
+ // Create a logger with a specific namespace
56
+ const log = (0, debug_1.default)('binding-Bluetooth');
41
57
  function asBle(form) {
42
58
  return form;
43
59
  }
@@ -98,7 +114,8 @@ class BluetoothClient {
98
114
  async readResource(form) {
99
115
  const deconstructedForm = (0, exports.deconstructForm)(form);
100
116
  await BLELibCore.connect(deconstructedForm.deviceId);
101
- console.debug('[binding-Bluetooth]', `invoke read operation on characteristic ${deconstructedForm.characteristicId}` +
117
+ BLELibCore.touchConnection(deconstructedForm.deviceId);
118
+ log(`invoke read operation on characteristic ${deconstructedForm.characteristicId}` +
102
119
  ` from service ${deconstructedForm.serviceId} on ${deconstructedForm.deviceId}`);
103
120
  // Get Characteristic
104
121
  const characteristic = await BLELibCore.getCharacteristic(deconstructedForm.deviceId, deconstructedForm.serviceId, deconstructedForm.characteristicId);
@@ -111,7 +128,10 @@ class BluetoothClient {
111
128
  console.error(error);
112
129
  throw new Error(`Error reading from Bluetooth device ${deconstructedForm.characteristicId}`);
113
130
  }
114
- await BLELibCore.close();
131
+ if (autoDisconnect) {
132
+ // disconnect on idle (handled inside BLELibCore timers)
133
+ BLELibCore.touchConnection(deconstructedForm.deviceId);
134
+ }
115
135
  // Return proper Content (with toBuffer)
116
136
  return fromBuffer(deconstructedForm.contentType || 'application/x.binary-data-stream', buffer);
117
137
  }
@@ -121,23 +141,43 @@ class BluetoothClient {
121
141
  async writeResource(form, content) {
122
142
  const deconstructedForm = (0, exports.deconstructForm)(form);
123
143
  await BLELibCore.connect(deconstructedForm.deviceId);
144
+ BLELibCore.touchConnection(deconstructedForm.deviceId);
124
145
  // Convert content -> Buffer
125
146
  let buffer;
126
147
  if (content) {
127
- // prefer the canonical method available on node-wot Content
148
+ // 1) If node-wot gives you a canonical helper, use it
128
149
  if (typeof content.toBuffer === 'function') {
129
150
  buffer = await content.toBuffer();
130
151
  }
131
152
  else {
153
+ // 2) Manually read the body and preserve Buffers as-is
132
154
  const chunks = [];
133
155
  for await (const chunk of content.body) {
134
- chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
156
+ if (Buffer.isBuffer(chunk)) {
157
+ chunks.push(chunk); // already a Buffer → keep as-is
158
+ }
159
+ else if (typeof chunk === 'string') {
160
+ chunks.push(Buffer.from(chunk, 'utf8'));
161
+ }
162
+ else {
163
+ // covers Uint8Array, Array<number>, etc.
164
+ chunks.push(Buffer.from(chunk));
165
+ }
166
+ }
167
+ // If there was exactly one Buffer, just use it directly
168
+ if (chunks.length === 0) {
169
+ buffer = Buffer.alloc(0);
170
+ }
171
+ else if (chunks.length === 1) {
172
+ buffer = chunks[0];
173
+ }
174
+ else {
175
+ buffer = Buffer.concat(chunks);
135
176
  }
136
- buffer = Buffer.concat(chunks);
137
177
  }
138
178
  }
139
179
  else {
140
- // If content not defined write buffer < 00 >
180
+ // If content not defined write buffer <00>
141
181
  buffer = Buffer.alloc(1);
142
182
  }
143
183
  // Get Characteristic
@@ -145,13 +185,13 @@ class BluetoothClient {
145
185
  // Select what operation should be executed
146
186
  switch (deconstructedForm.ble_operation) {
147
187
  case 'sbo:write':
148
- console.debug('[binding-Bluetooth]', `invoke write operation on characteristic ${deconstructedForm.characteristicId}` +
188
+ log(`invoke write operation on characteristic ${deconstructedForm.characteristicId}` +
149
189
  ` from service ${deconstructedForm.serviceId} on ${deconstructedForm.deviceId}`);
150
190
  // write value with response
151
191
  await characteristic.writeValue(buffer, { offset: 0, type: 'request' });
152
192
  break;
153
193
  case 'sbo:write-without-response':
154
- console.debug('[binding-Bluetooth]', `invoke write-without-response operation on characteristic ${deconstructedForm.characteristicId}` +
194
+ log(`invoke write-without-response operation on characteristic ${deconstructedForm.characteristicId}` +
155
195
  ` from service ${deconstructedForm.serviceId} on ${deconstructedForm.deviceId}`);
156
196
  // write value without response
157
197
  await characteristic.writeValue(buffer, { offset: 0, type: 'command' });
@@ -160,7 +200,9 @@ class BluetoothClient {
160
200
  throw new Error(`[binding-Bluetooth] unknown operation ${deconstructedForm.operation}`);
161
201
  }
162
202
  }
163
- await BLELibCore.close();
203
+ if (autoDisconnect) {
204
+ BLELibCore.touchConnection(deconstructedForm.deviceId);
205
+ }
164
206
  }
165
207
  /**
166
208
  * Invokes an action (write + trivial response)
@@ -175,7 +217,7 @@ class BluetoothClient {
175
217
  }
176
218
  async unlinkResource(form) {
177
219
  const deconstructedForm = (0, exports.deconstructForm)(form);
178
- console.debug('[binding-Bluetooth]', `unsubscribing from characteristic with serviceId ${deconstructedForm.serviceId} characteristicId ` +
220
+ log(`unsubscribing from characteristic with serviceId ${deconstructedForm.serviceId} characteristicId ` +
179
221
  `${deconstructedForm.characteristicId} on ${deconstructedForm.deviceId}`);
180
222
  const characteristic = await BLELibCore.getCharacteristic(deconstructedForm.deviceId, deconstructedForm.serviceId, deconstructedForm.characteristicId);
181
223
  await characteristic.stopNotifications();
@@ -185,10 +227,12 @@ class BluetoothClient {
185
227
  */
186
228
  async subscribeResource(form, next, error, complete) {
187
229
  const deconstructedForm = (0, exports.deconstructForm)(form);
230
+ await BLELibCore.connect(deconstructedForm.deviceId);
231
+ BLELibCore.holdConnection(deconstructedForm.deviceId);
188
232
  if (deconstructedForm.ble_operation !== 'sbo:notify') {
189
233
  throw new Error(`[binding-Bluetooth] operation ${deconstructedForm.ble_operation} is not supported`);
190
234
  }
191
- console.debug('[binding-Bluetooth]', `subscribing to characteristic with serviceId ${deconstructedForm.serviceId} ` +
235
+ log(`subscribing to characteristic with serviceId ${deconstructedForm.serviceId} ` +
192
236
  `characteristicId ${deconstructedForm.characteristicId}`);
193
237
  const characteristic = await BLELibCore.getCharacteristic(deconstructedForm.deviceId, deconstructedForm.serviceId, deconstructedForm.characteristicId);
194
238
  await characteristic.startNotifications();
@@ -213,9 +257,11 @@ class BluetoothClient {
213
257
  void characteristic
214
258
  .stopNotifications()
215
259
  .then(() => {
260
+ BLELibCore.releaseConnection(deconstructedForm.deviceId);
216
261
  complete?.();
217
262
  })
218
263
  .catch((e) => {
264
+ BLELibCore.releaseConnection(deconstructedForm.deviceId);
219
265
  error?.(e);
220
266
  });
221
267
  });
@@ -235,4 +281,4 @@ class BluetoothClient {
235
281
  }
236
282
  }
237
283
  exports.default = BluetoothClient;
238
- //# sourceMappingURL=Bluetooth-client.js.map
284
+ //# sourceMappingURL=Bluetooth-gatt-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Bluetooth-gatt-client.js","sourceRoot":"","sources":["../src/Bluetooth-gatt-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,oDAEC;AAED,sDAEC;AAhBD,yCAA0E;AAC1E,oDAAiD;AAEjD,mCAAkC;AAClC,kDAA0B;AAC1B,sEAAwD;AAExD,+CAA+C;AAC/C,IAAI,cAAc,GAAG,IAAI,CAAC;AAE1B,SAAgB,oBAAoB;IAClC,cAAc,GAAG,IAAI,CAAC;AACxB,CAAC;AAED,SAAgB,qBAAqB;IACnC,cAAc,GAAG,KAAK,CAAC;AACzB,CAAC;AAED,4CAA4C;AAC5C,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,mBAAmB,CAAC,CAAC;AASvC,SAAS,KAAK,CAAC,IAAU;IACvB,OAAO,IAAwB,CAAC;AAClC,CAAC;AAED,SAAS,UAAU,CAAC,IAAY,EAAE,GAAW;IAC3C,OAAO;QACL,IAAI;QACJ,IAAI,EAAE,iBAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;QACxB,KAAK,CA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,EAAE,CAAC;gBAChB,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;YACb,CAAC;QACH,CAAC,CAAC;QAEF,cAAc,CAAC,EAAE,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAE3C,+CAA+C;QAC/C,MAAM,GAAG,GAAG,IAAI,2BAAY,EAAE,CAAC;QAC/B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE;YACX,kBAAkB;YAClB,cAAc,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;YAC9C,KAAK,cAAc;iBAChB,iBAAiB,EAAE;iBACnB,IAAI,CAAC,GAAG,EAAE;gBACT,UAAU,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;gBACzD,QAAQ,EAAE,EAAE,CAAC;YACf,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE;gBAChB,UAAU,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;gBACzD,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;YACb,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,QAAQ;IACV,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,QAAQ;IACV,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,GAAW;QACvC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IAEM,WAAW,CAChB,SAA2B,EAC3B,YAAsB;QAEtB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAxPD,kCAwPC"}
@@ -1,6 +1,7 @@
1
1
  import { Form } from "@node-wot/core";
2
- export { default as BluetoothClient } from './Bluetooth-client.js';
3
- export { default as BluetoothClientFactory } from './Bluetooth-client-factory.js';
2
+ export { default as BluetoothClient } from './Bluetooth-gatt-client.js';
3
+ export { BluetoothGATTClientFactory } from './Bluetooth-client-factory.js';
4
+ export { BluetoothGapClientFactory } from './Bluetooth-client-factory.js';
4
5
  export declare class BluetoothForm extends Form {
5
6
  'wbt:id': string;
6
7
  'datatype': string;
package/dist/Bluetooth.js CHANGED
@@ -3,12 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BluetoothForm = exports.BluetoothClientFactory = exports.BluetoothClient = void 0;
6
+ exports.BluetoothForm = exports.BluetoothGapClientFactory = exports.BluetoothGATTClientFactory = exports.BluetoothClient = void 0;
7
7
  const core_1 = require("@node-wot/core");
8
- var Bluetooth_client_js_1 = require("./Bluetooth-client.js");
9
- Object.defineProperty(exports, "BluetoothClient", { enumerable: true, get: function () { return __importDefault(Bluetooth_client_js_1).default; } });
8
+ var Bluetooth_gatt_client_js_1 = require("./Bluetooth-gatt-client.js");
9
+ Object.defineProperty(exports, "BluetoothClient", { enumerable: true, get: function () { return __importDefault(Bluetooth_gatt_client_js_1).default; } });
10
+ // Export the default (GATT) factory as expected by legacy code
10
11
  var Bluetooth_client_factory_js_1 = require("./Bluetooth-client-factory.js");
11
- Object.defineProperty(exports, "BluetoothClientFactory", { enumerable: true, get: function () { return __importDefault(Bluetooth_client_factory_js_1).default; } });
12
+ Object.defineProperty(exports, "BluetoothGATTClientFactory", { enumerable: true, get: function () { return Bluetooth_client_factory_js_1.BluetoothGATTClientFactory; } });
13
+ // Also export the GAP factory so it can be used
14
+ var Bluetooth_client_factory_js_2 = require("./Bluetooth-client-factory.js");
15
+ Object.defineProperty(exports, "BluetoothGapClientFactory", { enumerable: true, get: function () { return Bluetooth_client_factory_js_2.BluetoothGapClientFactory; } });
12
16
  class BluetoothForm extends core_1.Form {
13
17
  'wbt:id';
14
18
  'datatype';
@@ -1 +1 @@
1
- {"version":3,"file":"Bluetooth.js","sourceRoot":"","sources":["../src/Bluetooth.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAsC;AAEtC,6DAAiE;AAAzD,uIAAA,OAAO,OAAmB;AAClC,6EAAgF;AAAxE,sJAAA,OAAO,OAA0B;AAEzC,MAAa,aAAc,SAAQ,WAAI;IAC9B,QAAQ,CAAS;IACjB,UAAU,CAAS;CAC3B;AAHD,sCAGC"}
1
+ {"version":3,"file":"Bluetooth.js","sourceRoot":"","sources":["../src/Bluetooth.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAsC;AAEtC,uEAAwE;AAA/D,4IAAA,OAAO,OAAmB;AACnC,+DAA+D;AAC/D,6EAA2E;AAAlE,yIAAA,0BAA0B,OAAA;AAEnC,gDAAgD;AAChD,6EAA0E;AAAjE,wIAAA,yBAAyB,OAAA;AAElC,MAAa,aAAc,SAAQ,WAAI;IAC9B,QAAQ,CAAS;IACjB,UAAU,CAAS;CAC3B;AAHD,sCAGC"}