Skip to content
This repository has been archived by the owner on May 29, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/site
Browse files Browse the repository at this point in the history
  • Loading branch information
RamBoFe committed Mar 26, 2019
2 parents 4cdb213 + d2db6ac commit 3cc41ea
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
11 changes: 11 additions & 0 deletions api/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ export const IN_PROGRESS = 'progress';
export const DELIVERED = 'delivered';
export const DONE = 'done';
export const CANCELED = 'canceled';
export const CANCELED_TECHNICAL = 'canceled_technical';
export const CANCELED_REQUESTED_CUSTOMER = 'canceled_requested_customer';
export const CANCELED_CUSTOMER_OVERLOAD = 'canceled_customer_overload';
export const CANCELED_CUSTOMER_MISSING = 'canceled_customer_missing';
export const CANCELED_STATUSES = [
CANCELED,
CANCELED_TECHNICAL,
CANCELED_REQUESTED_CUSTOMER,
CANCELED_CUSTOMER_OVERLOAD,
CANCELED_CUSTOMER_MISSING,
];

export const isDeclined = status => status.startsWith(DECLINED);

Expand Down
2 changes: 1 addition & 1 deletion pages/_ride_id.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export default {
try {
const rideAPI = $api
.rides('id,departure(label,location(coordinates)),arrival(label,location(coordinates)),'
+ 'driver(id,name),car(id,model(label)),position,status');
+ 'driver(id,name),car(id,model(label)),position,status,token');
const { data: ride } = await rideAPI.getRide(rideId, token);
const { data: { position, date } } = await rideAPI.getDriverPosition(rideId, token);
Expand Down
22 changes: 15 additions & 7 deletions plugins/socket.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import Vue from 'vue';
import VueSocketio from 'vue-socket.io-extended';
import io from 'socket.io-client';
import { CANCELED_STATUSES, DELIVERED } from '../api/status';


export default function ({ env, store, query }, inject) {
export default function ({ env, store }, inject) {
const ioInstance = io(env.apiUrl, { autoConnect: false });
Vue.use(VueSocketio, ioInstance, { store });
inject('io', ioInstance);
ioInstance.on('connect', () => {
const { token = null } = query;
ioInstance.emit('roomJoinRide', { id: store.getters['ride/rideId'], token });
ioInstance.emit(
'roomJoinRide',
{ id: store.getters['ride/ride'].id, token: store.getters['ride/ride'].token },
);
});
const autoConnect = (rideId) => {
if (rideId) {
ioInstance.on('rideUpdate', (ride) => {
if (ride && (ride.status === DELIVERED || CANCELED_STATUSES.indexOf(ride.status) !== -1)) {
ioInstance.close();
}
});
const autoConnect = (ride) => {
if (ride && ride.id && ride.status !== DELIVERED && CANCELED_STATUSES.indexOf(ride.status) === -1) {
ioInstance.open();
} else {
ioInstance.close();
}
};
autoConnect(store.getters['ride/rideId']);
store.watch((state, getters) => getters['ride/rideId'], autoConnect);
autoConnect(store.getters['ride/ride']);
store.watch((state, getters) => getters['ride/ride'], autoConnect);
}

0 comments on commit 3cc41ea

Please sign in to comment.