Class JingleSession
- java.lang.Object
-
- org.jivesoftware.smackx.jingleold.JingleNegotiator
-
- org.jivesoftware.smackx.jingleold.JingleSession
-
- All Implemented Interfaces:
MediaReceivedListener
public final class JingleSession extends JingleNegotiator implements MediaReceivedListener
An abstract Jingle session. This class contains some basic properties of every Jingle session. However, the concrete implementation can be found in subclasses.
-
-
Field Summary
Fields Modifier and Type Field Description protected List<JingleMediaManager>
jingleMediaManagers
-
Fields inherited from class org.jivesoftware.smackx.jingleold.JingleNegotiator
session
-
-
Constructor Summary
Constructors Constructor Description JingleSession(XMPPConnection conn, JingleSessionRequest request, Jid initiator, Jid responder, List<JingleMediaManager> jingleMediaManagers)
JingleSession constructor (for an outgoing Jingle session).JingleSession(XMPPConnection conn, Jid initiator, Jid responder, String sessionid, List<JingleMediaManager> jingleMediaManagers)
Full featured JingleSession constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addContentNegotiator(ContentNegotiator inContentNegotiator)
Add a new content negotiator on behalf of a <content/> section received.void
addJingleMediaSession(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.IQ
createJingleError(IQ iq, JingleError jingleError)
Complete and send an error.List<IQ>
dispatchIncomingPacket(IQ iq, String id)
Dispatch an incoming packet.protected void
doStart()
Each of the negotiators has their individual behavior when they start.boolean
equals(Object obj)
protected static String
generateSessionId()
Generate a unique session ID.XMPPConnection
getConnection()
Jid
getInitiator()
Get the session initiator.static JingleSession
getInstanceFor(XMPPConnection con)
Returns the JingleSession related to a particular connection.List<JingleMediaManager>
getMediaManagers()
Get the Media Manager of this Jingle Session.JingleMediaSession
getMediaSession(String mediaManagerName)
The jingle session may have one or more media managers that are trying to establish media sessions.Jid
getResponder()
Get the session responder.JingleSessionState
getSessionState()
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(String participant)
Called when new Media is received.void
receivePacketAndRespond(IQ iq)
Process and respond to an incoming packet.protected void
removeAsyncPacketListener()
Remove the stanza listener used for processing 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
sendStanza(IQ iq)
void
setInitiator(Jid initiator)
Set the session initiator.void
setMediaManagers(List<JingleMediaManager> jingleMediaManagers)
Set the Media Manager of this Jingle Session.void
setResponder(Jid responder)
Set the session responder.void
setSessionState(JingleSessionState stateIs)
Validate the state changes.protected void
setSid(String sessionId)
Set the session IDvoid
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(String reason)
Terminates the session with a custom reason.protected void
triggerMediaReceived(String participant)
Trigger a media received event.protected void
triggerSessionClosed(String reason)
Trigger a session closed event.protected void
triggerSessionClosedOnError(XMPPException exc)
Trigger a session closed event due to an error.protected void
updatePacketListener()
Install the stanza listener.-
Methods inherited from class org.jivesoftware.smackx.jingleold.JingleNegotiator
addExpectedId, addListener, getListenersList, getNegotiatorState, getSession, isExpectedId, isStarted, removeExpectedId, removeListener, setNegotiatorState, setSession, start
-
-
-
-
Field Detail
-
jingleMediaManagers
protected List<JingleMediaManager> jingleMediaManagers
-
-
Constructor Detail
-
JingleSession
public JingleSession(XMPPConnection conn, Jid initiator, Jid responder, String sessionid, List<JingleMediaManager> jingleMediaManagers)
Full featured JingleSession constructor.- Parameters:
conn
- TODO javadoc me please the XMPPConnection which is usedinitiator
- TODO javadoc me please the initiator JIDresponder
- TODO javadoc me please the responder JIDsessionid
- TODO javadoc me please the session IDjingleMediaManagers
- TODO javadoc me please the jingleMediaManager
-
JingleSession
public JingleSession(XMPPConnection conn, JingleSessionRequest request, Jid initiator, Jid responder, List<JingleMediaManager> jingleMediaManagers)
JingleSession constructor (for an outgoing Jingle session).- Parameters:
conn
- Connectionrequest
- the request.initiator
- the initiator JIDresponder
- the responder JIDjingleMediaManagers
- the jingleMediaManager
-
-
Method Detail
-
getInitiator
public Jid getInitiator()
Get the session initiator.- Returns:
- the initiator
-
getConnection
public XMPPConnection getConnection()
- Overrides:
getConnection
in classJingleNegotiator
-
setInitiator
public void setInitiator(Jid initiator)
Set the session initiator.- Parameters:
initiator
- TODO javadoc me please the initiator to set
-
getMediaManagers
public List<JingleMediaManager> getMediaManagers()
Get the Media Manager of this Jingle Session.- Returns:
- the JingleMediaManagers
-
setMediaManagers
public void setMediaManagers(List<JingleMediaManager> jingleMediaManagers)
Set the Media Manager of this Jingle Session.- Parameters:
jingleMediaManagers
- TODO javadoc me please
-
getResponder
public Jid getResponder()
Get the session responder.- Returns:
- the responder
-
setResponder
public void setResponder(Jid responder)
Set the session responder.- Parameters:
responder
- TODO javadoc me please the receptor to set
-
setSid
protected void setSid(String sessionId)
Set the session ID- Parameters:
sessionId
- TODO javadoc me please the sid to set
-
generateSessionId
protected static String generateSessionId()
Generate a unique session ID.- Returns:
- the generated session ID.
-
setSessionState
public void setSessionState(JingleSessionState stateIs)
Validate the state changes.- Parameters:
stateIs
- the jingle session state.
-
getSessionState
public JingleSessionState getSessionState()
-
isFullyEstablished
public boolean isFullyEstablished()
Return true if all of the media managers have finished.- Returns:
true
if fully established.
-
receivePacketAndRespond
public void receivePacketAndRespond(IQ iq) throws XMPPException, SmackException, InterruptedException
Process and respond to an incoming packet. This method is called from the stanza listener dispatcher when a new stanza has arrived. The method is responsible for recognizing the stanza 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 stanza that will be sent to the other end point.- Parameters:
iq
- TODO javadoc me please the stanza received- Throws:
XMPPException
- if an XMPP protocol error was received.SmackException
- if Smack detected an exceptional situation.InterruptedException
- if the calling thread was interrupted.
-
dispatchIncomingPacket
public List<IQ> dispatchIncomingPacket(IQ iq, String id) throws XMPPException, SmackException, InterruptedException
Dispatch an incoming packet. The method is responsible for recognizing the stanza type and, depending on the current state, delivering the stanza to the right event handler and wait for a response.- Specified by:
dispatchIncomingPacket
in classJingleNegotiator
- Parameters:
iq
- TODO javadoc me please the stanza receivedid
- the ID of the response that will be sent- Returns:
- the new Jingle stanza to send.
- Throws:
XMPPException
- if an XMPP protocol error was received.SmackException
- if Smack detected an exceptional situation.InterruptedException
- if the calling thread was interrupted.
-
addContentNegotiator
public void addContentNegotiator(ContentNegotiator inContentNegotiator)
Add a new content negotiator on behalf of a <content/> section received.- Parameters:
inContentNegotiator
- the content negotiator.
-
sendStanza
public void sendStanza(IQ iq) throws SmackException.NotConnectedException, InterruptedException
-
sendFormattedJingle
public Jingle sendFormattedJingle(Jingle jout) throws SmackException.NotConnectedException, InterruptedException
Complete and send a packet. Complete all the null fields in a Jingle reponse, using the session information we have.- Parameters:
jout
- the Jingle stanza we want to complete and send- Returns:
- the Jingle stanza.
- Throws:
SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
sendFormattedJingle
public Jingle sendFormattedJingle(IQ iq, Jingle jout) throws SmackException.NotConnectedException, InterruptedException
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 stanza we are responding tojout
- the Jingle stanza we want to complete and send- Returns:
- the Jingle stanza.
- Throws:
SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
createAck
public IQ createAck(IQ iq)
Acknowledge a IQ packet.- Parameters:
iq
- The IQ to acknowledge.- Returns:
- the ack IQ.
-
getInstanceFor
public static JingleSession getInstanceFor(XMPPConnection con)
Returns the JingleSession related to a particular connection.- Parameters:
con
- TODO javadoc me please A XMPP connection- Returns:
- a Jingle session
-
removeAsyncPacketListener
protected void removeAsyncPacketListener()
Remove the stanza listener used for processing packet.
-
updatePacketListener
protected void updatePacketListener()
Install the stanza listener. The listener is responsible for responding to any stanza that we receive...
-
addMediaListener
public void addMediaListener(JingleMediaListener li)
Add a listener for jmf negotiation events.- Parameters:
li
- TODO javadoc me please The listener
-
removeMediaListener
public void removeMediaListener(JingleMediaListener li)
Remove a listener for jmf negotiation events.- Parameters:
li
- TODO javadoc me please The listener
-
addTransportListener
public void addTransportListener(JingleTransportListener li)
Add a listener for transport negotiation events.- Parameters:
li
- TODO javadoc me please The listener
-
removeTransportListener
public void removeTransportListener(JingleTransportListener li)
Remove a listener for transport negotiation events.- Parameters:
li
- TODO javadoc me please The listener
-
setupListeners
public void setupListeners()
Setup the listeners that act on events coming from the lower level negotiators.
-
triggerSessionClosed
protected void triggerSessionClosed(String reason)
Trigger a session closed event.- Parameters:
reason
- the reason.
-
triggerSessionClosedOnError
protected void triggerSessionClosedOnError(XMPPException exc)
Trigger a session closed event due to an error.- Parameters:
exc
- the exception.
-
triggerMediaReceived
protected void triggerMediaReceived(String participant)
Trigger a media received event.- Parameters:
participant
- the participant.
-
terminate
public void terminate() throws XMPPException, SmackException.NotConnectedException, InterruptedException
Terminates the session with default reason.- Throws:
XMPPException
- if an XMPP protocol error was received.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
terminate
public void terminate(String reason) throws XMPPException, SmackException.NotConnectedException, InterruptedException
Terminates the session with a custom reason.- Parameters:
reason
- the reason.- Throws:
XMPPException
- if an XMPP protocol error was received.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.
-
close
public void close()
Terminate negotiations.- Overrides:
close
in classJingleNegotiator
-
isClosed
public boolean isClosed()
-
createJingleError
public IQ createJingleError(IQ iq, JingleError jingleError)
Complete and send an error. Complete all the null fields in an IQ error response, using the session information we have or some info from the incoming packet.- Parameters:
iq
- The Jingle stanza we are responding tojingleError
- the IQ stanza we want to complete and send- Returns:
- the jingle error IQ.
-
mediaReceived
public void mediaReceived(String participant)
Called when new Media is received.- Specified by:
mediaReceived
in interfaceMediaReceivedListener
- Parameters:
participant
- the participant.
-
startOutgoing
public void startOutgoing() throws IllegalStateException, SmackException, InterruptedException
This is the starting point for intitiating a new session.- Throws:
IllegalStateException
- if an illegal state was encounteredSmackException
- if Smack detected an exceptional situation.InterruptedException
- if the calling thread was interrupted.
-
startIncoming
public void startIncoming()
This is the starting point for responding to a new session.
-
doStart
protected void doStart()
Description copied from class:JingleNegotiator
Each of the negotiators has their individual behavior when they start.- Specified by:
doStart
in classJingleNegotiator
-
addJingleMediaSession
public void addJingleMediaSession(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.- Parameters:
mediaManagerName
- the name of the media manager.mediaSession
- the jingle media session.
-
getMediaSession
public JingleMediaSession getMediaSession(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.- Parameters:
mediaManagerName
- the name of the media manager.- Returns:
- the jingle media session.
-
-