Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting timeout for function onTextmessage() #211

Open
MitoCodeGithub opened this issue Sep 23, 2023 · 1 comment
Open

Getting timeout for function onTextmessage() #211

MitoCodeGithub opened this issue Sep 23, 2023 · 1 comment
Labels
help wanted Help wanted from contributors for resolving issue.

Comments

@MitoCodeGithub
Copy link

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
Copy link
Collaborator

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.

@Sebbo94BY Sebbo94BY added the help wanted Help wanted from contributors for resolving issue. label Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Help wanted from contributors for resolving issue.
Projects
None yet
Development

No branches or pull requests

2 participants