refactor(pads): improve session creation

Add a throttle control to avoid multiple create session calls in a short
period of time.
This commit is contained in:
Pedro Beschorner Marin 2022-04-07 10:26:59 -03:00
parent 3853d9f799
commit 307a6cb83c

View File

@ -1,9 +1,11 @@
import _ from 'lodash';
import Pads, { PadsUpdates } from '/imports/api/pads';
import { makeCall } from '/imports/ui/services/api';
import Auth from '/imports/ui/services/auth';
import Settings from '/imports/ui/services/settings';
const PADS_CONFIG = Meteor.settings.public.pads;
const THROTTLE_TIMEOUT = 2000;
const getLang = () => {
const { locale } = Settings.application;
@ -38,6 +40,11 @@ const hasPad = (externalId) => {
const createSession = (externalId) => makeCall('createSession', externalId);
const throttledCreateSession = _.throttle(createSession, THROTTLE_TIMEOUT, {
leading: true,
trailing: false,
});
const buildPadURL = (padId) => {
if (padId) {
const params = getParams();
@ -89,7 +96,7 @@ export default {
getPadId,
createGroup,
hasPad,
createSession,
createSession: (externalId) => throttledCreateSession(externalId),
buildPadURL,
getRev,
getPadTail,