import Pusher from "pusher-js";
// Configure Pusher client
const pusher = new Pusher(import.meta.env.VITE_REVERB_APP_KEY, { //jwmobrei3pmoleii6tab
wsHost: import.meta.env.VITE_REVERB_HOST, // apiv3.thuelai.vn
wsPort: import.meta.env.VITE_REVERB_PORT, // 8080
wssPort: import.meta.env.VITE_REVERB_SCHEME, // wss
forceTLS: false,
disableStats: true,
enabledTransports: ["ws", "wss"],
cluster: "mt1",
authEndpoint: "/api/customer/broadcasting/auth",
auth: {
headers: {
Authorization: "Bearer TOKEN",
Accept: "application/json",
},
},
});
// Subscribe to private channel
const channel = pusher.subscribe("private-chillgo.customer.1");
// Listen for events
channel.bind("DriverStatusUpdated", function (data) {
console.log("Received event:", data);
});
// Handle connection states
pusher.connection.bind("connected", () => {
console.log("Connected to Reverb websockets");
});
pusher.connection.bind("error", (err) => {
console.error("Connection error:", err);
});
// Export for reuse if needed
export default pusher;
{
"service_id":2,
"pick_up_address":"Hồ phú đô",
"pick_up_latitude":21.0257737,
"pick_up_longitude":105.7433512,
"drop_off_address":"Hồ hoàn kiếm",
"drop_off_latitude":21.0284297,
"drop_off_longitude":105.7782687
}
{
"code": 200,
"message": "Success",
"data": {
"customer_id": 1,
"booking_service_id": 2,
"created_at": "2025-04-21T02:33:55.000000Z",
"updated_at": "2025-04-21T02:33:55.000000Z",
"pick_up_address": "Hồ phú đô",
"pick_up_latitude": 21.0257737,
"pick_up_longitude": 105.7433512,
"drop_off_address": "Hồ hoàn kiếm",
"drop_off_latitude": 21.0284297,
"drop_off_longitude": 105.7782687,
"number_hour": 0,
"number_day": 0,
"distance": 6.069,
"start_date": null,
"end_date": null,
"requirement": "",
"note": "",
"number_driver": 1,
"base_price": 321000,
"info_price": "{\"base_price\":321000,\"vat\":0,\"platform_fee\":0,\"final_price\":321000}",
"final_price": 321000,
"order_status_id": 1,
"id": 14
}
}
{
"event":"chillgo.driver.ride.new",
"data":"{\"ride\":{\"id\":5,\"pick_up_address\":\"Hồ phú đô\",\"pick_up_latitude\":\"21.0257737\",\"pick_up_longitude\":\"105.7433512\",\"drop_off_address\":\"Hồ hoàn kiếm\",\"drop_off_latitude\":\"21.0284297\",\"drop_off_longitude\":\"105.7782687\",\"distance\":\"6.07\",\"final_price\":\"321000.00\",\"status\":{\"id\":1,\"label\":\"Đang tìm tài xế\"}},\"time\":\"2025-04-21 02:33:55\"}",
"channel":"private-chillgo.driver.1"
}
API: api/driver/booking/accept
{
"code": 200,
"message": "Success",
"data": {
"message": "Your application has been recorded"
}
}
Chạy link http://localhost:8000/demo-accept-driver để chấp nhận cuốc xe
Chú ý là demo nên 1 cuốc chỉ nên có 1 thằng nhận để dễ làm.
Hiện tại đang làm đơn giản sắp xếp thằng gần nhất dựa trên khoảng cách tài xế gửi lên. Nếu làm nhiều tài xế thì chú ý cái này
{"event":"chillgo.driver.ride.changed","data":"{\"ride\":{\"id\":5,\"pick_up_address\":\"Hồ phú đô\",\"pick_up_latitude\":\"21.0257737\",\"pick_up_longitude\":\"105.7433512\",\"drop_off_address\":\"Hồ hoàn kiếm\",\"drop_off_latitude\":\"21.0284297\",\"drop_off_longitude\":\"105.7782687\",\"distance\":\"6.07\",\"final_price\":\"321000.00\",\"status\":{\"id\":2,\"label\":\"Tìm thấy tài xế\"}},\"time\":\"2025-04-21 02:40:54\"}","channel":"private-chillgo.driver.1"}
{"event":"chillgo.customer.ride.changed","data":"{\"ride\":{\"id\":5,\"pick_up_address\":\"Hồ phú đô\",\"pick_up_latitude\":\"21.0257737\",\"pick_up_longitude\":\"105.7433512\",\"drop_off_address\":\"Hồ hoàn kiếm\",\"drop_off_latitude\":\"21.0284297\",\"drop_off_longitude\":\"105.7782687\",\"distance\":\"6.07\",\"final_price\":\"321000.00\",\"status\":{\"id\":2,\"label\":\"Tìm thấy tài xế\"}},\"time\":\"2025-04-21 02:40:54\"}","channel":"private-chillgo.customer.1"}
| ID | Trạng thái |
|---|---|
| 1 | Đang tìm tài xế |
| 2 | Tìm thấy tài xế |
| 3 | Tài xế đang di chuyển |
| 4 | Tài xế đã đến nơi |
| 5 | Tài xế đang chờ khách |
| 6 | Tài xế đã đón khách |
| 7 | Đang di chuyển |
| 8 | Đã hoàn thành chuyến |
| 9 | Đã đánh giá chuyến đi |
| 10 | Tài xế hủy chuyến |
| 11 | Khách hàng hủy chuyến |
| 12 | Hệ thống hủy chuyển |
| 13 | Admin hủy chuyển |
api/driver/booking/status
Request: ride_id, status images[]
{
"code": 200,
"message": "Success",
"data": {
"message": "Ride status updated successfully"
}
}