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

feat: load limits from server #725

Merged
merged 6 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
'/e2e/',
'/src/web-components',
],
transformIgnorePatterns: ['node_modules/(?!@superviz/socket-client)'],
transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.js$': 'ts-jest',
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"yargs": "^17.7.2"
},
"dependencies": {
"@superviz/socket-client": "1.9.1",
"bowser": "^2.11.0",
"bowser-jr": "^1.0.6",
"debug": "^4.3.4",
Expand Down
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
3 changes: 2 additions & 1 deletion src/lib/socket/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Socket } from 'socket.io-client';

import { ErrorCallback } from '../common/types/callbacks.types';


import { ClientState, ConnectionState, SocketErrorEvent, SocketEvent } from './types';
import { Logger } from '../../../common/utils';

Expand All @@ -13,7 +14,7 @@ export class ClientConnection {
public state: ClientState;

constructor(private socket: Socket) {
this.logger = new Logger('@superviz/socket-client/connection');
this.logger = new Logger('@superviz/sdk/socket-client/connection');
this.subscribeToManagerEvents();
this.stateObserver = new Subject();
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/socket/presence/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class PresenceRoom {
private observers: Map<PresenceEvents, Subject<PresenceEvent>> = new Map();

constructor(private io: Socket, private presence: Presence, private roomId: string) {
this.logger = new Logger('@superviz/socket-client/presence');
this.logger = new Logger('@superviz/sdk/socket-client/presence');

this.registerSubsjects();
this.subscribeToPresenceEvents();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/socket/room/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Room {
private apiKey: string,
private maxConnections: number | 'unlimited' = 100,
) {
this.logger = new Logger('@superviz/socket-client/room');
this.logger = new Logger('@superviz/sdk/socket-client/room');

const payload: JoinRoomPayload = {
name: roomId,
Expand Down
20 changes: 11 additions & 9 deletions src/services/api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ const INVALID_API_KEY = 'unit-test-invalid-api-key';
const MOCK_ABLY_KEY = 'unit-test-ably-key';

const CHECK_LIMITS_MOCK = {
usage: LIMITS_MOCK,
limits: LIMITS_MOCK,
};

const FETCH_PARTICIPANTS_BY_GROUP_MOCK = [
{
id: "any_user_id",
name: "any_name",
id: 'any_user_id',
name: 'any_name',
avatar: null,
email: 'any_email',
}
]
},
];

jest.mock('../../common/utils', () => {
return {
Expand Down Expand Up @@ -209,26 +209,28 @@ describe('ApiService', () => {
const baseUrl = 'https://dev.nodeapi.superviz.com';
const response = await ApiService.fetchLimits(baseUrl, VALID_API_KEY);

expect(response).toEqual(CHECK_LIMITS_MOCK.usage);
expect(response).toEqual(CHECK_LIMITS_MOCK.limits);
});
});

describe('fetchParticipants', () => {
test('should return the participants', async () => {
const response = await ApiService.fetchParticipantsByGroup('any_group_id');

expect(response).toEqual([{"avatar": null, "id": "any_user_id", "name": "any_name", "email": "any_email"}]);
expect(response).toEqual([
{ avatar: null, id: 'any_user_id', name: 'any_name', email: 'any_email' },
]);
});
});

describe('Mentions', () => {
test('should create a mention', async () => {
const response = await ApiService.createMentions({
commentsId: 'any_comment_id',
participants: []
participants: [],
});

expect(response).toEqual({});
});
})
});
});
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
2 changes: 1 addition & 1 deletion src/services/roomState/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PresenceEvent, PresenceEvents, Room, RoomEvents, SocketEvent } from '../../lib/socket';
import { PresenceEvent, PresenceEvents, Room, SocketEvent } from '../../lib/socket';

import { TranscriptState } from '../../common/types/events.types';
import { ParticipantType, VideoParticipant } from '../../common/types/participant.types';
Expand Down
57 changes: 16 additions & 41 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2472,13 +2472,6 @@
unbzip2-stream "1.4.3"
yargs "17.7.1"

"@reactivex/rxjs@^6.6.7":
version "6.6.7"
resolved "https://registry.yarnpkg.com/@reactivex/rxjs/-/rxjs-6.6.7.tgz#52ab48f989aba9cda2b995acc904a43e6e1b3b40"
integrity sha512-xZIV2JgHhWoVPm3uVcFbZDRVJfx2hgqmuTX7J4MuKaZ+j5jN29agniCPBwrlCmpA15/zLKcPi7/bogt0ZwOFyA==
dependencies:
tslib "^1.9.0"

"@rollup/plugin-node-resolve@^15.0.1":
version "15.1.0"
resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.1.0.tgz#9ffcd8e8c457080dba89bb9fcb583a6778dc757e"
Expand Down Expand Up @@ -2662,22 +2655,9 @@
"@sinonjs/commons" "^3.0.0"

"@socket.io/component-emitter@~3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz#96116f2a912e0c02817345b3c10751069920d553"
integrity sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==

"@superviz/socket-client@1.9.1":
version "1.9.1"
resolved "https://registry.yarnpkg.com/@superviz/socket-client/-/socket-client-1.9.1.tgz#392c370b049996dd7ea4d668ef9f69f3d8f7a123"
integrity sha512-esDtE/bSGNW1DeSuqv9/gE4tVDyaYxeQDrSeAlTA+rHQWPLOsOKyYE6r0SyNQJtThzgm0/VLtAGc+pGdcdSc8g==
dependencies:
"@reactivex/rxjs" "^6.6.7"
debug "^4.3.5"
lodash "^4.17.21"
rxjs "^7.8.1"
semantic-release-version-file "^1.0.2"
socket.io-client "^4.7.5"
zod "^3.23.8"
version "3.1.2"
resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz#821f8442f4175d8f0467b9daf26e3a18e2d02af2"
integrity sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==

"@tootallnate/once@2":
version "2.0.0"
Expand Down Expand Up @@ -4755,7 +4735,7 @@ debounce@^1.2.0:
resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.1.tgz#38881d8f4166a5c5848020c11827b834bcb3e0a5"
integrity sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==

debug@4, debug@4.3.4, debug@^4.0.0, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4, debug@~4.3.1, debug@~4.3.2:
debug@4, debug@4.3.4, debug@^4.0.0, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
Expand All @@ -4776,7 +4756,7 @@ debug@^3.1.0, debug@^3.2.7:
dependencies:
ms "^2.1.1"

debug@^4.3.1, debug@^4.3.5:
debug@^4.3.1, debug@~4.3.1, debug@~4.3.2:
version "4.3.5"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.5.tgz#e83444eceb9fedd4a1da56d671ae2446a01a6e1e"
integrity sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==
Expand Down Expand Up @@ -5035,20 +5015,20 @@ end-of-stream@^1.1.0:
once "^1.4.0"

engine.io-client@~6.5.2:
version "6.5.3"
resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-6.5.3.tgz#4cf6fa24845029b238f83c628916d9149c399bc5"
integrity sha512-9Z0qLB0NIisTRt1DZ/8U2k12RJn8yls/nXMZLn+/N8hANT3TcYjKFKcwbw5zFQiN4NTde3TSY9zb79e1ij6j9Q==
version "6.5.4"
resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-6.5.4.tgz#b8bc71ed3f25d0d51d587729262486b4b33bd0d0"
integrity sha512-GeZeeRjpD2qf49cZQ0Wvh/8NJNfeXkXXcoGh+F77oEAgo9gUHwT1fCRxSNU+YEEaysOJTnsFHmM5oAcPy4ntvQ==
dependencies:
"@socket.io/component-emitter" "~3.1.0"
debug "~4.3.1"
engine.io-parser "~5.2.1"
ws "~8.11.0"
ws "~8.17.1"
xmlhttprequest-ssl "~2.0.0"

engine.io-parser@~5.2.1:
version "5.2.2"
resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-5.2.2.tgz#37b48e2d23116919a3453738c5720455e64e1c49"
integrity sha512-RcyUFKA93/CXH20l4SoVvzZfrSDMOTUS3bWVpTt2FuFP+XYrL8i8oonHP7WInRyVHXh0n/ORtoeiE1os+8qkSw==
version "5.2.3"
resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-5.2.3.tgz#00dc5b97b1f233a23c9398d0209504cf5f94d92f"
integrity sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==

entities@^4.4.0:
version "4.5.0"
Expand Down Expand Up @@ -10598,11 +10578,6 @@ tsconfig-paths@^3.15.0:
minimist "^1.2.6"
strip-bom "^3.0.0"

tslib@^1.9.0:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@^2.0.1, tslib@^2.4.0:
version "2.6.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.1.tgz#fd8c9a0ff42590b25703c0acb3de3d3f4ede0410"
Expand Down Expand Up @@ -11148,10 +11123,10 @@ ws@^8.11.0:
resolved "https://registry.yarnpkg.com/ws/-/ws-8.14.2.tgz#6c249a806eb2db7a20d26d51e7709eab7b2e6c7f"
integrity sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==

ws@~8.11.0:
version "8.11.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.11.0.tgz#6a0d36b8edfd9f96d8b25683db2f8d7de6e8e143"
integrity sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==
ws@~8.17.1:
version "8.17.1"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.1.tgz#9293da530bb548febc95371d90f9c878727d919b"
integrity sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==

xml-name-validator@^4.0.0:
version "4.0.0"
Expand Down
Loading