001/**
002 *
003 * Copyright 2003-2006 Jive Software.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.jingleold.nat;
018
019import org.jivesoftware.smack.SmackException.NotConnectedException;
020import org.jivesoftware.smack.XMPPConnection;
021import org.jivesoftware.smack.XMPPException;
022
023import org.jivesoftware.smackx.jingleold.JingleSession;
024import org.jivesoftware.smackx.jingleold.listeners.CreatedJingleSessionListener;
025import org.jivesoftware.smackx.jingleold.listeners.JingleSessionListener;
026import org.jivesoftware.smackx.jingleold.media.PayloadType;
027
028/**
029 * A Jingle Transport Manager implementation to be used for NAT Networks.
030 * This kind of transport needs that the connected XMPP Server provide a Bridge Service. (http://www.jivesoftware.com/protocol/rtpbridge)
031 * To relay the jmf outside the NAT.
032 *
033 * @author Thiago Camargo
034 */
035@SuppressWarnings("UnusedVariable")
036public class BridgedTransportManager extends JingleTransportManager implements JingleSessionListener, CreatedJingleSessionListener {
037
038    XMPPConnection xmppConnection;
039
040    public BridgedTransportManager(XMPPConnection xmppConnection) {
041        super();
042        this.xmppConnection = xmppConnection;
043    }
044
045    /**
046     * Return the correspondent resolver
047     *
048     * @param session correspondent Jingle Session
049     * @return resolver TODO javadoc me please
050     */
051    @Override
052    protected TransportResolver createResolver(JingleSession session) {
053        BridgedResolver bridgedResolver = new BridgedResolver(this.xmppConnection);
054        return bridgedResolver;
055    }
056
057    // Implement a Session Listener to relay candidates after establishment
058
059    @Override
060    public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) throws NotConnectedException, InterruptedException {
061        RTPBridge rtpBridge = RTPBridge.relaySession(lc.getConnection(), lc.getSessionId(), lc.getPassword(), rc, lc);
062    }
063
064    @Override
065    public void sessionDeclined(String reason, JingleSession jingleSession) {
066    }
067
068    @Override
069    public void sessionRedirected(String redirection, JingleSession jingleSession) {
070    }
071
072    @Override
073    public void sessionClosed(String reason, JingleSession jingleSession) {
074    }
075
076    @Override
077    public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
078    }
079
080    @Override
081    public void sessionMediaReceived(JingleSession jingleSession, String participant) {
082        // Do Nothing
083    }
084
085    // Session Created
086
087    @Override
088    public void sessionCreated(JingleSession jingleSession) {
089        jingleSession.addListener(this);
090    }
091}