@stoprocent/noble 1.17.1 → 1.17.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/examples/peripheral-explorer-async.js +11 -5
- package/index.d.ts +10 -2
- package/lib/hci-socket/bindings.js +2 -2
- package/package.json +1 -1
- package/prebuilds/darwin-x64+arm64/@stoprocent+noble.node +0 -0
- package/prebuilds/win32-ia32/@stoprocent+noble.node +0 -0
- package/prebuilds/win32-x64/@stoprocent+noble.node +0 -0
- package/test/lib/hci-socket/bindings.test.js +4 -4
|
@@ -2,19 +2,23 @@ const noble = require('../');
|
|
|
2
2
|
|
|
3
3
|
const directConnect = process.argv[2].toLowerCase();
|
|
4
4
|
const peripheralIdOrAddress = process.argv[3].toLowerCase();
|
|
5
|
+
const addressType = process.argv[4].toLowerCase() || 'random';
|
|
5
6
|
|
|
6
7
|
const starTime = Date.now();
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
async function main () {
|
|
10
|
+
try {
|
|
11
|
+
await noble.waitForPoweredOn();
|
|
10
12
|
if (directConnect === '1') {
|
|
11
|
-
await noble.
|
|
12
|
-
await
|
|
13
|
+
const peripheral = await noble.connectAsync(peripheralIdOrAddress.replace(/:/g, ''), { addressType });
|
|
14
|
+
await explore(peripheral);
|
|
13
15
|
} else {
|
|
14
16
|
await noble.startScanningAsync();
|
|
15
17
|
}
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error('Error:', error);
|
|
16
20
|
}
|
|
17
|
-
}
|
|
21
|
+
}
|
|
18
22
|
|
|
19
23
|
noble.on('discover', async (peripheral) => {
|
|
20
24
|
if ([peripheral.id, peripheral.address].includes(peripheralIdOrAddress)) {
|
|
@@ -143,3 +147,5 @@ process.on('SIGTERM', function () {
|
|
|
143
147
|
console.log('Caught interrupt signal');
|
|
144
148
|
noble.stopScanning(() => process.exit());
|
|
145
149
|
});
|
|
150
|
+
|
|
151
|
+
main();
|
package/index.d.ts
CHANGED
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
|
|
14
14
|
import events = require("events");
|
|
15
15
|
|
|
16
|
+
export interface ConnectOptions {
|
|
17
|
+
addressType?: 'public' | 'random';
|
|
18
|
+
minInterval?: number;
|
|
19
|
+
maxInterval?: number;
|
|
20
|
+
latency?: number;
|
|
21
|
+
timeout?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
export declare function waitForPoweredOn(timeout?: number): Promise<void>;
|
|
17
25
|
/**
|
|
18
26
|
* @deprecated
|
|
@@ -26,8 +34,8 @@ export declare function startScanning(serviceUUIDs?: string[], allowDuplicates?:
|
|
|
26
34
|
export declare function startScanningAsync(serviceUUIDs?: string[], allowDuplicates?: boolean): Promise<void>;
|
|
27
35
|
export declare function stopScanning(callback?: () => void): void;
|
|
28
36
|
export declare function stopScanningAsync(): Promise<void>;
|
|
29
|
-
export declare function connect(peripheralUuid: string, options?:
|
|
30
|
-
export declare function connectAsync(peripheralUuid: string, options?:
|
|
37
|
+
export declare function connect(peripheralUuid: string, options?: ConnectOptions, callback?: (error: Error | undefined, peripheral: Peripheral) => void): void;
|
|
38
|
+
export declare function connectAsync(peripheralUuid: string, options?: ConnectOptions): Promise<Peripheral>;
|
|
31
39
|
export declare function cancelConnect(peripheralUuid: string, options?: object): void;
|
|
32
40
|
export declare function reset(): void;
|
|
33
41
|
export declare function stop(): void;
|
|
@@ -51,14 +51,14 @@ NobleBindings.prototype.stopScanning = function () {
|
|
|
51
51
|
this._gap.stopScanning();
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
NobleBindings.prototype.connect = function (peripheralUuid, parameters) {
|
|
54
|
+
NobleBindings.prototype.connect = function (peripheralUuid, parameters = {}) {
|
|
55
55
|
let address = this._addresses[peripheralUuid];
|
|
56
56
|
let addressType = this._addresseTypes[peripheralUuid] || 'random'; // Default to 'random' if type is not defined
|
|
57
57
|
|
|
58
58
|
// If address is not available, generate it from the UUID using the transformation logic inline
|
|
59
59
|
if (!address) {
|
|
60
60
|
address = peripheralUuid.match(/.{1,2}/g).join(':'); // Converts UUID back to MAC address format
|
|
61
|
-
addressType = (
|
|
61
|
+
addressType = typeof(parameters) === 'object' && parameters.addressType ? parameters.addressType : 'random';
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// Manage connection attempts
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -135,23 +135,23 @@ describe('hci-socket bindings', () => {
|
|
|
135
135
|
it('missing peripheral, no queue, public address', () => {
|
|
136
136
|
bindings._hci.createLeConn = fake.resolves(null);
|
|
137
137
|
|
|
138
|
-
bindings.connect('112233445566', '
|
|
138
|
+
bindings.connect('112233445566', { addressType: 'public' });
|
|
139
139
|
|
|
140
140
|
should(bindings._pendingConnectionUuid).eql('112233445566');
|
|
141
141
|
|
|
142
142
|
assert.calledOnce(bindings._hci.createLeConn);
|
|
143
|
-
assert.calledWith(bindings._hci.createLeConn, '11:22:33:44:55:66', 'public', '
|
|
143
|
+
assert.calledWith(bindings._hci.createLeConn, '11:22:33:44:55:66', 'public', { addressType: 'public' });
|
|
144
144
|
});
|
|
145
145
|
|
|
146
146
|
it('missing peripheral, no queue, random address', () => {
|
|
147
147
|
bindings._hci.createLeConn = fake.resolves(null);
|
|
148
148
|
|
|
149
|
-
bindings.connect('f32233445566', '
|
|
149
|
+
bindings.connect('f32233445566', { addressType: 'random' });
|
|
150
150
|
|
|
151
151
|
should(bindings._pendingConnectionUuid).eql('f32233445566');
|
|
152
152
|
|
|
153
153
|
assert.calledOnce(bindings._hci.createLeConn);
|
|
154
|
-
assert.calledWith(bindings._hci.createLeConn, 'f3:22:33:44:55:66', 'random', '
|
|
154
|
+
assert.calledWith(bindings._hci.createLeConn, 'f3:22:33:44:55:66', 'random', { addressType: 'random' });
|
|
155
155
|
});
|
|
156
156
|
|
|
157
157
|
it('existing peripheral, no queue', () => {
|