UNPKG

fcr-core

Version:

Core APIs for building online scenes

103 lines (102 loc) 3.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WHITEBOARD_WIDTH = exports.WHITEBOARD_HEIGHT = void 0; exports.convertToForgeBoardTool = convertToForgeBoardTool; exports.resizeToMax = exports.getAnnotationConfigFromRoomProperties = void 0; var _enum = require("./enum"); var _imports = require("../../imports"); function convertToForgeBoardTool(type) { switch (type) { case _enum.FcrBoardToolType.ARROW: return 'arrow'; case _enum.FcrBoardToolType.CURVE: return 'curve'; case _enum.FcrBoardToolType.ELLIPSE: return 'ellipse'; case _enum.FcrBoardToolType.ERASER: return 'eraser'; case _enum.FcrBoardToolType.LASER_POINTER: return 'laser'; case _enum.FcrBoardToolType.TEXT: return 'text'; case _enum.FcrBoardToolType.RECTANGLE: return 'rectangle'; case _enum.FcrBoardToolType.TRIANGLE: return 'triangle'; case _enum.FcrBoardToolType.SELECTOR: return 'selector'; case _enum.FcrBoardToolType.STRAIGHT: return 'line'; // case FcrBoardToolType.PENTAGRAM: // return 'pentagram'; // case FcrBoardToolType.RHOMBUS: // return 'rhombus'; case _enum.FcrBoardToolType.HAND: return 'grab'; default: return 'curve'; } } const getAnnotationConfigFromRoomProperties = (properties, logger) => { const boardAppId = (0, _imports.get)(properties, 'widgets.annotation.extra.boardAppId'); const boardId = (0, _imports.get)(properties, 'widgets.annotation.extra.boardId'); const boardToken = (0, _imports.get)(properties, 'widgets.annotation.extra.boardToken'); const boardRegion = (0, _imports.get)(properties, 'widgets.annotation.extra.boardRegion'); let width = (0, _imports.get)(properties, 'widgets.annotation.size.width'); let height = (0, _imports.get)(properties, 'widgets.annotation.size.height'); if (typeof width !== 'number') { logger.warn("got invalid width for annotation board, width: ".concat(width)); width = 0; } if (typeof height !== 'number') { logger.warn("got invalid height for annotation board, height: ".concat(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: ".concat(boardWidthVal, ", height: ").concat(boardHeightVal)); } logger.info("got board config info, ".concat((0, _imports.jsonstring)({ boardAppId, boardId, boardToken, boardRegion, boardWidth, boardHeight }))); return { size: { width: boardWidth, height: boardHeight }, extra: { boardAppId, boardId, boardToken, region: boardRegion } }; }; exports.getAnnotationConfigFromRoomProperties = getAnnotationConfigFromRoomProperties; const resizeToMax = function (w, h) { let scaleBase = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : FCR_ANNOTATION_SCALE_BASE; const scale = scaleBase / Math.max(w, h); return { width: Math.round(w * scale), height: Math.round(h * scale) }; }; exports.resizeToMax = resizeToMax; const FCR_ANNOTATION_SCALE_BASE = 1920; const WHITEBOARD_WIDTH = exports.WHITEBOARD_WIDTH = 1920; const WHITEBOARD_HEIGHT = exports.WHITEBOARD_HEIGHT = 1080;