Polling 'record' based on new 'activeclients' in pazpar2
[pazpar2-moved-to-github.git] / js / pz2.js
index 53c0c2a..f290eec 100644 (file)
--- a/js/pz2.js
+++ b/js/pz2.js
@@ -98,6 +98,8 @@ var pz2 = function ( paramArray )
     this.showFastCount = 4;
     this.bytargetTime = paramArray.bytargettime || 1000;
     this.bytargetTimer = null;
+    this.recordTime = paramArray.recordtime || 500;
+    this.recordTimer = null;
 
     // counters for each command and applied delay
     this.dumpFactor = 500;
@@ -105,6 +107,7 @@ var pz2 = function ( paramArray )
     this.termCounter = 0;
     this.statCounter = 0;
     this.bytargetCounter = 0;
+    this.recordCounter = 0;
 
     // active clients, updated by stat and show
     // might be an issue since bytarget will poll accordingly
@@ -490,7 +493,7 @@ pz2.prototype =
            recordParams,
             function(data) {
                 var recordNode;
-                var record;
+                var record;                                
                 //raw record
                 if (context.currRecOffset !== null) {
                     record = new Array();
@@ -511,7 +514,21 @@ pz2.prototype =
                     //parse record
                     } else {
                         record = Element_parseChildNodes(recordNode);
-                    }                    
+                    }    
+                   var activeClients = 
+                      Number( data.getElementsByTagName("activeclients")[0]
+                               .childNodes[0].nodeValue );
+                   context.activeClients = activeClients; 
+                    context.recordCounter++;
+                    var delay = context.recordTime + context.recordCounter * context.dumpFactor;
+                    if ( activeClients > 0 )
+                        context.recordTimer = 
+                           setTimeout ( 
+                               function() {
+                                  context.record(id, offset, syntax, handler);
+                                  },
+                                  delay
+                               );                                    
                     callback(record, args);
                 }
                 else