Commit 2a383afd authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix checkstyle issues

parent 4e101ae7
......@@ -5,7 +5,7 @@ import android.content.Intent;
import chat.rocket.android.activity.ServerConfigActivity;
/**
* utility class for launching Activity
* utility class for launching Activity.
*/
public class LaunchUtil {
/**
......
......@@ -24,11 +24,11 @@ import jp.co.crowdworks.realm_java_helpers.RealmObjectObserver;
*/
public class ServerConfigActivity extends AbstractFragmentActivity {
private String mServerConfigId;
private RealmObjectObserver<ServerConfig> mServerConfigObserver =
private String serverConfigId;
private RealmObjectObserver<ServerConfig> serverConfigObserver =
new RealmObjectObserver<ServerConfig>() {
@Override protected RealmQuery<ServerConfig> query(Realm realm) {
return realm.where(ServerConfig.class).equalTo("id", mServerConfigId);
return realm.where(ServerConfig.class).equalTo("id", serverConfigId);
}
@Override protected void onChange(ServerConfig config) {
......@@ -93,8 +93,8 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
return;
}
mServerConfigId = intent.getStringExtra("id");
if (TextUtils.isEmpty(mServerConfigId)) {
serverConfigId = intent.getStringExtra("id");
if (TextUtils.isEmpty(serverConfigId)) {
finish();
return;
}
......@@ -105,11 +105,11 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
@Override protected void onResume() {
super.onResume();
RocketChatService.keepalive(this);
mServerConfigObserver.sub();
serverConfigObserver.sub();
}
@Override protected void onPause() {
mServerConfigObserver.unsub();
serverConfigObserver.unsub();
super.onPause();
}
......@@ -152,21 +152,21 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
}
@Override protected void showFragment(Fragment fragment) {
injectIdArgTo(fragment);
injectServerConfigIdArgTo(fragment);
super.showFragment(fragment);
}
@Override protected void showFragmentWithBackStack(Fragment fragment) {
injectIdArgTo(fragment);
injectServerConfigIdArgTo(fragment);
super.showFragmentWithBackStack(fragment);
}
private void injectIdArgTo(Fragment fragment) {
private void injectServerConfigIdArgTo(Fragment fragment) {
Bundle args = fragment.getArguments();
if (args == null) {
args = new Bundle();
}
args.putString("id", mServerConfigId);
args.putString("id", serverConfigId);
fragment.setArguments(args);
}
......
......@@ -12,18 +12,19 @@ import android.view.ViewGroup;
* Fragment base class for this Application.
*/
public abstract class AbstractFragment extends Fragment {
protected View mRootView;
protected View rootView;
protected abstract @LayoutRes int getLayout();
protected abstract void onSetupView();
@Nullable @Override
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
mRootView = inflater.inflate(getLayout(), container, false);
rootView = inflater.inflate(getLayout(), container, false);
onSetupView();
return mRootView;
return rootView;
}
protected void finish() {
......
......@@ -6,7 +6,7 @@ import chat.rocket.android.fragment.AbstractFragment;
import chat.rocket.android.helper.TextUtils;
abstract class AbstractServerConfigFragment extends AbstractFragment {
protected String mServerConfigId;
protected String serverConfigId;
@Override public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -17,8 +17,8 @@ abstract class AbstractServerConfigFragment extends AbstractFragment {
return;
}
mServerConfigId = args.getString("id");
if (TextUtils.isEmpty(mServerConfigId)) {
serverConfigId = args.getString("id");
if (TextUtils.isEmpty(serverConfigId)) {
finish();
return;
}
......
......@@ -18,14 +18,14 @@ import org.json.JSONObject;
* Input server host.
*/
public class InputHostnameFragment extends AbstractServerConfigFragment {
private Handler mShowError = new Handler() {
private Handler errorShowingHandler = new Handler() {
@Override public void handleMessage(Message msg) {
Toast.makeText(mRootView.getContext(), (String) msg.obj, Toast.LENGTH_SHORT).show();
Toast.makeText(rootView.getContext(), (String) msg.obj, Toast.LENGTH_SHORT).show();
}
};
RealmObjectObserver<ServerConfig> mObserver = new RealmObjectObserver<ServerConfig>() {
RealmObjectObserver<ServerConfig> serverConfigObserver = new RealmObjectObserver<ServerConfig>() {
@Override protected RealmQuery<ServerConfig> query(Realm realm) {
return realm.where(ServerConfig.class).equalTo("id", mServerConfigId);
return realm.where(ServerConfig.class).equalTo("id", serverConfigId);
}
@Override protected void onChange(ServerConfig config) {
......@@ -41,42 +41,42 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
}
@Override protected void onSetupView() {
mRootView.findViewById(R.id.btn_connect).setOnClickListener(view -> handleConnect());
rootView.findViewById(R.id.btn_connect).setOnClickListener(view -> handleConnect());
mObserver.sub();
serverConfigObserver.sub();
}
private void handleConnect() {
final TextView editor = (TextView) mRootView.findViewById(R.id.editor_hostname);
final TextView editor = (TextView) rootView.findViewById(R.id.editor_hostname);
final String hostname =
TextUtils.or(TextUtils.or(editor.getText(), editor.getHint()), "").toString();
RealmHelperBolts.executeTransaction(
realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class,
new JSONObject().put("id", mServerConfigId)
new JSONObject().put("id", serverConfigId)
.put("hostname", hostname)
.put("connectionError", JSONObject.NULL))).continueWith(new LogcatIfError());
}
@Override public void onResume() {
super.onResume();
mObserver.keepalive();
serverConfigObserver.keepalive();
}
@Override public void onDestroyView() {
mObserver.unsub();
serverConfigObserver.unsub();
super.onDestroyView();
}
private void showError(String errString) {
mShowError.removeMessages(0);
Message msg = Message.obtain(mShowError, 0, errString);
mShowError.sendMessageDelayed(msg, 160);
errorShowingHandler.removeMessages(0);
Message msg = Message.obtain(errorShowingHandler, 0, errString);
errorShowingHandler.sendMessageDelayed(msg, 160);
}
private void onRenderServerConfig(ServerConfig config) {
final TextView editor = (TextView) mRootView.findViewById(R.id.editor_hostname);
final TextView editor = (TextView) rootView.findViewById(R.id.editor_hostname);
if (!TextUtils.isEmpty(config.getHostname())) {
editor.setText(config.getHostname());
......@@ -90,7 +90,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
private void clearConnectionErrorAndHostname() {
RealmHelperBolts.executeTransaction(
realm -> realm.createOrUpdateObjectFromJson(ServerConfig.class,
new JSONObject().put("id", mServerConfigId)
new JSONObject().put("id", serverConfigId)
.put("hostname", JSONObject.NULL)
.put("connectionError", JSONObject.NULL))).continueWith(new LogcatIfError());
}
......
......@@ -19,7 +19,8 @@ public class TextUtils {
/**
* Returns str if it is not empty; otherwise defaultValue is returned.
*/
@SuppressWarnings("PMD.ShortMethodName") public static CharSequence or(CharSequence str,
@SuppressWarnings("PMD.ShortMethodName")
public static CharSequence or(CharSequence str,
CharSequence defaultValue) {
if (isEmpty(str)) {
return defaultValue;
......
......@@ -4,9 +4,10 @@ import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
/**
* subscription model for "meteor_accounts_loginServiceConfiguration"
* subscription model for "meteor_accounts_loginServiceConfiguration".
*/
@SuppressWarnings("PMD.ShortVariable") public class MeteorLoginServiceConfiguration
@SuppressWarnings("PMD.ShortVariable")
public class MeteorLoginServiceConfiguration
extends RealmObject {
@PrimaryKey private String id;
private String service;
......
......@@ -12,9 +12,10 @@ import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts;
import org.json.JSONObject;
/**
* Server configuration
* Server configuration.
*/
@SuppressWarnings("PMD.ShortVariable") public class ServerConfig extends RealmObject {
@SuppressWarnings("PMD.ShortVariable")
public class ServerConfig extends RealmObject {
@PrimaryKey private String id;
private String hostname;
private String connectionError;
......
package chat.rocket.android.service;
/**
* interface for observer and ddp_subscription
* interface for observer and ddp_subscription.
*/
public interface Registerable {
/**
* register
* register.
*/
void register();
/**
* keepalive
* keepalive.
*/
void keepalive();
/**
* unregister
* unregister.
*/
void unregister();
}
......@@ -20,8 +20,8 @@ import jp.co.crowdworks.realm_java_helpers.RealmListObserver;
*/
public class RocketChatService extends Service {
private HashMap<String, RocketChatWebSocketThread> mWebSocketThreads;
private RealmListObserver<ServerConfig> mConnectionRequiredServerConfigObserver =
private HashMap<String, RocketChatWebSocketThread> webSocketThreads;
private RealmListObserver<ServerConfig> connectionRequiredServerConfigObserver =
new RealmListObserver<ServerConfig>() {
@Override protected RealmResults<ServerConfig> queryItems(Realm realm) {
return realm.where(ServerConfig.class)
......@@ -51,17 +51,17 @@ public class RocketChatService extends Service {
@Override public void onCreate() {
super.onCreate();
mWebSocketThreads = new HashMap<>();
webSocketThreads = new HashMap<>();
}
@Override public int onStartCommand(Intent intent, int flags, int startId) {
mConnectionRequiredServerConfigObserver.keepalive();
connectionRequiredServerConfigObserver.keepalive();
return START_STICKY;
}
private void syncWebSocketThreadsWith(List<ServerConfig> configList) {
final Iterator<Map.Entry<String, RocketChatWebSocketThread>> iterator =
mWebSocketThreads.entrySet().iterator();
webSocketThreads.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, RocketChatWebSocketThread> entry = iterator.next();
......@@ -90,18 +90,20 @@ public class RocketChatService extends Service {
private Task<RocketChatWebSocketThread> findOrCreateWebSocketThread(final ServerConfig config) {
final String serverConfigId = config.getId();
if (mWebSocketThreads.containsKey(serverConfigId)) {
return Task.forResult(mWebSocketThreads.get(serverConfigId));
if (webSocketThreads.containsKey(serverConfigId)) {
return Task.forResult(webSocketThreads.get(serverConfigId));
} else {
return RocketChatWebSocketThread.getStarted(getApplicationContext(), config)
.onSuccessTask(task -> {
mWebSocketThreads.put(serverConfigId, task.getResult());
webSocketThreads.put(serverConfigId, task.getResult());
return task;
});
}
}
@Nullable @Override public IBinder onBind(Intent intent) {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
......@@ -24,17 +24,17 @@ public class RocketChatWebSocketThread extends HandlerThread {
private static final Class[] REGISTERABLE_CLASSES = {
LoginServiceConfigurationSubscriber.class
};
private final Context mAppContext;
private final String mServerConfigId;
private final ArrayList<Registerable> mListeners = new ArrayList<>();
private RocketChatWebSocketAPI mWebSocketAPI;
private boolean mSocketExists;
private boolean mListenersRegistered;
private final Context appContext;
private final String serverConfigId;
private final ArrayList<Registerable> listeners = new ArrayList<>();
private RocketChatWebSocketAPI webSocketAPI;
private boolean socketExists;
private boolean listenersRegistered;
private RocketChatWebSocketThread(Context appContext, String serverConfigId) {
super("RC_thread_" + serverConfigId);
mServerConfigId = serverConfigId;
mAppContext = appContext;
this.serverConfigId = serverConfigId;
this.appContext = appContext;
}
/**
......@@ -57,14 +57,14 @@ public class RocketChatWebSocketThread extends HandlerThread {
}
/**
* terminate the thread
* terminate the thread.
*/
@DebugLog public static void terminate(RocketChatWebSocketThread thread) {
thread.quit();
}
private Task<Void> ensureConnection() {
if (mWebSocketAPI == null || !mWebSocketAPI.isConnected()) {
if (webSocketAPI == null || !webSocketAPI.isConnected()) {
return registerListeners();
} else {
return Task.forResult(null);
......@@ -113,21 +113,21 @@ public class RocketChatWebSocketThread extends HandlerThread {
private void prepareWebSocket() {
ServerConfig config = RealmHelper.executeTransactionForRead(
realm -> realm.where(ServerConfig.class).equalTo("id", mServerConfigId).findFirst());
realm -> realm.where(ServerConfig.class).equalTo("id", serverConfigId).findFirst());
if (mWebSocketAPI == null || !mWebSocketAPI.isConnected()) {
mWebSocketAPI = RocketChatWebSocketAPI.create(config.getHostname());
if (webSocketAPI == null || !webSocketAPI.isConnected()) {
webSocketAPI = RocketChatWebSocketAPI.create(config.getHostname());
}
}
@DebugLog private Task<Void> registerListeners() {
if (mSocketExists) {
if (socketExists) {
return Task.forResult(null);
}
mSocketExists = true;
socketExists = true;
prepareWebSocket();
return mWebSocketAPI.connect().onSuccess(task -> {
return webSocketAPI.connect().onSuccess(task -> {
registerListenersActually();
DDPClient client = task.getResult().client;
......@@ -146,7 +146,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
return null;
}).continueWith(task -> {
if (task.isFaulted()) {
ServerConfig.logError(mServerConfigId, task.getError());
ServerConfig.logError(serverConfigId, task.getError());
}
return null;
});
......@@ -154,20 +154,20 @@ public class RocketChatWebSocketThread extends HandlerThread {
//@DebugLog
private void registerListenersActually() {
if (mListenersRegistered) {
if (listenersRegistered) {
return;
}
mListenersRegistered = true;
listenersRegistered = true;
for (Class clazz : REGISTERABLE_CLASSES) {
try {
Constructor ctor = clazz.getConstructor(Context.class, RocketChatWebSocketAPI.class);
Object obj = ctor.newInstance(mAppContext, mWebSocketAPI);
Object obj = ctor.newInstance(appContext, webSocketAPI);
if (obj instanceof Registerable) {
Registerable registerable = (Registerable) obj;
registerable.register();
mListeners.add(registerable);
listeners.add(registerable);
}
} catch (Exception exception) {
Timber.w(exception, "Failed to register listeners!!");
......@@ -177,32 +177,32 @@ public class RocketChatWebSocketThread extends HandlerThread {
//@DebugLog
private void keepaliveListeners() {
if (!mSocketExists || !mListenersRegistered) {
if (!socketExists || !listenersRegistered) {
return;
}
for (Registerable registerable : mListeners) {
for (Registerable registerable : listeners) {
registerable.keepalive();
}
}
//@DebugLog
private void unregisterListeners() {
if (!mSocketExists || !mListenersRegistered) {
if (!socketExists || !listenersRegistered) {
return;
}
Iterator<Registerable> iterator = mListeners.iterator();
Iterator<Registerable> iterator = listeners.iterator();
while (iterator.hasNext()) {
Registerable registerable = iterator.next();
registerable.unregister();
iterator.remove();
}
if (mWebSocketAPI != null) {
mWebSocketAPI.close();
mWebSocketAPI = null;
if (webSocketAPI != null) {
webSocketAPI.close();
webSocketAPI = null;
}
mListenersRegistered = false;
mSocketExists = false;
listenersRegistered = false;
socketExists = false;
}
}
......@@ -16,14 +16,14 @@ import rx.Subscription;
import timber.log.Timber;
abstract class AbstractDDPDocEventSubscriber implements Registerable {
protected final Context mContext;
protected final RocketChatWebSocketAPI mAPI;
private String mID;
private Subscription mSubscription;
protected final Context context;
protected final RocketChatWebSocketAPI webSocketAPI;
private String subscriptionId;
private Subscription rxSubscription;
protected AbstractDDPDocEventSubscriber(Context context, RocketChatWebSocketAPI api) {
mContext = context;
mAPI = api;
this.context = context;
this.webSocketAPI = api;
}
protected abstract String getSubscriptionName();
......@@ -32,13 +32,13 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
protected abstract Class<? extends RealmObject> getModelClass();
protected JSONObject customizeFieldJSON(JSONObject json) {
protected JSONObject customizeFieldJson(JSONObject json) {
return json;
}
@Override public void register() {
mAPI.subscribe(getSubscriptionName(), null).onSuccess(task -> {
mID = task.getResult().id;
webSocketAPI.subscribe(getSubscriptionName(), null).onSuccess(task -> {
subscriptionId = task.getResult().id;
return null;
}).continueWith(task -> {
if (task.isFaulted()) {
......@@ -57,7 +57,7 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
}
private void registerSubscriptionCallback() {
mSubscription = mAPI.getSubscriptionCallback()
rxSubscription = webSocketAPI.getSubscriptionCallback()
.filter(event -> event instanceof DDPSubscription.DocEvent)
.cast(DDPSubscription.DocEvent.class)
.filter(event -> getSubscriptionCallbackName().equals(event.collection))
......@@ -74,8 +74,8 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
} else if (docEvent instanceof DDPSubscription.MovedBefore) {
//ignore movedBefore
}
} catch (Exception e) {
Timber.w(e, "failed to handle subscription callback");
} catch (Exception exception) {
Timber.w(exception, "failed to handle subscription callback");
}
});
}
......@@ -87,35 +87,20 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
}).continueWith(new LogcatIfError());
}
protected void onDocumentChanged(DDPSubscription.Changed docEvent) {
RealmHelperBolts.executeTransaction(realm -> {
onDocumentChanged(realm, docEvent);
return null;
}).continueWith(new LogcatIfError());
private void onDocumentAdded(Realm realm, DDPSubscription.Added docEvent) throws JSONException {
//executed in RealmTransaction
JSONObject json = new JSONObject().put("id", docEvent.docID);
mergeJson(json, docEvent.fields);
realm.createOrUpdateObjectFromJson(getModelClass(), customizeFieldJson(json));
}
protected void onDocumentRemoved(DDPSubscription.Removed docEvent) {
protected void onDocumentChanged(DDPSubscription.Changed docEvent) {
RealmHelperBolts.executeTransaction(realm -> {
onDocumentRemoved(realm, docEvent);
onDocumentChanged(realm, docEvent);
return null;
}).continueWith(new LogcatIfError());
}
private void mergeJSON(JSONObject target, JSONObject src) throws JSONException {
Iterator<String> iterator = src.keys();
while (iterator.hasNext()) {
String key = iterator.next();
target.put(key, src.get(key));
}
}
private void onDocumentAdded(Realm realm, DDPSubscription.Added docEvent) throws JSONException {
//executed in RealmTransaction
JSONObject json = new JSONObject().put("id", docEvent.docID);
mergeJSON(json, docEvent.fields);
realm.createOrUpdateObjectFromJson(getModelClass(), customizeFieldJSON(json));
}
private void onDocumentChanged(Realm realm, DDPSubscription.Changed docEvent)
throws JSONException {
//executed in RealmTransaction
......@@ -124,8 +109,15 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
String fieldToDelete = docEvent.cleared.getString(i);
json.remove(fieldToDelete);
}
mergeJSON(json, docEvent.fields);
realm.createOrUpdateObjectFromJson(getModelClass(), customizeFieldJSON(json));
mergeJson(json, docEvent.fields);
realm.createOrUpdateObjectFromJson(getModelClass(), customizeFieldJson(json));
}
protected void onDocumentRemoved(DDPSubscription.Removed docEvent) {
RealmHelperBolts.executeTransaction(realm -> {
onDocumentRemoved(realm, docEvent);
return null;
}).continueWith(new LogcatIfError());
}
private void onDocumentRemoved(Realm realm, DDPSubscription.Removed docEvent)
......@@ -134,16 +126,24 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
realm.where(getModelClass()).equalTo("id", docEvent.docID).findAll().deleteAllFromRealm();
}
private void mergeJson(JSONObject target, JSONObject src) throws JSONException {
Iterator<String> iterator = src.keys();
while (iterator.hasNext()) {
String key = iterator.next();
target.put(key, src.get(key));
}
}
@Override public void keepalive() {
}
@Override public void unregister() {
if (mSubscription != null) {
mSubscription.unsubscribe();
if (rxSubscription != null) {
rxSubscription.unsubscribe();
}
if (!TextUtils.isEmpty(mID)) {
mAPI.unsubscribe(mID).continueWith(new LogcatIfError());
if (!TextUtils.isEmpty(subscriptionId)) {
webSocketAPI.unsubscribe(subscriptionId).continueWith(new LogcatIfError());
}
}
}
......@@ -9,12 +9,12 @@ import jp.co.crowdworks.realm_java_helpers.RealmListObserver;
abstract class AbstractModelObserver<T extends RealmObject> extends RealmListObserver<T>
implements Registerable {
protected final Context mContext;
protected final RocketChatWebSocketAPI mAPI;
protected final Context context;
protected final RocketChatWebSocketAPI webSocketAPI;
protected AbstractModelObserver(Context context, RocketChatWebSocketAPI api) {
mContext = context;
mAPI = api;
this.context = context;
webSocketAPI = api;
}
@Override public void register() {
......
......@@ -4,7 +4,7 @@ import android.content.Context;
import android.util.AttributeSet;
/**
* TextView with font-awesome
* TextView with font-awesome.
*/
public class FontAwesomeTextView extends AbstractCustomFontTextView {
public FontAwesomeTextView(Context context, AttributeSet attrs, int defStyle) {
......
......@@ -4,7 +4,7 @@ import android.content.Context;
import android.util.AttributeSet;
/**
* TextView with fontello
* TextView with fontello.
*/
public class FontelloTextView extends AbstractCustomFontTextView {
public FontelloTextView(Context context, AttributeSet attrs, int defStyle) {
......
......@@ -18,7 +18,7 @@ import java.util.ArrayList;
* View for indicating "waiting for connection ..." and so on.
*/
public class WaitingView extends LinearLayout {
private ArrayList<View> mDots;
private ArrayList<View> dots;
public WaitingView(Context context) {
super(context);
......@@ -53,7 +53,7 @@ public class WaitingView extends LinearLayout {
array.recycle();
}
mDots = new ArrayList<>();
dots = new ArrayList<>();
setOrientation(HORIZONTAL);
for (int i = 0; i < count; i++) {
addDot(context, size);
......@@ -78,12 +78,12 @@ public class WaitingView extends LinearLayout {
dot.setLayoutParams(new FrameLayout.LayoutParams(size, size, Gravity.CENTER));
frameLayout.addView(dot);
addView(frameLayout);
mDots.add(dot);
dots.add(dot);
}
private void start() {
for (int i = 0; i < mDots.size(); i++) {
animateDot(mDots.get(i), 160 * i, 480, 480);
for (int i = 0; i < dots.size(); i++) {
animateDot(dots.get(i), 160 * i, 480, 480);
}
}
......@@ -111,7 +111,7 @@ public class WaitingView extends LinearLayout {
}
private void cancel() {
for (View dot : mDots) {
for (View dot : dots) {
dot.clearAnimation();
}
}
......
......@@ -13,12 +13,12 @@ import rx.Observable;
* API for several POST actions.
*/
public class RocketChatWebSocketAPI {
private final DDPClient mDDPClient;
private final String mHostName;
private final DDPClient ddpClient;
private final String hostname;
private RocketChatWebSocketAPI(String hostname) {
mDDPClient = new DDPClient(OkHttpHelper.getClientForWebSocket());
mHostName = hostname;
ddpClient = new DDPClient(OkHttpHelper.getClientForWebSocket());
this.hostname = hostname;
}
/**
......@@ -32,41 +32,41 @@ public class RocketChatWebSocketAPI {
* Connect to WebSocket server with DDP client.
*/
public Task<DDPClientCallback.Connect> connect() {
return mDDPClient.connect("wss://" + mHostName + "/websocket");
return ddpClient.connect("wss://" + hostname + "/websocket");
}
/**
* Returns whether DDP client is connected to WebSocket server.
*/
public boolean isConnected() {
return mDDPClient.isConnected();
return ddpClient.isConnected();
}
/**
* close connection.
*/
public void close() {
mDDPClient.close();
ddpClient.close();
}
/**
* Subscribe with DDP client.
*/
public Task<DDPSubscription.Ready> subscribe(final String name, JSONArray param) {
return mDDPClient.sub(UUID.randomUUID().toString(), name, param);
return ddpClient.sub(UUID.randomUUID().toString(), name, param);
}
/**
* Unsubscribe with DDP client.
*/
public Task<DDPSubscription.NoSub> unsubscribe(final String subscriptionId) {
return mDDPClient.unsub(subscriptionId);
return ddpClient.unsub(subscriptionId);
}
/**
* Returns Observable for handling DDP subscription.
*/
public Observable<DDPSubscription.Event> getSubscriptionCallback() {
return mDDPClient.getSubscriptionCallback();
return ddpClient.getSubscriptionCallback();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment