Skip to content

Commit

Permalink
Merge pull request #153 from SuperViz/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
carlossantos74 authored Dec 3, 2024
2 parents 11ab7c7 + 0ff7855 commit bc57bb6
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 158 deletions.
4 changes: 2 additions & 2 deletions apps/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"watch": "vite",
"watch": "vite --host",
"build": "tsc -b && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
Expand Down Expand Up @@ -45,7 +45,7 @@
"@types/react-dom": "^18.3.0",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"@typescript-eslint/parser": "^8.17.0",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.20",
"eslint": "^8.57.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"@types/jest": "^29.5.13",
"prettier": "^3.2.5",
"turbo": "^2.1.1",
"turbo": "^2.3.3",
"typescript": "^5.6.2"
},
"packageManager": "pnpm@9.10.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/autodesk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/autodesk-viewer-plugin",
"version": "1.22.3",
"version": "1.22.4-beta.1",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"@typescript-eslint/parser": "^8.17.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/matterport/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/matterport-plugin",
"version": "1.2.3",
"version": "1.2.4-beta.1",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down
6 changes: 3 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@superviz/react-sdk",
"private": false,
"version": "1.14.3",
"version": "1.14.4-beta.1",
"type": "module",
"scripts": {
"watch": "./node_modules/typescript/bin/tsc && vite build --watch",
Expand Down Expand Up @@ -50,7 +50,7 @@
"devDependencies": {
"@anolilab/semantic-release-pnpm": "^1.1.3",
"@eslint/compat": "^1.1.1",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-replace": "^6.0.1",
"@semantic-release/release-notes-generator": "^14.0.1",
"@types/forge-viewer": "^7.89.1",
"@types/lodash": "^4.17.6",
Expand All @@ -59,7 +59,7 @@
"@types/react-dom": "^18.3.0",
"@types/three": "^0.166.0",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"@typescript-eslint/parser": "^8.17.0",
"@vitejs/plugin-react": "^4.3.1",
"@vitejs/plugin-react-swc": "^3.7.0",
"eslint": "^9.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/realtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/realtime",
"version": "1.2.3",
"version": "1.2.4-beta.1",
"description": "SuperViz Real-Time",
"main": "./dist/node/index.cjs.js",
"module": "./dist/browser/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/sdk",
"version": "6.7.3",
"version": "6.7.4-beta.1",
"description": "SuperViz SDK",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -70,7 +70,7 @@
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"playwright": "^1.48.1",
"playwright": "^1.49.0",
"rimraf": "^5.0.7",
"semantic-release": "^24.0.0",
"ts-jest": "^29.1.5",
Expand Down
57 changes: 45 additions & 12 deletions packages/sdk/src/components/video/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PresenceEvent } from '@superviz/socket-client';

import { MOCK_CONFIG } from '../../../__mocks__/config.mock';
import { EVENT_BUS_MOCK } from '../../../__mocks__/event-bus.mock';
import { LIMITS_MOCK } from '../../../__mocks__/limits.mock';
import { MOCK_OBSERVER_HELPER } from '../../../__mocks__/observer-helper.mock';
import { MOCK_AVATAR, MOCK_LOCAL_PARTICIPANT } from '../../../__mocks__/participants.mock';
import {
Expand All @@ -16,6 +17,7 @@ import {
RealtimeEvent,
TranscriptState,
} from '../../common/types/events.types';
import { MEETING_COLORS } from '../../common/types/meeting-colors.types';
import {
Participant,
ParticipantType,
Expand All @@ -26,11 +28,10 @@ import { useStore } from '../../common/utils/use-store';
import { IOC } from '../../services/io';
import { Presence3DManager } from '../../services/presence-3d-manager';
import { VideoFrameState } from '../../services/video-conference-manager/types';

import { ParticipantToFrame } from './types';

import { VideoConference } from '.';
import { MEETING_COLORS } from '../../common/types/meeting-colors.types';
import { LIMITS_MOCK } from '../../../__mocks__/limits.mock';

Object.assign(global, { TextDecoder, TextEncoder });

Expand Down Expand Up @@ -141,7 +142,7 @@ describe('VideoConference', () => {
});

describe('host handler', () => {
test('should set as host the first participant that joins the room and type is host', () => {
test('should set as host the first participant that joins the room and type is host', async () => {
const participant: Participant[] = [
{
timestamp: 0,
Expand All @@ -162,6 +163,24 @@ describe('VideoConference', () => {

const fn = jest.fn();

// Mock room.presence.get to return our test participant
VideoConferenceInstance['room'] = {
...VideoConferenceInstance['room'],
presence: {
get: jest.fn().mockImplementation((success) => {
success([{
id: MOCK_LOCAL_PARTICIPANT.id,
data: {
...participant[0],
type: ParticipantType.HOST,
joinedMeeting: true,
},
}]);
}),
update: jest.fn(),
},
} as any;

VideoConferenceInstance['useStore'] = jest.fn().mockReturnValue({
participants: {
value: {
Expand All @@ -175,17 +194,13 @@ describe('VideoConference', () => {
value: '',
publish: fn,
},
destroy: jest.fn(),
});

VideoConferenceInstance['roomState']['setHost'] = fn;
VideoConferenceInstance['onParticipantListUpdate']({
[MOCK_LOCAL_PARTICIPANT.id]: {
...participant[0],
},
});
VideoConferenceInstance['roomState'].setHost = fn;
await VideoConferenceInstance['validateIfInTheRoomHasHost']();

expect(fn).toHaveBeenCalledWith(MOCK_LOCAL_PARTICIPANT.id);
expect(fn).toHaveBeenCalledWith(MOCK_LOCAL_PARTICIPANT.id);
});

test('should keep the host if it is already set and stays in the room', () => {
Expand Down Expand Up @@ -274,22 +289,40 @@ describe('VideoConference', () => {
expect(VideoConferenceInstance['roomState'].setHost).not.toBeCalled();
});

test('should init the timer to kick participants if the host leaves', () => {
test('should init the timer to kick participants if the host leaves', async () => {
VideoConferenceInstance['participantsTypes'] = {};
VideoConferenceInstance['localParticipant'] = {
...MOCK_LOCAL_PARTICIPANT,
type: ParticipantType.GUEST,
};
VideoConferenceInstance['kickParticipantsOnHostLeave'] = true;

// Mock room.presence.get to return empty list (no hosts)
VideoConferenceInstance['room'] = {
...VideoConferenceInstance['room'],
presence: {
get: jest.fn().mockImplementation((success) => {
success([]);
}),
update: jest.fn(),
off: jest.fn(),
},
} as any;

VideoConferenceInstance['useStore'] = jest.fn().mockReturnValue({
participants: {
value: {
[MOCK_LOCAL_PARTICIPANT.id]: VideoConferenceInstance['localParticipant'],
},
},
hostId: {
value: '',
publish: jest.fn(),
},
destroy: jest.fn(),
});
VideoConferenceInstance['validateIfInTheRoomHasHost']();

await VideoConferenceInstance['validateIfInTheRoomHasHost']();

jest.advanceTimersByTime(3000 * 60);

Expand Down
61 changes: 42 additions & 19 deletions packages/sdk/src/components/video/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PresenceEvent, PresenceEvents, Room } from '@superviz/socket-client';
import type * as Socket from '@superviz/socket-client';

import { ColorsVariables } from '../../common/types/colors.types';
import {
Expand All @@ -12,6 +13,7 @@ import {
RealtimeEvent,
TranscriptState,
} from '../../common/types/events.types';
import { MEETING_COLORS } from '../../common/types/meeting-colors.types';
import {
VideoParticipant,
ParticipantType,
Expand All @@ -22,6 +24,7 @@ import { Logger } from '../../common/utils';
import { BrowserService } from '../../services/browser';
import config from '../../services/config';
import { ConnectionService } from '../../services/connection-status';
import { coreBridge } from '../../services/core-bridge';
import { RoomStateService } from '../../services/room-state';
import VideoConferenceManager from '../../services/video-conference-manager';
import {
Expand All @@ -37,8 +40,6 @@ import { BaseComponent } from '../base';
import { ComponentNames } from '../types';

import { ParticipantToFrame, VideoComponentOptions } from './types';
import { MEETING_COLORS } from '../../common/types/meeting-colors.types';
import { coreBridge } from '../../services/core-bridge';

const KICK_PARTICIPANTS_TIME = 1000 * 60;
let KICK_PARTICIPANTS_TIMEOUT: ReturnType<typeof setTimeout> | null = null;
Expand Down Expand Up @@ -497,8 +498,7 @@ export class VideoConference extends BaseComponent {
const _ = {
[RealtimeEvent.REALTIME_HOST_CHANGE]: (data: string) => this.roomState.setHost(data),
[RealtimeEvent.REALTIME_GATHER]: (data: boolean) => this.roomState.setGather(data),
[RealtimeEvent.REALTIME_GRID_MODE_CHANGE]: (data: boolean) =>
this.roomState.setGridMode(data),
[RealtimeEvent.REALTIME_GRID_MODE_CHANGE]: (data: boolean) => this.roomState.setGridMode(data),
[RealtimeEvent.REALTIME_DRAWING_CHANGE]: (data: DrawingData) => {
this.roomState.setDrawing(data);
},
Expand Down Expand Up @@ -798,13 +798,13 @@ export class VideoConference extends BaseComponent {

const newHost = participant
? {
id: participant.id,
color: participant.slot?.color || MEETING_COLORS.gray,
avatar: participant.avatar,
type: participant.type,
name: participant.name,
isHost: participant.id === hostId,
}
id: participant.id,
color: participant.slot?.color || MEETING_COLORS.gray,
avatar: participant.avatar,
type: participant.type,
name: participant.name,
isHost: participant.id === hostId,
}
: null;

if (KICK_PARTICIPANTS_TIMEOUT && !!newHost) {
Expand Down Expand Up @@ -894,21 +894,44 @@ export class VideoConference extends BaseComponent {
* @description checks if the room has a host
* @returns {void}
*/
private validateIfInTheRoomHasHost = (): void => {
private validateIfInTheRoomHasHost = async (): Promise<void> => {
if (!this.roomState) return;

const { hostId } = this.useStore(StoreType.VIDEO);
const { participants } = this.useStore(StoreType.GLOBAL);
const participantsList = Object.values(participants.value);

// list with all participants that have the type host and are in the meeting
const participantsCanBeHost = participantsList.filter((participant) => {
return (
participant.type === ParticipantType.HOST &&
this.participantsOnMeeting.some((p) => p.id === participant.id)
const participantsList = await new Promise<Socket.PresenceEvent[]>((resolve, reject) => {
this.room.presence.get(
(data) => resolve(data),
(error) => {
const message = `[SuperViz] ${error.name} - ${error.message}`;
this.logger.log(error);
console.error(message);
reject(error);
},
);
});

// list with all participants that have the type host and are in the meeting
const participantsCanBeHost = participantsList.filter(
(participant: Socket.PresenceEvent<VideoParticipant>) => {
return (
participant.data.type === ParticipantType.HOST && participant.data.joinedMeeting
);
},
);

this.logger.log(
'video conference @ validate if in the room has host - conditions to init kick all participants timeout',
{
participantsCanBeHost,
participantListInTheStore: participantsList,
participantsOnMeeting: this.participantsOnMeeting,
kickParticipantsOnHostLeave: this.kickParticipantsOnHostLeave,
localParticipantCanBeHost: this.localParticipant?.type === ParticipantType.HOST,
kickParticipantsTimeout: KICK_PARTICIPANTS_TIMEOUT,
},
);

if (
!participantsCanBeHost.length &&
this.kickParticipantsOnHostLeave &&
Expand Down
2 changes: 1 addition & 1 deletion packages/socket-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/socket-client",
"version": "1.13.3",
"version": "1.13.4-beta.1",
"description": "SuperViz Socket Client",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/three/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/threejs-plugin",
"version": "1.2.3",
"version": "1.2.4-beta.1",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/yjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superviz/yjs",
"version": "1.0.3",
"version": "1.0.4-beta.1",
"description": "",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
Loading

0 comments on commit bc57bb6

Please sign in to comment.