Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

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

Vlad Piersec59caa0cf42da
diff --git a/react/features/app/reducers.any.js b/react/features/app/reducers.any.js
index 57626bf0e1..b22bc15c55 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 a315ecdd4e..6dbeaa213b 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 c39c335186..372103063b 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 255632f9f2..7898c1dbbb 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 0000000000..70cb517cfb
--- /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;
+ }
+ },
+);