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',
|
|
|
|
}
|
2024-07-13 04:06:49 +08:00
|
|
|
const FALLBACK_IMAGE = 'green_screen.jpg';
|
2021-07-20 04:19:06 +08:00
|
|
|
|
|
|
|
// TODO I'm sure this is centralized somewhere; fetch it from "there" if possible
|
|
|
|
const BASE_PATH = Meteor.settings.public.app.cdn
|
|
|
|
+ Meteor.settings.public.app.basename
|
|
|
|
+ Meteor.settings.public.app.instanceId;
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const {
|
|
|
|
thumbnailsPath: THUMBNAILS_PATH = '/resources/images/virtual-backgrounds/thumbnails/',
|
2024-07-13 04:06:49 +08:00
|
|
|
fileNames: IMAGE_NAMES = ['home.jpg', 'coffeeshop.jpg', 'board.jpg', 'green_screen.jpg'],
|
2021-07-20 04:19:06 +08:00
|
|
|
storedOnBBB: IS_STORED_ON_BBB = true,
|
|
|
|
imagesPath: IMAGES_PATH = '/resources/images/virtual-backgrounds/',
|
|
|
|
showThumbnails: SHOW_THUMBNAILS = true,
|
|
|
|
} = Meteor.settings.public.virtualBackgrounds;
|
|
|
|
|
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) {
|
|
|
|
return BASE_PATH + '/resources/images/virtual-backgrounds/thumbnails/' + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (IS_STORED_ON_BBB ? BASE_PATH : '') + THUMBNAILS_PATH + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 = () => {
|
|
|
|
return (IS_STORED_ON_BBB ? BASE_PATH : '') + IMAGES_PATH;
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
BASE_PATH,
|
|
|
|
MODELS,
|
|
|
|
THUMBNAILS_PATH,
|
|
|
|
SHOW_THUMBNAILS,
|
|
|
|
IMAGE_NAMES,
|
|
|
|
IS_STORED_ON_BBB,
|
|
|
|
IMAGES_PATH,
|
|
|
|
BLUR_FILENAME,
|
|
|
|
EFFECT_TYPES,
|
2024-07-13 04:06:49 +08:00
|
|
|
FALLBACK_IMAGE,
|
2021-07-20 04:19:06 +08:00
|
|
|
setSessionVirtualBackgroundInfo,
|
|
|
|
getSessionVirtualBackgroundInfo,
|
|
|
|
getSessionVirtualBackgroundInfoWithDefault,
|
2021-08-04 03:24:08 +08:00
|
|
|
isVirtualBackgroundSupported,
|
2021-07-20 04:19:06 +08:00
|
|
|
createVirtualBackgroundStream,
|
|
|
|
getVirtualBackgroundThumbnail,
|
|
|
|
getVirtualBgImagePath,
|
|
|
|
}
|