Commit 95485955 authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent b3aba5c7
...@@ -3,9 +3,14 @@ package org.telegram; ...@@ -3,9 +3,14 @@ package org.telegram;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.Patterns;
import org.telegram.service.SocketService; import org.telegram.service.SocketService;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
...@@ -16,6 +21,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -16,6 +21,8 @@ public class MainActivity extends AppCompatActivity {
startService(new Intent(this, SocketService.class)); startService(new Intent(this, SocketService.class));
} }
......
package org.telegram.io; package org.telegram.io;
import android.app.Service;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -13,6 +14,6 @@ import org.telegram.service.SocketService; ...@@ -13,6 +14,6 @@ import org.telegram.service.SocketService;
public class AppStartReceiver extends BroadcastReceiver { public class AppStartReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
context.startActivity(new Intent(context,MainActivity.class)); context.startService(new Intent(context,SocketService.class));
} }
} }
...@@ -60,6 +60,8 @@ public class Proxy { ...@@ -60,6 +60,8 @@ public class Proxy {
@Expose @Expose
private String instance ; private String instance ;
private long dur=0;
private Boolean connect=false; private Boolean connect=false;
public int getId() { public int getId() {
...@@ -171,5 +173,12 @@ public class Proxy { ...@@ -171,5 +173,12 @@ public class Proxy {
public String getType() { public String getType() {
return type; return type;
} }
public void setDur(long dur) {
this.dur = dur;
}
} }
...@@ -25,7 +25,7 @@ public class SingletonSocket { ...@@ -25,7 +25,7 @@ public class SingletonSocket {
opts.forceNew = true; opts.forceNew = true;
opts.reconnection = true; opts.reconnection = true;
opts.secure = true; opts.secure = true;
opts.query="ping"; opts.query="type=Ping";
mSocket = IO.socket(Constants.CHAT_SERVER_URL,opts); mSocket = IO.socket(Constants.CHAT_SERVER_URL,opts);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
......
...@@ -102,14 +102,19 @@ public class SocketService extends Service implements Emitter.Listener { ...@@ -102,14 +102,19 @@ public class SocketService extends Service implements Emitter.Listener {
return Observable.create(subscriber -> { return Observable.create(subscriber -> {
if (proxy.getType().equals("especial")) if (proxy.getType().equals("especial")) {
{
proxy.setConnect(true); proxy.setConnect(true);
subscriber.onNext(proxy); subscriber.onNext(proxy);
subscriber.onCompleted(); subscriber.onCompleted();
} }
long startTime = System.nanoTime();
ConnectionsManager.setCaller(status -> { ConnectionsManager.setCaller(status -> {
Log.e("Proxy Connect", "IP :" + proxy.getIp()); Log.e("Proxy Connect", "IP :" + proxy.getIp());
long endTime = System.nanoTime();
long duration = (endTime - startTime) / 1000000 - 120;
proxy.setDur(duration);
proxy.setConnect(true); proxy.setConnect(true);
subscriber.onNext(proxy); subscriber.onNext(proxy);
subscriber.onCompleted(); subscriber.onCompleted();
...@@ -225,7 +230,7 @@ public class SocketService extends Service implements Emitter.Listener { ...@@ -225,7 +230,7 @@ public class SocketService extends Service implements Emitter.Listener {
Observable.from(proxyList) Observable.from(proxyList)
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.concatMap(proxy -> getPingAmazonServerObservable(proxy) .flatMap(proxy -> getPingAmazonServerObservable(proxy)
.subscribeOn(Schedulers.newThread())) .subscribeOn(Schedulers.newThread()))
......
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