use of org.jivesoftware.smackx.jingle.nat.FixedTransportManager in project Smack by igniterealtime.
the class JingleManagerTest method testSendSimpleMessage.
/**
* High level API test. This is a simple test to use with an XMPP client and
* check if the client receives the message 1. User_1 will send an
* invitation to user_2.
*/
public void testSendSimpleMessage() {
resetCounter();
try {
FixedResolver tr0 = new FixedResolver("127.0.0.1", 54222);
FixedTransportManager ftm0 = new FixedTransportManager(tr0);
TestMediaManager tmm0 = new TestMediaManager(ftm0);
tmm0.setPayloads(getTestPayloads1());
List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
trl0.add(tmm0);
FixedResolver tr1 = new FixedResolver("127.0.0.1", 54567);
FixedTransportManager ftm1 = new FixedTransportManager(tr1);
TestMediaManager tmm1 = new TestMediaManager(ftm1);
tmm1.setPayloads(getTestPayloads1());
List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
trl1.add(tmm1);
JingleManager man0 = new JingleManager(getConnection(0), trl0);
JingleManager man1 = new JingleManager(getConnection(1), trl1);
// Session 1 waits for connections
man1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
/**
* Called when a new session request is detected
*/
public void sessionRequested(final JingleSessionRequest request) {
incCounter();
System.out.println("Session request detected, from " + request.getFrom());
}
});
// Session 0 starts a request
System.out.println("Starting session request, to " + getFullJID(1) + "...");
JingleSession session0 = man0.createOutgoingJingleSession(getFullJID(1));
session0.startOutgoing();
Thread.sleep(5000);
assertTrue(valCounter() > 0);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "exception", e);
fail("An error occured with Jingle");
}
}
use of org.jivesoftware.smackx.jingle.nat.FixedTransportManager in project Smack by igniterealtime.
the class JingleSessionTest method testGetInstanceFor.
public void testGetInstanceFor() {
String ini1 = "initiator1";
String sid1 = "sid1";
String ini2 = "initiator2";
String sid2 = "sid2";
FixedResolver tr1 = new FixedResolver("127.0.0.1", 54222);
FixedTransportManager ftm1 = new FixedTransportManager(tr1);
TestMediaManager tmm1 = new TestMediaManager(ftm1);
List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
trl1.add(tmm1);
JingleSession js1 = new JingleSession(getConnection(0), ini1, null, sid1, trl1);
JingleSession js2 = new JingleSession(getConnection(1), ini2, null, sid2, trl1);
// For a packet, we should be able to get a session that handles that...
assertNotNull(JingleSession.getInstanceFor(getConnection(0)));
assertNotNull(JingleSession.getInstanceFor(getConnection(1)));
assertEquals(JingleSession.getInstanceFor(getConnection(0)), js1);
assertEquals(JingleSession.getInstanceFor(getConnection(1)), js2);
}
use of org.jivesoftware.smackx.jingle.nat.FixedTransportManager in project Smack by igniterealtime.
the class JingleManagerTest method testEqualPayloadsSetSession.
/**
* This is a simple test where both endpoints have exactly the same payloads
* and the session is accepted.
*/
public void testEqualPayloadsSetSession() {
resetCounter();
try {
FixedResolver tr0 = new FixedResolver("127.0.0.1", 54213);
FixedTransportManager ftm0 = new FixedTransportManager(tr0);
TestMediaManager tmm0 = new TestMediaManager(ftm0);
tmm0.setPayloads(getTestPayloads1());
List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
trl0.add(tmm0);
FixedResolver tr1 = new FixedResolver("127.0.0.1", 54531);
FixedTransportManager ftm1 = new FixedTransportManager(tr1);
TestMediaManager tmm1 = new TestMediaManager(ftm1);
tmm1.setPayloads(getTestPayloads1());
List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
trl1.add(tmm1);
JingleManager man0 = new JingleManager(getConnection(0), trl0);
JingleManager man1 = new JingleManager(getConnection(1), trl1);
man0.addCreationListener(ftm0);
man1.addCreationListener(ftm1);
man1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
/**
* Called when a new session request is detected
*/
public void sessionRequested(final JingleSessionRequest request) {
System.out.println("Session request detected, from " + request.getFrom() + ": accepting.");
try {
// We accept the request
JingleSession session1 = request.accept();
session1.addListener(new JingleSessionListener() {
public void sessionClosed(String reason, JingleSession jingleSession) {
System.out.println("sessionClosed().");
}
public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
System.out.println("sessionClosedOnError().");
}
public void sessionDeclined(String reason, JingleSession jingleSession) {
System.out.println("sessionDeclined().");
}
public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) {
incCounter();
System.out.println("Responder: the session is fully established.");
System.out.println("+ Payload Type: " + pt.getId());
System.out.println("+ Local IP/port: " + lc.getIp() + ":" + lc.getPort());
System.out.println("+ Remote IP/port: " + rc.getIp() + ":" + rc.getPort());
}
public void sessionMediaReceived(JingleSession jingleSession, String participant) {
// Do Nothing
}
public void sessionRedirected(String redirection, JingleSession jingleSession) {
}
});
session1.startIncoming();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "exception", e);
}
}
});
// Session 0 starts a request
System.out.println("Starting session request with equal payloads, to " + getFullJID(1) + "...");
JingleSession session0 = man0.createOutgoingJingleSession(getFullJID(1));
session0.startOutgoing();
Thread.sleep(20000);
assertTrue(valCounter() == 1);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "exception", e);
fail("An error occured with Jingle");
}
}
use of org.jivesoftware.smackx.jingle.nat.FixedTransportManager in project Smack by igniterealtime.
the class JingleManagerTest method testMediaManager.
/**
* This is a full test in the Jingle API.
*/
public void testMediaManager() {
resetCounter();
XMPPTCPConnection x0 = getConnection(0);
XMPPTCPConnection x1 = getConnection(1);
FixedResolver tr0 = new FixedResolver("127.0.0.1", 20004);
FixedTransportManager ftm0 = new FixedTransportManager(tr0);
FixedResolver tr1 = new FixedResolver("127.0.0.1", 20040);
FixedTransportManager ftm1 = new FixedTransportManager(tr1);
try {
JingleMediaManager jingleMediaManager = new JingleMediaManager(ftm0) {
// Media Session Implementation
public JingleMediaSession createMediaSession(final PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local, final JingleSession jingleSession) {
return new JingleMediaSession(payloadType, remote, local, null, null) {
public void initialize() {
}
public void startTrasmit() {
incCounter();
System.out.println("Transmit");
}
public void startReceive() {
incCounter();
System.out.println("Receive");
}
public void setTrasmit(boolean active) {
}
public void stopTrasmit() {
incCounter();
System.out.println("Stop Transmit");
}
public void stopReceive() {
incCounter();
System.out.println("Stop Receive");
}
};
}
public List<PayloadType> getPayloads() {
return getTestPayloads1();
}
public PayloadType.Audio getPreferredAudioPayloadType() {
return (PayloadType.Audio) getTestPayloads1().get(0);
}
};
List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
trl0.add(jingleMediaManager);
List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
trl1.add(jingleMediaManager);
JingleManager jm0 = new JingleManager(x0, trl0);
JingleManager jm1 = new JingleManager(x1, trl1);
jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
public void sessionRequested(final JingleSessionRequest request) {
try {
JingleSession session = request.accept();
session.startIncoming();
} catch (XMPPException e) {
LOGGER.log(Level.WARNING, "exception", e);
}
}
});
JingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
js0.startOutgoing();
Thread.sleep(10000);
js0.terminate();
Thread.sleep(3000);
System.out.println(valCounter());
assertTrue(valCounter() == 8);
Thread.sleep(15000);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "exception", e);
}
}
use of org.jivesoftware.smackx.jingle.nat.FixedTransportManager in project Smack by igniterealtime.
the class JingleManagerTest method testAcceptJingleSession.
/**
* High level API test. This is a simple test to use with an XMPP client and
* check if the client receives the message 1. User_1 will send an
* invitation to user_2.
*/
public void testAcceptJingleSession() {
resetCounter();
try {
FixedResolver tr0 = new FixedResolver("127.0.0.1", 54222);
FixedTransportManager ftm0 = new FixedTransportManager(tr0);
TestMediaManager tmm0 = new TestMediaManager(ftm0);
tmm0.setPayloads(getTestPayloads1());
List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
trl0.add(tmm0);
FixedResolver tr1 = new FixedResolver("127.0.0.1", 54567);
FixedTransportManager ftm1 = new FixedTransportManager(tr1);
TestMediaManager tmm1 = new TestMediaManager(ftm1);
tmm1.setPayloads(getTestPayloads2());
List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
trl1.add(tmm1);
JingleManager man0 = new JingleManager(getConnection(0), trl0);
JingleManager man1 = new JingleManager(getConnection(1), trl1);
man1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
/**
* Called when a new session request is detected
*/
public void sessionRequested(final JingleSessionRequest request) {
incCounter();
System.out.println("Session request detected, from " + request.getFrom() + ": accepting.");
// We accept the request
try {
JingleSession session1 = request.accept();
session1.startIncoming();
} catch (Exception e) {
LOGGER.log(Level.WARNING, "exception", e);
}
}
});
// Session 0 starts a request
System.out.println("Starting session request, to " + getFullJID(1) + "...");
JingleSession session0 = man0.createOutgoingJingleSession(getFullJID(1));
session0.startOutgoing();
Thread.sleep(20000);
assertTrue(valCounter() > 0);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "exception", e);
fail("An error occured with Jingle");
}
}
Aggregations