blob: 9190dcc53a584a8a14b6a320146ede5e73030b7e [file] [log] [blame]
yi.zhang14e77a332024-04-18 09:15:59 +08001/**************************************************************
2 * Function :main.js for amlogic web_ui
3 * Date :2017-12-26
4 * Author :haibing.an
5 * @ :haibing.an@amlogic.com
6 **************************************************************/
7
8/***************************************************
9 *HTML url handle
10 * ************************************************/
11var obj_Data;
12function HTMLEnCode(str)
13{
14 var s = "";
15 if (str.length == 0) return "";
16 s = str.replace(/&/g, ">");
17 s = s.replace(/</g, "&lt;");
18 s = s.replace(/>/g, "&gt;");
19 s = s.replace(/ /g, "&nbsp;");
20 s = s.replace(/\'/g, "'");
21 s = s.replace(/\"/g, "&quot;");
22 s = s.replace(/\n/g, "<br>");
23 return s;
24}
25
26function handleCommand(command_xmlhttp, callback)
27{
28 if(command_xmlhttp.readyState==4)
29 {
30 if(command_xmlhttp.status == 200){
31 if(callback == null)
32 return;
33 callback(command_xmlhttp);
34 }
35 }
36}
37
38function send_command(command, callback,cgi)
39{
40 var cgi = cgi || "cgi-bin/main.cgi";
41 command_xmlhttp = GetXmlHttpObject(); //create req obj
42 command_xmlhttp.onreadystatechange = function () { //get data from web action
43 handleCommand(command_xmlhttp, callback);
44 }
45
46 command_xmlhttp.open("POST",cgi,true);
47 command_xmlhttp.setRequestHeader("If-Modified-Since","0");
48 command_xmlhttp.setRequestHeader("Cache-Control","no-cache");
49 command_xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
50 command_xmlhttp.send(command);
51}
52//--------------HTML url handle end---------------//
53
54function get_bt_list()
55{
56 document.getElementById("load_div").style="";
57 $(":button").attr("disabled",true);
58 var wifi_json = send_command("",bt_list_init,"cgi-bin/bt.cgi");
59}
60
61
62function bt_list_init(){
63 var response_bt_list = command_xmlhttp.responseText;
64 response_bt_list =response_bt_list.substring(response_bt_list.indexOf("{"),response_bt_list.lastIndexOf("}")) +"}";
65
66 var response_bt_list_json = eval("(" + response_bt_list + ")");
67 var len = response_bt_list_json.bt_list.length;
68 var htmlStr="";
69 for(var i=0; i< len ;i++){
70 console.log(response_bt_list_json.bt_list[i].name);
71 htmlStr += '<button type="button" name=" '+ i +'" class="btn bt_item btn-default btn-lg btn-block">'+response_bt_list_json.bt_list[i].name +'</button>'
72 }
73 document.getElementById("load_div").style="display:none";
74 $(":button").attr("disabled",false);
75 $('#bt_btn').html(htmlStr);
76}
77
78$('#bt_btn').on('click', 'button', function(){
79 send_command("", is_bt_ok, "cgi-bin/bt_con.cgi?index="+eval(this.name));
80})
81function is_bt_ok(){
82 var response_status = command_xmlhttp.responseText;
83 var stau = eval("(" + response_status +")");
84 if (stau.status=="ture")
85 alert("BT connecnt success");
86 else
87 alert("BT connecnt faile");
88}
89
90/*************************************************
91 * WI-FI handle
92 ************************************************/
93function get_wifi_list()
94{
95 var wifi_list = null;
96 var wifi_json = send_command("get_wifi_list", set_wifi_list_to_select);
97 show_loading();
98 setTimeout(function () { $('#loading').hide(); }, 3000);
99}
100
101function show_loading(){
102 loadNode = '<img id="loading" src="./images/loading.gif" />';
103 $('#loadpoint').html(loadNode);
104}
105
106function set_wifi(ssid,pwd)
107{
108 var wifi_ssid = ssid;
109 var wifi_pwd = pwd;
110 var wifi_json = send_command("set_wifi&ssid="+wifi_ssid+"&"+"pwd="+wifi_pwd);
111 show_loading();
112
113 setTimeout("check_wifi_connected1()", 10000);
114 setTimeout("check_wifi_connected1()", 15000);
115 setTimeout("check_wifi_connected1()", 20000);
116 setTimeout("check_wifi_connected1()", 25000);
117 setTimeout("check_wifi_connected1()", 30000);
118 setTimeout(function () { $('#loading').hide(); }, 31000);
119}
120
121function set_wifi_list_to_select(command_xmlhttp)
122{
123 var response_date = command_xmlhttp.responseText;
124
125 obj_Data = eval("("+response_date+")");
126 if(obj_Data.length == 0){
127 get_wifi_list();
128 }
129 else{
130 var htmlNodes = '';
131
132 for(var i = 0; i < obj_Data.length; i++){
133 htmlNodes += '<a class="list-group-item" id="wifi_' + i + '"' + ' role="button" data-toggle="modal" data-target="#myModal">' + obj_Data[i].ssid + '</a>';
134 }
135 htmlNodes += '</ul>';
136
137 $('#testtext').html(htmlNodes);
138
139 var j;
140 var index = 1;
141 var wifi_select = document.getElementById("ssid");
142 for(j = 0; j < obj_Data.length; j++){
143 var wifi = new Object;
144 wifi.ssid = obj_Data[j].ssid;
145 //wifi_select.Option.add(wifi.id);
146 }
147 }
148 check_wifi_connected();
149}
150
151function set_wifi_by_input()
152{
153 var input_ssid = document.getElementById("selfModal_ssid").value;
154 var input_pwd = document.getElementById("selfModal_pwd").value;
155 set_wifi(input_ssid,input_pwd);
156}
157
158function set_wifi_by_modal_input()
159{
160 setTimeout(function(){$("#mymodal").modal("hide")},2000);
161 var input_ssid = document.getElementById("modal_ssid").value;
162 var input_pwd = document.getElementById("modal_pwd").value;
163
164 set_wifi(input_ssid,input_pwd);
165}
166
167//-------------------------------------------------------
168function check_wifi_connected1() {
169 show_loading();
170 send_command("check_wifi_connected", handle_check_wifi1);
171}
172
173function handle_check_wifi1(command_xmlhttp)
174{
175 var response_check_wifi1 = command_xmlhttp.responseText;
176 var obj_check_wifi_Data1 = eval("("+response_check_wifi1+")");
177 var check_wifi_nc_Nodes1 = '<h3 style="color:red">No Connected</h3>';
178
179 if (obj_check_wifi_Data1.length > 7 && obj_check_wifi_Data1[8].info == "COMPLETED") {
180 var check_wifi_oc_Nodes1 = '<h3 style="color:green">' + obj_check_wifi_Data1[2].info + '</br>' + obj_check_wifi_Data1[9].info+ '</h3>';
181 $('#check_wifi').html(check_wifi_oc_Nodes1);
182 $('#loading').hide();
183 console.log("set DONE!");
184 }
185 if (obj_check_wifi_Data1[0].info == "SCANNING") {
186 $('#check_wifi').html(check_wifi_nc_Nodes1);
187 }
188 if (obj_check_wifi_Data1[0].info == "DISCONNECTED") {
189 $('#check_wifi').html(check_wifi_nc_Nodes1);
190 $('#loading').hide();
191 alert("Unknown error & stop");
192 }
193}
194
195//-----------------------------------------------
196
197function check_wifi_connected() {
198 show_loading();
199 setTimeout(function () { $('#loading').hide(); }, 2000);
200 send_command("check_wifi_connected", handle_check_wifi);
201}
202
203function handle_check_wifi(command_xmlhttp)
204{
205 var response_check_wifi = command_xmlhttp.responseText;
206 var obj_check_wifi_Data = eval("("+response_check_wifi+")");
207 var check_wifi_Nodes = "";
208
209 if (obj_check_wifi_Data.length < 4){
210 //if (obj_check_wifi_Data[0].info == "SCANNING")
211 check_wifi_Nodes = '<h3 style="color:red">No Connected</h3>';
212 }else{
213 if (obj_check_wifi_Data[8].info == "COMPLETED")
214 check_wifi_Nodes = '<h3 style="color:green">' + obj_check_wifi_Data[2].info + '</br>' + obj_check_wifi_Data[9].info + '</h3>';
215 }
216
217 $('#check_wifi').html(check_wifi_Nodes);
218}
219
220function goTop() {
221 $('html, body').animate({scrollTop:0}, 'fast');
222}
223
224function check_input_is_ok(input_text)
225{
226 if (input_text=="")
227 return false;
228 else
229 return true;
230}
231
232$('#testtext').on('click','a',function(){
233 var inner_ssid = this.innerText;
234 var my_ssid = document.getElementById("modal_ssid");
235 var my_pwd = document.getElementById("modal_pwd");
236 my_pwd.value = "";
237 my_ssid.value = inner_ssid;
238});
239//---------------WI-FI handle end---------------//
240
241
242/**********************************************
243 *RECORD handle
244 *********************************************/
245function get_record_list()
246{
247 send_command("get_record_list", handle_record_list);
248}
249
250function get_record_dl_list() {
251 send_command("get_record_dl_list", handle_record_dl_list);
252}
253
254function handle_record_list(command_xmlhttp)
255{
256 var response_record_date = command_xmlhttp.responseText;
257
258 var obj_record_Data = eval("("+response_record_date+")");
259 if(obj_record_Data.length == 0){
260 get_record_list();
261 }
262 else{
263 var html_record_Nodes = '';
264
265 for(var i = 0; i < obj_record_Data.length; i++){
266 html_record_Nodes += '<a class="list-group-item" id="record_' + i + '"' + ' role="button" data-toggle="modal" data-target="#recordModal">' + obj_record_Data[i].filename + '</a>';
267 }
268 html_record_Nodes += '</ul>';
269
270 $('#recordtext').html(html_record_Nodes);
271
272 var j;
273 var index = 1;
274 var record_select = document.getElementById("filename");
275 for(j = 0; j < obj_record_Data.length; j++){
276 var record = new Object;
277 record.filename = obj_record_Data.recordlist[j].filename;
278 record_select.Option.add(record.id);
279 }
280 }
281}
282
283function handle_record_dl_list() {
284 var response_record_dl_date = command_xmlhttp.responseText;
285
286 var obj_record_dl_Data = eval("("+response_record_dl_date+")");
287 if(obj_record_dl_Data.length == 0){
288 get_record_dl_list();
289 }
290 else{
291 var html_record_dl_Nodes = '';
292
293 for(var i = 0; i < obj_record_dl_Data.length; i++){
294 html_record_dl_Nodes += '<a class="list-group-item" download="" href="record/' + obj_record_dl_Data[i].filename + '"' + '>' + obj_record_dl_Data[i].filename + '</a>';
295 }
296 html_record_dl_Nodes += '</ul>';
297
298 $('#record_dl_text').html(html_record_dl_Nodes);
299 }
300}
301
302function start_record() {
303
304 var input_filename = document.getElementById("modal_filename").value;
305 var channel = $('#select-ch option:selected').val();
306 var rate = $('#select-rate option:selected').val();
307 var bits = $('#select-bits option:selected').val();
308 console.log(channel);
309 console.log(rate);
310 console.log(bits);
311 send_command("start_record&filename="+input_filename+"&ch="+channel+"&rate="+rate+"&bits="+bits);
312 //get_record_list();
313}
314
315function done_record() {
316 send_command("done_record");
317 get_record_list();
318}
319
320function delete_record() {
321 var input_filename = document.getElementById("modal_filename").value;
322 send_command("delete_record&filename="+input_filename);
323 get_record_list();
324}
325
326function play_record() {
327 var input_filename = document.getElementById("modal_filename").value;
328 send_command("play_record&filename="+input_filename);
329}
330
331function play_local_record() {
332 var play_filename = document.getElementById("modal_filename").value;
333 var player_nodes = "";
334 player_nodes += '<audio id ="music" controls="controls" muted="muted"><source src="record/'+play_filename+'"'+ '/>' + '</audio>';
335 $('#ol_player').html(player_nodes);
336 var music = document.getElementById('music');
337
338 var input_filename = document.getElementById("modal_filename").value;
339 send_command("play_record&filename="+input_filename);
340}
341
342function play_online_record() {
343 var play_filename = document.getElementById("modal_filename").value;
344 var player_nodes = "";
345 var file_info_nodes = "";
346 file_info_nodes += play_filename;
347 player_nodes += '<audio id ="music" controls="controls"><source src="record/'+play_filename+'"'+ '/>' + '</audio>';
348 $('#file_info').html(file_info_nodes);
349 $('#ol_player').html(player_nodes);
350 var music = document.getElementById('music');
351}
352
353$('#recordtext').on('click','a',function () {
354 var inner_filename = this.innerText;
355 var my_filename = document.getElementById("modal_filename");
356 my_filename.value = inner_filename;
357});
358//--------------RECORD handle end--------------//
359
360
361/***********************************************
362 * Spotify handle
363 **********************************************/
364function set_spotify(){
365 var spotify_username = document.getElementById("modal_spotify_username").value;
366 var spotify_pwd = document.getElementById("modal_spotify_pwd").value;
367 var spotify_dname = document.getElementById("modal_spotify_dname").value;
368
369 send_command("set_spotify&username="+spotify_username+"&"+"spotify_pwd="+spotify_pwd+"&"+"spotify_dname="+spotify_dname);
370 var showUserId = '<h3 style="color:green" align="center">Logging...</h3>';
371 $('#userinfo').html(showUserId);
372 setTimeout("check_spotify()",3000);
373}
374
375function TurnOffSpotify(){
376 send_command("kill_spotify");
377 var showStopping = '<h3 style="color:red" align="center">stopping...</h3>';
378 $('#userinfo').html(showStopping);
379 setTimeout("check_spotify()",3000);
380}
381
382function check_spotify(){
383 send_command("check_spotify",handle_check);
384}
385
386function handle_check(command_xmlhttp){
387
388 var response_check_date = command_xmlhttp.responseText;
389
390 if(response_check_date == "")
391 return;
392
393 if(response_check_date.length > 7){
394 send_command("get_spo_info",handle_get_info);
395 }
396 else{
397 var htmlNodes_spo_info = '<h3 style="color:red" align="center">Stopped</h3>';
398 $('#userinfo').html(htmlNodes_spo_info);
399 }
400}
401
402function handle_get_info(){
403 var response_spo_info = command_xmlhttp.responseText;
404 if(response_spo_info == "")
405 return;
406 var spo_info = eval("("+response_spo_info+")");
407 console.log(spo_info);
408 var old_uname = spo_info[0].infos;
409 var old_dname = spo_info[2].infos;
410
411 var htmlNodes_spo_info = '<h3 style="color:green" align="center">user: '+old_uname+' device: '+old_dname+'</h3>';
412 $('#userinfo').html(htmlNodes_spo_info);
413}
414//-------------Spotify handle end-------------//
415
416
417/**********************************************
418 * Swupdate handle
419 *********************************************/
420function system(){
421 var swupdate_href = '<li><a href="http://'+window.location.host+':8080" class="list-group-item" role="button">Swupdate</a></li>';
422 $('#swupdate').html(swupdate_href);
423
424 send_command("get_deviceinfo",show_device_info);
425}
426
427function show_device_info(command_xmlhttp){
428
429 send_command("runswupdate");
430 var response_dev_info = command_xmlhttp.responseText;
431 if(response_dev_info == "")
432 return;
433 var dev_info = eval("("+response_dev_info+")");
434 var htmlNodes_dev_info = '';
435
436 htmlNodes_dev_info += '<li class="list-group-item" align="center">KERNEL :' + dev_info[0].info+'</a></li>'
437 htmlNodes_dev_info += '<li class="list-group-item" align="center">ARCH :' + dev_info[8].info+'</a></li>'
438 htmlNodes_dev_info += '<li class="list-group-item" align="center">SSID :' + dev_info[1].info+'</a></li>'
439 htmlNodes_dev_info += '<li class="list-group-item" align="center">MODE :' + dev_info[2].info+'</a></li>'
440 htmlNodes_dev_info += '<li class="list-group-item" align="center">CIPHER :' + dev_info[3].info+'</a></li>'
441 htmlNodes_dev_info += '<li class="list-group-item" align="center">KEYMGMT :' + dev_info[4].info+'</a></li>'
442 htmlNodes_dev_info += '<li class="list-group-item" align="center">STATE :' + dev_info[5].info+'</a></li>'
443 htmlNodes_dev_info += '<li class="list-group-item" align="center">WIREIP :' + dev_info[6].info+'</a></li>'
444 htmlNodes_dev_info += '<li class="list-group-item" align="center">MAC :' + dev_info[7].info+'</a></li>'
445
446 $('#dev_info_show').html(htmlNodes_dev_info);
447}
448
449function stop_swupdate(){
450 send_command("endswupdate");
451}
452//-----------Swupdate handle end-----------//
453
454/***********************************************
455 * Soundbar handle
456 **********************************************/
457function send_audio_command(command, callback,cgi)
458{
459 var cgi = cgi || "cgi-bin/soundbar.cgi";
460 command_xmlhttp = GetXmlHttpObject(); //create req obj
461 command_xmlhttp.onreadystatechange = function () { //get data from web action
462 handleCommand(command_xmlhttp, callback);
463 }
464 var url = "";
465 url = cgi + "?command=" +command;
466 command_xmlhttp.open("GET",url,true);
467 command_xmlhttp.setRequestHeader("If-Modified-Since","0");
468 command_xmlhttp.setRequestHeader("Cache-Control","no-cache");
469 command_xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
470 command_xmlhttp.send(null);
471}
472
473function get_audio_input_list()
474{
475 var wifi_json = send_audio_command("showinput&", set_input_list_to_select);
476 show_loading();
477 setTimeout(function () { $('#loading').hide(); }, 3000);
478}
479
480function set_audio_input()
481{
482 setTimeout(function(){$("#mymodal").modal("hide")},2000);
483 var input_ssid = document.getElementById("modal_ssid").value;
484 var wifi_json = send_audio_command("enable-input&value="+input_ssid, set_input_list_to_select);
485
486 //set_wifi(input_ssid,input_pwd);
487}
488
489function set_input_list_to_select(command_xmlhttp)
490{
491 var response_date = command_xmlhttp.responseText;
492
493 obj_Data = eval("("+response_date+")");
494 if(obj_Data.length == 0){
495 get_audio_input_list();
496 }
497 else{
498 var htmlNodes = '';
499
500 for(var i = 0; i < obj_Data.length; i++){
501 if(obj_Data[i].enabled)
502 htmlNodes += '<a class="list-group-item" id="input_' + i + '"' + ' role="button" data-toggle="modal" data-target="#myModal">' + obj_Data[i].name + ' *' + '</a>';
503 else
504 htmlNodes += '<a class="list-group-item" id="input_' + i + '"' + ' role="button" data-toggle="modal" data-target="#myModal">' + obj_Data[i].name + '</a>';
505 }
506 htmlNodes += '</ul>';
507
508 $('#testtext').html(htmlNodes);
509
510 var j;
511 var index = 1;
512 var wifi_select = document.getElementById("ssid");
513 for(j = 0; j < obj_Data.length; j++){
514 var wifi = new Object;
515 wifi.ssid = obj_Data[j].name;
516 //wifi_select.Option.add(wifi.id);
517 }
518 }
519 get_audio_system_info()
520}
521
522$("#audiovolume")[0].oninput = function(){
523 change_audio_volume(this.value);
524}
525
526function change_audio_volume(audiovolume)
527{
528 var wifi_json = send_audio_command("set-volume&value="+audiovolume);
529}
530
531
532function update_audio_system_info(command_xmlhttp)
533{
534 var response_date = command_xmlhttp.responseText;
535
536 obj_Data = eval("("+response_date+")");
537 if(obj_Data.length == 0){
538 get_audio_system_info();
539 }
540 else{
541 // <input id="audiovolume" type="range" min="0" max="100" value="60" />
542 for(var i = 0; i < obj_Data.length; i++){
543 if(obj_Data[i].name == "volume"){
544 var audiovolumetest = document.getElementById("audiovolume");
545 audiovolumetest.value = obj_Data[i].value;
546 } else if(obj_Data[i].name == "mute"){
547 var audiomute = document.getElementById("audiomute");
548 audiomute.checked = obj_Data[i].value;
549 } else if(obj_Data[i].name == "eq_status"){
550 var eqstatus = document.getElementById("eq_status");
551 eqstatus.checked = obj_Data[i].value;
552 } else if(obj_Data[i].name == "eq1"){
553 var eq = document.getElementById("eqi1");
554 eq.value = obj_Data[i].value;
555 } else if(obj_Data[i].name == "eq2"){
556 var eq = document.getElementById("eqi2");
557 eq.value = obj_Data[i].value;
558 } else if(obj_Data[i].name == "eq3"){
559 var eq = document.getElementById("eqi3");
560 eq.value = obj_Data[i].value;
561 } else if(obj_Data[i].name == "eq4"){
562 var eq = document.getElementById("eqi4");
563 eq.value = obj_Data[i].value;
564 } else if(obj_Data[i].name == "eq5"){
565 var eq = document.getElementById("eqi5");
566 eq.value = obj_Data[i].value;
567 } else if(obj_Data[i].name == "eq6"){
568 var eq = document.getElementById("eqi6");
569 eq.value = obj_Data[i].value;
570 } else if(obj_Data[i].name == "eq7"){
571 var eq = document.getElementById("eqi7");
572 eq.value = obj_Data[i].value;
573 } else if(obj_Data[i].name == "eq7"){
574 var eq = document.getElementById("eqi7");
575 eq.value = obj_Data[i].value;
576 } else if(obj_Data[i].name == "eq8"){
577 var eq = document.getElementById("eqi8");
578 eq.value = obj_Data[i].value;
579 } else if(obj_Data[i].name == "eq9"){
580 var eq = document.getElementById("eqi9");
581 eq.value = obj_Data[i].value;
582 } else if(obj_Data[i].name == "eq10"){
583 var eq = document.getElementById("eqi10");
584 eq.value = obj_Data[i].value;
585 } else if(obj_Data[i].name == "eq11"){
586 var eq = document.getElementById("eqi11");
587 eq.value = obj_Data[i].value;
588 } else if(obj_Data[i].name == "eq12"){
589 var eq = document.getElementById("eqi12");
590 eq.value = obj_Data[i].value;
591 }
592 }
593 }
594 //check_wifi_connected();
595}
596
597function get_audio_system_info()
598{
599 var wifi_json = send_audio_command("getsysteminfo&", update_audio_system_info);
600}
601
602function set_audio_mute()
603{
604 var audio_mute = document.getElementById("audiomute").checked;
605 var wifi_json = send_audio_command("set-mute&value="+audio_mute);
606
607 //set_wifi(input_ssid,input_pwd);
608}
609
610
611
612function audio_reset_eq()
613{
614 var wifi_json = send_audio_command("reset-EQ&");
615 get_audio_system_info();
616}
617
618//$("#eqi1")[0].oninput = function(){
619// var wifi_json = send_audio_command("set-eq1&value="+this.value);
620//}
621
622function change_audio_equalizer(index, eq)
623{
624 var wifi_json = send_audio_command("set-eq"+index+"&value="+eq);
625}
626
627function audio_dataplay_play()
628{
629 var playstate = document.getElementById("audioplaystate");
630 var format = document.getElementById("audioplayformat");
631 if(playstate.value == "Play") {
632 send_audio_command("dataplay-start&value="+format.value);
633 playstate.value = "Stop"
634 } else if(playstate.value == "Stop") {
635 send_audio_command("dataplay-stop&");
636 playstate.value = "Play"
637 }
638}
639
640function set_audio_EQEnabled()
641{
642 var enabled = document.getElementById("eq_status").checked;
643 var wifi_json = send_audio_command("set-EQ&value="+enabled);
644 //set_wifi(input_ssid,input_pwd);
645}
646//-----------Soundbar handle end-----------//