2021-07-20 04:19:06 +08:00
|
|
|
import deviceInfo from '/imports/utils/deviceInfo';
|
2021-07-28 01:10:06 +08:00
|
|
|
import browserInfo from '/imports/utils/browserInfo';
|
2021-07-20 04:19:06 +08:00
|
|
|
import { createVirtualBackgroundService } from '/imports/ui/services/virtual-background';
|
2024-07-26 02:05:13 +08:00
|
|
|
import { getStorageSingletonInstance } from '/imports/ui/services/storage';
|
2021-07-20 04:19:06 +08:00
|
|
|
|
|
|
|
const BLUR_FILENAME = 'blur.jpg';
|
|
|
|
const EFFECT_TYPES = {
|
|
|
|
BLUR_TYPE: 'blur',
|
|
|
|
IMAGE_TYPE: 'image',
|
|
|
|
NONE_TYPE: 'none',
|
2024-07-19 04:24:10 +08:00
|
|
|
};
|
2021-07-20 04:19:06 +08:00
|
|
|
|
|
|
|
const MODELS = {
|
|
|
|
model96: {
|
|
|
|
path: '/resources/tfmodels/segm_lite_v681.tflite',
|
|
|
|
segmentationDimensions: {
|
2024-07-19 04:24:10 +08:00
|
|
|
height: 96,
|
|
|
|
width: 160,
|
|
|
|
},
|
2021-07-20 04:19:06 +08:00
|
|
|
},
|
|
|
|
model144: {
|
|
|
|
path: '/resources/tfmodels/segm_full_v679.tflite',
|
|
|
|
segmentationDimensions: {
|
2024-07-19 04:24:10 +08:00
|
|
|
height: 144,
|
|
|
|
width: 256,
|
|
|
|
},
|
2021-07-20 04:19:06 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-05-29 21:26:11 +08:00
|
|
|
const getBasePath = () => {
|
|
|
|
const BASE_PATH = window.meetingClientSettings.public.app.cdn
|
2024-08-03 02:10:39 +08:00
|
|
|
+ window.meetingClientSettings.public.app.basename;
|
2024-05-29 21:26:11 +08:00
|
|
|
|
|
|
|
return BASE_PATH;
|
|
|
|
};
|
|
|
|
|
|
|
|
const getThumbnailsPath = () => {
|
|
|
|
const {
|
|
|
|
thumbnailsPath: THUMBNAILS_PATH = '/resources/images/virtual-backgrounds/thumbnails/',
|
|
|
|
} = window.meetingClientSettings.public.virtualBackgrounds;
|
|
|
|
|
|
|
|
return THUMBNAILS_PATH;
|
|
|
|
};
|
|
|
|
|
|
|
|
const getImageNames = () => {
|
|
|
|
const {
|
|
|
|
fileNames: IMAGE_NAMES = ['home.jpg', 'coffeeshop.jpg', 'board.jpg'],
|
|
|
|
} = window.meetingClientSettings.public.virtualBackgrounds;
|
|
|
|
|
|
|
|
return IMAGE_NAMES;
|
|
|
|
};
|
|
|
|
|
|
|
|
const getIsStoredOnBBB = () => {
|
|
|
|
const {
|
|
|
|
storedOnBBB: IS_STORED_ON_BBB = true,
|
|
|
|
} = window.meetingClientSettings.public.virtualBackgrounds;
|
|
|
|
|
|
|
|
return IS_STORED_ON_BBB;
|
|
|
|
};
|
2021-07-20 04:19:06 +08:00
|
|
|
|
2022-04-12 01:09:13 +08:00
|
|
|
const createVirtualBackgroundStream = (type, name, isVirtualBackground, stream, customParams) => {
|
2021-07-20 04:19:06 +08:00
|
|
|
const buildParams = {
|
|
|
|
backgroundType: type,
|
|
|
|
backgroundFilename: name,
|
|
|
|
isVirtualBackground,
|
2022-04-12 01:09:13 +08:00
|
|
|
customParams,
|
2024-07-19 04:24:10 +08:00
|
|
|
};
|
2021-07-20 04:19:06 +08:00
|
|
|
|
|
|
|
return createVirtualBackgroundService(buildParams).then((service) => {
|
2024-07-19 04:24:10 +08:00
|
|
|
const effect = service.startEffect(stream);
|
2021-07-20 04:19:06 +08:00
|
|
|
return { service, effect };
|
|
|
|
});
|
2024-07-19 04:24:10 +08:00
|
|
|
};
|
2021-07-20 04:19:06 +08:00
|
|
|
|
|
|
|
const getVirtualBackgroundThumbnail = (name) => {
|
|
|
|
if (name === BLUR_FILENAME) {
|
2024-07-19 04:24:10 +08:00
|
|
|
return `${getBasePath()}/resources/images/virtual-backgrounds/thumbnails/${name}`;
|
2021-07-20 04:19:06 +08:00
|
|
|
}
|
|
|
|
|
2024-05-29 21:26:11 +08:00
|
|
|
return (getIsStoredOnBBB() ? getBasePath() : '') + getThumbnailsPath() + name;
|
2024-07-19 04:24:10 +08:00
|
|
|
};
|
2021-07-20 04:19:06 +08:00
|
|
|
|
|
|
|
// Stores the last chosen camera effect into the session storage in the following format:
|
|
|
|
// {
|
|
|
|
// type: <EFFECT_TYPES>,
|
|
|
|
// name: effect filename, if any
|
|
|
|
// }
|
2024-07-19 04:24:10 +08:00
|
|
|
const setSessionVirtualBackgroundInfo = (deviceId, type, name, uniqueId = null) => {
|
2024-07-26 02:05:13 +08:00
|
|
|
getStorageSingletonInstance().setItem(`VirtualBackgroundInfo_${deviceId}`, { type, name, uniqueId });
|
2024-07-19 04:24:10 +08:00
|
|
|
};
|
2021-07-20 04:19:06 +08:00
|
|
|
|
2024-07-26 02:05:13 +08:00
|
|
|
const getSessionVirtualBackgroundInfo = (deviceId) => getStorageSingletonInstance()
|
2024-07-19 04:24:10 +08:00
|
|
|
.getItem(`VirtualBackgroundInfo_${deviceId}`) || {
|
|
|
|
type: EFFECT_TYPES.NONE_TYPE,
|
|
|
|
};
|
2021-07-20 04:19:06 +08:00
|
|
|
|
2024-07-26 02:05:13 +08:00
|
|
|
const getSessionVirtualBackgroundInfoWithDefault = (deviceId) => getStorageSingletonInstance()
|
2024-07-19 04:24:10 +08:00
|
|
|
.getItem(`VirtualBackgroundInfo_${deviceId}`) || {
|
|
|
|
type: EFFECT_TYPES.BLUR_TYPE,
|
|
|
|
name: BLUR_FILENAME,
|
|
|
|
};
|
2021-07-20 04:19:06 +08:00
|
|
|
|
2024-07-26 02:05:13 +08:00
|
|
|
const removeSessionVirtualBackgroundInfo = (deviceId) => getStorageSingletonInstance()
|
2024-07-19 04:24:10 +08:00
|
|
|
.removeItem(`VirtualBackgroundInfo_${deviceId}`);
|
|
|
|
|
|
|
|
const isVirtualBackgroundSupported = () => !(deviceInfo.isIos || browserInfo.isSafari);
|
2021-07-20 04:19:06 +08:00
|
|
|
|
|
|
|
const getVirtualBgImagePath = () => {
|
2024-05-29 21:26:11 +08:00
|
|
|
const {
|
|
|
|
imagesPath: IMAGES_PATH = '/resources/images/virtual-backgrounds/',
|
|
|
|
} = window.meetingClientSettings.public.virtualBackgrounds;
|
|
|
|
|
|
|
|
return (getIsStoredOnBBB() ? getBasePath() : '') + IMAGES_PATH;
|
2024-07-19 04:24:10 +08:00
|
|
|
};
|
2021-07-20 04:19:06 +08:00
|
|
|
|
|
|
|
export {
|
2024-05-29 21:26:11 +08:00
|
|
|
getBasePath,
|
|
|
|
getImageNames,
|
2021-07-20 04:19:06 +08:00
|
|
|
MODELS,
|
|
|
|
BLUR_FILENAME,
|
|
|
|
EFFECT_TYPES,
|
|
|
|
setSessionVirtualBackgroundInfo,
|
|
|
|
getSessionVirtualBackgroundInfo,
|
|
|
|
getSessionVirtualBackgroundInfoWithDefault,
|
2024-07-19 04:24:10 +08:00
|
|
|
removeSessionVirtualBackgroundInfo,
|
2021-08-04 03:24:08 +08:00
|
|
|
isVirtualBackgroundSupported,
|
2021-07-20 04:19:06 +08:00
|
|
|
createVirtualBackgroundStream,
|
|
|
|
getVirtualBackgroundThumbnail,
|
|
|
|
getVirtualBgImagePath,
|
2024-05-29 21:26:11 +08:00
|
|
|
};
|