Offline mode with custom viewer

325 views
Skip to first unread message

Matt Parizeau

unread,
Apr 15, 2014, 8:26:02 PM4/15/14
to pdfnet-w...@googlegroups.com
Q:

Everything has been fine so far, and I am now trying to implement the offline feature with our customer viewer. I can get the saving portion to work
flawlessly, but have run into issues on the "loading" portion.

Currently, the relevant portion of my code is as follows:

var partRetriever = new window.CoreControls.PartRetrievers.HttpPartRetriever("XOD_URL_HERE",
    window
.CoreControls.PartRetrievers.CacheHinting.CACHE);

var doc = new window.CoreControls.Document(id);

doc
.InitOfflineDB(function() {
   
if (doc.IsDownloaded()) {
        doc
.SetOfflineModeEnabled(true); //Call #1
   
}

    doc
.LoadAsync(partRetriever, function() {
       
//Other code to call doc.LoadCanvasAsync() and create the viewer

       
//If the document isn't already saved, save it
       
if (!doc.IsDownloaded()) {
            doc
.StoreOffline(function() {
                doc
.SetOfflineModeEnabled(true); //Call #2
           
});
       
}
   
});
});

Assuming I test on a clean slate, I am able to view the XOD and later, when the download completes, confirm that the
IndexedDB/WebSQL databases are properly set up and populated.

The problems I run into are as follows:

1. After saving the XOD and calling SetOfflineModeEnabled() (Call #2 in the code), I notice that there HTTP requests are
still being made to get the saved XOD. Do I need to re-initialize a separate CoreControls.Document to avoid this?

2. When running the test a second time (after saving the XOD, call #1 in the code), I get the following syntax error from
CoreControls when calling SetOfflineModeEnabled():

Uncaught TypeError: Cannot read property 'ok' of undefined  corecontrols.js:8885
    h.Ha.Ju                                                 corecontrols.js:8885

That error message disappears if I do SetOfflineModeEnabled(false), but that obviously does not enable the offline mode.
Am I missing something? At the same time, are there other things I need to add/change to get the document to be read from
the IndexedDB/WebSQL database instead?

A:

1. I'm having trouble reproducing this with the latest WebViewer. Once you enable offline mode then any new requests for parts should be handled by the offline database instead of HTTP requests.

2. Instead of calling SetOfflineModeEnabled(true) you should set partRetriever = new CoreControls.PartRetrievers.WebDBPartRetriever();. When LoadAsync is called with a WebDB part retriever then it automatically switches to offline mode and everything is loaded from the offline database.

Reply all
Reply to author
Forward
0 new messages