@bits-innovate/react-native-vstarcam 1.0.40 → 1.0.42
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.
|
@@ -99,62 +99,13 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
99
99
|
return param;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
// Virtual UIDs: start with letters, have 7+ digits, end with letters
|
|
104
|
-
private static final Pattern VIRTUAL_UID_PATTERN = Pattern.compile("^[a-zA-Z]{1,}\\d{7,}.*[a-zA-Z]$");
|
|
105
|
-
|
|
106
|
-
// Check if a device ID is a virtual UID that needs conversion
|
|
107
|
-
private static boolean isVirtualId(String deviceId) {
|
|
108
|
-
if (deviceId == null || deviceId.length() < 10) return false;
|
|
109
|
-
return VIRTUAL_UID_PATTERN.matcher(deviceId).matches();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Convert virtual UID to real client ID using VStarCam API
|
|
113
|
-
// Returns: {uid, supplier, cluster} or null on failure
|
|
114
|
-
private String[] convertVirtualUid(String virtualUid) {
|
|
115
|
-
try {
|
|
116
|
-
URL url = new URL("https://vuid.eye4.cn?vuid=" + virtualUid);
|
|
117
|
-
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
118
|
-
conn.setRequestMethod("GET");
|
|
119
|
-
conn.setConnectTimeout(10000);
|
|
120
|
-
conn.setReadTimeout(10000);
|
|
121
|
-
conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
|
|
122
|
-
|
|
123
|
-
int responseCode = conn.getResponseCode();
|
|
124
|
-
if (responseCode == 200) {
|
|
125
|
-
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
126
|
-
StringBuilder response = new StringBuilder();
|
|
127
|
-
String line;
|
|
128
|
-
while ((line = reader.readLine()) != null) {
|
|
129
|
-
response.append(line);
|
|
130
|
-
}
|
|
131
|
-
reader.close();
|
|
132
|
-
|
|
133
|
-
JSONObject json = new JSONObject(response.toString());
|
|
134
|
-
String uid = json.optString("uid", null);
|
|
135
|
-
String supplier = json.optString("supplier", "");
|
|
136
|
-
String cluster = json.optString("cluster", "");
|
|
137
|
-
|
|
138
|
-
if (uid != null && !uid.isEmpty()) {
|
|
139
|
-
Log.d(TAG, "Converted virtual UID " + virtualUid + " -> real UID: " + uid + " (supplier: " + supplier + ", cluster: " + cluster + ")");
|
|
140
|
-
return new String[]{uid, supplier, cluster};
|
|
141
|
-
}
|
|
142
|
-
} else {
|
|
143
|
-
Log.e(TAG, "Virtual UID conversion failed, HTTP " + responseCode);
|
|
144
|
-
}
|
|
145
|
-
conn.disconnect();
|
|
146
|
-
} catch (Exception e) {
|
|
147
|
-
Log.e(TAG, "Failed to convert virtual UID: " + e.getMessage(), e);
|
|
148
|
-
}
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
|
|
102
|
+
|
|
152
103
|
private final ReactApplicationContext reactContext;
|
|
153
104
|
private final ExecutorService executor;
|
|
154
105
|
|
|
155
106
|
// Client tracking - maps our clientPtr to actual SDK client handle
|
|
156
107
|
// Made static so VStarCamVideoView can access SDK pointers
|
|
157
|
-
private static Map<Integer, ClientInfo> clients = new
|
|
108
|
+
private static Map<Integer, ClientInfo> clients = new java.util.concurrent.ConcurrentHashMap<>();
|
|
158
109
|
private boolean isNativeLibraryLoaded = false;
|
|
159
110
|
private boolean isP2PInitialized = false;
|
|
160
111
|
|
|
@@ -165,8 +116,7 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
165
116
|
private Class<?> releaseListenerClass = null;
|
|
166
117
|
|
|
167
118
|
private static class ClientInfo {
|
|
168
|
-
String deviceId; // Original device ID
|
|
169
|
-
String realClientId; // Converted client ID (for JNI calls)
|
|
119
|
+
String deviceId; // Original device ID
|
|
170
120
|
long sdkClientPtr = 0; // Actual SDK client pointer (long)
|
|
171
121
|
boolean isConnected = false;
|
|
172
122
|
boolean isLoggedIn = false;
|
|
@@ -433,23 +383,10 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
433
383
|
return;
|
|
434
384
|
}
|
|
435
385
|
|
|
436
|
-
//
|
|
437
|
-
String
|
|
438
|
-
if (isVirtualId(deviceId)) {
|
|
439
|
-
Log.d(TAG, "Device ID " + deviceId + " looks like a virtual UID, converting...");
|
|
440
|
-
String[] conversionResult = convertVirtualUid(deviceId);
|
|
441
|
-
if (conversionResult != null && conversionResult[0] != null) {
|
|
442
|
-
realClientId = conversionResult[0];
|
|
443
|
-
Log.d(TAG, "Using converted client ID: " + realClientId);
|
|
444
|
-
} else {
|
|
445
|
-
Log.w(TAG, "Virtual UID conversion failed, trying with original ID");
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// Call JNIApi.create(did, serverParam) with real client ID
|
|
450
|
-
String serviceParam = getServiceParam(realClientId); // Use real client ID prefix
|
|
386
|
+
// Call JNIApi.create(did, serverParam)
|
|
387
|
+
String serviceParam = getServiceParam(deviceId);
|
|
451
388
|
Method createMethod = jniApiClass.getMethod("create", String.class, String.class);
|
|
452
|
-
Object result = createMethod.invoke(null,
|
|
389
|
+
Object result = createMethod.invoke(null, deviceId, serviceParam);
|
|
453
390
|
long sdkClientPtr = (Long) result;
|
|
454
391
|
|
|
455
392
|
Log.d(TAG, "JNIApi.create result: " + sdkClientPtr);
|
|
@@ -465,11 +402,10 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
465
402
|
|
|
466
403
|
ClientInfo clientInfo = new ClientInfo();
|
|
467
404
|
clientInfo.deviceId = deviceId;
|
|
468
|
-
clientInfo.realClientId = realClientId; // Store the converted ID
|
|
469
405
|
clientInfo.sdkClientPtr = sdkClientPtr;
|
|
470
406
|
clients.put(ourClientPtr, clientInfo);
|
|
471
407
|
|
|
472
|
-
Log.d(TAG, "Created client: ourPtr=" + ourClientPtr + ", sdkPtr=" + sdkClientPtr
|
|
408
|
+
Log.d(TAG, "Created client: ourPtr=" + ourClientPtr + ", sdkPtr=" + sdkClientPtr);
|
|
473
409
|
promise.resolve(ourClientPtr);
|
|
474
410
|
} catch (Exception e) {
|
|
475
411
|
Log.e(TAG, "clientCreate failed", e);
|
|
@@ -505,11 +441,10 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
505
441
|
params.putInt("state", 1); // CONNECTING
|
|
506
442
|
sendEvent("onConnectionStateChanged", params);
|
|
507
443
|
|
|
508
|
-
//
|
|
509
|
-
String realId = clientInfo.realClientId != null ? clientInfo.realClientId : clientInfo.deviceId;
|
|
444
|
+
// Construct the service param string
|
|
510
445
|
String param = (serverParam != null && !serverParam.isEmpty())
|
|
511
446
|
? serverParam
|
|
512
|
-
: getServiceParam(
|
|
447
|
+
: getServiceParam(clientInfo.deviceId);
|
|
513
448
|
|
|
514
449
|
// Default connectType to 126 (from V1 app) if not specified
|
|
515
450
|
// connectType 126 = P2P/Relay combination that works reliably
|
|
@@ -552,6 +487,24 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
552
487
|
});
|
|
553
488
|
}
|
|
554
489
|
|
|
490
|
+
/**
|
|
491
|
+
* Get the current connection state of a client
|
|
492
|
+
*/
|
|
493
|
+
@ReactMethod
|
|
494
|
+
public void clientGetState(int clientPtr, Promise promise) {
|
|
495
|
+
ClientInfo clientInfo = clients.get(clientPtr);
|
|
496
|
+
if (clientInfo == null) {
|
|
497
|
+
promise.resolve(5); // DISCONNECTED
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
WritableMap result = Arguments.createMap();
|
|
502
|
+
result.putInt("state", clientInfo.isConnected ? 3 : 1); // 3=ONLINE, 1=CONNECTING (approx)
|
|
503
|
+
result.putBoolean("isConnected", clientInfo.isConnected);
|
|
504
|
+
result.putBoolean("isLoggedIn", clientInfo.isLoggedIn);
|
|
505
|
+
promise.resolve(result);
|
|
506
|
+
}
|
|
507
|
+
|
|
555
508
|
/**
|
|
556
509
|
* Login to camera
|
|
557
510
|
* JNIApi.login(long clientPtr, String username, String password)
|
|
@@ -577,32 +530,21 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
577
530
|
Method loginMethod = jniApiClass.getMethod("login",
|
|
578
531
|
long.class, String.class, String.class);
|
|
579
532
|
|
|
580
|
-
Log.d(TAG, "Calling JNIApi.login(" + clientInfo.sdkClientPtr + ", " + username + "
|
|
533
|
+
Log.d(TAG, "Calling JNIApi.login(" + clientInfo.sdkClientPtr + ", " + username + ")");
|
|
581
534
|
|
|
582
|
-
boolean loginSuccess = false;
|
|
583
535
|
try {
|
|
584
536
|
loginMethod.invoke(null, clientInfo.sdkClientPtr, username, password);
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
} catch (java.lang.reflect.InvocationTargetException ite) {
|
|
588
|
-
Throwable cause = ite.getCause();
|
|
589
|
-
Log.e(TAG, "JNIApi.login threw exception: " + cause, cause);
|
|
590
|
-
promise.resolve(false);
|
|
591
|
-
return;
|
|
592
|
-
} catch (Throwable t) {
|
|
593
|
-
Log.e(TAG, "JNIApi.login crashed: " + t.getMessage(), t);
|
|
537
|
+
} catch (Exception e) {
|
|
538
|
+
Log.e(TAG, "Login failed: " + e.getMessage());
|
|
594
539
|
promise.resolve(false);
|
|
595
540
|
return;
|
|
596
541
|
}
|
|
597
542
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
clientInfo.password = password;
|
|
602
|
-
}
|
|
543
|
+
clientInfo.isLoggedIn = true;
|
|
544
|
+
clientInfo.username = username;
|
|
545
|
+
clientInfo.password = password;
|
|
603
546
|
|
|
604
|
-
|
|
605
|
-
promise.resolve(loginSuccess);
|
|
547
|
+
promise.resolve(true);
|
|
606
548
|
} catch (Exception e) {
|
|
607
549
|
Log.e(TAG, "clientLogin failed", e);
|
|
608
550
|
promise.reject("LOGIN_ERROR", e.getMessage());
|
|
@@ -90,6 +90,7 @@ public class VStarCamVideoView extends FrameLayout
|
|
|
90
90
|
// Based on decompiling app_player-5.0.0.aar classes.jar
|
|
91
91
|
String[] classNames = {
|
|
92
92
|
"com.veepai.AppPlayerApi", // Main API class from AAR
|
|
93
|
+
"com.veepai.AppPlayer", // Possible alternative
|
|
93
94
|
"com.veepai.app_player.AppPlayerPlugin", // Flutter plugin wrapper
|
|
94
95
|
"com.vstarcam.player.AppPlayer",
|
|
95
96
|
"com.vstarcam.AppPlayer",
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -288,6 +288,14 @@ class VStarCamClient {
|
|
|
288
288
|
return VStarCamModule.clientCheckMode(this.clientPtr);
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
+
/**
|
|
292
|
+
* Get the current connection state of the client
|
|
293
|
+
*/
|
|
294
|
+
async getState(): Promise<any> {
|
|
295
|
+
if (!this.clientPtr) return { state: 5, isConnected: false };
|
|
296
|
+
return VStarCamModule.clientGetState(this.clientPtr);
|
|
297
|
+
}
|
|
298
|
+
|
|
291
299
|
/**
|
|
292
300
|
* Login to the camera
|
|
293
301
|
* @param username Camera username (default: admin)
|