/** * Full featured JingleSession constructor * * @param conn * the XMPPConnection which is used * @param initiator * the initiator JID * @param responder * the responder JID * @param sessionid * the session ID * @param jingleMediaManagers * the jingleMediaManager */ public JingleSession(XMPPConnection conn, String initiator, String responder, String sessionid, List<JingleMediaManager> jingleMediaManagers) { super(); this.initiator = initiator; this.responder = responder; this.sid = sessionid; this.jingleMediaManagers = jingleMediaManagers; this.setSession(this); this.connection = conn; // Initially, we don't known the session state. setSessionState(JingleSessionStateUnknown.getInstance()); contentNegotiators = new ArrayList<ContentNegotiator>(); mediaSessionMap = new HashMap<String, JingleMediaSession>(); // Add the session to the list and register the listeneres registerInstance(); installConnectionListeners(conn); }
/** * Return all supported Payloads for this Manager. * * @return The Payload List */ public List<PayloadType> getPayloads() { List<PayloadType> list = new ArrayList<PayloadType>(); if (preferredPayloadType != null) list.add(preferredPayloadType); for (JingleMediaManager manager : managers) { for (PayloadType payloadType : manager.getPayloads()) { if (!list.contains(payloadType) && !payloadType.equals(preferredPayloadType)) list.add(payloadType); } } return list; }
/** * Returns a new JingleMediaSession * * @param payloadType payloadType * @param remote remote Candidate * @param local local Candidate * @return JingleMediaSession JingleMediaSession */ public JingleMediaSession createMediaSession(PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local, final JingleSession jingleSession) { for (JingleMediaManager manager : managers) { if (manager.getPayloads().contains(payloadType)) { return manager.createMediaSession(payloadType, remote, local, jingleSession); } } return null; }
/** * Trigger a session established event. * @throws NotConnectedException */ private void triggerContentEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc) throws NotConnectedException { // Let the session know that we've established a content/media segment. JingleSession session = getSession(); if (session != null) { List<JingleListener> listeners = session.getListenersList(); for (JingleListener li : listeners) { if (li instanceof JingleSessionListener) { JingleSessionListener sli = (JingleSessionListener) li; sli.sessionEstablished(pt, rc, lc, session); } } } // Create a media session for each media manager in the session. if (mediaNeg.getMediaManager() != null) { rc.removeCandidateEcho(); lc.removeCandidateEcho(); jingleMediaSession = getMediaNegotiator().getMediaManager().createMediaSession(pt, rc, lc, session); jingleMediaSession.addMediaReceivedListener(session); if (jingleMediaSession != null) { jingleMediaSession.startTrasmit(); jingleMediaSession.startReceive(); for (TransportCandidate candidate : getTransportNegotiator().getOfferedCandidates()) candidate.removeCandidateEcho(); } JingleMediaManager mediaManager = getMediaNegotiator().getMediaManager(); getSession().addJingleMediaSession(mediaManager.getName(), jingleMediaSession); } }
/** * This is the starting point for intitiating a new session. * * @throws IllegalStateException * @throws SmackException */ public void startOutgoing() throws IllegalStateException, SmackException { updatePacketListener(); setSessionState(JingleSessionStatePending.getInstance()); Jingle jingle = new Jingle(JingleActionEnum.SESSION_INITIATE); // Create a content negotiator for each media manager on the session. for (JingleMediaManager mediaManager : getMediaManagers()) { ContentNegotiator contentNeg = new ContentNegotiator(this, ContentNegotiator.INITIATOR, mediaManager.getName()); // Create the media negotiator for this content description. contentNeg.setMediaNegotiator(new MediaNegotiator(this, mediaManager, mediaManager.getPayloads(), contentNeg)); JingleTransportManager transportManager = mediaManager.getTransportManager(); TransportResolver resolver = null; try { resolver = transportManager.getResolver(this); } catch (XMPPException e) { e.printStackTrace(); } if (resolver.getType().equals(TransportResolver.Type.rawupd)) { contentNeg.setTransportNegotiator(new TransportNegotiator.RawUdp(this, resolver, contentNeg)); } if (resolver.getType().equals(TransportResolver.Type.ice)) { contentNeg.setTransportNegotiator(new TransportNegotiator.Ice(this, resolver, contentNeg)); } addContentNegotiator(contentNeg); } // Give each of the content negotiators a chance to return a portion of the structure to make the Jingle packet. for (ContentNegotiator contentNegotiator : contentNegotiators) { jingle.addContent(contentNegotiator.getJingleContent()); } // Save the session-initiate packet ID, so that we can respond to it. sessionInitPacketID = jingle.getStanzaId(); sendStanza(jingle); // Now setup to track the media negotiators, so that we know when (if) to send a session-accept. setupListeners(); // Give each of the content negotiators a chance to start // and return a portion of the structure to make the Jingle packet. // Don't do this anymore. The problem is that the other side might not be ready. // Later when we receive our first jingle packet from the other side we'll fire-up the negotiators // before processing it. (See receivePacketAndRespond() above. // for (ContentNegotiator contentNegotiator : contentNegotiators) { // contentNegotiator.start(); // } }
public void addMediaManager(JingleMediaManager manager) { managers.add(manager); }
public void removeMediaManager(JingleMediaManager manager) { managers.remove(manager); }
/** * JingleSession constructor (for an outgoing Jingle session) * * @param conn * Connection * @param initiator * the initiator JID * @param responder * the responder JID * @param jingleMediaManagers * the jingleMediaManager */ public JingleSession(XMPPConnection conn, JingleSessionRequest request, String initiator, String responder, List<JingleMediaManager> jingleMediaManagers) { this(conn, initiator, responder, generateSessionId(), jingleMediaManagers); //sessionRequest = request; // unused }
/** * Get the Media Manager of this Jingle Session * * @return the JingleMediaManagers */ public List<JingleMediaManager> getMediaManagers() { return jingleMediaManagers; }
/** * Set the Media Manager of this Jingle Session * * @param jingleMediaManagers */ public void setMediaManagers(List<JingleMediaManager> jingleMediaManagers) { this.jingleMediaManagers = jingleMediaManagers; }
/** * Get the Media Managers of this Jingle Manager * * @return the list of JingleMediaManagers */ public List<JingleMediaManager> getMediaManagers() { return jingleMediaManagers; }
/** * Set the Media Managers of this Jingle Manager * * @param jingleMediaManagers JingleMediaManager to be used for open, close, start and stop jmf streamings */ public void setMediaManagers(List<JingleMediaManager> jingleMediaManagers) { this.jingleMediaManagers = jingleMediaManagers; }