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

Commit

Permalink
feat: load limits from server
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossantos74 committed Jul 19, 2024
1 parent ce84111 commit fe93e58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
19 changes: 3 additions & 16 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ const init = async (apiKey: string, options: SuperVizSdkOptions): Promise<Launch
throw new Error('Failed to validate API key');
}

const [environment, waterMark] = await Promise.all([
const [environment, waterMark, limits] = await Promise.all([
ApiService.fetchConfig(apiUrl, apiKey),
ApiService.fetchWaterMark(apiUrl, apiKey),
ApiService.fetchLimits(apiUrl, apiKey),
]).catch(() => {
throw new Error('Failed to load configuration from server');
});
Expand All @@ -129,21 +130,7 @@ const init = async (apiKey: string, options: SuperVizSdkOptions): Promise<Launch
environment: (options.environment as EnvironmentTypes) ?? EnvironmentTypes.PROD,
roomId,
debug: options.debug,
limits: {
presence: {
canUse: true,
maxParticipants: 50,
},
realtime: {
canUse: true,
maxParticipants: 200,
},
videoConference: {
canUse: true,
maxParticipants: 255,
canUseTranscript: true,
},
},
limits,
waterMark,
colors: options.customColors,
features,
Expand Down
18 changes: 7 additions & 11 deletions src/services/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { SuperVizSdkOptions } from '../../common/types/sdk-options.types';
import { doRequest } from '../../common/utils';
import { Annotation } from '../../components/comments/types';
import config from '../config';

import { ComponentLimits } from '../limits/types';

import {
AnnotationParams,
CommentParams,
CreateOrUpdateParticipantParams,
FetchAnnotationsParams,
MentionParams
MentionParams,
} from './types';

export default class ApiService {
Expand All @@ -32,11 +32,11 @@ export default class ApiService {
return doRequest(url, 'POST', { apiKey });
}

static async fetchLimits(baseUrl: string, apikey: string) {
const path: string = '/user/check_limits';
static async fetchLimits(baseUrl: string, apikey: string): Promise<ComponentLimits> {
const path: string = '/user/check_limits_v2';
const url: string = this.createUrl(baseUrl, path);
const result = await doRequest(url, 'GET', '', { apikey });
return result.usage;
return result.limits;
}

static async fetchWaterMark(baseUrl: string, apiKey: string) {
Expand Down Expand Up @@ -130,18 +130,14 @@ export default class ApiService {
return doRequest(url, 'POST', body, { apikey });
}

static async fetchParticipantsByGroup(
groupId: string,
) {
static async fetchParticipantsByGroup(groupId: string) {
const path = `/groups/participants/${groupId}`;
const baseUrl = config.get<string>('apiUrl');
const url = this.createUrl(baseUrl, path, { take: 10000 });
return doRequest(url, 'GET', undefined, { apikey: config.get('apiKey') });
}

static async createMentions(
mentionParams: MentionParams
) {
static async createMentions(mentionParams: MentionParams) {
const path = '/mentions';
const baseUrl = config.get<string>('apiUrl');
const url = this.createUrl(baseUrl, path);
Expand Down

0 comments on commit fe93e58

Please sign in to comment.