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;
});
}));
}
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);
}
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));
}
Aggregations