DocApe.js 31.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
// //////////////////////////////////////////////////////////////////////////////
//
//  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';
import GlobalConfig from 'GlobalConfig';
import EngineUtils from 'EngineUtils';

let loger = Loger.getLoger('DocApe');
//let itemIdx = 0;//table插入新数据的计数id,目前用时间戳

class DocApe extends Ape {
    constructor() {
        super(
            ApeConsts.DOCSHARING_SESSION_ID,
            ApeConsts.DOCSHARING_SESSION_NAME,
            ApeConsts.DOCSHARING_SESSION_TAG
        );
        this.docList = {};//记录文档的数组this.docList[itemIdx]=itemIdx的数据

        // 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, ApeConsts.DOCSHARING_OBJ_TABLE_NAME, ApeConsts.DOCSHARING_OBJ_TABLE_TAG, 0, new ArrayBuffer);
   }

    /////////////发送数据操作//////////////////////////////////////////////////////
    //上传文档
    documentUpload(paramInfo) {
        if (paramInfo == null || EngineUtils.isEmptyObject(paramInfo)) {
            loger.warn('上传文档->失败->参数错误->',paramInfo);
            this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
            return;
        }
        //判断文档是否已经存在,每个文档都有唯一的docId,如果已经同步的文档中存在相同的docId就不需要再同步
        if (this.checkDocId(paramInfo.docId)) {
            //文档已经存在相同的docId,不需要同步上传
            loger.warn('上传文档->失败->文档档的docId无效或已经存在相同的docId不需要上传');
            return;
        }

        let itemIdx = EngineUtils.creatSoleNumberFromTimestamp();//
        let docDataModelPdu = this.packPdu(paramInfo, itemIdx);
        if (docDataModelPdu == null) {
            loger.log('上传文档->失败->数据无效');
            this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
            return;
        }
        //console.log(docDataModelPdu);

        let tableItemPdu = new pdu['RCRegistryTableItemPdu'];
        tableItemPdu.itemIdx = itemIdx;//直接用时间戳作为id
        tableItemPdu.registerObjId = ApeConsts.DOCSHARING_OBJ_TABLE_ID;// tableItemPdu.registerObjId=ApeConsts.DOCSHARING_OBJ_TABLE_ID_H5;
        tableItemPdu.owner = 0;//收到flash的是这个值,不清楚先写固定
        tableItemPdu.itemData = docDataModelPdu.toArrayBuffer();

        //insert
        let tableInsertItemPdu = new pdu['RCRegistryTableInsertItemPdu'];
        //optional RCPduType_E type = 1 [default = RCPDU_REG_TABLE_UPDATE_PDU];
        //repeated RCRegistryTableItemPdu items = 2;
        tableInsertItemPdu.type = pdu.RCPDU_REG_TABLE_INSERT_PDU;//
        tableInsertItemPdu.items.push(tableItemPdu);

        let updateObjPdu = new pdu['RCRegistryUpdateObjPdu'];
        updateObjPdu.objId = ApeConsts.DOCSHARING_OBJ_TABLE_ID;// updateObjPdu.objId = ApeConsts.DOCSHARING_OBJ_TABLE_ID_H5;
        updateObjPdu.subType = tableInsertItemPdu.type;
        updateObjPdu.userData = tableInsertItemPdu.toArrayBuffer();

        //同步
        let adapterItemPdu = new pdu['RCAdapterItemPdu'];
        adapterItemPdu.type = pdu.RCPDU_REG_UPDATE_OBJ;
        adapterItemPdu.itemData = updateObjPdu.toArrayBuffer();

        let adapterPdu = new pdu['RCAdapterPdu'];
        adapterPdu.type = pdu.RCPDU_REG_ADAPTER;
        adapterPdu.item.push(adapterItemPdu);

        loger.log("上传文档->发送->itemIdx=" + tableItemPdu.itemIdx);
        this.sendUniform(adapterPdu, true);
    }

    updaterDoc(_docDataModel, _itemIdx) {
        //loger.log("文档===updaterDoc ",_itemIdx);
        //验证坐标点集合数组是否合法
        if (_docDataModel == null || _itemIdx == null) {
            this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
            return null;
        }
        loger.log("文档->updaterDoc ", _docDataModel);

        let docDataModelPdu = this.packPdu(_docDataModel, _itemIdx);
        let tableItemPdu = new pdu['RCRegistryTableItemPdu'];
        tableItemPdu.itemIdx = _itemIdx;//直接用时间戳作为id
        //tableItemPdu.registerObjId=ApeConsts.DOCSHARING_OBJ_TABLE_ID;// tableItemPdu.registerObjId=ApeConsts.DOCSHARING_OBJ_TABLE_ID_H5;
        tableItemPdu.owner = 0;//收到flash的是这个值,不清楚先写固定
        tableItemPdu.itemData = docDataModelPdu.toArrayBuffer();

        //insert
        let tableInsertItemPdu = new pdu['RCRegistryTableUpdateItemPdu'];
        //optional RCPduType_E type = 1 [default = RCPDU_REG_TABLE_UPDATE_PDU];
        //repeated RCRegistryTableItemPdu items = 2;
        tableInsertItemPdu.type = pdu.RCPDU_REG_TABLE_UPDATE_PDU;//
        tableInsertItemPdu.items.push(tableItemPdu);

        let updateObjPdu = new pdu['RCRegistryUpdateObjPdu'];
        updateObjPdu.objId = ApeConsts.DOCSHARING_OBJ_TABLE_ID;// updateObjPdu.objId = ApeConsts.DOCSHARING_OBJ_TABLE_ID_H5;
        updateObjPdu.subType = tableInsertItemPdu.type;
        updateObjPdu.userData = tableInsertItemPdu.toArrayBuffer();

        //同步
        let adapterItemPdu = new pdu['RCAdapterItemPdu'];
        adapterItemPdu.type = pdu.RCPDU_REG_UPDATE_OBJ;
        adapterItemPdu.itemData = updateObjPdu.toArrayBuffer();

        let adapterPdu = new pdu['RCAdapterPdu'];
        adapterPdu.type = pdu.RCPDU_REG_ADAPTER;
        adapterPdu.item.push(adapterItemPdu);

        loger.log("发送更新文档.itemIdx=" + tableItemPdu.itemIdx);
        this.sendUniform(adapterPdu, true);
    }
    //获取文档的完整地址和所有图片
    getDocFullAddress(_param){
        if (_param == null || _param.url == null || _param.itemIdx ==null) {
            loger.warn('获取文档完整地址->传递的参数不正确->', _param);
            return {"code":ApeConsts.RETURN_FAILED, "data": "获取文档时传递的参数不对"};
        }
        let fullPath='';//文档路径地址
        let pageNum=1;//总页数
        let docType="";//文档地址的后缀类型
        let fileType="";//文档的原始类型
        let docItem=this.docList[_param.itemIdx];
        if(docItem){
            fullPath=docItem.url||"";
            pageNum=docItem.pageNum||1;
            fileType=docItem.fileType||""
        }else {
            fullPath =_param.url;
        }

        //获取当前文档的后缀名
        docType=this._getDocType(fullPath);
        let substrFullPath=this._getDocPath(fullPath);//获取去掉后缀和文件名的地址,需要获取同目录下其他文件
        let imagesArr=[];
        let htmlPath="";
        let pdfPath="";

        //根据文件后缀名,生成对应的访问地址
        if(docType=="jpg"||docType=="png"||docType=="swf"||docType=="pdf"||docType=="doc"||docType=="pptx"){
            //页数从1开始
            for (let i = 1; i <=pageNum; i++) {
                imagesArr.push(substrFullPath + "/" + i + ".jpg");
            }
        }
        if(docType=="swf"||docType=="pdf"||docType=="doc"||docType=="pptx"){
            pdfPath=fullPath.replace(/\.swf/g, ".pdf")||"";
        }
        //动态PPT
        if(docType=="html"){
             htmlPath=fullPath;
        }
        //返回文档第所有地址
        return {'code':ApeConsts.RETURN_SUCCESS, 'data': '','docFullAddress':{
                'images':imagesArr,
                'pdf':pdfPath,
                'html':htmlPath
        }};
    }

    _getDocType(_fullPath){
        if(!_fullPath){
            return "";
        }
        if(_fullPath.lastIndexOf(".jpg")>=0){
            return "jpg";
        }
        if(_fullPath.lastIndexOf(".png")>=0){
            return "png";
        }
        if(_fullPath.lastIndexOf(".swf")>=0){
            return "swf";
        }
        if(_fullPath.lastIndexOf(".pdf")>=0){
            return "pdf";
        }
        if(_fullPath.lastIndexOf(".doc")>=0){
            return "doc";
        }
        if(_fullPath.lastIndexOf(".html")>=0){
            return "html";
        }
        if(_fullPath.lastIndexOf(".pptx")>=0){
            return "pptx";
        }
        return "";
    }
    //获取去掉文件名和后缀名的地址 http://www.xxx.xxx/image/aa.jpg  -->http://www.xxx.xxx/image/
    _getDocPath(_fullPath){
        if(!_fullPath){
            return "";
        }
        var lastIndex = _fullPath.lastIndexOf("/");
        if (lastIndex > 0) {
            return _fullPath.substr(0, lastIndex);
        }
        return _fullPath;
    }

    //获取文档的图片完整地址
    getDocImageFullPath(_param) {
        if (_param == null || _param.relativeUrl == null || _param.relativeUrl == "") {
            loger.warn('获取文档完整地址,传递的参数不对.', _param);
            return [];
        }

        let port = (GlobalConfig.DOCServerPort == "" || GlobalConfig.DOCServerPort == null) ? "" : ":" + GlobalConfig.DOCServerPort;
        let fullPath = GlobalConfig.DOCServerIP + port + _param.relativeUrl;
        if (fullPath && fullPath.indexOf("http://") < 0) {
            fullPath = "http://" + fullPath;
        }

        var fileType = "jpg";
        switch (_param.type) {
            case "jpg":
                fileType = "jpg";
                fullPath = this.replacePathType(fullPath) + ".jpg";
                break;
            case "png":
                fileType = "png";
                fullPath = this.replacePathType(fullPath) + ".png";
                break;
            default :
                //不做处理,直接返回拼接的地址
                break;
        }

        if (_param.pageNum && parseInt(_param.pageNum) > 1) {
            //如果是多页的,需要返回序列
            var lastIndex = fullPath.lastIndexOf("/");
            if (lastIndex > 0) {
                let newPath = fullPath.substr(0, lastIndex);
                let pathArr = [];
                //页数从1开始
                for (let i = 1; i <= _param.pageNum; i++) {
                    pathArr.push(newPath + "/" + i + "." + fileType);
                }
                return pathArr;
            } else {
                return [fullPath];
            }
        } else {
            return [fullPath];
        }
    }

    //获取文档的pdf完整地址
    getDocPDFFullPath(_param) {
        if (_param == null || _param.relativeUrl == null || _param.relativeUrl == "") {
            loger.warn('获取文档完整地址,传递的参数不对.', _param);
            return [];
        }
        let port = (GlobalConfig.DOCServerPort == "" || GlobalConfig.DOCServerPort == null) ? "" : ":" + GlobalConfig.DOCServerPort;
        let fullPath = GlobalConfig.DOCServerIP + port + _param.relativeUrl;
        if (fullPath && fullPath.indexOf("http://") < 0) {
            fullPath = "http://" + fullPath;
        }
        fullPath = this.replacePathType(fullPath) + ".pdf";
        return [fullPath];
    }

    // 去除文件的后缀格式名称
    replacePathType(_path) {
        let path = _path;
        path = path.replace(/.jpg/g, "");
        path = path.replace(/.png/g, "");
        path = path.replace(/.swf/g, "");
        path = path.replace(/.pdf/g, "");
        return path;
    }

    //组织完整的文档信息,包含上传时的信息和转换后的完整地址信息
    _docPackFullInfo(_itemDataInfo){
        let itemDataInfo=_itemDataInfo;
        let getDocAddress=this.getDocFullAddress(_itemDataInfo);
        if(getDocAddress.code==ApeConsts.RETURN_SUCCESS){
            itemDataInfo.images=getDocAddress.docFullAddress.images||[];
            itemDataInfo.pdf=getDocAddress.docFullAddress.pdf||"";
            itemDataInfo.html=getDocAddress.docFullAddress.html||"";
        }else {
            itemDataInfo.images=[];
            itemDataInfo.pdf='';
            itemDataInfo.html='';
        }
        loger.log('docPackFullInfo->', itemDataInfo);
        return itemDataInfo;
    }
    //更新文档模块的录制信息,每次开启录制的时候需要把当前文档的信息更新一次
    updaterRecordApeStatus(_param){
       /* if(GlobalConfig.isHost&&!GlobalConfig.isRecordPlayBack&&GlobalConfig.activeDocId>0){
            loger.log("录制状态发送改变->更新当前的文档数据->docId:", GlobalConfig.activeDocId, 'page:',GlobalConfig.activeDocCurPage);
            this.documentSwitchPage({
                "itemIdx": GlobalConfig.activeDocId,
                "curPageNo":GlobalConfig.activeDocCurPage
            });
        }*/
        loger.warn("录制状态发送改变->更新当前的文档数据->docId:", GlobalConfig.activeDocId, 'page:',GlobalConfig.activeDocCurPage);
        this.documentSwitchPage({
            "itemIdx": GlobalConfig.activeDocId,
            "curPageNo":GlobalConfig.activeDocCurPage
        });
    }
    //清除当前文档模块的数据
    clearData(){
        loger.log("clearData->")
        this.docList={};
        GlobalConfig.activeDocId=0;
        GlobalConfig.activeDocCurPage=1;

    }
    //切换文档
    documentSwitchDoc(paramInfo) {
        loger.log('切换文档->', paramInfo);
        if (GlobalConfig.isRecordPlayBack) {
            loger.warn('录制回放状态不允许切换文档');
            return;
        }

        if (paramInfo == null || paramInfo.itemIdx == null) {
            loger.warn('切换文档失败,参数错误', paramInfo);
            this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
            return;
        }

        if (paramInfo.itemIdx == GlobalConfig.activeDocId && GlobalConfig.activeDocId != 0) {
            loger.warn('文档已经显示', paramInfo.itemIdx, GlobalConfig.activeDocId);
            return;
        }

        //更新切换之前的文档的数据,要显示当前切换的文档,上一个文档需要隐藏
        let oldDocModel;
        if (GlobalConfig.activeDocId != 0) {
            oldDocModel = this.docList[GlobalConfig.activeDocId];
            if (oldDocModel) {
                oldDocModel.action = ApeConsts.DOC_ACTION_NORMAL;
                oldDocModel.visible = false;//设置为不可见
                oldDocModel.animationStep=1;//切换文档之后动画步数还原
            }
        }

        //获取已经存在的数据
        let docDataModel = this.docList[paramInfo.itemIdx];
        if (docDataModel == null) {
            loger.warn('切换文档失败,文档不存在', paramInfo);
            this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
            return;
        }

        //更新当前选择的文档数据的字段
        docDataModel.action = ApeConsts.DOC_ACTION_SWITCH_DOC;
        docDataModel.visible = paramInfo.visible || false;//默认是false
        docDataModel.animationStep=1;//切换文档之后动画步数还原

        //loger.log('切换文档,当前文档和上一个显示的文档都需要更新状态');
        loger.log({"oldDoc": oldDocModel, "nowDoc": docDataModel});
        //更新当前选择的文档
        this.updaterDoc(docDataModel, docDataModel.itemIdx);

        //更新上一个文档 隐藏
        if (oldDocModel) {
            this.updaterDoc(oldDocModel, oldDocModel.itemIdx);
        }
    }


    //文档翻页
    documentSwitchPage(paramInfo) {
        loger.log('文档翻页->',paramInfo);
        //获取已经存在的数据
        let docDataModel = this.docList[paramInfo.itemIdx];
        //console.log(docDataModelPdu);
        //console.log(docDataModel);
        if (docDataModel == null) {
            loger.log('文档翻页->文档不存在', paramInfo);
            this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
            return;
        }
        //更新数据的字段
        docDataModel.action = ApeConsts.DOC_ACTION_SWITCH_PAGE;
        docDataModel.curPageNo = parseInt(paramInfo.curPageNo) || 1;
        docDataModel.animationStep=1;//切换文档之后动画步数还原
        if (docDataModel.curPageNo < 1) {
            docDataModel.curPageNo = 1;//默认值最小是1
        }
        this.updaterDoc(docDataModel, docDataModel.itemIdx);
    }

    //文档动画切换
    documentSwitchAnimation(paramInfo) {
        loger.log('文档页面动画切换->',paramInfo);
        //获取已经存在的数据
        let docDataModel = this.docList[GlobalConfig.activeDocId];
        if (docDataModel == null) {
            loger.log('文档页面动画切换->文档不存在',GlobalConfig.activeDocId, paramInfo);
            this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
            return;
        }
        //更新数据的字段
        docDataModel.action = ApeConsts.DOC_ACTION_SWITCH_ANIMATION;
        docDataModel.animationStep=docDataModel.animationStep||1;//最少步骤是1
        if(paramInfo&&paramInfo.step==-1){
            //上一个
            docDataModel.animationStep--;
        }else{
            //下一个
            docDataModel.animationStep++;
        }
        if (!docDataModel.animationStep||docDataModel.animationStep < 1) {
            docDataModel.animationStep = 1;//默认值最小是1
        }
        this.updaterDoc(docDataModel, docDataModel.itemIdx);
    }

    //文档切换显示模式
    documentSwitchShowModel(paramInfo) {
        loger.log('文档切换显示模式', paramInfo);
        //获取已经存在的数据
        let docDataModel = this.docList[paramInfo.itemIdx];

        if (docDataModel == null) {
            loger.log('文档切换显示模式->文档不存在', paramInfo);
            this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
            return;
        }
        //更新数据的字段
        docDataModel.action = ApeConsts.DOC_ACTION_SWITCH_PAGE;
        docDataModel.curPageNo = parseInt(paramInfo.curPageNo) || 1;
        if (docDataModel.curPageNo < 1) {
            docDataModel.curPageNo = 1;//默认值最小是1
        }
        this.updaterDoc(docDataModel, docDataModel.itemIdx);
    }

    //缩放/滚动/显示模式
    documentCommand(paramInfo) {
        //获取已经存在的数据
        let docDataModel = this.docList[paramInfo.itemIdx];
        if (docDataModel == null) {
            loger.log('documentCommand失败,文档不存在', paramInfo);
            this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
            return;
        }
        //更新数据的字段
        docDataModel.action = ApeConsts.DOC_ACTION_COMMAND;
        docDataModel.showType = parseInt(paramInfo.showType) || 0;//0;//完整显示;1;//按宽度显示;2;//按高度显示
        this.updaterDoc(docDataModel, docDataModel.itemIdx);
    }

    //删除所有文档
    documentDeleteAll(_param) {
        for (let key in this.docList) {
            //console.log("key:"+key);
            loger.log("删除文档数据->itemIdx:" + key);
            this.documentDelete({"itemIdx": key});
        }
    }

    //删除文档
    documentDelete(paramInfo) {
        //{"itemIdx":itemIdx}
        let tableDeleteItemPdu = new pdu['RCRegistryTableDeleteItemPdu'];
        //optional RCPduType_E type = 1 [default = RCPDU_REG_TABLE_DELETE_PDU];
        // repeated uint32 item_idx = 2;
        tableDeleteItemPdu.type = pdu.RCPDU_REG_TABLE_DELETE_PDU;//
        tableDeleteItemPdu.itemIdx = parseInt(paramInfo.itemIdx);//这里需要设置要删除的数据的itemIdx,每条数据的这个id都不一样

        let updateObjPdu = new pdu['RCRegistryUpdateObjPdu'];
        updateObjPdu.objId = ApeConsts.DOCSHARING_OBJ_TABLE_ID;//    updateObjPdu.objId = ApeConsts.DOCSHARING_OBJ_TABLE_ID_H5;
        updateObjPdu.subType = tableDeleteItemPdu.type;
        updateObjPdu.userData = tableDeleteItemPdu.toArrayBuffer();

        //同步
        let adapterItemPdu = new pdu['RCAdapterItemPdu'];
        adapterItemPdu.type = pdu.RCPDU_REG_UPDATE_OBJ;
        adapterItemPdu.itemData = updateObjPdu.toArrayBuffer();

        let adapterPdu = new pdu['RCAdapterPdu'];
        adapterPdu.type = pdu.RCPDU_REG_ADAPTER;
        adapterPdu.item.push(adapterItemPdu);

        loger.log("文档发送删除数据=============>" + tableDeleteItemPdu.itemIdx);
        this.sendUniform(adapterPdu, true);
    }

    /////收到消息处理/////////////////////////////////////////////////////////////////////////////////
    tableInsertHandler(owner, itemIdx, itemData) {
     /*   let itemDataInfo = this.unPackPdu(owner, itemIdx, itemData);
        this.docList[itemIdx] = itemDataInfo;

        if (itemDataInfo.visible == "true" || itemDataInfo.visible == true) {
            GlobalConfig.activeDocId = itemDataInfo.itemIdx;//当前激活的文档ID
            GlobalConfig.activeDocCurPage = itemDataInfo.curPageNo;//当前激活的文档的当前页
            loger.log('tableInsertHandler 设置当前激活的文档id');
        }
        loger.log('tableInsertHandler->', itemDataInfo);
        this._emit(MessageTypes.DOC_UPDATE, itemDataInfo);//用添加和更新都统一DOC_UPDATE

        //文档数据更新完毕,如果当前没有显示的文档,默认选择一个显示
        if (GlobalConfig.activeDocId < 1 && itemDataInfo) {
            let paramInfo = {
                "itemIdx": itemDataInfo.itemIdx,
                "visible": true
            };
            this.documentSwitchDoc(paramInfo);
        }*/
    }
    //添加文档
    tableInsertApeHandler(_tableUpdateItems, _seekTime) {
        let tableInsertItems =_tableUpdateItems;
        let tableInsertItemsLen = tableInsertItems.length;
        loger.log('添加文档->', "activeDocId->", GlobalConfig.activeDocId, "tableUpdateItemsLen->", tableInsertItemsLen);
        for (let i = 0; i < tableInsertItemsLen; ++i) {
            let insertItem = tableInsertItems[i];
            //this.tableInsertHandler(insertItem.owner, insertItem.itemIdx, insertItem.itemData);
            let itemDataInfo = this.unPackPdu(insertItem.owner, insertItem.itemIdx, insertItem.itemData);
            if(itemDataInfo){
                this.docList[insertItem.itemIdx] = itemDataInfo;
                if (itemDataInfo.visible == "true" || itemDataInfo.visible == true) {
                    GlobalConfig.activeDocId = itemDataInfo.itemIdx;//当前激活的文档ID
                    GlobalConfig.activeDocCurPage = itemDataInfo.curPageNo;//当前激活的文档的当前页
                    loger.log('添加文档->设置当前激活的文档id');
                }
                let getdocPackFullInfo= this._docPackFullInfo(itemDataInfo);
                this._emit(MessageTypes.DOC_UPDATE, getdocPackFullInfo);//用添加和更新都统一DOC_UPDATE
            }
        }
        //文档数据更新完毕,如果当前没有显示的文档,默认选择一个显示
        this._showDefaultDoc();
    }
    tableDeleteHandler(object_id, tableDeleteData) {
        loger.log('删除文档数据->', object_id, tableDeleteData);//["tableDeleteHandler",1179649,{"type":231,"itemIdx":[1486301768]}]
        if (tableDeleteData && tableDeleteData.itemIdx) {
            let len = tableDeleteData.itemIdx.length;
            let itemIdxs = tableDeleteData.itemIdx;
            for (let i = 0; i < len; i++) {
                if (this.docList[itemIdxs[i]]) {
                    loger.log("删除文档数据:", itemIdxs[i]);
                    //this._emit(MessageTypes.DOC_DELETE, {"itemIdx": itemIdxs[i]});
                    let itemDataInfo = this.docList[itemIdxs[i]];
                    if (itemDataInfo && (itemDataInfo.visible == "true" || itemDataInfo.visible == true)) {
                        GlobalConfig.activeDocId = 0;//当前激活的文档ID
                        GlobalConfig.activeDocCurPage = 1;//当前激活的文档的当前页
                        loger.log('删除文档数据->清除当前显示的文档');
                    }
                    this._emit(MessageTypes.DOC_DELETE, {"itemIdx": itemIdxs[i]});
                    delete this.docList[itemIdxs[i]];
                }
            }
        }
    }

    tableUpdateHandler(owner, itemIdx, itemData) {
        //这个方法废弃,更新用tableUpdateApeHandler方法
        /*   let itemDataInfo =  this.unPackPdu(owner, itemIdx, itemData);
         if(itemDataInfo!=null){
         this.docList[itemIdx] = itemDataInfo;
         if(itemDataInfo&&(itemDataInfo.visible=="true"||itemDataInfo.visible==true)){
         GlobalConfig.activeDocId=itemDataInfo.itemIdx;//当前激活的文档ID
         GlobalConfig.activeDocCurPage=itemDataInfo.curPageNo;//当前激活的文档的当前页
         loger.log('tableUpdateHandler 设置当前激活的文档id');
         }
         loger.log('tableUpdateHandler 发送给客户端');
         loger.log(itemDataInfo);
         this._emit(MessageTypes.DOC_UPDATE,itemDataInfo);

         }else {
         loger.log('tableUpdateHandler 数据无效--> itemIdx',itemIdx);
         }*/
    }

    tableUpdateApeHandler(_tableUpdateItems, _seekTime) {
        let tableUpdateItemsLen = _tableUpdateItems.length;
        loger.log('更新文档->', "activeDocId->", GlobalConfig.activeDocId, "更新的数量->", tableUpdateItemsLen);
        for (let i = 0; i < tableUpdateItemsLen; ++i) {
            let tableItem = _tableUpdateItems[i];
            let itemDataInfo = this.unPackPdu(tableItem.owner, tableItem.itemIdx, tableItem.itemData);
            if (itemDataInfo != null) {
                this.docList[tableItem.itemIdx] = itemDataInfo;
                if (itemDataInfo && (itemDataInfo.visible == "true" || itemDataInfo.visible == true)) {
                    GlobalConfig.activeDocId = itemDataInfo.itemIdx;//当前激活的文档ID
                    GlobalConfig.activeDocCurPage = itemDataInfo.curPageNo;//当前激活的文档的当前页
                    loger.log('更新文档->设置当前激活的文档id->', GlobalConfig.activeDocId, "curPageNum->", GlobalConfig.activeDocCurPage);
                }
                let getdocPackFullInfo= this._docPackFullInfo(itemDataInfo);
                this._emit(MessageTypes.DOC_UPDATE, getdocPackFullInfo);
            } else {
                loger.log('更新文档-> 数据无效--> itemIdx', itemIdx);
            }
        }
        this._showDefaultDoc();
    }

    //果当前没有显示的文档,默认选择一个显示文档
    _showDefaultDoc() {
        //显示默认文档条件->1.非录制回放状态下 2.只有host有权限操作 3.当前激活的文档id不为0
        if (GlobalConfig.isRecordPlayBack || !GlobalConfig.isHost || GlobalConfig.activeDocId > 0) {
            return;
        }

        let tempDocItemIdx;//临时记录文档数据,用于显示默认文档
        for (let key in this.docList) {
            tempDocItemIdx= this.docList[key];
            if (tempDocItemIdx) {
                loger.log("选择一个文档作为默认文档显示->", tempDocItemIdx);
                let paramInfo = {
                    "itemIdx": tempDocItemIdx.itemIdx,
                    "visible": true
                };
                this.documentSwitchDoc(paramInfo);
                //选择完成就跳出循环
              return;
            }
        }
    }

    onJoinChannelHandlerSuccess() {
        loger.log(this._session_name + ' onJoinChannelHandlerSuccess===========================');
        if (this._apeDelayed) {
            // this._apeDelayedMsgs.push(regBuffer);
            // this._apeDelayedStart();
            setTimeout(() => {
                this._emit(DocApe.DOC_JOIN_CHANNEL_SUCCESS);
            }, (GlobalConfig.mcuDelay + GlobalConfig.docDelay) || 12000 + GlobalConfig.docDelay);
        } else {
            setTimeout(() => {
                this._emit(DocApe.DOC_JOIN_CHANNEL_SUCCESS);
            }, GlobalConfig.docDelay);
        }
    }

    //检查文档是否已经存在,如果存在 返回true,否则返回false
    checkDocId(_docId) {
        if (_docId == null) {
            loger.warn('查找文档->失败->参数为null');
            return true;
        }
        //遍历查找
        for (let key in this.docList) {
            let item = this.docList[key];
            if (item && item.docId == _docId) {
                loger.log('查找文档->已经存在->',_docId);
                return true;
            }
        }
        loger.log('查找文档->没有查找到文档->',_docId);
        //储存的数据中没有查找到
        return false;
    }

    ///////数据的封包和解包/////////////////////////////////////////
    packPdu(_param, _itemIdx) {
        loger.log("文档->packPdu");
        //验证坐标点集合数组是否合法
        if (_param == null || _itemIdx == null) {
            this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
            return null;
        }
        //判断type类型,根据type设置不同的参数
        let docModelPdu = new pdu['RCDocSendDataModelPdu'];
        docModelPdu.itemIdx = _itemIdx;
        docModelPdu.owner = GlobalConfig.nodeId;
        docModelPdu.from = GlobalConfig.nodeId;
        docModelPdu.curPageNo = _param.curPageNo || 1;
        docModelPdu.pageNum = _param.pageNum || 1;
        docModelPdu.fileType = _param.fileType || "";
        docModelPdu.creatUserId = _param.creatUserId || "0";
        docModelPdu.url = _param.url||"";//这个地址没用到,数据太长占用资源 暂停使用//"http://101.200.150.192/DocSharing/data/h5test/20170206-171100025/7e9c4178cac1133e0dd9d5b583439122.jpg";
        docModelPdu.relativeUrl = _param.relativeUrl || "";//"/DocSharing/data/h5test/20170206-171100025/7e9c4178cac1133e0dd9d5b583439122.jpg";
        docModelPdu.curV = _param.curV || 0;
        docModelPdu.curH = _param.curH || 0;
        docModelPdu.scale = _param.scale || 100;//按百分比
        docModelPdu.visible = _param.visible || false;
        docModelPdu.action = _param.action || ApeConsts.DOC_ACTION_NORMAL;//0,无操作, 1翻页、2.显示/隐藏, 3缩放/滚动
        docModelPdu.docId = _param.docId || "";//文档在服务器数据库中的唯一id,必须有
        docModelPdu.md5 = _param.md5 || "";//MD5
        docModelPdu.fileName = _param.fileName || "doc_" + _itemIdx;//文档的名字
        docModelPdu.dynamicTS = _param.dynamicTS || "0";//文档上传后返回值中的字段dynamicTransferStatic
        docModelPdu.showType = _param.showType || 0;//文档显示模式
        docModelPdu.animationStep=_param.animationStep || 1;//当前页面上的动画步数(动态ppt时有这个字段)
        //loger.log(docModelPdu);
        return docModelPdu;
    }

    unPackPdu(owner, itemIdx, itemData) {
        if (owner == null || itemIdx == null || itemData == null) {
            this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_APE_INTERFACE_PARAM_WRONG);
            return null;
        }
        try {
            let docModelPdu = pdu['RCDocSendDataModelPdu'].decode(itemData);
            loger.log("文档===>unPackPdu");
            return docModelPdu;
        } catch (err) {
            loger.log("文档===>unPackPdu->Pdu解析错误->itemIdx=" + itemIdx + "->err:" + err.message);
        }
        return null;
    }


}
DocApe.prototype.DOC_JOIN_CHANNEL_SUCCESS = DocApe.DOC_JOIN_CHANNEL_SUCCESS = 'docServer.join.channel.success';
export default DocApe;