EngineEntrance.js 4.5 KB
import Emiter from './Emiter';
import Sass from 'Sass';
import Mcu from 'mcu';
import MessageTypes from 'MessageTypes';
import Loger from 'Loger';
import ConferApe from 'apes/ConferApe';
import ChatApe from 'apes/ChatApe';
import VideoChat from 'apes/VideoApe';
import DocApe from 'apes/DocApe';
import WhiteBoardApe from 'apes/WhiteBoardApe';
import EngineUtils from "EngineUtils";

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

let info={"version":"v1.0.0","author":"3mang"};

let confInfo={};
let sass;
let mcu ;
let confer_ape;
let chat_ape;
let video_ape;
let doc_ape;
let wb_ape;

export default class MessageEntrance extends Emiter {
  constructor() {
    super();

    this.info=info;

    // 应用层会议信息
    confInfo = {};

    // Sass平台层
    sass = Sass;
    sass.on('*', (type, data) => this._emit(type, data));
    sass.on(sass.SUCCESS, this._h5SassSuccessHandler.bind(this));

    // 底层MCU消息层
    mcu = Mcu;
    mcu.on('*', (type, data) => this._emit(type, data));
    mcu.on(MessageTypes.CONFERENCE_JOIN_SUCCESS, this._conferenceJoinSuccessHandler.bind(this));

    // 注册所有应用Ape
    confer_ape = new ConferApe();
    confer_ape.on('*', (type, data) => this._emit(type, data));
    confer_ape.on(MessageTypes.DOC_SWITCH, this.docSwitchHandler.bind(this));

    chat_ape = new ChatApe();
    chat_ape.on('*', (type, data) => this._emit(type, data));

    video_ape = new VideoChat();
    video_ape.on('*', (type, data) => this._emit(type, data));

    doc_ape = new DocApe();
    doc_ape.on('*', (type, data) => this._emit(type, data));
    doc_ape.on(MessageTypes.DOC_UPDATE, this.docUpdateHandler.bind(this));

    doc_ape.on(MessageTypes.DOC_DEL, this.docDeleteHandler.bind(this));

    wb_ape = new WhiteBoardApe();
    wb_ape.on('*', (type, data) => this._emit(type, data));
    wb_ape.on(MessageTypes.ANNO_UPDATE, this.annoUpdateHandler.bind(this));
    this.on(MessageTypes.DOC_SHOW, this.docShowHandler.bind(this));

    this.sendChatMsg=this._sendChatMsg;
    this.joinClass=this._joinClass;
  }

  // 进入会议
  _joinClass(_confInfo) {
    confInfo = _confInfo||{};
    if(confInfo===null||EngineUtils.isEmptyObject(confInfo)){
      loger.log('不能进入会议,传递的参数不对.',_confInfo);
      return ;
    }
    if(sass){
      sass.sassChecking(_confInfo);
    }
  }

  // 离开会议
  leaveClass() {
    if(mcu){
      mcu.leaveMCU();
    }
  }
  // 通过SASS平台验证
  _h5SassSuccessHandler() {
    loger.log('加入底层MCU会议.'+confInfo.toString());
    if(mcu){
      mcu.joinMCU(confInfo);
    }
  }

  // MCU 会议成功
  _conferenceJoinSuccessHandler() {
    if(sass){
      sass.getClassDetail();//会议信息
      sass.getMeetingParm();//会议参数大全
    }
  }
  // 参会处理
  conferenceHandler(msg_type) {
    var msg = {
      type: msg_type,
      data: null
    };
    this._emit(msg.type, msg);
  }
  // 发送聊天消息
  /* _sendChatMsg(to, msg) {
    if (chat_ape) {
      chat_ape.sendChatMsg(to, msg);
    }
  }*/
  _sendChatMsg(_messageInfo) {
    if(_messageInfo===null||EngineUtils.isEmptyObject(_messageInfo)){
      loger.log('sendChatMsg 传递的参数不对',_messageInfo);
      return ;
    }

    if (chat_ape) {
      chat_ape.sendChatMsg(_messageInfo);
    }
  }

  // 白板笔记更新
  annoUpdateHandler(annoInfo) {
    const activeDocId = confer_ape.activeDocId;
    const docItem = doc_ape.docList[activeDocId];
    if (docItem && annoInfo.id == docItem.wbid) {
      this._emit(MessageTypes.DOC_ANNO, annoInfo);
    }
  }

  // 文档变更-笔记处理
  docShowHandler(docItem) {
    loger.log('Doc Show ->' + docItem.id + '|' + docItem.curPageNo);

    const annoInfo = wb_ape.annoInfos[docItem.wbid];
    if (annoInfo) {
      this._emit(MessageTypes.DOC_ANNO, annoInfo);
    } else {
      this._emit(MessageTypes.DOC_ANNO);

    }

  }

  // 文档切换
  docSwitchHandler() {
    const activeDocId = confer_ape.activeDocId;
    loger.log('Switch Doc Active -> ' + activeDocId);
    const docItem = doc_ape.docList[activeDocId];
    if (docItem) {
      this._emit(MessageTypes.DOC_SHOW, docItem);
    }
  }

  // 文档变更
  docUpdateHandler(docItem) {
    loger.log('Doc UpdateId ->' + docItem.id + '| activeDocId ->' + confer_ape.activeDocId);
    if (docItem.id == confer_ape.activeDocId) {
      this._emit(MessageTypes.DOC_SHOW, docItem);
    }
  }

  //文档删除
    docDeleteHandler(docItem){
        if (docItem.id == confer_ape.activeDocId) {
            this._emit(MessageTypes.DOC_DEL, docItem);
        }
    }
}
//MessageEntrance.MessageTypes = MessageTypes;