Search in sources :

Example 1 with ServerInfo

use of chat.rocket.core.models.ServerInfo in project Rocket.Chat.Android by RocketChat.

the class RocketChatWebSocketThread method connectDDPClient.

private Single<Boolean> connectDDPClient() {
    return prepareDDPClient().flatMap(_val -> Single.fromEmitter(emitter -> {
        ServerInfo info = connectivityManager.getServerInfoForHost(hostname);
        RCLog.d("DDPClient#connect");
        ddpClient.connect(info.getSession(), info.isSecure()).onSuccessTask(task -> {
            final String newSession = task.getResult().session;
            connectivityManager.notifyConnectionEstablished(hostname, newSession);
            task.getResult().client.getOnCloseCallback().onSuccess(_task -> {
                if (listenersRegistered) {
                    terminate();
                }
                return null;
            });
            return realmHelper.executeTransaction(realm -> {
                RealmSession sessionObj = RealmSession.queryDefaultSession(realm).findFirst();
                if (sessionObj == null) {
                    realm.createOrUpdateObjectFromJson(RealmSession.class, new JSONObject().put(RealmSession.ID, RealmSession.DEFAULT_ID));
                } else {
                    if (!TextUtils.isEmpty(sessionObj.getToken()) && sessionObj.isTokenVerified()) {
                        sessionObj.setTokenVerified(false);
                        sessionObj.setError(null);
                    }
                }
                return null;
            });
        }).continueWith(task -> {
            if (task.isFaulted()) {
                emitter.onError(task.getError());
            } else {
                emitter.onSuccess(true);
            }
            return null;
        });
    }));
}
Also used : Context(android.content.Context) FileUploadingToUrlObserver(chat.rocket.android.service.observer.FileUploadingToUrlObserver) DDPClientWrapper(chat.rocket.android.api.DDPClientWrapper) Constructor(java.lang.reflect.Constructor) LogIfError(chat.rocket.android.helper.LogIfError) DebugLog(hugo.weaving.DebugLog) ArrayList(java.util.ArrayList) MethodCallHelper(chat.rocket.android.api.MethodCallHelper) MethodCallObserver(chat.rocket.android.service.observer.MethodCallObserver) NewMessageObserver(chat.rocket.android.service.observer.NewMessageObserver) Single(rx.Single) JSONObject(org.json.JSONObject) ServerInfo(chat.rocket.core.models.ServerInfo) LoginServiceConfigurationSubscriber(chat.rocket.android.service.ddp.base.LoginServiceConfigurationSubscriber) Handler(android.os.Handler) CurrentUserObserver(chat.rocket.android.service.observer.CurrentUserObserver) UserDataSubscriber(chat.rocket.android.service.ddp.base.UserDataSubscriber) Task(bolts.Task) TextUtils(chat.rocket.android.helper.TextUtils) SessionObserver(chat.rocket.android.service.observer.SessionObserver) Iterator(java.util.Iterator) RealmSession(chat.rocket.persistence.realm.models.internal.RealmSession) ActiveUsersSubscriber(chat.rocket.android.service.ddp.base.ActiveUsersSubscriber) RCLog(chat.rocket.android.log.RCLog) GcmPushRegistrationObserver(chat.rocket.android.service.observer.GcmPushRegistrationObserver) FileUploadingWithUfsObserver(chat.rocket.android.service.observer.FileUploadingWithUfsObserver) HandlerThread(android.os.HandlerThread) RealmHelper(chat.rocket.persistence.realm.RealmHelper) LoadMessageProcedureObserver(chat.rocket.android.service.observer.LoadMessageProcedureObserver) TokenLoginObserver(chat.rocket.android.service.observer.TokenLoginObserver) GetUsersOfRoomsProcedureObserver(chat.rocket.android.service.observer.GetUsersOfRoomsProcedureObserver) PushSettingsObserver(chat.rocket.android.service.observer.PushSettingsObserver) RealmStore(chat.rocket.persistence.realm.RealmStore) JSONObject(org.json.JSONObject) ServerInfo(chat.rocket.core.models.ServerInfo) RealmSession(chat.rocket.persistence.realm.models.internal.RealmSession)

Example 2 with ServerInfo

use of chat.rocket.core.models.ServerInfo in project Rocket.Chat.Android by RocketChat.

the class AbstractAuthedActivity method recoverFromHostnameError.

private void recoverFromHostnameError() {
    final List<ServerInfo> serverInfoList = ConnectivityManager.getInstance(getApplicationContext()).getServerList();
    if (serverInfoList == null || serverInfoList.size() == 0) {
        LaunchUtil.showAddServerActivity(this);
        return;
    }
    // just connect to the first available
    final ServerInfo serverInfo = serverInfoList.get(0);
    rocketChatCache.setSelectedServerHostname(serverInfo.getHostname());
    rocketChatCache.setSelectedRoomId(null);
}
Also used : ServerInfo(chat.rocket.core.models.ServerInfo)

Example 3 with ServerInfo

use of chat.rocket.core.models.ServerInfo in project Rocket.Chat.Android by RocketChat.

the class RocketChatApplication method onCreate.

@Override
public void onCreate() {
    if (BuildConfig.DEBUG) {
        enableStrictMode();
    }
    super.onCreate();
    RocketChatPersistenceRealm.init(this);
    List<ServerInfo> serverInfoList = ConnectivityManager.getInstance(this).getServerList();
    for (ServerInfo serverInfo : serverInfoList) {
        RealmStore.put(serverInfo.getHostname());
    }
    if (BuildConfig.DEBUG) {
        enableStetho();
    }
    RocketChatWidgets.initialize(this, OkHttpHelper.getClientForDownloadFile(this));
}
Also used : ServerInfo(chat.rocket.core.models.ServerInfo)

Aggregations

ServerInfo (chat.rocket.core.models.ServerInfo)3 Context (android.content.Context)1 Handler (android.os.Handler)1 HandlerThread (android.os.HandlerThread)1 Task (bolts.Task)1 DDPClientWrapper (chat.rocket.android.api.DDPClientWrapper)1 MethodCallHelper (chat.rocket.android.api.MethodCallHelper)1 LogIfError (chat.rocket.android.helper.LogIfError)1 TextUtils (chat.rocket.android.helper.TextUtils)1 RCLog (chat.rocket.android.log.RCLog)1 ActiveUsersSubscriber (chat.rocket.android.service.ddp.base.ActiveUsersSubscriber)1 LoginServiceConfigurationSubscriber (chat.rocket.android.service.ddp.base.LoginServiceConfigurationSubscriber)1 UserDataSubscriber (chat.rocket.android.service.ddp.base.UserDataSubscriber)1 CurrentUserObserver (chat.rocket.android.service.observer.CurrentUserObserver)1 FileUploadingToUrlObserver (chat.rocket.android.service.observer.FileUploadingToUrlObserver)1 FileUploadingWithUfsObserver (chat.rocket.android.service.observer.FileUploadingWithUfsObserver)1 GcmPushRegistrationObserver (chat.rocket.android.service.observer.GcmPushRegistrationObserver)1 GetUsersOfRoomsProcedureObserver (chat.rocket.android.service.observer.GetUsersOfRoomsProcedureObserver)1 LoadMessageProcedureObserver (chat.rocket.android.service.observer.LoadMessageProcedureObserver)1 MethodCallObserver (chat.rocket.android.service.observer.MethodCallObserver)1