websocket stuff
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user