Commit 95485955 authored by Ahmad Nemati's avatar Ahmad Nemati

init

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