added assets into stream

This commit is contained in:
2026-06-27 15:51:44 +03:30
parent a0b3d8d3f5
commit 7b05db0ff0
6 changed files with 170 additions and 16 deletions
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Site;
use App\Http\Controllers\Controller;
use App\Services\AssetSummaryService;
use App\Services\LivePriceCacheService;
use App\Services\PriceBroadcastService;
use App\Services\PriceStreamService;
@@ -19,7 +20,11 @@ class PriceStreamController extends Controller
abort(404);
}
return response()->stream(function () use ($service) {
$customer = auth('customer')->user();
$customerId = $customer ? (int) $customer->id : 0;
$customerOwnerType = $customer ? (int) $customer->type : 0;
return response()->stream(function () use ($service, $customerId, $customerOwnerType) {
@set_time_limit(0);
if (function_exists('apache_setenv')) {
@@ -50,6 +55,18 @@ class PriceStreamController extends Controller
$send('list', $list);
}
$customerLastId = 0;
if ($customerId > 0) {
$assets = app(AssetSummaryService::class)->buildForCustomer(
$customerId,
$customerOwnerType > 0 ? $customerOwnerType : 2
);
if ($assets !== []) {
$send('assets', $assets);
}
$customerLastId = $service->currentCustomerSeq($customerId);
}
$lastId = $service->currentSeq();
$heartbeatTicks = 0;
@@ -62,6 +79,13 @@ class PriceStreamController extends Controller
$lastId = (int) $event['id'];
}
if ($customerId > 0) {
foreach ($service->consumeCustomerSince($customerId, $customerLastId) as $event) {
$send((string) $event['event'], $event['data']);
$customerLastId = (int) $event['id'];
}
}
$heartbeatTicks++;
// هر ۵ ثانیه — LiteSpeed/پروکسی اتصال بیکار را نمی‌بندد
if ($heartbeatTicks >= 10) {