TrtcCloudImpl.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  2. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  3. return new (P || (P = Promise))(function (resolve, reject) {
  4. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  5. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  6. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  7. step((generator = generator.apply(thisArg, _arguments || [])).next());
  8. });
  9. };
  10. import { NAME } from './constants';
  11. import { TRTCRoleType, TRTCAudioQuality, TRTCVideoRotation, TRTCVideoFillMode, TRTCVideoMirrorType, TRTCVideoStreamType, TRTCVideoEncParam, TRTCAppScene, TRTCAudioRoute, TRTCBeautyStyle, } from './TrtcDefines';
  12. import TrtcError, { TXLiteJSError, generateError_ } from './TrtcCode';
  13. const TrtcNativeTrtcCloudModule = uni.requireNativePlugin('TRTCCloudUniPlugin-TRTCCloudImpl');
  14. const TXAudioEffectManagerModule = uni.requireNativePlugin('TRTCCloudUniPlugin-TRTCCloudImpl-TXAudioEffectManagerModule');
  15. const TrtcEvent = uni.requireNativePlugin('globalEvent');
  16. let trtcCloud = null; // trtcCloud 单例
  17. export default class TrtcCloudImpl {
  18. constructor() {
  19. this.listenersMap_ = new Map();
  20. }
  21. static _createInstance() {
  22. try {
  23. if (trtcCloud) {
  24. return trtcCloud;
  25. }
  26. TrtcNativeTrtcCloudModule.sharedInstance();
  27. trtcCloud = new TrtcCloudImpl();
  28. return trtcCloud;
  29. }
  30. catch (error) {
  31. throw generateError_(error);
  32. }
  33. }
  34. static _getInstance() {
  35. if (trtcCloud) {
  36. return trtcCloud;
  37. }
  38. throw new TrtcError({
  39. code: TXLiteJSError.INVALID_OPERATION,
  40. message: 'get trtcCloud failed, please create trtcCloud first',
  41. });
  42. }
  43. static _destroyInstance() {
  44. try {
  45. trtcCloud = null;
  46. TrtcNativeTrtcCloudModule.destroySharedInstance();
  47. }
  48. catch (error) {
  49. throw new TrtcError({
  50. code: error.code || TXLiteJSError.UNKNOWN,
  51. message: error.message,
  52. name: error.name,
  53. });
  54. }
  55. }
  56. // 截图保存
  57. // async saveImage_(base64Data) {
  58. // return new Promise((resolve, reject) => {
  59. // let bitmap = new plus.nativeObj.Bitmap();
  60. // bitmap.loadBase64Data(base64Data, () => {
  61. // const url = "_doc/" + new Date().getTime() + ".png"; // url为时间戳命名方式
  62. // console.log('saveHeadImgFile', url);
  63. // bitmap.save(url, { overwrite: true }, (i) => {
  64. // uni.saveImageToPhotosAlbum({
  65. // filePath: url,
  66. // success: function() {
  67. // uni.showToast({
  68. // title: '图片保存成功',
  69. // icon: 'none'
  70. // })
  71. // bitmap.clear();
  72. // resolve({ code: 0, message: '图片保存成功' });
  73. // }
  74. // });
  75. // }, (e) => {
  76. // uni.showToast({
  77. // title: '图片保存失败, 请重新截图',
  78. // icon: 'none'
  79. // })
  80. // bitmap.clear();
  81. // resolve({ code: -1, message: '图片保存失败, 请重新截图' });
  82. // });
  83. // });
  84. // });
  85. // }
  86. on(event, callback) {
  87. if (typeof event !== NAME.STRING || typeof callback !== NAME.FUNCTION) {
  88. throw new TrtcError({
  89. code: TXLiteJSError.INVALID_PARAMETER,
  90. message: `${NAME.LOG_PREFIX} please check the on method parameter types. event type is a ${typeof event}; callback type is a ${typeof callback}`,
  91. });
  92. }
  93. const nativeListener = (res) => __awaiter(this, void 0, void 0, function* () {
  94. const { data = [] } = res;
  95. const code = data[0];
  96. const message = data[1] || '';
  97. const extraInfo = data[2] || {};
  98. switch (event) {
  99. case 'onEnterRoom': {
  100. const result = code;
  101. callback(result);
  102. break;
  103. }
  104. case 'onExitRoom': {
  105. const reason = code;
  106. callback(reason);
  107. break;
  108. }
  109. case 'onFirstVideoFrame': {
  110. const userId = code;
  111. const streamType = data[1] || 0;
  112. const width = data[2] || 0;
  113. const height = data[3] || 0;
  114. callback({ userId, streamType, width, height });
  115. break;
  116. }
  117. case 'onFirstAudioFrame': {
  118. const userId = code || '';
  119. callback(userId);
  120. break;
  121. }
  122. case 'onMicDidReady': {
  123. callback();
  124. break;
  125. }
  126. case 'onCameraDidReady': {
  127. callback();
  128. break;
  129. }
  130. case 'onNetworkQuality': {
  131. const localQuality = data[0];
  132. const remoteQuality = data[1];
  133. callback({ localQuality, remoteQuality });
  134. break;
  135. }
  136. case 'onRemoteUserEnterRoom': {
  137. const userId = code || '';
  138. callback(userId);
  139. break;
  140. }
  141. case 'onRemoteUserLeaveRoom': {
  142. const userId = code || '';
  143. const reason = message;
  144. callback({ userId, reason });
  145. break;
  146. }
  147. case 'onSendFirstLocalAudioFrame': {
  148. callback();
  149. break;
  150. }
  151. case 'onSendFirstLocalVideoFrame': {
  152. const streamType = code;
  153. callback(streamType);
  154. break;
  155. }
  156. case 'onStatistics': {
  157. const statics = data[0] || {};
  158. callback(statics);
  159. break;
  160. }
  161. case 'onUserAudioAvailable': {
  162. const userId = code || '';
  163. const available = message;
  164. callback({ userId, available });
  165. break;
  166. }
  167. case 'onUserVideoAvailable': {
  168. const userId = code || '';
  169. const available = message;
  170. callback({ userId, available });
  171. break;
  172. }
  173. case 'onUserVoiceVolume': {
  174. const userVolumes = data[0];
  175. const totalVolume = data[1];
  176. callback({ userVolumes, totalVolume });
  177. break;
  178. }
  179. case 'onSwitchRole': {
  180. callback({ code, message });
  181. break;
  182. }
  183. case 'onScreenCaptureStarted': {
  184. callback({ code, message });
  185. break;
  186. }
  187. case 'onScreenCapturePaused': {
  188. callback({ code, message });
  189. break;
  190. }
  191. case 'onScreenCaptureResumed': {
  192. callback({ code, message });
  193. break;
  194. }
  195. case 'onScreenCaptureStopped': {
  196. callback({ code, message });
  197. break;
  198. }
  199. case 'onUserSubStreamAvailable': {
  200. const userId = code || '';
  201. const available = message;
  202. callback({ userId, available });
  203. break;
  204. }
  205. case 'onSnapshotComplete': {
  206. // base64 直接保存到本地图库
  207. // const { code: snapShotCode, message: msg } = await this.saveImage_(code);
  208. // callback({ snapShotCode, message: msg });
  209. callback({ base64Data: code, message });
  210. break;
  211. }
  212. case 'onUserVideoSizeChanged': {
  213. callback(data);
  214. break;
  215. }
  216. case 'onStart': {
  217. callback({ id: code, errCode: message });
  218. break;
  219. }
  220. case 'onPlayProgress': {
  221. callback({ id: code, curPtsMS: message, durationMS: extraInfo });
  222. break;
  223. }
  224. case 'onComplete': {
  225. callback({ id: code, errCode: message });
  226. break;
  227. }
  228. case 'onConnectOtherRoom': {
  229. // 拿不到 userid, 为了和 native 参数保持一致,所以空字符串代替
  230. callback({ userId: '', errCode: code, errMsg: message });
  231. break;
  232. }
  233. case 'onDisconnectOtherRoom': {
  234. callback({ errCode: code, errMsg: message });
  235. break;
  236. }
  237. case 'onError': {
  238. console.error(`onError: ${code}, ${message}, ${extraInfo}`);
  239. callback(generateError_({ message }, code, extraInfo));
  240. break;
  241. }
  242. default: {
  243. callback({ code, message, extraInfo });
  244. }
  245. }
  246. });
  247. this.listenersMap_.set(event, nativeListener); // 多次设置同一个事件时,后面的 callback 覆盖前面
  248. TrtcEvent.addEventListener(event, nativeListener);
  249. }
  250. off(event) {
  251. if (typeof event !== NAME.STRING) {
  252. throw new TrtcError({
  253. code: TXLiteJSError.INVALID_PARAMETER,
  254. message: `${NAME.LOG_PREFIX} please check the off method parameter types. event type is a ${typeof event} not a ${NAME.STRING}`,
  255. });
  256. }
  257. try {
  258. if (event === '*') {
  259. this.listenersMap_.forEach((value, key) => {
  260. TrtcEvent.removeEventListener(key, value);
  261. });
  262. this.listenersMap_.clear();
  263. }
  264. else {
  265. TrtcEvent.removeEventListener(event, this.listenersMap_.get(event));
  266. this.listenersMap_.delete(event);
  267. }
  268. }
  269. catch (error) {
  270. throw generateError_(error);
  271. }
  272. }
  273. enterRoom(params, scene) {
  274. if (scene !== TRTCAppScene.TRTCAppSceneVideoCall && scene !== TRTCAppScene.TRTCAppSceneLIVE && scene !== TRTCAppScene.TRTCAppSceneAudioCall && scene !== TRTCAppScene.TRTCAppSceneVoiceChatRoom) {
  275. throw new TrtcError({
  276. code: TXLiteJSError.INVALID_PARAMETER,
  277. message: `${NAME.LOG_PREFIX} please check the enterRoom method parameters. scene is not of TRTCAppScene`,
  278. });
  279. }
  280. try {
  281. const enterRoomParams = Object.assign(Object.assign({}, params), { role: params.role || TRTCRoleType.TRTCRoleAnchor, appScene: scene });
  282. TrtcNativeTrtcCloudModule.enterRoom(enterRoomParams);
  283. }
  284. catch (error) {
  285. throw generateError_(error);
  286. }
  287. }
  288. exitRoom() {
  289. try {
  290. TrtcNativeTrtcCloudModule.exitRoom();
  291. }
  292. catch (error) {
  293. throw generateError_(error);
  294. }
  295. }
  296. connectOtherRoom(params) {
  297. try {
  298. TrtcNativeTrtcCloudModule.connectOtherRoom(params);
  299. }
  300. catch (error) {
  301. throw generateError_(error);
  302. }
  303. }
  304. disconnectOtherRoom() {
  305. try {
  306. TrtcNativeTrtcCloudModule.disconnectOtherRoom();
  307. }
  308. catch (error) {
  309. throw generateError_(error);
  310. }
  311. }
  312. switchRole(role) {
  313. if (role !== TRTCRoleType.TRTCRoleAnchor && role !== TRTCRoleType.TRTCRoleAudience) {
  314. throw new TrtcError({
  315. code: TXLiteJSError.INVALID_PARAMETER,
  316. message: `${NAME.LOG_PREFIX} please check the switchRole method parameter. role is not of TRTCRoleType`,
  317. });
  318. }
  319. try {
  320. role && TrtcNativeTrtcCloudModule.switchRole(role);
  321. }
  322. catch (error) {
  323. throw generateError_(error);
  324. }
  325. }
  326. startLocalPreview(isFrontCamera = true, viewId) {
  327. if (typeof isFrontCamera !== NAME.BOOLEAN || !viewId || typeof viewId !== NAME.STRING) {
  328. throw new TrtcError({
  329. code: TXLiteJSError.INVALID_PARAMETER,
  330. message: `${NAME.LOG_PREFIX} please check the startLocalPreview method parameters`,
  331. });
  332. }
  333. try {
  334. let param = { isFrontCamera: !!isFrontCamera };
  335. param = viewId ? Object.assign(Object.assign({}, param), { userId: viewId }) : param;
  336. TrtcNativeTrtcCloudModule.startLocalPreview(param);
  337. }
  338. catch (error) {
  339. throw generateError_(error);
  340. }
  341. }
  342. setVideoEncoderParam(param) {
  343. try {
  344. TrtcNativeTrtcCloudModule.setVideoEncoderParam(param);
  345. }
  346. catch (error) {
  347. throw generateError_(error);
  348. }
  349. }
  350. stopLocalPreview() {
  351. try {
  352. TrtcNativeTrtcCloudModule.stopLocalPreview();
  353. }
  354. catch (error) {
  355. throw generateError_(error);
  356. }
  357. }
  358. switchCamera(isFrontCamera) {
  359. if (typeof isFrontCamera !== NAME.BOOLEAN) {
  360. throw new TrtcError({
  361. code: TXLiteJSError.INVALID_PARAMETER,
  362. message: `${NAME.LOG_PREFIX} please check the switchCamera method parameter`,
  363. });
  364. }
  365. try {
  366. TrtcNativeTrtcCloudModule.switchCamera(isFrontCamera);
  367. }
  368. catch (error) {
  369. throw generateError_(error);
  370. }
  371. }
  372. setLocalRenderParams(params) {
  373. try {
  374. const { rotation = TRTCVideoRotation.TRTCVideoRotation_0, fillMode = TRTCVideoFillMode.TRTCVideoFillMode_Fill, mirrorType = TRTCVideoMirrorType.TRTCVideoMirrorType_Auto } = params;
  375. TrtcNativeTrtcCloudModule.setLocalRenderParams({
  376. rotation,
  377. fillMode,
  378. mirrorType,
  379. });
  380. }
  381. catch (error) {
  382. throw generateError_(error);
  383. }
  384. }
  385. muteLocalVideo(streamType, mute) {
  386. if (streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub || typeof mute !== NAME.BOOLEAN) {
  387. throw new TrtcError({
  388. code: TXLiteJSError.INVALID_PARAMETER,
  389. message: `${NAME.LOG_PREFIX} please check the muteLocalVideo method parameters`,
  390. });
  391. }
  392. try {
  393. TrtcNativeTrtcCloudModule.muteLocalVideo({ streamType, mute: !!mute });
  394. }
  395. catch (error) {
  396. throw generateError_(error);
  397. }
  398. }
  399. startRemoteView(userId, streamType, viewId) {
  400. if (!userId || streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSmall && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub || !viewId) {
  401. throw new TrtcError({
  402. code: TXLiteJSError.INVALID_PARAMETER,
  403. message: `${NAME.LOG_PREFIX} please check the startRemoteView method parameters`,
  404. });
  405. }
  406. try {
  407. TrtcNativeTrtcCloudModule.startRemoteView({ userId, streamType, viewId });
  408. }
  409. catch (error) {
  410. throw generateError_(error);
  411. }
  412. }
  413. stopRemoteView(userId, streamType) {
  414. if (!userId || streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSmall && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub) {
  415. throw new TrtcError({
  416. code: TXLiteJSError.INVALID_PARAMETER,
  417. message: `${NAME.LOG_PREFIX} please check the stopRemoteView method parameters`,
  418. });
  419. }
  420. try {
  421. TrtcNativeTrtcCloudModule.stopRemoteView({ userId, streamType });
  422. }
  423. catch (error) {
  424. throw generateError_(error);
  425. }
  426. }
  427. // 远端渲染设置
  428. setRemoteRenderParams(userId, streamType, params) {
  429. try {
  430. if (!userId || (streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub)) {
  431. throw new TrtcError({
  432. code: TXLiteJSError.INVALID_PARAMETER,
  433. message: `${NAME.LOG_PREFIX} please check the snapshotVideo method parameters`,
  434. });
  435. }
  436. const { rotation = TRTCVideoRotation.TRTCVideoRotation_0, fillMode = TRTCVideoFillMode.TRTCVideoFillMode_Fill, mirrorType = TRTCVideoMirrorType.TRTCVideoMirrorType_Auto } = params;
  437. TrtcNativeTrtcCloudModule.setRemoteRenderParams({
  438. userId,
  439. streamType,
  440. rotation,
  441. fillMode,
  442. mirrorType
  443. });
  444. }
  445. catch (error) {
  446. throw generateError_(error);
  447. }
  448. }
  449. // 截图
  450. snapshotVideo(userId, streamType, sourceType) {
  451. if (streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub) {
  452. throw new TrtcError({
  453. code: TXLiteJSError.INVALID_PARAMETER,
  454. message: `${NAME.LOG_PREFIX} please check the snapshotVideo method parameters`,
  455. });
  456. }
  457. try {
  458. TrtcNativeTrtcCloudModule.snapshotVideo({ userId: userId || null, streamType, sourceType });
  459. }
  460. catch (error) {
  461. throw generateError_(error);
  462. }
  463. }
  464. startLocalAudio(quality = TRTCAudioQuality.TRTCAudioQualityDefault) {
  465. if (quality !== TRTCAudioQuality.TRTCAudioQualitySpeech && quality !== TRTCAudioQuality.TRTCAudioQualityDefault && quality !== TRTCAudioQuality.TRTCAudioQualityMusic) {
  466. throw new TrtcError({
  467. code: TXLiteJSError.INVALID_PARAMETER,
  468. message: `${NAME.LOG_PREFIX} please check the startLocalAudio method parameters`,
  469. });
  470. }
  471. try {
  472. TrtcNativeTrtcCloudModule.startLocalAudio(quality);
  473. }
  474. catch (error) {
  475. throw generateError_(error);
  476. }
  477. }
  478. stopLocalAudio() {
  479. try {
  480. TrtcNativeTrtcCloudModule.stopLocalAudio();
  481. }
  482. catch (error) {
  483. throw generateError_(error);
  484. }
  485. }
  486. muteLocalAudio(mute) {
  487. if (typeof mute !== NAME.BOOLEAN) {
  488. throw new TrtcError({
  489. code: TXLiteJSError.INVALID_PARAMETER,
  490. message: `${NAME.LOG_PREFIX} please check the muteLocalAudio method parameters, mute type is a ${typeof mute} not a ${NAME.BOOLEAN}`,
  491. });
  492. }
  493. try {
  494. TrtcNativeTrtcCloudModule.muteLocalAudio(!!mute);
  495. }
  496. catch (error) {
  497. throw generateError_(error);
  498. }
  499. }
  500. muteRemoteAudio(userId, mute) {
  501. if (typeof mute !== NAME.BOOLEAN || !userId) {
  502. throw new TrtcError({
  503. code: TXLiteJSError.INVALID_PARAMETER,
  504. message: `${NAME.LOG_PREFIX} please check the muteRemoteAudio method parameters`,
  505. });
  506. }
  507. try {
  508. TrtcNativeTrtcCloudModule.muteRemoteAudio({ userId, mute: !!mute });
  509. }
  510. catch (error) {
  511. throw generateError_(error);
  512. }
  513. }
  514. muteAllRemoteAudio(mute) {
  515. if (typeof mute !== NAME.BOOLEAN) {
  516. throw new TrtcError({
  517. code: TXLiteJSError.INVALID_PARAMETER,
  518. message: `${NAME.LOG_PREFIX} please check the muteAllRemoteAudio method parameters, mute type is a ${typeof mute} not a ${NAME.BOOLEAN}`,
  519. });
  520. }
  521. try {
  522. TrtcNativeTrtcCloudModule.muteAllRemoteAudio(!!mute);
  523. }
  524. catch (error) {
  525. throw generateError_(error);
  526. }
  527. }
  528. setAudioRoute(route) {
  529. if (route !== TRTCAudioRoute.TRTCAudioRouteSpeaker && route !== TRTCAudioRoute.TRTCAudioRouteEarpiece) {
  530. throw new TrtcError({
  531. code: TXLiteJSError.INVALID_PARAMETER,
  532. message: `${NAME.LOG_PREFIX} please check the setAudioRoute method parameter, route is not of TRTCAudioRoute`,
  533. });
  534. }
  535. try {
  536. TrtcNativeTrtcCloudModule.setAudioRoute(route);
  537. }
  538. catch (error) {
  539. throw generateError_(error);
  540. }
  541. }
  542. enableAudioVolumeEvaluation(interval) {
  543. if (typeof interval !== NAME.NUMBER) {
  544. throw new TrtcError({
  545. code: TXLiteJSError.INVALID_PARAMETER,
  546. message: `${NAME.LOG_PREFIX} please check the enableAudioVolumeEvaluation method parameter, interval type is a ${typeof interval} not a ${NAME.NUMBER}`,
  547. });
  548. }
  549. try {
  550. interval > 0 && TrtcNativeTrtcCloudModule.enableAudioVolumeEvaluation(interval);
  551. }
  552. catch (error) {
  553. throw generateError_(error);
  554. }
  555. }
  556. // ///////////////////////////////////////////////////////////////////////////////
  557. //
  558. // 美颜 + 水印
  559. //
  560. // ///////////////////////////////////////////////////////////////////////////////
  561. setBeautyStyle(beautyStyle) {
  562. if (beautyStyle !== TRTCBeautyStyle.TRTCBeautyStyleSmooth && beautyStyle !== TRTCBeautyStyle.TRTCBeautyStyleNature && beautyStyle !== TRTCBeautyStyle.TRTCBeautyStylePitu) {
  563. throw new TrtcError({
  564. code: TXLiteJSError.INVALID_PARAMETER,
  565. message: `${NAME.LOG_PREFIX} please check the setBeautyStyle method parameter, beautyStyle is not of TRTCBeautyStyle`,
  566. });
  567. }
  568. try {
  569. TrtcNativeTrtcCloudModule.setBeautyStyle(beautyStyle);
  570. }
  571. catch (error) {
  572. throw generateError_(error);
  573. }
  574. }
  575. setBeautyLevel(beautyLevel) {
  576. if (typeof beautyLevel !== NAME.NUMBER || (beautyLevel < 0 || beautyLevel > 9)) {
  577. throw new TrtcError({
  578. code: TXLiteJSError.INVALID_PARAMETER,
  579. message: `${NAME.LOG_PREFIX} please check the setBeautyLevel method parameter, beautyLevel should in the range 0-9`,
  580. });
  581. }
  582. try {
  583. TrtcNativeTrtcCloudModule.setBeautyLevel(beautyLevel);
  584. }
  585. catch (error) {
  586. throw generateError_(error);
  587. }
  588. }
  589. // ///////////////////////////////////////////////////////////////////////////////
  590. //
  591. // 背景音效
  592. //
  593. // ///////////////////////////////////////////////////////////////////////////////
  594. startPlayMusic(musicParam) {
  595. try {
  596. const { id = 0 } = musicParam || {};
  597. TXAudioEffectManagerModule.startPlayMusic(Object.assign(Object.assign({}, musicParam), { ID: id })); // v1.2.0 的 iOS 解析的是 ID, v1.2.1 插件进行了修复
  598. }
  599. catch (error) {
  600. throw generateError_(error);
  601. }
  602. }
  603. stopPlayMusic(id) {
  604. try {
  605. TXAudioEffectManagerModule.stopPlayMusic(id);
  606. }
  607. catch (error) {
  608. throw generateError_(error);
  609. }
  610. }
  611. pausePlayMusic(id) {
  612. try {
  613. TXAudioEffectManagerModule.pausePlayMusic(id);
  614. }
  615. catch (error) {
  616. throw generateError_(error);
  617. }
  618. }
  619. resumePlayMusic(id) {
  620. try {
  621. TXAudioEffectManagerModule.resumePlayMusic(id);
  622. }
  623. catch (error) {
  624. throw generateError_(error);
  625. }
  626. }
  627. // ///////////////////////////////////////////////////////////////////////////////
  628. //
  629. // 屏幕分享
  630. //
  631. // ///////////////////////////////////////////////////////////////////////////////
  632. setSubStreamEncoderParam(param) {
  633. try {
  634. TrtcNativeTrtcCloudModule.setSubStreamEncoderParam(param);
  635. }
  636. catch (error) {
  637. throw generateError_(error);
  638. }
  639. }
  640. startScreenCapture(streamType = TRTCVideoStreamType.TRTCVideoStreamTypeSub, encParams = null) {
  641. try {
  642. let platform = uni.getSystemInfoSync().platform;
  643. if ((streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeSub && streamType !== TRTCVideoStreamType.TRTCVideoStreamTypeBig)) {
  644. streamType = TRTCVideoStreamType.TRTCVideoStreamTypeSub;
  645. }
  646. const screenCaptureParams = Object.assign({ streamType }, encParams);
  647. if (platform === NAME.ANDROID) {
  648. TrtcNativeTrtcCloudModule.startScreenCapture(screenCaptureParams);
  649. }
  650. if (platform === NAME.IOS) {
  651. // 开始应用内的屏幕分享(仅支持 iOS 13.0 及以上系统)
  652. TrtcNativeTrtcCloudModule.startScreenCaptureInApp(screenCaptureParams);
  653. // if (shareSource === TRTCShareSource.InApp) {
  654. // TrtcNativeTrtcCloudModule.startScreenCaptureInApp(screenCaptureParams);
  655. // }
  656. // // 开始全系统的屏幕分享(仅支持 iOS 11.0 及以上系统)
  657. // if (shareSource === TRTCShareSource.ByReplaykit) {
  658. // TrtcNativeTrtcCloudModule.startScreenCaptureByReplaykit({ ...screenCaptureParams, appGroup: null });
  659. // }
  660. }
  661. }
  662. catch (error) {
  663. throw generateError_(error);
  664. }
  665. }
  666. stopScreenCapture() {
  667. try {
  668. TrtcNativeTrtcCloudModule.stopScreenCapture();
  669. }
  670. catch (error) {
  671. throw generateError_(error);
  672. }
  673. }
  674. pauseScreenCapture() {
  675. try {
  676. TrtcNativeTrtcCloudModule.pauseScreenCapture();
  677. }
  678. catch (error) {
  679. throw generateError_(error);
  680. }
  681. }
  682. resumeScreenCapture() {
  683. try {
  684. TrtcNativeTrtcCloudModule.resumeScreenCapture();
  685. }
  686. catch (error) {
  687. throw generateError_(error);
  688. }
  689. }
  690. }