fix(vpaas): Count endpoint only when there are 2 or more participants

This commit is contained in:
Vlad Piersec 2020-09-17 12:21:01 +03:00 committed by vp8x8
parent bdda8c56c7
commit 59caa0cf42
5 changed files with 57 additions and 5 deletions

View File

@ -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';

View File

@ -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';

View File

@ -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
};
}

View File

@ -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);

View File

@ -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;
}
},
);