Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60bcd23f5b | ||
|
|
c674d0fa72 | ||
|
|
c072f52a1a | ||
|
|
ceadd4e5a2 | ||
|
|
b32006cf10 | ||
|
|
0ab6194b43 | ||
|
|
46f359bb1e | ||
|
|
9b852dc40c | ||
|
|
a6d837f953 | ||
|
|
921882054d | ||
|
|
cdd2fcb59e | ||
|
|
8daeed6b5f | ||
|
|
6d05233a6e |
1
dist/homeassistant.d.ts
vendored
1
dist/homeassistant.d.ts
vendored
@@ -28,5 +28,6 @@ export type API_HA_DeskPosition = {
|
|||||||
position: string;
|
position: string;
|
||||||
is_standing: boolean;
|
is_standing: boolean;
|
||||||
last_changed: string;
|
last_changed: string;
|
||||||
|
last_changed_seconds: number;
|
||||||
};
|
};
|
||||||
//# sourceMappingURL=homeassistant.d.ts.map
|
//# sourceMappingURL=homeassistant.d.ts.map
|
||||||
2
dist/homeassistant.d.ts.map
vendored
2
dist/homeassistant.d.ts.map
vendored
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"homeassistant.d.ts","sourceRoot":"","sources":["../src/homeassistant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE;QACV,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,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AAC;CAC1B;AAED,MAAM,MAAM,mBAAmB,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;CAC7B,CAAC"}
|
||||||
4
dist/homepage.d.ts
vendored
4
dist/homepage.d.ts
vendored
@@ -1,5 +1,5 @@
|
|||||||
import { API_HA_DeskPosition } from "./homeassistant";
|
import { type API_HA_DeskPosition } from "./homeassistant";
|
||||||
import { TidalGetCurrent } from "./tidal";
|
import { type TidalGetCurrent } from "./tidal";
|
||||||
export type FullInformation = {
|
export type FullInformation = {
|
||||||
ha_desk_position: API_HA_DeskPosition | null;
|
ha_desk_position: API_HA_DeskPosition | null;
|
||||||
ha_temp: string | null;
|
ha_temp: string | null;
|
||||||
|
|||||||
2
dist/homepage.d.ts.map
vendored
2
dist/homepage.d.ts.map
vendored
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"homepage.d.ts","sourceRoot":"","sources":["../src/homepage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,MAAM,eAAe,GAAG;IAC7B,gBAAgB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC7C,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,aAAa,EAAE,eAAe,GAAG,IAAI,CAAC;CACtC,CAAA"}
|
{"version":3,"file":"homepage.d.ts","sourceRoot":"","sources":["../src/homepage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC7B,gBAAgB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC7C,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,aAAa,EAAE,eAAe,GAAG,IAAI,CAAC;CACtC,CAAC"}
|
||||||
14
dist/sse.d.ts
vendored
14
dist/sse.d.ts
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
import { UUID } from "crypto";
|
||||||
export type SseClient = {
|
export type SseClient = {
|
||||||
id: number;
|
id: UUID;
|
||||||
send: (data: SseEvent) => void;
|
send: (data: SseEvent) => void;
|
||||||
};
|
};
|
||||||
export type SseEvent = {
|
export type SseEvent = {
|
||||||
@@ -7,10 +8,19 @@ export type SseEvent = {
|
|||||||
data?: unknown;
|
data?: unknown;
|
||||||
message?: string;
|
message?: string;
|
||||||
};
|
};
|
||||||
|
export type SseClientChangeEvent = {
|
||||||
|
type: "add" | "remove";
|
||||||
|
clientId: string;
|
||||||
|
clientCount: number;
|
||||||
|
};
|
||||||
|
export type SseClientChangeCallback = (event: SseClientChangeEvent) => void;
|
||||||
export declare class SseService {
|
export declare class SseService {
|
||||||
private clients;
|
private clients;
|
||||||
|
private clientChangeCallbacks;
|
||||||
|
onClientChange(callback: SseClientChangeCallback): () => void;
|
||||||
|
private emitClientChange;
|
||||||
addClient(client: SseClient): void;
|
addClient(client: SseClient): void;
|
||||||
removeClient(clientId: number): void;
|
removeClient(clientId: string): void;
|
||||||
notifyClients(event: SseEvent): void;
|
notifyClients(event: SseEvent): void;
|
||||||
getClientCount(): number;
|
getClientCount(): number;
|
||||||
}
|
}
|
||||||
|
|||||||
2
dist/sse.d.ts.map
vendored
2
dist/sse.d.ts.map
vendored
@@ -1 +1 @@
|
|||||||
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,SAAS,GAAG;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;CAC/B,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,MAAM,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KAAK,EAAE,QAAQ,GAAG,IAAI;IAMpC,cAAc,IAAI,MAAM;CAGxB"}
|
||||||
37
dist/sse.js
vendored
37
dist/sse.js
vendored
@@ -1,21 +1,40 @@
|
|||||||
import { logInfo } from "./logger";
|
import { logInfo } from "./logger.js";
|
||||||
export class SseService {
|
export class SseService {
|
||||||
clients = new Set();
|
clients = new Map();
|
||||||
|
clientChangeCallbacks = [];
|
||||||
|
onClientChange(callback) {
|
||||||
|
this.clientChangeCallbacks.push(callback);
|
||||||
|
return () => {
|
||||||
|
this.clientChangeCallbacks = this.clientChangeCallbacks.filter((cb) => cb !== callback);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
emitClientChange(event) {
|
||||||
|
for (const callback of this.clientChangeCallbacks) {
|
||||||
|
callback(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
addClient(client) {
|
addClient(client) {
|
||||||
this.clients.add(client);
|
this.clients.set(client.id, client);
|
||||||
logInfo(`SSE client connected: ${client.id}. Total clients: ${this.clients.size}`);
|
logInfo(`SSE client connected: ${client.id}. Total clients: ${this.clients.size}`);
|
||||||
|
this.emitClientChange({
|
||||||
|
type: "add",
|
||||||
|
clientId: client.id,
|
||||||
|
clientCount: this.clients.size,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
removeClient(clientId) {
|
removeClient(clientId) {
|
||||||
const client = [...this.clients].find((c) => c.id === clientId);
|
this.clients.delete(clientId);
|
||||||
if (client) {
|
|
||||||
this.clients.delete(client);
|
|
||||||
logInfo(`SSE client disconnected: ${clientId}. Total clients: ${this.clients.size}`);
|
logInfo(`SSE client disconnected: ${clientId}. Total clients: ${this.clients.size}`);
|
||||||
}
|
this.emitClientChange({
|
||||||
|
type: "remove",
|
||||||
|
clientId,
|
||||||
|
clientCount: this.clients.size,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
notifyClients(event) {
|
notifyClients(event) {
|
||||||
this.clients.forEach((client) => {
|
for (const client of this.clients.values()) {
|
||||||
client.send(event);
|
client.send(event);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
getClientCount() {
|
getClientCount() {
|
||||||
return this.clients.size;
|
return this.clients.size;
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@dpu/shared",
|
"name": "@dpu/shared",
|
||||||
"version": "1.5.3",
|
"version": "1.6.4",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@dpu/shared",
|
"name": "@dpu/shared",
|
||||||
"version": "1.5.3",
|
"version": "1.6.4",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
"chalk": "^5.6.2",
|
"chalk": "^5.6.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@dpu/shared",
|
"name": "@dpu/shared",
|
||||||
"version": "1.5.3",
|
"version": "1.6.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -31,4 +31,5 @@ export type API_HA_DeskPosition = {
|
|||||||
position: string;
|
position: string;
|
||||||
is_standing: boolean;
|
is_standing: boolean;
|
||||||
last_changed: string;
|
last_changed: string;
|
||||||
|
last_changed_seconds: number;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { API_HA_DeskPosition } from "./homeassistant";
|
import { type API_HA_DeskPosition } from "./homeassistant";
|
||||||
import { TidalGetCurrent } from "./tidal";
|
import { type TidalGetCurrent } from "./tidal";
|
||||||
|
|
||||||
export type FullInformation = {
|
export type FullInformation = {
|
||||||
ha_desk_position: API_HA_DeskPosition | null;
|
ha_desk_position: API_HA_DeskPosition | null;
|
||||||
ha_temp: string | null;
|
ha_temp: string | null;
|
||||||
tidal_current: TidalGetCurrent | null;
|
tidal_current: TidalGetCurrent | null;
|
||||||
}
|
};
|
||||||
|
|||||||
58
src/sse.ts
58
src/sse.ts
@@ -1,40 +1,72 @@
|
|||||||
import { logInfo } from "./logger";
|
import { UUID } from "crypto";
|
||||||
|
import { logInfo } from "./logger.js";
|
||||||
|
|
||||||
export type SseClient = {
|
export type SseClient = {
|
||||||
id: number;
|
id: UUID;
|
||||||
send: (data: SseEvent) => void;
|
send: (data: SseEvent) => void;
|
||||||
}
|
};
|
||||||
|
|
||||||
export type SseEvent = {
|
export type SseEvent = {
|
||||||
type: string;
|
type: string;
|
||||||
data?: unknown;
|
data?: unknown;
|
||||||
message?: string;
|
message?: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export type SseClientChangeEvent = {
|
||||||
|
type: "add" | "remove";
|
||||||
|
clientId: string;
|
||||||
|
clientCount: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SseClientChangeCallback = (event: SseClientChangeEvent) => void;
|
||||||
|
|
||||||
export class SseService {
|
export class SseService {
|
||||||
private clients = new Set<SseClient>();
|
private clients: Map<string, SseClient> = new Map();
|
||||||
|
private clientChangeCallbacks: SseClientChangeCallback[] = [];
|
||||||
|
|
||||||
|
onClientChange(callback: SseClientChangeCallback): () => void {
|
||||||
|
this.clientChangeCallbacks.push(callback);
|
||||||
|
return () => {
|
||||||
|
this.clientChangeCallbacks = this.clientChangeCallbacks.filter(
|
||||||
|
(cb) => cb !== callback,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private emitClientChange(event: SseClientChangeEvent): void {
|
||||||
|
for (const callback of this.clientChangeCallbacks) {
|
||||||
|
callback(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addClient(client: SseClient): void {
|
addClient(client: SseClient): void {
|
||||||
this.clients.add(client);
|
this.clients.set(client.id, client);
|
||||||
logInfo(
|
logInfo(
|
||||||
`SSE client connected: ${client.id}. Total clients: ${this.clients.size}`,
|
`SSE client connected: ${client.id}. Total clients: ${this.clients.size}`,
|
||||||
);
|
);
|
||||||
|
this.emitClientChange({
|
||||||
|
type: "add",
|
||||||
|
clientId: client.id,
|
||||||
|
clientCount: this.clients.size,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeClient(clientId: number): void {
|
removeClient(clientId: string): void {
|
||||||
const client = [...this.clients].find((c) => c.id === clientId);
|
this.clients.delete(clientId);
|
||||||
if (client) {
|
|
||||||
this.clients.delete(client);
|
|
||||||
logInfo(
|
logInfo(
|
||||||
`SSE client disconnected: ${clientId}. Total clients: ${this.clients.size}`,
|
`SSE client disconnected: ${clientId}. Total clients: ${this.clients.size}`,
|
||||||
);
|
);
|
||||||
}
|
this.emitClientChange({
|
||||||
|
type: "remove",
|
||||||
|
clientId,
|
||||||
|
clientCount: this.clients.size,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyClients(event: SseEvent): void {
|
notifyClients(event: SseEvent): void {
|
||||||
this.clients.forEach((client) => {
|
for (const client of this.clients.values()) {
|
||||||
client.send(event);
|
client.send(event);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getClientCount(): number {
|
getClientCount(): number {
|
||||||
|
|||||||
Reference in New Issue
Block a user