-
Notifications
You must be signed in to change notification settings - Fork 243
/
eventcenter.cpp
executable file
·486 lines (423 loc) · 13.6 KB
/
eventcenter.cpp
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
#include "eventcenter.h"
#include "login/UserLoginWdg.h"
#include "Room/RoomWdg.h"
#include "Video/VideoWin.h"
#include "Video/VideoMgr.h"
#include "Video/VideoMonitorMgr.h"
#include "VideoMonitor/videomonitormain.h"
#include "Room/LeftWdg.h"
#include "Room/WdgNetInfo.h"
#include <QDebug>
#include <QMessageBox>
#include <QProcess>
IMeetingFrame* g_pMeetingFrame = NULL;
IZYMediaStreamManager *g_pStreamMgr = NULL;
EventCenter*EventCenter::m_instahce = NULL;
EventCenter* EventCenter::GetInstance()
{
return m_instahce;
}
EventCenter::EventCenter(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags)
{
m_instahce = this;
m_bInRoom = false;
m_roomId = 0;
//setWindowFlags(Qt::FramelessWindowHint);//这个是widget的标题栏和边框去掉
//setAttribute(Qt::WA_TranslucentBackground);
this->hide();
//RoomWdg::GetInstance()->CenterWindow();
//RoomWdg::GetInstance()->showMaximized();
UserLoginWdg::GetInstance()->show();
//初始化视频会议框架
CreateMeetingFrame(&g_pMeetingFrame,this,(HWND)RoomWdg::GetInstance()->winId(),
this,AppSetting::GetInstance()->GetServerAddress().toStdString());
connect(this,SIGNAL(EventLoginSuccess()),this,SLOT(On_UI_LoginSuccess()));
connect(this,SIGNAL(EventLoginFailed()),UserLoginWdg::GetInstance(),SLOT(OnLoginFailed()));
connect(this,SIGNAL(EventAddUser()),LeftWdg::GetInstance(),SLOT(OnAddUser()));
connect(this,SIGNAL(EventDelUser()),LeftWdg::GetInstance(),SLOT(OnDelUser()));
connect(this,SIGNAL(EventGetRoomList(int)),UserLoginWdg::GetInstance(),SLOT(OnGetRoomList(int)));
connect(this,SIGNAL(EventUpdateUI()),this,SLOT(OnUpdateUI()));
connect(this,SIGNAL(EventSetSpeaker(bool)),this,SLOT(OnSetSpeaker(bool)));
connect(this,SIGNAL(EventSpeakModeChange(int)),this,SLOT(OnSpeakModeChange(int)));
connect(this,SIGNAL(EventRoomModeChange(int)),this,SLOT(OnRoomModeChange(int)));
connect(this,SIGNAL(EventOnStreamNetInfo(int,int,int)),WdgNetInfo::GetInstance(),SLOT(OnNetInfo(int,int,int)));
connect(this,SIGNAL(EventOnStreamNetInfo(int,int,int)),RoomWdg::GetInstance(),SLOT(OnNetInfo(int,int,int)));
// sean add 收到消息后发送信号
connect(this,SIGNAL(getMessageEvent(unsigned long long ,QString*,
int ,unsigned long ,unsigned long ,QString *)),LeftWdg::GetInstance(),SLOT(getMessageFromOthers(unsigned long long ,QString*, int ,unsigned long ,unsigned long ,QString *)));
connect(this,SIGNAL(EventUserOffline(unsigned long long)),this,SLOT(OnUserOffline(unsigned long long )));
connect(this,SIGNAL(EventRecvRemoteVideo(unsigned long long)),
this,SLOT(OnRecvRemoteVideo(unsigned long long)));
connect(this,SIGNAL(EventSetAsBigVideo(unsigned long long)),
this,SLOT(OnSetAsBigVideo(unsigned long long)));
connect(this,SIGNAL(EventEnterRoom(unsigned int)),this,SLOT(OnEnterRoom(unsigned int)));
//打开文档
connect(this,SIGNAL(EventOpenDoc(QString,int,int)),RoomWdg::GetInstance(),
SLOT(OnOpenDoc(QString,int,int)));
//关闭文档
connect(this,SIGNAL(EventCloseDoc()),RoomWdg::GetInstance(),SLOT(OnCloseDoc()));
//共享光标
connect(this,SIGNAL(EventShowRemoteCursor(float,float)),RoomWdg::GetInstance(),
SLOT(OnShowRemoteCursor(float,float)));
//关闭光标
connect(this,SIGNAL(EventCloseRemoteCursor()),RoomWdg::GetInstance(),SLOT(OnCloseRemoteCursor()));
connect(this,SIGNAL(EventOnStartVideoMonitor()),this,SLOT(On_UI_StartVideoMonitor()));
connect(this,SIGNAL(EventOnStopVideoMonitor()),this,SLOT(On_UI_StopVideoMonitor()));
connect(this,SIGNAL(EventRecvVideoSSRC(unsigned long long ,unsigned int)),
this,SLOT(On_UI_RecvVideoSSRC(unsigned long long ,unsigned int)));
connect(this,SIGNAL(EventUpdateSoft(QString)),this,SLOT(On_UI_UpdateSoft(QString)));
connect(this,SIGNAL(EventNetEvent(unsigned int)),this,SLOT(On_UI_NetEvent(unsigned int)));
//掉线重连定时器
m_reConnectTimer = new QTimer(this);
m_reConnectTimer->setInterval(1000*3);
connect(m_reConnectTimer, SIGNAL(timeout()), this,SLOT(OnReConnectTimer()));
}
EventCenter::~EventCenter()
{
}
bool EventCenter::winEvent (MSG* msg, long *result)
{
switch(msg->message)
{
case WM_CREATE:
break;
}
return FALSE;
}
void EventCenter::OnEnterRoom(unsigned int result)
{
//进入房间成功
if(result == 0)
{
UserLoginWdg::GetInstance()->setHidden(true);
MeetingListWdg::GetTableViewInstance()->hide();
}
else
{
UserLoginWdg::GetInstance()->setHidden(false);
MeetingListWdg::GetTableViewInstance()->hide();
RoomWdg::GetInstance()->setHidden(true);
QMessageBox::information(NULL,"提示","用户达到房间最大数");
}
}
void EventCenter::On_MeetingEvent_ShareCursor(float x,float y)
{
emit EventShowRemoteCursor(x,y);
}
void EventCenter::On_MeetingEvent_StopShareCursor()
{
qDebug()<<"On_MeetingEvent_StopShareCursor()";
emit EventCloseRemoteCursor();
}
void EventCenter::On_MeetingEvent_EnterRoom_Result(uint32_t status,char *msg)
{
emit EventEnterRoom(status);
emit EventAddUser();
m_bInRoom = true;
if(g_pMeetingFrame!=NULL)
{
ROOM_INFO roomInfo;
if(g_pMeetingFrame->GetCurrentRoomInfo(&roomInfo))
{
if(roomInfo.speakMode == 1)
{
g_pMeetingFrame->StartPublishAudio(0,AppSetting::GetInstance()->GetMicIndex()-1);
}
}
}
}
//返回用户登录结果
void EventCenter::On_MeetingEvent_Login_Result(uint32_t status,char *msg)
{
qDebug()<<status<<msg;
if(status == 0)
{
emit EventLoginSuccess();
}
else
{
emit EventLoginFailed();
}
}
//用户上线
void EventCenter::On_MeetingEvent_Member_Online(uint64_t ulUserID,char*strUserName,
uint32_t userType,uint32_t userRoomType)
{
qDebug()<<"user online"<<QString::fromUtf8(strUserName)<<ulUserID;
emit EventAddUser();
emit EventUpdateUI();
}
//用户下线
void EventCenter::On_MeetingEvent_Member_Offline(uint64_t ulUserID)
{
emit EventUserOffline(ulUserID);
emit EventDelUser();
}
void EventCenter::OnUserOffline(unsigned long long sessionID)
{
if(g_pMeetingFrame)
{
VideoMgr::GetInstance()->GivebackVideo(sessionID);
VideoMonitorMain::GetInstance()->RemoveVideo(sessionID);
}
emit EventUpdateUI();
}
void EventCenter::On_MeetingEvent_UpdateSoft(std::string url)
{
emit EventUpdateSoft(QString(url.data()));
}
void EventCenter::On_UI_UpdateSoft(QString url)
{
QString strTip;
if(url.isEmpty())
return;
strTip = QString("软件现在的版本号是:%1,与服务器版本号不一致,请点击确定按钮自动更新,或者手动下载,下载地址:%2").
arg(g_pMeetingFrame->GetVersion()).arg(url);
QMessageBox::StandardButton rb = QMessageBox::warning(NULL,"升级提示",strTip,
QMessageBox::Cancel|QMessageBox::Ok);
if(rb == QMessageBox::Ok){
//启动更新软件进程
QProcess *pProcess = new QProcess(this);
QStringList argList;
argList.append(url);
pProcess->startDetached("AutoUpdate.exe",argList);
g_pMeetingFrame->Release();
QApplication::quit();
}
}
void EventCenter::On_MeetingEvent_GetRoomList(uint32_t total)
{
//qDebug()<<"On_MeetingEvent_GetRoomList";
emit EventGetRoomList(total);
}
//收到文本聊天消息
void EventCenter::On_MeetingEvent_Text_Msg(uint64_t ulUserID,char*strMsg,
int font_size,unsigned long fontFlat,unsigned long color,char *familly)
{
qDebug()<<"On_MeetingEvent_Text_Msg == \n"<<strMsg;
QString *str = new QString(strMsg);
QString *familyStr = new QString(familly);
emit getMessageEvent(ulUserID,str,font_size,fontFlat,color,familyStr);
}
void EventCenter::On_MeetingEvent_OpenDoc(std::string strUrl,int index,int total)
{
qDebug()<<"open url:"<<strUrl.data()<<"index:"<<index<<" total:"<<total;
emit EventOpenDoc(QString(strUrl.data()),index,total);
}
//关闭文档共享
void EventCenter:: On_MeetingEvent_CloseDoc()
{
emit EventCloseDoc();
}
//通知界面层被设置成发言人
void EventCenter::On_MeetingEvent_SetAsSpeaker(uint64_t ulUserID,bool bSet)
{
//emit EventSetSpeaker(bSet);
if(bSet)
{
g_pMeetingFrame->StartPublishAudio(0,AppSetting::GetInstance()->GetMicIndex()-1);
}
else
{
g_pMeetingFrame->StopPublishAudio(0);
}
}
void EventCenter::OnSetSpeaker(bool bSet)
{
if(bSet)
{
g_pMeetingFrame->StartPublishAudio(0,AppSetting::GetInstance()->GetMicIndex()-1);
}
else
{
g_pMeetingFrame->StopPublishAudio(0);
}
}
//通知界面层被设置成为主讲
void EventCenter::On_MeetingEvent_SetAsShower(uint64_t ulUserID,bool bSet)
{
}
//通知界面层被设置成为管理员
void EventCenter::On_MeetingEvent_SetAsAdmin(uint64_t ulUserID,bool bSet)
{
}
//通知主讲人或者管理员,有普通用户申请了发言
void EventCenter::On_MeetingEvent_ApplySpeaker(uint64_t fromUserID)
{
}
//通知界面层用户取消了发言请求
void EventCenter::On_MeetingEvent_CancelApplySpeaker(uint64_t fromUserID)
{
}
//通知界面层,用户角色改变了
void EventCenter::On_MeetingEvent_UserRole_Change(uint64_t ulUserID,int role)
{
}
//通知界面接收视频
void EventCenter::On_MeetingEvent_RecvMyVideo(uint64_t sessionID,uint32_t channelID)
{
qDebug()<<"RecvMyVideo:"<<sessionID<<":"<<channelID;
qDebug()<<"******************OnRecvRemoteVideo1111111111111111111*************";
emit EventRecvRemoteVideo(sessionID);
}
//发言模式有了变化
void EventCenter::On_MeetingEvent_SpeakMode_Change(int mode)
{
emit EventSpeakModeChange(mode);
}
//发言模式有了变化
void EventCenter::On_MeetingEvent_RoomMode_Change(int mode)
{
emit EventRoomModeChange(mode);
}
void EventCenter::OnRoomModeChange(int mode)
{
qDebug()<<"OnRoomModeChange"<<mode;
RoomWdg::GetInstance()->OnRoomModeChange(mode);
VideoMgr::GetInstance()->OnRoomModeChange(mode);
}
void EventCenter::OnSpeakModeChange(int mode)
{
if(mode == 1)
{
//如果用户还没有开始语音,帮他打开语音
if(g_pMeetingFrame->HasStartAudio() == false)
g_pMeetingFrame->StartPublishAudio(0,AppSetting::GetInstance()->GetMicIndex()-1);
}
else
{
//如果用户已经打开语音,帮他关掉
if(g_pMeetingFrame->HasStartAudio() == true)
g_pMeetingFrame->StopPublishAudio(0);
}
OnUpdateUI();
}
void EventCenter::On_MeetingEvent_CloseMyVideo(uint64_t sessionID,uint32_t channelID)
{
if(g_pMeetingFrame)
{
VideoMgr::GetInstance()->GivebackVideo(sessionID);
g_pMeetingFrame->StopRecvRemoteVideo(sessionID);
emit EventUpdateUI();
}
}
// 网络状态;
void EventCenter::OnNetEvent(uint32_t code,const char* msg)
{
qDebug()<<"OnNetEvent"<<code<<" msg:"<<msg;
emit EventNetEvent(code);
}
void EventCenter::On_UI_NetEvent(unsigned int code){
switch(code){
case NET_EVENT_CONNECT_SUCCESS:
qDebug()<<"连接服务器成功";
if(m_reConnectTimer!=NULL&m_reConnectTimer->isActive())
m_reConnectTimer->stop();
break;
case NET_EVENT_LOST_CONNECTION:
qDebug()<<"和服务器断开连接了";
if(g_pMeetingFrame)
g_pMeetingFrame->StopAllMediaStream();
VideoMgr::GetInstance()->FreeAll();
if(m_reConnectTimer)
m_reConnectTimer->start();
break;
case NET_EVENT_TIME_OUT:
//QMessageBox::warning(NULL,"提示","连接服务器超时");
break;
}
}
//掉线重新连接
void EventCenter::OnReConnectTimer(){
if(g_pMeetingFrame)
g_pMeetingFrame->ReConnect();
}
void EventCenter::OnRecvRemoteVideo(unsigned long long sessionID)
{
if(g_pMeetingFrame!=NULL)
{
IVideoWin * videoWin = VideoMgr::GetInstance()->GetFreeVideo();
qDebug()<<"******************OnRecvRemoteVideo22222222*************";
if(videoWin == NULL)
{
MessageBox(NULL,L"视频位置已占满",NULL,NULL);
return;
}
videoWin->SetUserID(sessionID);
g_pMeetingFrame->StartRecvRemoteVideo(sessionID,0,videoWin);
}
}
void EventCenter::On_MeetingEvent_UpdateUI()
{
emit EventUpdateUI();
}
void EventCenter::OnUpdateUI()
{
LeftWdg::GetInstance()->UpdateUI();
RoomWdg::GetInstance()->UpdateUI();
VideoMgr::GetInstance()->UpdateUI();
}
void EventCenter::StreamEvent_OnNetInfo(int delay,int uploadLost,int downloadLost)
{
emit EventOnStreamNetInfo(delay,uploadLost,downloadLost);
}
//声音的大小,bCapture是否为采集声音,ulSSRC编号,value 能量值
void EventCenter::StreamEvent_AudioEnergy(bool bCapture,uint32_t ulSSRC,int16_t value)
{
LeftWdg::GetInstance()->SetAudioValue(ulSSRC,value);
//emit EventUpdateUI();
//qDebug()<<"StreamEvent_AudioEnergy Value: "<<value;
}
//得到第一个关键帧,视频开始可以显示出来
void EventCenter::StreamEvent_GetFirstKeyFrame(uint32_t ulSSRC)
{
//qDebug()<<"Get First Key Video Frame";
}
void EventCenter::On_MeetingEvent_SetAsBigVideo(uint64_t sessionID)
{
emit EventSetAsBigVideo(sessionID);
}
void EventCenter::OnSetAsBigVideo(unsigned long long sessionID)
{
if(sessionID == g_pMeetingFrame->GetMySessionID())
VideoMgr::GetInstance()->SetBigVideo(0);
else
VideoMgr::GetInstance()->SetBigVideo(sessionID);
}
void EventCenter::On_MeetingEvent_StartVideoMonitor(){
emit EventOnStartVideoMonitor();
}
void EventCenter::On_MeetingEvent_StopVideoMonitor(){
emit EventOnStopVideoMonitor();
}
//暂停发送视频
void EventCenter::On_MeetingEvent_PauseVideo(){
}
//恢复发送视频
void EventCenter::On_MeetingEvent_ResumeVideo(){
}
void EventCenter::On_MeetingEvent_RecvUserVideoSSRC(uint32_t ssrc,uint64_t sessionId,char* userName){
emit EventRecvVideoSSRC((unsigned long long)sessionId,(unsigned int)ssrc);
}
void EventCenter::On_UI_StartVideoMonitor(){
RoomWdg::GetInstance()->OnStartVideoMonitor();
}
void EventCenter::On_UI_StopVideoMonitor(){
RoomWdg::GetInstance()->OnStopVideoMonitor();
}
void EventCenter::On_UI_RecvVideoSSRC(unsigned long long sessionID,unsigned int ssrc){
qDebug()<<"recv ssrc:"<<ssrc<<"session id:"<<sessionID;
if(g_pMeetingFrame->GetUserRole(0)==1)
VideoMonitorMain::GetInstance()->AddVideo(sessionID,ssrc);
}
void EventCenter::On_UI_LoginSuccess(){
if(m_bInRoom == false){
UserLoginWdg::GetInstance()->OnLoginSuccess();
}else{
//重新连接成功处理
if(m_roomId!=0){
g_pMeetingFrame->EnterRoom(m_roomId);
}
}
}