frontend: refactor WebComponentManagerService to integrate MeetingService and improve message handling
This commit is contained in:
parent
459a37bee8
commit
256f38ee58
@ -1,12 +1,12 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { AppDataService, ParticipantTokenService, RoomService } from '@lib/services';
|
import { AppDataService, MeetingService, ParticipantTokenService, RoomService } from '@lib/services';
|
||||||
import {
|
import {
|
||||||
WebComponentCommand,
|
WebComponentCommand,
|
||||||
WebComponentEvent,
|
WebComponentEvent,
|
||||||
WebComponentInboundCommandMessage,
|
WebComponentInboundCommandMessage,
|
||||||
WebComponentOutboundEventMessage
|
WebComponentOutboundEventMessage
|
||||||
} from '@lib/typings/ce';
|
} from '@lib/typings/ce';
|
||||||
import { LoggerService, OpenViduService, PanelService } from 'openvidu-components-angular';
|
import { LoggerService, OpenViduService } from 'openvidu-components-angular';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service to manage the commands from OpenVidu Meet WebComponent/Iframe.
|
* Service to manage the commands from OpenVidu Meet WebComponent/Iframe.
|
||||||
@ -26,9 +26,9 @@ export class WebComponentManagerService {
|
|||||||
protected loggerService: LoggerService,
|
protected loggerService: LoggerService,
|
||||||
protected appDataService: AppDataService,
|
protected appDataService: AppDataService,
|
||||||
protected participantService: ParticipantTokenService,
|
protected participantService: ParticipantTokenService,
|
||||||
protected panelService: PanelService,
|
|
||||||
protected openviduService: OpenViduService,
|
protected openviduService: OpenViduService,
|
||||||
protected roomService: RoomService
|
protected roomService: RoomService,
|
||||||
|
protected meetingService: MeetingService
|
||||||
) {
|
) {
|
||||||
this.log = this.loggerService.get('OpenVidu Meet - WebComponentManagerService');
|
this.log = this.loggerService.get('OpenVidu Meet - WebComponentManagerService');
|
||||||
this.boundHandleMessage = this.handleMessage.bind(this);
|
this.boundHandleMessage = this.handleMessage.bind(this);
|
||||||
@ -41,7 +41,7 @@ export class WebComponentManagerService {
|
|||||||
// Listen for messages from the iframe
|
// Listen for messages from the iframe
|
||||||
window.addEventListener('message', this.boundHandleMessage);
|
window.addEventListener('message', this.boundHandleMessage);
|
||||||
// Send ready message to parent
|
// Send ready message to parent
|
||||||
window.parent.postMessage(
|
this.sendMessageToParent(
|
||||||
{
|
{
|
||||||
event: WebComponentEvent.READY,
|
event: WebComponentEvent.READY,
|
||||||
payload: {}
|
payload: {}
|
||||||
@ -58,10 +58,10 @@ export class WebComponentManagerService {
|
|||||||
this.log.d('Stopped commands listener');
|
this.log.d('Stopped commands listener');
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessageToParent(event: WebComponentOutboundEventMessage) {
|
sendMessageToParent(event: WebComponentOutboundEventMessage, targetOrigin: string = this.parentDomain) {
|
||||||
if (!this.appDataService.isEmbeddedMode()) return;
|
if (!this.appDataService.isEmbeddedMode()) return;
|
||||||
this.log.d('Sending message to parent :', event);
|
this.log.d('Sending message to parent:', event);
|
||||||
window.parent.postMessage(event, this.parentDomain);
|
window.parent.postMessage(event, targetOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async handleMessage(event: MessageEvent): Promise<void> {
|
protected async handleMessage(event: MessageEvent): Promise<void> {
|
||||||
@ -81,26 +81,35 @@ export class WebComponentManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.origin !== this.parentDomain) {
|
if (event.origin !== this.parentDomain) {
|
||||||
// console.warn(`Untrusted origin: ${event.origin}`);
|
console.warn(`Untrusted origin: ${event.origin}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the room is connected before processing command
|
||||||
|
if (!this.openviduService.isRoomConnected()) {
|
||||||
|
this.log.w('Received command but room is not connected');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug('Message received from parent:', event.data);
|
console.debug('Message received from parent:', event.data);
|
||||||
// TODO: reject if room is not connected
|
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case WebComponentCommand.END_MEETING:
|
case WebComponentCommand.END_MEETING:
|
||||||
// Moderator only
|
// Only moderators can end the meeting
|
||||||
if (this.participantService.isModeratorParticipant()) {
|
if (!this.participantService.isModeratorParticipant()) {
|
||||||
const roomId = this.roomService.getRoomId();
|
this.log.w('End meeting command received but participant is not a moderator');
|
||||||
await this.roomService.endMeeting(roomId);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.log.d('Ending meeting...');
|
||||||
|
const roomId = this.roomService.getRoomId();
|
||||||
|
await this.meetingService.endMeeting(roomId);
|
||||||
|
} catch (error) {
|
||||||
|
this.log.e('Error ending meeting:', error);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
// case WebComponentCommand.TOGGLE_CHAT:
|
|
||||||
// Toggle chat
|
|
||||||
// this.panelService.togglePanel(PanelType.CHAT);
|
|
||||||
// break;
|
|
||||||
case WebComponentCommand.LEAVE_ROOM:
|
case WebComponentCommand.LEAVE_ROOM:
|
||||||
// Leave room.
|
|
||||||
await this.openviduService.disconnectRoom();
|
await this.openviduService.disconnectRoom();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user