@bits-innovate/react-native-vstarcam 1.0.39 → 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.
@@ -80,7 +80,6 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
80
80
  put("ACAE", "EEGDFHBLKGJIGEJLEKGOFMEDHAMHHJNAGGFABMCOBGJOLHLJDFAFCPPHGILKIKLMANNHKEDKOINIBNCPJOMK:vstarcam2018"); // Try VSTH params
81
81
  put("ACDG", "EEGDFHBLKGJIGEJLEKGOFMEDHAMHHJNAGGFABMCOBGJOLHLJDFAFCPPHGILKIKLMANNHKEDKOINIBNCPJOMK:vstarcam2018"); // Same as ACAE/VSTH
82
82
  put("ACAQ", "EEGDFHBLKGJIGEJLEKGOFMEDHAMHHJNAGGFABMCOBGJOLHLJDFAFCPPHGILKIKLMANNHKEDKOINIBNCPJOMK:vstarcam2018"); // Same as ACAE/VSTH
83
- put("ACAG", "EEGDFHBLKGJIGEJLEKGOFMEDHAMHHJNAGGFABMCOBGJOLHLJDFAFCPPHGILKIKLMANNHKEDKOINIBNCPJOMK:vstarcam2018"); // Same as ACAE/VSTH
84
83
  // Fallback for unknown prefixes
85
84
  put("DEFAULT", "EBGBEMBMKGJMGAJPEIGIFKEGHBMCHMNFGKEGBFCBBMJELILDCJADCIOLHHLLJBKEAMMBLCDGONMDBJCJJPNFJP");
86
85
  }};
@@ -100,62 +99,13 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
100
99
  return param;
101
100
  }
102
101
 
103
- // Pattern to detect virtual UIDs (like ACAE0001151GWYQ)
104
- // Virtual UIDs: start with letters, have 7+ digits, end with letters
105
- private static final Pattern VIRTUAL_UID_PATTERN = Pattern.compile("^[a-zA-Z]{1,}\\d{7,}.*[a-zA-Z]$");
106
-
107
- // Check if a device ID is a virtual UID that needs conversion
108
- private static boolean isVirtualId(String deviceId) {
109
- if (deviceId == null || deviceId.length() < 10) return false;
110
- return VIRTUAL_UID_PATTERN.matcher(deviceId).matches();
111
- }
112
-
113
- // Convert virtual UID to real client ID using VStarCam API
114
- // Returns: {uid, supplier, cluster} or null on failure
115
- private String[] convertVirtualUid(String virtualUid) {
116
- try {
117
- URL url = new URL("https://vuid.eye4.cn?vuid=" + virtualUid);
118
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
119
- conn.setRequestMethod("GET");
120
- conn.setConnectTimeout(10000);
121
- conn.setReadTimeout(10000);
122
- conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
123
-
124
- int responseCode = conn.getResponseCode();
125
- if (responseCode == 200) {
126
- BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
127
- StringBuilder response = new StringBuilder();
128
- String line;
129
- while ((line = reader.readLine()) != null) {
130
- response.append(line);
131
- }
132
- reader.close();
133
-
134
- JSONObject json = new JSONObject(response.toString());
135
- String uid = json.optString("uid", null);
136
- String supplier = json.optString("supplier", "");
137
- String cluster = json.optString("cluster", "");
138
-
139
- if (uid != null && !uid.isEmpty()) {
140
- Log.d(TAG, "Converted virtual UID " + virtualUid + " -> real UID: " + uid + " (supplier: " + supplier + ", cluster: " + cluster + ")");
141
- return new String[]{uid, supplier, cluster};
142
- }
143
- } else {
144
- Log.e(TAG, "Virtual UID conversion failed, HTTP " + responseCode);
145
- }
146
- conn.disconnect();
147
- } catch (Exception e) {
148
- Log.e(TAG, "Failed to convert virtual UID: " + e.getMessage(), e);
149
- }
150
- return null;
151
- }
152
-
102
+
153
103
  private final ReactApplicationContext reactContext;
154
104
  private final ExecutorService executor;
155
105
 
156
106
  // Client tracking - maps our clientPtr to actual SDK client handle
157
107
  // Made static so VStarCamVideoView can access SDK pointers
158
- private static Map<Integer, ClientInfo> clients = new java.util.concurrent.ConcurrentHashMap<>();
108
+ private static Map<Integer, ClientInfo> clients = new HashMap<>();
159
109
  private boolean isNativeLibraryLoaded = false;
160
110
  private boolean isP2PInitialized = false;
161
111
 
@@ -166,8 +116,7 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
166
116
  private Class<?> releaseListenerClass = null;
167
117
 
168
118
  private static class ClientInfo {
169
- String deviceId; // Original device ID (can be virtual UID)
170
- String realClientId; // Converted client ID (for JNI calls)
119
+ String deviceId; // Original device ID
171
120
  long sdkClientPtr = 0; // Actual SDK client pointer (long)
172
121
  boolean isConnected = false;
173
122
  boolean isLoggedIn = false;
@@ -434,23 +383,10 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
434
383
  return;
435
384
  }
436
385
 
437
- // Check if this is a virtual UID that needs conversion
438
- String realClientId = deviceId;
439
- if (isVirtualId(deviceId)) {
440
- Log.d(TAG, "Device ID " + deviceId + " looks like a virtual UID, converting...");
441
- String[] conversionResult = convertVirtualUid(deviceId);
442
- if (conversionResult != null && conversionResult[0] != null) {
443
- realClientId = conversionResult[0];
444
- Log.d(TAG, "Using converted client ID: " + realClientId);
445
- } else {
446
- Log.w(TAG, "Virtual UID conversion failed, trying with original ID");
447
- }
448
- }
449
-
450
- // Call JNIApi.create(did, serverParam) with real client ID
451
- String serviceParam = getServiceParam(realClientId); // Use real client ID prefix
386
+ // Call JNIApi.create(did, serverParam)
387
+ String serviceParam = getServiceParam(deviceId);
452
388
  Method createMethod = jniApiClass.getMethod("create", String.class, String.class);
453
- Object result = createMethod.invoke(null, realClientId, serviceParam);
389
+ Object result = createMethod.invoke(null, deviceId, serviceParam);
454
390
  long sdkClientPtr = (Long) result;
455
391
 
456
392
  Log.d(TAG, "JNIApi.create result: " + sdkClientPtr);
@@ -461,16 +397,15 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
461
397
  return;
462
398
  }
463
399
 
464
- // Generate a unique internal client ID
465
- int ourClientPtr = nextClientPtr.getAndIncrement();
400
+ // Generate our own client ID (hash of deviceId) and store mapping
401
+ int ourClientPtr = Math.abs(deviceId.hashCode());
466
402
 
467
403
  ClientInfo clientInfo = new ClientInfo();
468
404
  clientInfo.deviceId = deviceId;
469
- clientInfo.realClientId = realClientId; // Store the converted ID
470
405
  clientInfo.sdkClientPtr = sdkClientPtr;
471
406
  clients.put(ourClientPtr, clientInfo);
472
407
 
473
- Log.d(TAG, "Created client: ourPtr=" + ourClientPtr + ", sdkPtr=" + sdkClientPtr + ", realId=" + realClientId);
408
+ Log.d(TAG, "Created client: ourPtr=" + ourClientPtr + ", sdkPtr=" + sdkClientPtr);
474
409
  promise.resolve(ourClientPtr);
475
410
  } catch (Exception e) {
476
411
  Log.e(TAG, "clientCreate failed", e);
@@ -506,11 +441,10 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
506
441
  params.putInt("state", 1); // CONNECTING
507
442
  sendEvent("onConnectionStateChanged", params);
508
443
 
509
- // Use realClientId for service param lookup (it has the correct prefix like VSTN)
510
- String realId = clientInfo.realClientId != null ? clientInfo.realClientId : clientInfo.deviceId;
444
+ // Construct the service param string
511
445
  String param = (serverParam != null && !serverParam.isEmpty())
512
446
  ? serverParam
513
- : getServiceParam(realId);
447
+ : getServiceParam(clientInfo.deviceId);
514
448
 
515
449
  // Default connectType to 126 (from V1 app) if not specified
516
450
  // connectType 126 = P2P/Relay combination that works reliably
@@ -578,32 +512,21 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
578
512
  Method loginMethod = jniApiClass.getMethod("login",
579
513
  long.class, String.class, String.class);
580
514
 
581
- Log.d(TAG, "Calling JNIApi.login(" + clientInfo.sdkClientPtr + ", " + username + ", ***)");
515
+ Log.d(TAG, "Calling JNIApi.login(" + clientInfo.sdkClientPtr + ", " + username + ")");
582
516
 
583
- boolean loginSuccess = false;
584
517
  try {
585
518
  loginMethod.invoke(null, clientInfo.sdkClientPtr, username, password);
586
- Log.d(TAG, "JNIApi.login returned normally");
587
- loginSuccess = true;
588
- } catch (java.lang.reflect.InvocationTargetException ite) {
589
- Throwable cause = ite.getCause();
590
- Log.e(TAG, "JNIApi.login threw exception: " + cause, cause);
591
- promise.resolve(false);
592
- return;
593
- } catch (Throwable t) {
594
- Log.e(TAG, "JNIApi.login crashed: " + t.getMessage(), t);
519
+ } catch (Exception e) {
520
+ Log.e(TAG, "Login failed: " + e.getMessage());
595
521
  promise.resolve(false);
596
522
  return;
597
523
  }
598
524
 
599
- if (loginSuccess) {
600
- clientInfo.isLoggedIn = true;
601
- clientInfo.username = username;
602
- clientInfo.password = password;
603
- }
525
+ clientInfo.isLoggedIn = true;
526
+ clientInfo.username = username;
527
+ clientInfo.password = password;
604
528
 
605
- Log.d(TAG, "JNIApi.login completed with result: " + loginSuccess);
606
- promise.resolve(loginSuccess);
529
+ promise.resolve(true);
607
530
  } catch (Exception e) {
608
531
  Log.e(TAG, "clientLogin failed", e);
609
532
  promise.reject("LOGIN_ERROR", e.getMessage());
@@ -866,6 +789,10 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
866
789
  } catch (Exception e) {
867
790
  Log.e(TAG, "checkMode JNI call failed", e);
868
791
  }
792
+ } else {
793
+ Log.w(TAG, "checkMode skipped: clientInfo=" + clientInfo +
794
+ ", jniApiClass=" + (jniApiClass != null) +
795
+ ", sdkPtr=" + (clientInfo != null ? clientInfo.sdkClientPtr : "null"));
869
796
  }
870
797
 
871
798
  // Mode > 0 means connected (1=P2P, 2=Relay, 3=Socket)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bits-innovate/react-native-vstarcam",
3
- "version": "1.0.39",
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",