react-native-bluebreeze 0.0.1
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/LICENSE +20 -0
- package/README.md +33 -0
- package/android/build.gradle +122 -0
- package/android/generated/java/com/bluebreeze/NativeBlueBreezeSpec.java +153 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNBlueBreezeSpec-generated.cpp +156 -0
- package/android/generated/jni/RNBlueBreezeSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI-generated.cpp +171 -0
- package/android/generated/jni/react/renderer/components/RNBlueBreezeSpec/RNBlueBreezeSpecJSI.h +632 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/bluebreeze/BlueBreezeModule.kt +23 -0
- package/android/src/main/java/com/bluebreeze/BlueBreezePackage.kt +34 -0
- package/ios/BlueBreezeImpl.swift +477 -0
- package/ios/Bluebreeze.h +6 -0
- package/ios/Bluebreeze.mm +280 -0
- package/ios/generated/RNBlueBreezeSpec/RNBlueBreezeSpec-generated.mm +219 -0
- package/ios/generated/RNBlueBreezeSpec/RNBlueBreezeSpec.h +117 -0
- package/ios/generated/RNBlueBreezeSpecJSI-generated.cpp +171 -0
- package/ios/generated/RNBlueBreezeSpecJSI.h +632 -0
- package/package.json +203 -0
- package/react-native-bluebreeze.podspec +44 -0
- package/react-native.config.js +12 -0
- package/src/NativeBlueBreeze.ts +142 -0
- package/src/index.tsx +99 -0
package/package.json
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-bluebreeze",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "BlueBreeze bindings for React Native. A modern Bluetooth LE library.",
|
|
5
|
+
"source": "./src/index.tsx",
|
|
6
|
+
"main": "./lib/commonjs/index.js",
|
|
7
|
+
"module": "./lib/module/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./lib/typescript/module/src/index.d.ts",
|
|
12
|
+
"default": "./lib/module/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./lib/typescript/commonjs/src/index.d.ts",
|
|
16
|
+
"default": "./lib/commonjs/index.js"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src",
|
|
22
|
+
"lib",
|
|
23
|
+
"android",
|
|
24
|
+
"ios",
|
|
25
|
+
"cpp",
|
|
26
|
+
"*.podspec",
|
|
27
|
+
"react-native.config.js",
|
|
28
|
+
"!ios/build",
|
|
29
|
+
"!android/build",
|
|
30
|
+
"!android/gradle",
|
|
31
|
+
"!android/gradlew",
|
|
32
|
+
"!android/gradlew.bat",
|
|
33
|
+
"!android/local.properties",
|
|
34
|
+
"!**/__tests__",
|
|
35
|
+
"!**/__fixtures__",
|
|
36
|
+
"!**/__mocks__",
|
|
37
|
+
"!**/.*"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"example": "yarn workspace react-native-bluebreeze-example",
|
|
41
|
+
"test": "jest",
|
|
42
|
+
"typecheck": "tsc",
|
|
43
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
44
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
45
|
+
"prepare": "bob build",
|
|
46
|
+
"release": "release-it"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"react-native",
|
|
50
|
+
"ios",
|
|
51
|
+
"android"
|
|
52
|
+
],
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/like-magic-dev/bluebreeze-react-native.git"
|
|
56
|
+
},
|
|
57
|
+
"author": "Alessandro Mulloni <ale@likemagic.dev> (https://likemagic.dev)",
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "https://github.com/like-magic-dev/bluebreeze-react-native/issues"
|
|
61
|
+
},
|
|
62
|
+
"homepage": "https://github.com/like-magic-dev/bluebreeze-react-native#readme",
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"registry": "https://registry.npmjs.org/"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@commitlint/config-conventional": "^17.0.2",
|
|
68
|
+
"@evilmartians/lefthook": "^1.5.0",
|
|
69
|
+
"@react-native-community/cli": "15.0.1",
|
|
70
|
+
"@react-native/eslint-config": "^0.73.1",
|
|
71
|
+
"@release-it/conventional-changelog": "^9.0.2",
|
|
72
|
+
"@types/jest": "^29.5.5",
|
|
73
|
+
"@types/react": "^18.2.44",
|
|
74
|
+
"commitlint": "^17.0.2",
|
|
75
|
+
"del-cli": "^5.1.0",
|
|
76
|
+
"eslint": "^8.51.0",
|
|
77
|
+
"eslint-config-prettier": "^9.0.0",
|
|
78
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
79
|
+
"jest": "^29.7.0",
|
|
80
|
+
"prettier": "^3.0.3",
|
|
81
|
+
"react": "18.3.1",
|
|
82
|
+
"react-native": "0.76.5",
|
|
83
|
+
"react-native-builder-bob": "^0.35.2",
|
|
84
|
+
"release-it": "^17.10.0",
|
|
85
|
+
"turbo": "^1.10.7",
|
|
86
|
+
"typescript": "^5.2.2"
|
|
87
|
+
},
|
|
88
|
+
"resolutions": {
|
|
89
|
+
"@types/react": "^18.2.44"
|
|
90
|
+
},
|
|
91
|
+
"peerDependencies": {
|
|
92
|
+
"react": "*",
|
|
93
|
+
"react-native": "*"
|
|
94
|
+
},
|
|
95
|
+
"workspaces": [
|
|
96
|
+
"example"
|
|
97
|
+
],
|
|
98
|
+
"packageManager": "yarn@3.6.1",
|
|
99
|
+
"jest": {
|
|
100
|
+
"preset": "react-native",
|
|
101
|
+
"modulePathIgnorePatterns": [
|
|
102
|
+
"<rootDir>/example/node_modules",
|
|
103
|
+
"<rootDir>/lib/"
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
"commitlint": {
|
|
107
|
+
"extends": [
|
|
108
|
+
"@commitlint/config-conventional"
|
|
109
|
+
]
|
|
110
|
+
},
|
|
111
|
+
"release-it": {
|
|
112
|
+
"git": {
|
|
113
|
+
"commitMessage": "chore: release ${version}",
|
|
114
|
+
"tagName": "v${version}"
|
|
115
|
+
},
|
|
116
|
+
"npm": {
|
|
117
|
+
"publish": true
|
|
118
|
+
},
|
|
119
|
+
"github": {
|
|
120
|
+
"release": true
|
|
121
|
+
},
|
|
122
|
+
"plugins": {
|
|
123
|
+
"@release-it/conventional-changelog": {
|
|
124
|
+
"preset": "angular"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
"eslintConfig": {
|
|
129
|
+
"root": true,
|
|
130
|
+
"extends": [
|
|
131
|
+
"@react-native",
|
|
132
|
+
"prettier"
|
|
133
|
+
],
|
|
134
|
+
"rules": {
|
|
135
|
+
"react/react-in-jsx-scope": "off",
|
|
136
|
+
"prettier/prettier": [
|
|
137
|
+
"error",
|
|
138
|
+
{
|
|
139
|
+
"quoteProps": "consistent",
|
|
140
|
+
"singleQuote": true,
|
|
141
|
+
"tabWidth": 2,
|
|
142
|
+
"trailingComma": "es5",
|
|
143
|
+
"useTabs": false
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
"eslintIgnore": [
|
|
149
|
+
"node_modules/",
|
|
150
|
+
"lib/"
|
|
151
|
+
],
|
|
152
|
+
"prettier": {
|
|
153
|
+
"quoteProps": "consistent",
|
|
154
|
+
"singleQuote": true,
|
|
155
|
+
"tabWidth": 2,
|
|
156
|
+
"trailingComma": "es5",
|
|
157
|
+
"useTabs": false
|
|
158
|
+
},
|
|
159
|
+
"react-native-builder-bob": {
|
|
160
|
+
"source": "src",
|
|
161
|
+
"output": "lib",
|
|
162
|
+
"targets": [
|
|
163
|
+
"codegen",
|
|
164
|
+
[
|
|
165
|
+
"commonjs",
|
|
166
|
+
{
|
|
167
|
+
"esm": true
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
[
|
|
171
|
+
"module",
|
|
172
|
+
{
|
|
173
|
+
"esm": true
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
[
|
|
177
|
+
"typescript",
|
|
178
|
+
{
|
|
179
|
+
"project": "tsconfig.build.json",
|
|
180
|
+
"esm": true
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
]
|
|
184
|
+
},
|
|
185
|
+
"codegenConfig": {
|
|
186
|
+
"name": "RNBlueBreezeSpec",
|
|
187
|
+
"type": "modules",
|
|
188
|
+
"jsSrcsDir": "src",
|
|
189
|
+
"outputDir": {
|
|
190
|
+
"ios": "ios/generated",
|
|
191
|
+
"android": "android/generated"
|
|
192
|
+
},
|
|
193
|
+
"android": {
|
|
194
|
+
"javaPackageName": "com.bluebreeze"
|
|
195
|
+
},
|
|
196
|
+
"includesGeneratedCode": true
|
|
197
|
+
},
|
|
198
|
+
"create-react-native-library": {
|
|
199
|
+
"type": "turbo-module",
|
|
200
|
+
"languages": "kotlin-objc",
|
|
201
|
+
"version": "0.45.5"
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
5
|
+
|
|
6
|
+
Pod::Spec.new do |s|
|
|
7
|
+
s.name = "react-native-bluebreeze"
|
|
8
|
+
s.version = package["version"]
|
|
9
|
+
s.summary = package["description"]
|
|
10
|
+
s.homepage = package["homepage"]
|
|
11
|
+
s.license = package["license"]
|
|
12
|
+
s.authors = package["author"]
|
|
13
|
+
|
|
14
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
15
|
+
s.source = { :git => "https://github.com/like-magic-dev/bluebreeze-react-native.git", :tag => "#{s.version}" }
|
|
16
|
+
|
|
17
|
+
s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
|
|
18
|
+
s.private_header_files = "ios/**/*.h"
|
|
19
|
+
|
|
20
|
+
s.dependency "BlueBreeze"
|
|
21
|
+
|
|
22
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
23
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
24
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
25
|
+
install_modules_dependencies(s)
|
|
26
|
+
else
|
|
27
|
+
s.dependency "React-Core"
|
|
28
|
+
|
|
29
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
30
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
31
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
32
|
+
s.pod_target_xcconfig = {
|
|
33
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
34
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
35
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
36
|
+
}
|
|
37
|
+
s.dependency "React-Codegen"
|
|
38
|
+
s.dependency "RCT-Folly"
|
|
39
|
+
s.dependency "RCTRequired"
|
|
40
|
+
s.dependency "RCTTypeSafety"
|
|
41
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
import type {EventEmitter} from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
+
|
|
5
|
+
export interface BBCharacteristic {
|
|
6
|
+
id: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
properties: string[];
|
|
9
|
+
|
|
10
|
+
// Data
|
|
11
|
+
data(): number[];
|
|
12
|
+
readonly dataEmitter: EventEmitter<number[]>;
|
|
13
|
+
|
|
14
|
+
// Notifying
|
|
15
|
+
notifyEnabled(): boolean;
|
|
16
|
+
readonly notifyEnabledEmitter: EventEmitter<boolean>;
|
|
17
|
+
|
|
18
|
+
// Operations
|
|
19
|
+
read: () => Promise<number[]>;
|
|
20
|
+
write: (data: number[], withResponse: boolean) => Promise<void>;
|
|
21
|
+
subscribe: () => Promise<void>;
|
|
22
|
+
unsubscribe: () => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface BBService {
|
|
26
|
+
id: string;
|
|
27
|
+
name?: string;
|
|
28
|
+
characteristics: BBCharacteristic[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface BBDeviceServicesEvent {
|
|
32
|
+
id: string;
|
|
33
|
+
value: BBService[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface BBDeviceConnectionStatusEvent {
|
|
37
|
+
id: string;
|
|
38
|
+
value: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface BBDeviceMTUEvent {
|
|
42
|
+
id: string;
|
|
43
|
+
value: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface BBDeviceCharacteristicDataEvent {
|
|
47
|
+
id: string;
|
|
48
|
+
serviceId: string;
|
|
49
|
+
characteristicId: string;
|
|
50
|
+
value: number[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface BBDeviceCharacteristicNotifyEnabledEvent {
|
|
54
|
+
id: string;
|
|
55
|
+
serviceId: string;
|
|
56
|
+
characteristicId: string;
|
|
57
|
+
value: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface BBDevice {
|
|
61
|
+
id: string;
|
|
62
|
+
name?: string;
|
|
63
|
+
rssi: number;
|
|
64
|
+
isConnectable: boolean;
|
|
65
|
+
manufacturerId?: number;
|
|
66
|
+
manufacturerName?: string;
|
|
67
|
+
manufacturerData?: number[];
|
|
68
|
+
advertisedServices: string[];
|
|
69
|
+
|
|
70
|
+
// Services
|
|
71
|
+
services(): BBService[];
|
|
72
|
+
readonly servicesEmitter: EventEmitter<BBService[]>;
|
|
73
|
+
|
|
74
|
+
// Connection status
|
|
75
|
+
connectionStatus(): string;
|
|
76
|
+
readonly connectionStatusEmitter: EventEmitter<string>;
|
|
77
|
+
|
|
78
|
+
// MTU
|
|
79
|
+
mtu(): number;
|
|
80
|
+
readonly mtuEmitter: EventEmitter<number>;
|
|
81
|
+
|
|
82
|
+
// Operations
|
|
83
|
+
connect: () => Promise<void>;
|
|
84
|
+
disconnect: () => Promise<void>;
|
|
85
|
+
discoverServices: () => Promise<void>;
|
|
86
|
+
requestMTU: (mtu: number) => Promise<number>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface Spec extends TurboModule {
|
|
90
|
+
// Authorization
|
|
91
|
+
authorizationStatus(): string;
|
|
92
|
+
readonly authorizationStatusEmitter: EventEmitter<string>;
|
|
93
|
+
authorizationRequest(): void;
|
|
94
|
+
|
|
95
|
+
// State
|
|
96
|
+
state(): string;
|
|
97
|
+
readonly stateEmitter: EventEmitter<string>;
|
|
98
|
+
|
|
99
|
+
// Scanning
|
|
100
|
+
scanningEnabled(): boolean;
|
|
101
|
+
readonly scanningEnabledEmitter: EventEmitter<boolean>;
|
|
102
|
+
scanningStart(): void;
|
|
103
|
+
scanningStop(): void;
|
|
104
|
+
|
|
105
|
+
// Devices
|
|
106
|
+
devices(): BBDevice[];
|
|
107
|
+
readonly devicesEmitter: EventEmitter<BBDevice[]>;
|
|
108
|
+
|
|
109
|
+
// Device services
|
|
110
|
+
deviceServices(id: string): BBService[];
|
|
111
|
+
readonly deviceServicesEmitter: EventEmitter<BBDeviceServicesEvent>;
|
|
112
|
+
|
|
113
|
+
// Device connection status
|
|
114
|
+
deviceConnectionStatus(id: string): string;
|
|
115
|
+
readonly deviceConnectionStatusEmitter: EventEmitter<BBDeviceConnectionStatusEvent>;
|
|
116
|
+
|
|
117
|
+
// Device MTU
|
|
118
|
+
deviceMTU(id: string): number;
|
|
119
|
+
readonly deviceMTUEmitter: EventEmitter<BBDeviceMTUEvent>;
|
|
120
|
+
|
|
121
|
+
// Device operation
|
|
122
|
+
deviceConnect(id: string): Promise<void>;
|
|
123
|
+
deviceDisconnect(id: string): Promise<void>;
|
|
124
|
+
deviceDiscoverServices(id: string): Promise<void>;
|
|
125
|
+
deviceRequestMTU(id: string, mtu: number): Promise<number>;
|
|
126
|
+
|
|
127
|
+
// Device characteristic data
|
|
128
|
+
deviceCharacteristicData(id: string, serviceId: string, characteristicId: string): number[];
|
|
129
|
+
readonly deviceCharacteristicDataEmitter: EventEmitter<BBDeviceCharacteristicDataEvent>;
|
|
130
|
+
|
|
131
|
+
// Device characteristic notify enabled
|
|
132
|
+
deviceCharacteristicNotifyEnabled(id: string, serviceId: string, characteristicId: string): boolean;
|
|
133
|
+
readonly deviceCharacteristicNotifyEnabledEmitter: EventEmitter<BBDeviceCharacteristicNotifyEnabledEvent>;
|
|
134
|
+
|
|
135
|
+
// Device characteristic operations
|
|
136
|
+
deviceCharacteristicRead(id: string, serviceId: string, characteristicId: string): Promise<number[]>;
|
|
137
|
+
deviceCharacteristicWrite(id: string, serviceId: string, characteristicId: string, data: number[], withResponse: boolean): Promise<void>;
|
|
138
|
+
deviceCharacteristicSubscribe(id: string, serviceId: string, characteristicId: string): Promise<void>;
|
|
139
|
+
deviceCharacteristicUnsubscribe(id: string, serviceId: string, characteristicId: string): Promise<void>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('BlueBreeze');
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { EventEmitter } from 'react-native/Libraries/Types/CodegenTypes';
|
|
2
|
+
import BlueBreeze, {type BBCharacteristic, type BBDevice, type BBService} from './NativeBlueBreeze';
|
|
3
|
+
|
|
4
|
+
// Authorization to use BLE
|
|
5
|
+
|
|
6
|
+
export const authorizationRequest = BlueBreeze.authorizationRequest;
|
|
7
|
+
|
|
8
|
+
export const authorizationStatus = BlueBreeze.authorizationStatus;
|
|
9
|
+
|
|
10
|
+
export const authorizationStatusEmitter = BlueBreeze.authorizationStatusEmitter;
|
|
11
|
+
|
|
12
|
+
// State
|
|
13
|
+
|
|
14
|
+
export const state = BlueBreeze.state;
|
|
15
|
+
|
|
16
|
+
export const stateEmitter = BlueBreeze.stateEmitter;
|
|
17
|
+
|
|
18
|
+
// Scanning
|
|
19
|
+
|
|
20
|
+
export const scanningEnabled = BlueBreeze.scanningEnabled;
|
|
21
|
+
|
|
22
|
+
export const scanningEnabledEmitter = BlueBreeze.scanningEnabledEmitter;
|
|
23
|
+
|
|
24
|
+
export const scanningStart = BlueBreeze.scanningStart;
|
|
25
|
+
|
|
26
|
+
export const scanningStop = BlueBreeze.scanningStop;
|
|
27
|
+
|
|
28
|
+
// Devices
|
|
29
|
+
|
|
30
|
+
const characteristicAddMethods = (device: BBDevice, service: BBService, characteristic: BBCharacteristic): BBCharacteristic => {
|
|
31
|
+
return {
|
|
32
|
+
...characteristic,
|
|
33
|
+
data: () => BlueBreeze.deviceCharacteristicData(device.id, service.id, characteristic.id),
|
|
34
|
+
dataEmitter: (handler: (arg: number[]) => void | Promise<void>) => {
|
|
35
|
+
return BlueBreeze.deviceCharacteristicDataEmitter((value) => {
|
|
36
|
+
if ((value["id"] === device.id) && (value["serviceId"] === service.id) && (value["characteristicId"] === characteristic.id) && (value["value"] != undefined)) {
|
|
37
|
+
handler(value["value"]);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
notifyEnabled: () => BlueBreeze.deviceCharacteristicNotifyEnabled(device.id, service.id, characteristic.id),
|
|
42
|
+
notifyEnabledEmitter: (handler: (arg: boolean) => void | Promise<void>) => {
|
|
43
|
+
return BlueBreeze.deviceCharacteristicNotifyEnabledEmitter((value) => {
|
|
44
|
+
if ((value["id"] === device.id) && (value["serviceId"] === service.id) && (value["characteristicId"] === characteristic.id) && (value["value"] != undefined)) {
|
|
45
|
+
handler(value["value"]);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
read: () => BlueBreeze.deviceCharacteristicRead(device.id, service.id, characteristic.id),
|
|
50
|
+
write: (data: number[], withResponse: boolean) => BlueBreeze.deviceCharacteristicWrite(device.id, service.id, characteristic.id, data, withResponse),
|
|
51
|
+
subscribe: () => BlueBreeze.deviceCharacteristicSubscribe(device.id, service.id, characteristic.id),
|
|
52
|
+
unsubscribe: () => BlueBreeze.deviceCharacteristicUnsubscribe(device.id, service.id, characteristic.id),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const serviceAddMethods = (device: BBDevice, service: BBService): BBService => {
|
|
57
|
+
return {
|
|
58
|
+
...service,
|
|
59
|
+
characteristics: service.characteristics.map((characteristic) => characteristicAddMethods(device, service, characteristic)),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const deviceAddMethods = (device: BBDevice): BBDevice => {
|
|
64
|
+
return {
|
|
65
|
+
...device,
|
|
66
|
+
connectionStatus: () => BlueBreeze.deviceConnectionStatus(device.id),
|
|
67
|
+
connectionStatusEmitter: (handler: (arg: string) => void | Promise<void>) => {
|
|
68
|
+
return BlueBreeze.deviceConnectionStatusEmitter((value) => {
|
|
69
|
+
if ((value["id"] === device.id) && (value["value"] != undefined)) {
|
|
70
|
+
handler(value["value"]);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
services: () => BlueBreeze.deviceServices(device.id).map((service) => serviceAddMethods(device, service)),
|
|
75
|
+
servicesEmitter: (handler: (arg: BBService[]) => void | Promise<void>) => {
|
|
76
|
+
return BlueBreeze.deviceServicesEmitter((value) => {
|
|
77
|
+
if ((value["id"] === device.id) && (value["value"] != undefined)) {
|
|
78
|
+
const services = value["value"];
|
|
79
|
+
handler(services.map((service) => serviceAddMethods(device, service)));
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
connect: () => BlueBreeze.deviceConnect(device.id),
|
|
84
|
+
disconnect: () => BlueBreeze.deviceDisconnect(device.id),
|
|
85
|
+
discoverServices: () => BlueBreeze.deviceDiscoverServices(device.id),
|
|
86
|
+
requestMTU: (mtu: number) => BlueBreeze.deviceRequestMTU(device.id, mtu),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const devices = (): BBDevice[] => {
|
|
91
|
+
return BlueBreeze.devices().map((device) => deviceAddMethods(device));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const devicesEmitter: EventEmitter<BBDevice[]> = (handler: (arg: BBDevice[]) => void | Promise<void>) => {
|
|
95
|
+
handler(devices());
|
|
96
|
+
return BlueBreeze.devicesEmitter((devices) => {
|
|
97
|
+
handler(devices.map((device) => deviceAddMethods(device)));
|
|
98
|
+
});
|
|
99
|
+
}
|