Compare commits

..

24 Commits

Author SHA1 Message Date
Darius
60bcd23f5b 1.6.4 2026-02-05 22:51:24 +01:00
Darius
c674d0fa72 1.6.3 2026-02-05 22:50:07 +01:00
Darius
c072f52a1a add seconds to API 2026-02-05 22:50:02 +01:00
Darius
ceadd4e5a2 1.6.2 2026-02-05 22:22:05 +01:00
Darius
b32006cf10 dont actually need that 2026-02-05 22:21:57 +01:00
Darius
0ab6194b43 1.6.1 2026-02-05 22:16:12 +01:00
Darius
46f359bb1e add LastPoll Type 2026-02-05 22:16:06 +01:00
Darius
9b852dc40c 1.6.0 2026-02-05 22:05:43 +01:00
Darius
a6d837f953 make clients of sse service observable 2026-02-05 22:05:35 +01:00
Darius
921882054d 1.5.5 2026-02-05 04:32:04 +01:00
Darius
cdd2fcb59e set => map 2026-02-05 04:31:54 +01:00
Darius
8daeed6b5f 1.5.4 2026-02-05 01:00:05 +01:00
Darius
6d05233a6e fix logger import 2026-02-05 00:59:56 +01:00
Darius
3dd61ab4e8 1.5.3 2026-02-05 00:47:31 +01:00
Darius
b7ea7bc552 dont need volume 2026-02-05 00:47:23 +01:00
Darius
d23c89c3c9 1.5.2 2026-02-05 00:31:13 +01:00
Darius
fd766a822c add homepage information type pt2 2026-02-05 00:31:08 +01:00
Darius
bf580c8a84 1.5.1 2026-02-05 00:27:11 +01:00
Darius
12fc98c925 add homepage information type 2026-02-05 00:26:47 +01:00
Darius
3b7ef0f3ee 1.5.0 2026-02-04 21:52:35 +01:00
Darius
ada7268062 sse typing 2026-02-04 21:52:32 +01:00
Darius
b55e1dd0a6 1.4.1 2026-02-03 22:20:11 +01:00
Darius
49f04ef82f dont make it more complicated than needed 2026-02-03 22:20:01 +01:00
Darius
862401fa9b forgot to build oops 2026-01-28 22:53:57 +01:00
20 changed files with 217 additions and 37 deletions

View File

@@ -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

View File

@@ -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,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC9C,GAAG,EAAE,mBAAmB,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,YAAY,EAAE,WAAW,CAAC;CAC3B;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC"} {"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;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE;QACX,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;KACvB,CAAC;IACF,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE;QACR,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACvB,CAAC;CACF,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC/C,GAAG,EAAE,mBAAmB,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,YAAY,EAAE,WAAW,CAAC;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"}

8
dist/homepage.d.ts vendored Normal file
View File

@@ -0,0 +1,8 @@
import { type API_HA_DeskPosition } from "./homeassistant";
import { type TidalGetCurrent } from "./tidal";
export type FullInformation = {
ha_desk_position: API_HA_DeskPosition | null;
ha_temp: string | null;
tidal_current: TidalGetCurrent | null;
};
//# sourceMappingURL=homepage.d.ts.map

1
dist/homepage.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"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"}

1
dist/homepage.js vendored Normal file
View File

@@ -0,0 +1 @@
export {};

2
dist/index.d.ts vendored
View File

@@ -1,6 +1,8 @@
export * from "./fastify.js"; export * from "./fastify.js";
export * from "./homeassistant.js"; export * from "./homeassistant.js";
export * from "./homepage.js";
export * from "./logger.js"; export * from "./logger.js";
export * from "./sse.js";
export * from "./tidal.js"; export * from "./tidal.js";
export * from "./timehelper.js"; export * from "./timehelper.js";
//# sourceMappingURL=index.d.ts.map //# sourceMappingURL=index.d.ts.map

2
dist/index.d.ts.map vendored
View File

@@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"} {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}

2
dist/index.js vendored
View File

@@ -1,5 +1,7 @@
export * from "./fastify.js"; export * from "./fastify.js";
export * from "./homeassistant.js"; export * from "./homeassistant.js";
export * from "./homepage.js";
export * from "./logger.js"; export * from "./logger.js";
export * from "./sse.js";
export * from "./tidal.js"; export * from "./tidal.js";
export * from "./timehelper.js"; export * from "./timehelper.js";

27
dist/sse.d.ts vendored Normal file
View File

@@ -0,0 +1,27 @@
import { UUID } from "crypto";
export type SseClient = {
id: UUID;
send: (data: SseEvent) => void;
};
export type SseEvent = {
type: string;
data?: unknown;
message?: string;
};
export type SseClientChangeEvent = {
type: "add" | "remove";
clientId: string;
clientCount: number;
};
export type SseClientChangeCallback = (event: SseClientChangeEvent) => void;
export declare class SseService {
private clients;
private clientChangeCallbacks;
onClientChange(callback: SseClientChangeCallback): () => void;
private emitClientChange;
addClient(client: SseClient): void;
removeClient(clientId: string): void;
notifyClients(event: SseEvent): void;
getClientCount(): number;
}
//# sourceMappingURL=sse.d.ts.map

1
dist/sse.d.ts.map vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAG9B,MAAM,MAAM,SAAS,GAAG;IACvB,EAAE,EAAE,IAAI,CAAC;IACT,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IAClC,IAAI,EAAE,KAAK,GAAG,QAAQ,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;AAE5E,qBAAa,UAAU;IACtB,OAAO,CAAC,OAAO,CAAqC;IACpD,OAAO,CAAC,qBAAqB,CAAiC;IAE9D,cAAc,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,IAAI;IAS7D,OAAO,CAAC,gBAAgB;IAMxB,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI;IAYlC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAYpC,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAMpC,cAAc,IAAI,MAAM;CAGxB"}

42
dist/sse.js vendored Normal file
View File

@@ -0,0 +1,42 @@
import { logInfo } from "./logger.js";
export class SseService {
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) {
this.clients.set(client.id, client);
logInfo(`SSE client connected: ${client.id}. Total clients: ${this.clients.size}`);
this.emitClientChange({
type: "add",
clientId: client.id,
clientCount: this.clients.size,
});
}
removeClient(clientId) {
this.clients.delete(clientId);
logInfo(`SSE client disconnected: ${clientId}. Total clients: ${this.clients.size}`);
this.emitClientChange({
type: "remove",
clientId,
clientCount: this.clients.size,
});
}
notifyClients(event) {
for (const client of this.clients.values()) {
client.send(event);
}
}
getClientCount() {
return this.clients.size;
}
}

18
dist/tidal.d.ts vendored
View File

@@ -1,14 +1,26 @@
export type TidalSong = { export type TidalGetCurrent = {
title: string; title: string;
artists: string; artists: string;
artistsArray: string[];
album: string; album: string;
playingFrom: string; playingFrom: string;
status: "playing" | "paused"; status: "playing" | "paused";
url: string; url: string;
current: string; current: string;
currentInSeconds: number;
duration: string; duration: string;
}; durationInSeconds: number;
export type TidalVolume = { image: string;
icon: string;
localAlbumArt: string;
favorite: boolean;
trackId: string;
volume: number; volume: number;
player: {
status: "playing" | "paused";
shuffle: boolean;
repeat: "all" | "single" | "none";
};
artist: string;
}; };
//# sourceMappingURL=tidal.d.ts.map //# sourceMappingURL=tidal.d.ts.map

2
dist/tidal.d.ts.map vendored
View File

@@ -1 +1 @@
{"version":3,"file":"tidal.d.ts","sourceRoot":"","sources":["../src/tidal.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"} {"version":3,"file":"tidal.d.ts","sourceRoot":"","sources":["../src/tidal.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QACP,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;QAC7B,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;KAClC,CAAC;IACF,MAAM,EAAE,MAAM,CAAC;CACf,CAAC"}

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "@dpu/shared", "name": "@dpu/shared",
"version": "1.4.0", "version": "1.6.4",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@dpu/shared", "name": "@dpu/shared",
"version": "1.4.0", "version": "1.6.4",
"dependencies": { "dependencies": {
"axios": "^1.7.9", "axios": "^1.7.9",
"chalk": "^5.6.2", "chalk": "^5.6.2",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@dpu/shared", "name": "@dpu/shared",
"version": "1.4.0", "version": "1.6.4",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@@ -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;
}; };

8
src/homepage.ts Normal file
View File

@@ -0,0 +1,8 @@
import { type API_HA_DeskPosition } from "./homeassistant";
import { type TidalGetCurrent } from "./tidal";
export type FullInformation = {
ha_desk_position: API_HA_DeskPosition | null;
ha_temp: string | null;
tidal_current: TidalGetCurrent | null;
};

View File

@@ -1,5 +1,8 @@
export * from "./fastify.js"; export * from "./fastify.js";
export * from "./homeassistant.js"; export * from "./homeassistant.js";
export * from "./homepage.js";
export * from "./logger.js"; export * from "./logger.js";
export * from "./sse.js";
export * from "./tidal.js"; export * from "./tidal.js";
export * from "./timehelper.js"; export * from "./timehelper.js";

75
src/sse.ts Normal file
View File

@@ -0,0 +1,75 @@
import { UUID } from "crypto";
import { logInfo } from "./logger.js";
export type SseClient = {
id: UUID;
send: (data: SseEvent) => void;
};
export type SseEvent = {
type: string;
data?: unknown;
message?: string;
};
export type SseClientChangeEvent = {
type: "add" | "remove";
clientId: string;
clientCount: number;
};
export type SseClientChangeCallback = (event: SseClientChangeEvent) => void;
export class SseService {
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 {
this.clients.set(client.id, client);
logInfo(
`SSE client connected: ${client.id}. Total clients: ${this.clients.size}`,
);
this.emitClientChange({
type: "add",
clientId: client.id,
clientCount: this.clients.size,
});
}
removeClient(clientId: string): void {
this.clients.delete(clientId);
logInfo(
`SSE client disconnected: ${clientId}. Total clients: ${this.clients.size}`,
);
this.emitClientChange({
type: "remove",
clientId,
clientCount: this.clients.size,
});
}
notifyClients(event: SseEvent): void {
for (const client of this.clients.values()) {
client.send(event);
}
}
getClientCount(): number {
return this.clients.size;
}
}

View File

@@ -23,7 +23,3 @@ export type TidalGetCurrent = {
}; };
artist: string; artist: string;
}; };
export type TidalPutVolume = {
volume: number;
};