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