-
Notifications
You must be signed in to change notification settings - Fork 327
Description
What are some ways to run xeokit apps offline?
How to build a xeokit app for mobile devices, that can load models and save BCF viewpoints etc, at locations where a network is not available?
This is an open issue, where we might discuss techniques for building offline apps on xeokit.
Use Case
- Run a xeokit app in a browser on a tablet or phone, with no internet access (eg. on work site)
- Load large models (hundreds of MB) from the device's file system
- Save BCF JSON viewpoints to the device's file system
AFAIK I don't think we can use browser storage for (2) because the models will be too big. (3) could be done by running the JS in a container that provides file I/O hooks, or by serving HTTP pages locally and maybe feeding them data through a socket from a local file server process of some sort. Some thoughts below...
Limit of xeokit scope
Loading models with HTTP GETs is the only network activity that the xeokit SDK does. All other network
activity (eg. loading and saving BCF viewpoints) is the responsibility of the application layer, which is
outside the scope of xeokit. in other words, xeokit is a viewer SDK only, that only uses the network for loading models, using HTTP by default.
Accordingly, xeokit's BCFViewpointsPlugin, which captures and restores Viewer state to and from BCF JSON viewpoints, does not manage the actual persistence or transmission of those JSON viewpoints - it just transfers them in and out of the Viewer component.
The snippet below shows how we can inject custom data access objects into xeokit's loader plugins, which might be used to make a xeokit application load models off the file system and meet (2), if file system hooks were somehow available to the DAOs to use.
Run an example of custom loader DAOs here.
class MyDataSource {
constructor() {
}
getXKT(src, ok, error) {
// Fetch file from local database
}
}
const xktLoader = new XKTLoaderPlugin(viewer, {
dataSource: new MyDataSource()
});That doesn't solve saving and loading BCF of course.
Some Possibilities
Electron
While Electron itself does not natively support iOS development, it can be used to create applications for macOS, Windows, and Linux. I'm not sure, but perhaps it could load XKT files from the iOS file system?
Chrome+Node Running Locally
We could run an app locally on the device using nodejs. The app would:
- run an HTTP server on the user's device, that serves the app client HTML pages,
- run a NodeJS server process on the device that fetches models and saves BCF viewpoints for the client pages, using the device's file system, maybe with websockets or GET/PUT
- open the app pages in a browser on the device, run the app in the browser without internet
Chrome Embedded Framework
CEF allows us to embed a xeokit viewer in an app built in (at least) Java, python, .Net and Go. Essentially it provides a Javascript execution container with most standard browser APIs, that runs inside the Java/python/Net/Go environment, with hooks into that environment for things like file I/O. The app layer would manage the I/O as mentioned earlier, while possibly configuring the xeokit loader plugins with a custom DAO that hooks into the container's I/O.
Perhaps just build a CEF container in python that provides the I/O hooks for loading the models and saving/loading BCF?
Resources
- Offline Cookbook - offline application patterns; does not address our special requirement of offline persistence of large models, however.