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

Commit efef5d6

Browse files
Merge pull request #766 from SuperViz/beta
Beta
2 parents 098150f + 5abee05 commit efef5d6

File tree

98 files changed

+937
-1435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+937
-1435
lines changed

.esbuild/build.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ const esbuild = require('esbuild');
66
await Promise.all([
77
esbuild.build({
88
...cjsConfig,
9-
outfile: 'lib/index.cjs.js',
9+
outfile: 'dist/index.cjs.js',
1010
}),
1111

1212
esbuild.build({
1313
...esmConfig,
14-
outdir: 'lib',
14+
outdir: 'dist',
1515
}),
1616
]);
1717
} catch (error) {

__mocks__/config.mock.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { LIMITS_MOCK } from './limits.mock';
66
import { WATERMARK_MOCK } from './watermark.mock';
77

88
export const MOCK_CONFIG: Configuration = {
9-
ablyKey: 'unit-test-ably-key',
109
apiKey: 'unit-test-api-key',
1110
apiUrl: 'http://unit-test-api-url',
1211
conferenceLayerUrl: 'https://unit-test-conference-layer-url',

__mocks__/io.mock.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { jest } from '@jest/globals';
2-
import { Room } from '../src/lib/socket';
2+
import { Room } from '@superviz/socket-client';
33

44
export const MOCK_IO = {
55
ClientState: {

jest.setup.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ global.DOMPoint = class {
3636
}
3737
};
3838

39-
jest.mock('./src/lib/socket', () => MOCK_IO);
39+
jest.mock('@superviz/socket-client', () => MOCK_IO);

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"name": "@superviz/sdk",
33
"version": "0.0.0-development",
44
"description": "SuperViz SDK",
5-
"main": "./lib/index.js",
6-
"types": "./lib/index.d.ts",
5+
"main": "./dist/index.js",
6+
"types": "./dist/index.d.ts",
77
"exports": {
8-
"import": "./lib/index.js",
9-
"require": "./lib/index.cjs.js"
8+
"import": "./dist/index.js",
9+
"require": "./dist/index.cjs.js"
1010
},
1111
"files": [
12-
"lib"
12+
"dist"
1313
],
1414
"scripts": {
1515
"prepare": "husky install",
@@ -92,7 +92,7 @@
9292
"luxon": "^3.4.4",
9393
"rxjs": "^7.8.1",
9494
"semantic-release-version-file": "^1.0.2",
95-
"socket.io-client": "^4.7.5",
95+
"@superviz/socket-client": "^1.10.0",
9696
"zod": "^3.23.8"
9797
},
9898
"config": {

src/common/styles/global.css

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
--sv-primary: 98, 16, 204;
66
}
77

8-
html, body {
8+
html,
9+
body {
910
width: 100%;
1011
height: 100%;
1112
overflow: hidden;
@@ -46,14 +47,14 @@ html, body {
4647
display: none;
4748
}
4849

49-
5050
/* Presence Mouse */
5151

5252
.pointer-mouse {
5353
display: flex;
54-
height: 17px;
55-
width: 17px;
54+
height: 15px;
55+
width: 16px;
5656
background-image: url(https://production.cdn.superviz.com/static/pointers/0.svg);
57+
background-repeat: no-repeat;
5758
}
5859

5960
.mouse-user-name {
@@ -76,4 +77,4 @@ html, body {
7677
display: block;
7778
z-index: 2;
7879
transition: all 150ms linear, opacity 100s ease-in;
79-
}
80+
}

src/common/types/cdn.types.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {
1+
import type {
22
CanvasPin,
33
HTMLPin,
44
Comments,
@@ -8,15 +8,18 @@ import {
88
WhoIsOnline,
99
FormElements,
1010
} from '../../components';
11-
import { RealtimeComponentEvent, RealtimeComponentState } from '../../components/realtime/types';
12-
import { LauncherFacade } from '../../core/launcher/types';
13-
import {
11+
import type {
12+
RealtimeComponentEvent,
13+
RealtimeComponentState,
14+
} from '../../components/realtime/types';
15+
import type { LauncherFacade } from '../../core/launcher/types';
16+
import type {
1417
CamerasPosition,
1518
LayoutMode,
1619
LayoutPosition,
1720
} from '../../services/video-conference-manager/types';
1821

19-
import {
22+
import type {
2023
DeviceEvent,
2124
MeetingEvent,
2225
RealtimeEvent,
@@ -31,6 +34,10 @@ import {
3134
} from './events.types';
3235
import { ParticipantType } from './participant.types';
3336
import { SuperVizSdkOptions } from './sdk-options.types';
37+
import { StoreType } from '../types/stores.types';
38+
import { PresenceEvents } from '@superviz/socket-client';
39+
import { FieldEvents } from '../../components/form-elements/types';
40+
import { PinMode } from '../../web-components/comments/components/types';
3441

3542
export interface SuperVizCdn {
3643
init: (apiKey: string, options: SuperVizSdkOptions) => Promise<LauncherFacade>;
@@ -59,4 +66,9 @@ export interface SuperVizCdn {
5966
FormElements: typeof FormElements;
6067
RealtimeComponentState: typeof RealtimeComponentState;
6168
RealtimeComponentEvent: typeof RealtimeComponentEvent;
69+
StoreType: typeof StoreType;
70+
PresenceEvents: typeof PresenceEvents;
71+
FieldEvents: typeof FieldEvents;
72+
PinMode: typeof PinMode;
73+
Comment: typeof Comment;
6274
}

src/common/types/sdk-options.types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ export interface SuperVizSdkOptions {
1111
roomId: string;
1212
participant: {
1313
id: string;
14-
name: string;
14+
name?: string;
1515
avatar?: Avatar;
16+
email?: string;
1617
};
1718
group: Group;
1819
customColors?: ColorsVariables;

src/components/base/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Socket from '../../lib/socket';
1+
import * as Socket from '@superviz/socket-client';
22

33
import { ComponentLifeCycleEvent } from '../../common/types/events.types';
44
import { Group } from '../../common/types/participant.types';

src/components/comments/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ApiService from '../../services/api';
1111
import { IOC } from '../../services/io';
1212
import { Presence3DManager } from '../../services/presence-3d-manager';
1313
import { useGlobalStore } from '../../services/stores';
14-
import { CommentsFloatButton } from '../../web-components';
14+
import type { CommentsFloatButton } from '../../web-components/comments/components/float-button';
1515
import { ComponentNames } from '../types';
1616

1717
import { PinAdapter, CommentsSide, Annotation, PinCoordinates } from './types';

src/components/comments/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Logger } from '../../common/utils';
55
import ApiService from '../../services/api';
66
import config from '../../services/config';
77
import subject from '../../services/stores/subject';
8-
import type { Comments as CommentElement } from '../../web-components';
8+
import type { Comments as CommentElement } from '../../web-components/comments';
99
import { CommentsFloatButton } from '../../web-components/comments/components/float-button';
1010
import { BaseComponent } from '../base';
1111
import { ComponentNames } from '../types';
@@ -152,6 +152,7 @@ export class Comments extends BaseComponent {
152152
* @returns {void}
153153
*/
154154
protected start(): void {
155+
if (typeof window === 'undefined') return;
155156
this.clientUrl = window.location.href;
156157

157158
this.positionComments();

src/components/form-elements/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SocketEvent } from '../../lib/socket';
1+
import type { SocketEvent } from '@superviz/socket-client';
22

33
import { Participant } from '../../common/types/participant.types';
44
import { StoreType } from '../../common/types/stores.types';

src/components/form-elements/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SocketEvent } from '../../lib/socket';
1+
import { SocketEvent } from '@superviz/socket-client';
22

33
export type FormElementsProps = {
44
fields?: string[] | string;

src/components/presence-mouse/canvas/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Socket from '../../../lib/socket';
1+
import * as Socket from '@superviz/socket-client';
22
import { throttle } from 'lodash';
33

44
import { RealtimeEvent } from '../../../common/types/events.types';

src/components/presence-mouse/html/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as Socket from '../../../lib/socket';
1+
import * as Socket from '@superviz/socket-client';
22
import { isEqual } from 'lodash';
33
import { Subscription, fromEvent, throttleTime } from 'rxjs';
44

@@ -205,6 +205,8 @@ export class PointersHTML extends BaseComponent {
205205
* @returns {void}
206206
*/
207207
private onMyParticipantMouseLeave = (event: MouseEvent): void => {
208+
if (typeof window === 'undefined') return;
209+
208210
const { left, top, right, bottom } = this.container.getBoundingClientRect();
209211
const isInsideContainer =
210212
event.x > left && event.y > top && event.x < right && event.y < bottom;

src/components/realtime/channel.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ describe('Realtime Channel', () => {
3434
ChannelInstance['state'] = RealtimeChannelState.DISCONNECTED;
3535

3636
const spy = jest.spyOn(ChannelInstance['logger'], 'log' as any);
37-
ChannelInstance.publish('test');
37+
ChannelInstance.publish('test', {});
3838

3939
expect(spy).toHaveBeenCalled();
4040
});
4141

4242
test('should publish an event', () => {
4343
const spy = jest.spyOn(ChannelInstance['channel'], 'emit' as any);
44-
ChannelInstance.publish('test');
44+
ChannelInstance.publish('test', {});
4545

4646
expect(spy).toHaveBeenCalled();
4747
});

src/components/realtime/channel.ts

+32-25
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
import * as Socket from '../../lib/socket';
1+
import * as Socket from '@superviz/socket-client';
22
import throttle from 'lodash/throttle';
33

4-
import { ComponentLifeCycleEvent } from '../../common/types/events.types';
54
import { Participant } from '../../common/types/participant.types';
65
import { Logger, Observable, Observer } from '../../common/utils';
76
import { IOC } from '../../services/io';
87

9-
import { RealtimeChannelEvent, RealtimeChannelState, RealtimeData, RealtimeMessage } from './types';
8+
import {
9+
RealtimeChannelEvent,
10+
RealtimeChannelState,
11+
RealtimeData,
12+
RealtimeMessage,
13+
RealtimePublish,
14+
RealtimeChannelSubscribe,
15+
Callback,
16+
} from './types';
17+
import { RealtimePresence } from './presence';
1018

1119
export class Channel extends Observable {
1220
private name: string;
@@ -19,6 +27,7 @@ export class Channel extends Observable {
1927
event: string;
2028
callback: (data: unknown) => void;
2129
}> = [];
30+
public participant: RealtimePresence;
2231

2332
constructor(
2433
name: string,
@@ -36,6 +45,7 @@ export class Channel extends Observable {
3645

3746
this.subscribeToRealtimeEvents();
3847
this.logger.log('started');
48+
this.participant = new RealtimePresence(this.channel);
3949
}
4050

4151
public async disconnect(): Promise<void> {
@@ -51,16 +61,11 @@ export class Channel extends Observable {
5161

5262
/**
5363
* @function publish
54-
* @description Publishes an event with optional data to the channel.
64+
* @description Publishes an event with data to the channel.
5565
* @param event - The name of the event to publish.
56-
* @param data - Optional data to be sent along with the event.
66+
* @param data - Data to be sent along with the event.
5767
*/
58-
public publish = throttle((event: string, data?: unknown): void => {
59-
if (Object.values(ComponentLifeCycleEvent).includes(event as ComponentLifeCycleEvent)) {
60-
this.publishEventToClient(event, data);
61-
return;
62-
}
63-
68+
public publish: RealtimePublish = throttle((event: string, data): void => {
6469
if (this.state !== RealtimeChannelState.CONNECTED) {
6570
const message = `Realtime channel ${this.name} is not started yet. You can't publish event ${event} before start`;
6671
this.logger.log(message);
@@ -78,7 +83,10 @@ export class Channel extends Observable {
7883
* @param event - The name of the event to subscribe to.
7984
* @param callback - The callback function to handle the received data. It takes a parameter of type `RealtimeMessage` or `string`.
8085
*/
81-
public subscribe = (event: string, callback: (data: RealtimeMessage | string) => void): void => {
86+
public subscribe: RealtimeChannelSubscribe = <T = unknown>(
87+
event: string,
88+
callback: Callback<T>,
89+
): void => {
8290
if (this.state !== RealtimeChannelState.CONNECTED) {
8391
this.callbacksToSubscribeWhenJoined.push({ event, callback });
8492
return;
@@ -97,13 +105,11 @@ export class Channel extends Observable {
97105
* @param event - The event to unsubscribe from.
98106
* @param callback - An optional callback function to be called when the event is unsubscribed.
99107
*/
100-
public unsubscribe = (
108+
public unsubscribe: RealtimeChannelSubscribe = <T = unknown>(
101109
event: string,
102-
callback?: (data: RealtimeMessage | string) => void,
110+
callback?: Callback<T>,
103111
): void => {
104-
if (!this.observers[event]) return;
105-
106-
this.observers[event].unsubscribe(callback);
112+
this.observers[event]?.unsubscribe(callback);
107113
};
108114

109115
/**
@@ -116,7 +122,10 @@ export class Channel extends Observable {
116122
this.logger.log('realtime component @ changeState - state changed', state);
117123
this.state = state;
118124

119-
this.publishEventToClient(RealtimeChannelEvent.REALTIME_CHANNEL_STATE_CHANGED, this.state);
125+
this.publishEventToClient<RealtimeChannelState>(
126+
RealtimeChannelEvent.REALTIME_CHANNEL_STATE_CHANGED,
127+
this.state,
128+
);
120129
}
121130

122131
private subscribeToRealtimeEvents(): void {
@@ -136,13 +145,13 @@ export class Channel extends Observable {
136145

137146
this.channel.on<RealtimeData>(`message:${this.name}`, (event) => {
138147
this.logger.log('message received', event);
139-
this.publishEventToClient(event.data.name, {
148+
this.publishEventToClient<RealtimeMessage>(event.data.name, {
140149
data: event.data.payload,
141-
participantId: event?.presence?.id || null,
150+
participantId: event?.presence?.id ?? null,
142151
name: event.data.name,
143152
timestamp: event.timestamp,
144153
connectionId: event.connectionId,
145-
} as RealtimeMessage);
154+
});
146155
});
147156
}
148157

@@ -214,11 +223,9 @@ export class Channel extends Observable {
214223
* @param data - data to publish
215224
* @returns {void}
216225
*/
217-
private publishEventToClient = (event: string, data?: unknown): void => {
226+
private publishEventToClient = <T = unknown>(event: string, data?: T): void => {
218227
this.logger.log('realtime channel @ publishEventToClient', { event, data });
219228

220-
if (!this.observers[event]) return;
221-
222-
this.observers[event].publish(data);
229+
this.observers[event]?.publish(data);
223230
};
224231
}

0 commit comments

Comments
 (0)