@byteplus/react-native-live-pull 1.1.3-rc.4 → 1.2.0-rc.1

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.
Files changed (31) hide show
  1. package/android/build.gradle +2 -2
  2. package/android/src/main/java/com/volcengine/velive/rn/pull/ClassHelper.java +15 -0
  3. package/android/src/main/java/com/volcengine/velive/rn/pull/NativeVariableManager.java +1 -1
  4. package/android/src/main/java/com/volcengine/velive/rn/pull/VolcLiveModule.java +2 -0
  5. package/android/src/main/java/com/volcengine/velive/rn/pull/autogen/MethodSignature.java +66 -77
  6. package/android/src/main/java/com/volcengine/velive/rn/pull/pictureInpicture/FloatingWindowService.java +79 -15
  7. package/ios/VeLivePlayerMultiObserver.h +3 -2
  8. package/ios/VeLivePlayerMultiObserver.m +2 -2
  9. package/ios/include/react-native-velive-pull.modulemap +4 -0
  10. package/ios/pictureInpicture/PictureInPictureManager.h +21 -1
  11. package/ios/pictureInpicture/PictureInPictureManager.m +260 -141
  12. package/lib/commonjs/index.js +4455 -1648
  13. package/lib/module/index.js +4455 -1648
  14. package/lib/typescript/codegen/android/api.d.ts +51 -43
  15. package/lib/typescript/codegen/android/callback.d.ts +166 -0
  16. package/lib/typescript/codegen/android/errorcode.d.ts +123 -2
  17. package/lib/typescript/codegen/android/keytype.d.ts +501 -13
  18. package/lib/typescript/codegen/ios/api.d.ts +232 -16
  19. package/lib/typescript/codegen/ios/callback.d.ts +137 -1
  20. package/lib/typescript/codegen/ios/errorcode.d.ts +104 -0
  21. package/lib/typescript/codegen/ios/keytype.d.ts +460 -6
  22. package/lib/typescript/codegen/pack/api.d.ts +66 -57
  23. package/lib/typescript/codegen/pack/callback.d.ts +45 -21
  24. package/lib/typescript/codegen/pack/errorcode.d.ts +45 -15
  25. package/lib/typescript/codegen/pack/keytype.d.ts +388 -114
  26. package/lib/typescript/core/api.d.ts +13 -0
  27. package/lib/typescript/core/keytype.d.ts +18 -2
  28. package/package.json +1 -1
  29. package/react-native-velive-pull.podspec +12 -3
  30. package/ios/pictureInpicture/VeLivePictureInPictureController.h +0 -207
  31. package/ios/pictureInpicture/VeLivePictureInPictureController.m +0 -3393
@@ -88,6 +88,6 @@ dependencies {
88
88
  // noinspection GradleDynamicVersion
89
89
  implementation "com.facebook.react:react-native:+"
90
90
 
91
- implementation "com.volcengine:VolcApiEngine:1.2.3"
92
- implementation 'com.bytedanceapi:ttsdk-ttlivepull_rtc:1.41.300.103'
91
+ implementation "com.volcengine:VolcApiEngine:1.6.2"
92
+ implementation 'com.bytedanceapi:ttsdk-ttlivepull_rtc:1.46.300.2'
93
93
  }
@@ -0,0 +1,15 @@
1
+ package com.volcengine.velive.rn.pull;
2
+
3
+ import com.ss.videoarch.liveplayer.VeLivePlayer;
4
+ import com.ss.videoarch.liveplayer.VeLivePlayerDef;
5
+ import com.ss.videoarch.liveplayer.VeLivePlayerError;
6
+ import com.ss.videoarch.liveplayer.VeLivePlayerStatistics;
7
+ import com.volcengine.VolcApiEngine.runtime.Util;
8
+
9
+ public class ClassHelper {
10
+ public static void init() {
11
+ Util.JsonAbleClass.add(VeLivePlayerStatistics.class);
12
+ Util.JsonAbleClass.add(VeLivePlayerError.class);
13
+ Util.JsonAbleClass.add(VeLivePlayerDef.VeLivePlayerResolution.class);
14
+ }
15
+ }
@@ -8,7 +8,7 @@ import com.volcengine.VolcApiEngine.runtime.*;
8
8
  public class NativeVariableManager {
9
9
  static void init(@NonNull MessageClient msgClient, ReactApplicationContext reactContext) {
10
10
  var m = msgClient.proto.variableManager;
11
-
11
+
12
12
  m.registerVar("ApplicationContext", (Object[] args) -> reactContext.getApplicationContext());
13
13
  m.registerVar("ReactApplicationContext", (Object[] args) -> reactContext);
14
14
  }
@@ -10,6 +10,7 @@ import com.facebook.react.bridge.ReadableMap;
10
10
  import com.facebook.react.bridge.WritableMap;
11
11
  import com.facebook.react.module.annotations.ReactModule;
12
12
  import com.facebook.react.modules.core.DeviceEventManagerModule;
13
+ import com.ss.videoarch.liveplayer.VeLivePlayerDef;
13
14
  import com.volcengine.VolcApiEngine.*;
14
15
  import com.volcengine.velive.rn.pull.autogen.MethodSignature;
15
16
 
@@ -23,6 +24,7 @@ public class VolcLiveModule
23
24
  VolcLiveModule(ReactApplicationContext context) {
24
25
  super(context);
25
26
  MethodSignature.init();
27
+ ClassHelper.init();
26
28
  }
27
29
 
28
30
  @Override
@@ -4,123 +4,112 @@ import static com.volcengine.VolcApiEngine.runtime.MethodSignature.*;
4
4
 
5
5
  import android.view.Surface;
6
6
  import android.view.SurfaceHolder;
7
-
8
7
  import com.ss.videoarch.liveplayer.VeLivePlayer;
9
8
  import com.ss.videoarch.liveplayer.VeLivePlayerConfiguration;
10
9
  import com.ss.videoarch.liveplayer.VeLivePlayerDef;
11
10
  import com.ss.videoarch.liveplayer.VeLivePlayerObserver;
12
11
  import com.ss.videoarch.liveplayer.VeLivePlayerStreamData;
13
12
  import com.ss.videoarch.liveplayer.log.VeLivePlayerLogConfig;
14
-
15
13
  import java.util.Map;
16
14
 
17
15
  public class MethodSignature {
18
16
  static public void init() {
19
17
  try {
20
- var r = createClassMethodRegister("com.ss.videoarch.liveplayer.VideoLiveManager");
18
+ var r = createClassMethodRegister(
19
+ "com.ss.videoarch.liveplayer.VideoLiveManager");
21
20
 
22
- r.put(
23
- "setConfig",
24
- VeLivePlayer.class.getMethod("setConfig", VeLivePlayerConfiguration.class));
21
+ r.put("setConfig", VeLivePlayer.class.getMethod(
22
+ "setConfig", VeLivePlayerConfiguration.class));
23
+
24
+ r.put("setObserver", VeLivePlayer.class.getMethod(
25
+ "setObserver", VeLivePlayerObserver.class));
25
26
 
26
27
  r.put(
27
- "setObserver",
28
- VeLivePlayer.class.getMethod("setObserver", VeLivePlayerObserver.class));
28
+ "setRenderFillMode",
29
+ VeLivePlayer.class.getMethod(
30
+ "setRenderFillMode", VeLivePlayerDef.VeLivePlayerFillMode.class));
29
31
 
30
- r.put("setRenderFillMode",
31
- VeLivePlayer.class.getMethod("setRenderFillMode", VeLivePlayerDef.VeLivePlayerFillMode.class));
32
-
33
32
  r.put("getVersion", VeLivePlayer.class.getMethod("getVersion"));
34
-
35
- r.put(
36
- "setSurfaceHolder",
37
- VeLivePlayer.class.getMethod("setSurfaceHolder", SurfaceHolder.class));
38
-
39
- r.put("setSurface",
40
- VeLivePlayer.class.getMethod("setSurface", Surface.class));
41
33
 
42
- r.put(
43
- "setPlayUrl",
44
- VeLivePlayer.class.getMethod("setPlayUrl", String.class));
45
-
46
- r.put(
47
- "setLogLevel",
48
- VeLivePlayer.class.getMethod("setLogLevel", VeLivePlayerLogConfig.VeLivePlayerLogLevel.class));
34
+ r.put("setSurfaceHolder", VeLivePlayer.class.getMethod(
35
+ "setSurfaceHolder", SurfaceHolder.class));
36
+
37
+ r.put("setSurface",
38
+ VeLivePlayer.class.getMethod("setSurface", Surface.class));
39
+
40
+ r.put("setPlayUrl",
41
+ VeLivePlayer.class.getMethod("setPlayUrl", String.class));
49
42
 
50
43
  r.put(
51
- "setLogConfig",
52
- VeLivePlayer.class.getMethod("setLogConfig", VeLivePlayerLogConfig.class));
44
+ "setLogLevel",
45
+ VeLivePlayer.class.getMethod(
46
+ "setLogLevel", VeLivePlayerLogConfig.VeLivePlayerLogLevel.class));
47
+
48
+ r.put("setLogConfig", VeLivePlayer.class.getMethod(
49
+ "setLogConfig", VeLivePlayerLogConfig.class));
53
50
 
54
51
  r.put("setPlayStreamData",
55
- VeLivePlayer.class.getMethod("setPlayStreamData", VeLivePlayerStreamData.class));
56
-
57
- r.put(
58
- "play",
59
- VeLivePlayer.class.getMethod("play"));
60
- r.put(
61
- "pause",
62
- VeLivePlayer.class.getMethod("pause"));
52
+ VeLivePlayer.class.getMethod("setPlayStreamData",
53
+ VeLivePlayerStreamData.class));
63
54
 
64
- r.put(
65
- "stop",
66
- VeLivePlayer.class.getMethod("stop"));
55
+ r.put("play", VeLivePlayer.class.getMethod("play"));
56
+ r.put("pause", VeLivePlayer.class.getMethod("pause"));
57
+
58
+ r.put("stop", VeLivePlayer.class.getMethod("stop"));
67
59
 
68
60
  r.put("destroy", VeLivePlayer.class.getMethod("destroy"));
69
61
 
70
- r.put(
71
- "switchResolution",
72
- VeLivePlayer.class.getMethod("switchResolution", VeLivePlayerDef.VeLivePlayerResolution.class));
62
+ r.put("switchResolution",
63
+ VeLivePlayer.class.getMethod(
64
+ "switchResolution",
65
+ VeLivePlayerDef.VeLivePlayerResolution.class));
73
66
 
74
67
  r.put("isPlaying", VeLivePlayer.class.getMethod("isPlaying"));
75
68
 
76
- r.put(
77
- "setPlayerVolume",
78
- VeLivePlayer.class.getMethod("setPlayerVolume", float.class));
79
-
69
+ r.put("setPlayerVolume",
70
+ VeLivePlayer.class.getMethod("setPlayerVolume", float.class));
71
+
80
72
  r.put("setMute", VeLivePlayer.class.getMethod("setMute", boolean.class));
81
73
 
82
74
  r.put("isMute", VeLivePlayer.class.getMethod("isMute"));
83
-
84
- r.put(
85
- "setUrlHostIP",
86
- VeLivePlayer.class.getMethod("setUrlHostIP", Map.class));
87
75
 
88
- r.put(
89
- "setGlobalUrlHostIP",
90
- VeLivePlayer.class.getMethod("setGlobalUrlHostIP", Map.class));
76
+ r.put("setUrlHostIP",
77
+ VeLivePlayer.class.getMethod("setUrlHostIP", Map.class));
91
78
 
92
- r.put(
93
- "setProperty",
94
- VeLivePlayer.class.getMethod("setProperty", String.class, Object.class));
79
+ r.put("setGlobalUrlHostIP",
80
+ VeLivePlayer.class.getMethod("setGlobalUrlHostIP", Map.class));
95
81
 
96
- r.put(
97
- "snapshot",
98
- VeLivePlayer.class.getMethod("snapshot"));
82
+ r.put("setProperty", VeLivePlayer.class.getMethod(
83
+ "setProperty", String.class, Object.class));
99
84
 
100
- r.put(
101
- "enableVideoFrameObserver",
102
- VeLivePlayer.class.getMethod(
103
- "enableVideoFrameObserver",
104
- boolean.class, VeLivePlayerDef.VeLivePlayerPixelFormat.class, VeLivePlayerDef.VeLivePlayerVideoBufferType.class));
85
+ r.put("snapshot", VeLivePlayer.class.getMethod("snapshot"));
105
86
 
106
- r.put(
107
- "enableAudioFrameObserver",
108
- VeLivePlayer.class.getMethod(
109
- "enableAudioFrameObserver",
110
- boolean.class, boolean.class));
111
-
112
- r.put(
113
- "setRenderRotation",
114
- VeLivePlayer.class.getMethod("setRenderRotation", VeLivePlayerDef.VeLivePlayerRotation.class));
87
+ r.put("enableVideoFrameObserver",
88
+ VeLivePlayer.class.getMethod(
89
+ "enableVideoFrameObserver", boolean.class,
90
+ VeLivePlayerDef.VeLivePlayerPixelFormat.class,
91
+ VeLivePlayerDef.VeLivePlayerVideoBufferType.class));
92
+
93
+ r.put("enableAudioFrameObserver",
94
+ VeLivePlayer.class.getMethod(
95
+ "enableAudioFrameObserver", boolean.class, boolean.class,
96
+ VeLivePlayerDef.VeLivePlayerAudioBufferType.class));
115
97
 
116
98
  r.put(
117
- "setRenderMirror",
118
- VeLivePlayer.class.getMethod("setRenderMirror", VeLivePlayerDef.VeLivePlayerMirror.class));
119
-
99
+ "setRenderRotation",
100
+ VeLivePlayer.class.getMethod(
101
+ "setRenderRotation", VeLivePlayerDef.VeLivePlayerRotation.class));
102
+
103
+ r.put("setRenderMirror",
104
+ VeLivePlayer.class.getMethod(
105
+ "setRenderMirror", VeLivePlayerDef.VeLivePlayerMirror.class));
120
106
 
121
- r.put("setEnableSuperResolution", VeLivePlayer.class.getMethod("setEnableSuperResolution", boolean.class));
107
+ r.put("setEnableSuperResolution",
108
+ VeLivePlayer.class.getMethod("setEnableSuperResolution",
109
+ boolean.class));
122
110
 
123
- r.put("setEnableSharpen", VeLivePlayer.class.getMethod("setEnableSharpen", boolean.class));
111
+ r.put("setEnableSharpen",
112
+ VeLivePlayer.class.getMethod("setEnableSharpen", boolean.class));
124
113
 
125
114
  } catch (NoSuchMethodException e) {
126
115
  throw new RuntimeException(e);
@@ -1,6 +1,7 @@
1
1
  package com.volcengine.velive.rn.pull.pictureInpicture;
2
2
 
3
3
  import android.animation.ValueAnimator;
4
+ import android.app.ActivityManager;
4
5
  import android.app.Service;
5
6
  import android.content.BroadcastReceiver;
6
7
  import android.content.Context;
@@ -23,6 +24,7 @@ import android.view.ViewConfiguration;
23
24
  import android.view.WindowManager;
24
25
  import androidx.annotation.Nullable;
25
26
  import com.volcengine.velive.rn.pull.R;
27
+ import java.util.List;
26
28
 
27
29
  public class FloatingWindowService extends Service {
28
30
  private static final int MARGIN_TOP = 40;
@@ -66,6 +68,7 @@ public class FloatingWindowService extends Service {
66
68
  public void onDestroy() {
67
69
  Log.d(TAG, "onDestroy");
68
70
  super.onDestroy();
71
+
69
72
  unregisterActivityLaunchReceiver(); // Ensure receiver is unregistered on
70
73
  // destroy
71
74
  if (mSmallWindowView != null) {
@@ -110,15 +113,15 @@ public class FloatingWindowService extends Service {
110
113
 
111
114
  int maxLen;
112
115
  if (isPortrait) {
113
- // 竖屏时,宽度不能超过 drawableWidth
116
+ // in portrait mode, width cannot exceed drawableWidth
114
117
  maxLen = drawableWidth;
115
118
  } else {
116
- // 横屏时,高度不能超过 drawableHeight
119
+ // in landscape mode, height cannot exceed drawableHeight
117
120
  maxLen = drawableHeight;
118
121
  }
119
122
 
120
123
  int width, height;
121
- if (aspectRatio >= 1) { // 宽大于等于高 (横向视频或方形)
124
+ if (aspectRatio >= 1) { // wider than tall (landscape or square video)
122
125
  width = maxLen;
123
126
  height = (int)(width / aspectRatio);
124
127
  if (isPortrait && width > drawableWidth) {
@@ -178,28 +181,72 @@ public class FloatingWindowService extends Service {
178
181
  Log.d(TAG, "PIP window clicked");
179
182
 
180
183
  try {
181
- // Get the pacain activity
184
+ if (isAppRunningInForeground()) {
185
+ unregisterActivityLaunchReceiver();
186
+ stopSelf();
187
+ return;
188
+ }
189
+
190
+ // Get the main activity
182
191
  String packageName = this.getPackageName();
183
192
  Intent launchIntent =
184
- this.getPackageManager().getLaunchIntentForPackage(
185
- packageName);
186
-
193
+ this.getPackageManager().getLaunchIntentForPackage(packageName);
187
194
  if (launchIntent != null) {
188
- Log.d(TAG, "Launching app with intent: " + launchIntent);
189
195
  launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
190
196
  // Register receiver to stop service when activity is launched
191
197
  registerActivityLaunchReceiver();
192
198
  this.startActivity(launchIntent);
193
- } else {
194
- Log.e(TAG, "Could not create launch intent for package: " +
195
- packageName);
199
+
200
+ // Wait for app to reach foreground before closing floating window
201
+ checkAppForegroundAndClose();
196
202
  }
197
203
  } catch (Exception e) {
198
- Log.e(TAG, "Error launching app: " + e.getMessage(), e);
204
+
199
205
  }
200
- });
206
+ });
207
+ }
208
+ }
209
+ }
210
+
211
+ private boolean isAppRunningInForeground() {
212
+ ActivityManager activityManager =
213
+ (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
214
+ if (activityManager == null) {
215
+ return false;
216
+ }
217
+
218
+ String packageName = getPackageName();
219
+
220
+ // For Android API level 21 and above
221
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
222
+ List<ActivityManager.RunningAppProcessInfo> runningProcesses =
223
+ activityManager.getRunningAppProcesses();
224
+ if (runningProcesses != null) {
225
+ for (ActivityManager.RunningAppProcessInfo processInfo :
226
+ runningProcesses) {
227
+ if (processInfo.processName.equals(packageName)) {
228
+ // Check if the process is in foreground
229
+ if (processInfo.importance ==
230
+ ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
231
+ return true;
232
+ }
233
+ }
234
+ }
235
+ }
236
+ } else {
237
+ // For older Android versions, use deprecated method
238
+ @SuppressWarnings("deprecation")
239
+ List<ActivityManager.RunningTaskInfo> runningTasks =
240
+ activityManager.getRunningTasks(1);
241
+ if (runningTasks != null && !runningTasks.isEmpty()) {
242
+ ActivityManager.RunningTaskInfo topTask = runningTasks.get(0);
243
+ if (topTask.topActivity != null &&
244
+ packageName.equals(topTask.topActivity.getPackageName())) {
245
+ return true;
246
+ }
201
247
  }
202
248
  }
249
+ return false;
203
250
  }
204
251
 
205
252
  private void registerActivityLaunchReceiver() {
@@ -228,6 +275,25 @@ public class FloatingWindowService extends Service {
228
275
  }
229
276
  }
230
277
 
278
+ private Handler mHandler = new Handler(Looper.getMainLooper());
279
+
280
+ private void checkAppForegroundAndClose() {
281
+ mHandler.postDelayed(new Runnable() {
282
+ private int checkCount = 0;
283
+
284
+ @Override
285
+ public void run() {
286
+ if (isAppRunningInForeground()) {
287
+ unregisterActivityLaunchReceiver();
288
+ stopSelf();
289
+ } else if (checkCount < 20) { // Check up to 20 times
290
+ checkCount++;
291
+ mHandler.postDelayed(this, 500);
292
+ }
293
+ }
294
+ }, 500);
295
+ }
296
+
231
297
  // BroadcastReceiver to listen for activity launch confirmation
232
298
  private class ActivityLaunchReceiver extends BroadcastReceiver {
233
299
  @Override
@@ -373,8 +439,6 @@ public class FloatingWindowService extends Service {
373
439
  mLayoutParams.x = mLayoutParams.x + movedX;
374
440
  mLayoutParams.y = mLayoutParams.y + movedY;
375
441
 
376
- // 使用预先获取的屏幕高度 screenHeight
377
- // 限制y坐标在安全区域内
378
442
  mLayoutParams.y = Math.max(
379
443
  MARGIN_TOP, Math.min(mLayoutParams.y, this.screenHeight -
380
444
  mLayoutParams.height -
@@ -1,5 +1,5 @@
1
1
  #import <Foundation/Foundation.h>
2
- #import "TTSDKFramework/TVLManager.h"
2
+ #import <TTSDKFramework/TVLManager.h>
3
3
 
4
4
  NS_ASSUME_NONNULL_BEGIN
5
5
 
@@ -30,7 +30,8 @@ NS_ASSUME_NONNULL_BEGIN
30
30
  * @param observerId 观察者ID,相同ID会覆盖之前的观察者
31
31
  * @param observer 观察者对象
32
32
  */
33
- - (void)addObserver:(NSString *)observerId observer:(id<VeLivePlayerObserver>)observer;
33
+ - (void)addObserver:(NSString *)observerId
34
+ observer:(id<VeLivePlayerObserver>)observer;
34
35
 
35
36
  /**
36
37
  * 从代理列表中移除观察者
@@ -1,5 +1,5 @@
1
1
  #import "VeLivePlayerMultiObserver.h"
2
- #import "TTSDKFramework/TVLManager.h"
2
+ #import <TTSDKFramework/TVLManager.h>
3
3
 
4
4
  @interface VeLivePlayerMultiObserver ()
5
5
  @property(nonatomic, strong) NSMutableDictionary *observerDict;
@@ -35,7 +35,7 @@
35
35
  }
36
36
 
37
37
  - (void)setupPlayer:(TVLManager *)player {
38
- if(self.player) {
38
+ if (self.player) {
39
39
  [self clearObservers];
40
40
  }
41
41
  self.player = player;
@@ -0,0 +1,4 @@
1
+ module react_native_velive_pull {
2
+ header "../pictureInpicture/PictureInPictureManager.h"
3
+ export *
4
+ }
@@ -1,3 +1,4 @@
1
+ #import <AVKit/AVKit.h>
1
2
  #import <Foundation/Foundation.h>
2
3
  @class TVLManager;
3
4
  @class UIView;
@@ -11,6 +12,16 @@
11
12
 
12
13
  @interface VeLivePictureInPictureManager : NSObject
13
14
 
15
+ // Configure whether to support automatic picture-in-picture in background
16
+ // Default is NO
17
+ @property(nonatomic, assign)
18
+ BOOL canStartPictureInPictureAutomaticallyFromInline API_AVAILABLE(ios(14.2)
19
+ );
20
+
21
+ // Whether to automatically hide the current player's view controller after
22
+ // starting picture-in-picture, default is NO
23
+ @property(nonatomic, assign) BOOL autoHideViewController;
24
+
14
25
  // Expose shared instance methods to RN
15
26
  + (instancetype)sharedInstance;
16
27
  + (instancetype)getInstance;
@@ -25,5 +36,14 @@
25
36
  - (BOOL)isPictureInPictureSupported;
26
37
  - (void)setListener:(id<VeLivePictureInPictureManagerListener>)listener;
27
38
 
39
+ // register a PIP controller observer, returns an observer ID
40
+ - (NSString *)addPipControllerObserver:
41
+ (void (^)(AVPictureInPictureController *pipController))observer;
42
+
43
+ // remove a PIP controller observer by its ID
44
+ - (void)removePipControllerObserver:(NSString *)observerId;
28
45
 
29
- @end
46
+ // This method is used to remove all observers registered for the PIP controller
47
+ - (void)removeAllPipControllerObservers;
48
+
49
+ @end