mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-12-26 13:38:59 +00:00
Can get calls configuration
This commit is contained in:
parent
d73152dab6
commit
0a8ecf3fdf
@ -0,0 +1,112 @@
|
||||
package org.communiquons.android.comunic.client.data.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.communiquons.android.comunic.client.data.models.APIRequest;
|
||||
import org.communiquons.android.comunic.client.data.models.APIResponse;
|
||||
import org.communiquons.android.comunic.client.data.models.CallsConfiguration;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Calls helper
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class CallsHelper extends BaseHelper {
|
||||
|
||||
/**
|
||||
* Debug tag
|
||||
*/
|
||||
private static final String TAG = CallsHelper.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* We consider that it is not required to get call configuration twice on single
|
||||
* application lifetime
|
||||
*/
|
||||
private static CallsConfiguration mCallsConfiguration = null;
|
||||
|
||||
public CallsHelper(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get call configuration if required
|
||||
*/
|
||||
public void getCallConfigurationIfRequired(){
|
||||
|
||||
//If call configuration has already been retrieved, nothing to be done
|
||||
if(mCallsConfiguration != null)
|
||||
return;
|
||||
|
||||
APIRequest request = new APIRequest(getContext(), "calls/config");
|
||||
|
||||
try {
|
||||
|
||||
//Execute request
|
||||
APIResponse response = request.exec();
|
||||
|
||||
//Parse response
|
||||
mCallsConfiguration = JSONObjectToCallConfiguration(response.getJSONObject());
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Calls configuration, if available
|
||||
*
|
||||
* @return Calls configuration
|
||||
*/
|
||||
@Nullable
|
||||
public static CallsConfiguration getCallConfiguration(){
|
||||
return mCallsConfiguration;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checkout whether call system is currently available now or not.
|
||||
*
|
||||
* Notice : this value may return false even if call system is enabled, based
|
||||
* on the fact that call configuration may have not been already retrieved
|
||||
*
|
||||
* @return TRUE if call system is available / FALSE else
|
||||
*/
|
||||
public static boolean isCallSystemAvailable(){
|
||||
return mCallsConfiguration != null && mCallsConfiguration.isEnabled();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Turn a {@link JSONObject} object into a {@link CallsConfiguration} object.
|
||||
*
|
||||
* @param object Object to convert
|
||||
* @return The result of the operation
|
||||
* @throws JSONException Exception thrown in case of failure
|
||||
*/
|
||||
private static CallsConfiguration JSONObjectToCallConfiguration(JSONObject object)
|
||||
throws JSONException {
|
||||
|
||||
CallsConfiguration config = new CallsConfiguration();
|
||||
config.setEnabled(object.getBoolean("enabled"));
|
||||
|
||||
//Get further information only if required
|
||||
if(config.isEnabled()){
|
||||
config.setMaximumNumberMembers(object.getInt("maximum_number_members"));
|
||||
config.setSignalServerName(object.getString("signal_server_name"));
|
||||
config.setSignalServerPort(object.getInt("signal_server_port"));
|
||||
config.setSignalServerSecure(object.getBoolean("is_signal_server_secure"));
|
||||
config.setStunServer(object.getString("stun_server"));
|
||||
config.setTurnServer(object.getString("turn_server"));
|
||||
config.setTurnUsername(object.getString("turn_username"));
|
||||
config.setTurnPassword(object.getString("turn_password"));
|
||||
}
|
||||
|
||||
return config;
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package org.communiquons.android.comunic.client.data.models;
|
||||
|
||||
/**
|
||||
* Calls configuration object
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class CallsConfiguration {
|
||||
|
||||
//Private fields
|
||||
private boolean enabled;
|
||||
private int maximumNumberMembers;
|
||||
private String signalServerName;
|
||||
private int signalServerPort;
|
||||
private boolean isSignalSererSecure;
|
||||
private String stunServer;
|
||||
private String turnServer;
|
||||
private String turnUsername;
|
||||
private String turnPassword;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public int getMaximumNumberMembers() {
|
||||
return maximumNumberMembers;
|
||||
}
|
||||
|
||||
public void setMaximumNumberMembers(int maximum_number_members) {
|
||||
this.maximumNumberMembers = maximum_number_members;
|
||||
}
|
||||
|
||||
public String getSignalServerName() {
|
||||
return signalServerName;
|
||||
}
|
||||
|
||||
public void setSignalServerName(String signalServerName) {
|
||||
this.signalServerName = signalServerName;
|
||||
}
|
||||
|
||||
public int getSignalServerPort() {
|
||||
return signalServerPort;
|
||||
}
|
||||
|
||||
public void setSignalServerPort(int signalServerPort) {
|
||||
this.signalServerPort = signalServerPort;
|
||||
}
|
||||
|
||||
public boolean isSignalSererSecure() {
|
||||
return isSignalSererSecure;
|
||||
}
|
||||
|
||||
public void setSignalServerSecure(boolean signalSererSecure) {
|
||||
this.isSignalSererSecure = signalSererSecure;
|
||||
}
|
||||
|
||||
public String getStunServer() {
|
||||
return stunServer;
|
||||
}
|
||||
|
||||
public void setStunServer(String stunServer) {
|
||||
this.stunServer = stunServer;
|
||||
}
|
||||
|
||||
public String getTurnServer() {
|
||||
return turnServer;
|
||||
}
|
||||
|
||||
public void setTurnServer(String turnServer) {
|
||||
this.turnServer = turnServer;
|
||||
}
|
||||
|
||||
public String getTurnUsername() {
|
||||
return turnUsername;
|
||||
}
|
||||
|
||||
public void setTurnUsername(String turnUsername) {
|
||||
this.turnUsername = turnUsername;
|
||||
}
|
||||
|
||||
public String getTurnPassword() {
|
||||
return turnPassword;
|
||||
}
|
||||
|
||||
public void setTurnPassword(String turnPassword) {
|
||||
this.turnPassword = turnPassword;
|
||||
}
|
||||
}
|
@ -37,6 +37,7 @@ import org.communiquons.android.comunic.client.data.runnables.FriendRefreshLoopR
|
||||
import org.communiquons.android.comunic.client.data.services.NotificationsService;
|
||||
import org.communiquons.android.comunic.client.data.utils.PreferencesUtils;
|
||||
import org.communiquons.android.comunic.client.ui.asynctasks.FindVirtualDirectoryTask;
|
||||
import org.communiquons.android.comunic.client.ui.asynctasks.GetCallConfigurationTask;
|
||||
import org.communiquons.android.comunic.client.ui.asynctasks.SafeAsyncTask;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.ConversationFragment;
|
||||
import org.communiquons.android.comunic.client.ui.fragments.ConversationsListFragment;
|
||||
@ -181,6 +182,11 @@ public class MainActivity extends BaseActivity implements
|
||||
//Receive broadcasts
|
||||
IntentFilter intentFilter = new IntentFilter(NotificationsService.BROADCAST_ACTION);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter);
|
||||
|
||||
//Get calls configuration
|
||||
GetCallConfigurationTask callConfigurationTask = new GetCallConfigurationTask(this);
|
||||
callConfigurationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
getTasksManager().addTask(callConfigurationTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,25 @@
|
||||
package org.communiquons.android.comunic.client.ui.asynctasks;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.communiquons.android.comunic.client.data.helpers.CallsHelper;
|
||||
|
||||
/**
|
||||
* Get call configuration task
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
public class GetCallConfigurationTask extends SafeAsyncTask<Void, Void, Void> {
|
||||
|
||||
public GetCallConfigurationTask(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void[] objects) {
|
||||
|
||||
new CallsHelper(getContext()).getCallConfigurationIfRequired();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user