1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-05 12:41:08 +01:00

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7104 b35dd754-fafc-0310-a699-88a17e54d16e

This commit is contained in:
Thiago Camargo 2007-02-14 02:35:04 +00:00 committed by thiago
parent 858b84d912
commit ed660f73e9
5 changed files with 132 additions and 97 deletions

View file

@ -49,34 +49,34 @@ import java.util.List;
* Jingle is a session establishment protocol defined in (XEP-0166).
* It defines a framework for negotiating and managing out-of-band ( data that is send and receive through other connection than XMPP connection) data sessions over XMPP.
* With this protocol you can setup VOIP Calls, Video Streaming, File transfers and whatever out-of-band session based transmission.
*
* <p/>
* To create a Jingle Session you need a Transport method and a Payload type.
*
* <p/>
* A transport method is how it will trasmit and receive network packets. Transport MUST have one or more candidates.
* A transport candidate is an IP Address with a defined port, that other party must send data to.
*
* <p/>
* A supported payload type, is the data encoding format that the jmf will be transmitted.
* For instance an Audio Payload "GSM".
*
* <p/>
* A Jingle session negociates a payload type and a pair of transport candidates.
* Which means that when a Jingle Session is establhished you will have two defined transport candidates with addresses
* and a defined Payload type.
* In other words, you will have two IP address with their respective ports, and a Codec type defined.
*
* <p/>
* The JingleManager is a facade built upon Jabber Jingle (XEP-166) to allow the
* use of Jingle. This implementation allows the user to simply
* use this class for setting the Jingle parameters, create and receive Jingle Sessions.
*
* <p/>
* In order to use the Jingle, the user must provide a
* TransportManager that will handle the resolution of potential IP addresses taht can be used to transport the streaming (jmf).
* This TransportManager can be initialized with several default resolvers,
* including a fixed solver that can be used when the address and port are know
* in advance.
* This API have ready to use Transport Managers, for instance: BasicTransportManager, STUNTransportManager, BridgedTransportManager.
*
* <p/>
* You should also especify a JingleMediaManager if you want that JingleManager assume Media control
* Using a JingleMediaManager implementation is the easier way to implement a Jingle Application.
*
* <p/>
* Otherwise before creating an outgoing connection, the user must create jingle session
* listeners that will be called when different events happen. The most
* important event is <i>sessionEstablished()</i>, that will be called when all
@ -84,85 +84,85 @@ import java.util.List;
* transmission as well as the remote and local addresses and ports for the
* communication. See JingleSessionListener for a complete list of events that can be
* observed.
*
* <p/>
* This is an example of how to use the JingleManager:
* <i>This example implements a Jingle VOIP Call between two users.</i>
*
* <p/>
* <pre>
*
* <p/>
* To wait for an Incoming Jingle Session:
*
* <p/>
* try {
*
* <p/>
* // Connect to a XMPP Server
* XMPPConnection x1 = new XMPPConnection("xmpp.com");
* x1.connect();
* x1.login("juliet", "juliet");
*
* <p/>
* // Create a JingleManager using a BasicResolver
* final JingleManager jm1 = new JingleManager(
* x1, new BasicTransportManager());
*
* <p/>
* // Create a JingleMediaManager. In this case using Jingle Audio Media API
* JingleMediaManager jingleMediaManager = new AudioMediaManager();
*
* <p/>
* // Set the JingleMediaManager
* jm1.setMediaManager(jingleMediaManager);
*
* <p/>
* // Listen for incoming calls
* jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
* public void sessionRequested(JingleSessionRequest request) {
*
* <p/>
* try {
* // Accept the call
* IncomingJingleSession session = request.accept();
*
*
* <p/>
* <p/>
* // Start the call
* session.start();
* } catch (XMPPException e) {
* e.printStackTrace();
* }
*
* <p/>
* }
* });
*
* <p/>
* Thread.sleep(15000);
*
* <p/>
* } catch (Exception e) {
* e.printStackTrace();
* }
*
* <p/>
* To create an Outgoing Jingle Session:
*
* <p/>
* try {
*
* <p/>
* // Connect to a XMPP Server
* XMPPConnection x0 = new XMPPConnection("xmpp.com");
* x0.connect();
* x0.login("romeo", "romeo");
*
* <p/>
* // Create a JingleManager using a BasicResolver
* final JingleManager jm0 = new JingleManager(
* x0, new BasicTransportManager());
*
* <p/>
* // Create a JingleMediaManager. In this case using Jingle Audio Media API
* JingleMediaManager jingleMediaManager = new AudioMediaManager(); // Using Jingle Media API
*
* <p/>
* // Set the JingleMediaManager
* jm0.setMediaManager(jingleMediaManager);
*
* <p/>
* // Create a new Jingle Call with a full JID
* OutgoingJingleSession js0 = jm0.createOutgoingJingleSession("juliet@xmpp.com/Smack");
*
* <p/>
* // Start the call
* js0.start();
*
* <p/>
* Thread.sleep(10000);
* js0.terminate();
*
* <p/>
* Thread.sleep(3000);
*
* <p/>
* } catch (Exception e) {
* e.printStackTrace();
* }
@ -275,7 +275,8 @@ public class JingleManager implements JingleSessionListener {
if (aux != null)
try {
aux.terminate();
} catch (XMPPException e) {
}
catch (XMPPException e) {
e.printStackTrace();
}
}
@ -323,8 +324,8 @@ public class JingleManager implements JingleSessionListener {
/**
* Enables or disables the Jingle support on a given connection.
*
*
* <p/>
* <p/>
* Before starting any Jingle jmf session, check that the user can handle
* it. Enable the Jingle support to indicate that this client handles Jingle
* messages.
@ -334,7 +335,7 @@ public class JingleManager implements JingleSessionListener {
* @param enabled indicates if the service will be enabled or disabled
*/
public synchronized static void setServiceEnabled(XMPPConnection connection,
boolean enabled) {
boolean enabled) {
if (isServiceEnabled(connection) == enabled) {
return;
}
@ -342,7 +343,8 @@ public class JingleManager implements JingleSessionListener {
if (enabled) {
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(
Jingle.NAMESPACE);
} else {
}
else {
ServiceDiscoveryManager.getInstanceFor(connection).removeFeature(
Jingle.NAMESPACE);
}
@ -475,7 +477,8 @@ public class JingleManager implements JingleSessionListener {
for (CreatedJingleSessionListener createdJingleSessionListener : creationListeners) {
try {
createdJingleSessionListener.sessionCreated(jingleSession);
} catch (Exception e) {
}
catch (Exception e) {
e.printStackTrace();
}
}
@ -549,7 +552,8 @@ public class JingleManager implements JingleSessionListener {
for (JingleSession jingleSession : sessions)
try {
jingleSession.terminate();
} catch (XMPPException e) {
}
catch (XMPPException e) {
e.printStackTrace();
}
@ -589,7 +593,7 @@ public class JingleManager implements JingleSessionListener {
* @return The session on which the negotiation can be run.
*/
public OutgoingJingleSession createOutgoingJingleSession(String responder,
List<PayloadType> payloadTypes) throws XMPPException {
List<PayloadType> payloadTypes) throws XMPPException {
if (responder == null || StringUtils.parseName(responder).length() <= 0
|| StringUtils.parseServer(responder).length() <= 0
@ -666,8 +670,10 @@ public class JingleManager implements JingleSessionListener {
if (request == null) {
throw new NullPointerException("JingleMediaManager is not defined");
}
if (jingleMediaManager == null) return null;
return createIncomingJingleSession(request, jingleMediaManager.getPayloads());
if (jingleMediaManager != null)
return createIncomingJingleSession(request, jingleMediaManager.getPayloads());
return createIncomingJingleSession(request,null);
}
/**
@ -682,7 +688,8 @@ public class JingleManager implements JingleSessionListener {
if (jingleSession.getResponder().equals(jid)) {
return jingleSession;
}
} else if (jingleSession instanceof IncomingJingleSession) {
}
else if (jingleSession instanceof IncomingJingleSession) {
if (jingleSession.getInitiator().equals(jid)) {
return jingleSession;
}

View file

@ -118,7 +118,7 @@ public abstract class JingleSession extends JingleNegotiator {
static int ccc = 0;
private boolean closed = false;
private boolean closed = false;
/**
* Full featured JingleSession constructor
@ -343,6 +343,8 @@ public abstract class JingleSession extends JingleNegotiator {
public IQ dispatchIncomingPacket(IQ iq, String id) throws XMPPException {
IQ jout = null;
if (iq != null) System.out.println("L: " + iq.toXML());
if (invalidState()) {
throw new IllegalStateException(
"Illegal state in dispatch packet in Session manager.");
@ -377,12 +379,16 @@ public abstract class JingleSession extends JingleNegotiator {
jout = getState().eventInfo(jin);
}
else if (action.equals(Jingle.Action.SESSIONINITIATE)) {
jout = getState().eventInitiate(jin);
if (getState() != null)
jout = getState().eventInitiate(jin);
}
else if (action.equals(Jingle.Action.SESSIONREDIRECT)) {
jout = getState().eventRedirect(jin);
}
else if (action.equals(Jingle.Action.SESSIONTERMINATE)) {
System.out.println("SESSION PACKET");
jout = getState().eventTerminate(jin);
}
}
@ -417,6 +423,9 @@ public abstract class JingleSession extends JingleNegotiator {
public synchronized IQ respond(IQ iq) throws XMPPException {
IQ response = null;
if (iq != null)
System.out.println("TT: " + iq.toXML());
if (isValid()) {
String responseId = null;
IQ sessionResponse = null;
@ -887,10 +896,10 @@ public abstract class JingleSession extends JingleNegotiator {
if (iq instanceof Jingle) {
Jingle jin = (Jingle) iq;
//System.out.println("Jingle: " + iq.toXML());
System.out.println("Jingle: " + iq.toXML());
String sid = jin.getSid();
if (!sid.equals(getSid())) {
if (sid == null || !sid.equals(getSid())) {
System.out.println("Ignored Jingle(SID) " + sid + "|" + getSid() + " :" + iq.toXML());
return false;
}
@ -1091,8 +1100,8 @@ public abstract class JingleSession extends JingleNegotiator {
destroyMediaNeg();
destroyTransportNeg();
removePacketListener();
System.out.println("Negociation Closed");
closed=true;
System.out.println("Negociation Closed: "+getConnection().getUser());
closed = true;
super.close();
}

View file

@ -77,7 +77,9 @@ public class JingleSessionRequest {
pts);
session.setInitialSessionRequest(this);
// Acknowledge the IQ reception
session.sendAck(this.getJingle());
session.setSid(this.getSessionID());
//session.sendAck(this.getJingle());
//session.respond(this.getJingle());
}
return session;
}
@ -93,6 +95,11 @@ public class JingleSessionRequest {
synchronized (manager) {
session = manager.createIncomingJingleSession(this);
session.setInitialSessionRequest(this);
// Acknowledge the IQ reception
session.setSid(this.getSessionID());
//session.sendAck(this.getJingle());
//session.updatePacketListener();
//session.respond(this.getJingle());
}
return session;
}