The syncinfo query returns the following information about the last Pulsar sync:
- Last Sync Attempt Date/Time
- Last Successful Sync Date/Time
var request = { "type" : "syncinfo", "data" : { } // empty object- this is required in the current API }; bridge.sendRequest(request, function (results) { console.log('Javascript got its response: ' + str(results)); if (results.type === "syncinfoResponse") { var lastsyncattempt = results.data.lastsyncattempt; var lastsuccessfulsync = results.data.lastsuccessfulsync; } else if (results.type == 'error') { errStr = results.data; alert('A problem occurred:\n' + errStr); } });
var request = { "type" : "syncdata", "data" : { } // empty object- this is required in the current API }; bridge.sendRequest(request, function (results) { console.log('Javascript got its response: ' + str(results)); if (results.type === "syncDataResponse") { // successfully requested sync } else if (results.type == 'error') { errStr = results.data; alert('A problem occurred:\n' + errStr); } });
Overview
The Pulsar sync process provides a feedback mechanism for monitoring the overall progress of the sync. You can hook into progress and completion notifications from javascript by
registering handler functions with the Pulsar bridge. There can only be one handler assigned to a given handler name. See the examples of handler setup below:
...... // during bridge initialization bridge.addHandler = function(handlerName, handler) { window.WebViewJavascriptBridge.registerHandler(handlerName, handler); }; bridge.removeHandler = function(handlerName) { window.WebViewJavascriptBridge.deregisterHandler(handlerName); }; ...... // Add a handler bridge.addHandler("handlerA", function(data) { console.log("handlerA called from Pulsar"); }); doSomethingThatMakesPulsarCallHandlerA(); // Remove a handler bridge.removeHandler("handlerA");
syncDataUpdate handler
To receive progress updates during a sync initiated with the syncData request, register a handler with the name "syncDataUpdate". This function will receive an object with the progress information:
- "syncpass" - The Pulsar sync may take one or more passes to fully complete. This will be delivered as a string containing the pass number, an integer value
- "syncpercent" - This value will be delivered as a string containing a floating point value between 0 and 100.00
// Add a handler to respond to sync progress updates bridge.addHandler("syncDataUpdate", function(dataObj) { if (dataObj.hasOwnProperty("syncpercent") && dataObj.hasOwnProperty("syncpass")) { var syncPass = dataObj.syncpass; var syncPercent = dataObj.syncpercent; someScreenUpdate(syncPass, syncPercent); .... } });
syncDataFinished handler
To receive completion notifications for a sync initiated with the syncData request, register a handler with the name "syncDataFinished". This function will receive an object with the completion success status.
// Add a handler to respond to sync finished event bridge.addHandler("syncDataFinished", function(dataObj) { console.log("sync data finished"); if (dataObj.hasOwnProperty("success")) { if (dataObj.success) { doSyncSuccess(); } else { doSyncFailure(); } } });
The interruptsync request will attempt to stop the currently running sync, if any.
var request = { "type" : "interruptsync", "data" : { } // empty object- this is required in the current API }; bridge.sendRequest(request, function(responseData) { if (responseData.type === "interruptSyncResponse") { console.log('interruptSync: ' + str(responseData.data)); success(responseData.data); } else if (responseData.type == 'error') { var errStr = str(responseData.data); console.log('A problem occurred:\n' + errStr); } });