fcr-core
Version:
Core APIs for building online scenes
571 lines (565 loc) • 30.2 kB
JavaScript
"use strict";
require("core-js/modules/es.symbol.description.js");
require("core-js/modules/es.error.cause.js");
require("core-js/modules/es.array.push.js");
require("core-js/modules/esnext.function.metadata.js");
require("core-js/modules/esnext.iterator.filter.js");
require("core-js/modules/esnext.iterator.for-each.js");
require("core-js/modules/esnext.map.delete-all.js");
require("core-js/modules/esnext.map.emplace.js");
require("core-js/modules/esnext.map.every.js");
require("core-js/modules/esnext.map.filter.js");
require("core-js/modules/esnext.map.find.js");
require("core-js/modules/esnext.map.find-key.js");
require("core-js/modules/esnext.map.includes.js");
require("core-js/modules/esnext.map.key-of.js");
require("core-js/modules/esnext.map.map-keys.js");
require("core-js/modules/esnext.map.map-values.js");
require("core-js/modules/esnext.map.merge.js");
require("core-js/modules/esnext.map.reduce.js");
require("core-js/modules/esnext.map.some.js");
require("core-js/modules/esnext.map.update.js");
require("core-js/modules/esnext.symbol.metadata.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.FcrBoardMainWindowImpl = void 0;
require("core-js/modules/es.promise.finally.js");
require("core-js/modules/esnext.iterator.constructor.js");
require("core-js/modules/esnext.iterator.map.js");
require("core-js/modules/web.dom-collections.iterator.js");
require("core-js/modules/web.url.js");
require("core-js/modules/web.url.to-json.js");
require("core-js/modules/web.url-search-params.js");
require("core-js/modules/web.url-search-params.delete.js");
require("core-js/modules/web.url-search-params.has.js");
require("core-js/modules/web.url-search-params.size.js");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _whiteSnapshot = require("@netless/white-snapshot");
var _windowManager = require("@netless/window-manager");
var _appliancePlugin = require("@netless/appliance-plugin");
require("@netless/appliance-plugin/dist/style.css");
require("@netless/window-manager/dist/style.css");
var _utils = require("./utils");
var _mountManager = require("./mount-manager");
var _jsMd = require("js-md5");
var _logger = require("../../utilities/logger");
var _imports = require("../../imports");
var _boardSubwindow = require("./board-subwindow");
var _fullWorker = _interopRequireDefault(require("@netless/appliance-plugin/dist/fullWorker.js?raw"));
var _subWorker = _interopRequireDefault(require("@netless/appliance-plugin/dist/subWorker.js?raw"));
var _lodash = require("lodash");
var _imports2 = require("agora-rte-sdk/lib/imports");
var _FcrBoardMainWindowImpl;
let _initProto; //@ts-ignore
//@ts-ignore
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _applyDecs(e, t, r, n, o, a) { function i(e, t, r) { return function (n, o) { return r && r(n), e[t].call(n, o); }; } function c(e, t) { for (var r = 0; r < e.length; r++) e[r].call(t); return t; } function s(e, t, r, n) { if ("function" != typeof e && (n || void 0 !== e)) throw new TypeError(t + " must " + (r || "be") + " a function" + (n ? "" : " or undefined")); return e; } function applyDec(e, t, r, n, o, a, c, u, l, f, p, d, h) { function m(e) { if (!h(e)) throw new TypeError("Attempted to access private element on non-instance"); } var y, v = t[0], g = t[3], b = !u; if (!b) { r || Array.isArray(v) || (v = [v]); var w = {}, S = [], A = 3 === o ? "get" : 4 === o || d ? "set" : "value"; f ? (p || d ? w = { get: _setFunctionName(function () { return g(this); }, n, "get"), set: function (e) { t[4](this, e); } } : w[A] = g, p || _setFunctionName(w[A], n, 2 === o ? "" : A)) : p || (w = Object.getOwnPropertyDescriptor(e, n)); } for (var P = e, j = v.length - 1; j >= 0; j -= r ? 2 : 1) { var D = v[j], E = r ? v[j - 1] : void 0, I = {}, O = { kind: ["field", "accessor", "method", "getter", "setter", "class"][o], name: n, metadata: a, addInitializer: function (e, t) { if (e.v) throw Error("attempted to call addInitializer after decoration was finished"); s(t, "An initializer", "be", !0), c.push(t); }.bind(null, I) }; try { if (b) (y = s(D.call(E, P, O), "class decorators", "return")) && (P = y);else { var k, F; O.static = l, O.private = f, f ? 2 === o ? k = function (e) { return m(e), w.value; } : (o < 4 && (k = i(w, "get", m)), 3 !== o && (F = i(w, "set", m))) : (k = function (e) { return e[n]; }, (o < 2 || 4 === o) && (F = function (e, t) { e[n] = t; })); var N = O.access = { has: f ? h.bind() : function (e) { return n in e; } }; if (k && (N.get = k), F && (N.set = F), P = D.call(E, d ? { get: w.get, set: w.set } : w[A], O), d) { if ("object" == typeof P && P) (y = s(P.get, "accessor.get")) && (w.get = y), (y = s(P.set, "accessor.set")) && (w.set = y), (y = s(P.init, "accessor.init")) && S.push(y);else if (void 0 !== P) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0"); } else s(P, (p ? "field" : "method") + " decorators", "return") && (p ? S.push(P) : w[A] = P); } } finally { I.v = !0; } } return (p || d) && u.push(function (e, t) { for (var r = S.length - 1; r >= 0; r--) t = S[r].call(e, t); return t; }), p || b || (f ? d ? u.push(i(w, "get"), i(w, "set")) : u.push(2 === o ? w[A] : i.call.bind(w[A])) : Object.defineProperty(e, n, w)), P; } function u(e, t) { return Object.defineProperty(e, Symbol.metadata || Symbol.for("Symbol.metadata"), { configurable: !0, enumerable: !0, value: t }); } if (arguments.length >= 6) var l = a[Symbol.metadata || Symbol.for("Symbol.metadata")]; var f = Object.create(null == l ? null : l), p = function (e, t, r, n) { var o, a, i = [], s = function (t) { return _checkInRHS(t) === e; }, u = new Map(); function l(e) { e && i.push(c.bind(null, e)); } for (var f = 0; f < t.length; f++) { var p = t[f]; if (Array.isArray(p)) { var d = p[1], h = p[2], m = p.length > 3, y = 16 & d, v = !!(8 & d), g = 0 == (d &= 7), b = h + "/" + v; if (!g && !m) { var w = u.get(b); if (!0 === w || 3 === w && 4 !== d || 4 === w && 3 !== d) throw Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + h); u.set(b, !(d > 2) || d); } applyDec(v ? e : e.prototype, p, y, m ? "#" + h : _toPropertyKey(h), d, n, v ? a = a || [] : o = o || [], i, v, m, g, 1 === d, v && m ? s : r); } } return l(o), l(a), i; }(e, t, o, f); return r.length || u(e, f), { e: p, get c() { var t = []; return r.length && [u(applyDec(e, [r], n, e.name, 5, f, t), f), c.bind(null, t, e)]; } }; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _setFunctionName(e, t, n) { "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : ""); try { Object.defineProperty(e, "name", { configurable: !0, value: n ? n + " " + t : t }); } catch (e) {} return e; }
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); return e; }
class FcrBoardMainWindowImpl {
constructor(room) {
(0, _defineProperty2.default)(this, "logger", (_initProto(this), (0, _logger.createLogger)({
prefix: 'FcrBoardMainWindowImpl'
})));
(0, _defineProperty2.default)(this, "_memberState", {});
(0, _defineProperty2.default)(this, "_observable", new _imports.AgoraObservable());
(0, _defineProperty2.default)(this, "_destroyed", false);
this._whiteBoardroom = room;
this._whiteView = document.createElement('div');
this._initView();
this._addLogObserver();
}
async getSnapshotImage() {
this._preCheck({
wm: false
});
const whiteRoom = this._whiteBoardroom;
let result = new ImageData(1, 1);
if (whiteRoom) {
const sceneMap = whiteRoom.entireScenes();
const scenes = Object.keys(sceneMap);
if (scenes.length) {
const _room = Object.create(whiteRoom);
_room.state.cameraState = {
width: 2038,
height: 940
}; // 创建一个宽高
const cps = sceneMap['/'].map(scene => {
return () => (0, _whiteSnapshot.snapshot)(_room, {
scenePath: '/' + scene.name,
crossorigin: true,
background: '#fff',
src2dataurl: _utils.src2DataURL
});
});
try {
const merged = await (0, _utils.mergeCanvasImage)(cps);
const ctx = merged.getContext('2d');
if (ctx) {
result = ctx.getImageData(0, 0, merged.width, merged.height);
return result;
}
} catch (e) {
this.logger.error('[FcrBoardMainWindow] failed to take snapshot', e);
}
}
}
return result;
}
addObserver(observer) {
this._observable.addObserver(observer);
}
removeObserver(observer) {
this._observable.removeObserver(observer);
}
getContentView() {
return this._whiteView;
}
setScale(value) {
var _this$_windowManager;
const scale = Math.max(Math.min(value, 3), -3);
(_this$_windowManager = this._windowManager) === null || _this$_windowManager === void 0 || _this$_windowManager.moveCamera({
scale
});
}
async openSubWindowWithTaskId(title, taskId, urlPrefix) {
var _this$_windowManager2;
const appId = await ((_this$_windowManager2 = this._windowManager) === null || _this$_windowManager2 === void 0 ? void 0 : _this$_windowManager2.addApp({
kind: 'Slide',
options: {
scenePath: "/ppt".concat(taskId),
title
},
attributes: {
taskId,
url: urlPrefix
}
}));
if (appId) {
var _this$_windowManager3;
const app = (_this$_windowManager3 = this._windowManager) === null || _this$_windowManager3 === void 0 || (_this$_windowManager3 = _this$_windowManager3.apps) === null || _this$_windowManager3 === void 0 ? void 0 : _this$_windowManager3[appId];
return app ? new _boardSubwindow.FcrBoardSubWindowImpl(appId) : undefined;
}
}
async openSubWindowWithPageList(title, pageList) {
var _this$_windowManager4;
const scenePath = "/".concat(Date.now());
const appId = await ((_this$_windowManager4 = this._windowManager) === null || _this$_windowManager4 === void 0 ? void 0 : _this$_windowManager4.addApp({
kind: _windowManager.BuiltinApps.DocsViewer,
options: {
scenePath,
title,
scenes: this._convertToScenes(pageList)
}
}));
if (appId) {
var _this$_windowManager5;
const app = (_this$_windowManager5 = this._windowManager) === null || _this$_windowManager5 === void 0 || (_this$_windowManager5 = _this$_windowManager5.apps) === null || _this$_windowManager5 === void 0 ? void 0 : _this$_windowManager5[appId];
return app ? new _boardSubwindow.FcrBoardSubWindowImpl(appId) : undefined;
}
}
async setContainerSizeRatio(ratio) {
var _this$_windowManager6;
this._preCheck();
(_this$_windowManager6 = this._windowManager) === null || _this$_windowManager6 === void 0 || _this$_windowManager6.setContainerSizeRatio(ratio);
}
getPageInfo() {
this._preCheck();
const windowManager = this._windowManager;
return {
showIndex: (windowManager === null || windowManager === void 0 ? void 0 : windowManager.mainViewSceneIndex) || 0,
count: (windowManager === null || windowManager === void 0 ? void 0 : windowManager.mainViewScenesLength) || 0
};
}
async addPage() {
var _this$_windowManager7;
this._preCheck();
if ((_this$_windowManager7 = this._windowManager) !== null && _this$_windowManager7 !== void 0 && _this$_windowManager7.addPage) {
await this._windowManager.addPage();
await this._windowManager.nextPage();
}
}
async removePage() {
var _this$_windowManager8;
this._preCheck();
if ((_this$_windowManager8 = this._windowManager) !== null && _this$_windowManager8 !== void 0 && _this$_windowManager8.removePage) {
await this._windowManager.removePage();
}
}
async prevPage() {
var _this$_windowManager9;
this._preCheck();
if ((_this$_windowManager9 = this._windowManager) !== null && _this$_windowManager9 !== void 0 && _this$_windowManager9.prevPage) {
await this._windowManager.prevPage();
}
}
async nextPage() {
var _this$_windowManager0;
this._preCheck();
if ((_this$_windowManager0 = this._windowManager) !== null && _this$_windowManager0 !== void 0 && _this$_windowManager0.nextPage) {
await this._windowManager.nextPage();
}
}
async undo() {
this._preCheck({
wm: false
});
this._whiteBoardroom.undo();
}
async redo() {
this._preCheck({
wm: false
});
this._whiteBoardroom.redo();
}
async clean(retainPpt) {
this._preCheck({
wm: false
});
// this._whiteBoardroom?.cleanScene?.(true); // new version methods
this._whiteBoardroom.cleanCurrentScene(retainPpt);
}
async setToolType(type) {
this._preCheck({
wm: false
});
const [tool, shape] = (0, _utils.convertToNetlessBoardTool)(type);
const strokeType = (0, _utils.convertToNetlessStorkeType)(type);
const change = {
currentApplianceName: tool,
shapeType: shape,
strokeType
};
this._memberState = _objectSpread(_objectSpread({}, this._memberState), change);
if (this._windowManager) {
var _this$_appliancePlugi;
(_this$_appliancePlugi = this._appliancePluginInstance) === null || _this$_appliancePlugi === void 0 || _this$_appliancePlugi.setMemberState(change);
}
}
async setStrokeWidth(strokeWidth) {
this._preCheck();
const change = {
strokeWidth
};
this._memberState = _objectSpread(_objectSpread({}, this._memberState), change);
if (this._windowManager) {
this._whiteBoardroom.setMemberState(change);
}
}
async setStrokeColor(color) {
var _color$a;
this._preCheck();
const change = {
strokeColor: [color.r, color.g, color.b],
strokeOpacity: (_color$a = color.a) !== null && _color$a !== void 0 ? _color$a : 1
};
this._memberState = _objectSpread(_objectSpread({}, this._memberState), change);
if (this._windowManager) {
this._whiteBoardroom.setMemberState(change);
}
}
async setTextColor(color) {
var _color$a2;
this._preCheck();
const change = {
textColor: [color.r, color.g, color.b],
textOpacity: (_color$a2 = color.a) !== null && _color$a2 !== void 0 ? _color$a2 : 1
};
this._memberState = _objectSpread(_objectSpread({}, this._memberState), change);
if (this._windowManager) {
this._whiteBoardroom.setMemberState(change);
}
}
async setTextSize(size) {
this._preCheck();
const change = {
textSize: size
};
this._memberState = _objectSpread(_objectSpread({}, this._memberState), change);
if (this._windowManager) {
this._whiteBoardroom.setMemberState(change);
}
}
async setFillColor(fillColor) {
var _fillColor$a;
this._preCheck();
const change = {
fillColor: [fillColor.r, fillColor.g, fillColor.b],
fillOpacity: (_fillColor$a = fillColor.a) !== null && _fillColor$a !== void 0 ? _fillColor$a : 1
};
this._memberState = _objectSpread(_objectSpread({}, this._memberState), change);
if (this._windowManager) {
this._whiteBoardroom.setMemberState(change);
}
}
async setEraserSize(size) {
this._preCheck();
const change = {
pencilEraserSize: size
};
this._memberState = _objectSpread(_objectSpread({}, this._memberState), change);
if (this._windowManager) {
this._whiteBoardroom.setMemberState(change);
}
}
async setBackgroundColor(color) {
var _this$_whiteView$quer;
this._preCheck();
this._backgroundColor = color;
(_this$_whiteView$quer = this._whiteView.querySelector('.netless-whiteboard')) === null || _this$_whiteView$quer === void 0 || _this$_whiteView$quer.style.setProperty('background-color', color);
}
async insertImage(resourceUrl, x, y, width, height) {
const room = this._whiteBoardroom;
const windowManager = this._windowManager;
const preX = x;
const preY = y;
const preWidth = width;
const preHeight = height;
if (windowManager) {
var _this$_whiteView$clie, _this$_whiteView, _this$_whiteView$clie2, _this$_whiteView2;
let originX = 0;
let originY = 0;
if (this._whiteView) {
originX = this._whiteView.clientWidth / 2;
originY = this._whiteView.clientHeight / 2;
}
const {
x,
y
} = windowManager.mainView.convertToPointInWorld({
x: preX !== null && preX !== void 0 ? preX : originX,
y: preY !== null && preY !== void 0 ? preY : originY
});
const containerSize = {
width: (_this$_whiteView$clie = (_this$_whiteView = this._whiteView) === null || _this$_whiteView === void 0 ? void 0 : _this$_whiteView.clientWidth) !== null && _this$_whiteView$clie !== void 0 ? _this$_whiteView$clie : window.innerWidth,
height: (_this$_whiteView$clie2 = (_this$_whiteView2 = this._whiteView) === null || _this$_whiteView2 === void 0 ? void 0 : _this$_whiteView2.clientHeight) !== null && _this$_whiteView$clie2 !== void 0 ? _this$_whiteView$clie2 : window.innerHeight
};
const uuid = (0, _jsMd.md5)(resourceUrl);
const {
width,
height
} = await (0, _utils.fetchImageInfoByUrl)(resourceUrl, containerSize);
const imageInfo = {
uuid: uuid,
centerX: x,
centerY: y,
width: preWidth !== null && preWidth !== void 0 ? preWidth : width,
height: preHeight !== null && preHeight !== void 0 ? preHeight : height,
locked: false
};
windowManager.switchMainViewToWriter();
room.insertImage(imageInfo);
room.completeImageUpload(uuid, resourceUrl);
}
}
async insertMedia(resourceUrl, title) {
const windowManager = this._windowManager;
const room = this._whiteBoardroom;
if (windowManager) {
windowManager.addApp({
kind: _windowManager.BuiltinApps.MediaPlayer,
src: resourceUrl,
options: {
title: title
},
attributes: {
url: resourceUrl
}
});
}
}
destroy() {
if (this._windowManager) {
this._windowManager.destroy();
this._windowManager = undefined;
}
this._destroyed = true;
}
getWritable() {
return this._whiteBoardroom.isWritable;
}
_convertToScenes(pageList) {
return pageList.map(page => ({
name: page.name,
ppt: {
src: page.contentUrl,
width: page.contentWidth,
height: page.contentHeight,
previewURL: page.previewUrl
}
}));
}
_preCheck() {
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const {
privilege = true,
wm = true
} = options;
if (privilege && !this._whiteBoardroom.isWritable) {
this.logger.warn('Try to operate on board window without operation privilege');
}
if (wm && !this._windowManager) {
this.logger.warn('Try to operate on board window when board window not mounted');
}
}
_addWindowManagerEventListeners() {
const windowManager = this._windowManager;
windowManager === null || windowManager === void 0 || windowManager.emitter.on('mainViewSceneIndexChange', showIndex => {
const state = {
showIndex: showIndex,
count: (windowManager === null || windowManager === void 0 ? void 0 : windowManager.mainViewScenesLength) || 0
};
this._observable.notifyObservers('onPageInfoUpdated', state);
});
windowManager === null || windowManager === void 0 || windowManager.emitter.on('mainViewScenesLengthChange', count => {
const state = {
showIndex: (windowManager === null || windowManager === void 0 ? void 0 : windowManager.mainViewSceneIndex) || 0,
count: count
};
this._observable.notifyObservers('onPageInfoUpdated', state);
});
windowManager === null || windowManager === void 0 || windowManager.emitter.on('canUndoStepsChange', steps => {
this._observable.notifyObservers('onUndoStateUpdated', steps > 0);
});
windowManager === null || windowManager === void 0 || windowManager.emitter.on('canRedoStepsChange', steps => {
this._observable.notifyObservers('onRedoStateUpdated', steps > 0);
});
}
// don't remove, used by FcrWhiteboardControl
async _mount() {
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
let params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this._whiteboardPrivateParameters = params;
if (this._whiteBoardroom) {
var _this$_whiteboardPriv, _this$_whiteboardPriv2, _this$_whiteboardPriv3, _this$_whiteboardPriv4, _this$_whiteboardPriv5, _this$_whiteboardPriv6, _this$_whiteboardPriv7, _this$_whiteboardPriv8;
this._destroyed = false;
if (_mountManager.BoardMountManager.isMounting) {
this.logger.info('[FcrBoardMainWindow] wait for previous board window mounted, white room id:', this._whiteBoardroom.uuid);
// await when(() => !BoardMountManager.isMounting);
this.logger.info('[FcrBoardMainWindow] previous board window mounted, start mount current board window, white room id:', this._whiteBoardroom.uuid);
}
if (this._destroyed) {
this.logger.info('[FcrBoardMainWindow] current board window has been destroyed, white room id:', this._whiteBoardroom.uuid);
return;
}
_mountManager.BoardMountManager.setIsMounting(true);
this.logger.info('start mount board window, white room id:', this._whiteBoardroom.uuid);
const extras = (_this$_whiteboardPriv = (_this$_whiteboardPriv2 = this._whiteboardPrivateParameters) === null || _this$_whiteboardPriv2 === void 0 ? void 0 : _this$_whiteboardPriv2.extras) !== null && _this$_whiteboardPriv !== void 0 ? _this$_whiteboardPriv : {};
const cursor = (_this$_whiteboardPriv3 = (_this$_whiteboardPriv4 = this._whiteboardPrivateParameters) === null || _this$_whiteboardPriv4 === void 0 ? void 0 : _this$_whiteboardPriv4.cursor) !== null && _this$_whiteboardPriv3 !== void 0 ? _this$_whiteboardPriv3 : true;
const extendClass = (_this$_whiteboardPriv5 = this._whiteboardPrivateParameters) === null || _this$_whiteboardPriv5 === void 0 ? void 0 : _this$_whiteboardPriv5.extendClass;
const containerElement = (_this$_whiteboardPriv6 = this._whiteboardPrivateParameters) === null || _this$_whiteboardPriv6 === void 0 ? void 0 : _this$_whiteboardPriv6.containerElement;
let windowManagerParams = (_this$_whiteboardPriv7 = (_this$_whiteboardPriv8 = this._whiteboardPrivateParameters) === null || _this$_whiteboardPriv8 === void 0 ? void 0 : _this$_whiteboardPriv8.windowManagerParams) !== null && _this$_whiteboardPriv7 !== void 0 ? _this$_whiteboardPriv7 : {};
this.logger.info("set whiteboard extendClass: ".concat(extendClass));
this.logger.info("set whiteboard cursor: ".concat(cursor));
this.logger.info("set whiteboard extras: ".concat((0, _imports2.jsonstring)(extras)));
this.logger.info("set whiteboard windowManagerParams: ".concat((0, _imports2.jsonstring)(windowManagerParams)));
if (!(0, _lodash.isPlainObject)(windowManagerParams)) {
this.logger.warn('windowManagerParams is not a plain object');
windowManagerParams = {};
}
// 提前将 view 挂载到 containerElement 上,避免白板初始化时无法获取到正确的宽高
if (containerElement) {
containerElement.appendChild(this._whiteView);
}
await _windowManager.WindowManager.mount(_objectSpread({
debug: true,
room: this._whiteBoardroom,
container: this._whiteView,
cursor: cursor,
chessboard: false,
collectorContainer: options.collectorContainer,
containerSizeRatio: options.containerSizeRatio,
supportAppliancePlugin: true
}, windowManagerParams), extendClass).then(async wm => {
if (this._destroyed) {
wm.destroy();
return;
}
//@ts-ignore
window._wm = wm;
this._windowManager = wm;
this._windowManager.mainView.disableCameraTransform = true;
this._addWindowManagerEventListeners();
if (this._backgroundColor) {
var _this$_whiteView$quer2;
(_this$_whiteView$quer2 = this._whiteView.querySelector('.netless-whiteboard')) === null || _this$_whiteView$quer2 === void 0 || _this$_whiteView$quer2.style.setProperty('background-color', this._backgroundColor);
}
const fullWorkerBlob = new Blob([_fullWorker.default], {
type: 'text/javascript'
});
const fullWorkerUrl = URL.createObjectURL(fullWorkerBlob);
const subWorkerBlob = new Blob([_subWorker.default], {
type: 'text/javascript'
});
const subWorkerUrl = URL.createObjectURL(subWorkerBlob);
await this._windowManager.switchMainViewToWriter();
const appliancePluginInstance = await _appliancePlugin.ApplianceMultiPlugin.getInstance(wm, {
options: {
cdn: {
fullWorkerUrl,
subWorkerUrl
},
extras
}
});
//@ts-ignore
window.appliancePluginInstance = appliancePluginInstance;
this._appliancePluginInstance = appliancePluginInstance;
if (appliancePluginInstance.injectMethodToObject) {
appliancePluginInstance.injectMethodToObject(window, 'requestIdleCallback');
appliancePluginInstance.injectMethodToObject(window, 'cancelIdleCallback');
}
appliancePluginInstance.addListener('forceStop', reason => {
if (reason == 'longPencil') {
window.postMessage({
type: 'white-board-error',
data: {
reason: 'longPencil'
}
}, '*');
}
});
const hasPermission = this._whiteBoardroom.isWritable;
this.logger.info("after mount, isWritable: ".concat(hasPermission));
if (hasPermission) {
this._whiteBoardroom.setMemberState(this._memberState);
appliancePluginInstance.setMemberState({
strokeType: _appliancePlugin.EStrokeType.Normal
});
}
}).catch(e => {
this.logger.error('[FcrBoardMainWindow] failed to mount', e);
}).finally(() => {
this.logger.info('[FcrBoardMainWindow] finish mount board window, white room id:', this._whiteBoardroom.uuid);
_mountManager.BoardMountManager.setIsMounting(false);
});
}
}
_initView() {
this._whiteView.style.width = '100%';
this._whiteView.style.height = '100%';
this._whiteView.classList.add('fcr-whiteboard-window-view');
}
// don't remove, used by FcrWhiteboardControl
async _setRoom(room, options, params) {
this._whiteBoardroom = room;
if (this._windowManager) {
this.logger.info('destroy previous window manager');
this._windowManager.destroy();
}
await this._mount(options, params);
this.logger.info('restore member state');
room.setMemberState(this._memberState);
}
_addLogObserver() {
this.addObserver((0, _logger.generateLogObserver)(this.logger, ['onWritable', 'onPageInfoUpdated', 'onUndoStateUpdated', 'onRedoStateUpdated']));
}
}
exports.FcrBoardMainWindowImpl = FcrBoardMainWindowImpl;
_FcrBoardMainWindowImpl = FcrBoardMainWindowImpl;
[_initProto] = _applyDecs(_FcrBoardMainWindowImpl, [[[_imports.bound, _imports.trace], 2, "getSnapshotImage"], [_imports.trace, 2, "addObserver"], [_imports.trace, 2, "removeObserver"], [_imports.trace, 2, "getContentView"], [_imports.bound, 2, "setScale"], [_imports.bound, 2, "openSubWindowWithTaskId"], [_imports.bound, 2, "openSubWindowWithPageList"], [_imports.trace, 2, "getPageInfo"], [[_imports.bound, _imports.trace], 2, "addPage"], [[_imports.bound, _imports.trace], 2, "removePage"], [_imports.trace, 2, "prevPage"], [_imports.trace, 2, "nextPage"], [[_imports.bound, _imports.trace], 2, "undo"], [[_imports.bound, _imports.trace], 2, "redo"], [[_imports.bound, _imports.trace], 2, "clean"], [[_imports.bound, _imports.trace], 2, "setToolType"], [[_imports.bound, _imports.trace], 2, "setStrokeWidth"], [[_imports.bound, _imports.trace], 2, "setStrokeColor"], [[_imports.bound, _imports.trace], 2, "setTextColor"], [[_imports.bound, _imports.trace], 2, "setTextSize"], [[_imports.bound, _imports.trace], 2, "setFillColor"], [[_imports.bound, _imports.trace], 2, "setEraserSize"], [[_imports.bound, _imports.trace], 2, "setBackgroundColor"], [[_imports.bound, _imports.trace], 2, "insertImage"], [[_imports.bound, _imports.trace], 2, "insertMedia"], [_imports.trace, 2, "destroy"], [_imports.trace, 2, "getWritable"], [_imports.trace, 2, "_mount"], [_imports.trace, 2, "_setRoom"]], []).e;