You are right. Now when I understood predis-async and React a bit better, I got this working in no time.
Maybe the parts below helps others too while waiting for the better documentation from cboden.
Important bits from from my main (creating app and loop):
...
$loop = React\EventLoop\Factory::create();
$pubSubApp = new OpenPubSubRedis($di); // This is my own app, like $pusher in Ratchet tutorials.
$client->connect(array($pubSubApp, 'initRedisConnection'));
$webSock = new React\Socket\Server($loop);
$webSock->listen(8183, '0.0.0.0');
$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Ratchet\Wamp\WampServer(
$pubSubApp
)
)
),
$webSock
);
...
And from my OpenPubSubRedis initialized above class (connecting and handling incoming payloads from redis):
...
public function initRedisConnection(\Predis\Async\Client $redisClient)
{
$this->redisClient = $redisClient;
$channel = 'events-to-ws-pubsub';
$this->redisClient->pubSubLoop(
$channel,
array(
$this,
'onPublishEventFromRedis'
)
);
}
public function onPublishEventFromRedis($event, $pubsub)
{
//var_dump($event);
echo "Kind: $event->kind Channel: $event->channel Payload: $event->payload\n";
// find topic, broadcast and stuff or what ever you want to do.
}
...
Thanks once again cboden! Good stuff with Ratchet!
Cheers,
--
Tuomas