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';
|
|
|
|
|
|
|
|
const BLUR_FILENAME = 'blur.jpg';
|
|
|
|
const EFFECT_TYPES = {
|
|
|
|
BLUR_TYPE: 'blur',
|
|
|
|
IMAGE_TYPE: 'image',
|
|
|
|
NONE_TYPE: 'none',
|
|
|
|
}
|
|
|
|
|
|
|
|
const MODELS = {
|
|
|
|
model96: {
|
|
|
|
path: '/resources/tfmodels/segm_lite_v681.tflite',
|
|
|
|
segmentationDimensions: {
|
|
|
|
height: 96,
|
|
|
|
width: 160
|
|
|
|
}
|
|
|
|
},
|
|
|
|
model144: {
|
|
|
|
path: '/resources/tfmodels/segm_full_v679.tflite',
|
|
|
|
segmentationDimensions: {
|
|
|
|
height: 144,
|
|
|
|
width: 256
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-05-29 21:26:11 +08:00
|
|
|
const getBasePath = () => {
|
|
|
|
const BASE_PATH = window.meetingClientSettings.public.app.cdn
|
|
|
|
+ window.meetingClientSettings.public.app.basename
|
|
|
|
+ window.meetingClientSettings.public.app.instanceId;
|
|
|
|
|
|
|
|
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,
|
2021-07-20 04:19:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return createVirtualBackgroundService(buildParams).then((service) => {
|
|
|
|
const effect = service.startEffect(stream)
|
|
|
|
return { service, effect };
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const getVirtualBackgroundThumbnail = (name) => {
|
|
|
|
if (name === BLUR_FILENAME) {
|
2024-05-29 21:26:11 +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;
|
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
|
|
|
|
// }
|
2021-11-19 19:10:24 +08:00
|
|
|
const setSessionVirtualBackgroundInfo = (type, name, deviceId) => {
|
|
|
|
return Session.set(`VirtualBackgroundInfo_${deviceId}`, { type, name });
|
2021-07-20 04:19:06 +08:00
|
|
|
}
|
|
|
|
|
2021-11-19 19:10:24 +08:00
|
|
|
const getSessionVirtualBackgroundInfo = (deviceId) => {
|
|
|
|
return Session.get(`VirtualBackgroundInfo_${deviceId}`) || {
|
2021-07-20 04:19:06 +08:00
|
|
|
type: EFFECT_TYPES.NONE_TYPE,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-19 19:10:24 +08:00
|
|
|
const getSessionVirtualBackgroundInfoWithDefault = (deviceId) => {
|
|
|
|
return Session.get(`VirtualBackgroundInfo_${deviceId}`) || {
|
2021-07-20 04:19:06 +08:00
|
|
|
type: EFFECT_TYPES.BLUR_TYPE,
|
|
|
|
name: BLUR_FILENAME,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-04 03:24:08 +08:00
|
|
|
const isVirtualBackgroundSupported = () => {
|
2021-10-27 22:28:52 +08:00
|
|
|
return !(deviceInfo.isIos || browserInfo.isSafari);
|
2021-08-04 03:24:08 +08:00
|
|
|
}
|
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;
|
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,
|
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
|
|
|
};
|