ConstThe plugin keeps the last position of each URL for this player session
and skips a URL too long to be a key. Keys are counted in UTF-8 bytes, so
the length is measured with Buffer.byteLength, not length; a set
that would take the plugin's entries over 1 MiB rejects with limit and
changes nothing, so the plugin clears the old entries and goes on.
import { SESSION_STORAGE_LIMITS } from "@vestra-player/sdk/testing";
const session = plugin.storage.session;
if (Buffer.byteLength(url) <= SESSION_STORAGE_LIMITS.keyBytes) {
try {
await session.set(url, position);
} catch (error) {
if ((error as PluginError).code !== "limit") throw error;
// Full: start over rather than lose the newest position.
for (const key of await session.keys()) await session.delete(key);
await session.set(url, position);
}
}
The player's limits on SessionStorage. A key outside them fails with code
invalid; asetthat would make the plugin's entries larger thanbytesfails withlimitand changes nothing. A singlesetmust also fit in one message to the player (MESSAGE_LIMIT, 1 MiB with the key and the request around the value). The player's tests check that these agree with the player.