diff --git a/app/Http/Controllers/Site/PriceStreamController.php b/app/Http/Controllers/Site/PriceStreamController.php index bea6706..4c6c7ed 100644 --- a/app/Http/Controllers/Site/PriceStreamController.php +++ b/app/Http/Controllers/Site/PriceStreamController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Site; use App\Http\Controllers\Controller; use App\Services\AssetSummaryService; +use App\Services\CustomerPresenceService; use App\Services\LivePriceCacheService; use App\Services\PriceBroadcastService; use App\Services\PriceStreamService; @@ -45,6 +46,11 @@ class PriceStreamController extends Controller @flush(); }; + $presence = app(CustomerPresenceService::class); + if ($customerId > 0) { + $presence->touch($customerId, true); + } + $cache = app(LivePriceCacheService::class); $last = $cache->get() ?? $cache->buildFromDatabase(); if (is_array($last) && $last !== []) { @@ -91,6 +97,9 @@ class PriceStreamController extends Controller // هر ۵ ثانیه — LiteSpeed/پروکسی اتصال بیکار را نمی‌بندد if ($heartbeatTicks >= 10) { $send('ping', ['ts' => time()]); + if ($customerId > 0) { + $presence->touch($customerId); + } $heartbeatTicks = 0; } diff --git a/app/Services/CustomerPresenceService.php b/app/Services/CustomerPresenceService.php new file mode 100644 index 0000000..315b133 --- /dev/null +++ b/app/Services/CustomerPresenceService.php @@ -0,0 +1,41 @@ +where('id', $customerId) + ->update(['last_seen_at' => now()]); + } catch (\Throwable $e) { + // استریم قیمت نباید به‌خاطر presence بمیرد + report($e); + } + } +}