Advertisement
Guest User

JS

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