RestComm / restcomm-android-sdk

Android Mobile SDK to easily integrate communication features (WebRTC, messaging, presence, voice, video, screensharing) based on RestComm into native Mobile Applications
http://www.restcomm.com/
GNU Affero General Public License v3.0
153 stars 109 forks source link

Create new client with sdk #822

Open SlackingVeteran opened 6 years ago

SlackingVeteran commented 6 years ago

I was trying to figure out if android sdk allows to register new clients through sdk as well, I have searched a lot and no avail so far. Documentation has no references about creating new client. I have been able to initialize with existing users and use sdk to place calls but to add new client i have to login as administrator and add new client through the web page. It would be great if anyone can provide me some info about how to do it through sdk.

SlackingVeteran commented 6 years ago

The only reference I have found so far is by using RestComm API for clients for which I have to use post http request. Its doable for now but exposing the method through sdk would have been lot better.

gsaslis commented 6 years ago

@atsakiridis @ognjenns could you plz share some feedback here?

atsakiridis commented 6 years ago

@suyashbhatt you are right, this is the way its working right now; you need to take care of creating a client yourself. We are aware of the pain in this part and have plans on improving the UX in this part. Some ideas are either creating a default client per account, or taking care of it inside the SDK as you propose. Let me try to get back to you when I have more news on that.

gsaslis commented 6 years ago

@atsakiridis thanks for the feedback here!

In that case, do you think it's worth putting a small note at the docs, documenting this fact (and guiding ppl how to create this client)?

SlackingVeteran commented 6 years ago

I used retrofit with okhttp to call restcomm api with authorization. I can provide code snippet for that part if it helps, just let me know.

On Feb 5, 2018 11:57 AM, "Yorgos Saslis" notifications@github.com wrote:

@atsakiridis https://github.com/atsakiridis thanks for the feedback here!

In that case, do you think it's worth putting a small note at the docs, documenting this fact (and guiding ppl how to create this client)?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/RestComm/restcomm-android-sdk/issues/822#issuecomment-363147892, or mute the thread https://github.com/notifications/unsubscribe-auth/AFG8nt25FZpC-pRzyEhYjw59EneUO5k5ks5tRzMAgaJpZM4RoNWL .

atsakiridis commented 6 years ago

Sure @gsaslis let me open an issue for that. Thanks @suyashbhatt let me get back to you when I have more information

atsakiridis commented 6 years ago

Opened #846 for this

gsaslis commented 6 years ago

cool @atsakiridis - thanks!

@suyashbhatt any luck getting this off the ground in the meantime?

SlackingVeteran commented 6 years ago

I was successfully able to create new clients and authenticate within my android app. As I mentioned in my last comment I had to use retrofit to make post request and okhttp to create authentication token for retrofit.

gsaslis commented 6 years ago

great stuff @suyashbhatt !

In that case, could you perhaps share a code snippet here, for anyone else that stumbles across the same issue?

SlackingVeteran commented 6 years ago

Create retrofit interface:

import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Path;

public interface RetrofitService {
    @FormUrlEncoded
    @POST("Accounts/{accountSid}/Clients.json")
    Call<Object> createClient(@Path("accountSid") String accountSid, @Field("Login") String login, @Field("Password") String password);
}

Create new client from Activity:

// Register user to restcomm
OkHttpClient okHttpClient = new OkHttpClient().newBuilder().addInterceptor(new Interceptor() {
    @Override
    public okhttp3.Response intercept(Chain chain) throws IOException {
        Request originalRequest = chain.request();
        Request.Builder builder = originalRequest.newBuilder().header("Authorization", Credentials.basic("Replace with your Account Sid", "Replace with your Account API Secret"));

        Request newRequest = builder.build();
        return chain.proceed(newRequest);
    }
}).build();
Retrofit retrofit = new Retrofit.Builder()
        .baseUrl("http://your-ip-address:8443/restcomm/2012-04-24/")
        .addConverterFactory(GsonConverterFactory.create())
        .client(okHttpClient)
        .build();
mRetrofitService = retrofit.create(RetrofitService.class);
mRetrofitService.createClient("Replace with your Account Sid", "Replace with new client username", "Replace with new client password").enqueue(new Callback<Object>() {
    @Override public void onResponse(Call<Object> call, Response<Object> response) {
        Log.d(TAG, "onResponse: " + response.body().toString());
    }

    @Override public void onFailure(Call<Object> call, Throwable t) {
        Log.e(TAG, "onFailure: " + call, t);
    }
});
atsakiridis commented 6 years ago

Thanks for sharing @suyashbhatt, much appreciated!