react-native-flic2 2.0.0-beta.2 → 2.0.0-beta.21
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/Flic2.podspec +14 -4
- package/Flic2Device.podspec +21 -0
- package/Flic2Simulator.podspec +20 -0
- package/README.md +140 -22
- package/android/build.gradle +1 -1
- package/android/src/main/java/{com → nl/xguard}/flic2/ActivityUtil.kt +1 -1
- package/android/src/main/java/{com → nl/xguard}/flic2/Flic2ButtonListener.kt +19 -3
- package/android/src/main/java/{com → nl/xguard}/flic2/Flic2Converter.kt +2 -3
- package/android/src/main/java/{com → nl/xguard}/flic2/Flic2Module.kt +70 -53
- package/android/src/main/java/{com → nl/xguard}/flic2/Flic2Package.kt +2 -1
- package/android/src/main/java/{com → nl/xguard}/flic2/Flic2Service.kt +11 -22
- package/ios/Flic2.mm +45 -29
- package/ios/Flic2SimulatorStub.h +5 -0
- package/ios/Flic2SimulatorStub.mm +134 -0
- package/lib/module/NativeFlic2.js +45 -1
- package/lib/module/NativeFlic2.js.map +1 -1
- package/lib/module/index.js +10 -14
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeFlic2.d.ts +14 -49
- package/lib/typescript/src/NativeFlic2.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +17 -52
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +23 -23
- package/src/NativeFlic2.ts +76 -29
- package/src/index.ts +25 -40
- package/lib/module/index.bak.js +0 -161
- package/lib/module/index.bak.js.map +0 -1
- package/lib/typescript/src/index.bak.d.ts +0 -1
- package/lib/typescript/src/index.bak.d.ts.map +0 -1
- package/src/index.bak.tsx +0 -159
|
@@ -2,12 +2,10 @@ import { TypedEmitter } from './lib/typedEventEmitter';
|
|
|
2
2
|
import { type ButtonEvent, type FlicButton, type LatencyModeType, type ManagerStateChangeEvent, type ScanStatusChangeEvent, type TriggerModeType } from './NativeFlic2';
|
|
3
3
|
declare class Flic2 {
|
|
4
4
|
private isFlic2ManagerInitialized;
|
|
5
|
-
private sessionId;
|
|
6
5
|
eventEmitter: TypedEmitter<{
|
|
7
6
|
buttonEvent: (event: ButtonEvent) => void;
|
|
8
7
|
managerStateChange: (event: ManagerStateChangeEvent) => void;
|
|
9
8
|
scanStatusChange: (event: ScanStatusChangeEvent) => void;
|
|
10
|
-
managerInitialized: () => void;
|
|
11
9
|
}>;
|
|
12
10
|
/**
|
|
13
11
|
* Constructor.
|
|
@@ -21,25 +19,19 @@ declare class Flic2 {
|
|
|
21
19
|
*
|
|
22
20
|
* @returns A promise that resolves when the Flic2 manager is initialized.
|
|
23
21
|
*/
|
|
24
|
-
initialize(): Promise<
|
|
22
|
+
initialize(): Promise<void>;
|
|
25
23
|
/**
|
|
26
24
|
* Scan for buttons.
|
|
27
25
|
*
|
|
28
26
|
* @returns A promise that resolves when the scan is started. Events will be emitted for the scan process.
|
|
29
27
|
*/
|
|
30
|
-
startScan(): Promise<
|
|
31
|
-
success: boolean;
|
|
32
|
-
message: string;
|
|
33
|
-
}>;
|
|
28
|
+
startScan(): Promise<void>;
|
|
34
29
|
/**
|
|
35
30
|
* Stop the scan.
|
|
36
31
|
*
|
|
37
32
|
* @returns A promise that resolves when the scan is stopped.
|
|
38
33
|
*/
|
|
39
|
-
stopScan(): Promise<
|
|
40
|
-
success: boolean;
|
|
41
|
-
message: string;
|
|
42
|
-
}>;
|
|
34
|
+
stopScan(): Promise<void>;
|
|
43
35
|
/**
|
|
44
36
|
* Called when the Flic2 manager is initialized.
|
|
45
37
|
*/
|
|
@@ -55,28 +47,19 @@ declare class Flic2 {
|
|
|
55
47
|
*
|
|
56
48
|
* @returns A promise that resolves when the all known buttons are connected.
|
|
57
49
|
*/
|
|
58
|
-
connectAllKnownButtons(): Promise<
|
|
59
|
-
success: boolean;
|
|
60
|
-
message: string;
|
|
61
|
-
}>;
|
|
50
|
+
connectAllKnownButtons(): Promise<void>;
|
|
62
51
|
/**
|
|
63
52
|
* Disconnect all known buttons.
|
|
64
53
|
*
|
|
65
54
|
* @returns A promise that resolves when the all known buttons are disconnected.
|
|
66
55
|
*/
|
|
67
|
-
disconnectAllKnownButtons(): Promise<
|
|
68
|
-
success: boolean;
|
|
69
|
-
message: string;
|
|
70
|
-
}>;
|
|
56
|
+
disconnectAllKnownButtons(): Promise<void>;
|
|
71
57
|
/**
|
|
72
58
|
* Forget all buttons.
|
|
73
59
|
*
|
|
74
60
|
* @returns A promise that resolves when the all buttons are forgotten.
|
|
75
61
|
*/
|
|
76
|
-
forgetAllButtons(): Promise<
|
|
77
|
-
success: boolean;
|
|
78
|
-
message: string;
|
|
79
|
-
}>;
|
|
62
|
+
forgetAllButtons(): Promise<void>;
|
|
80
63
|
/**
|
|
81
64
|
* Check if a scan is currently running.
|
|
82
65
|
*
|
|
@@ -89,63 +72,45 @@ declare class Flic2 {
|
|
|
89
72
|
* @param uuid - The UUID of the button to forget.
|
|
90
73
|
* @returns A promise that resolves when the button is forgotten.
|
|
91
74
|
*/
|
|
92
|
-
forgetButton(uuid: string): Promise<
|
|
93
|
-
success: boolean;
|
|
94
|
-
message: string;
|
|
95
|
-
}>;
|
|
75
|
+
forgetButton(uuid: string): Promise<void>;
|
|
96
76
|
/**
|
|
97
77
|
* Connect a button.
|
|
98
78
|
*
|
|
99
79
|
* @param uuid - The UUID of the button to connect.
|
|
100
|
-
* @returns A promise that resolves
|
|
80
|
+
* @returns A promise that resolves with the button when the connection is initiated.
|
|
101
81
|
*/
|
|
102
|
-
buttonConnect(uuid: string): Promise<
|
|
103
|
-
success: boolean;
|
|
104
|
-
message: string;
|
|
105
|
-
}>;
|
|
82
|
+
buttonConnect(uuid: string): Promise<FlicButton>;
|
|
106
83
|
/**
|
|
107
84
|
* Disconnect a button.
|
|
108
85
|
*
|
|
109
86
|
* @param uuid - The UUID of the button to disconnect.
|
|
110
|
-
* @returns A promise that resolves
|
|
87
|
+
* @returns A promise that resolves with the button when the disconnection is initiated.
|
|
111
88
|
*/
|
|
112
|
-
buttonDisconnect(uuid: string): Promise<
|
|
113
|
-
success: boolean;
|
|
114
|
-
message: string;
|
|
115
|
-
}>;
|
|
89
|
+
buttonDisconnect(uuid: string): Promise<FlicButton>;
|
|
116
90
|
/**
|
|
117
91
|
* Set the trigger mode of a button.
|
|
118
92
|
*
|
|
119
93
|
* @param uuid - The UUID of the button to set the trigger mode of.
|
|
120
94
|
* @param mode - The trigger mode to set.
|
|
121
|
-
* @returns A promise that resolves when the trigger mode is set.
|
|
95
|
+
* @returns A promise that resolves with the button when the trigger mode is set.
|
|
122
96
|
*/
|
|
123
|
-
buttonSetTriggerMode(uuid: string, mode: TriggerModeType): Promise<
|
|
124
|
-
success: boolean;
|
|
125
|
-
message: string;
|
|
126
|
-
}>;
|
|
97
|
+
buttonSetTriggerMode(uuid: string, mode: TriggerModeType): Promise<FlicButton>;
|
|
127
98
|
/**
|
|
128
99
|
* Set the latency mode of a button.
|
|
129
100
|
*
|
|
130
101
|
* @param uuid - The UUID of the button to set the latency mode of.
|
|
131
102
|
* @param mode - The latency mode to set.
|
|
132
|
-
* @returns A promise that resolves when the latency mode is set.
|
|
103
|
+
* @returns A promise that resolves with the button when the latency mode is set.
|
|
133
104
|
*/
|
|
134
|
-
buttonSetLatencyMode(uuid: string, mode: LatencyModeType): Promise<
|
|
135
|
-
success: boolean;
|
|
136
|
-
message: string;
|
|
137
|
-
}>;
|
|
105
|
+
buttonSetLatencyMode(uuid: string, mode: LatencyModeType): Promise<FlicButton>;
|
|
138
106
|
/**
|
|
139
107
|
* Set the nickname of a button.
|
|
140
108
|
*
|
|
141
109
|
* @param uuid - The UUID of the button to set the nickname of.
|
|
142
110
|
* @param nickname - The nickname to set.
|
|
143
|
-
* @returns A promise that resolves when the nickname is set.
|
|
111
|
+
* @returns A promise that resolves with the button when the nickname is set.
|
|
144
112
|
*/
|
|
145
|
-
buttonSetNickname(uuid: string, nickname: string): Promise<
|
|
146
|
-
success: boolean;
|
|
147
|
-
message: string;
|
|
148
|
-
}>;
|
|
113
|
+
buttonSetNickname(uuid: string, nickname: string): Promise<FlicButton>;
|
|
149
114
|
/**
|
|
150
115
|
* Get all buttons.
|
|
151
116
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAoB,EAClB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB,cAAM,KAAK;IAET,OAAO,CAAC,yBAAyB,CAAkB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAoB,EAClB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB,cAAM,KAAK;IAET,OAAO,CAAC,yBAAyB,CAAkB;IAE5C,YAAY,EAAE,YAAY,CAAC;QAChC,WAAW,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;QAC1C,kBAAkB,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAC;QAC7D,gBAAgB,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,CAAC;KAC1D,CAAC,CAAC;IAEH;;;;;OAKG;;IAqBH;;;;OAIG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBxC;;;;OAIG;IACI,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC;;;;OAIG;IACI,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAMhC;;OAEG;IACI,aAAa,IAAI,IAAI;IAM5B;;;;OAIG;IACI,aAAa,IAAI,OAAO;IAM/B;;;;OAIG;IACI,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9C;;;;OAIG;IACI,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjD;;;;OAIG;IACI,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAMxC;;;;OAIG;IACI,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAMrC;;;;;OAKG;IACI,YAAY,CACjB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC;IAOhB;;;;;OAKG;IACI,aAAa,CAClB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,UAAU,CAAC;IAMtB;;;;;OAKG;IACI,gBAAgB,CACrB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,UAAU,CAAC;IAMtB;;;;;;OAMG;IACI,oBAAoB,CACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,UAAU,CAAC;IAMtB;;;;;;OAMG;IACI,oBAAoB,CACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,UAAU,CAAC;IAMtB;;;;;;OAMG;IACI,iBAAiB,CACtB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,CAAC;IAMtB;;;;OAIG;IACI,UAAU,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAM1C;;;;;OAKG;IACU,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAShE;;;;;;OAMG;IACU,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAe7D;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAM1B;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAsB3B;;;;OAIG;IACH,OAAO,CAAC,0BAA0B;IAalC;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;CAMjC;;AAGD,wBAA2B;AAG3B,mBAAmB,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-flic2",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.21",
|
|
4
4
|
"description": "React Native Flic plugin made with the Flic2 SDK (unofficial)",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -57,31 +57,31 @@
|
|
|
57
57
|
"registry": "https://registry.npmjs.org/"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@eslint/compat": "
|
|
61
|
-
"@eslint/eslintrc": "
|
|
62
|
-
"@eslint/js": "
|
|
63
|
-
"@evilmartians/lefthook": "
|
|
60
|
+
"@eslint/compat": "1.3.2",
|
|
61
|
+
"@eslint/eslintrc": "3.3.1",
|
|
62
|
+
"@eslint/js": "9.35.0",
|
|
63
|
+
"@evilmartians/lefthook": "1.12.3",
|
|
64
64
|
"@react-native-community/cli": "20.0.1",
|
|
65
65
|
"@react-native/babel-preset": "0.81.1",
|
|
66
|
-
"@react-native/eslint-config": "
|
|
67
|
-
"@release-it/conventional-changelog": "
|
|
68
|
-
"@types/react": "
|
|
69
|
-
"@typescript-eslint/eslint-plugin": "
|
|
70
|
-
"@typescript-eslint/parser": "
|
|
71
|
-
"del-cli": "
|
|
72
|
-
"eslint": "
|
|
73
|
-
"eslint-config-prettier": "
|
|
74
|
-
"eslint-plugin-ft-flow": "
|
|
75
|
-
"eslint-plugin-jest": "
|
|
76
|
-
"eslint-plugin-prettier": "
|
|
77
|
-
"eslint-plugin-react-native": "
|
|
78
|
-
"prettier": "
|
|
66
|
+
"@react-native/eslint-config": "0.81.1",
|
|
67
|
+
"@release-it/conventional-changelog": "10.0.1",
|
|
68
|
+
"@types/react": "19.1.0",
|
|
69
|
+
"@typescript-eslint/eslint-plugin": "8.46.2",
|
|
70
|
+
"@typescript-eslint/parser": "8.46.2",
|
|
71
|
+
"del-cli": "6.0.0",
|
|
72
|
+
"eslint": "8.57.1",
|
|
73
|
+
"eslint-config-prettier": "10.1.8",
|
|
74
|
+
"eslint-plugin-ft-flow": "3.0.11",
|
|
75
|
+
"eslint-plugin-jest": "29.0.1",
|
|
76
|
+
"eslint-plugin-prettier": "5.5.4",
|
|
77
|
+
"eslint-plugin-react-native": "5.0.0",
|
|
78
|
+
"prettier": "3.6.2",
|
|
79
79
|
"react": "19.1.0",
|
|
80
80
|
"react-native": "0.81.1",
|
|
81
|
-
"react-native-builder-bob": "
|
|
82
|
-
"release-it": "
|
|
83
|
-
"turbo": "
|
|
84
|
-
"typescript": "
|
|
81
|
+
"react-native-builder-bob": "0.40.13",
|
|
82
|
+
"release-it": "19.0.4",
|
|
83
|
+
"turbo": "2.5.6",
|
|
84
|
+
"typescript": "5.9.2"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"react": "*",
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
"type": "modules",
|
|
137
137
|
"jsSrcsDir": "src",
|
|
138
138
|
"android": {
|
|
139
|
-
"javaPackageName": "
|
|
139
|
+
"javaPackageName": "nl.xguard.flic2"
|
|
140
140
|
}
|
|
141
141
|
},
|
|
142
142
|
"create-react-native-library": {
|
package/src/NativeFlic2.ts
CHANGED
|
@@ -46,22 +46,24 @@ export type ScanStatusChangeEvent = {
|
|
|
46
46
|
result?: ScanResult;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
+
export type ButtonEventName =
|
|
50
|
+
| 'discovered'
|
|
51
|
+
| 'connected'
|
|
52
|
+
| 'ready'
|
|
53
|
+
| 'disconnected'
|
|
54
|
+
| 'connectionFailed'
|
|
55
|
+
| 'buttonDown'
|
|
56
|
+
| 'buttonUp'
|
|
57
|
+
| 'click'
|
|
58
|
+
| 'doubleClick'
|
|
59
|
+
| 'hold'
|
|
60
|
+
| 'unpaired'
|
|
61
|
+
| 'batteryUpdate'
|
|
62
|
+
| 'nicknameUpdate';
|
|
63
|
+
|
|
49
64
|
export type ButtonEvent = {
|
|
50
65
|
uuid: string;
|
|
51
|
-
event:
|
|
52
|
-
| 'discovered'
|
|
53
|
-
| 'connected'
|
|
54
|
-
| 'ready'
|
|
55
|
-
| 'disconnected'
|
|
56
|
-
| 'connectionFailed'
|
|
57
|
-
| 'buttonDown'
|
|
58
|
-
| 'buttonUp'
|
|
59
|
-
| 'click'
|
|
60
|
-
| 'doubleClick'
|
|
61
|
-
| 'hold'
|
|
62
|
-
| 'unpaired'
|
|
63
|
-
| 'batteryUpdate'
|
|
64
|
-
| 'nicknameUpdate';
|
|
66
|
+
event: ButtonEventName;
|
|
65
67
|
queued?: boolean;
|
|
66
68
|
age?: number;
|
|
67
69
|
nickname?: string;
|
|
@@ -133,33 +135,33 @@ export interface Spec extends TurboModule {
|
|
|
133
135
|
// Manager methods
|
|
134
136
|
initialize(
|
|
135
137
|
background: boolean
|
|
136
|
-
): Promise<
|
|
138
|
+
): Promise<void>;
|
|
137
139
|
getButtons(): Promise<FlicButton[]>;
|
|
138
|
-
scanForButtons(): Promise<
|
|
139
|
-
stopScan(): Promise<
|
|
140
|
-
forgetButton(uuid: string): Promise<
|
|
141
|
-
connectAllKnownButtons(): Promise<
|
|
142
|
-
disconnectAllKnownButtons(): Promise<
|
|
143
|
-
forgetAllButtons(): Promise<
|
|
140
|
+
scanForButtons(): Promise<void>;
|
|
141
|
+
stopScan(): Promise<void>;
|
|
142
|
+
forgetButton(uuid: string): Promise<void>;
|
|
143
|
+
connectAllKnownButtons(): Promise<void>;
|
|
144
|
+
disconnectAllKnownButtons(): Promise<void>;
|
|
145
|
+
forgetAllButtons(): Promise<void>;
|
|
144
146
|
isScanning(): Promise<boolean>;
|
|
145
147
|
|
|
146
148
|
// Button methods
|
|
147
|
-
connectButton(uuid: string): Promise<
|
|
149
|
+
connectButton(uuid: string): Promise<FlicButton>;
|
|
148
150
|
disconnectButton(
|
|
149
151
|
uuid: string
|
|
150
|
-
): Promise<
|
|
152
|
+
): Promise<FlicButton>;
|
|
151
153
|
setTriggerMode(
|
|
152
154
|
uuid: string,
|
|
153
|
-
mode:
|
|
154
|
-
): Promise<
|
|
155
|
+
mode: number
|
|
156
|
+
): Promise<FlicButton>;
|
|
155
157
|
setLatencyMode(
|
|
156
158
|
uuid: string,
|
|
157
|
-
mode:
|
|
158
|
-
): Promise<
|
|
159
|
+
mode: number
|
|
160
|
+
): Promise<FlicButton>;
|
|
159
161
|
setNickname(
|
|
160
162
|
uuid: string,
|
|
161
163
|
nickname: string
|
|
162
|
-
): Promise<
|
|
164
|
+
): Promise<FlicButton>;
|
|
163
165
|
|
|
164
166
|
// Event emitters
|
|
165
167
|
readonly onManagerStateChange: CodegenTypes.EventEmitter<ManagerStateChangeEvent>;
|
|
@@ -167,4 +169,49 @@ export interface Spec extends TurboModule {
|
|
|
167
169
|
readonly onButtonEvent: CodegenTypes.EventEmitter<ButtonEvent>;
|
|
168
170
|
}
|
|
169
171
|
|
|
170
|
-
|
|
172
|
+
const createFallbackButton = (uuid: string): FlicButton => ({
|
|
173
|
+
uuid,
|
|
174
|
+
identifier: uuid,
|
|
175
|
+
name: '',
|
|
176
|
+
nickname: '',
|
|
177
|
+
bluetoothAddress: '',
|
|
178
|
+
serialNumber: '',
|
|
179
|
+
state: 0,
|
|
180
|
+
stateName: 'disconnected',
|
|
181
|
+
triggerMode: 0,
|
|
182
|
+
triggerModeName: 'clickAndHold',
|
|
183
|
+
latencyMode: 0,
|
|
184
|
+
latencyModeName: 'normal',
|
|
185
|
+
pressCount: 0,
|
|
186
|
+
firmwareRevision: 0,
|
|
187
|
+
isReady: false,
|
|
188
|
+
batteryVoltage: 0,
|
|
189
|
+
isUnpaired: false,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const fallbackEventEmitter = (() => ({ remove: () => undefined })) as unknown as Spec['onManagerStateChange'];
|
|
193
|
+
|
|
194
|
+
const fallbackModule = {
|
|
195
|
+
initialize: async (_background: boolean) => undefined,
|
|
196
|
+
getButtons: async () => [],
|
|
197
|
+
scanForButtons: async () => undefined,
|
|
198
|
+
stopScan: async () => undefined,
|
|
199
|
+
forgetButton: async (_uuid: string) => undefined,
|
|
200
|
+
connectAllKnownButtons: async () => undefined,
|
|
201
|
+
disconnectAllKnownButtons: async () => undefined,
|
|
202
|
+
forgetAllButtons: async () => undefined,
|
|
203
|
+
isScanning: async () => false,
|
|
204
|
+
connectButton: async (uuid: string) => createFallbackButton(uuid),
|
|
205
|
+
disconnectButton: async (uuid: string) => createFallbackButton(uuid),
|
|
206
|
+
setTriggerMode: async (uuid: string, _mode: number) => createFallbackButton(uuid),
|
|
207
|
+
setLatencyMode: async (uuid: string, _mode: number) => createFallbackButton(uuid),
|
|
208
|
+
setNickname: async (uuid: string, nickname: string) => ({
|
|
209
|
+
...createFallbackButton(uuid),
|
|
210
|
+
nickname,
|
|
211
|
+
}),
|
|
212
|
+
onManagerStateChange: fallbackEventEmitter,
|
|
213
|
+
onScanStatusChange: fallbackEventEmitter as unknown as Spec['onScanStatusChange'],
|
|
214
|
+
onButtonEvent: fallbackEventEmitter as unknown as Spec['onButtonEvent'],
|
|
215
|
+
} as Spec;
|
|
216
|
+
|
|
217
|
+
export default TurboModuleRegistry.get<Spec>('Flic2') ?? fallbackModule;
|
package/src/index.ts
CHANGED
|
@@ -12,13 +12,10 @@ class Flic2 {
|
|
|
12
12
|
|
|
13
13
|
private isFlic2ManagerInitialized: boolean = false;
|
|
14
14
|
|
|
15
|
-
private sessionId: string;
|
|
16
|
-
|
|
17
15
|
public eventEmitter: TypedEmitter<{
|
|
18
16
|
buttonEvent: (event: ButtonEvent) => void;
|
|
19
17
|
managerStateChange: (event: ManagerStateChangeEvent) => void;
|
|
20
18
|
scanStatusChange: (event: ScanStatusChangeEvent) => void;
|
|
21
|
-
managerInitialized: () => void;
|
|
22
19
|
}>;
|
|
23
20
|
|
|
24
21
|
/**
|
|
@@ -29,11 +26,6 @@ class Flic2 {
|
|
|
29
26
|
*/
|
|
30
27
|
constructor() {
|
|
31
28
|
|
|
32
|
-
// generate a random session ID for the instance
|
|
33
|
-
this.sessionId = Math.random().toString(36).substring(2, 15);
|
|
34
|
-
|
|
35
|
-
console.log('Created new Flic2 instance with sessionId', this.sessionId);
|
|
36
|
-
|
|
37
29
|
// create event emitter
|
|
38
30
|
this.eventEmitter = new TypedEmitter<{
|
|
39
31
|
buttonEvent: (event: ButtonEvent) => void;
|
|
@@ -57,7 +49,7 @@ class Flic2 {
|
|
|
57
49
|
*
|
|
58
50
|
* @returns A promise that resolves when the Flic2 manager is initialized.
|
|
59
51
|
*/
|
|
60
|
-
public async initialize(): Promise<
|
|
52
|
+
public async initialize(): Promise<void> {
|
|
61
53
|
|
|
62
54
|
// check if the Flic2 manager is already initialized
|
|
63
55
|
if (this.isInitialized()) {
|
|
@@ -67,18 +59,10 @@ class Flic2 {
|
|
|
67
59
|
}
|
|
68
60
|
|
|
69
61
|
// initialize the Flic2 manager in background
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (!result.success) {
|
|
73
|
-
|
|
74
|
-
throw new Error(result.message);
|
|
75
|
-
|
|
76
|
-
}
|
|
62
|
+
await NativeFlic2.initialize(true);
|
|
77
63
|
|
|
78
64
|
this.onInitialized();
|
|
79
65
|
|
|
80
|
-
return true;
|
|
81
|
-
|
|
82
66
|
}
|
|
83
67
|
|
|
84
68
|
/**
|
|
@@ -86,7 +70,7 @@ class Flic2 {
|
|
|
86
70
|
*
|
|
87
71
|
* @returns A promise that resolves when the scan is started. Events will be emitted for the scan process.
|
|
88
72
|
*/
|
|
89
|
-
public startScan(): Promise<
|
|
73
|
+
public startScan(): Promise<void> {
|
|
90
74
|
|
|
91
75
|
return NativeFlic2.scanForButtons();
|
|
92
76
|
|
|
@@ -97,7 +81,7 @@ class Flic2 {
|
|
|
97
81
|
*
|
|
98
82
|
* @returns A promise that resolves when the scan is stopped.
|
|
99
83
|
*/
|
|
100
|
-
public stopScan(): Promise<
|
|
84
|
+
public stopScan(): Promise<void> {
|
|
101
85
|
|
|
102
86
|
return NativeFlic2.stopScan();
|
|
103
87
|
|
|
@@ -128,10 +112,7 @@ class Flic2 {
|
|
|
128
112
|
*
|
|
129
113
|
* @returns A promise that resolves when the all known buttons are connected.
|
|
130
114
|
*/
|
|
131
|
-
public connectAllKnownButtons(): Promise<{
|
|
132
|
-
success: boolean;
|
|
133
|
-
message: string;
|
|
134
|
-
}> {
|
|
115
|
+
public connectAllKnownButtons(): Promise<void> {
|
|
135
116
|
|
|
136
117
|
return NativeFlic2.connectAllKnownButtons();
|
|
137
118
|
|
|
@@ -142,10 +123,7 @@ class Flic2 {
|
|
|
142
123
|
*
|
|
143
124
|
* @returns A promise that resolves when the all known buttons are disconnected.
|
|
144
125
|
*/
|
|
145
|
-
public disconnectAllKnownButtons(): Promise<{
|
|
146
|
-
success: boolean;
|
|
147
|
-
message: string;
|
|
148
|
-
}> {
|
|
126
|
+
public disconnectAllKnownButtons(): Promise<void> {
|
|
149
127
|
|
|
150
128
|
return NativeFlic2.disconnectAllKnownButtons();
|
|
151
129
|
|
|
@@ -156,7 +134,7 @@ class Flic2 {
|
|
|
156
134
|
*
|
|
157
135
|
* @returns A promise that resolves when the all buttons are forgotten.
|
|
158
136
|
*/
|
|
159
|
-
public forgetAllButtons(): Promise<
|
|
137
|
+
public forgetAllButtons(): Promise<void> {
|
|
160
138
|
|
|
161
139
|
return NativeFlic2.forgetAllButtons();
|
|
162
140
|
|
|
@@ -181,7 +159,7 @@ class Flic2 {
|
|
|
181
159
|
*/
|
|
182
160
|
public forgetButton(
|
|
183
161
|
uuid: string
|
|
184
|
-
): Promise<
|
|
162
|
+
): Promise<void> {
|
|
185
163
|
|
|
186
164
|
return NativeFlic2.forgetButton(uuid);
|
|
187
165
|
|
|
@@ -192,11 +170,11 @@ class Flic2 {
|
|
|
192
170
|
* Connect a button.
|
|
193
171
|
*
|
|
194
172
|
* @param uuid - The UUID of the button to connect.
|
|
195
|
-
* @returns A promise that resolves
|
|
173
|
+
* @returns A promise that resolves with the button when the connection is initiated.
|
|
196
174
|
*/
|
|
197
175
|
public buttonConnect(
|
|
198
176
|
uuid: string
|
|
199
|
-
): Promise<
|
|
177
|
+
): Promise<FlicButton> {
|
|
200
178
|
|
|
201
179
|
return NativeFlic2.connectButton(uuid);
|
|
202
180
|
|
|
@@ -206,11 +184,11 @@ class Flic2 {
|
|
|
206
184
|
* Disconnect a button.
|
|
207
185
|
*
|
|
208
186
|
* @param uuid - The UUID of the button to disconnect.
|
|
209
|
-
* @returns A promise that resolves
|
|
187
|
+
* @returns A promise that resolves with the button when the disconnection is initiated.
|
|
210
188
|
*/
|
|
211
189
|
public buttonDisconnect(
|
|
212
190
|
uuid: string
|
|
213
|
-
): Promise<
|
|
191
|
+
): Promise<FlicButton> {
|
|
214
192
|
|
|
215
193
|
return NativeFlic2.disconnectButton(uuid);
|
|
216
194
|
|
|
@@ -221,12 +199,12 @@ class Flic2 {
|
|
|
221
199
|
*
|
|
222
200
|
* @param uuid - The UUID of the button to set the trigger mode of.
|
|
223
201
|
* @param mode - The trigger mode to set.
|
|
224
|
-
* @returns A promise that resolves when the trigger mode is set.
|
|
202
|
+
* @returns A promise that resolves with the button when the trigger mode is set.
|
|
225
203
|
*/
|
|
226
204
|
public buttonSetTriggerMode(
|
|
227
205
|
uuid: string,
|
|
228
206
|
mode: TriggerModeType
|
|
229
|
-
): Promise<
|
|
207
|
+
): Promise<FlicButton> {
|
|
230
208
|
|
|
231
209
|
return NativeFlic2.setTriggerMode(uuid, mode);
|
|
232
210
|
|
|
@@ -237,12 +215,12 @@ class Flic2 {
|
|
|
237
215
|
*
|
|
238
216
|
* @param uuid - The UUID of the button to set the latency mode of.
|
|
239
217
|
* @param mode - The latency mode to set.
|
|
240
|
-
* @returns A promise that resolves when the latency mode is set.
|
|
218
|
+
* @returns A promise that resolves with the button when the latency mode is set.
|
|
241
219
|
*/
|
|
242
220
|
public buttonSetLatencyMode(
|
|
243
221
|
uuid: string,
|
|
244
222
|
mode: LatencyModeType
|
|
245
|
-
): Promise<
|
|
223
|
+
): Promise<FlicButton> {
|
|
246
224
|
|
|
247
225
|
return NativeFlic2.setLatencyMode(uuid, mode);
|
|
248
226
|
|
|
@@ -253,12 +231,12 @@ class Flic2 {
|
|
|
253
231
|
*
|
|
254
232
|
* @param uuid - The UUID of the button to set the nickname of.
|
|
255
233
|
* @param nickname - The nickname to set.
|
|
256
|
-
* @returns A promise that resolves when the nickname is set.
|
|
234
|
+
* @returns A promise that resolves with the button when the nickname is set.
|
|
257
235
|
*/
|
|
258
236
|
public buttonSetNickname(
|
|
259
237
|
uuid: string,
|
|
260
238
|
nickname: string
|
|
261
|
-
): Promise<
|
|
239
|
+
): Promise<FlicButton> {
|
|
262
240
|
|
|
263
241
|
return NativeFlic2.setNickname(uuid, nickname);
|
|
264
242
|
|
|
@@ -358,6 +336,13 @@ class Flic2 {
|
|
|
358
336
|
*/
|
|
359
337
|
private onNativeManagerStateChange(event: ManagerStateChangeEvent): void {
|
|
360
338
|
|
|
339
|
+
// When manager is restored, mark it as initialized
|
|
340
|
+
if (event.event === 'restored' && !this.isFlic2ManagerInitialized) {
|
|
341
|
+
|
|
342
|
+
this.onInitialized();
|
|
343
|
+
|
|
344
|
+
}
|
|
345
|
+
|
|
361
346
|
this.eventEmitter.emit('managerStateChange', event);
|
|
362
347
|
|
|
363
348
|
}
|