use of com.fitpay.android.webview.events.RtmMessage in project fitpay-android-sdk by fitpay.
the class RtmParserTest method testWebAppVersionSame.
@Test
public void testWebAppVersionSame() {
String rtmMsgStr = "{\"callbackId\":\"0\",\"data\":\"{\\\"version\\\":3}\",\"type\":\"version\"}";
RtmMessage msg = Constants.getGson().fromJson(rtmMsgStr, RtmMessage.class);
int webAppRtmVersion = RtmType.RTM_VERSION;
String errorMsg = null;
try {
RtmParserImpl.parse(wvci, webAppRtmVersion, msg);
} catch (IllegalStateException e) {
errorMsg = e.getMessage();
}
Assert.assertNull(errorMsg);
}
use of com.fitpay.android.webview.events.RtmMessage in project fitpay-android-sdk by fitpay.
the class WebViewCommunicatorImpl method dispatchMessage.
@Override
@JavascriptInterface
public void dispatchMessage(String message) throws JSONException {
if (message == null) {
FPLog.w(WV_DATA, "\\Received\\: invalid message");
throw new IllegalArgumentException("invalid message");
}
JSONObject obj = new JSONObject(message);
String callBackId = obj.getString("callBackId");
if (callBackId == null) {
FPLog.w(WV_DATA, "\\Received\\: callBackId is missing in the message");
throw new IllegalArgumentException("callBackId is missing in the message");
}
String type = obj.getString("type");
if (type == null) {
FPLog.w(WV_DATA, "\\Received\\: type is missing in the message");
throw new IllegalArgumentException("type is missing in the message");
}
FPLog.i(WV_DATA, String.format(Locale.getDefault(), "\\Received\\: callbackId:%s type:%s", callBackId, type));
String dataStr = obj.has("data") ? obj.getString("data") : null;
RxBus.getInstance().post(new RtmMessage(callBackId, dataStr, type));
}
Aggregations