justtalktest.cpp
14.8 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
#include "justtalktest.h"
#include "../JusCall/JusCallPch.h"
#include "gotyecpp/gotyemsg.h"
#include <QDebug>
#include "StandardPaths.h"
#include <QMessageBox>
#include "Notification.h"
#include "JusDoodle/DoodleManager.h"
#define MIC_CONFIG_NAME "MyMic"
#define SPK_CONFIG_NAME "MySpk"
#define CAM_CONFIG_NAME "MyCam"
#include "iwebrequest.h"
#include "grape/zmf.h"
#include "avatar/zos/zos_type.h"
#include "lemon/service/rcs/mtc_cli.h"
#include "lemon/service/rcs/mtc_call.h"
#include "lemon/service/rcs/mtc_cli_cfg.h"
#include "lemon/service/rcs/mtc_cli_cb.h"
#include "lemon/service/rcs/mtc_ue.h"
#include "lemon/service/rcs/mtc_ue_db.h"
#include "lemon/service/rcs/mtc_user.h"
#include "lemon/service/rcs/mtc_prof.h"
#include "lemon/service/rcs/mtc_prov_db.h"
#include "lemon/service/rcs/mtc_media.h"
#include "lemon/service/rcs/mtc_mdm.h"
#include "lemon/service/rcs/mtc_call_db.h"
#include "GlobalSetting.h"
#define MY_PROF_DIR (StandardPaths::getProfilePath().toUtf8().data())
#define MY_LOG_DIR (StandardPaths::getLogPath().toUtf8().data())
#define MY_APP_KEY "9a56b858a19f192c6cf65097"
//#define MY_APP_KEY "6c06d1b0d9015e47ec144097"
extern "C" {
static ZINT MyProcServiceEvent(ZCONST ZCHAR * pcName, ZCOOKIE zCookie, ZCONST ZCHAR * pcInfo)
{
Notification info = Notification::parse(pcInfo);
((MainApp *)qApp)->notifyServiceEvent(pcName, zCookie, info);
return ZOK;
}
static void MyProcAudioEvent(int iEvnetType, const char* json, int)
{
Notification info = Notification::parse(json);
((MainApp *)qApp)->notifyAudioEvent(iEvnetType, info);
}
static void MyProcVideoEvent(int iEvnetType, const char* json, int)
{
Notification info = Notification::parse(json);
((MainApp *)qApp)->notifyVideoEvent(iEvnetType, info);
}
}
JustTalkTest::JustTalkTest(QWidget* parent):QWidget(parent), _doodleSessId(0)
{
connect((MainApp *)qApp, SIGNAL(serviceEvent(const QString &, size_t, const Notification &)),
SLOT(onServiceEvent(const QString &, size_t, const Notification &)));
connect(this, SIGNAL(closeClient()), SLOT(onCloseClient()), Qt::QueuedConnection);
IWebRequest *webrequest = IWebRequest::Instance();
connect(webrequest, SIGNAL(response(int,int,QString,QString)), this, SLOT(doResponse(int,int,QString,QString)));
// init audio and video interfaces
Zmf_AudioInitialize((void *)winId());
Zmf_VideoInitialize((void *)winId());
// init service SDK
Mtc_CliCfgSetLogDir(MY_LOG_DIR);
Mtc_CliInit(MY_PROF_DIR, NULL);
// set notification process
Mtc_CliCbSetNotify(MyProcServiceEvent);
// set AppKey
Mtc_CliApplyAppKey(MY_APP_KEY);
GotyeMsg::Instance()->init();
// init call manager
RCallManager::Instance()->init();
connect(RCallManager::Instance(), SIGNAL(CallIncoming(const QString,const QString)), SIGNAL(CallIncoming(const QString,const QString)));
connect(RCallManager::Instance(), SIGNAL(CallOutgoing(QString)), SIGNAL(CallOutgoing(QString)));
// init doodle manager
JusDoodle::DoodleManager::Instance()->init();
connect(JusDoodle::DoodleManager::Instance(), SIGNAL(sessCreated(int)),
SIGNAL(CallUiShow(int)));
// add server
servers << "sudp:dev.ae.justalkcloud.com:9851" << "sudp:ae.justalkcloud.com:9851";
onBitrateChanged(2);
// add bitrate
if (Mtc_MdmAnGetBitrateMode() == EN_MTC_AN_HIGH)
qDebug("高Bitrate");
else if (Mtc_MdmAnGetBitrateMode() == EN_MTC_AN_LOW)
qDebug("低Bitrate");
else
qDebug("中Bitrate");
onNackChanged(2);
// add nack modes
ZUINT iHighRtt;
Mtc_CallDbGetVideoNackRttRange(ZNULL, &iHighRtt);
if (iHighRtt >= 800)
qDebug() << QString::fromLocal8Bit("高质量");
else if (iHighRtt >= 500)
qDebug("中质量");
else
qDebug("低质量");
QStringList names;
QStringList ids;
char acName[512];
char acId[512];
int i;
int count;
// add micphone
count = Zmf_AudioInputGetCount();
for (i = 0, names.clear(), ids.clear(); i< count; i++)
{
Zmf_AudioInputGetName(i, acId, acName);
names << QString::fromUtf8(acName);
ids << QString::fromUtf8(acId);
QString value = _GlobalSetting.readConfigValue(MIC_CONFIG_NAME);
if (value.contains(QString::fromUtf8(acId)))
{
RCallManager::Instance()->setMicphone(QString::fromUtf8(acId));
}
}
// add speaker
QString speakerName = QString("");
count = Zmf_AudioOutputGetCount();
for (i = 0, names.clear(), ids.clear(); i< count; i++)
{
Zmf_AudioOutputGetName(i, acId, acName);
speakerName.sprintf(acName);
names << QString::fromUtf8(acName);
ids << QString::fromUtf8(acId);
}
RCallManager::Instance()->setSpeaker(ids.at(0));
// add camera
count = Zmf_VideoCaptureGetCount();
for (i = 0, names.clear(), ids.clear(); i< count; i++)
{
Zmf_VideoCaptureGetName(i, acId, acName);
names << QString::fromUtf8(acName);
ids << QString::fromUtf8(acId);
QString value = _GlobalSetting.readConfigValue(CAM_CONFIG_NAME);
if (value.contains(QString::fromUtf8(acId)))
{
RCallManager::Instance()->setCamera(QString::fromUtf8(acId));
}
}
//connect(ui->startDoodleButton, SIGNAL(clicked()), this, SLOT(on_startDoodleButton_clicked()));
}
void JustTalkTest::loginAuth()
{
qDebug() << "_GlobalSetting.sigAuth.sig:" <<_GlobalSetting.sigAuth.sig ;
Mtc_UePromptAuthCode(_GlobalSetting.sigAuth.sig.toLocal8Bit().data());
}
void JustTalkTest::doResponse(int cmd,int errorId,QString,QString)
{
switch(cmd)
{
case REQ_LOGIN:
{
on_loginButton_clicked();
}
break;
case REQ_GETJUSIG:
{
// if(!GotyeMsg::Instance()->isLogin)
// GotyeMsg::Instance()->login(QString("%1").arg(_GlobalSetting.userInfo.uid));
loginAuth();
break;
}
case REQ_USER_ONLINE:
{
// loginAuth();
// on_loginButton_clicked();
break;
}
case REQ_USER_OFFLINE:
{
// GotyeMsg::Instance()->logout();
// Mtc_CliLogout();
// on_loginButtonOut_clicked();
break;
}
case REQ_LOGOUT:
{
GotyeMsg::Instance()->logout();
Mtc_CliLogout();
qApp->exit(773);
break;
}
default:
break;
}
}
JustTalkTest::~JustTalkTest()
{
Mtc_CliDestroy();
Zmf_AudioTerminate();
Zmf_VideoTerminate();
}
void JustTalkTest::onServiceEvent(const QString &name, size_t, const Notification &_info)
{
Notification info = (Notification &)_info;
unsigned int iCallId = (unsigned int)info.getIntValue(MtcCallIdKey);
qDebug() << "void JustTalkTest::onServiceEvent" << name << info.toJson();
if (name == MtcUeAuthorizationRequireNotification)
{
QString nonce = info.getStringValue(MtcUeAuthNonceKey);
QString uri = info.getStringValue(MtcUeUriKey);
QStringList params;
params << nonce;
params << uri;
IWebRequest::Instance()->sendRequestToServer(REQ_GETJUSIG, params);
}
else if (name == MtcCallIncomingNotification)
{
int course_id = 0;
QJsonDocument myjsonDoc1 = QJsonDocument::fromJson(info.getStringValue(MtcCallUserDataKey).toLatin1());
QString img = myjsonDoc1.object().find("avatar_s").value().toString();
QString name = QString::fromLatin1(Mtc_CallGetPeerDisplayName(iCallId));
QString uid = QString::fromLatin1(Mtc_CallGetPeerName(iCallId));
// qDebug()<<"Uid = "<<uid.remove(0,2)<<"\n";
if(myjsonDoc1.object().find("course_id").value().isDouble())
course_id = (int)myjsonDoc1.object().find("course_id").value().toDouble();
else if(myjsonDoc1.object().find("course_id").value().isString())
{
course_id = (int)myjsonDoc1.object().find("course_id").value().toString().toInt();
}
if (RCallManager::Instance()->m_pRSession && (RCallManager::Instance()->m_pRSession->sessId() != iCallId))
{
// only support one session now
Mtc_CallTerm(iCallId, EN_MTC_CALL_TERM_STATUS_BUSY, ZNULL);
}
else
emit CallIncoming(uid.remove(0,2),img,course_id);
}
else if (name == MtcUeAuthorizationExpiredNotification)
{
Mtc_UeRefreshAuth();
}
else if (name == MtcUeCreateOkNotification)
{
if (Mtc_CliLogin(MTC_LOGIN_OPTION_PREEMPTIVE, "") != ZOK)
{
emit justMessage(JustTalkFail1);
emit this->closeClient();
}
}
else if (name == MtcUeCreateDidFaillNotification)
{
if (info.getIntValue(MtcUeReasonKey) != EN_MTC_UE_REASON_ACCOUNT_EXIST
|| Mtc_CliLogin(MTC_LOGIN_OPTION_PREEMPTIVE, "") != ZOK)
{
emit justMessage(JustTalkFail2);
emit this->closeClient();
}
}
else if (name == MtcCliServerLoginOkNotification)
{
emit justMessage(JustTalkSuccess);
}
else if (name == MtcCliServerLoginDidFailNotification)
{
emit justMessage(JustTalkFail3);
emit this->closeClient();
}
else if (name == MtcCliServerDidLogoutNotification)
{
// emit justMessage(JustTalkFail4);
emit this->closeClient();
}
else if (name == MtcCliServerLogoutedNotification)
{
emit justLogouted(2);
emit this->closeClient();
}
else if (name == MtcCallVideoReceiveStatusChangedNotification)
{
int videoType = info.getIntValue(MtcCallVideoStatusKey);
if(videoType == EN_MTC_CALL_TRANSMISSION_NORMAL)
emit videoReceive(true);
else if(videoType == EN_MTC_CALL_TRANSMISSION_CAMOFF)
emit videoReceive(false);
}
else if (name == MtcCallNetworkStatusChangedNotification)
{
// qDebug() << "void RCallManager::onServiceEvent" << name << info.toJson();
// qDebug("CMQ networkNum = %d",info.getIntValue(MtcCallNetworkStatusKey)+3);
emit CallNetStrength(info.getIntValue(MtcCallNetworkStatusKey)+3);
}
}
void JustTalkTest::onCloseClient()
{
Mtc_CliStop();
Mtc_CliClose();
}
void JustTalkTest::onBitrateChanged(int currentIndex)
{
if (currentIndex == 2)
Mtc_MdmAnSetBitrateMode(EN_MTC_AN_HIGH);
else if (currentIndex == 1)
Mtc_MdmAnSetBitrateMode(EN_MTC_AN_MID);
else
Mtc_MdmAnSetBitrateMode(EN_MTC_AN_LOW);
}
void JustTalkTest::onNackChanged(int currentIndex)
{
if (currentIndex == 2)
Mtc_CallDbSetVideoNackRttRange(100, 800);
else if (currentIndex == 1)
Mtc_CallDbSetVideoNackRttRange(100, 500);
else
Mtc_CallDbSetVideoNackRttRange(100, 300);
}
void JustTalkTest::onMicphoneChanged(int currentIndex)
{
if (currentIndex != -1)
{
// QString id = ui->micphoneBox->itemData(currentIndex).toString();
// RCallManager::Instance()->setMicphone(id);
// Mtc_ProvDbSetExtnParm((char *)MIC_CONFIG_NAME, id.toUtf8().data());
}
}
void JustTalkTest::onSpeakerChanged(int currentIndex)
{
if (currentIndex != -1)
{
// QString id = ui->speakerBox->itemData(currentIndex).toString();
// RCallManager::Instance()->setSpeaker(id);
// Mtc_ProvDbSetExtnParm((char *)SPK_CONFIG_NAME, id.toUtf8().data());
}
}
void JustTalkTest::onCameraChanged(int currentIndex)
{
if (currentIndex != -1)
{
// QString id = ui->cameraBox->itemData(currentIndex).toString();
// RCallManager::Instance()->setSpeaker(id);
// Mtc_ProvDbSetExtnParm((char *)CAM_CONFIG_NAME, id.toUtf8().data());
}
}
void JustTalkTest::on_loginButtonOut_clicked()
{
if (Mtc_CliLogout() != ZOK)
{
QMessageBox message(QMessageBox::Warning, "Information", "Logout failed.", QMessageBox::Ok, NULL);
message.exec();
onCloseClient();
}
qDebug("CMQ on_loginButtonOut_clicked Mtc_CliLogout...1\n");
}
void JustTalkTest::on_loginButton_clicked()
{
//GotyeMsg::Instance()->sendMessage("6", "Hello屈威");
QString username = QString("t_%1").arg(_GlobalSetting.userInfo.uid);
QString password = "123456";
// init audio and video interfaces
int ret = Zmf_AudioInitialize((HWND)winId());
ret = Zmf_VideoInitialize((HWND)winId());
qDebug() << "Userid:" << username;
// open profile
if (Mtc_CliOpen(username.toUtf8().data()) != ZOK)
{
QMessageBox message(QMessageBox::Warning, "Information", "Open failed.", QMessageBox::Ok, NULL);
message.exec();
Mtc_CliDestroy();
Zmf_AudioTerminate();
Zmf_VideoTerminate();
return;
}
// set profile
Mtc_UeDbSetIdType(EN_MTC_USER_ID_USERNAME);
Mtc_UeDbSetUserName(username.toUtf8().data());
Mtc_UeDbSetPassword(password.toUtf8().data());
Mtc_UeDbSetServer(servers.at(0).toUtf8().data()); //测试环境
// Mtc_UeDbSetServer(servers.at(1).toUtf8().data()); //正式环境
// save provision file
Mtc_ProfSaveProvision();
// start client
if (Mtc_CliStart() != ZOK)
{
QMessageBox message(QMessageBox::Warning, "Information", "Start failed.", QMessageBox::Ok, NULL);
message.exec();
Mtc_CliDestroy();
Zmf_AudioTerminate();
Zmf_VideoTerminate();
return;
}
// create user
if (Mtc_UeCreate(0, username.toUtf8().data(),
password.toUtf8().data()) != ZOK)
{
QMessageBox message(QMessageBox::Warning, "Information", "Login failed.", QMessageBox::Ok, NULL);
message.exec();
Mtc_CliDestroy();
Zmf_AudioTerminate();
Zmf_VideoTerminate();
return;
}
qDebug() << "Userid:log in";
}
void JustTalkTest::on_voiceCallButton_clicked()
{
RCallManager::Instance()->startSess("100", false);
}
void JustTalkTest::on_videoCallButton_clicked()
{
RCallManager::Instance()->startSess("100", true);
}
void JustTalkTest::on_startDoodleButton_clicked()
{
JusDoodle::DoodleManager::Instance()->startSess(RCallManager::Instance()->getSessId(), 10);
}
void JustTalkTest::onSessCreated(int sessId)
{
QStringList imagePaths = QStringList();
imagePaths << "./images/background_0.png";
imagePaths << "./images/background_1.png";
imagePaths << "./images/background_2.png";
imagePaths << "./images/background_3.png";
imagePaths << "./images/background_4.png";
imagePaths << "./images/background_5.png";
imagePaths << "./images/background_6.png";
imagePaths << "./images/background_7.png";
imagePaths << "./images/background_8.png";
JusDoodle::DoodleManager::Instance()->setBackgroundImages(sessId, imagePaths);
}
void JustTalkTest::initDeivce(const QStringList &names, const QStringList &ids,
const char *configName)
{
QString value = _GlobalSetting.readConfigValue(CAM_CONFIG_NAME);
if(!ids.contains(value))
{
_GlobalSetting.writeConfigValue(configName, ids[0]);
}
}