react-native-gizwits-sdk-v5 0.1.0-rongwei
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 +21 -0
- package/README.md +56 -0
- package/android/build.gradle +86 -0
- package/android/lib/sdk-bluetooth-release.aar +0 -0
- package/android/lib/sdk-lan-release.aar +0 -0
- package/android/lib/sdk-mqtt-release.aar +0 -0
- package/android/lib/sdk-release.aar +0 -0
- package/android/src/main/AndroidManifest.xml +23 -0
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/GizRNCallbackManager.kt +120 -0
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizDeviceManagerModule.kt +416 -0
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizParamsChecker.kt +58 -0
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizSDKManagerModule.kt +375 -0
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizSDKManagerPackage.kt +24 -0
- package/android/src/main/java/com/gizwits/reactnativegizwitssdkv5/RNGizUserManagerModule.kt +86 -0
- package/ios/GizRNCallbackManager.swift +31 -0
- package/ios/RNGizDeviceManagerModule-Bridging-Header.h +5 -0
- package/ios/RNGizDeviceManagerModule.m +26 -0
- package/ios/RNGizDeviceManagerModule.swift +479 -0
- package/ios/RNGizParamsChecker.swift +28 -0
- package/ios/RNGizSDKManagerModule-Bridging-Header.h +5 -0
- package/ios/RNGizSDKManagerModule.m +20 -0
- package/ios/RNGizSDKManagerModule.swift +139 -0
- package/ios/RNGizSDKManagerModule.xcodeproj/project.pbxproj +314 -0
- package/ios/RNGizUserManagerModule-Bridging-Header.h +5 -0
- package/ios/RNGizUserManagerModule.m +20 -0
- package/ios/RNGizUserManagerModule.swift +84 -0
- package/lib/Base.d.ts +6 -0
- package/lib/Base.js +25 -0
- package/lib/Base.js.map +1 -0
- package/lib/device.d.ts +25 -0
- package/lib/device.js +151 -0
- package/lib/device.js.map +1 -0
- package/lib/index.d.ts +39 -0
- package/lib/index.js +232 -0
- package/lib/index.js.map +1 -0
- package/lib/types.d.ts +155 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/user.d.ts +13 -0
- package/lib/user.js +37 -0
- package/lib/user.js.map +1 -0
- package/package.json +73 -0
- package/react-native-gizwits-sdk-v5.podspec +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Gizwits
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# API 文档
|
|
2
|
+
|
|
3
|
+
[API文档](https://sdkdoc.gizwits.com/rn/basic)
|
|
4
|
+
|
|
5
|
+
# 基本概念
|
|
6
|
+
|
|
7
|
+
## 设备对象
|
|
8
|
+
根据通讯方式来区分,模组有以下几种通讯方式
|
|
9
|
+
|
|
10
|
+
* 蓝牙
|
|
11
|
+
* 局域网
|
|
12
|
+
* mqtt
|
|
13
|
+
|
|
14
|
+
对应的,在SDK,设备就衍生出了三种能力
|
|
15
|
+
|
|
16
|
+
* bleCapability
|
|
17
|
+
* lanCapability
|
|
18
|
+
* mqttCapability
|
|
19
|
+
|
|
20
|
+

|
|
21
|
+
|
|
22
|
+
这三个能力都继承于 BaseCapability,都实现了控制、连接等功能。在开发的过程中您可以自由的选择连接某个通道,对某个通道下发指令。
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
// ble
|
|
26
|
+
await device.bleCapability.connect()
|
|
27
|
+
device.bleCapability.getDp()
|
|
28
|
+
|
|
29
|
+
// mqtt
|
|
30
|
+
await device.mqttCapability.connect()
|
|
31
|
+
device.mqttCapability.getDp()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 连接的云服务
|
|
35
|
+
初始化sdk的时候,您可以手动选择连接的云
|
|
36
|
+
* api.gizwits.com 大陆
|
|
37
|
+
* euapi.gizwits.com 欧洲地区
|
|
38
|
+
* usapi.gizwits.com 美东地区
|
|
39
|
+
```javascript
|
|
40
|
+
import RNGizSDKManagerModule from 'react-native-gizwits-sdk-v5';
|
|
41
|
+
let data = await RNGizSDKManagerModule.initSDK({
|
|
42
|
+
appID: 'xxx',
|
|
43
|
+
appSecret: 'xxx',
|
|
44
|
+
productInfos: [
|
|
45
|
+
{
|
|
46
|
+
productKey: 'xxx',
|
|
47
|
+
productSecret: 'xxx',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
serverInfo: {
|
|
51
|
+
openAPIInfo: "api.gizwits.com"
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
如果不填写,将会按照客户端所在的地区自动选择
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.safeExtGet = { prop, fallback ->
|
|
3
|
+
return rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
4
|
+
}
|
|
5
|
+
ext {
|
|
6
|
+
gson_version = '2.9.1'
|
|
7
|
+
startup_version = '1.1.1'
|
|
8
|
+
kotlin_coroutine_version = '1.6.4'
|
|
9
|
+
retrofit_version = '2.9.0'
|
|
10
|
+
room_version = '2.5.0'
|
|
11
|
+
mqtt_version = '1.2.5'
|
|
12
|
+
ktor_network_version = '2.1.0'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
repositories {
|
|
16
|
+
google()
|
|
17
|
+
mavenCentral()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
dependencies {
|
|
21
|
+
classpath 'com.android.tools.build:gradle:7.0.4'
|
|
22
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', '1.8.0')}"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def safeExtGet(prop, fallback) {
|
|
27
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
apply plugin: 'com.android.library'
|
|
31
|
+
apply plugin: 'kotlin-android'
|
|
32
|
+
|
|
33
|
+
android {
|
|
34
|
+
namespace 'com.gizwits.reactnativegizwitssdkv5'
|
|
35
|
+
compileSdkVersion safeExtGet('compileSdkVersion', 34)
|
|
36
|
+
buildToolsVersion safeExtGet('buildToolsVersion', '33.0.0')
|
|
37
|
+
|
|
38
|
+
defaultConfig {
|
|
39
|
+
minSdkVersion safeExtGet('minSdkVersion', 26)
|
|
40
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 34)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// compileOptions {
|
|
44
|
+
// sourceCompatibility JavaVersion.VERSION_11
|
|
45
|
+
// targetCompatibility JavaVersion.VERSION_11
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
// kotlinOptions {
|
|
49
|
+
// jvmTarget = '11'
|
|
50
|
+
// }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
repositories {
|
|
54
|
+
google()
|
|
55
|
+
mavenCentral()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
dependencies {
|
|
59
|
+
//noinspection GradleDynamicVersion
|
|
60
|
+
implementation 'com.facebook.react:react-native:+'
|
|
61
|
+
|
|
62
|
+
implementation 'com.jakewharton.timber:timber:5.0.1'
|
|
63
|
+
implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:$mqtt_version"
|
|
64
|
+
|
|
65
|
+
implementation "androidx.startup:startup-runtime:$startup_version"
|
|
66
|
+
|
|
67
|
+
// implementation("io.github.gizwits:sdk:1.0.0-rongwei")
|
|
68
|
+
// implementation("io.github.gizwits:sdk-bluetooth:1.0.0-rongwei")
|
|
69
|
+
// implementation("io.github.gizwits:sdk-lan:1.0.0-rongwei")
|
|
70
|
+
// implementation("io.github.gizwits:sdk-mqtt:1.0.0-rongwei")
|
|
71
|
+
implementation("libs/sdk-release.aar", { ext: 'aar' })
|
|
72
|
+
implementation("libs/sdk-bluetooth-release.aar", { ext: 'aar' })
|
|
73
|
+
implementation("libs/sdk-lan-release.aar", { ext: 'aar' })
|
|
74
|
+
implementation("libs/sdk-mqtt-release.aar", { ext: 'aar' })
|
|
75
|
+
// implementation files('libs/sdk-release.aar', 'libs/sdk-bluetooth-release.aar', 'libs/sdk-lan-release.aar', 'libs/sdk-mqtt-release.aar')
|
|
76
|
+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutine_version")
|
|
77
|
+
// retrofit
|
|
78
|
+
implementation("com.squareup.retrofit2:retrofit:$retrofit_version")
|
|
79
|
+
implementation("com.squareup.retrofit2:converter-gson:$retrofit_version")
|
|
80
|
+
implementation("com.squareup.retrofit2:converter-scalars:$retrofit_version")
|
|
81
|
+
// gson
|
|
82
|
+
implementation("com.google.code.gson:gson:$gson_version")
|
|
83
|
+
//ktor
|
|
84
|
+
implementation "io.ktor:ktor-network:$ktor_network_version"
|
|
85
|
+
|
|
86
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
package="com.gizwits.reactnativegizwitssdkv5" xmlns:tools="http://schemas.android.com/tools">
|
|
3
|
+
|
|
4
|
+
<uses-permission android:name="android.permission.INTERNET"/>
|
|
5
|
+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
|
6
|
+
<uses-permission
|
|
7
|
+
android:name="android.permission.BLUETOOTH"
|
|
8
|
+
android:maxSdkVersion="30"/>
|
|
9
|
+
<uses-permission
|
|
10
|
+
android:name="android.permission.BLUETOOTH_ADMIN"
|
|
11
|
+
android:maxSdkVersion="30"/>
|
|
12
|
+
<uses-permission
|
|
13
|
+
android:name="android.permission.BLUETOOTH_SCAN"
|
|
14
|
+
android:usesPermissionFlags="neverForLocation"
|
|
15
|
+
tools:targetApi="s" />
|
|
16
|
+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
|
|
17
|
+
|
|
18
|
+
<application>
|
|
19
|
+
<meta-data
|
|
20
|
+
android:name="io.sentry.auto-init"
|
|
21
|
+
android:value="false" />
|
|
22
|
+
</application>
|
|
23
|
+
</manifest>
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
package com.gizwits.reactnativegizwitssdkv5
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.Callback
|
|
5
|
+
import com.facebook.react.bridge.WritableArray
|
|
6
|
+
import com.facebook.react.bridge.WritableMap
|
|
7
|
+
import com.gizwits.smart.sdk.exception.GizException
|
|
8
|
+
import com.google.gson.Gson
|
|
9
|
+
import com.google.gson.annotations.SerializedName
|
|
10
|
+
import com.google.gson.reflect.TypeToken
|
|
11
|
+
import org.json.JSONArray
|
|
12
|
+
import org.json.JSONException
|
|
13
|
+
import org.json.JSONObject
|
|
14
|
+
|
|
15
|
+
class GizResult<T> {
|
|
16
|
+
@SerializedName("success")
|
|
17
|
+
var success = false;
|
|
18
|
+
@SerializedName("data")
|
|
19
|
+
var data: T? = null
|
|
20
|
+
@SerializedName("error")
|
|
21
|
+
var error: Number? = null
|
|
22
|
+
@SerializedName("message")
|
|
23
|
+
var message: String = ""
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
object GizRNCallbackManager {
|
|
27
|
+
|
|
28
|
+
fun <T> callbackWithResult(callback: Callback, result: Result<T>) {
|
|
29
|
+
var data = GizResult<T>();
|
|
30
|
+
if (result.isSuccess) {
|
|
31
|
+
data.success = true
|
|
32
|
+
data.data = result.getOrNull()
|
|
33
|
+
} else {
|
|
34
|
+
data.success = false
|
|
35
|
+
result.exceptionOrNull()?.let {
|
|
36
|
+
try {
|
|
37
|
+
data.error = (it as GizException).errorCode
|
|
38
|
+
data.message = (it as GizException).localizedMessage
|
|
39
|
+
} catch (e: Exception) {
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
val resultData = convertToMap(data)
|
|
45
|
+
if (result.isSuccess) {
|
|
46
|
+
callback.invoke(null, resultData)
|
|
47
|
+
} else {
|
|
48
|
+
callback.invoke(resultData, null)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fun jsonArray2WriteableArray(jsonArray: JSONArray): WritableArray? {
|
|
53
|
+
return try {
|
|
54
|
+
val writableArray = Arguments.createArray()
|
|
55
|
+
for (i in 0 until jsonArray.length()) {
|
|
56
|
+
val `object` = jsonArray[i]
|
|
57
|
+
if (`object` is String) {
|
|
58
|
+
writableArray.pushString(jsonArray.getString(i))
|
|
59
|
+
} else if (`object` is Boolean) {
|
|
60
|
+
writableArray.pushBoolean(jsonArray.getBoolean(i))
|
|
61
|
+
} else if (`object` is Int) {
|
|
62
|
+
writableArray.pushInt(jsonArray.getInt(i))
|
|
63
|
+
} else if (`object` is Double) {
|
|
64
|
+
writableArray.pushDouble(jsonArray.getDouble(i))
|
|
65
|
+
} else if (`object` is JSONObject) {
|
|
66
|
+
writableArray.pushMap(jsonObject2WriteableMap(jsonArray.getJSONObject(i)))
|
|
67
|
+
} else if (`object` is JSONArray) {
|
|
68
|
+
writableArray.pushArray(jsonArray2WriteableArray(jsonArray.getJSONArray(i)))
|
|
69
|
+
} else {
|
|
70
|
+
writableArray.pushNull()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
writableArray
|
|
74
|
+
} catch (e: JSONException) {
|
|
75
|
+
e.printStackTrace()
|
|
76
|
+
null
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
fun jsonObject2WriteableMap(jsonObject: JSONObject): WritableMap? {
|
|
80
|
+
return try {
|
|
81
|
+
val writableMap = Arguments.createMap()
|
|
82
|
+
val iterator: Iterator<*> = jsonObject.keys()
|
|
83
|
+
while (iterator.hasNext()) {
|
|
84
|
+
val key = iterator.next() as String
|
|
85
|
+
val `object` = jsonObject[key]
|
|
86
|
+
if (`object` is String) {
|
|
87
|
+
writableMap.putString(key, jsonObject.getString(key))
|
|
88
|
+
} else if (`object` is Boolean) {
|
|
89
|
+
writableMap.putBoolean(key, jsonObject.getBoolean(key))
|
|
90
|
+
} else if (`object` is Int) {
|
|
91
|
+
writableMap.putInt(key, jsonObject.getInt(key))
|
|
92
|
+
} else if (`object` is Double) {
|
|
93
|
+
writableMap.putDouble(key, jsonObject.getDouble(key))
|
|
94
|
+
} else if (`object` is JSONObject) {
|
|
95
|
+
writableMap.putMap(key, jsonObject2WriteableMap(jsonObject.getJSONObject(key)))
|
|
96
|
+
} else if (`object` is JSONArray) {
|
|
97
|
+
writableMap.putArray(
|
|
98
|
+
key,
|
|
99
|
+
jsonArray2WriteableArray(jsonObject.getJSONArray(key))
|
|
100
|
+
)
|
|
101
|
+
} else {
|
|
102
|
+
writableMap.putNull(key)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
writableMap
|
|
106
|
+
} catch (e: JSONException) {
|
|
107
|
+
e.printStackTrace()
|
|
108
|
+
null
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
public inline fun <reified T : Any> convertToMap(obj: T): WritableMap? {
|
|
112
|
+
val gson = Gson()
|
|
113
|
+
val jsonString = gson.toJson(obj)
|
|
114
|
+
return try {
|
|
115
|
+
jsonObject2WriteableMap(JSONObject(jsonString))
|
|
116
|
+
} catch (e: Exception) {
|
|
117
|
+
null
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|