II kam up mit Art und Weise, das zu tun. ich bin sicher, dass es nicht richtig ist, aber funktioniert.
ich globale Array für alle Verbindungen
private $globals = array();
Und jetzt mache ich s gemacht omething wie folgt aus:
public function onPublish(ConnectionInterface $connection, Topic $topic, WampRequest $request, $event, array $exclude, array $eligible)
{
$user = $this->clientManipulator->getClient($connection);
/* Saving current session to global array
* $event returns form data sent in json format
*/
if ($topic->getId() === 'chat/global/waiting-room'){
$this->globals[$connection->WAMP->sessionId] = $event;
$this->globals[$connection->WAMP->sessionId]['id'] = $connection->WAMP->sessionId;
}
}
Jetzt bin ich gebrauchte Perodic Timer wie folgt aus:
public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request)
{
## global data:
$topicTimer = $connection->PeriodicTimer;
$allMembers = $this->clientManipulator->getAll($topic, true);
$user = $this->clientManipulator->getClient($connection);
$userSessionId = $connection->WAMP->sessionId;
if ($topic->getId() === 'chat/global/waiting-room'){
$userData = $this->globals[$connection->WAMP->sessionId];
## Set timer every 5 seconds
if(!$this->periodicTimer->isPeriodicTimerActive($this, 'getPair-'.$userSessionId)){
$this->periodicTimer->addPeriodicTimer($this, 'getPair-'.$userSessionId, 5, function() use ($userData, $userSessionId, $topic) {
## my own method for pair searching in $this->globals;
$pair = $this->findPairForCurrentUser($userSessionId);
if(NULL !== $pair)
{
#Send info to Two people about room and do redirect in jquery.
$topic->broadcast(
array(
'msg' => 'We did it! Connecting now...',
'room' => array(
'slug' => uniqid("room"),
'id' => rand(0,1923)
)
),
array(),
array(
$userData['id'],
$pair
)
);
# Remove perodic timer :)
$this->periodicTimer->cancelPeriodicTimer($this, 'getPair-'.$userSessionId);
}
});
}
}
- FAZIT:
- Haupt-ID für erfassen Personen aktuellen websocket Session-ID ist.
- globaler Array, in dem KEY aktuelle ws Session-ID ist Formulardaten Umgang
- Jede Verbindung neue Perodic Timer startet als "getPair-" + aktuelle ws Session-ID
- Bei disconnect Ich überprüfe, dass die globale Array mit Strom ws Sitzungs-ID ist festgelegt. Wenn ja, zerstöre.