Skip to content

Commit

Permalink
fix(vpaas): Count endpoint only when there are 2 or more participants
Browse files Browse the repository at this point in the history
  • Loading branch information
vp8x8 committed Oct 12, 2020
1 parent bdda8c5 commit 59caa0c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
1 change: 1 addition & 0 deletions react/features/app/reducers.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import '../base/sounds/reducer';
import '../base/testing/reducer';
import '../base/tracks/reducer';
import '../base/user-interaction/reducer';
import '../billing-counter/reducer';
import '../blur/reducer';
import '../calendar-sync/reducer';
import '../chat/reducer';
Expand Down
5 changes: 5 additions & 0 deletions react/features/billing-counter/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
* Action used to store the billing id.
*/
export const SET_BILLING_ID = 'SET_BILLING_ID';

/**
* Action used to store the flag signaling the endpoint has been counted.
*/
export const SET_ENDPOINT_COUNTED = 'SET_ENDPOINT_COUNTED';
14 changes: 13 additions & 1 deletion react/features/billing-counter/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import uuid from 'uuid';

import { SET_BILLING_ID } from './actionTypes';
import { SET_BILLING_ID, SET_ENDPOINT_COUNTED } from './actionTypes';
import { extractVpaasTenantFromPath, getBillingId, sendCountRequest } from './functions';

/**
Expand Down Expand Up @@ -33,6 +33,7 @@ export function countEndpoint() {
jwt,
tenant
});
dispatch(setEndpointCounted());
}
};
}
Expand All @@ -49,3 +50,14 @@ function setBillingId(value) {
value
};
}

/**
* Action used to mark the endpoint as counted.
*
* @returns {Object}
*/
function setEndpointCounted() {
return {
type: SET_ENDPOINT_COUNTED
};
}
13 changes: 9 additions & 4 deletions react/features/billing-counter/middleware.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CONFERENCE_JOINED } from '../base/conference/actionTypes';
import { PARTICIPANT_JOINED } from '../base/participants/actionTypes';
import { MiddlewareRegistry } from '../base/redux';

import { SET_BILLING_ID } from './actionTypes';
Expand All @@ -11,6 +11,7 @@ import { setBillingId } from './functions';
* @param {Store} store - The redux store.
* @returns {Function}
*/

MiddlewareRegistry.register(store => next => async action => {
switch (action.type) {
case SET_BILLING_ID: {
Expand All @@ -19,12 +20,16 @@ MiddlewareRegistry.register(store => next => async action => {
break;
}

case CONFERENCE_JOINED: {
store.dispatch(countEndpoint());
case PARTICIPANT_JOINED: {
const shouldCount = !store.getState()['features/billing-counter'].endpointCounted
&& !action.participant.local;

if (shouldCount) {
store.dispatch(countEndpoint());
}

break;
}

}

return next(action);
Expand Down
29 changes: 29 additions & 0 deletions react/features/billing-counter/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ReducerRegistry } from '../base/redux';

import {
SET_ENDPOINT_COUNTED
} from './actionTypes';

const DEFAULT_STATE = {
endpointCounted: false
};

/**
* Listen for actions that mutate the billing-counter state
*/
ReducerRegistry.register(
'features/billing-counter', (state = DEFAULT_STATE, action) => {
switch (action.type) {

case SET_ENDPOINT_COUNTED: {
return {
...state,
endpointCounted: true
};
}

default:
return state;
}
},
);

0 comments on commit 59caa0c

Please sign in to comment.