Skip to content

Commit

Permalink
feat: add getTrack for websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
beoe committed Dec 28, 2015
1 parent fff11d6 commit 1a73d2d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Expand Up @@ -2,7 +2,7 @@

<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
id="info.snowhow.plugin.gpstrack"
version="0.2.2">
version="0.3.0">

<name>gpstrack</name>

Expand Down
6 changes: 6 additions & 0 deletions src/android/GPSServer.java
Expand Up @@ -14,6 +14,8 @@
import org.java_websocket.server.WebSocketServer;
import android.util.Log;

import org.json.JSONObject;

import info.snowhow.plugin.RecorderService;

/**
Expand Down Expand Up @@ -44,6 +46,10 @@ public void onMessage( WebSocket conn, String message ) {
Log.d(LOG_TAG, "got msg from UI: ->"+message+"<-");
if (message.equals("quit")) {
rs.stopRecording();
} else if (message.equals("getTrack")) {
String track = rs.getTrack().toString();
Log.d(LOG_TAG, "got track from Recorder "+track+"<-");
sendString("{ \"type\": \"track\", \"msg\": "+rs.getTrack().toString()+" }");
} else if (message.equals("getFilename")) {
sendString("{ \"type\": \"filename\", \"msg\": \""+rs.getTrackFilename()+"\" }");
}
Expand Down
19 changes: 18 additions & 1 deletion src/android/RecorderService.java
Expand Up @@ -31,6 +31,7 @@
import java.io.RandomAccessFile;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
Expand Down Expand Up @@ -58,7 +59,7 @@


public class RecorderService extends Service {
private static final String GPS_TRACK_VERSION = "0.2.2";
private static final String GPS_TRACK_VERSION = "0.3.0";

private static final String LOG_TAG = "GPSTrack";
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 10; // in Meters
Expand Down Expand Up @@ -380,6 +381,22 @@ public String getTrackFilename() {
return tf;
}

public JSONObject getTrack() {
JSONObject t = new JSONObject();
try {
File file = new File(tf);
FileInputStream fis = new FileInputStream(file);
byte[] data = new byte[(int) file.length()];
fis.read(data);
fis.close();
String str = new String(data, "UTF-8");
t = new JSONObject(str);
} catch (Exception e) {
Log.d(LOG_TAG, "getTrack:", e);
}
return t;
}


private BroadcastReceiver RecorderServiceBroadcastReceiver = new BroadcastReceiver() {
@Override
Expand Down

0 comments on commit 1a73d2d

Please sign in to comment.