webcomponent: add kick participant command

This commit is contained in:
juancarmore 2025-07-07 20:28:23 +02:00
parent 3904ab05b7
commit 424db94781
5 changed files with 49 additions and 3 deletions

View File

@ -38,6 +38,6 @@ export class MeetingService {
async kickParticipant(roomId: string, participantId: string): Promise<void> {
const path = `${this.MEETINGS_API}/${roomId}/participants/${participantId}`;
await this.httpService.deleteRequest(path);
this.log.d(`Participant ${participantId} kicked from room ${roomId}`);
this.log.d(`Participant '${participantId}' kicked from room ${roomId}`);
}
}

View File

@ -111,6 +111,29 @@ export class WebComponentManagerService {
break;
case WebComponentCommand.LEAVE_ROOM:
await this.openviduService.disconnectRoom();
break;
case WebComponentCommand.KICK_PARTICIPANT:
// Only moderators can kick participants
if (!this.participantService.isModeratorParticipant()) {
this.log.w('Kick participant command received but participant is not a moderator');
return;
}
if (!payload || !('participantIdentity' in payload)) {
this.log.e('Kick participant command received without participant identity');
return;
}
const participantIdentity = payload['participantIdentity'];
try {
this.log.d(`Kicking participant '${participantIdentity}' from the meeting...`);
const roomId = this.roomService.getRoomId();
await this.meetingService.kickParticipant(roomId, participantIdentity);
} catch (error) {
this.log.e(`Error kicking participant '${participantIdentity}':`, error);
}
break;
default:
break;

View File

@ -164,6 +164,14 @@ export class CommandsManager {
this.sendMessage(message);
}
public kickParticipant(participantIdentity: string) {
const message: WebComponentInboundCommandMessage = {
command: WebComponentCommand.KICK_PARTICIPANT,
payload: { participantIdentity }
};
this.sendMessage(message);
}
/**
* Sends a message to the iframe using window.postMessage
*

View File

@ -217,4 +217,12 @@ export class OpenViduMeet extends HTMLElement {
public leaveRoom() {
this.commandsManager.leaveRoom();
}
/**
* Kicks a participant from the meeting.
* @param participantIdentity The identity of the participant to kick
*/
public kickParticipant(participantIdentity: string) {
this.commandsManager.kickParticipant(participantIdentity);
}
}

View File

@ -16,7 +16,12 @@ export enum WebComponentCommand {
/**
* Disconnects the local participant from the current room.
*/
LEAVE_ROOM = 'LEAVE_ROOM'
LEAVE_ROOM = 'LEAVE_ROOM',
/**
* Kicks a participant from the meeting.
* This command is only available for the moderator.
*/
KICK_PARTICIPANT = 'KICK_PARTICIPANT'
}
/**
@ -34,7 +39,9 @@ export interface WebComponentCommandPayloads {
};
[WebComponentCommand.END_MEETING]: void;
[WebComponentCommand.LEAVE_ROOM]: void;
// [WebComponentCommand.TOGGLE_CHAT]: void;
[WebComponentCommand.KICK_PARTICIPANT]: {
participantIdentity: string;
};
}
/**