DocApe.js 2.6 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:30:43
//  QQ Email: 1669499355@qq.com
//  Last Modified time: 2016-09-21 14:12:25
//  Description: LiveClass-DocApe
//
// //////////////////////////////////////////////////////////////////////////////

import Ape from './Ape';
import ApeConsts from './ApeConsts';
import pdu from 'pdus';
import Loger from 'Loger';
import MessageTypes from 'MessageTypes';

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

class DocApe extends Ape {
  constructor() {
    super(
      ApeConsts.DOCSHARING_SESSION_ID,
      ApeConsts.DOCSHARING_SESSION_NAME,
      ApeConsts.DOCSHARING_SESSION_TAG
    );
    this.docList = {};


    // Ape Models
    this.registerKey(this._session_id, this._session_name, this._session_tag, new ArrayBuffer);
    this.registerObj(pdu.RCPDU_REG_REGISTER_TABLE, ApeConsts.DOCSHARING_OBJ_TABLE_ID_H5, ApeConsts.DOCSHARING_OBJ_TABLE_NAME_H5, ApeConsts.DOCSHARING_OBJ_TABLE_TAG_H5, 0, new ArrayBuffer);

    // 延迟
      this._apeDelayed = true;
  }

  tableInsertHandler(owner, tableId, recordData) {
    this.tableUpdateHandler(owner, tableId, recordData);
  }

  tableDeleteHandler(tableId, record){
      const re={};
      re.type=ApeConsts.DOCUMENT_DEL;
      this._emit(MessageTypes.DOC_DEL, re);
  }
  tableUpdateHandler(owner, recordId, recordData) {
    try {
      const recordInfo = pdu['RCDocSendDataRequestPdu'].decode(recordData);
      recordInfo.type = ApeConsts.DOCUMENT_LOAD;

      recordInfo.ext = recordInfo.name.substr(recordInfo.name.indexOf('.') + 1);
      recordInfo.wbid = (recordInfo.id << 10) + recordInfo.curPageNo;
      recordInfo.isPicture = ~['bmp', 'png', 'gif', 'jpg', 'jpeg'].indexOf(recordInfo.ext);

      if (recordInfo.isPicture) {
        recordInfo.namePath = recordInfo.uri.substring(0, recordInfo.uri.lastIndexOf('.'));
        recordInfo.loadURL = recordInfo.namePath + '.' + recordInfo.ext;
      } else {
        recordInfo.namePath = recordInfo.uri.substring(0, recordInfo.uri.lastIndexOf('/'));
        recordInfo.loadURL = `${recordInfo.namePath}/${recordInfo.curPageNo}.jpg`;
      }
      this.docList[recordId] = recordInfo;
      this._emit(MessageTypes.DOC_UPDATE, recordInfo);
      loger.log('Doc update ->' + recordId);
    } catch (e) {
      loger.warn('Doc Table Update Decode包异常');
    }
  }


}

export default DocApe;