UNPKG

fcr-core

Version:

Core APIs for building online scenes

105 lines 3.63 kB
import { FcrErrorCode, FcrErrorModuleCode, generateFcrCoreClientError, handleRequestError } from '../../../utilities/error'; import { createLogger } from '../../../utilities/logger'; import { FcrBaseWhiteboardControlImpl } from '../base'; import { ANNOTATION_APP_ID } from '../constant'; import { FcrBoardPropertiesState } from '../../whiteboard-control/type'; import { ErrorModuleCode } from 'agora-rte-sdk/lib/imports'; import { AgoraRteConnectionState } from 'agora-rte-sdk/lib/type'; const addBoardConnectingObserver = (board, sceneConfig) => { board.addObserver({ onConnectionStateUpdated: state => { if (state === AgoraRteConnectionState.CONNECTED) { if (sceneConfig.isAndroidByOwner()) { board.getMainWindow()?.setAutoCancelDraw(true); } else { board.getMainWindow()?.setAutoCancelDraw(false); } } } }); }; export class FcrAnnotationControlImpl extends FcrBaseWhiteboardControlImpl { logger = createLogger({ prefix: 'FcrAnnotationControlImpl' }); constructor(rtmClient, config, forgeInitConfigFetcher, _sceneConfig, _api) { super(rtmClient, config, forgeInitConfigFetcher, _api); this.rtmClient = rtmClient; this.config = config; this._sceneConfig = _sceneConfig; this._api = _api; addBoardConnectingObserver(this, this._sceneConfig); } async syncScreenShareOwnerAnnotationOpenDone() { try { await this._api.syncScreenShareOwnerAnnotationOpenDone(this._sceneConfig.sceneId); return 0; } catch (e) { const error = e; const errorMessage = error.message; throw generateFcrCoreClientError(FcrErrorModuleCode.FCR_ROOM_WHITEBOARD, FcrErrorCode.LOCAL_HTTP_REQUEST_FAILED, `sync screen share owner annotation open done failed: ${errorMessage}`, errorMessage); } } async syncWhiteboardWriteCount(isWritable) { await handleRequestError(() => this._api.setWhiteboardWriteCount({ roomId: this.config.roomId, userId: this.config.userId, state: isWritable ? 1 : 0 }), ErrorModuleCode.FCR_ROOM_WHITEBOARD, `set whiteboard write permission to ${isWritable} failed`); return 0; } async open() { const state = this._sceneConfig.getAnnotationState(); if (state === FcrBoardPropertiesState.INACTIVE) { return await super.internalOpen(true); } else { return await super.internalOpen(false); } } getApplicationId() { return ANNOTATION_APP_ID; } getWhiteboardOption() { return { width: this.config.size.width, height: this.config.size.height, defaultToolbarStyle: { tool: 'laser' }, maxScaleRatio: 1 }; } } export class FcrStandaloneAnnotationControlImpl extends FcrBaseWhiteboardControlImpl { logger = createLogger({ prefix: 'FcrStandaloneAnnotationControlImpl' }); constructor(rtmClient, config, forgeInitConfigFetcher, _sceneConfig) { super(rtmClient, config, forgeInitConfigFetcher); this.rtmClient = rtmClient; this.config = config; this._sceneConfig = _sceneConfig; addBoardConnectingObserver(this, this._sceneConfig); } async open() { const state = this._sceneConfig.getAnnotationState(); if (state === FcrBoardPropertiesState.INACTIVE) { return await super.internalOpen(true); } else { return await super.internalOpen(false); } } getApplicationId() { return ANNOTATION_APP_ID; } getWhiteboardOption() { return { width: this.config.size.width, height: this.config.size.height, defaultToolbarStyle: { tool: 'laser' }, maxScaleRatio: 1 }; } }