org.jivesoftware.smackx.jingle
Class JingleSession

java.lang.Object
  extended by org.jivesoftware.smackx.jingle.JingleNegotiator
      extended by org.jivesoftware.smackx.jingle.JingleSession

public class JingleSession
extends JingleNegotiator

An abstract Jingle session.

This class contains some basic properties of every Jingle session. However, the concrete implementation can be found in subclasses.

Author:
Alvaro Saurin, Jeff Williams

Constructor Summary
JingleSession(XMPPConnection conn, JingleSessionRequest request, java.lang.String initiator, java.lang.String responder, java.util.List<JingleMediaManager> jingleMediaManagers)
          JingleSession constructor (for an outgoing Jingle session)
JingleSession(XMPPConnection conn, java.lang.String initiator, java.lang.String responder, java.lang.String sessionid, java.util.List<JingleMediaManager> jingleMediaManagers)
          Full featured JingleSession constructor
 
Method Summary
 void addContentNegotiator(ContentNegotiator inContentNegotiator)
          Add a new content negotiator on behalf of a section received.
 void addJingleMediaSession(java.lang.String mediaManagerName, JingleMediaSession mediaSession)
          The jingle session may have one or more media managers that are trying to establish media sessions.
 void addMediaListener(JingleMediaListener li)
          Add a listener for jmf negotiation events
 void addTransportListener(JingleTransportListener li)
          Add a listener for transport negotiation events
 void close()
          Terminate negotiations.
 IQ createAck(IQ iq)
          Acknowledge a IQ packet.
static IQ createError(java.lang.String ID, java.lang.String to, java.lang.String from, int errCode, XMPPError error)
          A convience method to create an error packet.
static IQ createIQ(java.lang.String ID, java.lang.String to, java.lang.String from, IQ.Type type)
          A convience method to create an IQ packet.
 IQ createJingleError(IQ iq, JingleError jingleError)
          Complete and send an error.
 java.util.List<IQ> dispatchIncomingPacket(IQ iq, java.lang.String id)
          Dispatch an incoming packet.
 boolean equals(java.lang.Object obj)
           
 XMPPConnection getConnection()
           
 java.lang.String getInitiator()
          Get the session initiator
static JingleSession getInstanceFor(XMPPConnection con)
          Returns the JingleSession related to a particular connection.
 java.util.List<JingleMediaManager> getMediaManagers()
          Get the Media Manager of this Jingle Session
 JingleMediaSession getMediaSession(java.lang.String mediaManagerName)
          The jingle session may have one or more media managers that are trying to establish media sessions.
 java.lang.String getResponder()
          Get the session responder
 JingleSessionState getSessionState()
           
 java.lang.String getSid()
          Get the session ID
 int hashCode()
          Send a content info message.
 boolean isClosed()
           
 boolean isFullyEstablished()
          Return true if all of the media managers have finished
 void mediaReceived(java.lang.String participant)
          Called when new Media is received.
 void receivePacketAndRespond(IQ iq)
          Process and respond to an incoming packet.
 void removeMediaListener(JingleMediaListener li)
          Remove a listener for jmf negotiation events
 void removeTransportListener(JingleTransportListener li)
          Remove a listener for transport negotiation events
 Jingle sendFormattedJingle(IQ iq, Jingle jout)
          Complete and send a packet.
 Jingle sendFormattedJingle(Jingle jout)
          Complete and send a packet.
 void sendPacket(IQ iq)
           
 void setInitiator(java.lang.String initiator)
          Set the session initiator
 void setMediaManagers(java.util.List<JingleMediaManager> jingleMediaManagers)
          Set the Media Manager of this Jingle Session
 void setResponder(java.lang.String responder)
          Set the session responder.
 void setSessionState(JingleSessionState stateIs)
          Validate the state changes.
 void setupListeners()
          Setup the listeners that act on events coming from the lower level negotiators.
 void startIncoming()
          This is the starting point for responding to a new session.
 void startOutgoing()
          This is the starting point for intitiating a new session.
 void terminate()
          Terminates the session with default reason.
 void terminate(java.lang.String reason)
          Terminates the session with a custom reason.
 
Methods inherited from class org.jivesoftware.smackx.jingle.JingleNegotiator
addExpectedId, addListener, getNegotiatorState, getSession, isExpectedId, isStarted, removeExpectedId, removeListener, setNegotiatorState, setSession, start
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JingleSession

public JingleSession(XMPPConnection conn,
                     java.lang.String initiator,
                     java.lang.String responder,
                     java.lang.String sessionid,
                     java.util.List<JingleMediaManager> jingleMediaManagers)
Full featured JingleSession constructor

Parameters:
conn - XMPPConnection
initiator - the initiator JID
responder - the responder JID
sessionid - the session ID
jingleMediaManager - the jingleMediaManager

JingleSession

public JingleSession(XMPPConnection conn,
                     JingleSessionRequest request,
                     java.lang.String initiator,
                     java.lang.String responder,
                     java.util.List<JingleMediaManager> jingleMediaManagers)
JingleSession constructor (for an outgoing Jingle session)

Parameters:
conn - XMPPConnection
initiator - the initiator JID
responder - the responder JID
jingleMediaManager - the jingleMediaManager
Method Detail

getInitiator

public java.lang.String getInitiator()
Get the session initiator

Returns:
the initiator

getConnection

public XMPPConnection getConnection()
Overrides:
getConnection in class JingleNegotiator

setInitiator

public void setInitiator(java.lang.String initiator)
Set the session initiator

Parameters:
initiator - the initiator to set

getMediaManagers

public java.util.List<JingleMediaManager> getMediaManagers()
Get the Media Manager of this Jingle Session

Returns:

setMediaManagers

public void setMediaManagers(java.util.List<JingleMediaManager> jingleMediaManagers)
Set the Media Manager of this Jingle Session

Parameters:
jingleMediaManager -

getResponder

public java.lang.String getResponder()
Get the session responder

Returns:
the responder

setResponder

public void setResponder(java.lang.String responder)
Set the session responder.

Parameters:
responder - the receptor to set

getSid

public java.lang.String getSid()
Get the session ID

Returns:
the sid

setSessionState

public void setSessionState(JingleSessionState stateIs)
Validate the state changes.


getSessionState

public JingleSessionState getSessionState()

isFullyEstablished

public boolean isFullyEstablished()
Return true if all of the media managers have finished


receivePacketAndRespond

public void receivePacketAndRespond(IQ iq)
                             throws XMPPException
Process and respond to an incoming packet.

This method is called from the packet listener dispatcher when a new packet has arrived. The method is responsible for recognizing the packet type and, depending on the current state, delivering it to the right event handler and wait for a response. The response will be another Jingle packet that will be sent to the other end point.

Parameters:
iq - the packet received
Throws:
XMPPException

dispatchIncomingPacket

public java.util.List<IQ> dispatchIncomingPacket(IQ iq,
                                                 java.lang.String id)
                                          throws XMPPException
Dispatch an incoming packet. The method is responsible for recognizing the packet type and, depending on the current state, delivering the packet to the right event handler and wait for a response.

Specified by:
dispatchIncomingPacket in class JingleNegotiator
Parameters:
iq - the packet received
id - the ID of the response that will be sent
Returns:
the new Jingle packet to send.
Throws:
XMPPException

addContentNegotiator

public void addContentNegotiator(ContentNegotiator inContentNegotiator)
Add a new content negotiator on behalf of a section received.


sendPacket

public void sendPacket(IQ iq)

sendFormattedJingle

public Jingle sendFormattedJingle(Jingle jout)
Complete and send a packet. Complete all the null fields in a Jingle reponse, using the session information we have.

Parameters:
jout - the Jingle packet we want to complete and send

sendFormattedJingle

public Jingle sendFormattedJingle(IQ iq,
                                  Jingle jout)
Complete and send a packet. Complete all the null fields in a Jingle reponse, using the session information we have or some info from the incoming packet.

Parameters:
iq - The Jingle packet we are responing to
jout - the Jingle packet we want to complete and send

createAck

public IQ createAck(IQ iq)
Acknowledge a IQ packet.

Parameters:
iq - The IQ to acknowledge

hashCode

public int hashCode()
Send a content info message.

Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

getInstanceFor

public static JingleSession getInstanceFor(XMPPConnection con)
Returns the JingleSession related to a particular connection.

Parameters:
con - A XMPP connection
Returns:
a Jingle session

addMediaListener

public void addMediaListener(JingleMediaListener li)
Add a listener for jmf negotiation events

Parameters:
li - The listener

removeMediaListener

public void removeMediaListener(JingleMediaListener li)
Remove a listener for jmf negotiation events

Parameters:
li - The listener

addTransportListener

public void addTransportListener(JingleTransportListener li)
Add a listener for transport negotiation events

Parameters:
li - The listener

removeTransportListener

public void removeTransportListener(JingleTransportListener li)
Remove a listener for transport negotiation events

Parameters:
li - The listener

setupListeners

public void setupListeners()
Setup the listeners that act on events coming from the lower level negotiators.


terminate

public void terminate()
               throws XMPPException
Terminates the session with default reason.

Throws:
XMPPException

terminate

public void terminate(java.lang.String reason)
               throws XMPPException
Terminates the session with a custom reason.

Throws:
XMPPException

close

public void close()
Terminate negotiations.

Overrides:
close in class JingleNegotiator

isClosed

public boolean isClosed()

createIQ

public static IQ createIQ(java.lang.String ID,
                          java.lang.String to,
                          java.lang.String from,
                          IQ.Type type)
A convience method to create an IQ packet.

Parameters:
ID - The packet ID of the
to - To whom the packet is addressed.
from - From whom the packet is sent.
type - The iq type of the packet.
Returns:
The created IQ packet.

createError

public static IQ createError(java.lang.String ID,
                             java.lang.String to,
                             java.lang.String from,
                             int errCode,
                             XMPPError error)
A convience method to create an error packet.

Parameters:
ID - The packet ID of the
to - To whom the packet is addressed.
from - From whom the packet is sent.
errCode - The error code.
errStr - The error string.
Returns:
The created IQ packet.

createJingleError

public IQ createJingleError(IQ iq,
                            JingleError jingleError)
Complete and send an error. Complete all the null fields in an IQ error reponse, using the sesssion information we have or some info from the incoming packet.

Parameters:
iq - The Jingle packet we are responing to
error - the IQ packet we want to complete and send

mediaReceived

public void mediaReceived(java.lang.String participant)
Called when new Media is received.


startOutgoing

public void startOutgoing()
                   throws java.lang.IllegalStateException
This is the starting point for intitiating a new session.

Throws:
java.lang.IllegalStateException

startIncoming

public void startIncoming()
This is the starting point for responding to a new session.


addJingleMediaSession

public void addJingleMediaSession(java.lang.String mediaManagerName,
                                  JingleMediaSession mediaSession)
The jingle session may have one or more media managers that are trying to establish media sessions. When the media manager succeeds in creating a media session is registers it with the session by the media manager's static name. This routine is where the media manager does the registering.


getMediaSession

public JingleMediaSession getMediaSession(java.lang.String mediaManagerName)
The jingle session may have one or more media managers that are trying to establish media sessions. When the media manager succeeds in creating a media session is registers it with the session by the media manager's static name. This routine is where other objects can access the registered media sessions. NB: If the media manager has not succeeded in establishing a media session then this could return null.