Update: 2026-06-21 02:07:00
This commit is contained in:
@@ -143,7 +143,7 @@ class LocationController extends GetxController with WidgetsBindingObserver {
|
||||
|
||||
// إيقاف خدمة الخلفية
|
||||
BackgroundServiceHelper.stopService();
|
||||
|
||||
|
||||
if (socket == null || (!socket!.connected && !_isInitializingSocket)) {
|
||||
Log.print("🔄 Initializing Socket on resume...");
|
||||
initSocket();
|
||||
@@ -213,7 +213,7 @@ class LocationController extends GetxController with WidgetsBindingObserver {
|
||||
try {
|
||||
// العودة للـ Websocket حصراً لأنه الوحيد الذي ينجح في فتح القناة
|
||||
socket = IO.io(
|
||||
'https://location.intaleq.xyz',
|
||||
AppLink.locationSocketUrl,
|
||||
IO.OptionBuilder()
|
||||
.setTransports(['websocket'])
|
||||
.setQuery({'driver_id': driverId, 'token': token, 'EIO': '3'})
|
||||
@@ -360,8 +360,9 @@ class LocationController extends GetxController with WidgetsBindingObserver {
|
||||
var sortedKeys = rideData.keys
|
||||
.where((e) => int.tryParse(e) != null)
|
||||
.map((e) => int.parse(e))
|
||||
.toList()..sort();
|
||||
|
||||
.toList()
|
||||
..sort();
|
||||
|
||||
for (var key in sortedKeys) {
|
||||
driverList.add(rideData[key.toString()]);
|
||||
}
|
||||
@@ -598,7 +599,7 @@ class LocationController extends GetxController with WidgetsBindingObserver {
|
||||
_recordTimer =
|
||||
Timer.periodic(recDur, (_) => _recordCurrentLocationToBuffer());
|
||||
_uploadBatchTimer = Timer.periodic(upDur, (_) => _flushBufferToServer());
|
||||
|
||||
|
||||
// محاولة إعادة الاتصال بالسوكيت إذا انقطع كل 3 ثواني
|
||||
_socketWatchdogTimer = Timer.periodic(const Duration(seconds: 3), (_) {
|
||||
if (!isSocketConnected && !_isInitializingSocket) {
|
||||
@@ -636,10 +637,10 @@ class LocationController extends GetxController with WidgetsBindingObserver {
|
||||
|
||||
Future<void> _flushBufferToServer() async {
|
||||
if (_trackBuffer.isEmpty) return;
|
||||
|
||||
|
||||
int itemsToTake = _trackBuffer.length > 100 ? 100 : _trackBuffer.length;
|
||||
List<Map<String, dynamic>> batch = _trackBuffer.sublist(0, itemsToTake);
|
||||
|
||||
|
||||
final String driverId = (box.read(BoxName.driverID) ?? '').toString();
|
||||
try {
|
||||
var res = await CRUD().post(
|
||||
@@ -686,7 +687,8 @@ class LocationController extends GetxController with WidgetsBindingObserver {
|
||||
interval: interval,
|
||||
distanceFilter: _isPowerSavingMode ? 20 : 10,
|
||||
);
|
||||
Log.print("🔋 Location settings updated. Power Save: $_isPowerSavingMode");
|
||||
Log.print(
|
||||
"🔋 Location settings updated. Power Save: $_isPowerSavingMode");
|
||||
} catch (e) {
|
||||
Log.print("❌ Failed to update location settings: $e");
|
||||
}
|
||||
@@ -697,7 +699,7 @@ class LocationController extends GetxController with WidgetsBindingObserver {
|
||||
final dist =
|
||||
(_lastSqlLoc == null) ? 999.0 : _calculateDistance(_lastSqlLoc!, pos);
|
||||
if (dist < 15.0) return;
|
||||
|
||||
|
||||
final accel = _calcAcceleration(currentSpeed, now) ?? 0.0;
|
||||
_lastSqlLoc = pos;
|
||||
|
||||
@@ -719,7 +721,7 @@ class LocationController extends GetxController with WidgetsBindingObserver {
|
||||
if (_behaviorBuffer.isEmpty) return;
|
||||
List<Map<String, dynamic>> batch = List.from(_behaviorBuffer);
|
||||
_behaviorBuffer.clear();
|
||||
|
||||
|
||||
Future.microtask(() async {
|
||||
try {
|
||||
for (var data in batch) {
|
||||
@@ -799,7 +801,9 @@ class LocationController extends GetxController with WidgetsBindingObserver {
|
||||
try {
|
||||
if (await _ensureServiceAndPermission()) {
|
||||
final locData = await location.getLocation();
|
||||
if (locData != null && locData.latitude != null && locData.longitude != null) {
|
||||
if (locData != null &&
|
||||
locData.latitude != null &&
|
||||
locData.longitude != null) {
|
||||
myLocation = LatLng(locData.latitude!, locData.longitude!);
|
||||
heading = locData.heading ?? 0.0;
|
||||
speed = locData.speed ?? 0.0;
|
||||
@@ -814,7 +818,8 @@ class LocationController extends GetxController with WidgetsBindingObserver {
|
||||
final homeCtrl = Get.find<HomeCaptainController>();
|
||||
if (homeCtrl.mapHomeCaptainController != null &&
|
||||
homeCtrl.isMapReadyForCommands) {
|
||||
Log.print("📍 [LocationController] Animating camera to single location update");
|
||||
Log.print(
|
||||
"📍 [LocationController] Animating camera to single location update");
|
||||
homeCtrl.mapHomeCaptainController?.animateCamera(
|
||||
CameraUpdate.newLatLngZoom(myLocation, 17.5),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user