Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Data Sync
syncinfo

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);
    }
});    


syncdata

The syncdata request will attempt to initiate a Pulsar sync action. This method is equivalent to pressing the "Sync now" button from the native Pulsar home screen. 

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);
	}
});
Handling Sync Notifications

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");
Sync Progress


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:

  1. "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
  2. "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);
		....
    }
});
Sync Completion


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();
        }
    }
});
interruptsync

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));
        var syncSuccess = responseData.data.success;
    } else if (responseData.type == 'error') {
        var errStr = str(responseData.data);
        console.log('A problem occurred:\n' + errStr);
    }
});
  • No labels