@vestra-player/sdk - v1.11.3
    Preparing search index...

    Interface SessionStorage

    plugin.storage.session: JSON values that live as long as the player, not as long as the plugin's process (like chrome.storage.session).

    activate can run more than once in one player session: the player stops and starts a plugin's process again when the plugin is reloaded (also a development load with --plugin) or upgraded, and after a crash or a failed start; the player also restarts plugins that share a process, and stops an idle plugin after 30 s and starts it on its next use. Variables, timers, fetch calls, sockets and pending promises do not survive that (nor do they keep the plugin running): keep state that must survive a restart here (or in storage.json when it must also survive the player quitting) and pick it up again in activate.

    Values
    The plugin's process restarts: reload, upgrade, crash kept
    The plugin failed to start or failed, and starts again kept
    The user, or a plugin that manages plugins (packages.setEnabled(id, false)), disables the plugin cleared
    An update or reinstall with enabled: false switches an enabled plugin off cleared
    The plugin is uninstalled cleared
    An earlier installation kept for a later reinstall (after a replace) is dropped because the player keeps only so many cleared
    The player quits cleared
    • Per plugin. A plugin sees only its own keys. Like dataDirectory, the values belong to the installation: a development load (--plugin) has its own.
    • JSON. set stores what JSON.stringify(value) writes, and get returns that, parsed: undefined object properties are dropped, a Date comes back as a string, NaN as null. The order of an object's properties is not kept: they may come back in another order. A value JSON.stringify cannot write (undefined, a function, a cycle, a BigInt) or a string with a lone surrogate ("\uD800") fails with invalid. The value is not checked when it comes back: after an upgrade an older version's value may be read, so check its shape when it matters.
    • Bounded. Keys are 1–1024 bytes of text. A plugin holds at most 1 MiB, counting every key, its value as compact JSON and 128 bytes per key (SESSION_STORAGE_LIMITS); a set beyond it fails with limit and changes nothing. One set is also one message to the player, at most 1 MiB with its key, so a single value is a little smaller than that; a larger one fails with limit. Split large state over several keys.
    • Each call is one request. A set is kept once its promise resolves, so a crash right after loses nothing; there is no debounce. Calls answer in order.

    A download queue survives the plugin being reloaded or crashing, and is empty again when the player starts next time. Session storage lives in the player process for one player run; each set is kept once its promise resolves, so nothing is lost if the plugin dies right after.

    // A queue the plugin is working through: after a reload or a crash it
    // goes on where it stopped, after the player quits it starts afresh.
    const pending = (await plugin.storage.session.get<string[]>("queue")) ?? [];
    pending.push("https://example.com/a.mkv");
    await plugin.storage.session.set("queue", pending);

    1.5.25

    The player keeps the values in its own memory, per plugin, until it quits; the plugin's process may restart in between. Each call is one request to the player, answered in order, with no debounce.

    interface SessionStorage {
        get<T = unknown>(key: string): Promise<T | undefined>;
        set(key: string, value: unknown): Promise<void>;
        delete(key: string): Promise<void>;
        keys(): Promise<string[]>;
    }
    Index
    • The value stored under key, or undefined when there is none.

      Type Parameters

      • T = unknown

      Parameters

      • key: string

      Returns Promise<T | undefined>

      invalid (rejects) A bad key (empty, over 1024 bytes, with NUL or a lone surrogate).

      disabled (rejects) The plugin is stopping.

      unsupported (rejects) A player before 0.5.5.

      After a reload the plugin resumes the item it was working on. get asks the player and resolves with the value parsed from JSON, or undefined when nothing is stored; the value is not checked, so its shape is checked here.

      const current = await plugin.storage.session.get<{ url: string }>("current");
      if (typeof current?.url === "string") await plugin.osd.show("Resuming {}", [current.url]);

      1.5.25

    • Store or replace value under key. invalid for a bad key or a value that is not JSON, limit when the plugin's values would be over 1 MiB or the request over the 1 MiB message limit.

      Parameters

      • key: string
      • value: unknown

      Returns Promise<void>

      invalid (rejects) A bad key, or a value JSON cannot hold (or a string with a lone surrogate).

      disabled (rejects) The plugin is stopping.

      unsupported (rejects) A player before 0.5.5.

      limit (rejects) The plugin's values would pass 1 MiB, or the request the 1 MiB message limit; nothing changes.

      The plugin records the URL it is processing, so a reload can continue with it. The value is stored as JSON.stringify writes it, and is kept once the promise resolves.

      await plugin.storage.session.set("current", { url: "https://example.com/a.mkv" });
      

      1.5.25

    • Remove a key; removing a missing one is fine.

      Parameters

      • key: string

      Returns Promise<void>

      invalid (rejects) A bad key.

      disabled (rejects) The plugin is stopping.

      unsupported (rejects) A player before 0.5.5.

      When the work finishes, the plugin removes the entry so that a later reload does not resume it. Removing a key that is not there is fine.

      await plugin.storage.session.delete("current");
      

      1.5.25

    • The keys stored, in code point order.

      Returns Promise<string[]>

      disabled (rejects) The plugin is stopping.

      unsupported (rejects) A player before 0.5.5.

      The plugin starts its session state over. keys lists the plugin's own keys in code point order; each delete is a request of its own.

      const session = plugin.storage.session;
      for (const key of await session.keys()) await session.delete(key);

      1.5.25