* feat: add object base64 hash method * chore: add script to add package * feat: add request-handler package * wip: add request handlers for all jobs and widget api procedures * wip: remove errors shown in logs, add missing decryption for secrets in cached-request-job-handler * wip: highly improve request handler, add request handlers for calendar, media-server, indexer-manager and more, add support for multiple inputs from job handler creator * refactor: move media-server requests to request-handler, add invalidation logic for dns-hole and media requests * refactor: remove unused integration item middleware * feat: add invalidation to switch entity action of smart-home * fix: lint issues * chore: use integration-kind-by-category instead of union for request-handlers * fix: build not working for tasks and websocket * refactor: add more logs * refactor: readd timestamp logic for diconnect status * fix: lint and typecheck issue * chore: address pull request feedback
53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
import { observable } from "@trpc/server/observable";
|
|
|
|
import { getIntegrationKindsByCategory } from "@homarr/definitions";
|
|
import type { StreamSession } from "@homarr/integrations";
|
|
import { mediaServerRequestHandler } from "@homarr/request-handler/media-server";
|
|
|
|
import type { IntegrationAction } from "../../middlewares/integration";
|
|
import { createManyIntegrationMiddleware } from "../../middlewares/integration";
|
|
import { createTRPCRouter, publicProcedure } from "../../trpc";
|
|
|
|
const createMediaServerIntegrationMiddleware = (action: IntegrationAction) =>
|
|
createManyIntegrationMiddleware(action, ...getIntegrationKindsByCategory("mediaService"));
|
|
|
|
export const mediaServerRouter = createTRPCRouter({
|
|
getCurrentStreams: publicProcedure
|
|
.unstable_concat(createMediaServerIntegrationMiddleware("query"))
|
|
.query(async ({ ctx }) => {
|
|
return await Promise.all(
|
|
ctx.integrations.map(async (integration) => {
|
|
const innerHandler = mediaServerRequestHandler.handler(integration, {});
|
|
const { data } = await innerHandler.getCachedOrUpdatedDataAsync({ forceUpdate: false });
|
|
return {
|
|
integrationId: integration.id,
|
|
sessions: data,
|
|
};
|
|
}),
|
|
);
|
|
}),
|
|
subscribeToCurrentStreams: publicProcedure
|
|
.unstable_concat(createMediaServerIntegrationMiddleware("query"))
|
|
.subscription(({ ctx }) => {
|
|
return observable<{ integrationId: string; data: StreamSession[] }>((emit) => {
|
|
const unsubscribes: (() => void)[] = [];
|
|
for (const integration of ctx.integrations) {
|
|
const innerHandler = mediaServerRequestHandler.handler(integration, {});
|
|
|
|
const unsubscribe = innerHandler.subscribe((sessions) => {
|
|
emit.next({
|
|
integrationId: integration.id,
|
|
data: sessions,
|
|
});
|
|
});
|
|
unsubscribes.push(unsubscribe);
|
|
}
|
|
return () => {
|
|
unsubscribes.forEach((unsubscribe) => {
|
|
unsubscribe();
|
|
});
|
|
};
|
|
});
|
|
}),
|
|
});
|