callLogic.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  269. return;
  270. }
  271. _callActivityType = intentPtr->getExtra(callActivityType);
  272. if (_callActivityType == "fromCall") {
  273. int toId = 0;
  274. _toIdStr = intentPtr->getExtra(toIdStr);
  275. if (_toIdStr != "") {
  276. toId = atoi(_toIdStr.c_str());
  277. }
  278. // else {
  279. // std::string _callRoleType = intentPtr->getExtra(callRoleType);
  280. // if (_callRoleType == "") {
  281. // _callRoleType = "NURSE";
  282. // }
  283. //
  284. // Json::Value json;
  285. // json["roleType"] = _callRoleType;
  286. // tid = sendVoiceCall(json);
  287. // }
  288. // 呼叫的时候需要把tid放进去
  289. tid = sendVoiceCall(toId);
  290. setCallTid(tid);
  291. mButtonAnswerPtr->setVisible(false);
  292. std::string _callName = intentPtr->getExtra(callName);
  293. if (_callName != "") {
  294. mTextViewNamePtr->setText(LANGUAGEMANAGER->getValue("Call") + _callName);
  295. } else {
  296. mTextViewNamePtr->setTextTr("CallOutTitle");
  297. }
  298. mActivityPtr->registerUserTimer(CALLING_TIME, 60000); // 如果对方没接听,则发送一个CANCEL回去
  299. }
  300. else if (_callActivityType == "toCall") {
  301. TcpModel storeModel = CallingStatus::instance()->getTcpModel();
  302. TcpModel backTcp = storeModel;
  303. backTcp.data = storeModel.json["id"].asString();
  304. //back voice success
  305. sendVoiceTcp(VoiceAction::SUCCESS, backTcp, storeModel.from_id);
  306. mTextViewNamePtr->setText(storeModel.json["fromFrameName"].asString());
  307. //自动接听处理
  308. if (StoragePreferences::getBool(STORE_AUDO_ANSWER,false)){
  309. mButtonAnswerPtr->setVisible(false);
  310. voip::CallInfo info = GetTelephone()->GetCallInfo();
  311. if (info.state == voip::STATE_CALL_INCOMING
  312. || info.state == voip::STATE_CALL_EARLY) {
  313. GetTelephone()->Answer();
  314. //发出TCP
  315. sendVoiceTcp(VoiceAction::ACCEPT, storeModel, storeModel.from_id);
  316. }
  317. }
  318. }
  319. else if (_callActivityType == "handleHCall") {
  320. string handleCallIdStr = intentPtr->getExtra(handleCallId);
  321. int _handleCallId = std::stoi(handleCallIdStr);
  322. // 呼叫的时候需要把tid放进去
  323. tid = sendVoiceHCall(_handleCallId);
  324. setCallTid(tid);
  325. mButtonAnswerPtr->setVisible(false);
  326. std::string _callName = intentPtr->getExtra(callName);
  327. if (_callName != "") {
  328. mTextViewNamePtr->setText(LANGUAGEMANAGER->getValue("Call") + _callName);
  329. } else {
  330. mTextViewNamePtr->setTextTr("CallOutTitle");
  331. }
  332. mActivityPtr->registerUserTimer(CALLING_TIME, 60000); // 如果对方没接听,则发送一个CANCEL回去
  333. }
  334. else if (_callActivityType == "gainCall") {
  335. mButtonAnswerPtr->setVisible(false);
  336. std::string _callName = intentPtr->getExtra(callName);
  337. if (_callName != "") {
  338. mTextViewNamePtr->setText(LANGUAGEMANAGER->getValue("Call") + _callName);
  339. } else {
  340. mTextViewNamePtr->setTextTr("CallOutTitle");
  341. }
  342. mActivityPtr->registerUserTimer(GAIN_CALL_TIME, 60000);
  343. }
  344. }
  345. }
  346. /*
  347. * 当界面显示时触发
  348. */
  349. static void onUI_show() {
  350. EASYUICONTEXT->hideStatusBar();
  351. EASYUICONTEXT->hideNaviBar();
  352. }
  353. /*
  354. * 当界面隐藏时触发
  355. */
  356. static void onUI_hide() {
  357. }
  358. /*
  359. * 当界面完全退出时触发
  360. */
  361. static void onUI_quit() {
  362. EASYUICONTEXT->showNaviBar();
  363. EASYUICONTEXT->showStatusBar();
  364. CallingStatus::instance()->setBusy(false);
  365. CallingStatus::instance()->clearTcpModel();
  366. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "TCP"){
  367. voip::CallInfo info = GetTelephone()->GetCallInfo();
  368. if (info.state == voip::STATE_CALL_CALLING
  369. || info.state == voip::STATE_CALL_CALLING
  370. || info.state == voip::STATE_CALL_CONFIRMED){
  371. GetTelephone()->Hangup(info.id, voip::SIP_STATUS_CODE_DECLINE);
  372. GetTelephone()->Hangup();
  373. }
  374. }
  375. _callActivityType = "wait";
  376. mediaPlayer.Stop();
  377. mActivityPtr->unregisterUserTimer(goBack);
  378. }
  379. /**
  380. * 串口数据回调接口
  381. */
  382. static void onProtocolDataUpdate(const SProtocolData &data) {
  383. }
  384. /**
  385. * 定时器触发函数
  386. * 不建议在此函数中写耗时操作,否则将影响UI刷新
  387. * 参数: id
  388. * 当前所触发定时器的id,与注册时的id相同
  389. * 返回值: true
  390. * 继续运行当前定时器
  391. * false
  392. * 停止运行当前定时器
  393. */
  394. static bool onUI_Timer(int id){
  395. switch (id) {
  396. case 1: {
  397. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  398. voip::CallInfo info = GetTelephone()->GetCallInfo();
  399. if (info.state == voip::STATE_CALL_CONFIRMED){
  400. mButtonAnswerPtr->setVisible(false);
  401. }
  402. mTextViewNamePtr->setText(info.remote_uri);
  403. mTextViewStatePtr->setText(StateString(info.state));
  404. mTextViewDurationPtr->setText(
  405. base::format("%02d:%02d",
  406. info.duration/1000/60,
  407. info.duration/1000%60));
  408. } else {
  409. voip::CallInfo info = GetTelephone()->GetCallInfo();
  410. if (info.state == voip::STATE_CALL_CONFIRMED){
  411. mButtonAnswerPtr->setVisible(false);
  412. }
  413. mTextViewStatePtr->setText(StateString(info.state));
  414. mTextViewDurationPtr->setText(
  415. base::format("%02d:%02d",
  416. info.duration/1000/60,
  417. info.duration/1000%60));
  418. }
  419. }
  420. break;
  421. case kTimerAutoAnswer: {
  422. voip::CallInfo info = GetTelephone()->GetCallInfo();
  423. if (info.state == voip::STATE_CALL_INCOMING
  424. || info.state == voip::STATE_CALL_EARLY) {
  425. bool auto_answer = StoragePreferences::getBool(SIP_AUTO_ANSWER, false);
  426. LOGD("is auto answer: %d", auto_answer);
  427. if (auto_answer) {
  428. GetTelephone()->Answer();
  429. }
  430. }
  431. }
  432. return false;
  433. break;
  434. case goBack:{
  435. setSleepTimerRegistered(_isSleepTimerRegistered);
  436. EASYUICONTEXT->goBack();
  437. break;
  438. }
  439. case CALLING_TIME: {
  440. //TCP call
  441. sendVoiceCancel(StoragePreferences::getInt(STORE_DEVICE_ID,0), 0);
  442. lightControl("DOORLED", "000F");
  443. setSleepTimerRegistered(_isSleepTimerRegistered);
  444. EASYUICONTEXT->goBack();
  445. break;
  446. }
  447. case GAIN_CALL_TIME: {
  448. setSleepTimerRegistered(_isSleepTimerRegistered);
  449. EASYUICONTEXT->goBack();
  450. }
  451. break;
  452. default:
  453. break;
  454. }
  455. return true;
  456. }
  457. /**
  458. * 有新的触摸事件时触发
  459. * 参数:ev
  460. * 新的触摸事件
  461. * 返回值:true
  462. * 表示该触摸事件在此被拦截,系统不再将此触摸事件传递到控件上
  463. * false
  464. * 触摸事件将继续传递到控件上
  465. */
  466. static bool oncallActivityTouchEvent(const MotionEvent &ev) {
  467. switch (ev.mActionStatus) {
  468. case MotionEvent::E_ACTION_DOWN://触摸按下
  469. //LOGD("时刻 = %ld 坐标 x = %d, y = %d", ev.mEventTime, ev.mX, ev.mY);
  470. break;
  471. case MotionEvent::E_ACTION_MOVE://触摸滑动
  472. break;
  473. case MotionEvent::E_ACTION_UP: //触摸抬起
  474. break;
  475. default:
  476. break;
  477. }
  478. return false;
  479. }
  480. static void onVideoViewPlayerMessageListener_VideoView1(ZKVideoView *pVideoView, int msg) {
  481. switch (msg) {
  482. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_STARTED:
  483. break;
  484. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED:
  485. break;
  486. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_ERROR:
  487. break;
  488. }
  489. }
  490. static void onProgressChanged_SeekBarOutputVolume(ZKSeekBar *pSeekBar, int progress) {
  491. zk_audio_output_set_volume_native(progress);
  492. mTextViewOutputVolumePtr->setText(base::format("%d", progress));
  493. }
  494. static bool onButtonClick_ButtonHangup(ZKButton *pButton) {
  495. LOGD("handup click");
  496. voip::CallInfo info = GetTelephone()->GetCallInfo();
  497. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "TCP"){
  498. TcpModel storeModel = CallingStatus::instance()->getTcpModel();
  499. if (storeModel.json != 0) {
  500. //只回传iId
  501. storeModel.data = storeModel.json["id"].asString();
  502. if (info.state == voip::STATE_CALL_CALLING
  503. || info.state == voip::STATE_CALL_CALLING
  504. || info.state == voip::STATE_CALL_CONFIRMED){
  505. sendVoiceTcp(VoiceAction::HANDOFF, storeModel, storeModel.from_id);
  506. GetTelephone()->Hangup(info.id, voip::SIP_STATUS_CODE_DECLINE);
  507. GetTelephone()->Hangup();
  508. }
  509. else if (_callActivityType == "fromCall" || _callActivityType == "gainCall") {
  510. string storeModelStr = getTcpModelString(storeModel);
  511. sendVoiceTcp(VoiceAction::CANCEL, storeModel, storeModel.from_id);
  512. lightControl("DOORLED", "000F");
  513. }
  514. else if (_callActivityType == "handleHCall") {
  515. LOGD("storeModel.from_id ============> %d", storeModel.from_id);
  516. sendVoiceCancel(storeModel.to_id, 0);
  517. setSleepTimerRegistered(_isSleepTimerRegistered);
  518. EASYUICONTEXT->goBack();
  519. }
  520. else {
  521. storeModel.data = storeModel.json["id"].asString();
  522. sendVoiceTcp(VoiceAction::REJECT, storeModel, storeModel.from_id);
  523. }
  524. } else {
  525. TcpModel tcpModel;
  526. tcpModel.tid = tid;
  527. sendVoiceTcp(VoiceAction::CANCEL, tcpModel, StoragePreferences::getInt(STORE_DEVICE_ID,0));
  528. lightControl("DOORLED", "000F");
  529. }
  530. setSleepTimerRegistered(_isSleepTimerRegistered);
  531. EASYUICONTEXT->goBack();
  532. } else {
  533. GetTelephone()->Hangup();
  534. }
  535. return false;
  536. }
  537. static bool onButtonClick_ButtonAnswer(ZKButton *pButton) {
  538. LOGD(" ButtonClick ButtonAnswer !!!\n");
  539. lightControl("DOORLED", "000F");
  540. mButtonAnswerPtr->setVisible(false);
  541. if (StoragePreferences::getString(STORE_SIGNAL_TYPE, SIGNAL_TYPE) == "SIP"){
  542. voip::CallInfo info = GetTelephone()->GetCallInfo();
  543. GetTelephone()->Answer();
  544. } else {
  545. TcpModel model = CallingStatus::instance()->getTcpModel();
  546. //LOGD("storeModel :::: type=%s,action=%s,from=%d,to=%d",model.type.c_str(),model.action.c_str(),model.from_id,model.to_id);
  547. //std::string storeModelStr = getTcpModelString(model);
  548. //LOGD("storeModelStr ===== %s",storeModelStr.c_str());
  549. //只回传iId
  550. model.data = model.json["id"].asString();
  551. sendVoiceTcp(VoiceAction::ACCEPT, model, model.from_id);
  552. }
  553. return false;
  554. }
  555. static bool onButtonClick_ButtonVol(ZKButton *pButton) {
  556. LOGD(" ButtonClick ButtonVol !!!\n");
  557. return false;
  558. }
  559. static void onProgressChanged_SeekBarGain(ZKSeekBar *pSeekBar, int progress) {
  560. //LOGD(" ProgressChanged SeekBarGain %d !!!\n", progress);
  561. mTextViewGainPtr->setText(base::format("%d", progress));
  562. GetTelephone()->SetInputPcmGainSize(progress);
  563. }
  564. static void onProgressChanged_SeekBarInput(ZKSeekBar *pSeekBar, int progress) {
  565. //LOGD(" ProgressChanged SeekBarInput %d !!!\n", progress);
  566. mTextViewInputPtr->setText(base::format("%d", progress));
  567. zk_audio_input_set_volume_native(0, 0);
  568. zk_audio_input_set_volume_native(1, progress);
  569. }
  570. static void onVideoViewPlayerMessageListener_VideoView(ZKVideoView *pVideoView, int msg) {
  571. switch (msg) {
  572. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_STARTED:
  573. break;
  574. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_COMPLETED:
  575. break;
  576. case ZKVideoView::E_MSGTYPE_VIDEO_PLAY_ERROR:
  577. break;
  578. }
  579. }