feat(remote-control): remote control support for xtream and stalker live tv

This commit is contained in:
4gray committed 2026-02-13 22:17:20 +01:00
1 parent 12bbdf562a
commit 620ecb7518
8 files changed
+143 -35

No files matched your search

@@ -0,0 +1,34 @@
export type RemoteChannelDirection = 'up' | 'down';
/**
* Returns the adjacent item in the list for remote channel navigation.
* Uses wraparound when reaching the start or end of the list.
*/
export function getAdjacentChannelItem<T>(
items: T[],
activeId: string | number | null | undefined,
direction: RemoteChannelDirection,
getId: (item: T) => string | number | null | undefined
): T | null {
if (!Array.isArray(items) || items.length === 0 || activeId == null) {
return null;
}
const activeIdAsString = String(activeId);
const currentIndex = items.findIndex((item) => {
const itemId = getId(item);
return itemId != null && String(itemId) === activeIdAsString;
});
if (currentIndex === -1) {
return null;
}
const length = items.length;
const nextIndex =
direction === 'up'
? (currentIndex - 1 + length) % length
: (currentIndex + 1) % length;
return items[nextIndex] ?? null;
}