Overview
Overview
The "reader," codename Volpe, is a single-page web application (SPA) designed for the sole purpose of enabling users to read, listen to, and interact with content. While content can originate from various formats such as PDF, EPUB, or Audiobooks, all content undergoes preprocessing and optimization before being used within the reader.
The reader is always embedded within a host, referred to as volpe_host. The host is responsible for:
- Bootstrapping the reader.
- Providing essential metadata and session details.
- Acting as a proxy or gateway between the reader and the broader Publica.la platform.
The reader cannot function independently; it must be embedded within a host.
Embedding Methods
The reader is embedded differently depending on the host type:
- Web: Embedded using a secured
<iframe>. - Mobile and Desktop Apps: Embedded using a WebView (platform-specific implementations for iOS, Android, and Electron).
Reader Host Interaction
Host Components
-
reader-host-template.html:- Contains an
<iframe>element for loading the reader. - Initially, the
<iframe>does not have ansrcattribute, allowing controlled loading.
- Contains an
-
reader-host-manager.js:- Responsible for bootstrapping the reader (Volpe).
- Sends publication metadata and configuration to the reader.
- Acts as a communication bridge between the reader and the host.
Reader Load Sequence
- The host initiates the loading of the reader's
index.html. - When the
onloadevent triggers, the host sends asetHostLocationevent to the reader, including the host's location:{
"hostLocation": "window.location.href"
}- This ensures precise communication between the host and the reader using the
postMessageAPI.
- This ensures precise communication between the host and the reader using the
- The reader continues loading and, once ready, emits a
readerInitializedevent. - The host listens for
readerInitializedand responds withreadingSessionData, providing full session details to complete the loading process.
Events and Communication
Events from Reader to Host
The reader communicates key events to the host, including:
readerInitialized- Signals that the reader is ready to receive content and configuration.close- Requests the host to close the reader.locationChanged- Notifies the host of content position changes.shareContent- Provides shareable content details for the OS's native sharing UI.favoriteIssuesToggler- Requests the host to toggle a publication as a favorite.
Events from Host to Reader
The reader expects the following events from the host:
6. setHostLocation - Provides the host's URL for accurate communication.
7. **readingSessionData