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 java.util.logging.Level; 020import java.util.logging.Logger; 021 022import org.jivesoftware.smack.SmackException; 023import org.jivesoftware.smack.SmackException.NoResponseException; 024import org.jivesoftware.smack.SmackException.NotConnectedException; 025import org.jivesoftware.smack.XMPPConnection; 026import org.jivesoftware.smack.XMPPException; 027import org.jivesoftware.smack.XMPPException.XMPPErrorException; 028 029import org.jivesoftware.smackx.jingleold.JingleSession; 030import org.jivesoftware.smackx.jingleold.listeners.CreatedJingleSessionListener; 031import org.jivesoftware.smackx.jingleold.listeners.JingleSessionListener; 032import org.jivesoftware.smackx.jingleold.media.PayloadType; 033 034@SuppressWarnings("UnusedVariable") 035public class ICETransportManager extends JingleTransportManager implements JingleSessionListener, CreatedJingleSessionListener { 036 private static final Logger LOGGER = Logger.getLogger(ICETransportManager.class.getName()); 037 038 ICEResolver iceResolver = null; 039 040 public ICETransportManager(XMPPConnection xmppConnection, String server, int port) { 041 iceResolver = new ICEResolver(xmppConnection, server, port); 042 try { 043 iceResolver.initializeAndWait(); 044 } 045 catch (Exception e) { 046 LOGGER.log(Level.WARNING, "exception", e); 047 } 048 } 049 050 @Override 051 protected TransportResolver createResolver(JingleSession session) throws SmackException, InterruptedException { 052 try { 053 iceResolver.resolve(session); 054 } 055 catch (XMPPException e) { 056 LOGGER.log(Level.WARNING, "exception", e); 057 } 058 return iceResolver; 059 } 060 061 // Implement a Session Listener to relay candidates after establishment 062 063 @Override 064 public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc, JingleSession jingleSession) throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException { 065 if (lc instanceof ICECandidate) { 066 if (((ICECandidate) lc).getType().equals(ICECandidate.Type.relay)) { 067 RTPBridge rtpBridge = RTPBridge.relaySession(lc.getConnection(), lc.getSessionId(), lc.getPassword(), rc, lc); 068 } 069 } 070 } 071 072 @Override 073 public void sessionDeclined(String reason, JingleSession jingleSession) { 074 } 075 076 @Override 077 public void sessionRedirected(String redirection, JingleSession jingleSession) { 078 } 079 080 @Override 081 public void sessionClosed(String reason, JingleSession jingleSession) { 082 } 083 084 @Override 085 public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) { 086 } 087 088 @Override 089 public void sessionMediaReceived(JingleSession jingleSession, String participant) { 090 // Do Nothing 091 } 092 093 // Session Created 094 095 @Override 096 public void sessionCreated(JingleSession jingleSession) { 097 jingleSession.addListener(this); 098 } 099}