Skip to content

Commit

Permalink
Solution for issue #54 (#58)
Browse files Browse the repository at this point in the history
* Solution for issue #54

* Use the message's channel name to get the replay id

* Confirmed, use the subscription name for sending

* Clean the query string from the channel name, if one exists
  • Loading branch information
Alex Boyce authored Aug 15, 2019
1 parent e7d79a6 commit 0c8f921
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/Bayeux/Extension/ReplayExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,26 @@ public function getReplayIdForChannel(string $channelName)
return array_key_exists($channelName, $this->dataMap) ? $this->dataMap[$channelName] : $this->replayId;
}

/**
* @param string $channelName
* @param int $replayId
*
* @return ReplayExtension
*/
public function setReplayIdForChannel(string $channelName, int $replayId = self::REPLAY_NEWEST): self
{
$this->dataMap[$channelName] = $replayId;

return $this;
}

/**
* @param Message $message
*/
public function prepareSend(Message $message): void
{
if ($message->getChannel() === ChannelInterface::META_SUBSCRIBE) {
$ext = $message->getExt() ?: [];
$ext = $message->getExt() ?: [];
$ext[static::NAME] = [
$message->getSubscription() => $this->getReplayIdForChannel($message->getSubscription()),
];
Expand Down Expand Up @@ -94,7 +107,14 @@ public function processReceive(Message $message): void
*/
protected function persistReplayId(Message $message)
{
$event = $message->getData()->getEvent();
$this->dataMap[$message->getChannel()] = $event->getReplayId();
$event = $message->getData()->getEvent();
$channelName = $message->getChannel();

// Strip the query string, if one exists
if (false !== ($pos = strpos($channelName, '?'))) {
$channelName = substr($channelName, 0, $pos);
}

$this->setReplayIdForChannel($channelName, $event->getReplayId());
}
}

0 comments on commit 0c8f921

Please sign in to comment.