-
Notifications
You must be signed in to change notification settings - Fork 300
Mod remove chatters
Because of differences in the way browsers handle windows being closed, there is no reliable way to automatically log out the last user in the chat room if they do not close chat properly by using the Logout button.
One option might be to add an AJAX request (with a logout command) to the unload event of the chat page, but you cannot be sure it will be send by the browser, and the unload event is also fired if you reload the page.
A better solution is to call the method to remove inactive users from the online list using the chat interface class. This method can be called from a custom script (e.g. from a page on your website or using a cron-job). To do this, you can add the following code to a page on your website (like the front page of your forum, index.php). This will timeout inactive users even when nobody is in chat.
function getChatInterface() { static $ajaxChat; if(!$ajaxChat) { // URL to the chat directory: if(!defined('AJAX_CHAT_URL')) { define('AJAX_CHAT_URL', './chat/'); } // Path to the chat directory: if(!defined('AJAX_CHAT_PATH')) { define('AJAX_CHAT_PATH', realpath(dirname($_SERVER['SCRIPT_FILENAME']).'/chat').'/'); } // Validate the path to the chat: if(@is_file(AJAX_CHAT_PATH.'lib/classes.php')) { // Include Class libraries: require_once(AJAX_CHAT_PATH.'lib/classes.php'); // Initialize the chat interface: $ajaxChat = new CustomAJAXChatInterface(); } } return $ajaxChat; } function removeInactiveChatUsers() { $chatInterface = getChatInterface(); if($chatInterface) { $chatInterface->removeInactive(); } }