53 lines
1.6 KiB
TypeScript
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);
|
|
}
|
|
}
|
|
} |