@stoprocent/noble 2.3.7 → 2.3.9
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 +2 -2
- package/lib/hci-socket/hci.js +20 -11
- package/lib/noble.js +2 -2
- package/package.json +1 -1
- package/prebuilds/android-arm/@stoprocent+noble.armv7.node +0 -0
- package/prebuilds/android-arm64/@stoprocent+noble.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/@stoprocent+noble.node +0 -0
- package/prebuilds/linux-x64/@stoprocent+noble.musl.node +0 -0
- package/prebuilds/win32-ia32/@stoprocent+noble.node +0 -0
- package/prebuilds/win32-x64/@stoprocent+noble.node +0 -0
- package/test/noble.test.js +15 -1
package/index.d.ts
CHANGED
|
@@ -122,14 +122,14 @@ declare module '@stoprocent/noble' {
|
|
|
122
122
|
toString(): string;
|
|
123
123
|
|
|
124
124
|
on(event: "connect", listener: (error: Error | undefined) => void): this;
|
|
125
|
-
on(event: "disconnect", listener: (
|
|
125
|
+
on(event: "disconnect", listener: (reason: string) => void): this;
|
|
126
126
|
on(event: "rssiUpdate", listener: (rssi: number) => void): this;
|
|
127
127
|
on(event: "servicesDiscover", listener: (services: Service[]) => void): this;
|
|
128
128
|
on(event: "mtu", listener: (mtu: number) => void): this;
|
|
129
129
|
on(event: string, listener: Function): this;
|
|
130
130
|
|
|
131
131
|
once(event: "connect", listener: (error: Error | undefined) => void): this;
|
|
132
|
-
once(event: "disconnect", listener: (
|
|
132
|
+
once(event: "disconnect", listener: (reason: string) => void): this;
|
|
133
133
|
once(event: "rssiUpdate", listener: (rssi: number) => void): this;
|
|
134
134
|
once(event: "servicesDiscover", listener: (services: Service[]) => void): this;
|
|
135
135
|
once(event: string, listener: Function): this;
|
package/lib/hci-socket/hci.js
CHANGED
|
@@ -158,20 +158,29 @@ Hci.prototype.init = function (options) {
|
|
|
158
158
|
this._socket.on('error', this.onSocketError.bind(this));
|
|
159
159
|
this._socket.on('state', this.pollIsDevUp.bind(this));
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
161
|
+
try {
|
|
162
|
+
// Bind first (either user channel or raw)
|
|
163
|
+
if (this._userChannel) {
|
|
164
|
+
this._socket.bindUser(this._deviceId, this._bindParams);
|
|
165
|
+
} else {
|
|
166
|
+
if (!this._bound) {
|
|
167
|
+
this._socket.bindRaw(this._deviceId, this._bindParams);
|
|
168
|
+
this._bound = true;
|
|
169
|
+
}
|
|
170
170
|
}
|
|
171
|
+
|
|
172
|
+
// Start and reset (common to both paths)
|
|
171
173
|
this._socket.start();
|
|
172
|
-
this._isStarted = true;
|
|
173
174
|
this.reset();
|
|
174
|
-
|
|
175
|
+
|
|
176
|
+
// Set started flag and poll only for non-userChannel
|
|
177
|
+
if (!this._userChannel) {
|
|
178
|
+
this._isStarted = true;
|
|
179
|
+
this.pollIsDevUp();
|
|
180
|
+
}
|
|
181
|
+
} catch (error) {
|
|
182
|
+
debug(`init error: ${error.message}`);
|
|
183
|
+
this.emit('stateChange', 'unsupported');
|
|
175
184
|
}
|
|
176
185
|
};
|
|
177
186
|
|
package/lib/noble.js
CHANGED
|
@@ -431,7 +431,7 @@ class Noble extends EventEmitter {
|
|
|
431
431
|
this._bindings.disconnect(peripheralId);
|
|
432
432
|
}
|
|
433
433
|
|
|
434
|
-
_onDisconnect (peripheralId, reason) {
|
|
434
|
+
_onDisconnect (peripheralId, reason = 'unknown') {
|
|
435
435
|
const peripheral = this._peripherals.get(peripheralId);
|
|
436
436
|
|
|
437
437
|
if (peripheral) {
|
|
@@ -786,7 +786,7 @@ class Noble extends EventEmitter {
|
|
|
786
786
|
|
|
787
787
|
async _withDisconnectHandler (peripheralId, operation) {
|
|
788
788
|
return new Promise((resolve, reject) => {
|
|
789
|
-
const disconnectListener =
|
|
789
|
+
const disconnectListener = reason => reject(new Error(`Disconnected ${reason}`));
|
|
790
790
|
this.once(`disconnect:${peripheralId}`, disconnectListener);
|
|
791
791
|
|
|
792
792
|
Promise.resolve(operation())
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/test/noble.test.js
CHANGED
|
@@ -932,4 +932,18 @@ describe('noble', () => {
|
|
|
932
932
|
expect(peripheral.state).toBe('disconnected');
|
|
933
933
|
});
|
|
934
934
|
});
|
|
935
|
-
|
|
935
|
+
|
|
936
|
+
describe("_withDisconnectHandler", () => {
|
|
937
|
+
test("resolves operation result", async () => {
|
|
938
|
+
const promise = noble._withDisconnectHandler('peripheralUuid', () => Promise.resolve(1))
|
|
939
|
+
await expect(promise).resolves.toBe(1)
|
|
940
|
+
})
|
|
941
|
+
|
|
942
|
+
test("throws disconnect error if disconnected before resolve", async () => {
|
|
943
|
+
noble._peripherals.set('uuid', {emit: jest.fn()});
|
|
944
|
+
const promise = noble._withDisconnectHandler('uuid', () => Promise.resolve(1))
|
|
945
|
+
noble._onDisconnect('uuid')
|
|
946
|
+
await expect(promise).rejects.toThrow('Disconnected unknown')
|
|
947
|
+
})
|
|
948
|
+
})
|
|
949
|
+
});
|