Merge branch '436-cmb-uat-requests' into '424-cmb-release'
Add channel for rider availability to add/remove rider when rider goes online/offline. #436 See merge request jankstudio/resq!512
This commit is contained in:
commit
dc678fd622
3 changed files with 26 additions and 2 deletions
|
|
@ -36,6 +36,10 @@ class MapEventHandler {
|
|||
// subscribe to rider status
|
||||
console.log('subscribing to ' + my.options.channels.rider_status);
|
||||
my.mqtt.subscribe(my.options.channels.rider_status);
|
||||
|
||||
// subscribe to rider availability
|
||||
console.log('subscribing to ' + my.options.channels.rider_availability);
|
||||
my.mqtt.subscribe(my.options.channels.rider_availability);
|
||||
}
|
||||
|
||||
if (my.options.track_jo) {
|
||||
|
|
@ -76,6 +80,17 @@ class MapEventHandler {
|
|||
handleRider(chan_split, payload) {
|
||||
console.log("rider message");
|
||||
switch (chan_split[2]) {
|
||||
case "availability":
|
||||
console.log("got availability for rider " + chan_split[1] + " - " + payload);
|
||||
switch (payload) {
|
||||
case 'rider_offline':
|
||||
this.dashmap.removeRiderMarker(chan_split[1]);
|
||||
break;
|
||||
case 'rider_online':
|
||||
this.dashmap.putRiderAvailableMarker(chan_split[1], lat, lng);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "location":
|
||||
console.log("got location for rider " + chan_split[1] + " - " + payload);
|
||||
var pl_split = payload.split(':');
|
||||
|
|
@ -88,7 +103,7 @@ class MapEventHandler {
|
|||
var lat = parseFloat(pl_split[0]);
|
||||
var lng = parseFloat(pl_split[1]);
|
||||
|
||||
// TODO: check if available or not
|
||||
// TODO: cache rider availability status and check before displaying icon
|
||||
this.dashmap.putRiderAvailableMarker(chan_split[1], lat, lng);
|
||||
break;
|
||||
case "status":
|
||||
|
|
|
|||
|
|
@ -281,6 +281,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
|
||||
$this->em->flush();
|
||||
|
||||
// send mqtt event to put rider on map
|
||||
$channel = 'rider/' . $rider->getID() . '/availability';
|
||||
$this->mclient->publish($channel, 'rider_online');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
@ -301,6 +305,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
|
||||
$this->em->flush();
|
||||
|
||||
// send mqtt event to remove rider from map
|
||||
$channel = 'rider/' . $rider->getID() . '/availability';
|
||||
$this->mclient->publish($channel, 'rider_offline');
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,8 @@ function initEventHandler(dashmap, icons, ssl) {
|
|||
'rider_status': 'rider/+/status',
|
||||
'jo_location': 'jo/+/location',
|
||||
'jo_status': 'jo/+/status',
|
||||
'jo_origin': 'jo/+/origin'
|
||||
'jo_origin': 'jo/+/origin',
|
||||
'rider_availability': 'rider/+/availability'
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue