@stoprocent/noble 1.10.0 → 1.10.2

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/index.d.ts CHANGED
@@ -11,193 +11,201 @@
11
11
 
12
12
  /// <reference types="node" />
13
13
 
14
- import events = require("events");
15
-
16
- /**
17
- * @deprecated
18
- */
19
- export declare function startScanning(callback?: (error?: Error) => void): void;
20
- /**
21
- * @deprecated
22
- */
23
- export declare function startScanning(serviceUUIDs: string[], callback?: (error?: Error) => void): void;
24
- export declare function startScanning(serviceUUIDs?: string[], allowDuplicates?: boolean, callback?: (error?: Error) => void): void;
25
- export declare function startScanningAsync(serviceUUIDs?: string[], allowDuplicates?: boolean): Promise<void>;
26
- export declare function stopScanning(callback?: () => void): void;
27
- export declare function stopScanningAsync(): Promise<void>;
28
- export declare function cancelConnect(peripheralUuid: string, options?: object): void;
29
- export declare function reset(): void;
30
-
31
- export declare function on(event: "stateChange", listener: (state: string) => void): events.EventEmitter;
32
- export declare function on(event: "scanStart", listener: () => void): events.EventEmitter;
33
- export declare function on(event: "scanStop", listener: () => void): events.EventEmitter;
34
- export declare function on(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter;
35
- export declare function on(event: string, listener: Function): events.EventEmitter;
36
-
37
- export declare function once(event: "stateChange", listener: (state: string) => void): events.EventEmitter;
38
- export declare function once(event: "scanStart", listener: () => void): events.EventEmitter;
39
- export declare function once(event: "scanStop", listener: () => void): events.EventEmitter;
40
- export declare function once(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter;
41
- export declare function once(event: string, listener: Function): events.EventEmitter;
42
-
43
- export declare function removeListener(event: "stateChange", listener: (state: string) => void): events.EventEmitter;
44
- export declare function removeListener(event: "scanStart", listener: () => void): events.EventEmitter;
45
- export declare function removeListener(event: "scanStop", listener: () => void): events.EventEmitter;
46
- export declare function removeListener(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter;
47
- export declare function removeListener(event: string, listener: Function): events.EventEmitter;
48
-
49
- export declare function removeAllListeners(event?: string): events.EventEmitter;
50
-
51
- export declare var state: string;
52
-
53
- export var _bindings: any;
54
-
55
- export interface ServicesAndCharacteristics {
56
- services: Service[];
57
- characteristics: Characteristic[];
58
- }
59
14
 
60
- export declare class Peripheral extends events.EventEmitter {
61
- id: string;
62
- uuid: string;
63
- address: string;
64
- addressType: string;
65
- connectable: boolean;
66
- advertisement: Advertisement;
67
- rssi: number;
68
- services: Service[];
69
- state: 'error' | 'connecting' | 'connected' | 'disconnecting' | 'disconnected';
70
-
71
- connect(callback?: (error: string) => void): void;
72
- connectAsync(): Promise<void>;
73
- disconnect(callback?: () => void): void;
74
- disconnectAsync(): Promise<void>;
75
- updateRssi(callback?: (error: string, rssi: number) => void): void;
76
- updateRssiAsync(): Promise<number>;
77
- discoverServices(): void;
78
- discoverServicesAsync(): Promise<Service[]>;
79
- discoverServices(serviceUUIDs: string[], callback?: (error: string, services: Service[]) => void): void;
80
- discoverServicesAsync(serviceUUIDs: string[]): Promise<Service[]>;
81
- discoverAllServicesAndCharacteristics(callback?: (error: string, services: Service[], characteristics: Characteristic[]) => void): void;
82
- discoverAllServicesAndCharacteristicsAsync(): Promise<ServicesAndCharacteristics>;
83
- discoverSomeServicesAndCharacteristics(serviceUUIDs: string[], characteristicUUIDs: string[], callback?: (error: string, services: Service[], characteristics: Characteristic[]) => void): void;
84
- discoverSomeServicesAndCharacteristicsAsync(serviceUUIDs: string[], characteristicUUIDs: string[]): Promise<ServicesAndCharacteristics>;
85
- cancelConnect(options?: object): void;
86
-
87
- readHandle(handle: number, callback: (error: string, data: Buffer) => void): void;
88
- readHandleAsync(handle: number): Promise<Buffer>;
89
- writeHandle(handle: number, data: Buffer, withoutResponse: boolean, callback: (error: string) => void): void;
90
- writeHandleAsync(handle: number, data: Buffer, withoutResponse: boolean): Promise<void>;
91
- toString(): string;
92
-
93
- on(event: "connect", listener: (error: string) => void): this;
94
- on(event: "disconnect", listener: (error: string) => void): this;
95
- on(event: "rssiUpdate", listener: (rssi: number) => void): this;
96
- on(event: "servicesDiscover", listener: (services: Service[]) => void): this;
97
- on(event: string, listener: Function): this;
98
-
99
- once(event: "connect", listener: (error: string) => void): this;
100
- once(event: "disconnect", listener: (error: string) => void): this;
101
- once(event: "rssiUpdate", listener: (rssi: number) => void): this;
102
- once(event: "servicesDiscover", listener: (services: Service[]) => void): this;
103
- once(event: string, listener: Function): this;
104
- }
105
15
 
106
- export interface Advertisement {
107
- localName: string;
108
- serviceData: Array<{
109
- uuid: string,
110
- data: Buffer
111
- }>;
112
- txPowerLevel: number;
113
- manufacturerData: Buffer;
114
- serviceUuids: string[];
115
- }
116
-
117
- export declare class Service extends events.EventEmitter {
118
- uuid: string;
119
- name: string;
120
- type: string;
121
- includedServiceUuids: string[];
122
- characteristics: Characteristic[];
123
-
124
- discoverIncludedServices(): void;
125
- discoverIncludedServicesAsync(): Promise<string[]>;
126
- discoverIncludedServices(serviceUUIDs: string[], callback?: (error: string, includedServiceUuids: string[]) => void): void;
127
- discoverIncludedServicesAsync(serviceUUIDs: string[]): Promise<string[]>;
128
- discoverCharacteristics(): void;
129
- discoverCharacteristicsAsync(): Promise<Characteristic[]>;
130
- discoverCharacteristics(characteristicUUIDs: string[], callback?: (error: string, characteristics: Characteristic[]) => void): void;
131
- discoverCharacteristicsAsync(characteristicUUIDs: string[]): Promise<Characteristic[]>;
132
- toString(): string;
133
-
134
- on(event: "includedServicesDiscover", listener: (includedServiceUuids: string[]) => void): this;
135
- on(event: "characteristicsDiscover", listener: (characteristics: Characteristic[]) => void): this;
136
- on(event: string, listener: Function): this;
137
-
138
- once(event: "includedServicesDiscover", listener: (includedServiceUuids: string[]) => void): this;
139
- once(event: "characteristicsDiscover", listener: (characteristics: Characteristic[]) => void): this;
140
- once(event: string, listener: Function): this;
141
- }
142
-
143
- export declare class Characteristic extends events.EventEmitter {
144
- uuid: string;
145
- name: string;
146
- type: string;
147
- properties: string[];
148
- descriptors: Descriptor[];
149
-
150
- read(callback?: (error: string, data: Buffer) => void): void;
151
- readAsync(): Promise<Buffer>;
152
- write(data: Buffer, withoutResponse: boolean, callback?: (error: string) => void): void;
153
- writeAsync(data: Buffer, withoutResponse: boolean): Promise<void>;
154
- broadcast(broadcast: boolean, callback?: (error: string) => void): void;
155
- broadcastAsync(broadcast: boolean): Promise<void>;
156
- notify(notify: boolean, callback?: (error: string) => void): void;
157
- notifyAsync(notify: boolean): Promise<void>;
158
- discoverDescriptors(callback?: (error: string, descriptors: Descriptor[]) => void): void;
159
- discoverDescriptorsAsync(): Promise<Descriptor[]>;
160
- toString(): string;
161
- subscribe(callback?: (error: string) => void): void;
162
- subscribeAsync(): Promise<void>;
163
- unsubscribe(callback?: (error: string) => void): void;
164
- unsubscribeAsync(): Promise<void>;
165
-
166
- on(event: "read", listener: (data: Buffer, isNotification: boolean) => void): this;
167
- on(event: "write", withoutResponse: boolean, listener: (error: string) => void): this;
168
- on(event: "broadcast", listener: (state: string) => void): this;
169
- on(event: "notify", listener: (state: string) => void): this;
170
- on(event: "data", listener: (data: Buffer, isNotification: boolean) => void): this;
171
- on(event: "descriptorsDiscover", listener: (descriptors: Descriptor[]) => void): this;
172
- on(event: string, listener: Function): this;
173
- on(event: string, option: boolean, listener: Function): this;
174
-
175
- once(event: "read", listener: (data: Buffer, isNotification: boolean) => void): this;
176
- once(event: "write", withoutResponse: boolean, listener: (error: string) => void): this;
177
- once(event: "broadcast", listener: (state: string) => void): this;
178
- once(event: "notify", listener: (state: string) => void): this;
179
- once(event: "data", listener: (data: Buffer, isNotification: boolean) => void): this;
180
- once(event: "descriptorsDiscover", listener: (descriptors: Descriptor[]) => void): this;
181
- once(event: string, listener: Function): this;
182
- once(event: string, option: boolean, listener: Function): this;
183
- }
184
-
185
- export declare class Descriptor extends events.EventEmitter {
186
- uuid: string;
187
- name: string;
188
- type: string;
189
-
190
- readValue(callback?: (error: string, data: Buffer) => void): void;
191
- readValueAsync(): Promise<Buffer>;
192
- writeValue(data: Buffer, callback?: (error: string) => void): void;
193
- writeValueAsync(data: Buffer): Promise<void>;
194
- toString(): string;
195
-
196
- on(event: "valueRead", listener: (error: string, data: Buffer) => void): this;
197
- on(event: "valueWrite", listener: (error: string) => void): this;
198
- on(event: string, listener: Function): this;
16
+ import events = require("events");
199
17
 
200
- once(event: "valueRead", listener: (error: string, data: Buffer) => void): this;
201
- once(event: "valueWrite", listener: (error: string) => void): this;
202
- once(event: string, listener: Function): this;
18
+ declare function noble(option?: any);
19
+
20
+ declare namespace noble
21
+ {
22
+ /**
23
+ * @deprecated
24
+ */
25
+ export function startScanning(callback?: (error?: Error) => void): void;
26
+ /**
27
+ * @deprecated
28
+ */
29
+ export function startScanning(serviceUUIDs: string[], callback?: (error?: Error) => void): void;
30
+ export function startScanning(serviceUUIDs?: string[], allowDuplicates?: boolean, callback?: (error?: Error) => void): void;
31
+ export function startScanningAsync(serviceUUIDs?: string[], allowDuplicates?: boolean): Promise<void>;
32
+ export function stopScanning(callback?: () => void): void;
33
+ export function stopScanningAsync(): Promise<void>;
34
+ export function cancelConnect(peripheralUuid: string, options?: object): void;
35
+ export function reset(): void;
36
+
37
+ export function on(event: "stateChange", listener: (state: string) => void): events.EventEmitter;
38
+ export function on(event: "scanStart", listener: () => void): events.EventEmitter;
39
+ export function on(event: "scanStop", listener: () => void): events.EventEmitter;
40
+ export function on(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter;
41
+ export function on(event: string, listener: Function): events.EventEmitter;
42
+
43
+ export function once(event: "stateChange", listener: (state: string) => void): events.EventEmitter;
44
+ export function once(event: "scanStart", listener: () => void): events.EventEmitter;
45
+ export function once(event: "scanStop", listener: () => void): events.EventEmitter;
46
+ export function once(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter;
47
+ export function once(event: string, listener: Function): events.EventEmitter;
48
+
49
+ export function removeListener(event: "stateChange", listener: (state: string) => void): events.EventEmitter;
50
+ export function removeListener(event: "scanStart", listener: () => void): events.EventEmitter;
51
+ export function removeListener(event: "scanStop", listener: () => void): events.EventEmitter;
52
+ export function removeListener(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter;
53
+ export function removeListener(event: string, listener: Function): events.EventEmitter;
54
+
55
+ export function removeAllListeners(event?: string): events.EventEmitter;
56
+
57
+ export var state: string;
58
+
59
+ export var _bindings: any;
60
+
61
+ export interface ServicesAndCharacteristics {
62
+ services: Service[];
63
+ characteristics: Characteristic[];
64
+ }
65
+
66
+ export class Peripheral extends events.EventEmitter {
67
+ id: string;
68
+ uuid: string;
69
+ address: string;
70
+ addressType: string;
71
+ connectable: boolean;
72
+ advertisement: Advertisement;
73
+ rssi: number;
74
+ services: Service[];
75
+ state: 'error' | 'connecting' | 'connected' | 'disconnecting' | 'disconnected';
76
+
77
+ connect(callback?: (error: string) => void): void;
78
+ connectAsync(): Promise<void>;
79
+ disconnect(callback?: () => void): void;
80
+ disconnectAsync(): Promise<void>;
81
+ updateRssi(callback?: (error: string, rssi: number) => void): void;
82
+ updateRssiAsync(): Promise<number>;
83
+ discoverServices(): void;
84
+ discoverServicesAsync(): Promise<Service[]>;
85
+ discoverServices(serviceUUIDs: string[], callback?: (error: string, services: Service[]) => void): void;
86
+ discoverServicesAsync(serviceUUIDs: string[]): Promise<Service[]>;
87
+ discoverAllServicesAndCharacteristics(callback?: (error: string, services: Service[], characteristics: Characteristic[]) => void): void;
88
+ discoverAllServicesAndCharacteristicsAsync(): Promise<ServicesAndCharacteristics>;
89
+ discoverSomeServicesAndCharacteristics(serviceUUIDs: string[], characteristicUUIDs: string[], callback?: (error: string, services: Service[], characteristics: Characteristic[]) => void): void;
90
+ discoverSomeServicesAndCharacteristicsAsync(serviceUUIDs: string[], characteristicUUIDs: string[]): Promise<ServicesAndCharacteristics>;
91
+ cancelConnect(options?: object): void;
92
+
93
+ readHandle(handle: number, callback: (error: string, data: Buffer) => void): void;
94
+ readHandleAsync(handle: number): Promise<Buffer>;
95
+ writeHandle(handle: number, data: Buffer, withoutResponse: boolean, callback: (error: string) => void): void;
96
+ writeHandleAsync(handle: number, data: Buffer, withoutResponse: boolean): Promise<void>;
97
+ toString(): string;
98
+
99
+ on(event: "connect", listener: (error: string) => void): this;
100
+ on(event: "disconnect", listener: (error: string) => void): this;
101
+ on(event: "rssiUpdate", listener: (rssi: number) => void): this;
102
+ on(event: "servicesDiscover", listener: (services: Service[]) => void): this;
103
+ on(event: string, listener: Function): this;
104
+
105
+ once(event: "connect", listener: (error: string) => void): this;
106
+ once(event: "disconnect", listener: (error: string) => void): this;
107
+ once(event: "rssiUpdate", listener: (rssi: number) => void): this;
108
+ once(event: "servicesDiscover", listener: (services: Service[]) => void): this;
109
+ once(event: string, listener: Function): this;
110
+ }
111
+
112
+ export interface Advertisement {
113
+ localName: string;
114
+ serviceData: Array<{
115
+ uuid: string,
116
+ data: Buffer
117
+ }>;
118
+ txPowerLevel: number;
119
+ manufacturerData: Buffer;
120
+ serviceUuids: string[];
121
+ }
122
+
123
+ export class Service extends events.EventEmitter {
124
+ uuid: string;
125
+ name: string;
126
+ type: string;
127
+ includedServiceUuids: string[];
128
+ characteristics: Characteristic[];
129
+
130
+ discoverIncludedServices(): void;
131
+ discoverIncludedServicesAsync(): Promise<string[]>;
132
+ discoverIncludedServices(serviceUUIDs: string[], callback?: (error: string, includedServiceUuids: string[]) => void): void;
133
+ discoverIncludedServicesAsync(serviceUUIDs: string[]): Promise<string[]>;
134
+ discoverCharacteristics(): void;
135
+ discoverCharacteristicsAsync(): Promise<Characteristic[]>;
136
+ discoverCharacteristics(characteristicUUIDs: string[], callback?: (error: string, characteristics: Characteristic[]) => void): void;
137
+ discoverCharacteristicsAsync(characteristicUUIDs: string[]): Promise<Characteristic[]>;
138
+ toString(): string;
139
+
140
+ on(event: "includedServicesDiscover", listener: (includedServiceUuids: string[]) => void): this;
141
+ on(event: "characteristicsDiscover", listener: (characteristics: Characteristic[]) => void): this;
142
+ on(event: string, listener: Function): this;
143
+
144
+ once(event: "includedServicesDiscover", listener: (includedServiceUuids: string[]) => void): this;
145
+ once(event: "characteristicsDiscover", listener: (characteristics: Characteristic[]) => void): this;
146
+ once(event: string, listener: Function): this;
147
+ }
148
+
149
+ export class Characteristic extends events.EventEmitter {
150
+ uuid: string;
151
+ name: string;
152
+ type: string;
153
+ properties: string[];
154
+ descriptors: Descriptor[];
155
+
156
+ read(callback?: (error: string, data: Buffer) => void): void;
157
+ readAsync(): Promise<Buffer>;
158
+ write(data: Buffer, withoutResponse: boolean, callback?: (error: string) => void): void;
159
+ writeAsync(data: Buffer, withoutResponse: boolean): Promise<void>;
160
+ broadcast(broadcast: boolean, callback?: (error: string) => void): void;
161
+ broadcastAsync(broadcast: boolean): Promise<void>;
162
+ notify(notify: boolean, callback?: (error: string) => void): void;
163
+ notifyAsync(notify: boolean): Promise<void>;
164
+ discoverDescriptors(callback?: (error: string, descriptors: Descriptor[]) => void): void;
165
+ discoverDescriptorsAsync(): Promise<Descriptor[]>;
166
+ toString(): string;
167
+ subscribe(callback?: (error: string) => void): void;
168
+ subscribeAsync(): Promise<void>;
169
+ unsubscribe(callback?: (error: string) => void): void;
170
+ unsubscribeAsync(): Promise<void>;
171
+
172
+ on(event: "read", listener: (data: Buffer, isNotification: boolean) => void): this;
173
+ on(event: "write", withoutResponse: boolean, listener: (error: string) => void): this;
174
+ on(event: "broadcast", listener: (state: string) => void): this;
175
+ on(event: "notify", listener: (state: string) => void): this;
176
+ on(event: "data", listener: (data: Buffer, isNotification: boolean) => void): this;
177
+ on(event: "descriptorsDiscover", listener: (descriptors: Descriptor[]) => void): this;
178
+ on(event: string, listener: Function): this;
179
+ on(event: string, option: boolean, listener: Function): this;
180
+
181
+ once(event: "read", listener: (data: Buffer, isNotification: boolean) => void): this;
182
+ once(event: "write", withoutResponse: boolean, listener: (error: string) => void): this;
183
+ once(event: "broadcast", listener: (state: string) => void): this;
184
+ once(event: "notify", listener: (state: string) => void): this;
185
+ once(event: "data", listener: (data: Buffer, isNotification: boolean) => void): this;
186
+ once(event: "descriptorsDiscover", listener: (descriptors: Descriptor[]) => void): this;
187
+ once(event: string, listener: Function): this;
188
+ once(event: string, option: boolean, listener: Function): this;
189
+ }
190
+
191
+ export class Descriptor extends events.EventEmitter {
192
+ uuid: string;
193
+ name: string;
194
+ type: string;
195
+
196
+ readValue(callback?: (error: string, data: Buffer) => void): void;
197
+ readValueAsync(): Promise<Buffer>;
198
+ writeValue(data: Buffer, callback?: (error: string) => void): void;
199
+ writeValueAsync(data: Buffer): Promise<void>;
200
+ toString(): string;
201
+
202
+ on(event: "valueRead", listener: (error: string, data: Buffer) => void): this;
203
+ on(event: "valueWrite", listener: (error: string) => void): this;
204
+ on(event: string, listener: Function): this;
205
+
206
+ once(event: "valueRead", listener: (error: string, data: Buffer) => void): this;
207
+ once(event: "valueWrite", listener: (error: string) => void): this;
208
+ once(event: string, listener: Function): this;
209
+ }
203
210
  }
211
+ export = noble;
@@ -4,7 +4,7 @@ const events = require('events');
4
4
  const util = require('util');
5
5
 
6
6
  const async = require('async');
7
- const SerialPort = require('serialport');
7
+ const { SerialPort } = require('serialport');
8
8
  const HciSerialParser = require('./hci-serial-parser');
9
9
 
10
10
  const HCI_COMMAND_PKT = 0x01;
@@ -144,7 +144,8 @@ Hci.STATUS_MAPPER = STATUS_MAPPER;
144
144
 
145
145
  Hci.prototype.init = function (options) {
146
146
  // Create Serial Port
147
- this._socket = new SerialPort(process.env.NOBLE_HCI_UART_PORT || undefined, {
147
+ this._socket = new SerialPort({
148
+ path: process.env.NOBLE_HCI_UART_PORT || undefined,
148
149
  baudRate: parseInt(process.env.NOBLE_HCI_UART_BAUD_RATE) || 1000000,
149
150
  autoOpen: false,
150
151
  flowControl: true
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "license": "MIT",
8
8
  "name": "@stoprocent/noble",
9
9
  "description": "A Node.js BLE (Bluetooth Low Energy) central library.",
10
- "version": "1.10.0",
10
+ "version": "1.10.2",
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/stoprocent/noble.git"