callLogic.cc 20 KB

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