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; 020import org.jivesoftware.smack.SmackException.NotConnectedException; 021import org.jivesoftware.smack.XMPPConnection; 022import org.jivesoftware.smack.XMPPException; 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 028public class ICETransportManager extends JingleTransportManager implements JingleSessionListener, CreatedJingleSessionListener { 029 030 ICEResolver iceResolver = null; 031 032 public ICETransportManager(XMPPConnection xmppConnection, String server, int port) { 033 iceResolver = new ICEResolver(xmppConnection, server, port); 034 try { 035 iceResolver.initializeAndWait(); 036 } 037 catch (Exception e) { 038 e.printStackTrace(); 039 } 040 } 041 042 protected TransportResolver createResolver(JingleSession session) throws SmackException { 043 try { 044 iceResolver.resolve(session); 045 } 046 catch (XMPPException e) { 047 e.printStackTrace(); 048 } 049 return iceResolver; 050 } 051 052 // Implement a Session Listener to relay candidates after establishment 053 054 public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) throws NotConnectedException { 055 if (lc instanceof ICECandidate) { 056 if (((ICECandidate) lc).getType().equals("relay")) { 057 RTPBridge rtpBridge = RTPBridge.relaySession(lc.getConnection(), lc.getSessionId(), lc.getPassword(), rc, lc); 058 } 059 } 060 } 061 062 public void sessionDeclined(String reason, JingleSession jingleSession) { 063 } 064 065 public void sessionRedirected(String redirection, JingleSession jingleSession) { 066 } 067 068 public void sessionClosed(String reason, JingleSession jingleSession) { 069 } 070 071 public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) { 072 } 073 074 public void sessionMediaReceived(JingleSession jingleSession, String participant) { 075 // Do Nothing 076 } 077 078 // Session Created 079 080 public void sessionCreated(JingleSession jingleSession) { 081 jingleSession.addListener(this); 082 } 083}