planetteamspeak / ts3phpframework

Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
https://www.planetteamspeak.com
GNU General Public License v3.0
211 stars 59 forks source link

Getting timeout for function onTextmessage() #211

Open MitoCodeGithub opened 1 year ago

MitoCodeGithub commented 1 year ago

Hi,

I used the example of Creating a simple bot that listens for events but when I write to the bot I always get a timeout on my website.

$ts3->notifyRegister("textprivate");

TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyTextmessage", "onTextmessage");
$ts3->clientGetByName("Mito")->message("Write to me");
while(1) $ts3->getAdapter()->wait();
function onTextmessage(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host) {
    echo "Client " . $event["invokername"] . " sent textmessage: " . $event["msg"];
}

I'm using Cloudflare, could that be the problem?

Sebbo94BY commented 4 months ago

Hey @MitoCodeGithub, it seems like as you missed to setup the timeout handling in your code:

$ts3->notifyRegister("textprivate");

TeamSpeak3_Helper_Signal::getInstance()->subscribe("notifyTextmessage", "onTextmessage");

TeamSpeak3_Helper_Signal::getInstance()->subscribe('serverqueryWaitTimeout', "onWaitTimeout");

$ts3->clientGetByName("Mito")->message("Write to me");
while(1) $ts3->getAdapter()->wait();
function onTextmessage(TeamSpeak3_Adapter_ServerQuery_Event $event, TeamSpeak3_Node_Host $host) {
    echo "Client " . $event["invokername"] . " sent textmessage: " . $event["msg"];
}

function onWaitTimeout(int $idle_seconds, ServerQuery $serverquery)
{
    if ($serverquery->getQueryLastTimestamp() < time() - 260) {
        echo 'Sending keep-alive.';
        $serverquery->request('clientupdate');
    }
}

If you don't handle the timeouts, the connection will timeout after the default 300 seconds (5 minutes).

I don't know, how you have implemented this feature into your website, so I can't tell you what you need to change to avoid any kind of timeouts on the website. The above code will only avoid timeouts of the bot itself, when nothing happens for a specific time.