UNPKG

@tencentcloud/roomkit-web-vue3

Version:

<h1 align="center"> TUIRoomKit</h1> Conference (TUIRoomKit) is a product suitable for multi-person audio and video conversation scenarios such as business meetings, webinars, and online education. By integrating this product, you can add room management,

97 lines (96 loc) 2.9 kB
import { ref } from "vue"; import useRoomEngine from "../../../hooks/useRoomEngine.mjs"; import { TRTCBeautyStyle } from "../../../constants/room.mjs"; import logger from "../../../utils/common/logger/index.mjs"; const roomEngine = useRoomEngine(); let isBeautyReady = false; const beautyConfig = ref({ beautyLevel: 0, whitenessLevel: 0, ruddinessLevel: 0 }); const cachedBeautyConfig = { beautyLevel: 0, whitenessLevel: 0, ruddinessLevel: 0 }; async function setFreeBeauty(config) { cachedBeautyConfig.beautyLevel = config.beautyLevel; cachedBeautyConfig.whitenessLevel = config.whitenessLevel; cachedBeautyConfig.ruddinessLevel = config.ruddinessLevel; const beautyLevel = convertLevel(config.beautyLevel); const whitenessLevel = convertLevel(config.whitenessLevel); const ruddinessLevel = convertLevel(config.ruddinessLevel); await startCameraTestBeauty(beautyLevel, whitenessLevel, ruddinessLevel); } async function saveBeautySetting() { var _a; beautyConfig.value = { ...cachedBeautyConfig }; const trtcCloud = (_a = roomEngine.instance) == null ? void 0 : _a.getTRTCCloud(); if (trtcCloud === void 0) { logger.error("trtcCloud is undefined"); return; } logger.log("saveBeautySetting:", beautyConfig.value); const style = TRTCBeautyStyle.TRTCBeautyStyleNature; const beautyLevel = convertLevel(beautyConfig.value.beautyLevel); const whitenessLevel = convertLevel(beautyConfig.value.whitenessLevel); const ruddinessLevel = convertLevel(beautyConfig.value.ruddinessLevel); await checkInitBeauty(); await trtcCloud.setBeautyStyle( style, beautyLevel, whitenessLevel, ruddinessLevel ); } async function startCameraTestBeauty(beautyLevel, whitenessLevel, ruddinessLevel) { var _a; const trtcCloud = (_a = roomEngine.instance) == null ? void 0 : _a.getTRTCCloud(); if (trtcCloud === void 0) { logger.error("trtcCloud is undefined"); return; } await checkInitBeauty(); await trtcCloud.callExperimentalAPI( JSON.stringify({ api: "enableTestBeautyStyle", params: { style: TRTCBeautyStyle.TRTCBeautyStyleNature, beautyLevel, whitenessLevel, ruddinessLevel } }) ); } async function checkInitBeauty() { var _a; const trtcCloud = (_a = roomEngine.instance) == null ? void 0 : _a.getTRTCCloud(); if (trtcCloud === void 0) { logger.error("trtcCloud is undefined"); return; } if (isBeautyReady === false) { try { await trtcCloud.useBeautyStyle(); isBeautyReady = true; } catch (error) { logger.error("useBeautyStyle failed, error:", error); isBeautyReady = false; } } } function convertLevel(level) { return Math.floor(level / 100 * 9); } function useVideoEffectState() { return { beautyConfig, setFreeBeauty, saveBeautySetting }; } export { useVideoEffectState as default };