Files
WebRTC-Broadcast/public/js/services/UIController.ts
2025-09-05 00:36:54 -04:00

53 lines
1.6 KiB
TypeScript

import type { IUIController } from '../interfaces/IWebRTCClient.ts';
export class UIController implements IUIController {
private statusElement: HTMLElement;
private subscribersCountElement: HTMLElement | null;
private startButton: HTMLButtonElement | null;
private stopButton: HTMLButtonElement | null;
constructor(
statusElementId: string,
subscribersCountElementId?: string,
startButtonId?: string,
stopButtonId?: string
) {
this.statusElement = document.getElementById(statusElementId)!;
this.subscribersCountElement = subscribersCountElementId
? document.getElementById(subscribersCountElementId)
: null;
this.startButton = startButtonId
? document.getElementById(startButtonId) as HTMLButtonElement
: null;
this.stopButton = stopButtonId
? document.getElementById(stopButtonId) as HTMLButtonElement
: null;
}
updateStatus(status: string, className: string): void {
this.statusElement.textContent = status;
this.statusElement.className = `status ${className}`;
}
updateSubscribersCount(count: number): void {
if (this.subscribersCountElement) {
this.subscribersCountElement.textContent = `Subscribers: ${count}`;
}
}
setButtonStates(startEnabled: boolean, stopEnabled: boolean): void {
if (this.startButton) {
this.startButton.disabled = !startEnabled;
}
if (this.stopButton) {
this.stopButton.disabled = !stopEnabled;
}
}
onButtonClick(buttonId: string, handler: () => void): void {
const button = document.getElementById(buttonId);
if (button) {
button.addEventListener('click', handler);
}
}
}