@stoprocent/noble 1.9.2-16
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/.editorconfig +11 -0
- package/.eslintrc.js +25 -0
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/fediverse-action.yml +16 -0
- package/.github/workflows/nodepackage.yml +77 -0
- package/.github/workflows/npm-publish.yml +26 -0
- package/.github/workflows/prebuild.yml +65 -0
- package/.nycrc.json +4 -0
- package/CHANGELOG.md +119 -0
- package/LICENSE +20 -0
- package/MAINTAINERS.md +1 -0
- package/README.md +833 -0
- package/assets/noble-logo.png +0 -0
- package/assets/noble-logo.svg +13 -0
- package/binding.gyp +19 -0
- package/codecov.yml +5 -0
- package/examples/advertisement-discovery.js +65 -0
- package/examples/cache-gatt-discovery.js +198 -0
- package/examples/cache-gatt-reconnect.js +164 -0
- package/examples/echo.js +104 -0
- package/examples/enter-exit.js +78 -0
- package/examples/peripheral-explorer-async.js +133 -0
- package/examples/peripheral-explorer.js +225 -0
- package/examples/pizza/README.md +15 -0
- package/examples/pizza/central.js +194 -0
- package/examples/pizza/pizza.js +60 -0
- package/index.d.ts +203 -0
- package/index.js +6 -0
- package/lib/characteristic.js +161 -0
- package/lib/characteristics.json +449 -0
- package/lib/descriptor.js +72 -0
- package/lib/descriptors.json +47 -0
- package/lib/distributed/bindings.js +326 -0
- package/lib/hci-socket/acl-stream.js +60 -0
- package/lib/hci-socket/bindings.js +788 -0
- package/lib/hci-socket/crypto.js +74 -0
- package/lib/hci-socket/gap.js +432 -0
- package/lib/hci-socket/gatt.js +809 -0
- package/lib/hci-socket/hci-status.json +71 -0
- package/lib/hci-socket/hci.js +1264 -0
- package/lib/hci-socket/signaling.js +76 -0
- package/lib/hci-socket/smp.js +140 -0
- package/lib/hci-uart/bindings.js +569 -0
- package/lib/hci-uart/hci-serial-parser.js +70 -0
- package/lib/hci-uart/hci.js +1336 -0
- package/lib/mac/binding.gyp +26 -0
- package/lib/mac/bindings.js +11 -0
- package/lib/mac/src/ble_manager.h +41 -0
- package/lib/mac/src/ble_manager.mm +435 -0
- package/lib/mac/src/callbacks.cc +222 -0
- package/lib/mac/src/callbacks.h +84 -0
- package/lib/mac/src/napi_objc.h +12 -0
- package/lib/mac/src/napi_objc.mm +50 -0
- package/lib/mac/src/noble_mac.h +34 -0
- package/lib/mac/src/noble_mac.mm +264 -0
- package/lib/mac/src/objc_cpp.h +26 -0
- package/lib/mac/src/objc_cpp.mm +126 -0
- package/lib/mac/src/peripheral.h +23 -0
- package/lib/manufacture.js +48 -0
- package/lib/noble.js +593 -0
- package/lib/peripheral.js +219 -0
- package/lib/resolve-bindings-web.js +9 -0
- package/lib/resolve-bindings.js +44 -0
- package/lib/service.js +72 -0
- package/lib/services.json +92 -0
- package/lib/webbluetooth/bindings.js +368 -0
- package/lib/websocket/bindings.js +321 -0
- package/lib/win/binding.gyp +23 -0
- package/lib/win/bindings.js +11 -0
- package/lib/win/src/ble_manager.cc +802 -0
- package/lib/win/src/ble_manager.h +77 -0
- package/lib/win/src/callbacks.cc +274 -0
- package/lib/win/src/callbacks.h +33 -0
- package/lib/win/src/napi_winrt.cc +76 -0
- package/lib/win/src/napi_winrt.h +12 -0
- package/lib/win/src/noble_winrt.cc +308 -0
- package/lib/win/src/noble_winrt.h +34 -0
- package/lib/win/src/notify_map.cc +62 -0
- package/lib/win/src/notify_map.h +50 -0
- package/lib/win/src/peripheral.h +23 -0
- package/lib/win/src/peripheral_winrt.cc +296 -0
- package/lib/win/src/peripheral_winrt.h +82 -0
- package/lib/win/src/radio_watcher.cc +125 -0
- package/lib/win/src/radio_watcher.h +61 -0
- package/lib/win/src/winrt_cpp.cc +82 -0
- package/lib/win/src/winrt_cpp.h +11 -0
- package/lib/win/src/winrt_guid.cc +12 -0
- package/lib/win/src/winrt_guid.h +13 -0
- package/misc/nrf52840dk.hex +6921 -0
- package/misc/prj.conf +43 -0
- package/package.json +96 -0
- package/test/lib/characteristic.test.js +791 -0
- package/test/lib/descriptor.test.js +249 -0
- package/test/lib/distributed/bindings.test.js +918 -0
- package/test/lib/hci-socket/acl-stream.test.js +188 -0
- package/test/lib/hci-socket/bindings.test.js +1756 -0
- package/test/lib/hci-socket/crypto.test.js +55 -0
- package/test/lib/hci-socket/gap.test.js +1089 -0
- package/test/lib/hci-socket/gatt.test.js +2392 -0
- package/test/lib/hci-socket/hci.test.js +1891 -0
- package/test/lib/hci-socket/signaling.test.js +94 -0
- package/test/lib/hci-socket/smp.test.js +268 -0
- package/test/lib/manufacture.test.js +77 -0
- package/test/lib/peripheral.test.js +623 -0
- package/test/lib/resolve-bindings.test.js +102 -0
- package/test/lib/service.test.js +195 -0
- package/test/lib/webbluetooth/bindings.test.js +190 -0
- package/test/lib/websocket/bindings.test.js +456 -0
- package/test/noble.test.js +1565 -0
- package/test.js +131 -0
- package/with-bindings.js +5 -0
- package/ws-slave.js +404 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Type definitions for noble
|
|
2
|
+
// Project: https://github.com/sandeepmistry/noble
|
|
3
|
+
// Definitions by: Seon-Wook Park <https://github.com/swook>
|
|
4
|
+
// Shantanu Bhadoria <https://github.com/shantanubhadoria>
|
|
5
|
+
// Luke Libraro <https://github.com/lukel99>
|
|
6
|
+
// Dan Chao <https://github.com/bioball>
|
|
7
|
+
// Michal Lower <https://github.com/keton>
|
|
8
|
+
// Rob Moran <https://github.com/thegecko>
|
|
9
|
+
// Clayton Kucera <https://github.com/claytonkucera>
|
|
10
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
11
|
+
|
|
12
|
+
/// <reference types="node" />
|
|
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
|
+
|
|
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
|
+
|
|
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;
|
|
199
|
+
|
|
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;
|
|
203
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
const events = require('events');
|
|
2
|
+
const util = require('util');
|
|
3
|
+
|
|
4
|
+
const characteristics = require('./characteristics.json');
|
|
5
|
+
|
|
6
|
+
function Characteristic (noble, peripheralId, serviceUuid, uuid, properties) {
|
|
7
|
+
this._noble = noble;
|
|
8
|
+
this._peripheralId = peripheralId;
|
|
9
|
+
this._serviceUuid = serviceUuid;
|
|
10
|
+
|
|
11
|
+
this.uuid = uuid;
|
|
12
|
+
this.name = null;
|
|
13
|
+
this.type = null;
|
|
14
|
+
this.properties = properties;
|
|
15
|
+
this.descriptors = null;
|
|
16
|
+
|
|
17
|
+
const characteristic = characteristics[uuid];
|
|
18
|
+
if (characteristic) {
|
|
19
|
+
this.name = characteristic.name;
|
|
20
|
+
this.type = characteristic.type;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
util.inherits(Characteristic, events.EventEmitter);
|
|
25
|
+
|
|
26
|
+
Characteristic.prototype.toString = function () {
|
|
27
|
+
return JSON.stringify({
|
|
28
|
+
uuid: this.uuid,
|
|
29
|
+
name: this.name,
|
|
30
|
+
type: this.type,
|
|
31
|
+
properties: this.properties
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const read = function (callback) {
|
|
36
|
+
if (callback) {
|
|
37
|
+
const onRead = (data, isNotification) => {
|
|
38
|
+
// only call the callback if 'read' event and non-notification
|
|
39
|
+
// 'read' for non-notifications is only present for backwards compatbility
|
|
40
|
+
if (!isNotification) {
|
|
41
|
+
// remove the listener
|
|
42
|
+
this.removeListener('read', onRead);
|
|
43
|
+
|
|
44
|
+
// call the callback
|
|
45
|
+
callback(null, data);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
this.on('read', onRead);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this._noble.read(
|
|
53
|
+
this._peripheralId,
|
|
54
|
+
this._serviceUuid,
|
|
55
|
+
this.uuid
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
Characteristic.prototype.read = read;
|
|
60
|
+
Characteristic.prototype.readAsync = util.promisify(read);
|
|
61
|
+
|
|
62
|
+
const write = function (data, withoutResponse, callback) {
|
|
63
|
+
if (process.title !== 'browser') {
|
|
64
|
+
const allowedTypes = [
|
|
65
|
+
Buffer,
|
|
66
|
+
Uint8Array,
|
|
67
|
+
Uint16Array,
|
|
68
|
+
Uint32Array
|
|
69
|
+
];
|
|
70
|
+
if (!allowedTypes.some((allowedType) => data instanceof allowedType)) {
|
|
71
|
+
throw new Error(`data must be a ${allowedTypes.map((allowedType) => allowedType.name).join(' or ')}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (callback) {
|
|
76
|
+
this.once('write', () => {
|
|
77
|
+
callback(null);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this._noble.write(
|
|
82
|
+
this._peripheralId,
|
|
83
|
+
this._serviceUuid,
|
|
84
|
+
this.uuid,
|
|
85
|
+
data,
|
|
86
|
+
withoutResponse
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
Characteristic.prototype.write = write;
|
|
91
|
+
Characteristic.prototype.writeAsync = util.promisify(write);
|
|
92
|
+
|
|
93
|
+
const broadcast = function (broadcast, callback) {
|
|
94
|
+
if (callback) {
|
|
95
|
+
this.once('broadcast', () => {
|
|
96
|
+
callback(null);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this._noble.broadcast(
|
|
101
|
+
this._peripheralId,
|
|
102
|
+
this._serviceUuid,
|
|
103
|
+
this.uuid,
|
|
104
|
+
broadcast
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
Characteristic.prototype.broadcast = broadcast;
|
|
109
|
+
Characteristic.prototype.broadcastAsync = util.promisify(broadcast);
|
|
110
|
+
|
|
111
|
+
// deprecated in favour of subscribe/unsubscribe
|
|
112
|
+
const notify = function (notify, callback) {
|
|
113
|
+
if (callback) {
|
|
114
|
+
this.once('notify', () => {
|
|
115
|
+
callback(null);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this._noble.notify(
|
|
120
|
+
this._peripheralId,
|
|
121
|
+
this._serviceUuid,
|
|
122
|
+
this.uuid,
|
|
123
|
+
notify
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
Characteristic.prototype.notify = notify;
|
|
128
|
+
Characteristic.prototype.notifyAsync = util.promisify(notify);
|
|
129
|
+
|
|
130
|
+
const subscribe = function (callback) {
|
|
131
|
+
this.notify(true, callback);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
Characteristic.prototype.subscribe = subscribe;
|
|
135
|
+
Characteristic.prototype.subscribeAsync = util.promisify(subscribe);
|
|
136
|
+
|
|
137
|
+
const unsubscribe = function (callback) {
|
|
138
|
+
this.notify(false, callback);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
Characteristic.prototype.unsubscribe = unsubscribe;
|
|
142
|
+
Characteristic.prototype.unsubscribeAsync = util.promisify(unsubscribe);
|
|
143
|
+
|
|
144
|
+
const discoverDescriptors = function (callback) {
|
|
145
|
+
if (callback) {
|
|
146
|
+
this.once('descriptorsDiscover', descriptors => {
|
|
147
|
+
callback(null, descriptors);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
this._noble.discoverDescriptors(
|
|
152
|
+
this._peripheralId,
|
|
153
|
+
this._serviceUuid,
|
|
154
|
+
this.uuid
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
Characteristic.prototype.discoverDescriptors = discoverDescriptors;
|
|
159
|
+
Characteristic.prototype.discoverDescriptorsAsync = util.promisify(discoverDescriptors);
|
|
160
|
+
|
|
161
|
+
module.exports = Characteristic;
|