#include "justtalktest.h" #include "gotyecpp/gotyemsg.h" #include #include "StandardPaths.h" #include #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 = "<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]); } }