[Phpfreechat-svn] SF.net SVN: phpfreechat: [1185] trunk
Status: Beta
Brought to you by:
kerphi
From: <ke...@us...> - 2007-09-07 17:28:28
|
Revision: 1185 http://phpfreechat.svn.sourceforge.net/phpfreechat/?rev=1185&view=rev Author: kerphi Date: 2007-09-07 09:43:34 -0700 (Fri, 07 Sep 2007) Log Message: ----------- - remove the unused max_refresh_delay parameter - simplify the ajax request handling Modified Paths: -------------- trunk/data/public/js/pfcclient.js trunk/src/pfcglobalconfig.class.php trunk/themes/default/chat.js.tpl.php Modified: trunk/data/public/js/pfcclient.js =================================================================== --- trunk/data/public/js/pfcclient.js 2007-09-07 15:06:54 UTC (rev 1184) +++ trunk/data/public/js/pfcclient.js 2007-09-07 16:43:34 UTC (rev 1185) @@ -44,7 +44,6 @@ this.timeout = null; this.refresh_delay = pfc_refresh_delay; - this.max_refresh_delay = pfc_max_refresh_delay; this.last_response_time = new Date().getTime(); this.last_request_time = new Date().getTime(); @@ -191,13 +190,6 @@ trace('handleResponse: '+cmd + "-"+resp+"-"+param); } - // store the new refresh time - this.last_response_time = new Date().getTime(); - - // calculate the ping and display it - this.ping = this.last_response_time - this.last_request_time; - if ($('pfc_ping')) $('pfc_ping').innerHTML = this.ping+'ms'; - if (cmd == "connect") { if (resp == "ok") @@ -1027,6 +1019,9 @@ */ sendRequest: function(cmd, recipientid) { + // do not send another ajax requests if the last one is not yet finished + if (cmd == '/update' && this.pfc_ajax_connected) return; + if (cmd != "/update") { // setup a new timeout to update the chat in 5 seconds (in refresh_delay more exactly) @@ -1036,12 +1031,42 @@ if (pfc_debug) trace('sendRequest: '+cmd); } - - this.last_request_time = new Date().getTime(); + + // prepare the command string var rx = new RegExp('(^\/[^ ]+) *(.*)','ig'); if (!recipientid) recipientid = this.gui.getTabId(); cmd = cmd.replace(rx, '$1 '+this.clientid+' '+(recipientid==''?'0':recipientid)+' $2'); - return pfc_handleRequest(cmd); //eval('pfc_handleRequest(cmd);'); + + // send the real ajax request + var url = pfc_server_script_url; + var params = $H(); + params['pfc_ajax'] = 1; + params['f'] = 'handleRequest'; + params['cmd'] = cmd; + new Ajax.Request(url, { + method: 'post', + parameters: params, + onCreate: function(transport) { + this.pfc_ajax_connected = true; + // request time counter used by ping indicator + this.last_request_time = new Date().getTime(); + }.bind(this), + onSuccess: function(transport) { + if (!transport.status) return; // fix strange behavior on KHTML + + // request time counter used by ping indicator + this.last_response_time = new Date().getTime(); + // evaluate the javascript response + eval( transport.responseText ); + }.bind(this), + onComplete: function(transport) { + this.pfc_ajax_connected = false; + + // calculate the ping and display it + this.ping = Math.abs(this.last_response_time - this.last_request_time); + if ($('pfc_ping')) $('pfc_ping').innerHTML = this.ping+'ms'; + }.bind(this) + }); }, /** Modified: trunk/src/pfcglobalconfig.class.php =================================================================== --- trunk/src/pfcglobalconfig.class.php 2007-09-07 15:06:54 UTC (rev 1184) +++ trunk/src/pfcglobalconfig.class.php 2007-09-07 16:43:34 UTC (rev 1185) @@ -161,14 +161,6 @@ * (Default value: 5000 - 5,000ms = 5 seconds)</p> */ var $refresh_delay = 5000; - - /** - * <p>Indicate the maximum number of seconds to wait before the server response. - * If the latest refresh command is not received in this delay an other one will be created. - * This parameter is not implemented in the current version of phpfreechat. - * (Default value: 60000 - 60,000ms = 60 seconds)</p> - */ - var $max_refresh_delay = 60000; /** * <p>This is the time of inactivity to wait before a user is disconnected (in milliseconds). Modified: trunk/themes/default/chat.js.tpl.php =================================================================== --- trunk/themes/default/chat.js.tpl.php 2007-09-07 15:06:54 UTC (rev 1184) +++ trunk/themes/default/chat.js.tpl.php 2007-09-07 16:43:34 UTC (rev 1185) @@ -24,7 +24,6 @@ var pfc_clientid = <?php echo $json->encode(md5(uniqid(rand(), true))); ?>; var pfc_title = <?php echo $json->encode($title); ?>; var pfc_refresh_delay = <?php echo $json->encode($refresh_delay); ?>; -var pfc_max_refresh_delay = <?php echo $json->encode($max_refresh_delay); ?>; var pfc_start_minimized = <?php echo $json->encode($start_minimized); ?>; var pfc_nickmarker = <?php echo $json->encode($nickmarker); ?>; var pfc_clock = <?php echo $json->encode($clock); ?>; @@ -51,8 +50,9 @@ var pfc_nickname_color_list = <?php echo $json->encode($nickname_colorlist); ?>; var pfc_theme = <?php echo $json->encode($theme); ?>; var pfc_isready = false; +var pfc_server_script_url = <?php echo $json->encode($c->server_script_url); ?>; -/* prototype ajax config */ +// todo : move this code in pfcClient function pfc_loadChat() { var url = '<?php echo $c->server_script_url; ?>'; var params = $H(); @@ -66,22 +66,7 @@ } }); } -function pfc_handleRequest(cmd) { - var url = '<?php echo $c->server_script_url; ?>'; - var params = $H(); - params['pfc_ajax'] = 1; - params['f'] = 'handleRequest'; - params['cmd'] = cmd; - new Ajax.Request(url, { - method: 'get', - parameters: params, - onSuccess: function(transport) { - eval( transport.responseText ); - } - }); -} - window.onload = function () { pfc = new pfcClient(); if (pfc_isready) pfc_loadChat(pfc_theme); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |