@props(['session', 'teacher' => null]) @php $teacher = $teacher ?? sessionTeacher($session); $isLiveSessionTime = false; if ($session?->session_date && $session?->start_time && $session?->end_time) { $tz = config('app.timezone', 'Africa/Cairo'); $now = \Carbon\Carbon::now($tz); $sessionStart = \Carbon\Carbon::parse($session->session_date.' '.$session->start_time, $tz); $sessionEnd = \Carbon\Carbon::parse($session->session_date.' '.$session->end_time, $tz); if ($sessionEnd->lessThanOrEqualTo($sessionStart)) { $sessionEnd->addDay(); } // Only show when the session is today AND the current time is within the session window. $isToday = $now->isSameDay($sessionStart); $isLiveSessionTime = $isToday && $now->betweenIncluded($sessionStart, $sessionEnd); } $shouldShowMediaStatus = $isLiveSessionTime; @endphp @if ($shouldShowMediaStatus) @php $teacherUserId = $teacher?->user_id; $participants = $session ? ($session->relationLoaded('bbbParticipants') ? $session->bbbParticipants : $session->bbbParticipants()->get()) : collect(); $teacherBbbUserId = $teacherUserId ? 'user-'.$teacherUserId : null; $teacherParticipants = $teacherUserId ? $participants ->filter(fn ($item) => (int) $item->user_id === (int) $teacherUserId || $item->bbb_user_id === $teacherBbbUserId) ->values() : collect(); $isOnline = $teacherParticipants->contains(fn ($item) => (bool) $item->is_online); $micOpen = $isOnline && $teacherParticipants->contains(function ($item) { $lastMicUnmutedAt = $item->mic_unmuted_at; $lastMicMutedAt = $item->mic_muted_at; $hasRecentUnmute = $lastMicUnmutedAt && (! $lastMicMutedAt || $lastMicUnmutedAt->greaterThanOrEqualTo($lastMicMutedAt)); return ! (bool) $item->is_listening_only && ! (bool) $item->mic_is_muted && ((bool) $item->has_joined_voice || $hasRecentUnmute); }); $cameraOpen = $isOnline && $teacherParticipants->contains(fn ($item) => (bool) $item->has_video); @endphp