Advertisement
Guest User

JS

a guest
Feb 15th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!--
  2.  
  3. var fps = 30;
  4. var quality = 30;
  5. var timeout = 33;
  6. var baseURL = "{$url}";
  7. var xmlHttpOk = "{$xmlHttpOk}";
  8. var t_;
  9. var i_;
  10. var ct_;
  11. var id;
  12. var xmlHttp;
  13. var firstReq=true;
  14. var state = "null";
  15.  
  16. function showErrorImage()
  17. {
  18.     clearTimeout(t_);
  19.     clearInterval(i_);
  20.     document.images.cctv.onload = "";
  21.     document.images.cctv.src = "offline.jpg";
  22. }
  23.  
  24. function showStatusImage(imgUrl)
  25. {
  26.     clearTimeout(t_);
  27.     clearInterval(i_);
  28.     document.images.cctv.onload = "";
  29.     document.images.cctv.src = imgUrl;
  30. }
  31.  
  32. function reloadImage()
  33. {
  34.     var theDate = new Date();
  35.     var url = baseURL;
  36.     url += "&time=";
  37.     url += theDate.getTime();
  38.     document.images.cctv.src = url;  
  39. }
  40.  
  41. function fixImageTimeout()
  42. {
  43.     t_ = setTimeout("reloadImage();",timeout);
  44. }
  45.  
  46. function cTO()
  47. {
  48.     if(state=="running")
  49.     {
  50.         clearTimeout(t_);
  51.         reloadImage();
  52.     }
  53. }
  54.  
  55.  
  56.  
  57. function startPoll()
  58. {
  59.     document.images.cctv.onload=fixImageTimeout
  60.     fixConnectTimeout();
  61.     getStatus();    
  62. }
  63.  
  64. function fixStatusTimeout()
  65. {
  66.     ts_ = setTimeout("getStatus();",2000);
  67. }
  68.  
  69. function fixConnectTimeout()
  70. {
  71.     ct_ = setTimeout("showErrorImage();",45000);
  72. }
  73.  
  74. function getStatus()
  75. {
  76.     xmlHttp=GetXmlHttpObject()
  77.     if(xmlHttp==null)
  78.     {
  79.         alert("Browser does not support HTTP Request")
  80.         return
  81.     }
  82.     var url= xmlHttpOk
  83.     xmlHttp.onreadystatechange=stateChanged
  84.     xmlHttp.open("GET",url,true)
  85.     xmlHttp.send(null)
  86. }
  87.  
  88. function sendPass()
  89. {
  90.     xmlHttp=GetXmlHttpObject()
  91.     if(xmlHttp==null)
  92.     {
  93.         alert("Browser does not support HTTP Request")
  94.         return
  95.     }
  96.     var user = document.getElementById('user').value;
  97.     var pass = document.getElementById('pass').value;
  98.     var url=baseURL+"get?id="+id+"&u="+user+"&p="+pass+"&r="+Math.random()
  99.     xmlHttp.onreadystatechange=stateChanged
  100.     xmlHttp.open("GET",url,true)
  101.     xmlHttp.send(null)
  102. }
  103.  
  104.  
  105. function stateChanged()
  106. {
  107.     if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  108.     {
  109.         if(xmlHttp.status==200)
  110.         {
  111.             if(xmlHttp.responseText=="ok")
  112.             {
  113.                 if(firstReq)
  114.                 {
  115.                     i_ = setInterval("getStatus();",2000);
  116.                     clearTimeout(ct_);
  117.                     //hideLayer('passLyr');
  118.                     firstReq=false;
  119.                     state="running";
  120.                     document.images.cctv.onload=fixImageTimeout
  121.                     reloadImage();                  
  122.                 }
  123.             }
  124.             else if(xmlHttp.responseText=="2many")
  125.             {
  126.                 clearTimeout(ct_);
  127.                 state="2many";
  128.                 showStatusImage("img/toomany.jpg");
  129.                 window.status = "Try later...";            
  130.             }
  131.             else if(xmlHttp.responseText=="banned")
  132.             {
  133.                 clearTimeout(ct_);
  134.                 state="banned";
  135.                 showStatusImage("img/banned.jpg");              
  136.                 window.status = "You are banned.";
  137.             }
  138.             else if(xmlHttp.responseText=="dataLimit")
  139.             {
  140.                 state="datalimit";
  141.                 showStatusImage("img/datalimit.jpg");
  142.                 window.status = "You hit data limit.";
  143.             }
  144.             else if(xmlHttp.responseText=="timeLimit")
  145.             {
  146.                 state="timelimit";
  147.                 showStatusImage("img/timelimit.jpg");
  148.                 window.status = "You hit time limit.";
  149.             }
  150.             else if(xmlHttp.responseText=="kicked")
  151.             {
  152.                 state="kicked";
  153.                 showStatusImage("img/kicked.jpg");
  154.                 window.status = "You are kicked.";
  155.             }
  156.             else if(xmlHttp.responseText=="passErr")
  157.             {
  158.                 state="passErr";
  159.                 document.getElementById('passHeading').innerHTML = '<font color="#FF0000">Login Error!</font>';
  160.                 window.status = "Login Error!";
  161.             }
  162.             else if(xmlHttp.responseText=="pass")
  163.             {
  164.                 clearTimeout(ct_);
  165.                 state="pass";
  166.                 showStatusImage("img/pass.jpg");
  167.                 setLyr(document.getElementById('cctv'),'passLyr',false,0);
  168.                 showLayer('passLyr');
  169.             }
  170.             else if(xmlHttp.responseText=="playing sound")
  171.             {
  172.                 /* Do nothing */
  173.             }
  174.             else if(xmlHttp.responseText=="playing sound failed")
  175.             {
  176.                 alert("Failed to play sound!");
  177.             }
  178.             else
  179.             {
  180.                 state="error";
  181.                 showErrorImage();
  182.                 window.status = "Error...";
  183.                 alert("Unknown response: "+xmlHttp.responseText);
  184.             }
  185.         }
  186.         else if (xmlHttp.status==404)
  187.         {
  188.             //alert("Got 404");
  189.         }
  190.     }
  191. }
  192.  
  193. function GetXmlHttpObject()
  194. {  
  195.     var XMLHttp_=null
  196.     try
  197.     {
  198.         XMLHttp_=new ActiveXObject("Msxml2.XMLHTTP")
  199.     }
  200.     catch(e)
  201.     {
  202.         try
  203.         {
  204.             XMLHttp_=new ActiveXObject("Microsoft.XMLHTTP")
  205.         }catch(e){}
  206.     }
  207.  
  208.     if (XMLHttp_==null)
  209.     {
  210.         XMLHttp_=new XMLHttpRequest()
  211.     }
  212.  
  213.     return XMLHttp_;
  214. }
  215.  
  216. -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement