feat: add jellyfin integration (#672)
* feat: #655 implement jellyfin media server * fix: table overflow * feat: pr feedback * refactor: format * refactor: merge existing code * fix: code smells * refactor: format commit
This commit is contained in:
39
packages/api/src/router/widgets/media-server.ts
Normal file
39
packages/api/src/router/widgets/media-server.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { observable } from "@trpc/server/observable";
|
||||
|
||||
import type { StreamSession } from "@homarr/integrations";
|
||||
import { createItemAndIntegrationChannel } from "@homarr/redis";
|
||||
|
||||
import { createManyIntegrationMiddleware } from "../../middlewares/integration";
|
||||
import { createTRPCRouter, publicProcedure } from "../../trpc";
|
||||
|
||||
export const mediaServerRouter = createTRPCRouter({
|
||||
getCurrentStreams: publicProcedure
|
||||
.unstable_concat(createManyIntegrationMiddleware("jellyfin", "plex"))
|
||||
.query(async ({ ctx }) => {
|
||||
return await Promise.all(
|
||||
ctx.integrations.map(async (integration) => {
|
||||
const channel = createItemAndIntegrationChannel<StreamSession[]>("mediaServer", integration.id);
|
||||
const data = await channel.getAsync();
|
||||
return {
|
||||
integrationId: integration.id,
|
||||
sessions: data?.data ?? [],
|
||||
};
|
||||
}),
|
||||
);
|
||||
}),
|
||||
subscribeToCurrentStreams: publicProcedure
|
||||
.unstable_concat(createManyIntegrationMiddleware("jellyfin", "plex"))
|
||||
.subscription(({ ctx }) => {
|
||||
return observable<{ integrationId: string; data: StreamSession[] }>((emit) => {
|
||||
for (const integration of ctx.integrations) {
|
||||
const channel = createItemAndIntegrationChannel<StreamSession[]>("mediaServer", integration.id);
|
||||
void channel.subscribeAsync((sessions) => {
|
||||
emit.next({
|
||||
integrationId: integration.id,
|
||||
data: sessions,
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user