Browse Source

Add test case for issue #77

bel 10 years ago
parent
commit
4c37ed9e27
1 changed files with 30 additions and 1 deletions
  1. 30 1
      test/websocket.xhtml

+ 30 - 1
test/websocket.xhtml

@@ -20,6 +20,27 @@
     var hand_hour;
     var hand_min;
 
+    function queryStringElem(name, idx) {
+      if (typeof(queryStringElem_Table) != "object") {
+        queryStringElem_Table = {};
+        window.location.search.slice(1).split('&').forEach(
+          function(keyValuePair) {
+            keyValuePair = keyValuePair.split('=');
+            if (typeof(queryStringElem_Table[keyValuePair[0]]) != "object") {
+              queryStringElem_Table[keyValuePair[0]] = [];
+            }
+            var idx = queryStringElem_Table[keyValuePair[0]].length+1;
+            queryStringElem_Table[keyValuePair[0]][idx] = keyValuePair[1] || '';
+          }
+        );
+      }
+      idx = idx || 1;
+      if (queryStringElem_Table[name]) {
+        return queryStringElem_Table[name][idx];
+      }
+      return null;
+    }
+
     function webSockKeepAlive() {
       if (keepAlive) {
         connection.send('client still alive');
@@ -35,8 +56,16 @@
       hand_min = document.getElementById('hand_min');
       hand_hour = document.getElementById('hand_hour');
 
+      var ka = queryStringElem("keepAlive");
+      if (ka) {
+        use_keepAlive = (ka.toLowerCase()!="false") && (ka.toLowerCase()!=0);
+      } else {
+        use_keepAlive = true;
+      }
+
       connection.onopen = function () {
-        keepAlive = true;
+        keepAlive = use_keepAlive;
+        alert(keepAlive);
         webSockKeepAlive();
       };