Update: 2026-07-12 05:40:28
This commit is contained in:
@@ -21,6 +21,10 @@ class MapSocketController extends GetxController {
|
||||
int _socketLocationUpdatesCount = 0;
|
||||
Timer? _watchdogTimer;
|
||||
|
||||
// 🚌 مواصلاتي — الخط الحالي المشترَك فيه + مستمع تحديث موقع الباص
|
||||
int? _subscribedTransitRouteId;
|
||||
void Function(Map<String, dynamic> data)? onBusLocationUpdate;
|
||||
|
||||
DateTime? get lastDriverLocationTime => _lastSocketLocationTime;
|
||||
int get socketLocationUpdatesCount => _socketLocationUpdatesCount;
|
||||
|
||||
@@ -61,6 +65,10 @@ class MapSocketController extends GetxController {
|
||||
});
|
||||
Log.print("📡 Re-subscribed to driver location after connect");
|
||||
}
|
||||
if (_subscribedTransitRouteId != null) {
|
||||
socket.emit('subscribe_transit_route', {'route_id': _subscribedTransitRouteId});
|
||||
Log.print("🚌 Re-subscribed to transit route after connect");
|
||||
}
|
||||
update();
|
||||
});
|
||||
|
||||
@@ -89,6 +97,10 @@ class MapSocketController extends GetxController {
|
||||
});
|
||||
Log.print("📡 Re-subscribed to driver location after reconnect");
|
||||
}
|
||||
if (_subscribedTransitRouteId != null) {
|
||||
socket.emit('subscribe_transit_route', {'route_id': _subscribedTransitRouteId});
|
||||
Log.print("🚌 Re-subscribed to transit route after reconnect");
|
||||
}
|
||||
|
||||
if (rideLifecycle.isActiveRideState()) {
|
||||
Log.print("✅ Socket back online — stopping Fast Polling Fallback");
|
||||
@@ -131,6 +143,39 @@ class MapSocketController extends GetxController {
|
||||
socket.on('driver_location_update', (data) {
|
||||
handleDriverLocationUpdate(data);
|
||||
});
|
||||
|
||||
// 🚌 مواصلاتي — بثّ موقع الباص الحي لخط مشترَك فيه
|
||||
socket.on('bus_location_update', (data) {
|
||||
if (data == null) return;
|
||||
try {
|
||||
final map = Map<String, dynamic>.from(data as Map);
|
||||
onBusLocationUpdate?.call(map);
|
||||
} catch (e) {
|
||||
Log.print('Error parsing bus_location_update: $e');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ── مواصلاتي: اشتراك/إلغاء اشتراك ببثّ موقع خط ─────────────
|
||||
// يُستدعى عند فتح/إغلاق شاشة تتبع الباص الحي. يضمن السوكيت متصلاً أولاً.
|
||||
void subscribeToTransitRoute(int routeId) {
|
||||
_subscribedTransitRouteId = routeId;
|
||||
if (!isSocketConnected) {
|
||||
initConnectionWithSocket();
|
||||
// سيُعاد الاشتراك تلقائياً من onConnect إن أضفنا ذلك، لكن نحاول فوراً أيضاً
|
||||
}
|
||||
if (socket.connected) {
|
||||
socket.emit('subscribe_transit_route', {'route_id': routeId});
|
||||
Log.print('🚌 Subscribed to transit route #$routeId');
|
||||
}
|
||||
}
|
||||
|
||||
void unsubscribeFromTransitRoute(int routeId) {
|
||||
if (_subscribedTransitRouteId == routeId) _subscribedTransitRouteId = null;
|
||||
if (isSocketConnected && socket.connected) {
|
||||
socket.emit('unsubscribe_transit_route', {'route_id': routeId});
|
||||
Log.print('🚌 Unsubscribed from transit route #$routeId');
|
||||
}
|
||||
}
|
||||
|
||||
void _startHeartbeat() {
|
||||
|
||||
Reference in New Issue
Block a user