Pebble JS: add transactionId metadata to the appmessage.

Removes the errors in Pebble-Casio-WV58DE as reported in #482
This commit is contained in:
Daniele Gobbetti
2018-02-28 21:56:46 +01:00
parent 1e0d7550d9
commit d88badaf4d
2 changed files with 6 additions and 3 deletions
@@ -124,7 +124,7 @@ class PebbleIoThread extends GBDeviceIoThread {
jsEvent = "appmessage"; jsEvent = "appmessage";
} }
final String appMessage = PebbleUtils.parseIncomingAppMessage(message.message, message.appUUID); final String appMessage = PebbleUtils.parseIncomingAppMessage(message.message, message.appUUID, message.id);
LOG.debug("to WEBVIEW: event: " + jsEvent + " message: " + appMessage); LOG.debug("to WEBVIEW: event: " + jsEvent + " message: " + appMessage);
WebViewSingleton.invokeWebview(new WebViewSingleton.WebViewRunnable() { WebViewSingleton.invokeWebview(new WebViewSingleton.WebViewRunnable() {
@Override @Override
@@ -130,14 +130,14 @@ public class PebbleUtils {
return null; return null;
} }
public static String parseIncomingAppMessage(String msg, UUID uuid) { public static String parseIncomingAppMessage(String msg, UUID uuid, int transactionId) {
JSONObject jsAppMessage = new JSONObject(); JSONObject jsAppMessage = new JSONObject();
JSONObject knownKeys = PebbleUtils.getAppConfigurationKeys(uuid); JSONObject knownKeys = PebbleUtils.getAppConfigurationKeys(uuid);
SparseArray<String> appKeysMap = new SparseArray<>(); SparseArray<String> appKeysMap = new SparseArray<>();
if (knownKeys == null || msg == null) { if (knownKeys == null || msg == null) {
return "{}"; msg = "[]";
} }
String inKey, outKey; String inKey, outKey;
@@ -169,6 +169,9 @@ public class PebbleUtils {
} }
} }
jsAppMessage.put("payload", outgoing); jsAppMessage.put("payload", outgoing);
JSONObject data = new JSONObject();
data.put("transactionId", transactionId);
jsAppMessage.put("data", data);
} catch (Exception e) { } catch (Exception e) {
LOG.warn("Unable to parse incoming app message", e); LOG.warn("Unable to parse incoming app message", e);