From 59caa0cf42da0bc14de5da74bce0dc4cc327aed9 Mon Sep 17 00:00:00 2001 From: Vlad Piersec Date: Thu, 17 Sep 2020 12:21:01 +0300 Subject: [PATCH] fix(vpaas): Count endpoint only when there are 2 or more participants --- react/features/app/reducers.any.js | 1 + react/features/billing-counter/actionTypes.js | 5 ++++ react/features/billing-counter/actions.js | 14 ++++++++- react/features/billing-counter/middleware.js | 13 ++++++--- react/features/billing-counter/reducer.js | 29 +++++++++++++++++++ 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 react/features/billing-counter/reducer.js diff --git a/react/features/app/reducers.any.js b/react/features/app/reducers.any.js index 57626bf0e..b22bc15c5 100644 --- a/react/features/app/reducers.any.js +++ b/react/features/app/reducers.any.js @@ -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'; diff --git a/react/features/billing-counter/actionTypes.js b/react/features/billing-counter/actionTypes.js index a315ecdd4..6dbeaa213 100644 --- a/react/features/billing-counter/actionTypes.js +++ b/react/features/billing-counter/actionTypes.js @@ -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'; diff --git a/react/features/billing-counter/actions.js b/react/features/billing-counter/actions.js index c39c33518..372103063 100644 --- a/react/features/billing-counter/actions.js +++ b/react/features/billing-counter/actions.js @@ -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'; /** @@ -33,6 +33,7 @@ export function countEndpoint() { jwt, tenant }); + dispatch(setEndpointCounted()); } }; } @@ -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 + }; +} diff --git a/react/features/billing-counter/middleware.js b/react/features/billing-counter/middleware.js index 255632f9f..7898c1dbb 100644 --- a/react/features/billing-counter/middleware.js +++ b/react/features/billing-counter/middleware.js @@ -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'; @@ -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: { @@ -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); diff --git a/react/features/billing-counter/reducer.js b/react/features/billing-counter/reducer.js new file mode 100644 index 000000000..70cb517cf --- /dev/null +++ b/react/features/billing-counter/reducer.js @@ -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; + } + }, +);