streamPropertyChanged, getting escaped string in newValue property

We’re using Openvidu 2.20.0 and this is only an issue when we join the call from an Android app, the issue doesn’t exist between openvidu-browser users.

The android code that we’re using was initially based on the openvidu Android demo repo.

To the problem:

From the Android app we want to send the streamPropertyChanged event, changing the audioActive property.
This is the code that puts the parameters together.

Map<String, String> params = new HashMap<>();
      params.put("property", "audioActive");
      params.put("streamId", streamId);
      params.put("newValue", "true");
      params.put("reason", "publishAudio");
      this.ID_PUBLISHAUDIO.set(this.sendJson(JsonConstants.STREAMPROPERTYCHANGED_METHOD, params));

This event is recieved by other participants but it comes out like this in the websocket message:

{"method":"streamPropertyChanged","params":{"connectionId":"con_LO2S0hU7Gl","streamId":"str_CAM_LUck_con_LO2S0hU7Gl","property":"audioActive","newValue":"\"true\"","reason":"publishAudio"},"jsonrpc":"2.0"}

Please take note of the “newValue” value. This is how the browser user get the event - it is escaped and interpreted as false.

Is this something that you’ve seen before? I can’t find anything wrong in the app and no errors in the server logs.

Feels like this is an issue with how it’s sent via the Android app.
The sendJson method looks like this:

public synchronized int sendJson(String method, Map<String, String> params) {
        final int id = RPC_ID.get();
        JSONObject jsonObject = new JSONObject();
        try {
            JSONObject paramsJson = new JSONObject();
            for (Map.Entry<String, String> param : params.entrySet()) {
                paramsJson.put(param.getKey(), param.getValue());
            }
            jsonObject.put("jsonrpc", JsonConstants.JSON_RPCVERSION);
            jsonObject.put("method", method);
            jsonObject.put("id", id);
            jsonObject.put("params", paramsJson);
        } catch (JSONException e) {
            Log.e(TAG, "JSONException raised on sendJson", e);
            return -1;
        }
        this.websocket.sendText(jsonObject.toString());
        RPC_ID.incrementAndGet();
        return id;
    }

Just can’t find an issue with how the text is sent over the websocket.

Ok, if the “newValue” value is treated as its original typ (boolean) in a jsonObject, instead of a “true” string, it works fine.

In the sendJson method I added this “hack”, converting all “true” strings to booleans;

JSONObject paramsJson = new JSONObject();
            for (Map.Entry<String, String> param : params.entrySet()) {
              String key = param.getKey();
              String val = param.getValue();
              if(val.equals("true")) {
                paramsJson.put(key, true);
              }
              else {
                paramsJson.put(key, val);
              }
            }

and that’s how I could see that it would be better to work with the propert data types.

Trying to understand why sendJson, in the Android demo app, takes a Map<string, string>, when in fact it wants to convert it to a JSONObject anyways.
Anyone from the Openvidu team that has any deeper knowledge of that?

To avoid this problem we should probably change the types of the Map object to <String, Object> to allow other primitive types as values.

Thanks for confirming @pabloFuente