Open
Description
After disconnecting socket, it keeps listening and runs call(Object... args).
For connection:
Global.socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
if(Global.socket != null && Global.socket.connected()){
Global.socket.emit("deviceTokens", jsonObject);
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
Log.i("response", "connected at " + currentDateTimeString);
}
}
}).on("refresh", new Emitter.Listener() {
@Override
public void call(Object... args) {
if(Global.socket != null && Global.socket.connected()){
Global.socket.emit("deviceTokens", jsonObject);
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
Log.i("response", "refreshed at " + currentDateTimeString);
Intent intent = new Intent(context.getApplicationContext(), FirstRunActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("refresh", "server");
Util.deleteExistingFile(context);
ShopManager.getInstance().unregisterAds(context);
Activity act = (Activity) context;
act.startActivity(intent);
act.finish();
}
}
}).on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
Log.i("response", "disconnected at " + currentDateTimeString);
Global.socket = null;
}
});
Global.socket.connect();
For disconnection:
if (Global.socket != null) {
Global.socket.disconnect();
}
Btw, I am using io.socket:socket.io-client:1.0.0.