mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-07 14:18:25 +00:00
add stun client to UserInstance tester
git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@154 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
This commit is contained in:
parent
2fd672efbe
commit
78f9d28125
3 changed files with 29 additions and 3 deletions
|
|
@ -476,6 +476,7 @@ public static String lookupSipProxyUri(String aDomaine) {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] lookupSipProxiesUri(String aDomaine) {
|
||||
try {
|
||||
isReady();
|
||||
|
|
@ -485,6 +486,15 @@ public static String[] lookupSipProxiesUri(String aDomaine) {
|
|||
}
|
||||
}
|
||||
|
||||
public static String[] lookupMediaServerAddress(String aDomaine) {
|
||||
try {
|
||||
isReady();
|
||||
return mP2pProxyManagement.getMediaServerList();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static int getState() {
|
||||
try {
|
||||
isReady();
|
||||
|
|
|
|||
|
|
@ -51,6 +51,15 @@ public class StunClient {
|
|||
|
||||
private int SO_TIME_OUT = 300;
|
||||
|
||||
public StunClient(String[] aStunServerList) {
|
||||
List<InetSocketAddress> lAddressList = new ArrayList<InetSocketAddress>();
|
||||
for (String lStunInstance:aStunServerList) {
|
||||
URI lUri = URI.create(lStunInstance);
|
||||
InetSocketAddress lInetSocketAddress = new InetSocketAddress(lUri.getHost(),lUri.getPort());
|
||||
lAddressList.add(lInetSocketAddress);
|
||||
}
|
||||
mStunServerList = lAddressList;
|
||||
}
|
||||
StunClient(List<InetSocketAddress> aStunServerList) {
|
||||
mStunServerList = aStunServerList;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.apache.log4j.Logger;
|
|||
import org.linphone.p2pproxy.api.P2pProxyException;
|
||||
import org.linphone.p2pproxy.api.P2pProxyResourceManagement;
|
||||
import org.linphone.p2pproxy.core.P2pProxyMain;
|
||||
import org.linphone.p2pproxy.core.stun.StunClient;
|
||||
import org.linphone.p2pproxy.launcher.P2pProxylauncherConstants;
|
||||
import org.zoolu.net.SocketAddress;
|
||||
import org.zoolu.sip.provider.SipProvider;
|
||||
|
|
@ -41,6 +42,7 @@ private final Thread mFonisThread;
|
|||
private Timer mTimer = new Timer("Registartion timer");
|
||||
private final SipProvider mProvider;
|
||||
private final SipClient mSipClient;
|
||||
private StunClient mStunClient;
|
||||
private final int REGISTRATION_PERIOD=60;
|
||||
private final static Logger mLog = Logger.getLogger(UserInstance.class);
|
||||
private static boolean mIsRegistered = false;
|
||||
|
|
@ -79,6 +81,7 @@ public UserInstance(final String userName,final String aPreferedProxyUri) throws
|
|||
//InetAddress[] lAddresses = InetAddress.getAllByName("localhost");
|
||||
mProvider=new SipProvider(null,lSipPort);
|
||||
mSipClient = new SipClient(mProvider,userName,30000);
|
||||
|
||||
class RegistrarTimerTask extends TimerTask {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
@ -102,6 +105,10 @@ public UserInstance(final String userName,final String aPreferedProxyUri) throws
|
|||
//2 setOutbound proxy
|
||||
mProvider.setOutboundProxy(new SocketAddress(lProxyUri.getRawSchemeSpecificPart()));
|
||||
mLog.info("use outband proxy ["+mProvider.getOutboundProxy()+"]");
|
||||
//3 setup stun client
|
||||
|
||||
String [] lMediaServer = P2pProxyMain.lookupMediaServerAddress(P2pProxyResourceManagement.DOMAINE);
|
||||
mStunClient = new StunClient(lMediaServer);
|
||||
mSipClient.register(REGISTRATION_PERIOD,userName);
|
||||
mIsRegistered = true;
|
||||
} catch(Exception e) {
|
||||
|
|
@ -112,7 +119,7 @@ public UserInstance(final String userName,final String aPreferedProxyUri) throws
|
|||
}
|
||||
|
||||
};
|
||||
mTimer.schedule(new RegistrarTimerTask(), REGISTRATION_PERIOD-REGISTRATION_PERIOD/10);
|
||||
mTimer.schedule(new RegistrarTimerTask(), 0);
|
||||
mSipClient.listen();
|
||||
} catch (Exception e) {
|
||||
throw new P2pProxyException("cannot start client",e);
|
||||
|
|
@ -123,7 +130,7 @@ public void call(String aTo, int duration) {
|
|||
}
|
||||
public static void main(String[] args) throws P2pProxyException {
|
||||
String lFrom=null, lTo=null, lPreferedProxyUri=null;
|
||||
int lDuration = 10, lLoop=0;
|
||||
int lDuration = 10000, lLoop=0;
|
||||
for (int i=0; i < args.length; i=i+2) {
|
||||
String argument = args[i];
|
||||
if (argument.equals("-from")) {
|
||||
|
|
@ -157,7 +164,7 @@ public static void main(String[] args) throws P2pProxyException {
|
|||
usage();
|
||||
System.exit(1);
|
||||
}
|
||||
if (lTo == null) {
|
||||
if (lLoop != 0 && lTo == null) {
|
||||
System.out.println("missing -to ");
|
||||
usage();
|
||||
System.exit(1);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue