PassengerConsumer WebSocket - waimancoder/mytaxiproject2 GitHub Wiki

The PassengerConsumer WebSocket handles real-time communication for passengers when creating ride requests.

Connecting to the WebSocket

To establish a connection to the WebSocket, connect to the following URL:

ws://your-websocket-server-url/ws/passenger/<user_id>

Replace <user_id> with the actual user ID of the passenger.

Creating new ride request

To create a new ride request, send a JSON message with the following structure:

{
  "action": "create_ride_request",
  "pickup_latitude": "<pickup_latitude>",
  "pickup_longitude": "<pickup_longitude>",
  "dropoff_latitude": "<dropoff_latitude>",
  "dropoff_longitude": "<dropoff_longitude>",
  "pickup_address": "<pickup_address>",
  "dropoff_address": "<dropoff_address>",
}

Replace the placeholders with the actual values:

  • pickup_latitude (float): Latitude of the pickup location.
  • pickup_longitude (float): Longitude of the pickup location.
  • dropoff_latitude (float): Latitude of the dropoff location.
  • dropoff_longitude (float): Longitude of the dropoff location.
  • pickup_address (string): Address of the pickup location.
  • dropoff_address (string): Address of the dropoff location.
  • pickup_time (string): Pickup time as an ISO 8601 formatted string (e.g., "2023-03-15T12:00:00Z").
  • dropoff_time (string): Dropoff time as an ISO 8601 formatted string (e.g., "2023-03-15T12:30:00Z").
  • estimated_fare (decimal): Estimated fare for the ride.
  • payment_method (string): Payment method used for the ride.
  • distance (float): Distance of the ride in kilometers or miles, depending on your implementation.
  • duration (int): Duration of the ride in minutes.
  • special_requests (string, optional): Any special requests or notes from the passenger.

Sending chat messages

To create a chat message, send a JSON message with the following structure:

{
  **"action": "send_chat_message",**
  "message": "Hello, driver!"
}
  • message (string): message text to be sent

NOTE: send_chat_message is only available when driver accepts a ride request from passenger

Receiving messages

Passenger consumer currently only received chat_message from passenger and driver. To the differentiate the message sent, user_id will be provided in the response.

Example Response:

{
  "action": "chat_message",
  "user_id": "c18df757-d111-45c1-9b0b-45050cdef54c",
  "message": "hello passenger"
}

Disconnecting

To disconnect from the WebSocket, simply close the connection from the client-side. This will automatically disconnect the user from the server.

⚠️ **GitHub.com Fallback** ⚠️