LcpModule
The API of LCP, the package's entry point: Readium LCP for react-native-readium.
Every method rejects with an LcpError. Paths are absolute paths or file:// URLs.
Methods
initialize()
initialize(options?): Promise<boolean>;
Builds the LCP service and registers it with react-native-readium. Call it once, at
startup, and wait for it before giving a ReadiumView an LCP book. Safe to call again.
Parameters
| Parameter | Type |
|---|---|
options? | LcpInitOptions |
Returns
Promise<boolean>
false when the app was built without liblcp, so LCP isn't available.
Example
const available = await LCP.initialize({ deviceName: 'My phone' });
setAuthenticationHandler()
setAuthenticationHandler(handler?): void;
Answers passphrase requests from JS, while a book opens or a license is read. Without a handler, a license whose passphrase isn't already stored fails to open.
The handler's promise must always settle: resolve undefined when the user cancels, when a
newer request replaces the prompt, or when the prompt's screen goes away. Readium waits on it.
Parameters
| Parameter | Type | Description |
|---|---|---|
handler? | LcpAuthHandler | The handler; omit it to remove the current one. |
Returns
void
Example
LCP.setAuthenticationHandler(async ({ reason, hint }) =>
promptForPassphrase({ hint, wrong: reason === 'invalidPassphrase' })
);
addPassphrase()
addPassphrase(passphrase, options?): Promise<void>;
Stores a passphrase, so licenses it unlocks open without asking.
Parameters
| Parameter | Type |
|---|---|
passphrase | string |
options? | AddPassphraseOptions |
Returns
Promise<void>
Platform
iOS. Rejects with unsupported on Android, where readium-lcp keeps its passphrase
store internal; check capabilities.
forgetPassphrases()
forgetPassphrases(): Promise<void>;
Removes every stored passphrase, so each license asks again: for signing out or switching users. Licenses and their consumed print and copy rights are kept.
Returns
Promise<void>
Platform
iOS. Rejects with unsupported on Android; check capabilities.
acquirePublication()
acquirePublication(source, options?): Promise<LcpAcquiredPublication>;
Downloads the publication a license points to, and injects the license into it.
Parameters
| Parameter | Type | Description |
|---|---|---|
source | LcplSource | The license: { url } to download it, { path } to a local .lcpl, or { json } with its contents. |
options? | AcquirePublicationOptions | - |
Returns
Promise<LcpAcquiredPublication>
The downloaded publication, in a temporary location: move it where your app keeps books.
Throws
LcpError licenseRevoked, licenseExpired, … for a license that can't be used,
network when a download fails.
Example
const { localPath } = await LCP.acquirePublication(
{ url: lcplUrl },
{ onProgress: setProgress }
);
injectLicense()
injectLicense(licenseJSON, publicationPath): Promise<void>;
Injects a license into a publication the app downloaded itself.
Parameters
| Parameter | Type | Description |
|---|---|---|
licenseJSON | string | The license document (.lcpl) contents. |
publicationPath | string | The publication to inject it into. |
Returns
Promise<void>
getLicense()
getLicense(publicationPath, options?): Promise<LcpLicense>;
Reads and validates the license in a local publication: its loan, rights and status. May call the authentication handler for the passphrase.
Parameters
| Parameter | Type |
|---|---|
publicationPath | string |
options? | GetLicenseOptions |
Returns
Promise<LcpLicense>
The license, with restriction set when the book can't be read with it.
renewLoan()
renewLoan(publicationPath, options?): Promise<LcpLicense>;
Extends the loan, when the license's canRenewLoan is true.
Parameters
| Parameter | Type |
|---|---|
publicationPath | string |
options? | RenewLoanOptions |
Returns
Promise<LcpLicense>
The updated license.
Throws
LcpError invalidRenewalPeriod for an end date past maxRenewDate; renewFailed
when the provider refuses, including loans it only renews on its web page.
returnPublication()
returnPublication(publicationPath): Promise<void>;
Returns the book to its provider, ending the loan, when the license's canReturnPublication
is true.
Parameters
| Parameter | Type |
|---|---|
publicationPath | string |
Returns
Promise<void>
Throws
LcpError alreadyReturnedOrExpired, or returnFailed.
Properties
capabilities
readonly capabilities: LcpCapabilities;
What this platform supports, e.g. to hide a "Forget passphrases" button where it can't work.