callLogic.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. #pragma once
  2. #include "uart/ProtocolSender.h"
  3. #include <string>
  4. #include "core/utilities.h"
  5. #include "voip/telephone.h"
  6. #include "base/strings.hpp"
  7. #include "storage/StoragePreferences.h"
  8. #include "core/sip_config.h"
  9. #include "zkaudio.h"
  10. #include "service/BusinessConfig.h"
  11. #include "net/tcp_client.h"
  12. #include "net/tcp_util.h"
  13. #include "manager/ConfigManager.h"
  14. #include "voip/media_player.h"
  15. #include "manager/LanguageManager.h"
  16. std::string _isOutgoing;
  17. std::string _toIdStr;
  18. //voip::WAVPlayer wavPlayer; // 播放音频
  19. std::string tid;
  20. static base::MediaPlayer mediaPlayer;
  21. static bool _isSleepTimerRegistered = false;
  22. #define CALLING_TIME 60 // 用于控制呼叫时间,定时器
  23. const int goBack = 200;
  24. void callActivityFinish(CallFinishType type){
  25. switch (type){
  26. case CANCEL:
  27. LOGD("cancel");
  28. setSleepTimerRegistered(_isSleepTimerRegistered);
  29. EASYUICONTEXT->goBack();
  30. break;
  31. case REJECT:
  32. LOGD("reject");
  33. // wavPlayer.Stop();
  34. mediaPlayer.Stop();
  35. mTextViewNamePtr->setTextTr("RemoteRefuse");
  36. mActivityPtr->unregisterUserTimer(CALLING_TIME);
  37. mActivityPtr->registerUserTimer(goBack, 5000);
  38. break;
  39. case BUSY:
  40. LOGD("BUSY");
  41. // wavPlayer.Stop();
  42. mediaPlayer.Stop();
  43. mTextViewNamePtr->setTextTr("RemoteBusy");
  44. mActivityPtr->unregisterUserTimer(CALLING_TIME);
  45. mActivityPtr->registerUserTimer(goBack, 5000);
  46. break;
  47. case HANDOFF:
  48. LOGD("handoff");
  49. setSleepTimerRegistered(_isSleepTimerRegistered);
  50. EASYUICONTEXT->goBack();
  51. break;
  52. case FAILED:
  53. // wavPlayer.Stop();
  54. mediaPlayer.Stop();
  55. mTextViewNamePtr->setTextTr("CallFailed");
  56. mActivityPtr->registerUserTimer(goBack, 5000);
  57. break;
  58. case NOT_FOUND:
  59. {
  60. mTextViewNamePtr->setTextTr("NotFound");
  61. TcpModel storeModel = CallingStatus::instance()->getTcpModel();
  62. if (!storeModel.json.isNull() && storeModel.json > 0 && storeModel.json.isMember("id")) {
  63. sendVoiceCancel(storeModel.from_id);
  64. }
  65. else {
  66. sendVoiceCancel(0);
  67. }
  68. mActivityPtr->registerUserTimer(goBack, 5000);
  69. }
  70. break;
  71. case REQUEST_TIMES:
  72. {
  73. mTextViewNamePtr->setTextTr("RequestTimes");
  74. TcpModel storeModel = CallingStatus::instance()->getTcpModel();
  75. if (!storeModel.json.isNull() && storeModel.json > 0 && storeModel.json.isMember("id")) {
  76. sendVoiceCancel(storeModel.from_id);
  77. }
  78. else {
  79. sendVoiceCancel(0);
  80. }
  81. mActivityPtr->registerUserTimer(goBack, 5000);
  82. }
  83. break;
  84. case ACCEPT:
  85. mActivityPtr->unregisterUserTimer(CALLING_TIME);
  86. break;
  87. case A1CLICK:
  88. LOGD("a1 click");
  89. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "TCP"){
  90. TcpModel storeModel = CallingStatus::instance()->getTcpModel();
  91. //只回传iId
  92. storeModel.data = storeModel.json["id"].asString();
  93. voip::CallInfo info = GetTelephone()->GetCallInfo();
  94. LOGD("info state = %d",info.state);
  95. if (info.state == voip::STATE_CALL_CALLING
  96. || info.state == voip::STATE_CALL_CALLING
  97. || info.state == voip::STATE_CALL_CONFIRMED){
  98. sendVoiceTcp(VoiceAction::HANDOFF, storeModel, storeModel.from_id);
  99. GetTelephone()->Hangup(info.id, voip::SIP_STATUS_CODE_DECLINE);
  100. GetTelephone()->Hangup();
  101. setSleepTimerRegistered(_isSleepTimerRegistered);
  102. EASYUICONTEXT->goBack();
  103. } else if (_isOutgoing == "false"){ //state = 5
  104. mediaPlayer.Stop();
  105. mButtonAnswerPtr->setVisible(false);
  106. TcpModel model = CallingStatus::instance()->getTcpModel();
  107. model.data = model.json["id"].asString();
  108. sendVoiceTcp(VoiceAction::ACCEPT, model, model.from_id);
  109. mActivityPtr->unregisterUserTimer(CALLING_TIME);
  110. } else if (_isOutgoing == "true") {
  111. sendVoiceTcp(VoiceAction::CANCEL, storeModel, storeModel.from_id);
  112. setSleepTimerRegistered(_isSleepTimerRegistered);
  113. EASYUICONTEXT->goBack();
  114. }
  115. }
  116. break;
  117. case KEY6_CLICK:
  118. LOGD("KEY6 click");
  119. if (StoragePreferences::getString(STORE_SIGNAL_TYPE,"TCP")=="TCP"){
  120. TcpModel storeModel = CallingStatus::instance()->getTcpModel();
  121. //只回传iId
  122. storeModel.data = storeModel.json["id"].asString();
  123. voip::CallInfo info = GetTelephone()->GetCallInfo();
  124. LOGD("info state = %d",info.state);
  125. if (info.state == voip::STATE_CALL_CALLING
  126. || info.state == voip::STATE_CALL_CALLING
  127. || info.state == voip::STATE_CALL_CONFIRMED){
  128. sendVoiceTcp(VoiceAction::HANDOFF, storeModel, storeModel.from_id);
  129. GetTelephone()->Hangup(info.id, voip::SIP_STATUS_CODE_DECLINE);
  130. GetTelephone()->Hangup();
  131. setSleepTimerRegistered(_isSleepTimerRegistered);
  132. EASYUICONTEXT->goBack();
  133. // std::string heartStr = "DOORLED,000F";
  134. // const char* sendMsg = heartStr.c_str();
  135. // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  136. lightControl("DOORLED", "000F");
  137. } else if (_isOutgoing == "false"){ //state = 5
  138. mediaPlayer.Stop();
  139. mButtonAnswerPtr->setVisible(false);
  140. TcpModel model = CallingStatus::instance()->getTcpModel();
  141. model.data = model.json["id"].asString();
  142. sendVoiceTcp(VoiceAction::ACCEPT, model, model.from_id);
  143. mActivityPtr->unregisterUserTimer(CALLING_TIME);
  144. }
  145. }
  146. break;
  147. }
  148. }
  149. void buildSIP(std::string toSipId){
  150. // wavPlayer.Stop();
  151. mediaPlayer.Stop();
  152. int port = StoragePreferences::getInt(SIP_REG_PORT, SIP_REG_PORT_DEFAULT);
  153. std::string domain = StoragePreferences::getString(SIP_REG_DOMAIN, SIP_REG_DOMAIN_DEFAULT);
  154. //std::string od_number = StoragePreferences::getString(SIP_REG_DOOR_ACCOUNT, SIP_REG_DOOR_ACCOUNT_DEFAULT);
  155. std::string od_number_uri = URI(toSipId, domain, port);
  156. LOGD("xxxxxxxxxxxxxx %s",od_number_uri.c_str());
  157. GetTelephone()->MakeCall(od_number_uri);
  158. }
  159. void acceptSIP(){
  160. GetTelephone()->Answer();
  161. }
  162. //static ZKMediaPlayer sPlayer(ZKMediaPlayer::E_MEDIA_TYPE_AUDIO);
  163. namespace {
  164. const int kTimerAutoAnswer = 100;
  165. std::string StateString(voip::State state) {
  166. switch (state) {
  167. case voip::STATE_CALL_CALLING:
  168. case voip::STATE_CALL_EARLY:
  169. return LANGUAGEMANAGER->getValue("Calling");
  170. case voip::STATE_CALL_CONFIRMED:
  171. return LANGUAGEMANAGER->getValue("CallConfirmed");
  172. case voip::STATE_CALL_CONNECTING:
  173. return LANGUAGEMANAGER->getValue("CallConnecting");
  174. case voip::STATE_CALL_INCOMING:
  175. return LANGUAGEMANAGER->getValue("CallInComing");
  176. default:
  177. break;
  178. }
  179. return "";
  180. }
  181. } /* anonymous namespace */
  182. /**
  183. * 注册定时器
  184. * 填充数组用于注册定时器
  185. * 注意:id不能重复
  186. */
  187. static S_ACTIVITY_TIMEER REGISTER_ACTIVITY_TIMER_TAB[] = {
  188. //{0, 6000}, //定时器id=0, 时间间隔6秒
  189. {1, 1000},
  190. {kTimerAutoAnswer, 2000},
  191. };
  192. /**
  193. * 当界面构造时触发
  194. */
  195. static void onUI_init(){
  196. CallingStatus::instance()->setBusy(true);
  197. EASYUICONTEXT->hideStatusBar();
  198. EASYUICONTEXT->hideNaviBar();
  199. // GetTelephone()->SetInputPcmGainSize(10.0);
  200. // player = new ZKMediaPlayer(ZKMediaPlayer::E_MEDIA_TYPE_AUDIO);
  201. // player->play("/mnt/extsd/ui/hl.mp3");
  202. //界面操作
  203. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  204. voip::CallInfo info = GetTelephone()->GetCallInfo();
  205. mTextViewNamePtr->setText(info.remote_uri);
  206. if (info.state == voip::STATE_CALL_CALLING) {
  207. mButtonAnswerPtr->setVisible(false);
  208. }
  209. }
  210. // mSeekBarOutputVolumePtr->setMax(zk_audio_output_volume_native_max());
  211. bool isVolume = StoragePreferences::getBool(STORE_VOLUME, false);
  212. mSeekBarGainPtr->setVisible(isVolume);
  213. mTextViewGainPtr->setVisible(isVolume);
  214. mSeekBarInputPtr->setVisible(isVolume);
  215. mTextViewInputPtr->setVisible(isVolume);
  216. //打开时的声音大小
  217. int serverVol = StoragePreferences::getInt(STORE_DAY_VOL,PartSetting::dayBedVol);
  218. if (checkIsDay()){
  219. serverVol = StoragePreferences::getInt(STORE_NIGHT_VOL,PartSetting::nightBedVol);
  220. }
  221. double percent = (double)serverVol/(double)100;
  222. int vol = (int)(zk_audio_output_volume_native_max()*percent);
  223. LOGD("bed vol is %d. server is %d. max is %d",vol,serverVol, zk_audio_output_volume_native_max());
  224. zk_audio_output_set_volume_native(vol);
  225. mSeekBarOutputVolumePtr->setProgress(vol);
  226. mTextViewOutputVolumePtr->setTouchPass(true);
  227. mSeekBarGainPtr->setProgress(StoragePreferences::getInt(STORE_GAIN_SIZE, 2));
  228. mTextViewGainPtr->setTouchPass(true);
  229. mSeekBarInputPtr->setProgress(StoragePreferences::getInt(STORE_VOLUME_NATIVE, 6));
  230. mTextViewInputPtr->setTouchPass(true);
  231. // mTextViewNamePtr->setVisible(false);
  232. // mTextViewStatePtr->setVisible(false);
  233. // mTextViewDurationPtr->setVisible(false);
  234. }
  235. /**
  236. * 当切换到该界面时触发
  237. */
  238. static void onUI_intent(const Intent *intentPtr) {
  239. if(intentPtr != NULL) {
  240. BRIGHTNESSHELPER->screenOn();
  241. _isSleepTimerRegistered = getSleepTimerRegistered();
  242. setSleepTimerRegistered(false);
  243. // wavPlayer.Play(CONFIGMANAGER->getResFilePath("ring.wav"));
  244. // mediaPlayer.Play(CONFIGMANAGER->getResFilePath("ring.wav"));
  245. mediaPlayer.Play(CONFIGMANAGER->getResFilePath("ring.wav"), "", 1000,
  246. base::MediaPlayer::PlayMode::Loop);
  247. // 键值解析
  248. _isOutgoing = intentPtr->getExtra(isOutgoing);
  249. std::string _audioOnly = intentPtr->getExtra(audioOnly);
  250. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  251. return;
  252. }
  253. if (_isOutgoing == "true"){
  254. int toId = 0;
  255. _toIdStr = intentPtr->getExtra(toIdStr);
  256. if (_toIdStr != "") {
  257. toId = atoi(_toIdStr.c_str());
  258. }
  259. //TCP call
  260. TcpModel tcpModel;
  261. tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime());
  262. tcpModel.type = TcpType::VOICE;
  263. tcpModel.action = VoiceAction::CALL;
  264. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  265. tcpModel.to_id = toId;
  266. std::string req = getTcpModelString(tcpModel);
  267. LOGD("TCP CALL : %s",req.c_str());
  268. setCallTid(tcpModel.tid);
  269. //回调注册
  270. TcpCallback callback;
  271. callback.tid = tcpModel.tid;
  272. callback.jsonStr = req;
  273. callback.onSuccess = [](Json::Value json){
  274. LOGD("voice callback success");
  275. return 0;
  276. };
  277. callback.onFalied = [](Json::Value json){
  278. LOGD("voice callback failed");
  279. return 0;
  280. };
  281. TcpClient::instance()->sendMsgWithCb(req.c_str(), callback);
  282. // 呼叫的时候需要把tid放进去
  283. tid = tcpModel.tid;
  284. mButtonAnswerPtr->setVisible(false);
  285. std::string _callName = intentPtr->getExtra(callName);
  286. if (_callName != "") {
  287. mTextViewNamePtr->setText(LANGUAGEMANAGER->getValue("Call") + _callName);
  288. } else {
  289. mTextViewNamePtr->setTextTr("CallOutTitle");
  290. }
  291. mActivityPtr->registerUserTimer(CALLING_TIME, 60000); // 如果对方没接听,则发送一个CANCEL回去
  292. } else {
  293. TcpModel storeModel = CallingStatus::instance()->getTcpModel();
  294. TcpModel backTcp = storeModel;
  295. backTcp.data = storeModel.json["id"].asString();
  296. //back voice success
  297. sendVoiceTcp(VoiceAction::SUCCESS, backTcp, storeModel.from_id);
  298. mTextViewNamePtr->setText(storeModel.json["fromFrameName"].asString());
  299. //自动接听处理
  300. if (StoragePreferences::getBool(STORE_AUDO_ANSWER,false)){
  301. sleep(3);
  302. mediaPlayer.Stop();
  303. mButtonAnswerPtr->setVisible(false);
  304. GetTelephone()->Answer();
  305. //发出TCP
  306. sendVoiceTcp(VoiceAction::ACCEPT, storeModel, storeModel.from_id);
  307. }
  308. }
  309. }
  310. }
  311. /*
  312. * 当界面显示时触发
  313. */
  314. static void onUI_show() {
  315. EASYUICONTEXT->hideStatusBar();
  316. EASYUICONTEXT->hideNaviBar();
  317. }
  318. /*
  319. * 当界面隐藏时触发
  320. */
  321. static void onUI_hide() {
  322. }
  323. /*
  324. * 当界面完全退出时触发
  325. */
  326. static void onUI_quit() {
  327. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "TCP"){
  328. EASYUICONTEXT->showNaviBar();
  329. CallingStatus::instance()->setBusy(false);
  330. CallingStatus::instance()->clearTcpModel();
  331. voip::CallInfo info = GetTelephone()->GetCallInfo();
  332. if (info.state == voip::STATE_CALL_CALLING
  333. || info.state == voip::STATE_CALL_CALLING
  334. || info.state == voip::STATE_CALL_CONFIRMED){
  335. GetTelephone()->Hangup(info.id, voip::SIP_STATUS_CODE_DECLINE);
  336. GetTelephone()->Hangup();
  337. }
  338. }
  339. mediaPlayer.Stop();
  340. mActivityPtr->unregisterUserTimer(goBack);
  341. }
  342. /**
  343. * 串口数据回调接口
  344. */
  345. static void onProtocolDataUpdate(const SProtocolData &data) {
  346. }
  347. /**
  348. * 定时器触发函数
  349. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  350. * 参数: id
  351. * 当前所触发定时器的id,与注册时的id相同
  352. * 返回值: true
  353. * 继续运行当前定时器
  354. * false
  355. * 停止运行当前定时器
  356. */
  357. static bool onUI_Timer(int id){
  358. switch (id) {
  359. case 1: {
  360. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  361. voip::CallInfo info = GetTelephone()->GetCallInfo();
  362. if (info.state == voip::STATE_CALL_CONFIRMED){
  363. mButtonAnswerPtr->setVisible(false);
  364. }
  365. mTextViewNamePtr->setText(info.remote_uri);
  366. mTextViewStatePtr->setText(StateString(info.state));
  367. mTextViewDurationPtr->setText(
  368. base::format("%02d:%02d",
  369. info.duration/1000/60,
  370. info.duration/1000%60));
  371. } else {
  372. voip::CallInfo info = GetTelephone()->GetCallInfo();
  373. if (info.state == voip::STATE_CALL_CONFIRMED){
  374. mButtonAnswerPtr->setVisible(false);
  375. }
  376. mTextViewStatePtr->setText(StateString(info.state));
  377. mTextViewDurationPtr->setText(
  378. base::format("%02d:%02d",
  379. info.duration/1000/60,
  380. info.duration/1000%60));
  381. }
  382. }
  383. break;
  384. case kTimerAutoAnswer: {
  385. voip::CallInfo info = GetTelephone()->GetCallInfo();
  386. if (info.state == voip::STATE_CALL_INCOMING
  387. || info.state == voip::STATE_CALL_EARLY) {
  388. bool auto_answer = StoragePreferences::getBool(SIP_AUTO_ANSWER, false);
  389. LOGD("is auto answer: %d", auto_answer);
  390. if (auto_answer) {
  391. GetTelephone()->Answer();
  392. }
  393. }
  394. }
  395. return false;
  396. break;
  397. case goBack:{
  398. setSleepTimerRegistered(_isSleepTimerRegistered);
  399. EASYUICONTEXT->goBack();
  400. break;
  401. }
  402. case CALLING_TIME: {
  403. //TCP call
  404. TcpModel tcpModel;
  405. tcpModel.tid = base::format("t%d", TimeHelper::getCurrentTime());
  406. tcpModel.type = TcpType::VOICE;
  407. tcpModel.action = VoiceAction::CANCEL;
  408. tcpModel.from_id = StoragePreferences::getInt(STORE_DEVICE_ID,0);
  409. tcpModel.to_id = 0;
  410. std::string req = getTcpModelString(tcpModel);
  411. LOGD("TCP CALL : %s",req.c_str());
  412. TcpClient::instance()->sendMsg(req.c_str());
  413. // std::string heartStr = "DOORLED,000F";
  414. // const char* sendMsg = heartStr.c_str();
  415. // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  416. lightControl("DOORLED", "000F");
  417. setSleepTimerRegistered(_isSleepTimerRegistered);
  418. EASYUICONTEXT->goBack();
  419. break;
  420. }
  421. default:
  422. break;
  423. }
  424. return true;
  425. }
  426. /**
  427. * 有新的触摸事件时触发
  428. * 参数:ev
  429. * 新的触摸事件
  430. * 返回值:true
  431. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  432. * false
  433. * 触摸事件将继续传递到控件上
  434. */
  435. static bool oncallActivityTouchEvent(const MotionEvent &ev) {
  436. switch (ev.mActionStatus) {
  437. case MotionEvent::E_ACTION_DOWN://触摸按下
  438. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  439. break;
  440. case MotionEvent::E_ACTION_MOVE://触摸滑动
  441. break;
  442. case MotionEvent::E_ACTION_UP: //触摸抬起
  443. break;
  444. default:
  445. break;
  446. }
  447. return false;
  448. }
  449. static void onVideoViewPlayerMessageListener_VideoView1(ZKVideoView *pVideoView, int msg) {
  450. switch (msg) {
  451. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_STARTED:
  452. break;
  453. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED:
  454. break;
  455. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_ERROR:
  456. break;
  457. }
  458. }
  459. static void onProgressChanged_SeekBarOutputVolume(ZKSeekBar *pSeekBar, int progress) {
  460. zk_audio_output_set_volume_native(progress);
  461. mTextViewOutputVolumePtr->setText(base::format("%d", progress));
  462. }
  463. static bool onButtonClick_ButtonHangup(ZKButton *pButton) {
  464. LOGD("handup click");
  465. voip::CallInfo info = GetTelephone()->GetCallInfo();
  466. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "TCP"){
  467. TcpModel storeModel = CallingStatus::instance()->getTcpModel();
  468. if (storeModel.json != 0) {
  469. //只回传iId
  470. storeModel.data = storeModel.json["id"].asString();
  471. if (info.state == voip::STATE_CALL_CALLING
  472. || info.state == voip::STATE_CALL_CALLING
  473. || info.state == voip::STATE_CALL_CONFIRMED){
  474. sendVoiceTcp(VoiceAction::HANDOFF, storeModel, storeModel.from_id);
  475. GetTelephone()->Hangup(info.id, voip::SIP_STATUS_CODE_DECLINE);
  476. GetTelephone()->Hangup();
  477. } else if (_isOutgoing == "true") {
  478. string storeModelStr = getTcpModelString(storeModel);
  479. sendVoiceTcp(VoiceAction::CANCEL, storeModel, storeModel.from_id);
  480. // std::string heartStr = "DOORLED,000F";
  481. // const char* sendMsg = heartStr.c_str();
  482. // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  483. lightControl("DOORLED", "000F");
  484. } else {
  485. storeModel.data = storeModel.json["id"].asString();
  486. sendVoiceTcp(VoiceAction::REJECT, storeModel, storeModel.from_id);
  487. }
  488. } else {
  489. TcpModel tcpModel;
  490. tcpModel.tid = tid;
  491. sendVoiceTcp(VoiceAction::CANCEL, tcpModel, StoragePreferences::getInt(STORE_DEVICE_ID,0));
  492. // 还原成无灯光的状态
  493. // std::string heartStr = "DOORLED,000F";
  494. // const char* sendMsg = heartStr.c_str();
  495. // sendProtocolTo(UART_TTYS2, (byte*)(sendMsg), strlen(sendMsg));
  496. lightControl("DOORLED", "000F");
  497. }
  498. setSleepTimerRegistered(_isSleepTimerRegistered);
  499. EASYUICONTEXT->goBack();
  500. } else {
  501. GetTelephone()->Hangup();
  502. }
  503. return false;
  504. }
  505. static bool onButtonClick_ButtonAnswer(ZKButton *pButton) {
  506. LOGD(" ButtonClick ButtonAnswer !!!\n");
  507. mediaPlayer.Stop();
  508. mButtonAnswerPtr->setVisible(false);
  509. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  510. voip::CallInfo info = GetTelephone()->GetCallInfo();
  511. GetTelephone()->Answer();
  512. } else {
  513. TcpModel model = CallingStatus::instance()->getTcpModel();
  514. //LOGD("storeModel :::: type=%s,action=%s,from=%d,to=%d",model.type.c_str(),model.action.c_str(),model.from_id,model.to_id);
  515. //std::string storeModelStr = getTcpModelString(model);
  516. //LOGD("storeModelStr ===== %s",storeModelStr.c_str());
  517. //只回传iId
  518. model.data = model.json["id"].asString();
  519. sendVoiceTcp(VoiceAction::ACCEPT, model, model.from_id);
  520. }
  521. return false;
  522. }
  523. static bool onButtonClick_ButtonVol(ZKButton *pButton) {
  524. LOGD(" ButtonClick ButtonVol !!!\n");
  525. return false;
  526. }
  527. static void onProgressChanged_SeekBarGain(ZKSeekBar *pSeekBar, int progress) {
  528. //LOGD(" ProgressChanged SeekBarGain %d !!!\n", progress);
  529. mTextViewGainPtr->setText(base::format("%d", progress));
  530. GetTelephone()->SetInputPcmGainSize(progress);
  531. }
  532. static void onProgressChanged_SeekBarInput(ZKSeekBar *pSeekBar, int progress) {
  533. //LOGD(" ProgressChanged SeekBarInput %d !!!\n", progress);
  534. mTextViewInputPtr->setText(base::format("%d", progress));
  535. zk_audio_input_set_volume_native(0, 0);
  536. zk_audio_input_set_volume_native(1, progress);
  537. }
  538. static void onVideoViewPlayerMessageListener_VideoView(ZKVideoView *pVideoView, int msg) {
  539. switch (msg) {
  540. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_STARTED:
  541. break;
  542. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED:
  543. break;
  544. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_ERROR:
  545. break;
  546. }
  547. }