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

Commit

Permalink
fix: remove throttle for participants update
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossantos74 committed Feb 7, 2024
1 parent 6362584 commit c80c906
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/common/types/meeting-colors.types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export enum MeetingColors {
'yellow',
'turquoise',
'orange',
'blue',
Expand All @@ -15,11 +14,11 @@ export enum MeetingColors {
'bluelight',
'redlight',
'brown',
'yellow',
'gray',
}

export enum MeetingColorsHex {
'#FFEF33',
'#31E0B0',
'#FF5E10',
'#00ABF7',
Expand All @@ -35,5 +34,6 @@ export enum MeetingColorsHex {
'#75DEFE',
'#FAA291',
'#BB813F',
'#FFEF33',
'#878291',
}
75 changes: 35 additions & 40 deletions src/services/realtime/ably/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Ably from 'ably';
import throttle from 'lodash/throttle';

import { RealtimeEvent, TranscriptState } from '../../../common/types/events.types';
import { Nullable } from '../../../common/types/global.types';
import { MeetingColors } from '../../../common/types/meeting-colors.types';
import { Participant, ParticipantType } from '../../../common/types/participant.types';
import { RealtimeStateTypes } from '../../../common/types/realtime.types';
Expand Down Expand Up @@ -64,6 +65,7 @@ export default class AblyRealtimeService extends RealtimeService implements Ably
private state: RealtimeStateTypes = RealtimeStateTypes.DISCONNECTED;
private supervizChannelState: Ably.Types.ChannelStateChange;
private connectionState: Ably.Types.ConnectionStateChange;

constructor(apiUrl: string, ablyKey: string) {
super();

Expand Down Expand Up @@ -589,7 +591,7 @@ export default class AblyRealtimeService extends RealtimeService implements Ably
* @description updates local participant properties
* @returns {void}
*/
public updateMyProperties = throttle((newProperties: ParticipantInfo = {}): void => {
public updateMyProperties = (newProperties: ParticipantInfo = {}): void => {
const properties = newProperties;

if (this.isMessageTooBig(properties) || this.left || !this.enableSync || this.isSyncFrozen) {
Expand All @@ -609,7 +611,7 @@ export default class AblyRealtimeService extends RealtimeService implements Ably

this.supervizChannel.presence.update(this.myParticipant.data);
this.logger.log('REALTIME', 'updating my properties', this.myParticipant.data);
}, SYNC_PROPERTY_INTERVAL);
};

/**
* @function updateRoomProperties
Expand Down Expand Up @@ -836,8 +838,7 @@ export default class AblyRealtimeService extends RealtimeService implements Ably
*/
findSlotIndex = (myPresenceParam: AblyParticipant | Ably.Types.PresenceMessage) => {
let myPresence = myPresenceParam;

let availableSlots = Array.apply(null, { length: 15 }).map(Number.call, Number);
let availableSlots = Array.apply(null, { length: 16 }).map(Number.call, Number);

this.supervizChannel.presence.get((error, members) => {
if (error) {
Expand All @@ -849,6 +850,7 @@ export default class AblyRealtimeService extends RealtimeService implements Ably
if (member.connectionId === myPresence.connectionId) {
myPresence = member;
}

if (
member.connectionId !== myPresence.connectionId &&
member.data.hasOwnProperty('slotIndex')
Expand All @@ -864,15 +866,9 @@ export default class AblyRealtimeService extends RealtimeService implements Ably
}

const slotChosen = availableSlots[0];

this.myParticipant.data.slotIndex = slotChosen;
this.updateMyProperties({ slotIndex: slotChosen });

const timeToWait = Math.floor(Math.random() * 500);

setTimeout(() => {
this.confirmSlot(myPresence);
}, timeToWait);
this.confirmSlot(myPresence);
};

/**
Expand All @@ -881,37 +877,36 @@ export default class AblyRealtimeService extends RealtimeService implements Ably
* @param {Ably.Types.PresenceMessage} participant
* @returns {void}
*/
private confirmSlot = throttle(
async (myPresenceParam: AblyParticipant | Ably.Types.PresenceMessage) => {
const usedSlots: Ably.Types.PresenceMessage[] = [];
let myPresence = myPresenceParam;
this.supervizChannel.presence.get((err, members) => {
members.forEach((member) => {
if (member.connectionId === myPresence.connectionId) {
myPresence = member;
}
if (
member.connectionId !== myPresence.connectionId &&
member.data.slotIndex !== undefined
) {
usedSlots.push(member.data.slotIndex);
}
});
private confirmSlot = async (myPresenceParam: AblyParticipant | Ably.Types.PresenceMessage) => {
const usedSlots: Ably.Types.PresenceMessage[] = [];
let myPresence = myPresenceParam;
this.supervizChannel.presence.get((err, members) => {
members.forEach((member) => {
if (member.connectionId === myPresence.connectionId) {
myPresence = member;
}

if (
member.connectionId !== myPresence.connectionId &&
member.data.slotIndex !== undefined
) {
usedSlots.push(member.data.slotIndex);
}
});
});

if (
this.myParticipant.data.slotIndex === undefined ||
usedSlots.includes(this.myParticipant.data.slotIndex)
) {
this.findSlotIndex(myPresence);
} else {
// confirm slot and propagate
const roomProperties = await this.fetchRoomProperties();
this.updateRoomProperties(roomProperties);
}
},
1000,
);
if (
this.myParticipant.data.slotIndex === null ||
this.myParticipant.data.slotIndex === undefined ||
usedSlots.includes(this.myParticipant.data.slotIndex)
) {
this.findSlotIndex(myPresence);
} else {
// confirm slot and propagate
const roomProperties = await this.fetchRoomProperties();
this.updateRoomProperties(roomProperties);
}
};

/**
* @function onStateChange
Expand Down

0 comments on commit c80c906

Please sign in to comment.