MessageEngine.js
4.0 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
import Emiter from './Emiter';
import h5Sass 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';
let loger = Loger.getLoger('MessageEngine');
export default class MessageEngine extends Emiter {
constructor() {
super();
// 应用层会议信息
this.confInfo = null;
// Sass平台层
this.h5Sass = h5Sass;
this.h5Sass.on('*', (type, data) => this.emit(type, data));
this.h5Sass.on(h5Sass.SUCCESS, this._h5SassSuccessHandler.bind(this));
// 底层MCU消息层
this.mcu = mcu;
this.mcu.on('*', (type, data) => this.emit(type, data));
this.mcu.on(MessageTypes.CONFERENCE_JOIN_SUCCESS, this._conferenceJoinSuccessHandler.bind(this));
// 注册所有应用Ape
this.conferApe = new ConferApe();
this.conferApe.on('*', (type, data) => this.emit(type, data));
this.conferApe.on(MessageTypes.DOC_SWITCH, this.docSwitchHandler.bind(this));
this.chat_ape = new ChatApe();
this.chat_ape.on('*', (type, data) => this.emit(type, data));
this.video_ape = new VideoChat();
this.video_ape.on('*', (type, data) => this.emit(type, data));
this.doc_ape = new DocApe();
this.doc_ape.on('*', (type, data) => this.emit(type, data));
this.doc_ape.on(MessageTypes.DOC_UPDATE, this.docUpdateHandler.bind(this));
this.doc_ape.on(MessageTypes.DOC_DEL, this.docDeleteHandler.bind(this));
this.wb_ape = new WhiteBoardApe();
this.wb_ape.on('*', (type, data) => this.emit(type, data));
this.wb_ape.on(MessageTypes.ANNO_UPDATE, this.annoUpdateHandler.bind(this));
this.on(MessageTypes.DOC_SHOW, this.docShowHandler.bind(this));
//this.say = this.say.bind(this)
//this.hello = this.hello.bind(this)
this.init=this._init;
}
_init (id) {
console.log("Engine init "+id);
}
// 白板笔记更新
annoUpdateHandler(annoInfo) {
const activeDocId = this.conferApe.activeDocId;
const docItem = this.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 = this.wb_ape.annoInfos[docItem.wbid];
if (annoInfo) {
this.emit(MessageTypes.DOC_ANNO, annoInfo);
} else {
this.emit(MessageTypes.DOC_ANNO);
}
}
// 文档切换
docSwitchHandler() {
const activeDocId = this.conferApe.activeDocId;
loger.log('Switch Doc Active -> ' + activeDocId);
const docItem = this.doc_ape.docList[activeDocId];
if (docItem) {
this.emit(MessageTypes.DOC_SHOW, docItem);
}
}
// 文档变更
docUpdateHandler(docItem) {
loger.log('Doc UpdateId ->' + docItem.id + '| activeDocId ->' + this.conferApe.activeDocId);
if (docItem.id == this.conferApe.activeDocId) {
this.emit(MessageTypes.DOC_SHOW, docItem);
}
}
//文档删除
docDeleteHandler(docItem){
if (docItem.id == this.conferApe.activeDocId) {
this.emit(MessageTypes.DOC_DEL, docItem);
}
}
// MCU 会议成功
_conferenceJoinSuccessHandler() {
this.h5Sass.getClassDetail();
}
// 通过SASS平台验证
_h5SassSuccessHandler() {
loger.log('加入底层MCU会议.');
this.mcu.joinMCU(this.confInfo);
}
// 进入会议
joinClass(_confInfo) {
this.confInfo = _confInfo;
this.h5Sass.sassChecking(_confInfo);
}
// 离开会议
leaveClass() {
this.mcu.leaveMCU();
}
// 参会处理
conferenceHandler(msg_type) {
var msg = {
type: msg_type,
data: null
};
this.emit(msg.type, msg);
}
// 发送聊天消息
sendChatMsg(to, msg) {
if (this.chat_ape) {
this.chat_ape.sendChatMsg(to, msg);
}
}
}
MessageEngine.MessageTypes = MessageTypes;
MessageEngine.data={
aa:"aa",
bb:11,
cc:"cccc"
};