Autodesk Forge Viewer truly realizes single machine offline application

Keywords: Mobile network SQLite Database

Autodesk Forge Viewer to truly implement stand-alone offline application)

About the offline implementation of Autodesk Forge Viewer, the official has allowed exporting SVF and related documents, allowing users to deploy SVF and other documents to private servers, but this paper discusses another requirement. The customer requirement we met is that users may not be able to access the network (such as in the mine, warehouse and other non network environments) or not allow large ones in the mobile environment In the case of data transmission, we need to consider persisting SVF and other files into mobile Sqlite database, mobile device file system, browser storage object (LocalStorage).

The idea of realization is:

Modify the front-end code of the Viewer. In online mode, local persistence is realized by returning the result of the request sent by the Viewer like the server.
Development environment: APP is developed with Cordova, and the front-end framework uses Sencha Touch.

wgs.js
            worker.addEventListenerWithIntercept = function (listener) {
				var me = this;
				//Here, the APP is developed with Cordova, and the front-end framework uses Sencha Touch
				var forgeFileStore  = Ext.getStore('forgeFileStore');
				
                var callbackFn = function callbackFn(ew) {
                    if (worker.checkEvent(ew)) return;
					//When Online, save the svf file from the worker to the phone.
					if(ew.data.debug == "response"){
						forgeFileStore.addFile(ew.data.ckMessage.url);
					}else if(ew.data.debug == "request"){
						forgeFileStore.addCount(ew.data.ckMessage.url);
					}
                    listener(ew);
                };
                if (!interceptListeners) interceptListeners = [];
                interceptListeners.push({ arg: listener, callback: callbackFn });
                worker.addEventListener('message', callbackFn, false);		
                return callbackFn;
            };

In offline mode, change Web request to read persistent data to achieve offline goal

wgs.js
					this.WORKER_FETCHING_SCRIPT = true;
					var forgeFileStore  = Ext.getStore('forgeFileStore');
					if(!forgeFileStore.deviceIsOnline){
						_this.WORKER_FETCHING_SCRIPT = false;
						window.URL = window.URL || window.webkitURL;
						var callbacks = _this.WORKER_FETCHING_CALLBACKS.concat();
						_this.WORKER_FETCHING_CALLBACKS = [];
						for (var i = 0; i < callbacks.length; ++i) {
							callbacks[i].successCB && callbacks[i].successCB();
						};
						_this.WORKER_OFFLINEDATA_URL = forgeFileStore.getStaticFiles(scriptURL);
					}else{
						xhr.send();
					}

After the above customization of the Viewer, you can realize the real stand-alone offline application of the Viewer.

Posted by TechGuru on Mon, 23 Dec 2019 10:59:05 -0800