0
votes

I want to achieve such a functionality. That is: 1) in case of connecting to worklight server successfully, Direct Update is available. 2) in case of failing to connect to worklight server, the app can run offline.

Below is my configuration in "initOptions.js".

// # Should application automatically attempt to connect to Worklight Server on                           application start up
// # The default value is true, we are overriding it to false here.
connectOnStartup : true,

// # The callback function to invoke in case application fails to connect to Worklight Server
onConnectionFailure: function (){
    alert("onConnectionFailure");
    doDojoReady();
},

// # Worklight server connection timeout
timeout: 10 * 1000,

// # How often heartbeat request will be sent to Worklight Server
heartBeatIntervalInSecs: 20 * 60,

// # Should application produce logs
// # Default value is true
//enableLogger: false,

// # The options of busy indicator used during application start up
busyOptions: {text: "Loading..."

But it doesn't work. Any idea?

2
I am using worklight Version: 5.0.5. And when network is available, Direct Update works fine; But when offline, my app doesn't work. - Hugh Shao

2 Answers

1
votes

Direct Update happens only when a connection to the server is available. From the way you phrased your question, your problem is that when the app cannot connect to the server it doesn't work "offline". So your question has got nothing to do with Direct Update (if it does, re-phrase your question appropriately).

What you should do, is read the training material for working offline in Worklight.

You are not specifying what "doesn't work". Do you get the alert you've placed in onConnectionFailure? How does your doDojoReady function look like?

0
votes

I too am using Dojo in Worklight.

My practice is have worklight configured not to connect on startup

 var wlInitOptions = {  
     connectOnStartup : false

in my wl init I then initialise my dojo app,

 function wlCommonInit(){
  loadDojoLayers(); 
 };

requiring whatever layers I'm using, and then do the actual dojo parsing

 require([ "dojo/parser",
          "myApp/appController",
          "dojo/domReady!"
        ],
       function(parser, appController) {                
           parser.parse().then (function(){
                appController.init();
       });          
});

Finally, now WL, Dojo, and myApp are all ready I attempt the WL connection, calling this method from my appController.init()

connectWLServer: function() {

      // possibly WL.Client.login(realm) here

       var options = {
             onSuccess: lang.hitch(this, "connectedWLServer"),
             onFailure: lang.hitch(this, "connectWLServerFailed"),
       };

       WL.Client.connect(options);
}

Any Direct Update activities happen at this point. Note that the app as whole keeps going whether or not the connection works, but clearly we can run appropriate code in success and fail cases. Depending upon exactly what authentication is needed an explicit login call may be needed - adapter-based authentication can't happen automatically from inside the connect().