X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=js%2Fcomet.js;fp=js%2Fcomet.js;h=976c5fce2399d830ea141651d79686357ca7decd;hb=79f0cfc91b7220d98e4caf50fbb3857807fc6bc4;hp=8c427c978bf44f96cfa202723b8982cbe9e0b6e3;hpb=afc7c6e84fac05e989a208f72538e6a55daa758f;p=euphorik.git diff --git a/js/comet.js b/js/comet.js index 8c427c9..976c5fc 100644 --- a/js/comet.js +++ b/js/comet.js @@ -46,10 +46,10 @@ Comet = function(page, version) { this.page = page; this.version = version; - + // l'objet JSONHttpRequest représentant la connexion d'attente this.attenteCourante = undefined; - + // le multhreading du pauvre, merci javascript de m'offrire autant de primitives pour la gestion de la concurrence... this.stop = false; }; @@ -59,14 +59,14 @@ Comet = function(page, version) { */ Comet.prototype.stopAttenteCourante = function() { this.stop = true; - + if (this.attenteCourante) { this.attenteCourante.abort(); } }; /** - * Attend un événement lié à la page. Non-bloquant. + * Attend un événement lié à la page. Non-bloquant. * @funSend une fonction renvoyant les données json à envoyer * @funsReceive est un objet comprenant les fonctions à appeler en fonction du "reply" * les fonctions acceptent un paramètre correspondant au données reçues. @@ -74,11 +74,11 @@ Comet.prototype.stopAttenteCourante = function() { */ Comet.prototype.waitEvent = function(funSend, funsReceive) { this.stopAttenteCourante(); - + this.stop = false; - + var thisComet = this; - + // on doit conserver l'ordre des valeurs de l'objet JSON (le serveur les veut dans l'ordre définit dans le protocole) // TODO : ya pas mieux ? var dataToSend = { @@ -89,7 +89,7 @@ Comet.prototype.waitEvent = function(funSend, funsReceive) { objectEach(poulpe, function(k, v) { dataToSend[k] = v; }); - + this.attenteCourante = jQuery.ajax({ type: "POST", url: "request", @@ -100,13 +100,13 @@ Comet.prototype.waitEvent = function(funSend, funsReceive) { success: function(data) { funsReceive[data.reply](data); - + // rappel de la fonction dans 100 ms setTimeout(function(){ thisComet.waitEvent2(funSend, funsReceive); }, 100); }, error: function(XMLHttpRequest, textStatus, errorThrown) { - ;; console.log("Connexion perdue dans Comet.prototype.waitEvent() : \n" + textStatus); + // console.log("Connexion perdue dans Comet.prototype.waitEvent() : \n" + textStatus); setTimeout(function(){ thisComet.waitEvent2(funSend, funsReceive); }, 1000); } }); @@ -120,4 +120,4 @@ Comet.prototype.waitEvent2 = function(funSend, funsReceive) { return; } this.waitEvent(funSend, funsReceive); -}; \ No newline at end of file +};