Commit 8e0936c5 authored by Chris Scott's avatar Chris Scott

remove config param authToken in favour of entire http params object, more flexible for others

parent 23b7ebbc
...@@ -23,8 +23,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -23,8 +23,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
private Boolean isEnabled = false; private Boolean isEnabled = false;
private String authToken;
private String url; private String url;
private String params;
private String stationaryRadius = "30"; private String stationaryRadius = "30";
private String desiredAccuracy = "100"; private String desiredAccuracy = "100";
private String distanceFilter = "30"; private String distanceFilter = "30";
...@@ -38,12 +38,12 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -38,12 +38,12 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
if (ACTION_START.equalsIgnoreCase(action) && !isEnabled) { if (ACTION_START.equalsIgnoreCase(action) && !isEnabled) {
result = true; result = true;
if (authToken == null || url == null) { if (params == null || url == null) {
callbackContext.error("Call configure before calling start"); callbackContext.error("Call configure before calling start");
} else { } else {
callbackContext.success(); callbackContext.success();
updateServiceIntent.putExtra("authToken", authToken);
updateServiceIntent.putExtra("url", url); updateServiceIntent.putExtra("url", url);
updateServiceIntent.putExtra("params", params);
updateServiceIntent.putExtra("stationaryRadius", stationaryRadius); updateServiceIntent.putExtra("stationaryRadius", stationaryRadius);
updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy); updateServiceIntent.putExtra("desiredAccuracy", desiredAccuracy);
updateServiceIntent.putExtra("distanceFilter", distanceFilter); updateServiceIntent.putExtra("distanceFilter", distanceFilter);
...@@ -62,9 +62,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin { ...@@ -62,9 +62,8 @@ public class BackgroundGpsPlugin extends CordovaPlugin {
} else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) { } else if (ACTION_CONFIGURE.equalsIgnoreCase(action)) {
result = true; result = true;
try { try {
// [authToken, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]); // [params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
this.params = data.getString(0);
this.authToken = data.getString(0);
this.url = data.getString(1); this.url = data.getString(1);
this.stationaryRadius = data.getString(2); this.stationaryRadius = data.getString(2);
this.distanceFilter = data.getString(3); this.distanceFilter = data.getString(3);
......
...@@ -6,6 +6,7 @@ import org.apache.http.HttpResponse; ...@@ -6,6 +6,7 @@ import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import com.tenforwardconsulting.cordova.bgloc.data.DAOFactory; import com.tenforwardconsulting.cordova.bgloc.data.DAOFactory;
...@@ -65,8 +66,8 @@ public class LocationUpdateService extends Service implements LocationListener { ...@@ -65,8 +66,8 @@ public class LocationUpdateService extends Service implements LocationListener {
private PowerManager.WakeLock wakeLock; private PowerManager.WakeLock wakeLock;
private Location lastLocation; private Location lastLocation;
private long lastUpdateTime = 0l; private long lastUpdateTime = 0l;
private String authToken = "FAKE_TOKEN"; private JSONObject params;
private String url = "http://192.168.2.15:3000/users/current_location.json"; private String url = "http://192.168.2.15:3000/users/current_location.json";
private float stationaryRadius; private float stationaryRadius;
...@@ -151,8 +152,13 @@ public class LocationUpdateService extends Service implements LocationListener { ...@@ -151,8 +152,13 @@ public class LocationUpdateService extends Service implements LocationListener {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "Received start id " + startId + ": " + intent); Log.i(TAG, "Received start id " + startId + ": " + intent);
if (intent != null) { if (intent != null) {
authToken = intent.getStringExtra("authToken"); try {
params = new JSONObject(intent.getStringExtra("params"));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
url = intent.getStringExtra("url"); url = intent.getStringExtra("url");
stationaryRadius = Float.parseFloat(intent.getStringExtra("stationaryRadius")); stationaryRadius = Float.parseFloat(intent.getStringExtra("stationaryRadius"));
distanceFilter = Integer.parseInt(intent.getStringExtra("distanceFilter")); distanceFilter = Integer.parseInt(intent.getStringExtra("distanceFilter"));
...@@ -181,7 +187,7 @@ public class LocationUpdateService extends Service implements LocationListener { ...@@ -181,7 +187,7 @@ public class LocationUpdateService extends Service implements LocationListener {
startForeground(startId, notification); startForeground(startId, notification);
} }
Log.i(TAG, "- url: " + url); Log.i(TAG, "- url: " + url);
Log.i(TAG, "- token: " + authToken); Log.i(TAG, "- params: " + params.toString());
Log.i(TAG, "- stationaryRadius: " + stationaryRadius); Log.i(TAG, "- stationaryRadius: " + stationaryRadius);
Log.i(TAG, "- distanceFilter: " + distanceFilter); Log.i(TAG, "- distanceFilter: " + distanceFilter);
Log.i(TAG, "- desiredAccuracy: " + desiredAccuracy); Log.i(TAG, "- desiredAccuracy: " + desiredAccuracy);
...@@ -582,8 +588,6 @@ public class LocationUpdateService extends Service implements LocationListener { ...@@ -582,8 +588,6 @@ public class LocationUpdateService extends Service implements LocationListener {
Log.i(TAG, "Posting native location update: " + l); Log.i(TAG, "Posting native location update: " + l);
DefaultHttpClient httpClient = new DefaultHttpClient(); DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost request = new HttpPost(url); HttpPost request = new HttpPost(url);
JSONObject params = new JSONObject();
params.put("auth_token", authToken);
JSONObject location = new JSONObject(); JSONObject location = new JSONObject();
location.put("latitude", l.getLatitude()); location.put("latitude", l.getLatitude());
......
var exec = require("cordova/exec"); var exec = require("cordova/exec");
module.exports = { module.exports = {
configure: function(success, failure, config) { configure: function(success, failure, config) {
var authToken = config.authToken || 'BackgroundGeoLocation_auth_token', var params = JSON.stringify(config.params || {}),
url = config.url || 'BackgroundGeoLocation_url', url = config.url || 'BackgroundGeoLocation_url',
stationaryRadius = (config.stationaryRadius >= 0) ? config.stationaryRadius : 50, // meters stationaryRadius = (config.stationaryRadius >= 0) ? config.stationaryRadius : 50, // meters
distanceFilter = (config.distanceFilter >= 0) ? config.distanceFilter : 500, // meters distanceFilter = (config.distanceFilter >= 0) ? config.distanceFilter : 500, // meters
locationTimeout = (config.locationTimeout >= 0) ? config.locationTimeout : 60, // seconds locationTimeout = (config.locationTimeout >= 0) ? config.locationTimeout : 60, // seconds
desiredAccuracy = (config.desiredAccuracy >= 0) ? config.desiredAccuracy : 100; // meters desiredAccuracy = (config.desiredAccuracy >= 0) ? config.desiredAccuracy : 100; // meters
debug = config.debug || false; debug = config.debug || false;
...@@ -13,7 +13,7 @@ module.exports = { ...@@ -13,7 +13,7 @@ module.exports = {
failure || function() {}, failure || function() {},
'BackgroundGeoLocation', 'BackgroundGeoLocation',
'configure', 'configure',
[authToken, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]); [params, url, stationaryRadius, distanceFilter, locationTimeout, desiredAccuracy, debug]);
}, },
start: function(success, failure, config) { start: function(success, failure, config) {
exec(success || function() {}, exec(success || function() {},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment