added wss tools 6
This commit is contained in:
@@ -45,17 +45,55 @@ class PriceBroadcastService
|
||||
$lastChanged = is_array($lastPayload) && $lastPayload !== []
|
||||
&& $this->rememberHashIfChanged(self::LAST_HASH_KEY, $lastPayload);
|
||||
|
||||
$listPayload = $this->buildProductListPayload();
|
||||
$listChanged = $listPayload !== null
|
||||
&& $this->rememberHashIfChanged(self::LIST_HASH_KEY, $listPayload);
|
||||
$this->publishListIfChanged();
|
||||
|
||||
if ($lastChanged) {
|
||||
if ($lastChanged && is_array($lastPayload)) {
|
||||
$stream->publish('last', $lastPayload);
|
||||
}
|
||||
}
|
||||
|
||||
if ($listChanged) {
|
||||
$stream->publish('list', $listPayload);
|
||||
public function broadcastLastIfChanged(?array $lastPayload): void
|
||||
{
|
||||
$stream = app(PriceStreamService::class);
|
||||
if (! $stream->isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! is_array($lastPayload) || $lastPayload === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->rememberHashIfChanged(self::LAST_HASH_KEY, $lastPayload)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$stream->publish('last', $lastPayload);
|
||||
}
|
||||
|
||||
public function broadcastListIfChanged(): bool
|
||||
{
|
||||
$stream = app(PriceStreamService::class);
|
||||
if (! $stream->isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->publishListIfChanged();
|
||||
}
|
||||
|
||||
private function publishListIfChanged(): bool
|
||||
{
|
||||
$listPayload = $this->buildProductListPayload();
|
||||
if ($listPayload === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->rememberHashIfChanged(self::LIST_HASH_KEY, $listPayload)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
app(PriceStreamService::class)->publish('list', $listPayload);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user