The function TopicPeriodicTimerInterface::registerPeriodicTimer takes a Topic parameter, but once the first Topic registers a timer, it is not called for any additional Topic. Furthermore, if any one Topic has zero connections, any and all timers registered within the TopicInterface are cleared.
Example code
<?php
namespace App\Websocket\Topic;
use Gos\Bundle\WebSocketBundle\Topic\TopicPeriodicTimerInterface;
use Gos\Bundle\WebSocketBundle\Topic\TopicPeriodicTimerTrait;
use Ratchet\Wamp\Topic;
class AcmePeriodicTopic extends AcmeTopic implements TopicPeriodicTimerInterface
{
use TopicPeriodicTimerTrait;
public function registerPeriodicTimer(Topic $topic): void
{
// Adds the periodic timer the first time a client connects to the topic
$this->periodicTimer->addPeriodicTimer(
$this,
'hello',
300,
function () use ($topic) {
$topic->broadcast('Hello world');
}
);
}
/**
* Name of the topic.
*/
public function getName(): string
{
return 'acme.periodic.topic';
}
}
The root problem is that TopicPeriodicTimer::addPeriodicTimer doesn't take the Topic passed to TopicPeriodicTimerInterface::registerPeriodicTimer as a parameter.
Description
The function
TopicPeriodicTimerInterface::registerPeriodicTimer
takes aTopic
parameter, but once the firstTopic
registers a timer, it is not called for any additionalTopic
. Furthermore, if any oneTopic
has zero connections, any and all timers registered within theTopicInterface
are cleared.Example code
Steps
acme/foo
acme/foo
acme/bar
acme/bar
acme/bar
acme/foo