Reset ping timer when reset command is called
authorGiannis Kosmas <kosmas@lib.uoc.gr>
Wed, 3 Aug 2011 18:41:13 +0000 (21:41 +0300)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 9 Aug 2011 07:40:37 +0000 (09:40 +0200)
js/pz2.js

index c256800..50ecd01 100644 (file)
--- a/js/pz2.js
+++ b/js/pz2.js
@@ -91,6 +91,7 @@ var pz2 = function ( paramArray )
     this.currRecOffset = null;
 
     //timers
+    this.pingTimer = null;
     this.statTime = paramArray.stattime || 1000;
     this.statTimer = null;
     this.termTime = paramArray.termtime || 1000;
@@ -158,6 +159,7 @@ pz2.prototype =
             this.sessionID = null;
             this.initStatusOK = false;
             this.pingStatusOK = false;
+            clearTimeout(this.pingTimer);
         }
         this.searchStatusOK = false;
         this.stop();
@@ -196,12 +198,13 @@ pz2.prototype =
                         context.sessionID = 
                             data.getElementsByTagName("session")[0]
                                 .childNodes[0].nodeValue;
-                        setTimeout(
-                            function () {
-                                context.ping();
-                            },
-                            context.keepAlive
-                        );
+                        context.pingTimer =
+                            setTimeout(
+                                function () {
+                                    context.ping();
+                                },
+                                context.keepAlive
+                            );
                         if ( context.initCallback )
                             context.initCallback();
                     }
@@ -224,6 +227,9 @@ pz2.prototype =
             'Pz2.js: Ping not allowed (proxy mode) or session not initialized.'
             );
         var context = this;
+
+        clearTimeout(context.pingTimer);
+
         var request = new pzHttpRequest(this.pz2String, this.errorHandler);
         request.safeGet(
             { "command": "ping", "session": this.sessionID, "windowid" : window.name },
@@ -231,12 +237,13 @@ pz2.prototype =
                 if ( data.getElementsByTagName("status")[0]
                         .childNodes[0].nodeValue == "OK" ) {
                     context.pingStatusOK = true;
-                    setTimeout(
-                        function () {
-                            context.ping();
-                        }, 
-                        context.keepAlive
-                    );
+                    context.pingTimer =
+                        setTimeout(
+                            function () {
+                                context.ping();
+                            },
+                            context.keepAlive
+                        );
                 }
                 else
                     context.throwError('Ping failed. Malformed WS resonse.',