feat: استيراد كود سيرو إلى تريبز (سيرو @ecfe7568) — بلا تعديل
قرار المالك 2026-07-27: باك إند سيرو PHP هو المعتمد، وتطبيقاته المجرّبة ميدانياً تحل محل إعادة البناء المؤرشفة. سيرو نفسه لم يُمسّ. الخريطة: backend · payment_server · loction_server · ride_server · passenger_server · docker · dashboard · stress_test → الجذر siro_rider → apps/rider siro_driver → apps/driver siro_admin → dashboards/admin siro_service → dashboards/service android_bot → apps/android_bot socialBot → apps/socialBot نُسخ المتعقَّب في git سيرو فقط عبر `git archive` (3,198 ملفاً / ~169 م.ب) لا `cp -r` — فاستُثنيت مخلفات البناء تلقائياً. بلا أي تعديل محتوى عمداً: كل ما يلي يصير فرقاً مقروءاً مقابل المصدر. لم يُستورد وسببه: siromove.com (الموقع التسويقي يبقى marketing/ في تريبز، سيرو فيه 8 ملفات) · docs و planning (تريبز له docs/ الخاص) · deploy.sh (ليس نشراً على سيرفر بل `git add . && git push origin --all` — فخّ في مستودع آخر) · transit_dashboard (بانتظار قرار مصير backend-transit و dashboards/transit-web). ⚠️ لا يبني بعد — ثلاثة نواقص متوقعة ومقصودة: 1. `.env` و `lib/env/env.g.dart` غير متعقَّبين في سيرو (أسرار لكل مستأجر): كل تطبيق فلاتر يحتاج .env خاصاً ثم توليد env.g.dart بـ build_runner. 2. إعدادات Firebase (9 ملفات google-services.json و GoogleService-Info.plist) يستبعدها .gitignore تريبز — ولكل مستأجر مشروع Firebase خاص أصلاً. 3. apps/driver في سيرو يشير إلى `../../Intaleq/packages/get` خارج المستودع → يجب ضمّ الحزم داخله أسوة بـ apps/rider. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
9909d9b4c1
commit
4d8414c96b
@@ -0,0 +1,122 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../print.dart';
|
||||
|
||||
/// خدمة Android Live Update (Progress Style)
|
||||
///
|
||||
/// توفر واجهة موحدة للتحديث المباشر لحالة الرحلة على Android
|
||||
/// باستخدام NotificationCompat مع Progress Style (Android 16+)
|
||||
///
|
||||
/// هذه الخدمة مشابهة لـ [IosLiveActivityService] ولكن لمنصة Android
|
||||
class AndroidLiveUpdateService {
|
||||
static const MethodChannel _channel =
|
||||
MethodChannel('siro/android_live_update');
|
||||
|
||||
static bool _isSupported = false;
|
||||
static bool _isActive = false;
|
||||
|
||||
/// التحقق من دعم الجهاز للخدمة
|
||||
/// تعود true إذا كان Android 11+ (API 30+)
|
||||
static Future<bool> init() async {
|
||||
if (!Platform.isAndroid) return false;
|
||||
|
||||
try {
|
||||
final supported = await _channel.invokeMethod<bool>('isSupported');
|
||||
_isSupported = supported ?? false;
|
||||
Log.print(
|
||||
'📱 AndroidLiveUpdateService initialized: supported=$_isSupported');
|
||||
return _isSupported;
|
||||
} catch (e) {
|
||||
Log.print('❌ AndroidLiveUpdateService init error: $e');
|
||||
_isSupported = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// بدء التحديث المباشر للرحلة (عند قبول السائق)
|
||||
static Future<void> startLiveUpdate({
|
||||
required String rideId,
|
||||
required String driverName,
|
||||
required String etaText,
|
||||
required double progress,
|
||||
required String carDetails,
|
||||
}) async {
|
||||
if (!Platform.isAndroid || !_isSupported) return;
|
||||
|
||||
try {
|
||||
await _channel.invokeMethod('startLiveUpdate', {
|
||||
'rideId': rideId,
|
||||
'driverName': driverName,
|
||||
'etaText': etaText,
|
||||
'progress': progress,
|
||||
'carDetails': carDetails,
|
||||
});
|
||||
_isActive = true;
|
||||
Log.print('✅ Android Live Update Started');
|
||||
} catch (e) {
|
||||
Log.print('❌ AndroidLiveUpdateService startLiveUpdate error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// تحديث التقدم والوقت المتبقي
|
||||
static Future<void> updateProgress({
|
||||
required double progress,
|
||||
required String etaText,
|
||||
}) async {
|
||||
if (!Platform.isAndroid || !_isSupported || !_isActive) return;
|
||||
|
||||
try {
|
||||
await _channel.invokeMethod('updateProgress', {
|
||||
'progress': progress,
|
||||
'etaText': etaText,
|
||||
});
|
||||
} catch (e) {
|
||||
Log.print('❌ AndroidLiveUpdateService updateProgress error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// تحديث حالة الرحلة بالكامل
|
||||
static Future<void> updateStatus({
|
||||
required String status,
|
||||
required String driverName,
|
||||
required String etaText,
|
||||
required double progress,
|
||||
String carDetails = '',
|
||||
}) async {
|
||||
if (!Platform.isAndroid || !_isSupported || !_isActive) return;
|
||||
|
||||
try {
|
||||
await _channel.invokeMethod('updateStatus', {
|
||||
'status': status,
|
||||
'driverName': driverName,
|
||||
'etaText': etaText,
|
||||
'progress': progress,
|
||||
'carDetails': carDetails,
|
||||
});
|
||||
Log.print('✅ Android Live Update Status: $status');
|
||||
} catch (e) {
|
||||
Log.print('❌ AndroidLiveUpdateService updateStatus error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// إنهاء التحديث المباشر وإزالة الإشعار
|
||||
static Future<void> endLiveUpdate() async {
|
||||
if (!Platform.isAndroid || !_isSupported || !_isActive) return;
|
||||
|
||||
try {
|
||||
await _channel.invokeMethod('endLiveUpdate');
|
||||
_isActive = false;
|
||||
Log.print('✅ Android Live Update Ended');
|
||||
} catch (e) {
|
||||
Log.print('❌ AndroidLiveUpdateService endLiveUpdate error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// التحقق مما إذا كان التحديث نشطاً
|
||||
static bool get isActive => _isActive;
|
||||
|
||||
/// إعادة تعيين الحالة
|
||||
static void reset() {
|
||||
_isActive = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:sensors_plus/sensors_plus.dart';
|
||||
|
||||
import '../print.dart';
|
||||
|
||||
class EmergencySignalService {
|
||||
static final EmergencySignalService instance = EmergencySignalService._();
|
||||
EmergencySignalService._();
|
||||
|
||||
StreamSubscription<AccelerometerEvent>? _accelerometerSubscription;
|
||||
DateTime? _lastShakeTime;
|
||||
int _shakeCount = 0;
|
||||
|
||||
// Custom thresholds for shaking (force required)
|
||||
final double _shakeThresholdGravity = 2.7;
|
||||
final int _shakeSlopTimeMs = 500;
|
||||
final int _shakeCountResetTimeMs = 3000;
|
||||
final int _targetShakes = 5;
|
||||
|
||||
VoidCallback? _onEmergencyTriggered;
|
||||
|
||||
/// Starts listening to phone movement
|
||||
void startListening(VoidCallback onEmergencyTriggered) {
|
||||
_onEmergencyTriggered = onEmergencyTriggered;
|
||||
|
||||
if (_accelerometerSubscription != null) return;
|
||||
|
||||
_accelerometerSubscription = accelerometerEvents.listen((event) {
|
||||
double x = event.x;
|
||||
double y = event.y;
|
||||
double z = event.z;
|
||||
|
||||
// Calculate the gForce using pythagorean theorem
|
||||
double gX = x / 9.80665;
|
||||
double gY = y / 9.80665;
|
||||
double gZ = z / 9.80665;
|
||||
|
||||
// Overall gForce
|
||||
double gForce = sqrt(gX * gX + gY * gY + gZ * gZ);
|
||||
|
||||
if (gForce > _shakeThresholdGravity) {
|
||||
final now = DateTime.now();
|
||||
|
||||
// Ignore shakes that are too close to each other
|
||||
if (_lastShakeTime != null &&
|
||||
now.difference(_lastShakeTime!).inMilliseconds < _shakeSlopTimeMs) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset the counter if elapsed more than the reset window
|
||||
if (_lastShakeTime != null &&
|
||||
now.difference(_lastShakeTime!).inMilliseconds >
|
||||
_shakeCountResetTimeMs) {
|
||||
_shakeCount = 0;
|
||||
}
|
||||
|
||||
_lastShakeTime = now;
|
||||
_shakeCount++;
|
||||
|
||||
if (kDebugMode) {
|
||||
Log.print("🚨 Shake detected! Count: $_shakeCount");
|
||||
}
|
||||
|
||||
if (_shakeCount >= _targetShakes) {
|
||||
_shakeCount = 0; // Reset counter
|
||||
if (_onEmergencyTriggered != null) {
|
||||
_onEmergencyTriggered!();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void stopListening() {
|
||||
_accelerometerSubscription?.cancel();
|
||||
_accelerometerSubscription = null;
|
||||
_shakeCount = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:native_geofence/native_geofence.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'package:siro_rider/constant/links.dart';
|
||||
|
||||
// Top-level function for background execution
|
||||
@pragma('vm:entry-point')
|
||||
Future<void> geofenceBackgroundCallback(GeofenceCallbackParams params) async {
|
||||
if (params.event == GeofenceEvent.enter) {
|
||||
// Note: GetStorage might need to be initialized in the background isolate
|
||||
await GetStorage.init();
|
||||
final storage = GetStorage();
|
||||
final passengerId = storage.read('passenger_id') ?? '';
|
||||
if (passengerId.toString().isEmpty) return;
|
||||
|
||||
for (var geofence in params.geofences) {
|
||||
debugPrint('Entered Geofence: ${geofence.id}');
|
||||
|
||||
try {
|
||||
final url = Uri.parse('${AppLink.server}/api/location/sync_location.php');
|
||||
await http.post(url, body: {
|
||||
'passenger_id': passengerId.toString(),
|
||||
'lat': geofence.location.latitude.toString(),
|
||||
'lng': geofence.location.longitude.toString(),
|
||||
'source': 'geofence',
|
||||
});
|
||||
} catch (e) {
|
||||
debugPrint('Geofence API Error: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SiroGeofencingService {
|
||||
static final _storage = GetStorage();
|
||||
|
||||
static Future<void> initAndStart() async {
|
||||
try {
|
||||
await NativeGeofenceManager.instance.initialize();
|
||||
} catch (e) {
|
||||
debugPrint('Error initializing NativeGeofenceManager: $e');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> syncZonesWithServer(double lat, double lng) async {
|
||||
try {
|
||||
final passengerId = _storage.read('passenger_id') ?? '';
|
||||
if (passengerId.toString().isEmpty) return;
|
||||
|
||||
final url = Uri.parse('${AppLink.server}/api/location/sync_location.php');
|
||||
final response = await http.post(url, body: {
|
||||
'passenger_id': passengerId.toString(),
|
||||
'lat': lat.toString(),
|
||||
'lng': lng.toString(),
|
||||
'source': 'app_usage',
|
||||
});
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = json.decode(response.body);
|
||||
if (data['status'] == 'success' && data['update_geofences'] != null) {
|
||||
await _updateLocalGeofences(data['update_geofences']);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Error syncing geofence zones: $e');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> _updateLocalGeofences(List<dynamic> regions) async {
|
||||
try {
|
||||
for (var region in regions) {
|
||||
final geofence = Geofence(
|
||||
id: region['id'].toString(),
|
||||
location: Location(
|
||||
latitude: double.parse(region['latitude'].toString()),
|
||||
longitude: double.parse(region['longitude'].toString())),
|
||||
radiusMeters: double.parse(region['radius_meters'].toString()),
|
||||
triggers: {GeofenceEvent.enter},
|
||||
iosSettings: const IosGeofenceSettings(
|
||||
initialTrigger: true,
|
||||
),
|
||||
androidSettings: const AndroidGeofenceSettings(
|
||||
initialTriggers: {GeofenceEvent.enter},
|
||||
),
|
||||
);
|
||||
|
||||
await NativeGeofenceManager.instance.createGeofence(
|
||||
geofence,
|
||||
geofenceBackgroundCallback,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Error updating local geofences: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
import 'dart:math' as math;
|
||||
import '../../main.dart';
|
||||
import '../print.dart';
|
||||
|
||||
class OfflineMapService {
|
||||
static final OfflineMapService instance = OfflineMapService._();
|
||||
OfflineMapService._();
|
||||
|
||||
final _offlineRegionName = "UserRegion";
|
||||
bool _isDownloading = false;
|
||||
LatLng? _lastDownloadedCenter;
|
||||
|
||||
/// Calculate bounding box for a given center and radius in km
|
||||
LatLngBounds _calculateBounds(LatLng center, double radiusKm) {
|
||||
const double earthRadius = 6371.0;
|
||||
|
||||
// Latitude degrees per km
|
||||
double latDelta = (radiusKm / earthRadius) * (180 / math.pi);
|
||||
// Longitude degrees per km at given latitude
|
||||
double lngDelta = (radiusKm / earthRadius) *
|
||||
(180 / math.pi) /
|
||||
math.cos(center.latitude * math.pi / 180);
|
||||
|
||||
return LatLngBounds(
|
||||
southwest:
|
||||
LatLng(center.latitude - latDelta, center.longitude - lngDelta),
|
||||
northeast:
|
||||
LatLng(center.latitude + latDelta, center.longitude + lngDelta),
|
||||
);
|
||||
}
|
||||
|
||||
/// Downloads a specified radius around a coordinate
|
||||
Future<void> downloadRegion(LatLng center,
|
||||
{double radiusKm = 10.0,
|
||||
double minZoom = 6.0,
|
||||
double maxZoom = 15.0}) async {
|
||||
if (_isDownloading) return;
|
||||
|
||||
// Avoid re-downloading if the user hasn't moved significantly (e.g. > 5km)
|
||||
if (_lastDownloadedCenter != null) {
|
||||
double distance = _calculateDistance(center, _lastDownloadedCenter!);
|
||||
if (distance < 5.0) return; // skip if close to previously downloaded
|
||||
}
|
||||
|
||||
_isDownloading = true;
|
||||
|
||||
try {
|
||||
final bounds = _calculateBounds(center, radiusKm);
|
||||
|
||||
// Select style based on current theme
|
||||
final String styleStr =
|
||||
Get.isDarkMode ? "assets/style_dark.json" : "assets/style.json";
|
||||
|
||||
// iOS native crash guard: MLNTilePyramidOfflineRegion does not support relative asset URLs.
|
||||
// We skip native offline registration on iOS if using local assets to ensure stability.
|
||||
if (Platform.isIOS && !styleStr.startsWith('http')) {
|
||||
Log.print(
|
||||
"ℹ️ Skipping native offline registration on iOS for asset-based style to prevent crash.");
|
||||
return;
|
||||
}
|
||||
|
||||
final regionDefinition = OfflineRegionDefinition(
|
||||
bounds: bounds,
|
||||
mapStyleUrl: styleStr,
|
||||
minZoom: minZoom,
|
||||
maxZoom: maxZoom,
|
||||
);
|
||||
|
||||
// We'll update the last downloaded center immediately
|
||||
_lastDownloadedCenter = center;
|
||||
|
||||
// MapLibre standard API for offline downloads
|
||||
await downloadOfflineRegion(regionDefinition, metadata: {
|
||||
'name': '$_offlineRegionName-${center.latitude}-${center.longitude}',
|
||||
'downloadDate': DateTime.now().toIso8601String(),
|
||||
});
|
||||
|
||||
// Reassurance log for the user
|
||||
Log.print("📍 Map Ready: Service is utilizing local tile cache.");
|
||||
Log.print(
|
||||
"✅ Offline Map Cached for Region: $center (radius: ${radiusKm}km, style: $styleStr)");
|
||||
} catch (e) {
|
||||
Log.print("⚠️ Offline Map Download Failed: $e");
|
||||
} finally {
|
||||
_isDownloading = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper to calculate distance in km
|
||||
double _calculateDistance(LatLng p1, LatLng p2) {
|
||||
var p = 0.017453292519943295;
|
||||
var c = math.cos;
|
||||
var a = 0.5 -
|
||||
c((p2.latitude - p1.latitude) * p) / 2 +
|
||||
c(p1.latitude * p) *
|
||||
c(p2.latitude * p) *
|
||||
(1 - c((p2.longitude - p1.longitude) * p)) /
|
||||
2;
|
||||
return 12742 * math.asin(math.sqrt(a));
|
||||
}
|
||||
|
||||
/// Clears all offline map regions and tiles from local storage
|
||||
Future<void> clearCache() async {
|
||||
try {
|
||||
Log.print("♻️ Purging MapLibre Offline Cache...");
|
||||
// In maplibre_gl 0.25.0, we use top-level functions instead of an OfflineManager class
|
||||
final List<OfflineRegion> regions = await getListOfRegions();
|
||||
for (var region in regions) {
|
||||
await deleteOfflineRegion(region.id);
|
||||
}
|
||||
Log.print("✅ Map cache cleared successfully. ${regions.length} regions removed.");
|
||||
} catch (e) {
|
||||
Log.print("⚠️ Failed to clear map cache: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../print.dart';
|
||||
|
||||
/// خدمة التحكم بوضع النافذة العائمة (Picture-in-Picture) على أندرويد.
|
||||
/// تُستدعى عند بدء الرحلة لتفعيل PiP تلقائياً عند خروج المستخدم من التطبيق.
|
||||
class PipService {
|
||||
static const MethodChannel _channel = MethodChannel('siro/pip');
|
||||
|
||||
/// هل وضع PiP مدعوم على هذا الجهاز؟
|
||||
static Future<bool> isPipSupported() async {
|
||||
if (!Platform.isAndroid) return false;
|
||||
try {
|
||||
final result = await _channel.invokeMethod<bool>('isPipSupported');
|
||||
return result ?? false;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// تفعيل الدخول التلقائي لوضع PiP عند الخروج (أثناء الرحلة)
|
||||
static Future<void> enablePip() async {
|
||||
if (!Platform.isAndroid) return;
|
||||
try {
|
||||
await _channel.invokeMethod('enablePip');
|
||||
} catch (e) {
|
||||
Log.print('PiP enable error: \$e');
|
||||
}
|
||||
}
|
||||
|
||||
/// تعطيل الدخول التلقائي لوضع PiP (بعد انتهاء الرحلة)
|
||||
static Future<void> disablePip() async {
|
||||
if (!Platform.isAndroid) return;
|
||||
try {
|
||||
await _channel.invokeMethod('disablePip');
|
||||
} catch (e) {
|
||||
Log.print('PiP disable error: \$e');
|
||||
}
|
||||
}
|
||||
|
||||
/// الدخول يدوياً لوضع PiP
|
||||
static Future<bool> enterPip() async {
|
||||
if (!Platform.isAndroid) return false;
|
||||
try {
|
||||
final result = await _channel.invokeMethod<bool>('enterPip');
|
||||
return result ?? false;
|
||||
} catch (e) {
|
||||
Log.print('PiP enter error: \$e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// الاستماع لتغيير وضع PiP (الدخول/الخروج)
|
||||
static void listenToPipChanges(Function(bool isInPip) onChanged) {
|
||||
_channel.setMethodCallHandler((call) async {
|
||||
if (call.method == 'onPipChanged') {
|
||||
final isInPip = call.arguments as bool;
|
||||
onChanged(isInPip);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../controller/firebase/local_notification.dart';
|
||||
|
||||
class RideLiveNotification {
|
||||
static const int _notificationId = 888; // رقم ثابت لإشعار الرحلة
|
||||
// نستخدم نفس الـ plugin من NotificationController
|
||||
static FlutterLocalNotificationsPlugin get _plugin =>
|
||||
Get.find<NotificationController>().plugin;
|
||||
// static bool _initialized = false;
|
||||
|
||||
static Future<void> _showOrUpdate({
|
||||
required String title,
|
||||
required String body,
|
||||
required int progress,
|
||||
required int maxProgress,
|
||||
bool indeterminate = false,
|
||||
}) async {
|
||||
// await init();
|
||||
|
||||
final android = AndroidNotificationDetails(
|
||||
'live_ride_tracking', // channel id
|
||||
'Ride Tracking', // channel name
|
||||
channelDescription: 'Live updates for the current Siro ride',
|
||||
importance: Importance.max,
|
||||
priority: Priority.high,
|
||||
ongoing: true, // إشعار ثابت
|
||||
autoCancel: false,
|
||||
showProgress: true,
|
||||
onlyAlertOnce: true,
|
||||
maxProgress: maxProgress,
|
||||
progress: progress,
|
||||
indeterminate: indeterminate,
|
||||
icon: '@mipmap/launcher_icon', // غيّرها لو عندك أيقونة أخرى
|
||||
);
|
||||
|
||||
final details = NotificationDetails(android: android);
|
||||
|
||||
await _plugin.show(
|
||||
id: _notificationId,
|
||||
title: title,
|
||||
body: body,
|
||||
notificationDetails: details,
|
||||
);
|
||||
}
|
||||
|
||||
/// إلغاء إشعار الرحلة
|
||||
static Future<void> cancel() async {
|
||||
// await init();
|
||||
await _plugin.cancel(id: _notificationId);
|
||||
}
|
||||
|
||||
// ========= حالات جاهزة للحالات المختلفة =========
|
||||
|
||||
/// حالة البحث عن سائق
|
||||
static Future<void> showSearching(String statusText) async {
|
||||
await _showOrUpdate(
|
||||
title: 'جاري البحث عن سائق…',
|
||||
body: statusText,
|
||||
progress: 0,
|
||||
maxProgress: 0,
|
||||
indeterminate: true, // شريط متحرّك بدون نسبة
|
||||
);
|
||||
}
|
||||
|
||||
/// السائق في الطريق للراكب
|
||||
static Future<void> showDriverOnWay({
|
||||
required String driverName,
|
||||
required String etaText, // مثل: "8 دقائق"
|
||||
String? carInfo, // مثل: "هيونداي • أبيض • ABC-123"
|
||||
}) async {
|
||||
final info = [
|
||||
driverName,
|
||||
if (carInfo != null && carInfo.isNotEmpty) carInfo,
|
||||
etaText,
|
||||
].join(' • ');
|
||||
|
||||
await _showOrUpdate(
|
||||
title: 'السائق في الطريق إليك',
|
||||
body: info,
|
||||
progress: 0,
|
||||
maxProgress: 0,
|
||||
indeterminate: true,
|
||||
);
|
||||
}
|
||||
|
||||
/// السائق وصل لموقع الراكب
|
||||
static Future<void> showDriverArrived(String driverName) async {
|
||||
await _showOrUpdate(
|
||||
title: 'السائق وصل',
|
||||
body: 'الرجاء التوجّه لمقابلة $driverName عند نقطة الالتقاء',
|
||||
progress: 100,
|
||||
maxProgress: 100,
|
||||
indeterminate: false,
|
||||
);
|
||||
}
|
||||
|
||||
/// الرحلة جارية (Progress حقيقي)
|
||||
static Future<void> showTripInProgress({
|
||||
required int percentage, // من 0 إلى 100
|
||||
required String etaText, // "8 دقائق" مثلاً
|
||||
}) async {
|
||||
final safePercent = percentage.clamp(0, 100);
|
||||
await _showOrUpdate(
|
||||
title: 'الرحلة جارية الآن',
|
||||
body: 'المتبقي تقريبًا: $etaText',
|
||||
progress: safePercent,
|
||||
maxProgress: 100,
|
||||
indeterminate: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class RideTrackingNative {
|
||||
static const MethodChannel _channel = MethodChannel('siro/ride_tracking');
|
||||
|
||||
static Future<void> updateRideTracking({
|
||||
required String driverName,
|
||||
String driverPhone = '',
|
||||
required String carDetails,
|
||||
required double driverLat,
|
||||
required double driverLng,
|
||||
required double passengerLat,
|
||||
required double passengerLng,
|
||||
required double destLat,
|
||||
required double destLng,
|
||||
required String rideState, // "waiting" أو "inProgress"
|
||||
required int estimatedTimeMinutes,
|
||||
required double totalDistanceMeters,
|
||||
}) async {
|
||||
if (!Platform.isAndroid) return;
|
||||
|
||||
await _channel.invokeMethod('updateRideTracking', {
|
||||
'driverName': driverName,
|
||||
'driverPhone': driverPhone,
|
||||
'carDetails': carDetails,
|
||||
'driverLat': driverLat,
|
||||
'driverLng': driverLng,
|
||||
'passengerLat': passengerLat,
|
||||
'passengerLng': passengerLng,
|
||||
'destLat': destLat,
|
||||
'destLng': destLng,
|
||||
'rideState': rideState,
|
||||
'estimatedTime': estimatedTimeMinutes,
|
||||
'totalDistance': totalDistanceMeters,
|
||||
});
|
||||
}
|
||||
|
||||
static Future<void> stopRideTracking() async {
|
||||
if (!Platform.isAndroid) return;
|
||||
await _channel.invokeMethod('stopRideTracking');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:siro_rider/print.dart';
|
||||
|
||||
class SignalingService {
|
||||
WebSocket? _socket;
|
||||
final String _url = "wss://calls.intaleqapp.com/ws";
|
||||
|
||||
// Callbacks
|
||||
Function(List<dynamic> iceServers)? onConnected;
|
||||
Function(String reason)? onDisconnected;
|
||||
Function(Map<String, dynamic> offer)? onOffer;
|
||||
Function(Map<String, dynamic> answer)? onAnswer;
|
||||
Function(Map<String, dynamic> candidate)? onIceCandidate;
|
||||
Function(String reason)? onCallEnded;
|
||||
Function()? onParticipantJoined;
|
||||
|
||||
bool get isConnected => _socket != null && _socket!.readyState == WebSocket.open;
|
||||
|
||||
Future<void> connect(String sessionId, String userId) async {
|
||||
if (isConnected) return;
|
||||
|
||||
try {
|
||||
Log.print("Signaling: Connecting to $_url");
|
||||
_socket = await WebSocket.connect(_url)
|
||||
.timeout(const Duration(seconds: 8));
|
||||
|
||||
_socket!.listen(
|
||||
(data) {
|
||||
_handleMessage(data);
|
||||
},
|
||||
onError: (err) {
|
||||
Log.print("Signaling socket error: $err");
|
||||
disconnect("socket_error");
|
||||
},
|
||||
onDone: () {
|
||||
Log.print("Signaling socket closed by server");
|
||||
disconnect("socket_closed");
|
||||
},
|
||||
cancelOnError: true,
|
||||
);
|
||||
|
||||
// Send the authenticate message as the first message
|
||||
send("authenticate", {
|
||||
"session_id": sessionId,
|
||||
"user_id": userId,
|
||||
});
|
||||
} catch (e) {
|
||||
Log.print("Signaling connection failed: $e");
|
||||
onDisconnected?.call("connection_failed");
|
||||
}
|
||||
}
|
||||
|
||||
void _handleMessage(dynamic data) {
|
||||
try {
|
||||
Log.print("Signaling received raw: $data");
|
||||
final message = jsonDecode(data);
|
||||
if (message is! Map<String, dynamic>) return;
|
||||
|
||||
final type = message['type'];
|
||||
switch (type) {
|
||||
case 'authenticated':
|
||||
final iceServers = message['ice_servers'] as List<dynamic>? ?? [];
|
||||
onConnected?.call(iceServers);
|
||||
break;
|
||||
case 'participant_joined':
|
||||
onParticipantJoined?.call();
|
||||
break;
|
||||
case 'offer':
|
||||
if (message['sdp'] != null) {
|
||||
onOffer?.call(message['sdp']);
|
||||
}
|
||||
break;
|
||||
case 'answer':
|
||||
if (message['sdp'] != null) {
|
||||
onAnswer?.call(message['sdp']);
|
||||
}
|
||||
break;
|
||||
case 'ice_candidate':
|
||||
if (message['candidate'] != null) {
|
||||
onIceCandidate?.call(message['candidate']);
|
||||
}
|
||||
break;
|
||||
case 'call_ended':
|
||||
onCallEnded?.call(message['reason'] ?? 'normal');
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print("Error handling signaling message: $e");
|
||||
}
|
||||
}
|
||||
|
||||
void send(String type, Map<String, dynamic> data) {
|
||||
if (!isConnected) return;
|
||||
final msg = jsonEncode({
|
||||
'type': type,
|
||||
...data,
|
||||
});
|
||||
Log.print("Signaling sending: $msg");
|
||||
_socket!.add(msg);
|
||||
}
|
||||
|
||||
void disconnect([String reason = "user_hangup"]) {
|
||||
if (_socket != null) {
|
||||
_socket!.close();
|
||||
_socket = null;
|
||||
onDisconnected?.call(reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user