1

I am using Sinch to create an app in android and some of the functionalities that I need can only be implemented by calling their REST API. I want to mute a particular user, for that I have written the code like this

        String userName = call.getCallId();
        final String muteURL = URL+CallingUsersName+"/"+userName;
        final String muteParticipant = "{ \"command\" : \"mute\" }";
        JSONObject muteJSON;
        try{
            muteJSON = new JSONObject(muteParticipant);
            Toast.makeText(getActivity(),muteJSON.toString(),Toast.LENGTH_SHORT).show();
        }catch (JSONException e ) {
            muteJSON = null;
            Toast.makeText(getActivity(), e.toString(), Toast.LENGTH_SHORT).show();
        }
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.PATCH, muteURL, muteJSON, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                mConferenceParticipants.setText(response.toString());

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mConferenceParticipants.setText(error.toString());

            }
        }){
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> params = new HashMap<String, String>();
                String creds = String.format("%s:%s",AppKey,AppSecretKey);
                String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.NO_WRAP);
                params.put("Authorization", auth);
                params.put("Content-Type", "application/json");
//                params.put("X-HTTP-Method-Override", "PATCH");
                return params;
//                return super.getHeaders();
            }
        };
//        jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(8000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        rq.add(jsonObjectRequest);

When I call this request the meeting is actually going on but I am getting this error

BasicNetwork.performRequest: Unexpected response code 400 for https://callingapi.sinch.com/v1/conferences/id/Meeting/a291ba94-e430-454f-80a9-73013cd43451

I believe that 400 means Conference not found but the conference is established and in the same activity I am also calling the REST API that will tell me the no. of participants in the meeting and that is working correctly.

Any idea what is wrong in this?

Tyson
  • 747
  • 2
  • 6
  • 18
  • 400 means `Bad Request` so you must be building the request in an incorrect way. I've not worked with this API, it is the only thing I can say. – Alejandro Alcalde Mar 08 '17 at 15:38
  • ok I tried a new implementation then I got this error " BasicNetwork.performRequest: Unexpected response code 405 for https://callingapi.sinch.com/v1/conferences/id/Meeting/63801236-a270-44b9-a00c-5ee54b8c042a" – Tyson Mar 08 '17 at 16:11

2 Answers2

1

I tried to solve this problem for a long time and finally got it working. Here is the code:

  public void MuteTheParticipants(){
        String userName = call.getCallId();
        final String muteURL = URL+CallingUsersName+"/"+userName;
        StringRequest sr = new StringRequest(Request.Method.PATCH, muteURL, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                if(flag)
                    muteButton.setBackgroundResource(R.drawable.microphone);
                else
                    muteButton.setBackgroundResource(R.drawable.microphone_off
                    );

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(getActivity(),error.toString(),Toast.LENGTH_SHORT).show();
            }
        }){
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> params = new HashMap<String, String>();
                String creds = String.format("%s:%s",AppKey,AppSecretKey);
                String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.NO_WRAP);
                params.put("Authorization", auth);
                return params;
//                return super.getHeaders();
            }

            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                HashMap<String, String> params = new HashMap<String, String>();
                if(!flag) {
                    params.put("command", "mute");
                    flag = true;
                }else {
                    params.put("command", "unmute");
                    flag = false;
                }
                return params;
            }
        };
        sr.setRetryPolicy(new DefaultRetryPolicy(8000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        rq.add(sr);
}
Nirmal Raj
  • 729
  • 6
  • 18
0

your variable says username, it should be callid you mute not username

cjensen
  • 2,703
  • 1
  • 16
  • 15