@byteplus/react-native-live-push 1.3.0-rc.0 → 1.3.0-rc.2

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 +1 -1
  2. package/android/src/main/java/com/volcengine/velive/rn/push/VeLiveEffectHelper.java +222 -0
  3. package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushModule.java +2 -0
  4. package/android/src/main/java/com/volcengine/velive/rn/push/mixer/TextureMgr.java +6 -1
  5. package/ios/VeLivePushHelper.h +2 -1
  6. package/ios/VeLivePushHelper.m +7 -0
  7. package/lib/commonjs/index.js +487 -279
  8. package/lib/commonjs/typescript/core/api.d.ts +7 -1
  9. package/lib/commonjs/typescript/core/effect.d.ts +15 -0
  10. package/lib/commonjs/typescript/core/index.d.ts +1 -0
  11. package/lib/commonjs/typescript/platforms/android/extends.d.ts +2 -0
  12. package/lib/commonjs/typescript/platforms/android/helper.d.ts +10 -0
  13. package/lib/commonjs/typescript/platforms/ios/helper.d.ts +1 -0
  14. package/lib/commonjs/typescript/utils/index.d.ts +4 -0
  15. package/lib/module/index.js +487 -280
  16. package/lib/module/typescript/core/api.d.ts +7 -1
  17. package/lib/module/typescript/core/effect.d.ts +15 -0
  18. package/lib/module/typescript/core/index.d.ts +1 -0
  19. package/lib/module/typescript/platforms/android/extends.d.ts +2 -0
  20. package/lib/module/typescript/platforms/android/helper.d.ts +10 -0
  21. package/lib/module/typescript/platforms/ios/helper.d.ts +1 -0
  22. package/lib/module/typescript/utils/index.d.ts +4 -0
  23. package/lib/typescript/core/api.d.ts +7 -1
  24. package/lib/typescript/core/effect.d.ts +15 -0
  25. package/lib/typescript/core/index.d.ts +1 -0
  26. package/lib/typescript/platforms/android/extends.d.ts +2 -0
  27. package/lib/typescript/platforms/android/helper.d.ts +10 -0
  28. package/lib/typescript/platforms/ios/helper.d.ts +1 -0
  29. package/lib/typescript/utils/index.d.ts +4 -0
  30. package/package.json +1 -1
  31. package/react-native-velive-push.podspec +3 -3
@@ -87,6 +87,6 @@ dependencies {
87
87
  // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
88
88
  //noinspection GradleDynamicVersion
89
89
  implementation "com.facebook.react:react-native:+"
90
- implementation "com.volcengine:VolcApiEngine:1.6.2"
90
+ implementation "com.volcengine:VolcApiEngine:1.6.4"
91
91
  api 'com.bytedanceapi:ttsdk-ttlivepush_rtc:1.46.300.2'
92
92
  }
@@ -0,0 +1,222 @@
1
+ package com.volcengine.velive.rn.push;
2
+
3
+ import android.content.Context;
4
+ import android.text.TextUtils;
5
+
6
+ import com.pandora.common.env.Env;
7
+
8
+ import java.io.File;
9
+ import java.io.FileInputStream;
10
+ import java.io.FileOutputStream;
11
+ import java.io.IOException;
12
+ import java.io.InputStream;
13
+ import java.io.OutputStream;
14
+
15
+ public class VeLiveEffectHelper {
16
+ static Context context;
17
+ /**
18
+ * 获取证书文件路径
19
+ */
20
+ public static String getLicensePath(String name) {
21
+ // Context context = Env.getApplicationContext();
22
+ if (context == null) {
23
+ throw new IllegalStateException("context not set");
24
+ }
25
+ return context.getExternalFilesDir("assets").getAbsolutePath()
26
+ + "/resource/LicenseBag.bundle/" + name;
27
+ }
28
+
29
+ /**
30
+ * 获取模型文件路径
31
+ */
32
+ public static String getModelPath() {
33
+ // Context context = Env.getApplicationContext();
34
+ if (context == null) {
35
+ throw new IllegalStateException("context not set");
36
+ }
37
+ return context.getExternalFilesDir("assets").getAbsolutePath()
38
+ + "/resource/ModelResource.bundle";
39
+ }
40
+
41
+ /**
42
+ * 获取美颜文件路径
43
+ */
44
+ public static String getBeautyPathByName(String subPath) {
45
+ // Context context = Env.getApplicationContext();
46
+ if (context == null) {
47
+ throw new IllegalStateException("context not set");
48
+ }
49
+ return context.getExternalFilesDir("assets").getAbsolutePath()
50
+ + "/resource/ComposeMakeup.bundle/ComposeMakeup/" + subPath;
51
+ }
52
+
53
+ /**
54
+ * 获取贴纸文件路径
55
+ *
56
+ * @param name 贴纸文件名称
57
+ */
58
+ public static String getStickerPathByName(String name) {
59
+ // Context context = Env.getApplicationContext();
60
+ if (context == null) {
61
+ throw new IllegalStateException("context not set");
62
+ }
63
+ return context.getExternalFilesDir("assets").getAbsolutePath()
64
+ + "/resource/StickerResource.bundle/stickers/" + name;
65
+ }
66
+
67
+ /**
68
+ * 获取滤镜文件路径
69
+ *
70
+ * @param name 滤镜文件名称
71
+ */
72
+ public static String getFilterPathByName(String name) {
73
+ // Context context = Env.getApplicationContext();
74
+ if (context == null) {
75
+ throw new IllegalStateException("context not set");
76
+ }
77
+ return context.getExternalFilesDir("assets").getAbsolutePath()
78
+ + "/resource/FilterResource.bundle/Filter/" + name;
79
+ }
80
+
81
+ /**
82
+ * 初始化美颜资源文件
83
+ * 将安装包内的资源文件拷贝到外部存储上
84
+ */
85
+ public static void initVideoEffectResource() {
86
+ // Context context = Env.getApplicationContext();
87
+ if (context == null) {
88
+ throw new IllegalStateException("context not set");
89
+ }
90
+
91
+ // File versionFile = new File(getExternalResourcePath(), "version");
92
+ // if (versionFile.exists()) {
93
+ // String oldVer = readVersion(versionFile.getAbsolutePath());
94
+ // copyAssetFolder(context, "resource/version", versionFile.getAbsolutePath());
95
+ // String newVer = readVersion(versionFile.getAbsolutePath());
96
+ // if (TextUtils.equals(oldVer, newVer)) {
97
+ // return;
98
+ // }
99
+ // } else {
100
+ // copyAssetFile(context, "resource/version", versionFile.getAbsolutePath());
101
+ // }
102
+ updateEffectResource(context);
103
+ }
104
+
105
+ private static String readVersion(String fileName) {
106
+ String version = "";
107
+ try {
108
+ FileInputStream fin = new FileInputStream(fileName);
109
+ int length = fin.available();
110
+ byte[] buffer = new byte[length];
111
+ fin.read(buffer);
112
+ version = new String(buffer);
113
+ fin.close();
114
+ } catch (Exception e) {
115
+ e.printStackTrace();
116
+ }
117
+ return version;
118
+ }
119
+
120
+ private static void updateEffectResource(Context context) {
121
+ File licensePath = new File(getExternalResourcePath(), "LicenseBag.bundle");
122
+ removeFile(licensePath.getAbsolutePath());
123
+ copyAssetFolder(context, "resource/LicenseBag.bundle", licensePath.getAbsolutePath());
124
+ File modelPath = new File(getExternalResourcePath(), "ModelResource.bundle");
125
+ removeFile(modelPath.getAbsolutePath());
126
+ copyAssetFolder(context, "resource/ModelResource.bundle", modelPath.getAbsolutePath());
127
+ File stickerPath = new File(getExternalResourcePath(), "StickerResource.bundle");
128
+ removeFile(stickerPath.getAbsolutePath());
129
+ copyAssetFolder(context, "resource/StickerResource.bundle", stickerPath.getAbsolutePath());
130
+ File filterPath = new File(getExternalResourcePath(), "FilterResource.bundle");
131
+ removeFile(filterPath.getAbsolutePath());
132
+ copyAssetFolder(context, "resource/FilterResource.bundle", filterPath.getAbsolutePath());
133
+ File composerPath = new File(getExternalResourcePath(), "ComposeMakeup.bundle");
134
+ removeFile(composerPath.getAbsolutePath());
135
+ copyAssetFolder(context, "resource/ComposeMakeup.bundle", composerPath.getAbsolutePath());
136
+ }
137
+
138
+ private static void removeFile(String filePath) {
139
+ if (filePath == null || filePath.length() == 0) {
140
+ return;
141
+ }
142
+ try {
143
+ File file = new File(filePath);
144
+ if (file.exists()) {
145
+ removeFile(file);
146
+ }
147
+ } catch (Exception ex) {
148
+ ex.printStackTrace();
149
+ }
150
+ }
151
+
152
+ private static void removeFile(File file) {
153
+ // 如果是文件直接删除
154
+ if (file.isFile()) {
155
+ file.delete();
156
+ return;
157
+ }
158
+ // 如果是目录,递归判断,如果是空目录,直接删除,如果是文件,遍历删除
159
+ if (file.isDirectory()) {
160
+ File[] childFile = file.listFiles();
161
+ if (childFile == null || childFile.length == 0) {
162
+ file.delete();
163
+ return;
164
+ }
165
+ for (File f : childFile) {
166
+ removeFile(f);
167
+ }
168
+ file.delete();
169
+ }
170
+ }
171
+
172
+ public static String getExternalResourcePath() {
173
+ // Context context = Env.getApplicationContext();
174
+ if (context == null) {
175
+ throw new IllegalStateException("context not set");
176
+ }
177
+ return context.getExternalFilesDir("assets").getAbsolutePath() + "/resource/";
178
+ }
179
+
180
+ public static boolean copyAssetFolder(Context context, String srcName, String dstName) {
181
+ try {
182
+ boolean result = true;
183
+ String fileList[] = context.getAssets().list(srcName);
184
+ if (fileList == null)
185
+ return false;
186
+
187
+ if (fileList.length == 0) {
188
+ result = copyAssetFile(context, srcName, dstName);
189
+ } else {
190
+ File file = new File(dstName);
191
+ result = file.mkdirs();
192
+ for (String filename : fileList) {
193
+ result &= copyAssetFolder(context, srcName + File.separator + filename, dstName + File.separator + filename);
194
+ }
195
+ }
196
+ return result;
197
+ } catch (IOException e) {
198
+ e.printStackTrace();
199
+ return false;
200
+ }
201
+ }
202
+
203
+ public static boolean copyAssetFile(Context context, String srcName, String dstName) {
204
+ try {
205
+ InputStream in = context.getAssets().open(srcName);
206
+ File outFile = new File(dstName);
207
+ OutputStream out = new FileOutputStream(outFile);
208
+ byte[] buffer = new byte[1024];
209
+ int read;
210
+ while ((read = in.read(buffer)) != -1) {
211
+ out.write(buffer, 0, read);
212
+ }
213
+ in.close();
214
+ out.close();
215
+ return true;
216
+ } catch (IOException e) {
217
+ e.printStackTrace();
218
+ return false;
219
+ }
220
+ }
221
+
222
+ }
@@ -23,6 +23,7 @@ import com.ss.avframework.live.VeLivePusherObserver;
23
23
  import com.ss.avframework.live.statistics.VeLivePusherStatisticsExt;
24
24
  import com.volcengine.VolcApiEngine.*;
25
25
  import com.volcengine.VolcApiEngine.view.*;
26
+ import com.volcengine.velive.rn.push.VeLiveEffectHelper;
26
27
 
27
28
  import java.util.WeakHashMap;
28
29
 
@@ -37,6 +38,7 @@ public class VeLivePushModule extends VeLivePushModuleSpec implements IEventRece
37
38
 
38
39
  VeLivePushModule(ReactApplicationContext context) {
39
40
  super(context);
41
+ VeLiveEffectHelper.context = context;
40
42
  }
41
43
 
42
44
  @Override
@@ -52,7 +52,12 @@ public class TextureMgr {
52
52
  Bitmap bmp = null;
53
53
  Bitmap rotatedBmp = null;
54
54
  try {
55
- bm = new YuvHelper.NV21ToBitmap(Env.getApplicationContext());
55
+ android.content.Context context = Env.getApplicationContext();
56
+ if (context == null) {
57
+ // If context is null, skip processing and return
58
+ return;
59
+ }
60
+ bm = new YuvHelper.NV21ToBitmap(context);
56
61
  bmp = bm.nv21ToBitmap(byteBuffer.array(), width, height);
57
62
 
58
63
  if (bmp == null || bmp.isRecycled()) {
@@ -19,7 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
19
19
 
20
20
  + (void)removeVeLivePusher:(NSString *)key;
21
21
 
22
+ + (nullable NSString *)getResourcePath:(NSString *)subPath;
23
+
22
24
  @end
23
25
 
24
26
  NS_ASSUME_NONNULL_END
25
-
@@ -40,4 +40,11 @@ static NSMapTable<NSString *, VeLivePusher *> *pusherMap;
40
40
  [pusherMap removeObjectForKey:key];
41
41
  }
42
42
 
43
+ + (nullable NSString *)getResourcePath:(NSString *)subPath {
44
+ if (!subPath) {
45
+ return nil;
46
+ }
47
+ return [NSBundle.mainBundle pathForResource:subPath ofType:nil];
48
+ }
49
+
43
50
  @end