Interface: MediaSessionStorage
Defined in: packages/media-session/src/persistence.ts:46
Where a persisted session is written. Injected, structurally typed, and
never depended on — exactly the shape AsyncStorage, react-native-mmkv,
expo-sqlite/kv-store and a five-line in-memory map all already satisfy.
This package gains zero dependencies from persistence, for the same
reason wireAudioSession takes a structural player rather than importing
@afkcodes/timbre-player (ARCHITECTURE §3): the moment a session library picks a
storage engine, half its users have to ship two.
Both methods may be synchronous or return a promise; withPersistence handles either, and a synchronous implementation is written through synchronously (see its "Write scheduling" note).
Example
import AsyncStorage from '@react-native-async-storage/async-storage'
withPersistence(service, AsyncStorage) // async
const mmkv = new MMKV()
withPersistence(service, { // sync
getItem: (k) => mmkv.getString(k) ?? null,
setItem: (k, v) => mmkv.set(k, v),
})
Methods
getItem()
getItem(key: string): string | Promise<string | null> | null;
Defined in: packages/media-session/src/persistence.ts:48
null (not undefined) for "nothing stored" — AsyncStorage's contract.
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
string | Promise<string | null> | null
setItem()
setItem(key: string, value: string): void | Promise<void>;
Defined in: packages/media-session/src/persistence.ts:49
Parameters
| Parameter | Type |
|---|---|
key | string |
value | string |
Returns
void | Promise<void>