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

Commit d004243

Browse files
Merge pull request #725 from SuperViz/feat/load-limits-from-server
feat: load limits from server
2 parents cd4f2be + 6aeb7f0 commit d004243

File tree

10 files changed

+42
-83
lines changed

10 files changed

+42
-83
lines changed

jest.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module.exports = {
2020
'/e2e/',
2121
'/src/web-components',
2222
],
23-
transformIgnorePatterns: ['node_modules/(?!@superviz/socket-client)'],
2423
transform: {
2524
'^.+\\.ts$': 'ts-jest',
2625
'^.+\\.js$': 'ts-jest',

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
"yargs": "^17.7.2"
8383
},
8484
"dependencies": {
85-
"@superviz/socket-client": "1.9.1",
8685
"bowser": "^2.11.0",
8786
"bowser-jr": "^1.0.6",
8887
"debug": "^4.3.4",

src/core/index.ts

+3-16
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ const init = async (apiKey: string, options: SuperVizSdkOptions): Promise<Launch
107107
throw new Error('Failed to validate API key');
108108
}
109109

110-
const [environment, waterMark] = await Promise.all([
110+
const [environment, waterMark, limits] = await Promise.all([
111111
ApiService.fetchConfig(apiUrl, apiKey),
112112
ApiService.fetchWaterMark(apiUrl, apiKey),
113+
ApiService.fetchLimits(apiUrl, apiKey),
113114
]).catch(() => {
114115
throw new Error('Failed to load configuration from server');
115116
});
@@ -129,21 +130,7 @@ const init = async (apiKey: string, options: SuperVizSdkOptions): Promise<Launch
129130
environment: (options.environment as EnvironmentTypes) ?? EnvironmentTypes.PROD,
130131
roomId,
131132
debug: options.debug,
132-
limits: {
133-
presence: {
134-
canUse: true,
135-
maxParticipants: 50,
136-
},
137-
realtime: {
138-
canUse: true,
139-
maxParticipants: 200,
140-
},
141-
videoConference: {
142-
canUse: true,
143-
maxParticipants: 255,
144-
canUseTranscript: true,
145-
},
146-
},
133+
limits,
147134
waterMark,
148135
colors: options.customColors,
149136
features,

src/lib/socket/connection/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Socket } from 'socket.io-client';
33

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

6+
67
import { ClientState, ConnectionState, SocketErrorEvent, SocketEvent } from './types';
78
import { Logger } from '../../../common/utils';
89

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

1516
constructor(private socket: Socket) {
16-
this.logger = new Logger('@superviz/socket-client/connection');
17+
this.logger = new Logger('@superviz/sdk/socket-client/connection');
1718
this.subscribeToManagerEvents();
1819
this.stateObserver = new Subject();
1920
}

src/lib/socket/presence/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class PresenceRoom {
1414
private observers: Map<PresenceEvents, Subject<PresenceEvent>> = new Map();
1515

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

1919
this.registerSubsjects();
2020
this.subscribeToPresenceEvents();

src/lib/socket/room/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Room {
2424
private apiKey: string,
2525
private maxConnections: number | 'unlimited' = 100,
2626
) {
27-
this.logger = new Logger('@superviz/socket-client/room');
27+
this.logger = new Logger('@superviz/sdk/socket-client/room');
2828

2929
const payload: JoinRoomPayload = {
3030
name: roomId,

src/services/api/index.test.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ const INVALID_API_KEY = 'unit-test-invalid-api-key';
88
const MOCK_ABLY_KEY = 'unit-test-ably-key';
99

1010
const CHECK_LIMITS_MOCK = {
11-
usage: LIMITS_MOCK,
11+
limits: LIMITS_MOCK,
1212
};
1313

1414
const FETCH_PARTICIPANTS_BY_GROUP_MOCK = [
1515
{
16-
id: "any_user_id",
17-
name: "any_name",
16+
id: 'any_user_id',
17+
name: 'any_name',
1818
avatar: null,
1919
email: 'any_email',
20-
}
21-
]
20+
},
21+
];
2222

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

212-
expect(response).toEqual(CHECK_LIMITS_MOCK.usage);
212+
expect(response).toEqual(CHECK_LIMITS_MOCK.limits);
213213
});
214214
});
215215

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

220-
expect(response).toEqual([{"avatar": null, "id": "any_user_id", "name": "any_name", "email": "any_email"}]);
220+
expect(response).toEqual([
221+
{ avatar: null, id: 'any_user_id', name: 'any_name', email: 'any_email' },
222+
]);
221223
});
222224
});
223225

224226
describe('Mentions', () => {
225227
test('should create a mention', async () => {
226228
const response = await ApiService.createMentions({
227229
commentsId: 'any_comment_id',
228-
participants: []
230+
participants: [],
229231
});
230232

231233
expect(response).toEqual({});
232234
});
233-
})
235+
});
234236
});

src/services/api/index.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { SuperVizSdkOptions } from '../../common/types/sdk-options.types';
22
import { doRequest } from '../../common/utils';
33
import { Annotation } from '../../components/comments/types';
44
import config from '../config';
5-
5+
import { ComponentLimits } from '../limits/types';
66

77
import {
88
AnnotationParams,
99
CommentParams,
1010
CreateOrUpdateParticipantParams,
1111
FetchAnnotationsParams,
12-
MentionParams
12+
MentionParams,
1313
} from './types';
1414

1515
export default class ApiService {
@@ -32,11 +32,11 @@ export default class ApiService {
3232
return doRequest(url, 'POST', { apiKey });
3333
}
3434

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

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

133-
static async fetchParticipantsByGroup(
134-
groupId: string,
135-
) {
133+
static async fetchParticipantsByGroup(groupId: string) {
136134
const path = `/groups/participants/${groupId}`;
137135
const baseUrl = config.get<string>('apiUrl');
138136
const url = this.createUrl(baseUrl, path, { take: 10000 });
139137
return doRequest(url, 'GET', undefined, { apikey: config.get('apiKey') });
140138
}
141139

142-
static async createMentions(
143-
mentionParams: MentionParams
144-
) {
140+
static async createMentions(mentionParams: MentionParams) {
145141
const path = '/mentions';
146142
const baseUrl = config.get<string>('apiUrl');
147143
const url = this.createUrl(baseUrl, path);

src/services/roomState/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PresenceEvent, PresenceEvents, Room, RoomEvents, SocketEvent } from '../../lib/socket';
1+
import { PresenceEvent, PresenceEvents, Room, SocketEvent } from '../../lib/socket';
22

33
import { TranscriptState } from '../../common/types/events.types';
44
import { ParticipantType, VideoParticipant } from '../../common/types/participant.types';

yarn.lock

+16-41
Original file line numberDiff line numberDiff line change
@@ -2472,13 +2472,6 @@
24722472
unbzip2-stream "1.4.3"
24732473
yargs "17.7.1"
24742474

2475-
"@reactivex/rxjs@^6.6.7":
2476-
version "6.6.7"
2477-
resolved "https://registry.yarnpkg.com/@reactivex/rxjs/-/rxjs-6.6.7.tgz#52ab48f989aba9cda2b995acc904a43e6e1b3b40"
2478-
integrity sha512-xZIV2JgHhWoVPm3uVcFbZDRVJfx2hgqmuTX7J4MuKaZ+j5jN29agniCPBwrlCmpA15/zLKcPi7/bogt0ZwOFyA==
2479-
dependencies:
2480-
tslib "^1.9.0"
2481-
24822475
"@rollup/plugin-node-resolve@^15.0.1":
24832476
version "15.1.0"
24842477
resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.1.0.tgz#9ffcd8e8c457080dba89bb9fcb583a6778dc757e"
@@ -2662,22 +2655,9 @@
26622655
"@sinonjs/commons" "^3.0.0"
26632656

26642657
"@socket.io/component-emitter@~3.1.0":
2665-
version "3.1.0"
2666-
resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz#96116f2a912e0c02817345b3c10751069920d553"
2667-
integrity sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==
2668-
2669-
"@superviz/[email protected]":
2670-
version "1.9.1"
2671-
resolved "https://registry.yarnpkg.com/@superviz/socket-client/-/socket-client-1.9.1.tgz#392c370b049996dd7ea4d668ef9f69f3d8f7a123"
2672-
integrity sha512-esDtE/bSGNW1DeSuqv9/gE4tVDyaYxeQDrSeAlTA+rHQWPLOsOKyYE6r0SyNQJtThzgm0/VLtAGc+pGdcdSc8g==
2673-
dependencies:
2674-
"@reactivex/rxjs" "^6.6.7"
2675-
debug "^4.3.5"
2676-
lodash "^4.17.21"
2677-
rxjs "^7.8.1"
2678-
semantic-release-version-file "^1.0.2"
2679-
socket.io-client "^4.7.5"
2680-
zod "^3.23.8"
2658+
version "3.1.2"
2659+
resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz#821f8442f4175d8f0467b9daf26e3a18e2d02af2"
2660+
integrity sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==
26812661

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

4758-
debug@4, [email protected], 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:
4738+
debug@4, [email protected], debug@^4.0.0, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4:
47594739
version "4.3.4"
47604740
resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz"
47614741
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
@@ -4776,7 +4756,7 @@ debug@^3.1.0, debug@^3.2.7:
47764756
dependencies:
47774757
ms "^2.1.1"
47784758

4779-
debug@^4.3.1, debug@^4.3.5:
4759+
debug@^4.3.1, debug@~4.3.1, debug@~4.3.2:
47804760
version "4.3.5"
47814761
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.5.tgz#e83444eceb9fedd4a1da56d671ae2446a01a6e1e"
47824762
integrity sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==
@@ -5035,20 +5015,20 @@ end-of-stream@^1.1.0:
50355015
once "^1.4.0"
50365016

50375017
engine.io-client@~6.5.2:
5038-
version "6.5.3"
5039-
resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-6.5.3.tgz#4cf6fa24845029b238f83c628916d9149c399bc5"
5040-
integrity sha512-9Z0qLB0NIisTRt1DZ/8U2k12RJn8yls/nXMZLn+/N8hANT3TcYjKFKcwbw5zFQiN4NTde3TSY9zb79e1ij6j9Q==
5018+
version "6.5.4"
5019+
resolved "https://registry.yarnpkg.com/engine.io-client/-/engine.io-client-6.5.4.tgz#b8bc71ed3f25d0d51d587729262486b4b33bd0d0"
5020+
integrity sha512-GeZeeRjpD2qf49cZQ0Wvh/8NJNfeXkXXcoGh+F77oEAgo9gUHwT1fCRxSNU+YEEaysOJTnsFHmM5oAcPy4ntvQ==
50415021
dependencies:
50425022
"@socket.io/component-emitter" "~3.1.0"
50435023
debug "~4.3.1"
50445024
engine.io-parser "~5.2.1"
5045-
ws "~8.11.0"
5025+
ws "~8.17.1"
50465026
xmlhttprequest-ssl "~2.0.0"
50475027

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

50535033
entities@^4.4.0:
50545034
version "4.5.0"
@@ -10598,11 +10578,6 @@ tsconfig-paths@^3.15.0:
1059810578
minimist "^1.2.6"
1059910579
strip-bom "^3.0.0"
1060010580

10601-
tslib@^1.9.0:
10602-
version "1.14.1"
10603-
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
10604-
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
10605-
1060610581
tslib@^2.0.1, tslib@^2.4.0:
1060710582
version "2.6.1"
1060810583
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.1.tgz#fd8c9a0ff42590b25703c0acb3de3d3f4ede0410"
@@ -11148,10 +11123,10 @@ ws@^8.11.0:
1114811123
resolved "https://registry.yarnpkg.com/ws/-/ws-8.14.2.tgz#6c249a806eb2db7a20d26d51e7709eab7b2e6c7f"
1114911124
integrity sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==
1115011125

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

1115611131
xml-name-validator@^4.0.0:
1115711132
version "4.0.0"

0 commit comments

Comments
 (0)