mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-15 13:46:16 -08:00
feat(remote-control): remote control support for xtream and stalker live tv
This commit is contained in:
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;
|
||||
}
|
||||
Reference in new issue
Block a user