UNPKG

fcr-core

Version:

Core APIs for building online scenes

92 lines 2.87 kB
import { FcrBoardToolType } from './enum'; import { jsonstring, get } from '../../imports'; export function convertToForgeBoardTool(type) { switch (type) { case FcrBoardToolType.ARROW: return 'arrow'; case FcrBoardToolType.CURVE: return 'curve'; case FcrBoardToolType.ELLIPSE: return 'ellipse'; case FcrBoardToolType.ERASER: return 'eraser'; case FcrBoardToolType.LASER_POINTER: return 'laser'; case FcrBoardToolType.TEXT: return 'text'; case FcrBoardToolType.RECTANGLE: return 'rectangle'; case FcrBoardToolType.TRIANGLE: return 'triangle'; case FcrBoardToolType.SELECTOR: return 'selector'; case FcrBoardToolType.STRAIGHT: return 'line'; // case FcrBoardToolType.PENTAGRAM: // return 'pentagram'; // case FcrBoardToolType.RHOMBUS: // return 'rhombus'; case FcrBoardToolType.HAND: return 'grab'; default: return 'curve'; } } export const getAnnotationConfigFromRoomProperties = (properties, logger) => { const boardAppId = get(properties, 'widgets.annotation.extra.boardAppId'); const boardId = get(properties, 'widgets.annotation.extra.boardId'); const boardToken = get(properties, 'widgets.annotation.extra.boardToken'); const boardRegion = get(properties, 'widgets.annotation.extra.boardRegion'); let width = get(properties, 'widgets.annotation.size.width'); let height = get(properties, 'widgets.annotation.size.height'); if (typeof width !== 'number') { logger.warn(`got invalid width for annotation board, width: ${width}`); width = 0; } if (typeof height !== 'number') { logger.warn(`got invalid height for annotation board, height: ${height}`); height = 0; } const boardWidthVal = width; const boardHeightVal = height; let boardWidth = 0; let boardHeight = 0; if (boardWidthVal !== 0 && boardHeightVal !== 0) { ({ width: boardWidth, height: boardHeight } = resizeToMax(boardWidthVal, boardHeightVal, FCR_ANNOTATION_SCALE_BASE)); } else { logger.warn(`got invalid width or height for annotation board, skip resizing, width: ${boardWidthVal}, height: ${boardHeightVal}`); } logger.info(`got board config info, ${jsonstring({ boardAppId, boardId, boardToken, boardRegion, boardWidth, boardHeight })}`); return { size: { width: boardWidth, height: boardHeight }, extra: { boardAppId, boardId, boardToken, region: boardRegion } }; }; export const resizeToMax = (w, h, scaleBase = FCR_ANNOTATION_SCALE_BASE) => { const scale = scaleBase / Math.max(w, h); return { width: Math.round(w * scale), height: Math.round(h * scale) }; }; const FCR_ANNOTATION_SCALE_BASE = 1920; export const WHITEBOARD_WIDTH = 1920; export const WHITEBOARD_HEIGHT = 1080;