Closed J7mbo closed 6 years ago
A couple of things:
Connection
object is just a wrapper around Client
and mainly exists to give familiarity with those people using autobahn.js. It is generally better to just use the Client
.Connection->open()
call is hanging because it is starting the loop at that spot. You can pass false as a parameter to tell the loop to delay starting until later: $connection->open(false);
You can implement what you are trying to do by extending Client
:
class EventHandler extends Client implements RealmModuleInterface
{
public function getSubscribedRealmEvents()
{
return [
'SubscribeMessageEvent' => ['onSubscribe', 100]
];
}
public function onSubscribe(MessageEvent $event)
{
echo "Got subscribed event...\n";
$clientSession = $this->getSession();
if ($clientSession) {
/** @var SubscribeMessage $subscribeMessage */
$subscribeMessage = $event->message;
$clientSession->publish(
'some.topic',
[$event->session->getSessionId() . ' just subscribed to ' . $subscribeMessage->getTopicName()]
);
}
}
}
With the bootstrap:
$loop = Factory::create();
$router = new \Thruway\Peer\Router($loop);
$transport = new \Thruway\Transport\RatchetTransportProvider('0.0.0.0', 1338);
$router->addTransportProvider($transport);
$realmModule = new EventHandler('realm1', $loop);
$router->addInternalClient($realmModule);
$router->getRealmManager()->getRealm('realm1')->addModule($realmModule);
$router->start();
If you are looking to keep track of subscriptions, you may want to look at https://github.com/voryx/ThruwaySubscriptionMeta.
Very simply, I'm trying to have
onSubscribe
and be able to actually handle the broadcasting of data when I require, likely usingLoopInterface::addPeriodicTimer
. Regardless, when I try creating a connection within thisRealmModuleInterface
instance, it hangs on "Starting Transport". FTR, I'm doing this in a docker container.Then, when trying to subscribe with autobahn.js very simply (just a one line
session.subscribe()
call so omitted for brevity), it causes the hang:Here's the debug output:
Also, here's my bootstrap code:
What am I doing wrong?