Pagination
For lists that span multiple pages, the SDK provides async iterators. They request pages as you consume items, so you do not have to manage page numbers.
| Iterator | Items |
|---|---|
emby.iterateChats(query?) | Chats |
emby.iterateMessagesFromChat(chatId, query?) | Messages in a chat |
emby.iterateChatParticipants(chatId, query?) | Participants in a chat |
emby.iterateUserChats(userId, query?) | A user's chats |
Read items
for await (const chat of emby.iterateChats({ type: 'group', limit: 100 })) {
console.log(chat.id, chat.title);
}
Leaving the loop prevents further pages from being requested. An error on a page is thrown from the iteration.
Read pages and totals
for await (const page of emby.iterateChats().pages()) {
console.log(page.pagination.current, page.meta.total);
console.log(page.items);
console.log(page.raw);
}
Each page contains normalized items, pagination information, metadata and the untouched response in raw.
Collect a list
const participants = await emby
.iterateChatParticipants('support-42')
.toArray();
toArray() holds every result in memory. Prefer a loop for large lists. Each iteration, .pages() call or .toArray() call starts a fresh walk from the configured starting page.
Page sizes and request controls
Iterators default to 100 items per page. They clamp larger limits to 1000, or 250 for a user's chats. Unlike getMessagesFromChat(), the messages iterator takes page and limit inside its query object.
for await (const message of emby.iterateMessagesFromChat('support-42', {
limit: 200,
timeout: 5_000,
retries: 1,
signal: AbortSignal.timeout(30_000),
})) {
console.log(message.text);
}
Request controls apply to every page. The iterator stops when the server reports no next page. Without that signal, it stops on an empty or short page, or if the returned page number differs from the requested one. Lists can change during iteration, so page-based reads are not a consistent snapshot.
See Page, PageIterator and Errors and retries.