EngineEntrance.js
8.2 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
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 VideoApe from 'apes/VideoApe';
import DocApe from 'apes/DocApe';
import WhiteBoardApe from 'apes/WhiteBoardApe';
import EngineUtils from "EngineUtils";
import GlobalConfig from 'GlobalConfig';
let loger = Loger.getLoger('MessageEntrance');
let _sdkInfo={"version":"v1.0.0","author":"www.3mang.com"};
let _sass;
let _mcu ;
let _confer_ape;
let _chat_ape;
let _video_ape;
let _doc_ape;
let _wb_ape;
let _initSuccessCallBackFun;
let _initFailureCallBackFun;
let _joinClassSuccessCallBackFun;
let _joinClassFailureCallBackFun;
export default class MessageEntrance extends Emiter {
constructor() {
super();
//sdk 信息
this.sdkInfo=_sdkInfo;
loger.log(this.sdkInfo);
this.on(MessageTypes.CLASS_INIT_FAILED,this._sassInitFailedHandler.bind(this));
this.on(MessageTypes.CLASS_JOIN_FAILED,this._joinClassFailureHandler.bind(this));
this.on(MessageTypes.DOC_SHOW, this.docShowHandler.bind(this));
// Sass平台层
_sass = Sass;
_sass.on('*', (type, data) => this._emit(type, data));
_sass.on(_sass.SUCCESS, this._sassVerifySuccessHandler.bind(this));
_sass.on(_sass.CLASS_INIT_SUCCESS, this._sassInitSuccessHandler.bind(this));
_sass.on(_sass.CLASS_INIT_FAILED, this._sassInitFailedHandler.bind(this));
_sass.on(_sass.CLASS_GET_MEETING_PARAM,this._h5SassGetMeetingParaSuccessHandler);
// 底层MCU消息层
_mcu = Mcu;
_mcu.on('*', (type, data) => this._emit(type, data));
_mcu.on(MessageTypes.CLASS_JOIN_SUCCESS, this._joinClassSuccessHandler.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 VideoApe();
_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.init=this._init;
this.joinClass=this._joinClass;
this.sendChatMsg=this._sendChatMsg;
this.setDebugData=this._setDebugData;
}
_init(_param,_onSuccess,_onFailure){
_initSuccessCallBackFun=_onSuccess;
_initFailureCallBackFun=_onFailure;
//{"meetingNumber":"1653304953","portal":"112.126.80.182:80","userRole":"normal","userId":0}
//判断传入的参数是否存在
if(_param==null||EngineUtils.isEmptyObject(_param)){
loger.log('init初始化失败',MessageTypes.ERROR_PARAM);
this._emit(MessageTypes.CLASS_INIT_FAILED,MessageTypes.ERROR_PARAM);
return ;
}
//判断必要的参数字段值
if(_param.meetingNumber==null||isNaN(_param.meetingNumber)||_param.portal==null){
loger.log('init初始化失败',_param);
this._emit(MessageTypes.CLASS_INIT_FAILED,MessageTypes.ERROR_PARAM);
return ;
}
loger.log('init',_param);
//保存参数
GlobalConfig.confId=_param.meetingNumber;
GlobalConfig.portal=_param.portal;
GlobalConfig.userRole=_param.userRole||"normal";
GlobalConfig.userId=_param.userId||"0";
//获取课堂校验信息
if(_sass){
_sass.sassGetJoinParams(GlobalConfig.getConfInfo());
}
}
_joinClass(_param,_onSuccess,_onFailure){
_joinClassSuccessCallBackFun=_onSuccess;
_joinClassFailureCallBackFun=_onFailure;
//{"userName":"名字","password":""}
if(_param==null||EngineUtils.isEmptyObject(_param)){
this._emit(MessageTypes.CLASS_JOIN_FAILED,MessageTypes.ERROR_PARAM);
loger.log('不能进入会议,传递的参数不对.',_param);
return ;
}
//判断userName
if(_param.userName==null){
loger.log('不能进入会议,传递的参数不对.名字不能为空');
this._emit(MessageTypes.CLASS_JOIN_FAILED,MessageTypes.ERROR_PARAM);
return ;
}
GlobalConfig.userName=_param.userName;
GlobalConfig.password=_param.password||"";
//开始校验
if(_sass){
_sass.sassChecking(GlobalConfig.getConfInfo());
}
}
// 离开会议
leaveClass() {
if(_mcu){
_mcu.leaveMCU();
}
}
// 用meetingNumber向SASS平台获取入会验证信息成功
_sassInitSuccessHandler(_data) {
//{"siteId":"h5test","passwordRequired":true,"md5":"de399d5540b3da2fbc1eb0a770d4fd66","code":0,"msType":1}
if(_data){
GlobalConfig.md5=_data.md5||"";//这个暂时用假数据,后台接口写完就有数据了
GlobalConfig.msType=_data.msType||1;
GlobalConfig.passwordRequired=_data.passwordRequired||false;
GlobalConfig.siteId=_data.siteId;
}
loger.log('向SASS平台获取入会验证信息成功.');
this._emit(MessageTypes.CLASS_INIT_SUCCESS,_data);
if(_initSuccessCallBackFun){
_initSuccessCallBackFun(_data);
}
}
// 用meetingNumber向SASS平台获取入会验证信息失败
_sassInitFailedHandler() {
loger.log('向SASS平台获取入会验证信息失败.');
//this._emit(MessageTypes.CLASS_INIT_FAILED);
if(_initFailureCallBackFun){
_initFailureCallBackFun();
}
}
//使用固定的假数据
_setDebugData(_data){
loger.log("setDebugData "+_data);
GlobalConfig.setDebugData(_data);
}
// 通过SASS平台验证
_sassVerifySuccessHandler(_data) {
loger.log('加入底层MCU会议.');
if(_mcu){
_mcu.joinMCU(GlobalConfig.getConfInfo());
}
}
//获取会议所有参数
_h5SassGetMeetingParaSuccessHandler(_data){
loger.log('获取getMeetingParam完成.');
GlobalConfig.meetingParam=_data;
loger.log(_data);
}
// MCU 会议成功
_joinClassSuccessHandler() {
loger.log('MCU 会议成功.');
if(_sass){
_sass.getClassDetail();//会议信息
_sass.getMeetingParam();//会议参数大全
}
if(_joinClassSuccessCallBackFun){
_joinClassSuccessCallBackFun();
}
}
// MCU 会议失败
_joinClassFailureHandler(_data){
loger.log("_joinClassFailureHandler",_data);
if(_joinClassFailureCallBackFun){
_joinClassFailureCallBackFun(_data);
}
}
// 参会处理
conferenceHandler(msg_type) {
var msg = {
type: msg_type,
data: null
};
this._emit(msg.type, 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);
}
}
}