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;
022import org.jivesoftware.smackx.jingleold.JingleSession;
023import org.jivesoftware.smackx.jingleold.listeners.CreatedJingleSessionListener;
024import org.jivesoftware.smackx.jingleold.listeners.JingleSessionListener;
025import org.jivesoftware.smackx.jingleold.media.PayloadType;
026
027/**
028 * A Jingle Transport Manager implementation to be used for NAT Networks.
029 * This kind of transport needs that the connected XMPP Server provide a Bridge Service. (http://www.jivesoftware.com/protocol/rtpbridge)
030 * To relay the jmf outside the NAT.
031 *
032 * @author Thiago Camargo
033 */
034public class BridgedTransportManager extends JingleTransportManager implements JingleSessionListener, CreatedJingleSessionListener {
035
036    XMPPConnection xmppConnection;
037
038    public BridgedTransportManager(XMPPConnection xmppConnection) {
039        super();
040        this.xmppConnection = xmppConnection;
041    }
042
043    /**
044     * Return the correspondent resolver
045     *
046     * @param session correspondent Jingle Session
047     * @return resolver
048     */
049    @Override
050    protected TransportResolver createResolver(JingleSession session) {
051        BridgedResolver bridgedResolver = new BridgedResolver(this.xmppConnection);
052        return bridgedResolver;
053    }
054
055    // Implement a Session Listener to relay candidates after establishment
056
057    @Override
058    public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) throws NotConnectedException, InterruptedException {
059        RTPBridge rtpBridge = RTPBridge.relaySession(lc.getConnection(), lc.getSessionId(), lc.getPassword(), rc, lc);
060    }
061
062    @Override
063    public void sessionDeclined(String reason, JingleSession jingleSession) {
064    }
065
066    @Override
067    public void sessionRedirected(String redirection, JingleSession jingleSession) {
068    }
069
070    @Override
071    public void sessionClosed(String reason, JingleSession jingleSession) {
072    }
073
074    @Override
075    public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
076    }
077
078    @Override
079    public void sessionMediaReceived(JingleSession jingleSession, String participant) {
080        // Do Nothing
081    }
082
083    // Session Created
084
085    @Override
086    public void sessionCreated(JingleSession jingleSession) {
087        jingleSession.addListener(this);
088    }
089}