Websocket events
SWAT APIs provide websocket interface to subscribe for simulation events in the system. Client can subscribe to real-time feed of events to build interactive ridesharing applications.
Obtaining a token
First, client should obtain a token by API:
HTTP GET /api/v2/user/token/
Token response will look like this:
{
token: "<uuid>"
}
And then subscribe to the websocket stream using some of the following URLs
All simulation events
WSS GET /simulation_events/
This endpoint returns a websocket channel subscribed for all simulation events available for the current user.
Events from single simulation
WSS GET /simulation_events/{simulation_id}
Here the {simulation_id} is a simulation ID to be subscribed. This endpoint returns a websocket channel subscribed for all events for the particular {simulation_id}, if the simulation is visible for the current user.
Simulation events of the particular type
WSS GET /simulation_events/{type}
Here the {type} is a simulation event type to be subscribed (lowercase). This endpoint returns a websocket channel subscribed for all events for the particular {type}, on all simulations visible for the current user.
Events from single simulation of the particular message type
WSS GET /simulation_events/{simulation_id}/{type}
or
WSS GET /simulation_events/{type}/{simulation_id}
(both variants supported)
Here the Integer {simulation_id} is a simulation ID to be subscribed, and the string {type} is a simulation event type to be subscribed.
Available message types
| Message Type | Description |
|---|---|
assignment | Messages about new vehicle assignment |
bookings | Messages about new bookings |
bookings_cancellation | Message about bookings cancellation |
fail_to_board | Fail to board messages |
gps_data | GPS data messages |
offers | New Offers |
no_offer | No offer messages for booking |
node_status | Node status updates |
offer_accepted | Offer acceptance messages |
offer_rejected | Offer rejection messages |
scheduler_result | Scheduler results |
vehicle_states | Message about vehicle state (GPS and Nodes together) |
vehicle_use | Vehicle can/can not be used in simulation, for various reasons |
This endpoint returns a websocket channel subscribed to all events from the simulation {simulation_id} for the particular {type}.