WhiteBoardApe.js 2.3 KB
// //////////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2016-present  All Rights Reserved.
//  Licensed under the Apache License, Version 2.0 (the "License");
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Github Home: https://github.com/AlexWang1987
//  Author: AlexWang
//  Date: 2016-08-26 17:36:20
//  QQ Email: 1669499355@qq.com
//  Last Modified time: 2016-09-21 14:06:12
//  Description: LiveClass-WhiteBoardApe
//
// //////////////////////////////////////////////////////////////////////////////

import Ape from './Ape';
import ApeConsts from './ApeConsts';
import pdu from 'pdu';
import Loger from 'Loger';
import MessageTypes from 'MessageTypes';
import { Zlib } from 'zlibjs/bin/zlib.min';
import UTF8 from 'utf-8';

let loger = Loger.getLoger('WhiteBoardApe');

class WhiteBoardApe extends Ape {
  constructor() {
    super(
      ApeConsts.WHITEBOARD_SESSION_ID,
      ApeConsts.WHITEBOARD_SESSION_NAME,
      ApeConsts.WHITEBOARD_SESSION_TAG
    );
    // properties
    this.annoInfos = {};

    //Ape Models
    this.registerKey(this._session_id, this._session_name, this._session_tag, new ArrayBuffer);
    this.registerObj(pdu.RCPDU_REG_REGISTER_TABLE, ApeConsts.WHITEBOARD_OBJ_TABLE_ID,
      ApeConsts.WHITEBOARD_OBJ_TABLE_NAME, ApeConsts.WHITEBOARD_OBJ_TABLE_TAG, 0, new ArrayBuffer);

    // ape listeners
    this.on(pdu.RCPDU_CONFERENCE_SEND_DATA_REQUEST, this.whiteboardMsgComingHandler.bind(this));

    // 白板延迟
     this._apeDelayed = true;
  }

  whiteboardMsgComingHandler(pdu) {
      loger.warn('whiteboardMsgComingHandler needs to be handled.');
  }

  tableInsertHandler(tableId, record) {
      this.emitDocChange(ApeConsts.DOCUMENT_DEL);
  }

  tableUpdateHandler(owner, recordId, recordData) {
    const recordInfo = pdu['RCWhiteboardDataRequestPdu'].decode(recordData);
    // 目前只处理 文档标注
    if (recordInfo.type == ApeConsts.WBA_DOC_ANNOTATION) {
      const uncompressedBytes = new Zlib.Inflate(recordInfo.action.compact().view).decompress();
      const annoInfo = {
        id: recordId,
        svg: UTF8.getStringFromBytes(uncompressedBytes)
      };
      this.annoInfos[recordId] = annoInfo;
      this._emit(MessageTypes.ANNO_UPDATE, annoInfo);
    } else {
      loger.log('白板动作忽略,类型:', ApeConsts(recordInfo.type));
    }
  }
}

export default WhiteBoardApe;