tpl_tonghua.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title><?=$da['title']?></title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"/>
  7. <link rel="stylesheet" type="text/css" href="web/res/css/webimcss.css"/>
  8. <link rel="stylesheet" type="text/css" href="web/res/fontawesome/css/font-awesome.min.css">
  9. <link rel="shortcut icon" href="favicon.ico" />
  10. <script type="text/javascript" src="js/jquery.js"></script>
  11. <script type="text/javascript" src="js/js.js"></script>
  12. <script type="text/javascript" src="js/base64-min.js"></script>
  13. <script type="text/javascript" src="mode/plugin/trtc.js"></script>
  14. <script type="text/javascript" src="mode/plugin/jquery-rockmodels.js"></script>
  15. <script>
  16. adminid = <?=$da['adminid']?>;
  17. var localAudioTrack=false,localVideoTrack = false,remoteAudioTrack=false,remoteVideoTrack=false;
  18. function initbody(){
  19. c.init();
  20. }
  21. function bodyunload(){
  22. c.bodyunload(false);
  23. }
  24. var c = {
  25. iscall:<?=$ars['iscall']?>,
  26. type:0,
  27. callshu:30,
  28. id:<?=$ars['id']?>,
  29. nwwin:false,
  30. isuse:false,
  31. init:function(){
  32. this.userid = 'rock'+this.id+'';
  33. this.typearr = ['语音','视频'];
  34. this.name = '<?=$ars['name']?>';
  35. this.playobj = get('notify_sound_tonghua');
  36. js.initbtn(this);
  37. //接收端
  38. if(!this.iscall){
  39. this.type = <?=$thrs['type']?>;
  40. this.channel = '<?=$thrs['channel']?>';
  41. this.jieshoucall();
  42. }else{
  43. $('#calldiv').show();
  44. }
  45. if(nwjsgui){
  46. this.nwwin = nw.Window.get();
  47. this.nwwin.on('close', function(){
  48. c.bodyunload(this);
  49. });
  50. }
  51. if(window['TRTC']){
  52. this.isuse = true;
  53. }else{
  54. this.stateupdate('未安装插件,无法使用');
  55. }
  56. if(NOWURL.substr(0,5)!='https'){
  57. if(HOST.indexOf('localhost')==0 || HOST.indexOf('127.0.0.1')==0){
  58. }else{
  59. js.msg('msg','未使用https,功能受限');
  60. }
  61. }
  62. },
  63. hujiao:function(o1,lx){
  64. if(this.hujiaobo)return;
  65. if(!this.isuse){
  66. js.msg('msg','未安装插件,无法使用');
  67. return;
  68. }
  69. js.loading('请求中...');
  70. this.hujiaobo = true;
  71. this.type = lx;
  72. js.ajax('tonghua|thinit',{id:this.id,type:lx,rtctype:1},function(ret){
  73. c.hujiaoback(ret);
  74. }, 'get', function(str){
  75. js.msgerror(str);
  76. c.stateupdate(str);
  77. c.hujiaobo=false;
  78. });
  79. },
  80. stateupdate(str, bo){
  81. $('#wiatling').html(str);
  82. $('#wiatlings').html(str);
  83. document.title = str;
  84. if(bo)this.showtoast(str);
  85. },
  86. showtoast:function(str){
  87. js.msg('success',str);
  88. },
  89. hujiaoback:function(ret){
  90. this.thcan = ret.data;
  91. this.channel = this.thcan.channel;
  92. $('#backbtn').hide();
  93. $('#hujiaobtn').remove();
  94. $('#cancelbtn').show();
  95. this.initagoraRtc();
  96. this.callstartplay();
  97. this.callstrimes = js.now('time');
  98. this.callmiashue();
  99. this.hujiaobool = true;
  100. },
  101. callstartplay:function(){
  102. this.playobj.src='web/res/sound/call.mp3';
  103. if(this.playobj.play)this.playobj.play();
  104. },
  105. callstopplay:function(){
  106. if(this.playobj.pause)this.playobj.pause();
  107. },
  108. cancalpayls:function(){
  109. this.playobj.src='web/res/sound/gua.mp3';
  110. this.playobj.loop='';
  111. if(this.playobj.play)this.playobj.play();
  112. },
  113. callmiashue:function(){
  114. clearTimeout(this.callmiashuetime);
  115. var sj = parseInt((js.now('time')-this.callstrimes)*0.001);
  116. if(sj>this.callshu){
  117. this.cancelhus(5);
  118. return;
  119. }
  120. if(sj%2==0 && sj>0 && !this.ztpandbool){
  121. this.ztpandbool = true;
  122. js.ajax('tonghua|state',{channel:this.channel}, function(ret){
  123. var zt = ret.data.state;
  124. c.ztpandbool = false;
  125. if(!c.calljutong && (zt=='tongyi' || zt=='jujue'))c.callbackss(zt);
  126. },'get', function(st1){
  127. c.ztpandbool = false;
  128. js.msg();
  129. });
  130. }
  131. this.stateupdate(''+this.typearr[this.type]+'通话呼叫中已呼叫'+sj+'秒...');
  132. this.callmiashuetime = setTimeout(function(){c.callmiashue()},1000);
  133. },
  134. initagoraRtc:async function(){
  135. trtc = TRTC.create();
  136. trtc.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, ({ userId, streamType }) => {
  137. const view = `remote_stream`;
  138. trtc.startRemoteVideo({ userId, streamType, view });
  139. });
  140. //trtc.muteRemoteAudio(this.userid, false);
  141. },
  142. cancelhu:function(){
  143. this.cancelhus(3);
  144. },
  145. closewin:function(bo){
  146. if(bo){
  147. if(this.nwwin){
  148. this.nwwin.close(true);
  149. }else{
  150. window.close();
  151. }
  152. }else{
  153. setTimeout(function(){c.closewin(true)},2000);
  154. }
  155. },
  156. cancelhus:function(zt){
  157. $('#cancelbtn').hide();
  158. this.hujiaobool = false;
  159. clearTimeout(this.callmiashuetime);
  160. var ss1='';if(zt==5)ss1='无人接听';
  161. js.loading(''+ss1+'取消呼叫中...');
  162. this.stateupdate(''+ss1+'取消呼叫中...');
  163. this.callstopplay();
  164. js.ajax('tonghua|cancel',{channel:this.thcan.channel,state:zt},function(ret){
  165. c.stateupdate(''+ss1+'已取消呼叫', true);
  166. c.closewin();
  167. }, 'get', function(str){
  168. $('#cancelbtn').show();
  169. js.msgerror(str);
  170. c.stateupdate(str);
  171. });
  172. },
  173. //接通后显示视频
  174. localvadio:async function(){
  175. if(this.localvadiobool)return;
  176. this.localvadiobool = true;
  177. this.isjietong = true;
  178. this.showtoast(''+this.typearr[this.type]+'已接通');
  179. this.stateupdate('与'+this.name+''+this.typearr[this.type]+'通话中(00:00)');
  180. $('#backbtn').hide();
  181. this.starttime = js.now('time');
  182. this.showmian();
  183. $('#calldiv').remove();
  184. $('#canceldiv').show();
  185. if(this.type==1){
  186. $('#shipindiv').show();
  187. $('#yuyindiv').hide();
  188. $('#local_stream').show();
  189. $('#remote_stream').show();
  190. }
  191. await trtc.startLocalAudio();
  192. if(this.type==1){
  193. const view = 'local_stream';
  194. await trtc.startLocalVideo({ view })
  195. }
  196. try {
  197. const strRoomId = this.thcan.channel;
  198. const sdkAppId = this.thcan.appid;
  199. const userId = 'rock'+this.thcan.uid;
  200. const userSig = this.thcan.token;
  201. await trtc.enterRoom({ strRoomId: strRoomId, scene:'rtc', sdkAppId, userId, userSig });
  202. console.log('进房成功');
  203. } catch (error) {
  204. js.msg('msg','接通失败: ' + error);
  205. }
  206. },
  207. showmian:function(){
  208. var sj = parseInt((js.now('time')-this.starttime)*0.001);
  209. this.tonghuasj = sj;
  210. var fz = 0;
  211. if(sj>59)fz = parseInt(sj/60);
  212. var ms = sj-fz*60;
  213. this.stateupdate(''+this.typearr[this.type]+'通话中('+xy10(fz)+':'+xy10(ms)+')');
  214. if(sj>0 && sj%2==0 && !this.showmiaobool){
  215. this.showmiaobool = true;
  216. js.ajax('tonghua|stateth',{channel:this.channel}, function(ret){
  217. var zt = ret.data.state;
  218. c.showmiaobool = false;
  219. if(zt=='jiesu')c.callbackss(zt);
  220. },'get', function(st1){
  221. c.showmiaobool = false;
  222. js.msg();
  223. });
  224. }
  225. this.showmiantime = setTimeout(function(){c.showmian()},1000);
  226. },
  227. guaduan:function(){
  228. this.guaduanok(true);
  229. },
  230. guaduanok:function(bo){
  231. if(this.guaduanbool)return;
  232. this.guaduanbool = true;
  233. if(bo){
  234. this.showtoast('挂断中...');
  235. js.ajax('tonghua|jiesu',{channel:this.thcan.channel,toid:this.id}, function(ret){
  236. c.guaduanokok();
  237. },'get', function(str){
  238. c.guaduanokok();
  239. });
  240. }else{
  241. this.guaduanokok();
  242. }
  243. },
  244. guaduanokok:async function(){
  245. clearTimeout(this.showmiantime);
  246. trtc.stopLocalVideo()
  247. trtc.stopLocalAudio();
  248. await trtc.exitRoom();
  249. trtc.destroy();
  250. this.stateupdate('通话已结束', true);
  251. $('#canceldiv').remove();
  252. this.cancalpayls();
  253. this.closewin();
  254. },
  255. payerstart:function(){
  256. this.playobj.src='web/res/sound/mi.mp3';
  257. if(this.playobj.play)this.playobj.play();
  258. },
  259. payerend:function(){
  260. this.callstopplay();
  261. },
  262. qiehysq:function(){
  263. if(!this.yuancjinb){
  264. trtc.setRemoteAudioVolume(this.userid, 0);
  265. this.yuancjinb = true;
  266. $('#jingyinclltxt').html('开启声音');
  267. get('jingyincll').className='icon-volume-off';
  268. }else{
  269. trtc.setRemoteAudioVolume(this.userid, 100);
  270. this.yuancjinb = false;
  271. $('#jingyinclltxt').html('静音');
  272. get('jingyincll').className='icon-volume-up';
  273. }
  274. },
  275. //接电话端处理初始化
  276. jieshoucall:function(){
  277. $('#backbtn').hide();
  278. $('#anjiandiv').show();
  279. js.ajax('tonghua|receopen',{channel:this.channel});
  280. this.jieshoutimes(-1);
  281. this.isyaoqbool = true;
  282. this.payerstart();
  283. },
  284. jieshoutimes:function(i1){
  285. var str = this.typearr[this.type];
  286. var sys = this.callshu - <?=$thrs['sytime']?> -i1;
  287. if(sys<0){
  288. this.stateupdate('超时自动取消', true);
  289. this.jiedianha(false,3);
  290. }else{
  291. if(i1%2==0 && i1>0 && !this.ztpandbool){
  292. this.ztpandbool = true;
  293. js.ajax('tonghua|state',{channel:this.channel}, function(ret){
  294. var zt = ret.data.state;
  295. c.ztpandbool = false;
  296. if(zt=='cancel' || zt=='tongyi' || zt=='jujue')c.callbackss(zt);
  297. },'get', function(st1){
  298. c.ztpandbool = false;
  299. js.msg();
  300. });
  301. }
  302. this.stateupdate('邀请与您'+str+'通话('+sys+')...');
  303. this.jieshoutimesa = setTimeout(function(){c.jieshoutimes(i1+1)},1000);
  304. }
  305. },
  306. jiedianha:function(o1,lx){
  307. if(!this.isuse && lx==1){
  308. js.msg('msg','未安装插件,只能拒绝');
  309. return;
  310. }
  311. clearTimeout(this.jieshoutimesa);
  312. this.ismybool = true;
  313. this.isyaoqbool = false;
  314. $('#anjiandiv').hide();
  315. this.payerend();
  316. if(lx==1){
  317. this.stateupdate('接通中...');
  318. this.initagoraRtc();
  319. js.ajax('tonghua|jietong',{channel:this.channel,state:1},function(ret){
  320. c.jietongback(ret);
  321. }, 'get', function(str){
  322. js.msgerror(str);
  323. c.stateupdate(str);
  324. $('#anjiandiv').show();
  325. });
  326. }
  327. if(lx==2){
  328. this.stateupdate('拒绝中...');
  329. js.ajax('tonghua|jie',{channel:this.channel,state:2},function(ret){
  330. var ms2 = '已拒绝通话';
  331. if(ret.data.satype)ms2 = ret.data.satype;
  332. c.jiequxian(ms2);
  333. },'get', function(str){
  334. js.msgerror(str);
  335. c.stateupdate(str);
  336. $('#anjiandiv').show();
  337. });
  338. }
  339. if(lx==3){
  340. this.closewin();
  341. }
  342. },
  343. jiequxian:function(s1){
  344. this.stateupdate(s1, true);
  345. this.closewin();
  346. },
  347. jietongback:function(ret){
  348. this.thcan = ret.data;
  349. if(ret.data.satype){
  350. this.jiequxian(ret.data.satype);
  351. }else{
  352. this.stateupdate(''+this.typearr[this.type]+'通话中...');
  353. this.localvadio();//被叫端接通
  354. }
  355. },
  356. bodyunload:function(win){
  357. var lx = '';
  358. if(this.isjietong){
  359. this.guaduan();
  360. lx = '挂断中...';
  361. }else{
  362. if(this.hujiaobool){
  363. this.cancelhu();
  364. lx='取消中...';
  365. }
  366. if(this.isyaoqbool){
  367. this.jiedianha(false,2);
  368. lx='邀请中..';
  369. }
  370. }
  371. if(!lx){
  372. win.close(true);
  373. }
  374. },
  375. callbackss:function(lx){
  376. this.callstopplay();
  377. clearTimeout(this.callmiashuetime);
  378. clearTimeout(this.jieshoutimesa);
  379. if(lx=='jujue'){
  380. this.calljutong = true;
  381. this.hujiaobool = false;
  382. if(this.iscall){
  383. $('#cancelbtn').remove();;
  384. this.stateupdate('对方拒绝通话', true);
  385. this.closewin();
  386. }
  387. if(!this.iscall && !this.ismybool){
  388. this.stateupdate('已在另端拒绝', true);
  389. $('#anjiandiv').remove();
  390. this.closewin();
  391. }
  392. }
  393. if(lx=='tongyi'){
  394. this.calljutong = true;
  395. this.hujiaobool = false;
  396. if(this.iscall){
  397. this.stateupdate('接通中...');
  398. this.localvadio(); //主叫端接通
  399. }
  400. if(!this.iscall && !this.ismybool){
  401. this.stateupdate('已在另端接通', true);
  402. $('#anjiandiv').remove();
  403. this.closewin();
  404. }
  405. }
  406. //----以下是接收端处理----
  407. //呼叫已经取消
  408. if(lx=='cancel' && get('anjiandiv')){
  409. $('#anjiandiv').remove();
  410. clearTimeout(this.jieshoutimesa);
  411. this.stateupdate('对方已取消', true);
  412. this.closewin();
  413. }
  414. //对方挂电话
  415. if(lx=='jiesu'){
  416. this.guaduanok(false);
  417. }
  418. }
  419. }
  420. js.ajax=function(lex,ds,fun,lxss,efun){
  421. var lexa = lex.split('|');
  422. if(!lxss)lxss='type';
  423. var cans = {
  424. url:js.apiurl(lexa[0],lexa[1]),
  425. data:ds,
  426. type:lxss,
  427. dataType:'json',
  428. success:function(ret){
  429. js.unloading();
  430. if(ret.success){
  431. if(fun)fun(ret);
  432. }else{
  433. if(efun)efun(ret.msg)
  434. }
  435. },
  436. error:function(e){
  437. js.unloading();
  438. if(efun)efun('处理出错:'+e.responseText+'');
  439. }
  440. }
  441. $.ajax(cans);
  442. }
  443. js.initbtn = function(obj){
  444. var o = $("[clickevt]"),i,o1,cl;
  445. for(i=0; i<o.length; i++){
  446. o1 = $(o[i]);
  447. cl = o1.attr('clickadd');
  448. if(cl!='true'){
  449. o1.click(function(eo){
  450. var cls = $(this).attr('clickevt');
  451. if(typeof(cls)=='string'){
  452. cls=cls.split(',');
  453. obj[cls[0]](this, cls[1], cls[2], eo);
  454. }
  455. return false;
  456. });
  457. }
  458. }
  459. o.attr('clickadd','true');
  460. }
  461. </script>
  462. </head>
  463. <body style="overflow:hidden;background:#555555">
  464. <div id="local_stream" style="width:100px;height:150px;right:0px;top:0px;border:0px red solid;position:fixed;z-index:2;display:none"></div>
  465. <div id="remote_stream" style="width:100%;height:100%;left:0px;top:0px;border:0px red solid;position:fixed;z-index:1;display:none"></div>
  466. <div align="left" style="padding:0px 10px;height:60px;overflow:hidden;display:none;position:fixed;z-index:9;left:0;top:0" id="shipindiv">
  467. <table style="margin-top:10px"><tr>
  468. <td><img id="tonghuafaces" src="<?=$ars['face']?>" width="40px" height="40px" style="border-radius:50%"></td>
  469. <td width="5"></td>
  470. <td style="color:white"><?=$ars['name']?></td>
  471. <td width="10"></td>
  472. <td><div id="wiatlings" style="color:#888888;font-size:14px">等待呼叫</div></td>
  473. </tr></table>
  474. </div>
  475. <div align="center" style="position:fixed;z-index:9;left:0;top:0;width:100%" id="yuyindiv">
  476. <div style="margin-top:50px"><img id="tonghuaface" src="<?=$ars['face']?>" width="100px" height="100px" style="border-radius:50%"></div>
  477. <div style="color:white"><?=$ars['name']?></div>
  478. <div id="wiatling" style="color:#888888;font-size:14px;margin-top:5px">等待呼叫</div>
  479. </div>
  480. <div align="center" id="calldiv" style="position:fixed;bottom:50px;width:100%;display:none;z-index:9">
  481. <div id="hujiaobtn">
  482. <div style="color:#888888;font-size:12px">请选择通话类型</div>
  483. <table><tr>
  484. <td align="center">
  485. <div class="webbtn" clickevt="hujiao,0" align="center" style="width:90px;height:90px;background:#ff6600;color:white;line-height:90px;border-radius:50%;font-size:16px;margin-top:10px;padding:0"><i class="icon-volume-up"></i> 语音</div>
  486. </td>
  487. <td width="50"></td>
  488. <td align="center">
  489. <div class="webbtn" clickevt="hujiao,1" align="center" style="width:90px;height:90px;background:#339933;color:white;line-height:90px;border-radius:50%;font-size:16px;padding:0;margin-top:20px"><i class="icon-facetime-video"></i> 视频</div>
  490. </td>
  491. </tr></table>
  492. </div>
  493. <div id="cancelbtn" style="display:none">
  494. <div class="webbtn" clickevt="cancelhu" style="width:80px;height:80px;background:#FF6666;color:white;line-height:80px;border-radius:50%;font-size:40px;padding:0;margin-top:20px;transform:rotate(135deg);"><i class="icon-phone"></i></div>
  495. <div style="color:#888888;font-size:12px;margin-top:5px">取消</div>
  496. </div>
  497. </div>
  498. <div align="center" id="canceldiv" style="position:fixed;bottom:0px;width:100%;display:none;height:120px;overflow:hidden;z-index:9">
  499. <table style="margin-top:10px"><tr>
  500. <td align="center">
  501. <div class="webbtn" clickevt="guaduan" style="width:80px;height:80px;background:#FF6666;color:white;line-height:80px;border-radius:50%;font-size:40px;padding:0;margin-top:20px;margin:0;transform:rotate(135deg);"><i class="icon-phone"></i></div>
  502. <div style="color:#888888;font-size:12px;margin-top:5px">挂断</div>
  503. </td>
  504. <td width="30"></td>
  505. <td align="center">
  506. <div class="webbtn" clickevt="qiehysq" style="width:80px;height:80px;background:white;color:#000000;line-height:80px;border-radius:50%;font-size:40px;padding:0;margin-top:20px;margin:0"><i id="jingyincll" class="icon-volume-up"></i></div>
  507. <div id="jingyinclltxt" style="color:#888888;font-size:12px;margin-top:5px">静音</div>
  508. </td>
  509. </tr></table>
  510. </div>
  511. <div align="center" id="anjiandiv" style="position:fixed;bottom:50px;width:100%;display:none;z-index:9">
  512. <div>
  513. <table><tr>
  514. <td align="center">
  515. <div class="webbtn" clickevt="jiedianha,2" style="width:80px;height:80px;background:#FF6666;color:white;line-height:80px;border-radius:50%;font-size:40px;padding:0;margin-top:20px;transform:rotate(135deg);"><i class="icon-phone"></i></div>
  516. <div style="color:#888888;font-size:12px;margin-top:5px">拒绝</div>
  517. </td>
  518. <td width="50"></td>
  519. <td align="center">
  520. <div class="webbtn" clickevt="jiedianha,1" style="width:80px;height:80px;background:#339933;color:white;line-height:80px;border-radius:50%;font-size:40px;padding:0;margin-top:20px"><i class="icon-phone"></i></div>
  521. <div style="color:#888888;font-size:12px;margin-top:5px">接听</div>
  522. </td>
  523. </tr></table>
  524. </div>
  525. </div>
  526. <audio id="notify_sound_tonghua" hidden="true" loop="loop" autoplay="autoplay" src=""></audio>
  527. </body>
  528. </html>
粤ICP备19079148号