Skip to content

Commit

Permalink
Enable presence broadcast when license is validated
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva137 committed Sep 15, 2023
1 parent 361896e commit 6d49ccf
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions ee/packages/presence/src/Presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Presence extends ServiceClass implements IPresence {

private broadcastEnabled = true;

private hasLicense?: boolean;
private hasLicense = false;

private lostConTimeout?: NodeJS.Timeout;

Expand All @@ -39,9 +39,17 @@ export class Presence extends ServiceClass implements IPresence {
}
});

this.onEvent('license.module', ({ module, valid }) => {
this.onEvent('license.module', async ({ module, valid }) => {
if (module === 'scalability') {
this.hasLicense = valid;

if (!this.broadcastEnabled && valid) {
// broadcast should always be enabled if license is active (unless the troubleshoot setting is on)
const presenceBroadcastDisabled = await Settings.findOneById('Troubleshoot_Disable_Presence_Broadcast');
if (presenceBroadcastDisabled?.value === false) {
await this.toggleBroadcast(true);
}
}
}
});
}
Expand All @@ -58,9 +66,9 @@ export class Presence extends ServiceClass implements IPresence {
}, 10000);

try {
this.hasLicense = await License.hasLicense('scalability');

await Settings.updateValueById('Presence_broadcast_disabled', false);

this.hasLicense = await License.hasLicense('scalability');
} catch (e: unknown) {
// ignore
}
Expand All @@ -74,7 +82,7 @@ export class Presence extends ServiceClass implements IPresence {
}

async toggleBroadcast(enabled: boolean): Promise<void> {
if (this.hasLicense === false && this.getTotalConnections() > MAX_CONNECTIONS) {
if (!this.hasLicense && this.getTotalConnections() > MAX_CONNECTIONS) {
throw new Error('Cannot enable broadcast when there are more than 200 connections');
}
this.broadcastEnabled = enabled;
Expand Down Expand Up @@ -232,14 +240,7 @@ export class Presence extends ServiceClass implements IPresence {
}

private async validateAvailability(): Promise<void> {
if (this.hasLicense !== false) {
if (!this.broadcastEnabled) {
// broadcast should always be enabled if license is active (unless the troubleshoot setting is on)
const presenceBroadcastDisabled = await Settings.findOneById('Troubleshoot_Disable_Presence_Broadcast');
if (presenceBroadcastDisabled?.value === false) {
await this.toggleBroadcast(true);
}
}
if (this.hasLicense) {
return;
}

Expand Down

0 comments on commit 6d49ccf

Please sign in to comment.