// import 'dart:convert'; // import 'dart:developer'; // import 'dart:ui'; // import 'package:stomp_dart_client/stomp.dart'; // import 'package:stomp_dart_client/stomp_config.dart'; // import 'package:stomp_dart_client/stomp_frame.dart'; // // import '../config/constants/app_constant.dart'; // // typedef RideUpdateCallback = void Function(Map data); // // class SocketRideUpdateServices { // final String jwtToken; // final RideUpdateCallback onRideUpdate; // late final StompClient _stompClient; // // SocketRideUpdateServices({ // required this.jwtToken, // required this.onRideUpdate, // }); // // void connect({ VoidCallback? onConnected }) { // // _stompClient = StompClient( // config: StompConfig( // // for SockJS endpoint use ws://…/ws-sockjs // url: socketUrlNative, // webSocketConnectHeaders: { // 'Authorization': 'Bearer $jwtToken', // }, // stompConnectHeaders: { // 'Authorization': 'Bearer $jwtToken', // }, // onConnect: (frame) { // onConnected?.call(); // _subscribeToRideQueue(); // }, // onWebSocketError: (dynamic error) => print('WS error: $error'), // onStompError: (frame) => print('STOMP error: ${frame.body}'), // heartbeatIncoming: const Duration(seconds: 10), // heartbeatOutgoing: const Duration(seconds: 10), // ), // ); // _stompClient.activate(); // } // // void _onConnect(StompFrame frame) { // print('✅ STOMP connected, subscribing to /user/queue/ride_updates'); // _stompClient.subscribe( // destination: '/user/queue/ride_updates', // headers: {'id': 'ride-updates-sub'}, // callback: (frame) { // if (frame.body != null) { // final Map data = json.decode(frame.body!); // print('→ ride update: $data'); // onRideUpdate(data); // } // }, // ); // } // // void _subscribeToRideQueue() { // print('✅ STOMP connected, subscribing to /user/queue/ride_updates'); // _stompClient.subscribe( // destination: '/user/queue/ride_updates', // headers: { // 'id' : 'ride-updates-durable', // 'durable' : 'true', // 'auto-delete': 'false', // 'ack' : 'auto', // }, // callback: _handleUpdate, // ); // } // void _handleUpdate(StompFrame frame) { // if (frame.body != null) { // final data = json.decode(frame.body!); // onRideUpdate(Map.from(data)); // } // } // // /// Sends the driver’s acceptance to Spring’s @MessageMapping("/accept_ride") // void sendSendArrivedNotification({ // required int rideId, // }) { // log("send accepte ride **************"); // final payload = json.encode({ // 'rideId': rideId.toString(), // "type":'DRIVER_ARRIVED', // "message":'Driver arrived !!' // }); // _stompClient.send( // destination: '/app/ride_updates', // body: payload, // ); // print('→ sent ride_updates: $payload'); // } // // /// Sends the driver’s acceptance to Spring’s @MessageMapping("/accept_ride") // void sendStartRideNotification({ // required int rideId, // }) { // log("send accepte ride **************"); // final payload = json.encode({ // 'rideId': rideId.toString(), // "type":'RIDE_START', // "message":'Ride start !!' // }); // _stompClient.send( // destination: '/app/ride_updates', // body: payload, // ); // print('→ sent ride_updates: $payload'); // } // void sendCancelRideNotification({ // required int rideId, // }) { // log("send Cancel ride **************"); // final payload = json.encode({ // 'rideId': rideId.toString(), // "type":'RIDE_CANCEL_DRIVER', // "message":'Ride Cancel by the driver !!' // }); // _stompClient.send( // destination: '/app/ride_updates', // body: payload, // ); // print('→ sent ride_updates: $payload'); // } // void sendCompletedRideNotification({ // required int rideId, // }) { // log("send accepte ride **************"); // final payload = json.encode({ // 'rideId': rideId.toString(), // "type":'RIDE_END', // "message":'Ride END and process rating client !!' // }); // _stompClient.send( // destination: '/app/ride_updates', // body: payload, // ); // print('→ sent ride_updates: $payload'); // } // // // void disconnect() { // _stompClient.deactivate(); // } // }