websocket stuff

This commit is contained in:
Darius
2026-02-06 11:15:11 +01:00
parent 5866216e36
commit b9a494a87c
4 changed files with 2142 additions and 2170 deletions

View File

@@ -2,9 +2,8 @@ import {
BaseService,
FullInformation,
HomeAssistantDeskPositionResult,
SseClientChangeEvent,
SseService,
TidalGetCurrent,
WsService,
type ServiceResult,
} from "@dpu/shared";
import { logInfo, logWarning } from "@dpu/shared/dist/logger.js";
@@ -14,19 +13,19 @@ import { TidalService } from "../tidal/service";
export class HomepageService extends BaseService<null> {
private haService: HomeAssistantService;
private tidalService: TidalService;
private sseService: SseService;
private wsService: WsService;
private pollingInterval: ReturnType<typeof setInterval> | null = null;
private lastPoll: FullInformation | null = null;
constructor(
haService: HomeAssistantService,
tidalService: TidalService,
sseService: SseService,
wsService: WsService,
) {
super(null);
this.haService = haService;
this.tidalService = tidalService;
this.sseService = sseService;
this.wsService = wsService;
this.listenForClientChange();
}
@@ -87,7 +86,7 @@ export class HomepageService extends BaseService<null> {
if (updates.length > 0) {
logInfo("Updating clients");
this.sseService.notifyClients({
this.wsService.broadcast({
type: "update",
data: updates,
});
@@ -98,8 +97,8 @@ export class HomepageService extends BaseService<null> {
}
listenForClientChange(): void {
this.sseService.onClientChange((clientChange: SseClientChangeEvent) => {
if (clientChange.clientCount === 0) {
this.wsService.onClientChange((clients: number) => {
if (clients === 0) {
this.stopPolling();
} else {
if (!this.pollingInterval) {