@bits-innovate/react-native-vstarcam 1.0.40 → 1.0.41

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,56 +99,7 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
99
99
  return param;
100
100
  }
101
101
 
102
- // Pattern to detect virtual UIDs (like ACAE0001151GWYQ)
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
 
@@ -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 (can be virtual UID)
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
- // Check if this is a virtual UID that needs conversion
437
- String realClientId = deviceId;
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, realClientId, serviceParam);
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 + ", realId=" + realClientId);
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
- // Use realClientId for service param lookup (it has the correct prefix like VSTN)
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(realId);
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
@@ -577,32 +512,21 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
577
512
  Method loginMethod = jniApiClass.getMethod("login",
578
513
  long.class, String.class, String.class);
579
514
 
580
- Log.d(TAG, "Calling JNIApi.login(" + clientInfo.sdkClientPtr + ", " + username + ", ***)");
515
+ Log.d(TAG, "Calling JNIApi.login(" + clientInfo.sdkClientPtr + ", " + username + ")");
581
516
 
582
- boolean loginSuccess = false;
583
517
  try {
584
518
  loginMethod.invoke(null, clientInfo.sdkClientPtr, username, password);
585
- Log.d(TAG, "JNIApi.login returned normally");
586
- loginSuccess = true;
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);
519
+ } catch (Exception e) {
520
+ Log.e(TAG, "Login failed: " + e.getMessage());
594
521
  promise.resolve(false);
595
522
  return;
596
523
  }
597
524
 
598
- if (loginSuccess) {
599
- clientInfo.isLoggedIn = true;
600
- clientInfo.username = username;
601
- clientInfo.password = password;
602
- }
525
+ clientInfo.isLoggedIn = true;
526
+ clientInfo.username = username;
527
+ clientInfo.password = password;
603
528
 
604
- Log.d(TAG, "JNIApi.login completed with result: " + loginSuccess);
605
- promise.resolve(loginSuccess);
529
+ promise.resolve(true);
606
530
  } catch (Exception e) {
607
531
  Log.e(TAG, "clientLogin failed", e);
608
532
  promise.reject("LOGIN_ERROR", e.getMessage());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bits-innovate/react-native-vstarcam",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "description": "React Native bridge for VStarCam P2P SDK",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",