@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
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
#include <vector>
|
|
5
|
+
#import <Foundation/Foundation.h>
|
|
6
|
+
#import <CoreBluetooth/CoreBluetooth.h>
|
|
7
|
+
#include "peripheral.h"
|
|
8
|
+
|
|
9
|
+
#define IF(type, var, code) type var = code; if(var)
|
|
10
|
+
|
|
11
|
+
#if defined(MAC_OS_X_VERSION_10_13)
|
|
12
|
+
#pragma clang diagnostic push
|
|
13
|
+
#pragma clang diagnostic ignored "-Wunguarded-availability"
|
|
14
|
+
std::string stateToString(CBManagerState state);
|
|
15
|
+
#pragma clang diagnostic pop
|
|
16
|
+
#else
|
|
17
|
+
std::string stateToString(CBCentralManagerState state);
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
NSString* getNSUuid(CBPeripheral* peripheral);
|
|
22
|
+
std::string getUuid(CBPeripheral* peripheral);
|
|
23
|
+
std::string getAddress(std::string uuid, AddressType* addressType);
|
|
24
|
+
std::vector<std::string> getServices(NSArray<CBService*>* services);
|
|
25
|
+
std::vector<std::pair<std::string, std::vector<std::string>>> getCharacteristics(NSArray<CBCharacteristic*>* characteristics);
|
|
26
|
+
std::vector<std::string> getDescriptors(NSArray<CBDescriptor*>* descriptors);
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
//
|
|
2
|
+
// objc_cpp.mm
|
|
3
|
+
// noble-mac-native
|
|
4
|
+
//
|
|
5
|
+
// Created by Georg Vienna on 30.08.18.
|
|
6
|
+
//
|
|
7
|
+
#include "objc_cpp.h"
|
|
8
|
+
|
|
9
|
+
#if defined(MAC_OS_X_VERSION_10_13)
|
|
10
|
+
#pragma clang diagnostic push
|
|
11
|
+
#pragma clang diagnostic ignored "-Wunguarded-availability"
|
|
12
|
+
std::string stateToString(CBManagerState state)
|
|
13
|
+
{
|
|
14
|
+
switch(state) {
|
|
15
|
+
case CBManagerStatePoweredOff:
|
|
16
|
+
return "poweredOff";
|
|
17
|
+
case CBManagerStatePoweredOn:
|
|
18
|
+
return "poweredOn";
|
|
19
|
+
case CBManagerStateResetting:
|
|
20
|
+
return "resetting";
|
|
21
|
+
case CBManagerStateUnauthorized:
|
|
22
|
+
return "unauthorized";
|
|
23
|
+
case CBManagerStateUnknown:
|
|
24
|
+
return "unknown";
|
|
25
|
+
case CBManagerStateUnsupported:
|
|
26
|
+
return "unsupported";
|
|
27
|
+
}
|
|
28
|
+
return "unknown";
|
|
29
|
+
}
|
|
30
|
+
#pragma clang diagnostic pop
|
|
31
|
+
|
|
32
|
+
// In the 10.13 SDK, CBPeripheral became a subclass of CBPeer, which defines
|
|
33
|
+
// -[CBPeer identifier] as partially available. Pretend it still exists on
|
|
34
|
+
// CBPeripheral. At runtime the implementation on CBPeer will be invoked.
|
|
35
|
+
@interface CBPeripheral (HighSierraSDK)
|
|
36
|
+
@property(readonly, nonatomic) NSUUID* identifier;
|
|
37
|
+
@end
|
|
38
|
+
#else
|
|
39
|
+
std::string stateToString(CBCentralManagerState state)
|
|
40
|
+
{
|
|
41
|
+
switch(state) {
|
|
42
|
+
case CBCentralManagerStatePoweredOff:
|
|
43
|
+
return "poweredOff";
|
|
44
|
+
case CBCentralManagerStatePoweredOn:
|
|
45
|
+
return "poweredOn";
|
|
46
|
+
case CBCentralManagerStateResetting:
|
|
47
|
+
return "resetting";
|
|
48
|
+
case CBCentralManagerStateUnauthorized:
|
|
49
|
+
return "unauthorized";
|
|
50
|
+
case CBCentralManagerStateUnknown:
|
|
51
|
+
return "unknown";
|
|
52
|
+
case CBCentralManagerStateUnsupported:
|
|
53
|
+
return "unsupported";
|
|
54
|
+
}
|
|
55
|
+
return "unknown";
|
|
56
|
+
}
|
|
57
|
+
#endif
|
|
58
|
+
|
|
59
|
+
NSString* getNSUuid(CBPeripheral* peripheral) {
|
|
60
|
+
return peripheral.identifier.UUIDString;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
std::string getUuid(CBPeripheral* peripheral) {
|
|
64
|
+
return std::string([peripheral.identifier.UUIDString UTF8String]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
std::string getAddress(std::string uuid, AddressType* addressType) {
|
|
68
|
+
NSString* deviceUuid = [[NSString alloc] initWithCString:uuid.c_str() encoding:NSASCIIStringEncoding];
|
|
69
|
+
IF(NSDictionary*, plist, [NSDictionary dictionaryWithContentsOfFile:@"/Library/Preferences/com.apple.Bluetooth.plist"]) {
|
|
70
|
+
IF(NSDictionary*, cache, [plist objectForKey:@"CoreBluetoothCache"]) {
|
|
71
|
+
IF(NSDictionary*, entry, [cache objectForKey:deviceUuid]) {
|
|
72
|
+
IF(NSNumber*, type, [entry objectForKey:@"DeviceAddressType"]) {
|
|
73
|
+
*addressType = [type boolValue] ? RANDOM : PUBLIC;
|
|
74
|
+
}
|
|
75
|
+
IF(NSString*, address, [entry objectForKey:@"DeviceAddress"]) {
|
|
76
|
+
return [address UTF8String];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return "";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
std::vector<std::string> getServices(NSArray<CBService*>* services) {
|
|
85
|
+
std::vector<std::string> result;
|
|
86
|
+
if(services) {
|
|
87
|
+
for (CBService* service in services) {
|
|
88
|
+
result.push_back([[service.UUID UUIDString] UTF8String]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
#define TEST_PROP(type, str) if((characteristic.properties & type) == type) { properties.push_back(str); }
|
|
95
|
+
|
|
96
|
+
std::vector<std::pair<std::string, std::vector<std::string>>> getCharacteristics(NSArray<CBCharacteristic*>* characteristics) {
|
|
97
|
+
std::vector<std::pair<std::string, std::vector<std::string>>> result;
|
|
98
|
+
if(characteristics) {
|
|
99
|
+
for (CBCharacteristic* characteristic in characteristics) {
|
|
100
|
+
auto uuid = [[characteristic.UUID UUIDString] UTF8String];
|
|
101
|
+
auto properties = std::vector<std::string>();
|
|
102
|
+
TEST_PROP(CBCharacteristicPropertyBroadcast, "broadcast");
|
|
103
|
+
TEST_PROP(CBCharacteristicPropertyRead, "read");
|
|
104
|
+
TEST_PROP(CBCharacteristicPropertyWriteWithoutResponse, "writeWithoutResponse");
|
|
105
|
+
TEST_PROP(CBCharacteristicPropertyWrite, "write");
|
|
106
|
+
TEST_PROP(CBCharacteristicPropertyNotify, "notify");
|
|
107
|
+
TEST_PROP(CBCharacteristicPropertyIndicate, "indicate");
|
|
108
|
+
TEST_PROP(CBCharacteristicPropertyAuthenticatedSignedWrites, "authenticatedSignedWrites");
|
|
109
|
+
TEST_PROP(CBCharacteristicPropertyExtendedProperties, "extendedProperties");
|
|
110
|
+
TEST_PROP(CBCharacteristicPropertyNotifyEncryptionRequired, "notifyEncryptionRequired");
|
|
111
|
+
TEST_PROP(CBCharacteristicPropertyIndicateEncryptionRequired, "indicateEncryptionRequired");
|
|
112
|
+
result.push_back(std::make_pair(uuid, properties));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
std::vector<std::string> getDescriptors(NSArray<CBDescriptor*>* descriptors) {
|
|
119
|
+
std::vector<std::string> result;
|
|
120
|
+
if(descriptors) {
|
|
121
|
+
for (CBDescriptor* descriptor in descriptors) {
|
|
122
|
+
result.push_back([[descriptor.UUID UUIDString] UTF8String]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
using Data = std::vector<uint8_t>;
|
|
4
|
+
|
|
5
|
+
enum AddressType {
|
|
6
|
+
PUBLIC,
|
|
7
|
+
RANDOM,
|
|
8
|
+
UNKNOWN,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
class Peripheral {
|
|
12
|
+
public:
|
|
13
|
+
Peripheral() : address("unknown"), addressType(UNKNOWN), connectable(false) {
|
|
14
|
+
}
|
|
15
|
+
std::string address;
|
|
16
|
+
AddressType addressType;
|
|
17
|
+
bool connectable;
|
|
18
|
+
std::pair<std::string, bool> name;
|
|
19
|
+
std::pair<int, bool> txPowerLevel;
|
|
20
|
+
std::pair<Data, bool> manufacturerData;
|
|
21
|
+
std::pair<std::vector<std::pair<std::string, Data>>, bool> serviceData;
|
|
22
|
+
std::pair<std::vector<std::string>, bool> serviceUuids;
|
|
23
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
const tryRequire = modulePath => {
|
|
4
|
+
try {
|
|
5
|
+
return require(modulePath);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
console.error(`ERROR:\tCould not load manufacturer list from "${modulePath}".`);
|
|
8
|
+
console.error(`\tPlease see "${path.join(__dirname, '..', 'scripts', 'manufactures', 'README.md')}" for instructions.`);
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const hexValues = tryRequire('./manufactures-hex.json');
|
|
14
|
+
const decValues = tryRequire('./manufactures-dec.json');
|
|
15
|
+
|
|
16
|
+
function Manufacture (noble, data) {
|
|
17
|
+
this._noble = noble;
|
|
18
|
+
|
|
19
|
+
this.name = null;
|
|
20
|
+
this.data = data;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const tmp = JSON.parse(JSON.stringify(data)).data;
|
|
24
|
+
|
|
25
|
+
if (Array.isArray(tmp)) {
|
|
26
|
+
this.name = decValues[tmp[0]];
|
|
27
|
+
}
|
|
28
|
+
} catch (e) {
|
|
29
|
+
console.error(e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Manufacture.prototype.toString = function () {
|
|
34
|
+
return JSON.stringify({
|
|
35
|
+
name: this.name,
|
|
36
|
+
data: JSON.parse(JSON.stringify(this.data))
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
Manufacture.nameFromHex = function (hexValue) {
|
|
41
|
+
return hexValues[hexValue] || undefined;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
Manufacture.nameFromDec = function (decValue) {
|
|
45
|
+
return decValues[decValue] || undefined;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports = Manufacture;
|