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

Commit

Permalink
Merge pull request #657 from SuperViz/fix/update-host-and-name-video
Browse files Browse the repository at this point in the history
fix: update host and name video
  • Loading branch information
carlossantos74 authored May 10, 2024
2 parents 15b7bd0 + d673f23 commit f390898
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/components/video/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const VIDEO_MANAGER_MOCK = {
participantJoinedObserver: MOCK_OBSERVER_HELPER,
participantLeftObserver: MOCK_OBSERVER_HELPER,
participantListObserver: MOCK_OBSERVER_HELPER,
isMessageBridgeReady: jest.fn().mockReturnValue(true),
};

const MOCK_DRAW_DATA = {
Expand Down Expand Up @@ -188,12 +189,28 @@ describe('VideoConference', () => {
},
];

VideoConferenceInstance['roomState'].setHost = jest.fn();
const fn = jest.fn();

VideoConferenceInstance['useStore'] = jest.fn().mockReturnValue({
participants: {
value: {
[MOCK_LOCAL_PARTICIPANT.id]: {
...participant[0],
type: ParticipantType.HOST,
},
},
},
hostId: {
value: '',
publish: fn,
},
});

VideoConferenceInstance['roomState']['setHost'] = fn;
VideoConferenceInstance['onRealtimeParticipantsDidChange'](participant);

expect(VideoConferenceInstance['roomState'].setHost).toBeCalledWith(
MOCK_LOCAL_PARTICIPANT.id,
);
expect(fn).toBeCalledWith(MOCK_LOCAL_PARTICIPANT.id);
expect(fn).toBeCalledWith(MOCK_LOCAL_PARTICIPANT.id);
});

test('should keep the host if it is already set and stays in the room', () => {
Expand All @@ -215,13 +232,15 @@ describe('VideoConference', () => {
},
];

VideoConferenceInstance['useStore'](StoreType.GLOBAL).participants.publish({
[MOCK_LOCAL_PARTICIPANT.id]: {
...originalList[0],
},
});

VideoConferenceInstance['roomState'].setHost = jest.fn();
VideoConferenceInstance['onRealtimeParticipantsDidChange'](originalList);

expect(VideoConferenceInstance['roomState'].setHost).toBeCalledWith(
MOCK_LOCAL_PARTICIPANT.id,
);

VideoConferenceInstance['participantsTypes']['second-id'] = ParticipantType.HOST;
const secondList: ParticipantInfo[] = [
{
Expand Down Expand Up @@ -252,7 +271,7 @@ describe('VideoConference', () => {

VideoConferenceInstance['onRealtimeParticipantsDidChange'](secondList);

expect(VideoConferenceInstance['roomState'].setHost).toBeCalledTimes(1);
expect(VideoConferenceInstance['roomState'].setHost).toBeCalledTimes(0);
});

test('should not set host if the participant is not me', () => {
Expand Down Expand Up @@ -673,12 +692,13 @@ describe('VideoConference', () => {

describe('realtime events', () => {
test('should update host', () => {
VIDEO_MANAGER_MOCK.publishMessageToFrame = jest.fn();
const { hostId } = VideoConferenceInstance['useStore'](StoreType.VIDEO);
hostId.publish(MOCK_LOCAL_PARTICIPANT.id);
hostId.publish('new-host');

expect(VIDEO_MANAGER_MOCK.publishMessageToFrame).toBeCalledWith(
RealtimeEvent.REALTIME_HOST_CHANGE,
MOCK_LOCAL_PARTICIPANT.id,
'new-host',
);
});

Expand Down
11 changes: 11 additions & 0 deletions src/components/video/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,15 @@ export class VideoConference extends BaseComponent {
private setHost = (hostId: string): void => {
if (!this.videoManager) return;

if (!this.videoManager.isMessageBridgeReady) {
this.logger.log('video conference @ Message Bridge not ready yet');
setTimeout(() => {
this.logger.log('video conference @ Retrying to set host id');
this.setHost(hostId);
}, 3000);
return;
}

this.videoManager.publishMessageToFrame(RealtimeEvent.REALTIME_HOST_CHANGE, hostId);
this.onHostParticipantDidChange(hostId);
};
Expand Down Expand Up @@ -882,6 +891,7 @@ export class VideoConference extends BaseComponent {
isHost: true,
};
this.hasSetHost = true;
hostId.publish(host.id);
participants.publish(participantsList);
return;
}
Expand All @@ -890,6 +900,7 @@ export class VideoConference extends BaseComponent {

this.logger.log('video conference @ validate if in the room has host - set host', host);

hostId.publish(host.id);
this.roomState.setHost(host.id);
};
}
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import {
LayoutPosition,
} from './services/video-conference-manager/types';

export { StoreType } from './common/types/stores.types';

export { Presence3DManager } from './services/presence-3d-manager';

export { FieldEvents } from './components/form-elements/types';
export { PinMode } from './web-components/comments/components/types';

Expand Down
13 changes: 13 additions & 0 deletions src/services/message-bridge/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { MeetingEvent } from '../../common/types/events.types';
import { StoreType } from '../../common/types/stores.types';
import { Observer } from '../../common/utils';
import { Logger } from '../../common/utils/logger';
import { useStore } from '../../common/utils/use-store';

import { Message, MessageBridgeOptions } from './types';

Expand Down Expand Up @@ -93,6 +96,16 @@ export class MessageBridge {
return;
}

if (type === MeetingEvent.MEETING_PARTICIPANT_JOINED) {
const { participants } = useStore(StoreType.GLOBAL);
const participantsList = { ...participants.value };
participantsList[data.id] = {
...participantsList[data.id],
...data,
};
participants.publish(participantsList);
}

this.observers[type].publish(data);
};
}
4 changes: 4 additions & 0 deletions src/services/video-conference-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export default class VideoConfereceManager {
window.addEventListener('orientationchange', this.onWindowResize);
}

public get isMessageBridgeReady(): boolean {
return !!this.messageBridge;
}

get isWaterMarkEnabled(): boolean {
if (this.browserService.isMobileDevice) return false;
return this.frameConfig.waterMark;
Expand Down

0 comments on commit f390898

Please sign in to comment.