mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
Continue working on Jingle.
git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@7708 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
@ -22,6 +22,7 @@ import org.jivesoftware.smackx.jingle.media.PayloadType;
|
||||
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.ui.ChatRoom;
|
||||
import org.jivesoftware.spark.ui.ChatRoomClosingListener;
|
||||
import org.jivesoftware.spark.util.TaskEngine;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
import org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster;
|
||||
@ -40,7 +41,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Incoming call handles a single incoming Jingle call.
|
||||
*/
|
||||
public class IncomingCall implements JingleSessionListener {
|
||||
public class IncomingCall implements JingleSessionListener, ChatRoomClosingListener {
|
||||
|
||||
private SparkToaster toasterManager;
|
||||
|
||||
@ -273,4 +274,19 @@ public class IncomingCall implements JingleSessionListener {
|
||||
public void sessionClosedOnError(XMPPException xmppException, JingleSession jingleSession) {
|
||||
showCallEndedState();
|
||||
}
|
||||
|
||||
|
||||
public void closing() {
|
||||
if (session != null) {
|
||||
try {
|
||||
session.terminate();
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JingleStateManager.getInstance().removeJingleSession(chatRoom);
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,12 +16,9 @@ import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smackx.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.JingleSessionRequest;
|
||||
import org.jivesoftware.smackx.jingle.OutgoingJingleSession;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener;
|
||||
import org.jivesoftware.smackx.jingle.media.PayloadType;
|
||||
import org.jivesoftware.smackx.jingle.mediaimpl.jmf.JmfMediaManager;
|
||||
import org.jivesoftware.smackx.jingle.mediaimpl.jspeex.SpeexMediaManager;
|
||||
import org.jivesoftware.smackx.jingle.mediaimpl.multi.MultiMediaManager;
|
||||
@ -29,7 +26,6 @@ import org.jivesoftware.smackx.jingle.nat.BridgedTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.nat.ICETransportManager;
|
||||
import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.nat.STUN;
|
||||
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
||||
import org.jivesoftware.spark.PresenceManager;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
@ -37,13 +33,9 @@ import org.jivesoftware.spark.phone.Phone;
|
||||
import org.jivesoftware.spark.phone.PhoneManager;
|
||||
import org.jivesoftware.spark.plugin.Plugin;
|
||||
import org.jivesoftware.spark.ui.ChatRoom;
|
||||
import org.jivesoftware.spark.ui.ChatRoomListenerAdapter;
|
||||
import org.jivesoftware.spark.ui.ChatRoomNotFoundException;
|
||||
import org.jivesoftware.spark.ui.TranscriptWindow;
|
||||
import org.jivesoftware.spark.ui.rooms.ChatRoomImpl;
|
||||
import org.jivesoftware.spark.util.SwingWorker;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
import org.jivesoftware.sparkplugin.JingleStateManager.JingleRoomState;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
@ -65,14 +57,10 @@ import java.util.Map;
|
||||
/**
|
||||
* A simple Jingle Plugin for Spark that uses server Media Proxy for the transport and NAT Traversal
|
||||
*/
|
||||
public class JinglePlugin implements Plugin, JingleSessionListener, Phone {
|
||||
|
||||
private final Map<String, JingleSession> sessions = new HashMap<String, JingleSession>();
|
||||
public class JinglePlugin implements Plugin, Phone {
|
||||
|
||||
private JingleManager jingleManager;
|
||||
|
||||
private JingleStateManager stateManager;
|
||||
|
||||
private static final String JINGLE_NAMESPACE = "http://www.xmpp.org/extensions/xep-0166.html#ns";
|
||||
|
||||
private Map<String, Boolean> jingleFeature = new HashMap<String, Boolean>();
|
||||
@ -82,9 +70,6 @@ public class JinglePlugin implements Plugin, JingleSessionListener, Phone {
|
||||
// Add to PhoneManager
|
||||
PhoneManager.getInstance().addPhone(this);
|
||||
|
||||
// Initialize state manager.
|
||||
stateManager = JingleStateManager.getInstance();
|
||||
|
||||
// Adds a tab handler.
|
||||
SparkManager.getChatManager().addSparkTabHandler(new JingleTabHandler());
|
||||
|
||||
@ -161,18 +146,6 @@ public class JinglePlugin implements Plugin, JingleSessionListener, Phone {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// If a ChatRoom containing a JingleSession is closed, end the jingle session.
|
||||
SparkManager.getChatManager().addChatRoomListener(new ChatRoomListenerAdapter() {
|
||||
public void chatRoomClosed(ChatRoom room) {
|
||||
if (room instanceof ChatRoomImpl) {
|
||||
final ChatRoomImpl roomImpl = (ChatRoomImpl)room;
|
||||
if (sessions.containsKey(roomImpl.getJID())) {
|
||||
endCall(roomImpl);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -221,32 +194,15 @@ public class JinglePlugin implements Plugin, JingleSessionListener, Phone {
|
||||
return actions;
|
||||
}
|
||||
|
||||
public void endCall(ChatRoomImpl room) {
|
||||
JingleSession session = sessions.get(room.getJID());
|
||||
if (session == null) return;
|
||||
try {
|
||||
session.terminate();
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
sessions.remove(room.getJID());
|
||||
|
||||
// Update state
|
||||
stateManager.removeJingleSession(room);
|
||||
|
||||
// Notify state changed.
|
||||
SparkManager.getChatManager().notifySparkTabHandlers(room);
|
||||
}
|
||||
|
||||
public void placeCall(String jid) {
|
||||
jid = SparkManager.getUserManager().getFullJID(jid);
|
||||
|
||||
if (sessions.containsKey(jid)) {
|
||||
ChatRoom room = SparkManager.getChatManager().getChatRoom(StringUtils.parseBareAddress(jid));
|
||||
if (JingleStateManager.getInstance().getJingleRoomState(room) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChatRoom room = SparkManager.getChatManager().getChatRoom(StringUtils.parseBareAddress(jid));
|
||||
SparkManager.getChatManager().getChatContainer().activateChatRoom(room);
|
||||
|
||||
// Create a new Jingle Call with a full JID
|
||||
@ -260,12 +216,9 @@ public class JinglePlugin implements Plugin, JingleSessionListener, Phone {
|
||||
|
||||
// Start the call
|
||||
if (session != null) {
|
||||
session.addListener(this);
|
||||
session.start();
|
||||
sessions.put(jid, session);
|
||||
}
|
||||
|
||||
|
||||
TranscriptWindow transcriptWindow = room.getTranscriptWindow();
|
||||
StyledDocument doc = (StyledDocument)transcriptWindow.getDocument();
|
||||
Style style = doc.addStyle("StyleName", null);
|
||||
@ -283,12 +236,6 @@ public class JinglePlugin implements Plugin, JingleSessionListener, Phone {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
// Update state
|
||||
stateManager.addJingleSession(room, JingleRoomState.ringing);
|
||||
|
||||
// Notify state change
|
||||
SparkManager.getChatManager().notifySparkTabHandlers(room);
|
||||
|
||||
room.scrollToBottom();
|
||||
}
|
||||
|
||||
@ -302,66 +249,6 @@ public class JinglePlugin implements Plugin, JingleSessionListener, Phone {
|
||||
public void uninstall() {
|
||||
}
|
||||
|
||||
public void sessionEstablished(PayloadType payloadType, TransportCandidate transportCandidate, TransportCandidate transportCandidate1, JingleSession jingleSession) {
|
||||
}
|
||||
|
||||
public void sessionDeclined(String string, JingleSession jingleSession) {
|
||||
removeJingleSession(jingleSession);
|
||||
}
|
||||
|
||||
public void sessionRedirected(String string, JingleSession jingleSession) {
|
||||
}
|
||||
|
||||
public void sessionClosed(String string, JingleSession jingleSession) {
|
||||
if (jingleSession instanceof OutgoingJingleSession) {
|
||||
OutgoingJingleSession session = (OutgoingJingleSession)jingleSession;
|
||||
if (session.getState() instanceof OutgoingJingleSession.Active) {
|
||||
}
|
||||
else if (session.getState() instanceof OutgoingJingleSession.Pending) {
|
||||
}
|
||||
}
|
||||
removeJingleSession(jingleSession);
|
||||
}
|
||||
|
||||
public void sessionClosedOnError(XMPPException xmppException, JingleSession jingleSession) {
|
||||
removeJingleSession(jingleSession);
|
||||
}
|
||||
|
||||
private void removeJingleSession(JingleSession jingleSession) {
|
||||
try {
|
||||
if (sessions.containsValue(jingleSession)) {
|
||||
String found = null;
|
||||
for (String key : sessions.keySet()) {
|
||||
System.err.println("D:" + key);
|
||||
if (jingleSession.equals(sessions.get(key))) {
|
||||
found = key;
|
||||
}
|
||||
}
|
||||
System.err.println("REMOVED:" + found);
|
||||
if (found != null)
|
||||
sessions.remove(found);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Do Nothing
|
||||
}
|
||||
|
||||
// Remove from room
|
||||
String jid = jingleSession.getResponder();
|
||||
ChatRoom chatRoom = null;
|
||||
try {
|
||||
chatRoom = SparkManager.getChatManager().getChatContainer().getChatRoom(StringUtils.parseBareAddress(jid));
|
||||
// Update state
|
||||
stateManager.removeJingleSession(chatRoom);
|
||||
|
||||
// Notify state changed.
|
||||
SparkManager.getChatManager().notifySparkTabHandlers(chatRoom);
|
||||
}
|
||||
catch (ChatRoomNotFoundException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify user that a new incoming jingle request has been receieved.
|
||||
@ -369,7 +256,7 @@ public class JinglePlugin implements Plugin, JingleSessionListener, Phone {
|
||||
* @param request the <code>JingleSessionRequest</code>.
|
||||
*/
|
||||
private void incomingJingleSession(JingleSessionRequest request) {
|
||||
final IncomingCall incomingCall = new IncomingCall(request);
|
||||
new IncomingCall(request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -15,10 +15,14 @@ import org.jivesoftware.smackx.jingle.IncomingJingleSession;
|
||||
import org.jivesoftware.smackx.jingle.JingleNegotiator;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.OutgoingJingleSession;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener;
|
||||
import org.jivesoftware.smackx.jingle.listeners.JingleSessionStateListener;
|
||||
import org.jivesoftware.smackx.jingle.media.PayloadType;
|
||||
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.component.FileDragLabel;
|
||||
import org.jivesoftware.spark.ui.ChatRoom;
|
||||
import org.jivesoftware.spark.ui.ChatRoomClosingListener;
|
||||
import org.jivesoftware.spark.ui.ContactItem;
|
||||
import org.jivesoftware.spark.ui.ContactList;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
@ -49,7 +53,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Handles UI controls for outgoing jingle calls.
|
||||
*/
|
||||
public class OutgoingCall extends JPanel implements JingleSessionStateListener {
|
||||
public class OutgoingCall extends JPanel implements JingleSessionStateListener, JingleSessionListener, ChatRoomClosingListener {
|
||||
|
||||
private FileDragLabel imageLabel = new FileDragLabel();
|
||||
private JLabel titleLabel = new JLabel();
|
||||
@ -113,7 +117,6 @@ public class OutgoingCall extends JPanel implements JingleSessionStateListener {
|
||||
answerButton.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(73, 113, 196)));
|
||||
|
||||
setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.white));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,6 +128,11 @@ public class OutgoingCall extends JPanel implements JingleSessionStateListener {
|
||||
*/
|
||||
public void handleOutgoingCall(final JingleSession session, ChatRoom chatRoom, final String jid) {
|
||||
this.chatRoom = chatRoom;
|
||||
|
||||
JingleStateManager.getInstance().addJingleSession(chatRoom, JingleStateManager.JingleRoomState.ringing);
|
||||
|
||||
chatRoom.addClosingListener(this);
|
||||
session.addListener(this);
|
||||
cancelButton.setVisible(true);
|
||||
|
||||
this.session = session;
|
||||
@ -157,15 +165,17 @@ public class OutgoingCall extends JPanel implements JingleSessionStateListener {
|
||||
makeClickable(imageLabel);
|
||||
makeClickable(titleLabel);
|
||||
makeClickable(answerButton);
|
||||
|
||||
// Notify state change
|
||||
SparkManager.getChatManager().notifySparkTabHandlers(chatRoom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UI to reflect the current state.
|
||||
*/
|
||||
private void updateOutgoingCallPanel() {
|
||||
|
||||
if (session == null || session.isClosed()) {
|
||||
showCallEndedState();
|
||||
return;
|
||||
}
|
||||
else if (session instanceof OutgoingJingleSession) {
|
||||
answerButton.setVisible(false);
|
||||
@ -212,10 +222,14 @@ public class OutgoingCall extends JPanel implements JingleSessionStateListener {
|
||||
/**
|
||||
* Called when the call has ended.
|
||||
*/
|
||||
private void showCallEndedState() {
|
||||
final SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy h:mm a");
|
||||
titleLabel.setText("Voice chat ended on " + formatter.format(new Date()));
|
||||
|
||||
private void showCallEndedState(boolean answered) {
|
||||
if (answered) {
|
||||
final SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy h:mm a");
|
||||
titleLabel.setText("Voice chat ended on " + formatter.format(new Date()));
|
||||
}
|
||||
else {
|
||||
titleLabel.setText("Voice chat was rejected.");
|
||||
}
|
||||
|
||||
showAlert(true);
|
||||
cancelButton.setVisible(false);
|
||||
@ -357,4 +371,40 @@ public class OutgoingCall extends JPanel implements JingleSessionStateListener {
|
||||
}
|
||||
|
||||
|
||||
public void closing() {
|
||||
try {
|
||||
session.terminate();
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
Log.error(e);
|
||||
}
|
||||
|
||||
JingleStateManager.getInstance().removeJingleSession(chatRoom);
|
||||
}
|
||||
|
||||
public void sessionEstablished(PayloadType payloadType, TransportCandidate transportCandidate, TransportCandidate transportCandidate1, JingleSession jingleSession) {
|
||||
}
|
||||
|
||||
public void sessionDeclined(String string, JingleSession jingleSession) {
|
||||
}
|
||||
|
||||
public void sessionRedirected(String string, JingleSession jingleSession) {
|
||||
}
|
||||
|
||||
public void sessionClosed(String string, JingleSession jingleSession) {
|
||||
if (jingleSession instanceof OutgoingJingleSession) {
|
||||
OutgoingJingleSession session = (OutgoingJingleSession)jingleSession;
|
||||
if (session.getState() instanceof OutgoingJingleSession.Active) {
|
||||
showCallEndedState(true);
|
||||
}
|
||||
else if (session.getState() instanceof OutgoingJingleSession.Pending) {
|
||||
showCallEndedState(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sessionClosedOnError(XMPPException xmppException, JingleSession jingleSession) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user