emscripten Humble Cloud interface
Edward Rudd
2014-09-15 d94105b905534945d8f19d87607aed310d3c4d8b

add some documentation to the humble_api in the header. and don’t cache files by default.

  • requires implementing buildCacheKey extension point to cache files
2 files modified
17 ■■■■ changed files
client/library/humble_api.h 9 ●●●●● patch | view | raw | blame | history
client/library/library_humble.js 8 ●●●●● patch | view | raw | blame | history
client/library/humble_api.h
@@ -9,8 +9,17 @@
    bool humble_init();
    /**
     * Trigger a FS.syncfs call on the emscripten Filesystem
     */
    void humble_sync();
    /**
     * This method is 100% compatible to emscripten_async_wget_data.
     * Except that it can cache the fetched files into IndexedDB and it has 2 extension points
     *   one to map the URL/path (e.g. to handle pre-signed GETs against CDNs)
     *   another to map the URL path to a cache KEY. (e.g. if using relative allow it to be prefixed by something else
     */
    void humble_fetch_asset_data(const char* url, void *arg, em_async_wget_onload_func onload, em_arg_callback_func onerror);
#ifdef __cplusplus
client/library/library_humble.js
@@ -22,16 +22,18 @@
            if (HUMBLE_API.options.buildCacheKey) {
                return HUMBLE_API.options.buildCacheKey.call(HUMBLE_API, path);
            } else {
                return path;
                return null;
            }
        },
        storeToCache: function(path, byteArray, ondone) {
            HUMBLE_API.file_cache[path] = byteArray;
            if (path !== null) {
                HUMBLE_API.file_cache[path] = byteArray;
            }
            ondone(null);
        },
        fetchFromCache: function(path, ondone, onfail) {
            if (path in HUMBLE_API.file_cache) {
            if (path !== null && path in HUMBLE_API.file_cache) {
                ondone(HUMBLE_API.file_cache[path]);
            } else {
                // NULL for file not cached.  Error object otherwise