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.mediaimpl.test; 018 019import java.util.ArrayList; 020import java.util.List; 021 022import org.jivesoftware.smackx.jingleold.JingleSession; 023import org.jivesoftware.smackx.jingleold.media.JingleMediaManager; 024import org.jivesoftware.smackx.jingleold.media.JingleMediaSession; 025import org.jivesoftware.smackx.jingleold.media.PayloadType; 026import org.jivesoftware.smackx.jingleold.nat.JingleTransportManager; 027import org.jivesoftware.smackx.jingleold.nat.TransportCandidate; 028 029/** 030 * Implements a MediaManager for test purposes. 031 * 032 * @author Thiago Camargo 033 */ 034 035public class TestMediaManager extends JingleMediaManager { 036 037 public static final String MEDIA_NAME = "TestMedia"; 038 039 private List<PayloadType> payloads = new ArrayList<>(); 040 041 private PayloadType preferredPayloadType = null; 042 043 public TestMediaManager(JingleTransportManager transportManager) { 044 super(transportManager); 045 } 046 047 /** 048 * Return all supported Payloads for this Manager. 049 * 050 * @return The Payload List 051 */ 052 @Override 053 public List<PayloadType> getPayloads() { 054 return payloads; 055 } 056 057 public void setPayloads(List<PayloadType> payloads) { 058 this.payloads.addAll(payloads); 059 } 060 061 /** 062 * Returns a new JingleMediaSession. 063 * 064 * @param payloadType payloadType 065 * @param remote remote Candidate 066 * @param local local Candidate 067 * @return JingleMediaSession JingleMediaSession 068 */ 069 @Override 070 public JingleMediaSession createMediaSession(PayloadType payloadType, final TransportCandidate remote, 071 final TransportCandidate local, final JingleSession jingleSession) { 072 TestMediaSession session; 073 074 session = new TestMediaSession(payloadType, remote, local, "", jingleSession); 075 076 return session; 077 } 078 079 @Override 080 public PayloadType getPreferredPayloadType() { 081 if (preferredPayloadType != null) 082 return preferredPayloadType; 083 return super.getPreferredPayloadType(); 084 } 085 086 public void setPreferredPayloadType(PayloadType preferredPayloadType) { 087 this.preferredPayloadType = preferredPayloadType; 088 } 089 090 @Override 091 public String getName() { 092 return MEDIA_NAME; 093 } 094}