mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-23 13:07:59 +01:00
More Refactoring in Negotiation Speed
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7364 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
3c455c8367
commit
a616e34bd7
4 changed files with 42 additions and 26 deletions
|
@ -360,7 +360,7 @@ public abstract class JingleNegotiator {
|
|||
}
|
||||
|
||||
public Jingle eventTerminate(Jingle jin) throws XMPPException {
|
||||
if (neg != null) {
|
||||
if (neg != null && !neg.invalidState()) {
|
||||
neg.close();
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -547,7 +547,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
* @param iq The Jingle packet we are responing to
|
||||
* @param error the IQ packet we want to complete and send
|
||||
*/
|
||||
protected IQ sendFormattedError(IQ iq, JingleError error) {
|
||||
public IQ sendFormattedError(IQ iq, JingleError error) {
|
||||
IQ perror = null;
|
||||
if (error != null) {
|
||||
perror = createIQ(getSid(), iq.getFrom(), iq.getTo(), IQ.Type.ERROR);
|
||||
|
@ -1121,6 +1121,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
* @throws XMPPException
|
||||
*/
|
||||
public void terminate() throws XMPPException {
|
||||
if (isClosed()) return;
|
||||
System.out.println("State: " + this.getState());
|
||||
Jingle result = null;
|
||||
Jingle jout = new Jingle(Jingle.Action.SESSIONTERMINATE);
|
||||
|
@ -1133,6 +1134,7 @@ public abstract class JingleSession extends JingleNegotiator {
|
|||
* Terminate negotiations.
|
||||
*/
|
||||
public void close() {
|
||||
if (isClosed()) return;
|
||||
destroyMediaNeg();
|
||||
destroyTransportNeg();
|
||||
removePacketListener();
|
||||
|
|
|
@ -277,29 +277,43 @@ public abstract class TransportNegotiator extends JingleNegotiator {
|
|||
public void run() {
|
||||
|
||||
// Sleep for some time, waiting for the candidates checks
|
||||
try {
|
||||
Thread.sleep(CANDIDATES_ACCEPT_PERIOD
|
||||
+ TransportResolver.CHECK_TIMEOUT);
|
||||
|
||||
int totalTime= (CANDIDATES_ACCEPT_PERIOD + (TransportResolver.CHECK_TIMEOUT * (resolver.getCandidatesList().size()+1)));
|
||||
int tries = (int)Math.ceil(totalTime/1000);
|
||||
|
||||
for (int i = 0; i < tries; i++) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Once we are in pending state, look for any valid remote
|
||||
// candidate, and send an "accept" if we have one...
|
||||
TransportCandidate bestRemote = getBestRemoteCandidate();
|
||||
State state = getState();
|
||||
|
||||
if (bestRemote != null && (state == pending || state == active)) {
|
||||
// Accepting the remote candidate
|
||||
Jingle jout = new Jingle(Jingle.Action.TRANSPORTACCEPT);
|
||||
jout.addTransport(getJingleTransport(bestRemote));
|
||||
|
||||
// Send the packet
|
||||
js.sendFormattedJingle(jin, jout);
|
||||
|
||||
if (isEstablished()) {
|
||||
setState(active);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Once we are in pending state, look for any valid remote
|
||||
// candidate, and send an "accept" if we have one...
|
||||
TransportCandidate bestRemote = getBestRemoteCandidate();
|
||||
State state = getState();
|
||||
|
||||
if (bestRemote != null && (state == pending || state == active)) {
|
||||
// Accepting the remote candidate
|
||||
Jingle jout = new Jingle(Jingle.Action.TRANSPORTACCEPT);
|
||||
jout.addTransport(getJingleTransport(bestRemote));
|
||||
|
||||
// Send the packet
|
||||
js.sendFormattedJingle(jin, jout);
|
||||
|
||||
if (isEstablished()) {
|
||||
setState(active);
|
||||
if (getState() == null || !getState().equals(active)) {
|
||||
try {
|
||||
session.terminate();
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,10 +129,10 @@ public class JingleMediaTest extends SmackTestCase {
|
|||
x1, new BasicTransportManager());
|
||||
|
||||
MultiMediaManager jingleMediaManager0 = new MultiMediaManager();
|
||||
// jingleMediaManager0.addMediaManager(new SpeexMediaManager());
|
||||
jingleMediaManager0.addMediaManager(new SpeexMediaManager());
|
||||
jingleMediaManager0.addMediaManager(new JmfMediaManager());
|
||||
MultiMediaManager jingleMediaManager1 = new MultiMediaManager();
|
||||
// jingleMediaManager1.addMediaManager(new JmfMediaManager());
|
||||
jingleMediaManager1.addMediaManager(new JmfMediaManager());
|
||||
jingleMediaManager1.addMediaManager(new SpeexMediaManager());
|
||||
|
||||
jm0.setMediaManager(jingleMediaManager0);
|
||||
|
|
Loading…
Reference in a new issue