@tryvital/vital-devices-react-native 0.2.5

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/src/index.ts ADDED
@@ -0,0 +1,144 @@
1
+ import type { DeviceModel } from './model/device_model';
2
+ import { NativeModules, Platform } from 'react-native';
3
+ import { checkMultiple, PERMISSIONS } from 'react-native-permissions';
4
+ import { Brand } from './model/brand';
5
+ import { DeviceKind } from './model/device_model';
6
+
7
+ const LINKING_ERROR =
8
+ `The package 'vital-core-react-native' doesn't seem to be linked. Make sure: \n\n` +
9
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
10
+ '- You rebuilt the app after installing the package\n' +
11
+ '- You are not using Expo Go\n';
12
+
13
+ const VitalDevicesReactNative = NativeModules.VitalDevicesReactNative
14
+ ? NativeModules.VitalDevicesReactNative
15
+ : new Proxy(
16
+ {},
17
+ {
18
+ get() {
19
+ throw new Error(LINKING_ERROR);
20
+ },
21
+ }
22
+ );
23
+
24
+ export const VitalDevicesNativeModule = VitalDevicesReactNative;
25
+
26
+ export const VitalDevicesEvents = {
27
+ scanEvent: VitalDevicesNativeModule.ScanEvent,
28
+ pairEvent: VitalDevicesNativeModule.PairEvent,
29
+ glucoseMeterReadEvent: VitalDevicesNativeModule.GlucoseMeterReadEvent,
30
+ bloodPressureReadEvent: VitalDevicesNativeModule.BloodPressureReadEvent,
31
+ };
32
+
33
+ export class VitalDevicesManager {
34
+ async scanForDevice(deviceModel: DeviceModel) {
35
+ await this.checkPermission();
36
+
37
+ return NativeModules.VitalDevicesReactNative.startScanForDevice(
38
+ deviceModel.id,
39
+ deviceModel.name,
40
+ deviceModel.brand,
41
+ deviceModel.kind
42
+ );
43
+ }
44
+
45
+ async stopScan() {
46
+ return NativeModules.VitalDevicesReactNative.stopScanForDevice();
47
+ }
48
+
49
+ async pairDevice(scannedDeviceId: string) {
50
+ await this.checkPermission();
51
+
52
+ return NativeModules.VitalDevicesReactNative.pair(scannedDeviceId);
53
+ }
54
+
55
+ async readBloodPressure(scannedDeviceId: string) {
56
+ await this.checkPermission();
57
+
58
+ return NativeModules.VitalDevicesReactNative.startReadingBloodPressure(
59
+ scannedDeviceId
60
+ );
61
+ }
62
+
63
+ async readGlucoseMeter(scannedDeviceId: string) {
64
+ await this.checkPermission();
65
+
66
+ return NativeModules.VitalDevicesReactNative.startReadingGlucoseMeter(
67
+ scannedDeviceId
68
+ );
69
+ }
70
+
71
+ private async checkPermission() {
72
+ const result = await checkMultiple([
73
+ PERMISSIONS.ANDROID.BLUETOOTH_SCAN,
74
+ PERMISSIONS.ANDROID.BLUETOOTH_CONNECT,
75
+ ]);
76
+
77
+ if (result[PERMISSIONS.ANDROID.BLUETOOTH_SCAN] !== 'granted') {
78
+ throw new Error('Bluetooth scan permission is not granted');
79
+ }
80
+
81
+ if (result[PERMISSIONS.ANDROID.BLUETOOTH_CONNECT] !== 'granted') {
82
+ throw new Error('Bluetooth connect permission is not granted');
83
+ }
84
+ }
85
+
86
+ static brands = [
87
+ Brand.Omron,
88
+ Brand.AccuChek,
89
+ Brand.Contour,
90
+ Brand.Beurer,
91
+ Brand.Libre,
92
+ ];
93
+
94
+ static supportedDevices = [
95
+ {
96
+ id: 'omron_m4',
97
+ name: 'Omron Intelli IT M4',
98
+ brand: Brand.Omron,
99
+ kind: DeviceKind.BloodPressure,
100
+ },
101
+ {
102
+ id: 'omron_m7',
103
+ name: 'Omron Intelli IT M7',
104
+ brand: Brand.Omron,
105
+ kind: DeviceKind.BloodPressure,
106
+ },
107
+ {
108
+ id: 'accuchek_guide',
109
+ name: 'Accu-Chek Guide',
110
+ brand: Brand.AccuChek,
111
+ kind: DeviceKind.GlucoseMeter,
112
+ },
113
+ {
114
+ id: 'accuchek_guide_me',
115
+ name: 'Accu-Chek Guide Me',
116
+ brand: Brand.AccuChek,
117
+ kind: DeviceKind.GlucoseMeter,
118
+ },
119
+ {
120
+ id: 'accuchek_guide_active',
121
+ name: 'Accu-Chek Active',
122
+ brand: Brand.AccuChek,
123
+ kind: DeviceKind.GlucoseMeter,
124
+ },
125
+ {
126
+ id: 'contour_next_one',
127
+ name: 'Contour Next One',
128
+ brand: Brand.Contour,
129
+ kind: DeviceKind.GlucoseMeter,
130
+ },
131
+ {
132
+ id: 'beurer',
133
+ name: 'Beurer Devices',
134
+ brand: Brand.Beurer,
135
+ kind: DeviceKind.BloodPressure,
136
+ },
137
+ {
138
+ id: 'libre1',
139
+ name: 'Freestyle Libre 1',
140
+ brand: Brand.Libre,
141
+ kind: DeviceKind.GlucoseMeter,
142
+ },
143
+ ];
144
+ }
@@ -0,0 +1,8 @@
1
+ export var Brand;
2
+ (function (Brand) {
3
+ Brand["Omron"] = "omron";
4
+ Brand["AccuChek"] = "accuChek";
5
+ Brand["Contour"] = "contour";
6
+ Brand["Beurer"] = "beurer";
7
+ Brand["Libre"] = "libre";
8
+ })(Brand || (Brand = {}));
@@ -0,0 +1,7 @@
1
+ export enum Brand {
2
+ Omron = 'omron',
3
+ AccuChek = 'accuChek',
4
+ Contour = 'contour',
5
+ Beurer = 'beurer',
6
+ Libre = 'libre',
7
+ }
@@ -0,0 +1,5 @@
1
+ export var DeviceKind;
2
+ (function (DeviceKind) {
3
+ DeviceKind["BloodPressure"] = "bloodPressure";
4
+ DeviceKind["GlucoseMeter"] = "glucoseMeter";
5
+ })(DeviceKind || (DeviceKind = {}));
@@ -0,0 +1,13 @@
1
+ import type { Brand } from './brand';
2
+
3
+ export enum DeviceKind {
4
+ BloodPressure = 'bloodPressure',
5
+ GlucoseMeter = 'glucoseMeter',
6
+ }
7
+
8
+ export interface DeviceModel {
9
+ id: string;
10
+ name: string;
11
+ brand: Brand;
12
+ kind: DeviceKind;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { DeviceModel } from './device_model';
2
+
3
+ export interface ScannedDevice {
4
+ id: string;
5
+ name: string;
6
+ deviceModel: DeviceModel;
7
+ }
@@ -0,0 +1,35 @@
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 = "vital-devices-react-native"
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 => "14.0" }
15
+ s.source = { :git => "https://github.com/tryVital/vital-react-native.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
18
+
19
+ s.dependency "React-Core"
20
+
21
+ # Don't install the dependencies when we run `pod install` in the old architecture.
22
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
23
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
24
+ s.pod_target_xcconfig = {
25
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
26
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
27
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
28
+ }
29
+ s.dependency "React-Codegen"
30
+ s.dependency "RCT-Folly"
31
+ s.dependency "RCTRequired"
32
+ s.dependency "RCTTypeSafety"
33
+ s.dependency "ReactCommon/turbomodule/core"
34
+ end
35
+ end