Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: wait to assign a slot before try again
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossantos74 committed Jul 17, 2024
1 parent dd518a7 commit cdc1d7a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/services/slot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { useStore } from '../../common/utils/use-store';
import { ComponentNames } from '../../components/types';

export class SlotService {
private isAssigningSlot = false;

public slot: Slot = {
index: null,
color: MEETING_COLORS.gray,
Expand All @@ -34,6 +36,9 @@ export class SlotService {
* @returns void
*/
public async assignSlot(): Promise<Slot> {
if (this.isAssigningSlot) return this.slot;

this.isAssigningSlot = true;
let slots = Array.from({ length: 50 }, (_, i) => i);
let slot = Math.floor(Math.random() * 50);
const { localParticipant, participants } = useStore(StoreType.GLOBAL);
Expand Down Expand Up @@ -92,6 +97,7 @@ export class SlotService {

this.room.presence.update({ slot: slotData });

this.isAssigningSlot = false;
return slotData;
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -193,6 +199,8 @@ export class SlotService {
* @returns {void}
*/
private validateSlotType = async (participant: Participant): Promise<Slot> => {
if (this.isAssigningSlot) return this.slot;

const needSlot = this.participantNeedsSlot(participant);

if (participant.slot?.index === null && needSlot) {
Expand Down

0 comments on commit cdc1d7a

Please sign in to comment.