Update: 2026-07-12 05:40:28

This commit is contained in:
Hamza-Ayed
2026-07-12 05:40:28 +03:00
parent 1fa517acc9
commit 24fb56f08f
75 changed files with 5051 additions and 9 deletions
@@ -46,6 +46,19 @@ class LocationController extends GetxController with WidgetsBindingObserver {
bool isSocketConnected = false;
Timer? _socketHeartbeat;
// 🚌 مواصلاتي — وضع الباص: بينما نشط، الموقع يُبَث فقط عبر update_bus_location
// ولا يدخل حوض الرحلات العادي (geo:drivers:*)
bool isBusMode = false;
int? activeBusTripId;
int? activeBusRouteId;
void setBusMode({required bool enabled, int? tripId, int? routeId}) {
isBusMode = enabled;
activeBusTripId = enabled ? tripId : null;
activeBusRouteId = enabled ? routeId : null;
Log.print('🚌 Bus mode ${enabled ? "enabled" : "disabled"} (trip: $tripId, route: $routeId)');
}
StreamSubscription<LocationData>? _locSub;
StreamSubscription<BatteryState>? _batterySub;
@@ -431,7 +444,11 @@ class LocationController extends GetxController with WidgetsBindingObserver {
// الـ _locSub يرسل update_location عند كل تحرك (كل 5-10 ثوانٍ) تلقائياً.
// الـ heartbeat يكون مفيداً فقط عندما يتوقف الـ stream (الجهاز ثابت أو أوقف الخدمة).
if (_locSub != null) return;
if (socket != null && isSocketConnected && myLocation.latitude != 0) {
if (socket == null || !isSocketConnected || myLocation.latitude == 0) return;
if (isBusMode) {
emitBusLocationToSocket(myLocation, heading, speed);
} else {
emitLocationToSocket(myLocation, heading, speed);
}
});
@@ -477,6 +494,22 @@ class LocationController extends GetxController with WidgetsBindingObserver {
socket!.emit('update_location', payload);
}
}
// 🚌 مواصلاتي — بثّ موقع الباص (بديل عن update_location أثناء وضع الباص)
void emitBusLocationToSocket(LatLng pos, double head, double spd, {int? currentStopSeq}) {
if (activeBusTripId == null || activeBusRouteId == null) return;
if (socket == null || !socket!.connected) return;
socket!.emit('update_bus_location', {
'trip_id': activeBusTripId,
'route_id': activeBusRouteId,
'lat': pos.latitude,
'lng': pos.longitude,
'heading': head,
'speed': spd * 3.6,
if (currentStopSeq != null) 'current_stop_seq': currentStopSeq,
});
}
// ===================================================================
// ====== Tracking Logic ======
// ===================================================================
@@ -535,6 +568,14 @@ class LocationController extends GetxController with WidgetsBindingObserver {
_lastPosForDistance = pos;
update();
// 🚌 وضع الباص: بثّ موقع الباص فقط — لا يدخل حوض الرحلات العادي
if (isBusMode) {
emitBusLocationToSocket(pos, heading, speed);
await _saveBehaviorIfMoved(pos, now, currentSpeed: speed);
return;
}
emitLocationToSocket(pos, heading, speed);
if (Get.isRegistered<HomeCaptainController>()) {