react-native-gizwits-sdk-v5 1.6.2 → 1.6.3

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/.idea/misc.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager">
4
+ <output url="file://$PROJECT_DIR$/out" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/react-native-gizwits-sdk-v5.iml" filepath="$PROJECT_DIR$/.idea/react-native-gizwits-sdk-v5.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="inheritedJdk" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ </component>
9
+ </module>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,52 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="AutoImportSettings">
4
+ <option name="autoReloadType" value="NONE" />
5
+ </component>
6
+ <component name="ChangeListManager">
7
+ <list default="true" id="b2b95988-cfb1-4e9d-bf79-69c05c12f4d5" name="Changes" comment="">
8
+ <change beforePath="$PROJECT_DIR$/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizDeviceManagerModule.kt" beforeDir="false" afterPath="$PROJECT_DIR$/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizDeviceManagerModule.kt" afterDir="false" />
9
+ </list>
10
+ <option name="SHOW_DIALOG" value="false" />
11
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
12
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
13
+ <option name="LAST_RESOLUTION" value="IGNORE" />
14
+ </component>
15
+ <component name="ClangdSettings">
16
+ <option name="formatViaClangd" value="false" />
17
+ </component>
18
+ <component name="Git.Settings">
19
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
20
+ </component>
21
+ <component name="ProjectColorInfo"><![CDATA[{
22
+ "associatedIndex": 6
23
+ }]]></component>
24
+ <component name="ProjectId" id="36H1NmpF6OqIomV64QR0jdAkvwL" />
25
+ <component name="ProjectViewState">
26
+ <option name="hideEmptyMiddlePackages" value="true" />
27
+ <option name="showLibraryContents" value="true" />
28
+ </component>
29
+ <component name="PropertiesComponent"><![CDATA[{
30
+ "keyToString": {
31
+ "ModuleVcsDetector.initialDetectionPerformed": "true",
32
+ "RunOnceActivity.ShowReadmeOnStart": "true",
33
+ "RunOnceActivity.cidr.known.project.marker": "true",
34
+ "RunOnceActivity.git.unshallow": "true",
35
+ "RunOnceActivity.readMode.enableVisualFormatting": "true",
36
+ "cf.first.check.clang-format": "false",
37
+ "cidr.known.project.marker": "true",
38
+ "git-widget-placeholder": "feature/rongwei",
39
+ "last_opened_file_path": "/Users/roc/Documents/Code/Gizwits/iot-sdk/react-native-gizwits-sdk-v5"
40
+ }
41
+ }]]></component>
42
+ <component name="TaskManager">
43
+ <task active="true" id="Default" summary="Default task">
44
+ <changelist id="b2b95988-cfb1-4e9d-bf79-69c05c12f4d5" name="Changes" comment="" />
45
+ <created>1764648644343</created>
46
+ <option name="number" value="Default" />
47
+ <option name="presentableId" value="Default" />
48
+ <updated>1764648644343</updated>
49
+ </task>
50
+ <servers />
51
+ </component>
52
+ </project>
package/.prettierrc.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ jsxSingleQuote: true,
3
+ semi: false,
4
+ singleQuote: true,
5
+ }
Binary file
@@ -67,10 +67,10 @@ dependencies {
67
67
  // ESPTouch
68
68
  implementation 'com.github.EspressifApp:lib-esptouch-android:1.1.1'
69
69
 
70
- implementation("io.github.gizwits:sdk:1.4.3")
71
- implementation("io.github.gizwits:sdk-bluetooth:1.4.3")
72
- implementation("io.github.gizwits:sdk-lan:1.4.3")
73
- implementation("io.github.gizwits:sdk-mqtt:1.4.3")
70
+ implementation("io.github.gizwits:sdk:1.4.4")
71
+ implementation("io.github.gizwits:sdk-bluetooth:1.4.4")
72
+ implementation("io.github.gizwits:sdk-lan:1.4.4")
73
+ implementation("io.github.gizwits:sdk-mqtt:1.4.4")
74
74
  // implementation files('libs/sdk-release.aar', 'libs/sdk-bluetooth-release.aar', 'libs/sdk-lan-release.aar', 'libs/sdk-mqtt-release.aar')
75
75
  implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutine_version")
76
76
  // retrofit
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ presets: ['module:metro-react-native-babel-preset'],
3
+ }
package/ios/.DS_Store ADDED
Binary file
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>SchemeUserState</key>
6
+ <dict>
7
+ <key>RNGizSDKManagerModule.xcscheme_^#shared#^_</key>
8
+ <dict>
9
+ <key>orderHint</key>
10
+ <integer>0</integer>
11
+ </dict>
12
+ </dict>
13
+ </dict>
14
+ </plist>
package/lib/types.d.ts CHANGED
@@ -55,9 +55,10 @@ export interface GizBaseProfile {
55
55
  export type BlueToothType = 'Mesh' | 'Beacon' | 'Voice' | 'GATT';
56
56
  export type BlueToothVersion = 'BLE4' | 'BLE42' | 'BLE50';
57
57
  export type NetStatus = 0 | 1 | 2;
58
- export type GizWiFiActivatorEventType = 'START_WIFI_CONFIG' | 'START_CONNECT_DEVICE' | 'CONNECT_DEVICE_SUCCESS' | 'CONNECT_DEVICE_FAIL' | 'START_SEND_WIFI_CONFIG' | 'START_SEND_WIFI_CONFIG_SUCCESS' | 'START_SEND_WIFI_CONFIG_FAIL' | 'WIFI_CONFIG_RECV_SUCCESS' | 'START_SEARCH_RANDOM_CODE' | 'START_SEARCH_RANDOM_CODE_SUCCESS' | 'WIFI_CONFIG_SUCCESS' | 'WIFI_CONFIG_CANCEL' | 'WIFI_CONFIG_FAIL';
58
+ export type GizWiFiActivatorEventTypeAndroid = 'START_WIFI_CONFIG' | 'START_CONNECT_DEVICE' | 'CONNECT_DEVICE_SUCCESS' | 'CONNECT_DEVICE_FAIL' | 'START_SEND_WIFI_CONFIG' | 'START_SEND_WIFI_CONFIG_SUCCESS' | 'START_SEND_WIFI_CONFIG_FAIL' | 'WIFI_CONFIG_RECV_SUCCESS' | 'START_SEARCH_RANDOM_CODE' | 'START_SEARCH_RANDOM_CODE_SUCCESS' | 'WIFI_CONFIG_SUCCESS' | 'WIFI_CONFIG_CANCEL' | 'WIFI_CONFIG_FAIL';
59
+ export type GizWiFiActivatorEventTypeiOS = 1000 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1001 | 1011 | 1012 | 1013 | 1014 | 1015;
59
60
  export interface GizWiFiActivatorEvent {
60
- data: GizWiFiActivatorEventType;
61
+ data: GizWiFiActivatorEventTypeAndroid | GizWiFiActivatorEventTypeiOS;
61
62
  }
62
63
  export interface GizLanProfile extends GizBaseProfile {
63
64
  ip: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gizwits-sdk-v5",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "Gizwits",
5
5
  "homepage": "https://github.com/demchenkoalex/react-native-gizwits-sdk-v5#readme",
6
6
  "main": "lib/index.js",
package/src/Base.tsx ADDED
@@ -0,0 +1,28 @@
1
+ import { GizCallback, GizResult } from './types'
2
+
3
+ class Base {
4
+ callbackWapper(
5
+ func: (callback: GizCallback<any, any>) => void
6
+ ): Promise<GizResult<any, any>> {
7
+ const promise = new Promise((res, _) => {
8
+ func((error, data) => {
9
+ if (error) {
10
+ res(error)
11
+ } else {
12
+ res(data)
13
+ }
14
+ })
15
+ })
16
+
17
+ return promise as Promise<GizResult<any, any>>
18
+ }
19
+
20
+ deleteCallBack = (callbacks: any[], callback: any) => {
21
+ const index = callbacks.findIndex((item) => item === callback)
22
+ if (index !== -1) {
23
+ callbacks.splice(index, 1)
24
+ }
25
+ }
26
+ }
27
+
28
+ export default Base
@@ -0,0 +1,5 @@
1
+ import { addOne } from '../index'
2
+
3
+ test('addOne', () => {
4
+ expect(addOne(0)).toEqual(1)
5
+ })
package/src/device.tsx ADDED
@@ -0,0 +1,314 @@
1
+ import { NativeEventEmitter, NativeModules } from 'react-native'
2
+
3
+ import Base from './Base'
4
+ import {
5
+ GizCallback,
6
+ GizCapability,
7
+ GizDeviceData,
8
+ GizDeviceInfoProfile,
9
+ GizOTAFirmwareType,
10
+ GizOtaProgressCallback,
11
+ GizOtaProgressEventCallback,
12
+ GizProvideWiFiCredentialsCallback,
13
+ GizResult,
14
+ GizMusicalRhythmCallback,
15
+ MusicalRhythmParseMode,
16
+ GizLightDanceDataEvent,
17
+ } from './types'
18
+ const eventEmitter = new NativeEventEmitter(
19
+ NativeModules.RNGizDeviceManagerModule
20
+ )
21
+
22
+ class RNGizDeviceManagerModule extends Base {
23
+ otaEventCallbacks: GizOtaProgressEventCallback[] = []
24
+ provideWiFiCredentialsCallbacks: GizProvideWiFiCredentialsCallback[] = []
25
+ musicalRhythmCallbacks: { [keyof: string]: GizMusicalRhythmCallback } = {}
26
+
27
+ constructor() {
28
+ super()
29
+ eventEmitter.addListener('GizOTAProgressEvent', this.otaEventCallback)
30
+ eventEmitter.addListener(
31
+ 'GizProvideWiFiCredentialsEvent',
32
+ this.provideWiFiCredentialsCallback
33
+ )
34
+ eventEmitter.addListener(
35
+ 'GizMusicalRhythmEvnet',
36
+ this.musicalRhythmCallback
37
+ )
38
+ }
39
+
40
+ otaEventCallback: GizOtaProgressEventCallback = (data) => {
41
+ this.otaEventCallbacks.map((item) => {
42
+ item(data)
43
+ })
44
+ }
45
+ provideWiFiCredentialsCallback: GizProvideWiFiCredentialsCallback = (
46
+ data
47
+ ) => {
48
+ this.provideWiFiCredentialsCallbacks.map((item) => {
49
+ item(data)
50
+ })
51
+ }
52
+
53
+ musicalRhythmCallback: GizMusicalRhythmCallback = ({ deviceID, data }) => {
54
+ const callback = this.musicalRhythmCallbacks[deviceID]
55
+ if (callback) {
56
+ callback({ deviceID, data })
57
+ }
58
+ }
59
+
60
+ sendDp(
61
+ id: string,
62
+ type: GizCapability,
63
+ data: Object
64
+ ): Promise<GizResult<GizDeviceData, any>> {
65
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
66
+ const dataString = JSON.stringify(data)
67
+ NativeModules.RNGizDeviceManagerModule.sendDp(
68
+ {
69
+ id,
70
+ type,
71
+ data: dataString,
72
+ },
73
+ callback
74
+ )
75
+ })
76
+ }
77
+ getDp(
78
+ id: string,
79
+ type: GizCapability,
80
+ attrs?: string[]
81
+ ): Promise<GizResult<GizDeviceData, any>> {
82
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
83
+ NativeModules.RNGizDeviceManagerModule.getDp(
84
+ {
85
+ id,
86
+ type,
87
+ attrs,
88
+ },
89
+ callback
90
+ )
91
+ })
92
+ }
93
+
94
+ getDeviceInfo(
95
+ id: string,
96
+ type: GizCapability
97
+ ): Promise<GizResult<GizDeviceInfoProfile, any>> {
98
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
99
+ NativeModules.RNGizDeviceManagerModule.getDeviceInfo(
100
+ {
101
+ id,
102
+ type,
103
+ },
104
+ callback
105
+ )
106
+ })
107
+ }
108
+
109
+ connect(id: string, type: GizCapability): Promise<GizResult<any, any>> {
110
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
111
+ NativeModules.RNGizDeviceManagerModule.connect(
112
+ {
113
+ id,
114
+ type,
115
+ },
116
+ callback
117
+ )
118
+ })
119
+ }
120
+ disConnect(id: string, type: GizCapability): Promise<GizResult<any, any>> {
121
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
122
+ NativeModules.RNGizDeviceManagerModule.disConnect(
123
+ {
124
+ id,
125
+ type,
126
+ },
127
+ callback
128
+ )
129
+ })
130
+ }
131
+
132
+ updateDeviceInfo(
133
+ id: string,
134
+ alias?: string,
135
+ remark?: string
136
+ ): Promise<GizResult<any, any>> {
137
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
138
+ NativeModules.RNGizDeviceManagerModule.updateDeviceInfo(
139
+ {
140
+ id,
141
+ alias,
142
+ remark,
143
+ },
144
+ callback
145
+ )
146
+ })
147
+ }
148
+
149
+ bind(
150
+ id: string,
151
+ alias?: string,
152
+ remark?: string
153
+ ): Promise<GizResult<any, any>> {
154
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
155
+ NativeModules.RNGizDeviceManagerModule.bind(
156
+ {
157
+ id,
158
+ alias,
159
+ remark,
160
+ },
161
+ callback
162
+ )
163
+ })
164
+ }
165
+ unBind(id: string): Promise<GizResult<any, any>> {
166
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
167
+ NativeModules.RNGizDeviceManagerModule.unBind(
168
+ {
169
+ id,
170
+ },
171
+ callback
172
+ )
173
+ })
174
+ }
175
+ register(id: string): Promise<GizResult<any, any>> {
176
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
177
+ NativeModules.RNGizDeviceManagerModule.register(
178
+ {
179
+ id,
180
+ },
181
+ callback
182
+ )
183
+ })
184
+ }
185
+ checkUpdate(
186
+ id: string,
187
+ type: GizCapability,
188
+ firmwareType: GizOTAFirmwareType
189
+ ): Promise<GizResult<any, any>> {
190
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
191
+ NativeModules.RNGizDeviceManagerModule.checkUpdate(
192
+ {
193
+ id,
194
+ type,
195
+ firmwareType,
196
+ },
197
+ callback
198
+ )
199
+ })
200
+ }
201
+
202
+ async startUpgrade(
203
+ id: string,
204
+ type: GizCapability,
205
+ firmwareType: GizOTAFirmwareType,
206
+ callback: GizOtaProgressCallback
207
+ ): Promise<GizResult<any, any>> {
208
+ // 注册监听
209
+ const wapperCallback: GizOtaProgressEventCallback = ({ data }) => {
210
+ callback(data)
211
+ }
212
+ this.otaEventCallbacks.push(wapperCallback)
213
+ const data = await this.callbackWapper(
214
+ (callback: GizCallback<any, any>) => {
215
+ NativeModules.RNGizDeviceManagerModule.startUpgrade(
216
+ {
217
+ id,
218
+ type,
219
+ firmwareType,
220
+ },
221
+ callback
222
+ )
223
+ }
224
+ )
225
+ // OTA结束,销毁监听
226
+ this.deleteCallBack(this.otaEventCallbacks, wapperCallback)
227
+ return data
228
+ }
229
+
230
+ async provideWiFiCredentials(
231
+ id: string,
232
+ type: GizCapability,
233
+ ssid: string,
234
+ password: string,
235
+ timeout: number,
236
+ processHandler: GizProvideWiFiCredentialsCallback,
237
+ bindWithUid?: boolean
238
+ ): Promise<GizResult<any, any>> {
239
+ const wapperCallback: GizProvideWiFiCredentialsCallback = (data) => {
240
+ processHandler(data)
241
+ }
242
+ this.provideWiFiCredentialsCallbacks.push(wapperCallback)
243
+ const data = await this.callbackWapper(
244
+ (callback: GizCallback<any, any>) => {
245
+ NativeModules.RNGizDeviceManagerModule.provideWiFiCredentials(
246
+ {
247
+ id,
248
+ type,
249
+ ssid,
250
+ password,
251
+ timeout,
252
+ bindWithUid: bindWithUid ?? false,
253
+ },
254
+ callback
255
+ )
256
+ }
257
+ )
258
+ this.deleteCallBack(this.provideWiFiCredentialsCallbacks, wapperCallback)
259
+ return data
260
+ }
261
+
262
+ async stopProvideWiFiCredentials(
263
+ id: string,
264
+ type: GizCapability
265
+ ): Promise<GizResult<any, any>> {
266
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
267
+ NativeModules.RNGizDeviceManagerModule.stopProvideWiFiCredentials(
268
+ {
269
+ id,
270
+ type,
271
+ },
272
+ callback
273
+ )
274
+ })
275
+ }
276
+
277
+ async startMusicalRhythm(
278
+ id: string,
279
+ sensitivity: number,
280
+ mode: MusicalRhythmParseMode,
281
+ onData?: GizMusicalRhythmCallback
282
+ ): Promise<GizResult<any, any>> {
283
+ if (!!onData) {
284
+ this.musicalRhythmCallbacks[id] = onData
285
+ }
286
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
287
+ NativeModules.RNGizDeviceManagerModule.startMusicalRhythm(
288
+ {
289
+ id,
290
+ sensitivity,
291
+ mode,
292
+ needMonitor: !!onData,
293
+ },
294
+ callback
295
+ )
296
+ })
297
+ }
298
+ async stopMusicalRhythm(id: string): Promise<GizResult<any, any>> {
299
+ delete this.musicalRhythmCallbacks[id]
300
+
301
+ return this.callbackWapper((callback: GizCallback<any, any>) => {
302
+ NativeModules.RNGizDeviceManagerModule.stopMusicalRhythm(
303
+ {
304
+ id,
305
+ },
306
+ callback
307
+ )
308
+ })
309
+ }
310
+ }
311
+
312
+ export default new RNGizDeviceManagerModule()
313
+
314
+ export { RNGizDeviceManagerModule }