use of com.voipgrid.vialer.api.Registration in project vialer-android by VoIPGRID.
the class FcmMessagingService method replyServer.
/**
* Notify the middleware server that we are, in fact, alive.
* @param responseUrl the URL of the server
* @param requestToken unique_key for middleware for recognising SIP connection status updates.
* @param messageStartTime
*/
private void replyServer(String responseUrl, String requestToken, String messageStartTime, boolean isAvailable) {
mRemoteLogger.d("replyServer");
Registration registrationApi = ServiceGenerator.createService(this, Registration.class, responseUrl);
Call<ResponseBody> call = registrationApi.reply(requestToken, isAvailable, messageStartTime);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
}
});
}
use of com.voipgrid.vialer.api.Registration in project vialer-android by VoIPGRID.
the class MiddlewareHelper method register.
public static void register(final Context context, String token) {
Preferences sipPreferences = new Preferences(context);
Tracker analyticsTracker = ((AnalyticsApplication) context.getApplicationContext()).getDefaultTracker();
final AnalyticsHelper analyticsHelper = new AnalyticsHelper(analyticsTracker);
if (!sipPreferences.canUseSip()) {
return;
}
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = preferences.edit();
editor.putLong(LAST_REGISTRATION, System.currentTimeMillis());
JsonStorage jsonStorage = new JsonStorage(context);
AccountHelper accountHelper = new AccountHelper(context);
if (!jsonStorage.has(PhoneAccount.class)) {
return;
}
Registration api = ServiceGenerator.createService(context, Registration.class, getBaseApiUrl(context), accountHelper.getEmail(), accountHelper.getPassword());
String sipUserId = ((PhoneAccount) jsonStorage.get(PhoneAccount.class)).getAccountId();
String fullName = ((SystemUser) jsonStorage.get(SystemUser.class)).getFullName();
String appName = context.getPackageName();
Call<ResponseBody> call = api.register(fullName, token, sipUserId, Build.VERSION.CODENAME, Build.VERSION.RELEASE, appName);
editor.putString(CURRENT_TOKEN, token);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.isSuccessful()) {
setRegistrationStatus(context, STATUS_REGISTERED);
} else {
setRegistrationStatus(context, STATUS_FAILED);
analyticsHelper.sendException(context.getString(R.string.analytics_event_description_registration_failed));
}
editor.apply();
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
t.printStackTrace();
setRegistrationStatus(context, STATUS_FAILED);
}
});
}
use of com.voipgrid.vialer.api.Registration in project vialer-android by VoIPGRID.
the class MiddlewareHelper method unregister.
/**
* Function to synchronously unregister at the middleware if a phone account and
* token are present.
* @param context
*/
public static void unregister(final Context context) {
final RemoteLogger remoteLogger = new RemoteLogger(MiddlewareHelper.class).enableConsoleLogging();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String token = preferences.getString(CURRENT_TOKEN, "");
// Check if we have a phone account and a push token.
if (new Preferences(context).hasPhoneAccount() && !token.equals("")) {
JsonStorage jsonStorage = new JsonStorage(context);
AccountHelper accountHelper = new AccountHelper(context);
Registration api = ServiceGenerator.createService(context, Registration.class, getBaseApiUrl(context), accountHelper.getEmail(), accountHelper.getPassword());
String sipUserId = ((PhoneAccount) jsonStorage.get(PhoneAccount.class)).getAccountId();
String appName = context.getPackageName();
Call<ResponseBody> call = api.unregister(token, sipUserId, appName);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (response.isSuccessful()) {
remoteLogger.d("unregister successful");
setRegistrationStatus(context, STATUS_UNREGISTERED);
} else {
remoteLogger.d("unregister failed");
setRegistrationStatus(context, STATUS_FAILED);
}
}
@Override
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
remoteLogger.d("unregister failed");
setRegistrationStatus(context, STATUS_FAILED);
}
});
} else {
remoteLogger.d("No token or phone account so unregister");
setRegistrationStatus(context, STATUS_FAILED);
}
}
use of com.voipgrid.vialer.api.Registration in project vialer-android by VoIPGRID.
the class SipConfig method respondToMiddleware.
/**
* Response to the middleware on a incoming call to notify asterisk we are ready to accept
* calls.
*/
private void respondToMiddleware() {
Intent incomingCallDetails = mSipService.getIncomingCallDetails();
if (incomingCallDetails == null) {
mRemoteLogger.w("Trying to respond to middleware with no details");
return;
}
String url = incomingCallDetails.getStringExtra(SipConstants.EXTRA_RESPONSE_URL);
String messageStartTime = incomingCallDetails.getStringExtra(FcmMessagingService.MESSAGE_START_TIME);
String token = incomingCallDetails.getStringExtra(SipConstants.EXTRA_REQUEST_TOKEN);
// Set responded as soon as possible to avoid duplicate requests due to multiple
// onAccountRegistered calls in a row.
mHasRespondedToMiddleware = true;
AnalyticsHelper analyticsHelper = new AnalyticsHelper(((AnalyticsApplication) mSipService.getApplication()).getDefaultTracker());
Registration registrationApi = ServiceGenerator.createService(mSipService, Registration.class, url);
String analyticsLabel = ConnectivityHelper.get(mSipService).getAnalyticsLabel();
// Accepted event.
analyticsHelper.sendEvent(mSipService.getString(R.string.analytics_event_category_middleware), mSipService.getString(R.string.analytics_event_action_middleware_accepted), analyticsLabel);
// To ms.
long startTime = (long) (Double.parseDouble(messageStartTime) * 1000);
long startUpTime = System.currentTimeMillis() - startTime;
// Response timing.
analyticsHelper.sendTiming(mSipService.getString(R.string.analytics_event_category_middleware), mSipService.getString(R.string.analytics_event_name_call_response), startUpTime);
retrofit2.Call<ResponseBody> call = registrationApi.reply(token, true, messageStartTime);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(@NonNull retrofit2.Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
if (!response.isSuccessful()) {
mRemoteLogger.w("Unsuccessful response to middleware: " + Integer.toString(response.code()));
mSipService.stopSelf();
}
}
@Override
public void onFailure(@NonNull retrofit2.Call<ResponseBody> call, @NonNull Throwable t) {
mRemoteLogger.w("Failed sending response to middleware");
mSipService.stopSelf();
}
});
}
Aggregations