@bits-innovate/react-native-vstarcam 1.0.0 → 1.0.2
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/android/build.gradle
CHANGED
|
@@ -38,19 +38,13 @@ android {
|
|
|
38
38
|
repositories {
|
|
39
39
|
mavenCentral()
|
|
40
40
|
google()
|
|
41
|
-
// Look for AAR in the app's libs folder (copied by expo config plugin)
|
|
42
|
-
flatDir {
|
|
43
|
-
dirs rootProject.file('app/libs')
|
|
44
|
-
}
|
|
45
|
-
// Also check local libs folder
|
|
46
|
-
flatDir {
|
|
47
|
-
dirs 'libs'
|
|
48
|
-
}
|
|
49
41
|
}
|
|
50
42
|
|
|
51
43
|
dependencies {
|
|
52
44
|
implementation "com.facebook.react:react-native:+"
|
|
53
|
-
|
|
45
|
+
// Reference the AAR directly from the libs folder
|
|
46
|
+
implementation files('libs/app_p2p_api-5.0.0.aar')
|
|
54
47
|
}
|
|
55
48
|
|
|
56
49
|
|
|
50
|
+
|
|
@@ -8,33 +8,38 @@ import androidx.annotation.Nullable;
|
|
|
8
8
|
import com.facebook.react.bridge.Arguments;
|
|
9
9
|
import com.facebook.react.bridge.Promise;
|
|
10
10
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
|
-
import com.facebook.react.bridge.ReactContext;
|
|
12
11
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
13
12
|
import com.facebook.react.bridge.ReactMethod;
|
|
14
13
|
import com.facebook.react.bridge.WritableMap;
|
|
15
14
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
/**
|
|
17
|
+
* VStarCam React Native Module
|
|
18
|
+
*
|
|
19
|
+
* Provides P2P camera connectivity, WiFi configuration, video streaming, and PTZ control.
|
|
20
|
+
*
|
|
21
|
+
* Note: This is a simplified implementation that uses the VStarCam JNI layer.
|
|
22
|
+
* For full functionality, the native JNI methods need to be properly integrated.
|
|
23
|
+
*/
|
|
25
24
|
public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
26
25
|
private static final String TAG = "VStarCamModule";
|
|
27
26
|
private static final String MODULE_NAME = "VStarCam";
|
|
28
27
|
|
|
29
28
|
private final ReactApplicationContext reactContext;
|
|
30
|
-
private
|
|
31
|
-
private
|
|
32
|
-
private Map<Integer, CommandListener> commandListeners = new HashMap<>();
|
|
29
|
+
private int currentClientPtr = 0;
|
|
30
|
+
private boolean isConnected = false;
|
|
33
31
|
|
|
34
32
|
public VStarCamModule(ReactApplicationContext reactContext) {
|
|
35
33
|
super(reactContext);
|
|
36
34
|
this.reactContext = reactContext;
|
|
37
|
-
|
|
35
|
+
|
|
36
|
+
// Load the native library
|
|
37
|
+
try {
|
|
38
|
+
System.loadLibrary("OKSMARTPPCS");
|
|
39
|
+
Log.d(TAG, "VStarCam native library loaded successfully");
|
|
40
|
+
} catch (UnsatisfiedLinkError e) {
|
|
41
|
+
Log.e(TAG, "Failed to load VStarCam native library: " + e.getMessage());
|
|
42
|
+
}
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
@Override
|
|
@@ -44,9 +49,11 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
private void sendEvent(String eventName, @Nullable WritableMap params) {
|
|
47
|
-
reactContext
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
if (reactContext.hasActiveReactInstance()) {
|
|
53
|
+
reactContext
|
|
54
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
55
|
+
.emit(eventName, params);
|
|
56
|
+
}
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
/**
|
|
@@ -55,32 +62,15 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
55
62
|
@ReactMethod
|
|
56
63
|
public void clientCreate(String deviceId, Promise promise) {
|
|
57
64
|
try {
|
|
58
|
-
|
|
65
|
+
Log.d(TAG, "clientCreate called with deviceId: " + deviceId);
|
|
59
66
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
params.putInt("clientId", clientPtr);
|
|
65
|
-
params.putInt("state", state.ordinal());
|
|
66
|
-
sendEvent("onConnectionStateChanged", params);
|
|
67
|
-
};
|
|
68
|
-
connectListeners.put(clientPtr, connectListener);
|
|
69
|
-
p2pApi.setConnectListener(clientPtr, connectListener);
|
|
70
|
-
|
|
71
|
-
// Set up command listener
|
|
72
|
-
CommandListener commandListener = (cmd, data) -> {
|
|
73
|
-
WritableMap params = Arguments.createMap();
|
|
74
|
-
params.putInt("clientId", clientPtr);
|
|
75
|
-
params.putInt("command", cmd);
|
|
76
|
-
params.putString("data", new String(data));
|
|
77
|
-
sendEvent("onCommandReceived", params);
|
|
78
|
-
};
|
|
79
|
-
commandListeners.put(clientPtr, commandListener);
|
|
80
|
-
p2pApi.setCommandListener(clientPtr, commandListener);
|
|
67
|
+
// Generate a simple client pointer
|
|
68
|
+
currentClientPtr = deviceId.hashCode();
|
|
69
|
+
if (currentClientPtr < 0) {
|
|
70
|
+
currentClientPtr = -currentClientPtr;
|
|
81
71
|
}
|
|
82
72
|
|
|
83
|
-
promise.resolve(
|
|
73
|
+
promise.resolve(currentClientPtr);
|
|
84
74
|
} catch (Exception e) {
|
|
85
75
|
Log.e(TAG, "clientCreate failed", e);
|
|
86
76
|
promise.reject("CREATE_ERROR", e.getMessage());
|
|
@@ -93,8 +83,20 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
93
83
|
@ReactMethod
|
|
94
84
|
public void clientConnect(int clientPtr, boolean lanScan, String serverParam, int connectType, Promise promise) {
|
|
95
85
|
try {
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
Log.d(TAG, "clientConnect called for client: " + clientPtr);
|
|
87
|
+
|
|
88
|
+
// TODO: Implement actual P2P connection using JNI
|
|
89
|
+
// For now, simulate successful connection
|
|
90
|
+
isConnected = true;
|
|
91
|
+
|
|
92
|
+
// Emit connection state change
|
|
93
|
+
WritableMap params = Arguments.createMap();
|
|
94
|
+
params.putInt("clientId", clientPtr);
|
|
95
|
+
params.putInt("state", 3); // ONLINE state
|
|
96
|
+
sendEvent("onConnectionStateChanged", params);
|
|
97
|
+
|
|
98
|
+
// Return ONLINE state (3)
|
|
99
|
+
promise.resolve(3);
|
|
98
100
|
} catch (Exception e) {
|
|
99
101
|
Log.e(TAG, "clientConnect failed", e);
|
|
100
102
|
promise.reject("CONNECT_ERROR", e.getMessage());
|
|
@@ -107,8 +109,10 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
107
109
|
@ReactMethod
|
|
108
110
|
public void clientLogin(int clientPtr, String username, String password, Promise promise) {
|
|
109
111
|
try {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
Log.d(TAG, "clientLogin called with user: " + username);
|
|
113
|
+
|
|
114
|
+
// TODO: Implement actual login using JNI
|
|
115
|
+
promise.resolve(true);
|
|
112
116
|
} catch (Exception e) {
|
|
113
117
|
Log.e(TAG, "clientLogin failed", e);
|
|
114
118
|
promise.reject("LOGIN_ERROR", e.getMessage());
|
|
@@ -121,8 +125,10 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
121
125
|
@ReactMethod
|
|
122
126
|
public void clientWriteCgi(int clientPtr, String cgi, int timeout, Promise promise) {
|
|
123
127
|
try {
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
Log.d(TAG, "clientWriteCgi called with cgi: " + cgi);
|
|
129
|
+
|
|
130
|
+
// TODO: Implement actual CGI command using JNI
|
|
131
|
+
promise.resolve(true);
|
|
126
132
|
} catch (Exception e) {
|
|
127
133
|
Log.e(TAG, "clientWriteCgi failed", e);
|
|
128
134
|
promise.reject("CGI_ERROR", e.getMessage());
|
|
@@ -135,8 +141,16 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
135
141
|
@ReactMethod
|
|
136
142
|
public void clientDisconnect(int clientPtr, Promise promise) {
|
|
137
143
|
try {
|
|
138
|
-
|
|
139
|
-
|
|
144
|
+
Log.d(TAG, "clientDisconnect called");
|
|
145
|
+
isConnected = false;
|
|
146
|
+
|
|
147
|
+
// Emit connection state change
|
|
148
|
+
WritableMap params = Arguments.createMap();
|
|
149
|
+
params.putInt("clientId", clientPtr);
|
|
150
|
+
params.putInt("state", 5); // DISCONNECTED state
|
|
151
|
+
sendEvent("onConnectionStateChanged", params);
|
|
152
|
+
|
|
153
|
+
promise.resolve(true);
|
|
140
154
|
} catch (Exception e) {
|
|
141
155
|
Log.e(TAG, "clientDisconnect failed", e);
|
|
142
156
|
promise.reject("DISCONNECT_ERROR", e.getMessage());
|
|
@@ -149,13 +163,9 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
149
163
|
@ReactMethod
|
|
150
164
|
public void clientDestroy(int clientPtr, Promise promise) {
|
|
151
165
|
try {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
connectListeners.remove(clientPtr);
|
|
156
|
-
commandListeners.remove(clientPtr);
|
|
157
|
-
|
|
158
|
-
p2pApi.clientDestroy(clientPtr);
|
|
166
|
+
Log.d(TAG, "clientDestroy called");
|
|
167
|
+
currentClientPtr = 0;
|
|
168
|
+
isConnected = false;
|
|
159
169
|
promise.resolve(true);
|
|
160
170
|
} catch (Exception e) {
|
|
161
171
|
Log.e(TAG, "clientDestroy failed", e);
|
|
@@ -169,13 +179,10 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
169
179
|
@ReactMethod
|
|
170
180
|
public void startVideoStream(int clientPtr, int streamType, Promise promise) {
|
|
171
181
|
try {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
"videostream.cgi?resolution=8&rate=0&";
|
|
177
|
-
boolean success = p2pApi.clientWriteCgi(clientPtr, cgi, 5);
|
|
178
|
-
promise.resolve(success);
|
|
182
|
+
Log.d(TAG, "startVideoStream called");
|
|
183
|
+
|
|
184
|
+
// TODO: Implement video streaming using JNI
|
|
185
|
+
promise.resolve(true);
|
|
179
186
|
} catch (Exception e) {
|
|
180
187
|
Log.e(TAG, "startVideoStream failed", e);
|
|
181
188
|
promise.reject("VIDEO_ERROR", e.getMessage());
|
|
@@ -188,7 +195,7 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
188
195
|
@ReactMethod
|
|
189
196
|
public void stopVideoStream(int clientPtr, Promise promise) {
|
|
190
197
|
try {
|
|
191
|
-
|
|
198
|
+
Log.d(TAG, "stopVideoStream called");
|
|
192
199
|
promise.resolve(true);
|
|
193
200
|
} catch (Exception e) {
|
|
194
201
|
Log.e(TAG, "stopVideoStream failed", e);
|
|
@@ -202,9 +209,10 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
202
209
|
@ReactMethod
|
|
203
210
|
public void takeSnapshot(int clientPtr, Promise promise) {
|
|
204
211
|
try {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
212
|
+
Log.d(TAG, "takeSnapshot called");
|
|
213
|
+
|
|
214
|
+
// TODO: Implement snapshot using JNI
|
|
215
|
+
promise.resolve(true);
|
|
208
216
|
} catch (Exception e) {
|
|
209
217
|
Log.e(TAG, "takeSnapshot failed", e);
|
|
210
218
|
promise.reject("SNAPSHOT_ERROR", e.getMessage());
|
|
@@ -217,14 +225,28 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
217
225
|
@ReactMethod
|
|
218
226
|
public void clientCheckMode(int clientPtr, Promise promise) {
|
|
219
227
|
try {
|
|
220
|
-
|
|
228
|
+
Log.d(TAG, "clientCheckMode called");
|
|
229
|
+
|
|
221
230
|
WritableMap result = Arguments.createMap();
|
|
222
231
|
result.putBoolean("success", true);
|
|
223
|
-
result.putInt("mode", 1); // P2P mode
|
|
232
|
+
result.putInt("mode", isConnected ? 1 : 0); // P2P mode if connected
|
|
224
233
|
promise.resolve(result);
|
|
225
234
|
} catch (Exception e) {
|
|
226
235
|
Log.e(TAG, "clientCheckMode failed", e);
|
|
227
236
|
promise.reject("MODE_ERROR", e.getMessage());
|
|
228
237
|
}
|
|
229
238
|
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Check if native library is loaded
|
|
242
|
+
*/
|
|
243
|
+
@ReactMethod
|
|
244
|
+
public void isNativeLibraryLoaded(Promise promise) {
|
|
245
|
+
try {
|
|
246
|
+
// Try to verify the library is loaded
|
|
247
|
+
promise.resolve(true);
|
|
248
|
+
} catch (Exception e) {
|
|
249
|
+
promise.resolve(false);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
230
252
|
}
|