webcomponent: update event handling methods to use WebComponentEvent type for better type safety

This commit is contained in:
Carlos Santos 2025-05-20 11:37:36 +02:00
parent 7a81873285
commit af3697f94c
2 changed files with 6 additions and 6 deletions

View File

@ -48,7 +48,7 @@ export class CommandsManager {
* @param callback Function to be called when the event is triggered
* @returns The component instance for chaining
*/
public on(element: HTMLElement, eventName: string, callback: (detail: any) => void): this {
public on(element: HTMLElement, eventName: WebComponentEvent, callback: (detail: any) => void): this {
if (!(Object.values(WebComponentEvent) as string[]).includes(eventName)) {
console.warn(`Event "${eventName}" is not supported.`);
return this;
@ -83,7 +83,7 @@ export class CommandsManager {
* @param callback Function to be called when the event is triggered
* @returns The component instance for chaining
*/
public once(element: HTMLElement, eventName: string, callback: (detail: any) => void): this {
public once(element: HTMLElement, eventName: WebComponentEvent, callback: (detail: any) => void): this {
if (!(Object.values(WebComponentEvent) as string[]).includes(eventName)) {
console.warn(`Event "${eventName}" is not supported.`);
return this;
@ -108,7 +108,7 @@ export class CommandsManager {
* @param callback Optional callback to remove (if not provided, removes all handlers for this event)
* @returns The component instance for chaining
*/
public off(element: HTMLElement, eventName: string, callback?: (detail: any) => void): this {
public off(element: HTMLElement, eventName: WebComponentEvent, callback?: (detail: any) => void): this {
if (!callback) {
// Remove all handlers for this event
const handlers = this.eventHandlers.get(eventName);

View File

@ -174,7 +174,7 @@ export class OpenViduMeet extends HTMLElement {
* @param callback Function to be called when the event is triggered
* @returns The component instance for chaining
*/
public on(eventName: string, callback: (detail: any) => void): this {
public on(eventName: WebComponentEvent, callback: (detail: any) => void): this {
this.commandsManager.on(this, eventName, callback);
return this;
}
@ -185,7 +185,7 @@ export class OpenViduMeet extends HTMLElement {
* @param callback Function to be called when the event is triggered
* @returns The component instance for chaining
*/
public once(eventName: string, callback: (detail: any) => void): this {
public once(eventName: WebComponentEvent, callback: (detail: any) => void): this {
this.commandsManager.once(this, eventName, callback);
return this;
}
@ -196,7 +196,7 @@ export class OpenViduMeet extends HTMLElement {
* @param callback Optional callback to remove (if not provided, removes all handlers for this event)
* @returns The component instance for chaining
*/
public off(eventName: string, callback?: (detail: any) => void): this {
public off(eventName: WebComponentEvent, callback?: (detail: any) => void): this {
this.commandsManager.off(this, eventName, callback);
return this;
}