@bits-innovate/react-native-vstarcam 1.0.45 → 1.0.46
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.
|
@@ -830,39 +830,53 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
830
830
|
*/
|
|
831
831
|
@ReactMethod
|
|
832
832
|
public void startVideoStream(int clientPtr, int streamType, Promise promise) {
|
|
833
|
-
|
|
833
|
+
boolean success = sendCgiInternal(clientPtr,
|
|
834
|
+
String.format("livestream.cgi?streamid=10&substream=%d", streamType), 5);
|
|
835
|
+
|
|
836
|
+
if (success) {
|
|
837
|
+
WritableMap response = Arguments.createMap();
|
|
838
|
+
response.putBoolean("success", true);
|
|
839
|
+
response.putString("message", "Video stream started");
|
|
840
|
+
response.putInt("resolution", streamType);
|
|
841
|
+
promise.resolve(response);
|
|
842
|
+
} else {
|
|
843
|
+
promise.reject("E_VIDEO_START_FAILED", "Failed to send livestream.cgi");
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Helper for internal components to send CGI commands without a Promise
|
|
849
|
+
*/
|
|
850
|
+
public static boolean sendCgiInternal(int clientPtr, String cgi, int timeout) {
|
|
834
851
|
try {
|
|
835
852
|
ClientInfo clientInfo = clients.get(clientPtr);
|
|
836
853
|
if (clientInfo == null || clientInfo.sdkClientPtr == 0) {
|
|
837
|
-
|
|
838
|
-
return;
|
|
854
|
+
Log.e(TAG, "sendCgiInternal: Client not connected for ptr " + clientPtr);
|
|
855
|
+
return false;
|
|
839
856
|
}
|
|
840
857
|
|
|
841
|
-
//
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
"
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
Log.d(TAG, "Sending livestream start command: " + cgi);
|
|
851
|
-
|
|
852
|
-
Method writeCgiMethod = jniApiClass.getMethod("writeCgi", long.class, String.class, int.class);
|
|
853
|
-
Object result = writeCgiMethod.invoke(null, clientInfo.sdkClientPtr, cgi, 5);
|
|
854
|
-
|
|
855
|
-
Log.d(TAG, "livestream start command sent, result: " + result);
|
|
858
|
+
// Append login info if missing
|
|
859
|
+
String finalCgi = cgi;
|
|
860
|
+
if (!cgi.contains("loginuse=")) {
|
|
861
|
+
String sep = cgi.contains("?") ? "&" : "?";
|
|
862
|
+
finalCgi = cgi + sep + "loginuse=" + (clientInfo.username != null ? clientInfo.username : "admin") +
|
|
863
|
+
"&loginpas=" + (clientInfo.password != null ? clientInfo.password : "");
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
Log.d(TAG, "sendCgiInternal: " + finalCgi);
|
|
856
867
|
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
868
|
+
// Invoke JNIApi.writeCgi
|
|
869
|
+
// Since we need to access jniApiClass which is not static, we use reflection on the instance if available
|
|
870
|
+
// but for simplicity, we can just grab the class by name again or make the class ref static.
|
|
871
|
+
Class<?> jniClass = Class.forName("com.vstarcam.JNIApi");
|
|
872
|
+
Method writeCgiMethod = jniClass.getMethod("writeCgi", long.class, String.class, int.class);
|
|
873
|
+
Object result = writeCgiMethod.invoke(null, clientInfo.sdkClientPtr, finalCgi, timeout);
|
|
862
874
|
|
|
875
|
+
int res = (Integer) result;
|
|
876
|
+
return res == 0; // 0 usually means success in VStarCam JNI
|
|
863
877
|
} catch (Exception e) {
|
|
864
|
-
Log.e(TAG, "
|
|
865
|
-
|
|
878
|
+
Log.e(TAG, "sendCgiInternal failed", e);
|
|
879
|
+
return false;
|
|
866
880
|
}
|
|
867
881
|
}
|
|
868
882
|
|
|
@@ -964,7 +978,7 @@ public class VStarCamModule extends ReactContextBaseJavaModule {
|
|
|
964
978
|
@ReactMethod
|
|
965
979
|
public void getSdkVersion(Promise promise) {
|
|
966
980
|
WritableMap result = Arguments.createMap();
|
|
967
|
-
result.putString("version", "1.0.
|
|
981
|
+
result.putString("version", "1.0.46");
|
|
968
982
|
result.putBoolean("nativeLoaded", isNativeLibraryLoaded);
|
|
969
983
|
result.putString("nativeLib", "OKSMARTPPCS");
|
|
970
984
|
result.putBoolean("p2pInitialized", isP2PInitialized);
|
|
@@ -194,6 +194,11 @@ public class VStarCamVideoView extends FrameLayout
|
|
|
194
194
|
|
|
195
195
|
statusView.setText("Starting stream...");
|
|
196
196
|
|
|
197
|
+
// Start video stream on camera side via CGI
|
|
198
|
+
Log.d(TAG, "Requesting livestream start from camera...");
|
|
199
|
+
VStarCamModule.sendCgiInternal((int) clientPtr,
|
|
200
|
+
String.format("livestream.cgi?streamid=10&substream=%d", resolution), 5);
|
|
201
|
+
|
|
197
202
|
try {
|
|
198
203
|
// 1. Create player instance if needed
|
|
199
204
|
// API: createPlayer(long identifier, Surface surface, int width, int height, int flags)
|
|
@@ -245,6 +250,10 @@ public class VStarCamVideoView extends FrameLayout
|
|
|
245
250
|
|
|
246
251
|
Log.d(TAG, "Stopping stream...");
|
|
247
252
|
|
|
253
|
+
// Stop video stream on camera side via CGI
|
|
254
|
+
Log.d(TAG, "Requesting livestream stop from camera...");
|
|
255
|
+
VStarCamModule.sendCgiInternal((int) clientPtr, "livestream.cgi?streamid=11", 5);
|
|
256
|
+
|
|
248
257
|
try {
|
|
249
258
|
try {
|
|
250
259
|
Method stopMethod = appPlayerClass.getMethod("stop", long.class);
|