Adds dtmf support for jabber calls.

cusax-fix
Damian Minkov 15 years ago
parent de8a65cc55
commit b809c0f68b

@ -892,6 +892,7 @@ plugin.jabberaccregwizz.EXISTING_ACCOUNT=Existing XMPP account
plugin.jabberaccregwizz.DOMAIN_BYPASS_CAPS=Domain that will use GTalk call
plugin.jabberaccregwizz.TELEPHONY_DOMAIN=Telephony domain
plugin.jabberaccregwizz.ALLOW_NON_SECURE=Allow non-secure connections
plugin.jabberaccregwizz.DTMF_AUTO=Auto: Choose automatically between RTP and Inband
# mailbox
plugin.mailbox.OUTGOING=Outgoing Message:

@ -0,0 +1,208 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.jabber;
import java.util.*;
import net.java.sip.communicator.impl.neomedia.codec.*;
import net.java.sip.communicator.service.neomedia.*;
import net.java.sip.communicator.service.neomedia.format.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
/**
* Class responsible for sending a DTMF Tone using using rfc4733 or Inband.
*
* @author Damian Minkov
*/
public class OperationSetDTMFJabberImpl
implements OperationSetDTMF
{
/**
* Our class logger.
*/
private static final Logger logger
= Logger.getLogger(OperationSetDTMFJabberImpl.class);
/**
* The DTMF method used to send tones.
*/
private DTMFMethod dtmfMethod;
/**
* Constructor.
*
* @param pps the Jabber Protocol provider service
*/
public OperationSetDTMFJabberImpl(ProtocolProviderServiceJabberImpl pps)
{
this.dtmfMethod = this.getDTMFMethod(pps);
}
/**
* Sends the <tt>DTMFTone</tt> <tt>tone</tt> to <tt>callPeer</tt>.
*
* @param callPeer the call peer to send <tt>tone</tt> to.
* @param tone the DTMF tone to send to <tt>callPeer</tt>.
*
* @throws OperationFailedException with code OPERATION_NOT_SUPPORTED if
* DTMF tones are not supported for <tt>callPeer</tt>.
*
* @throws NullPointerException if one of the arguments is null.
*
* @throws IllegalArgumentException in case the call peer does not
* belong to the underlying implementation.
*/
public synchronized void startSendingDTMF(CallPeer callPeer, DTMFTone tone)
throws OperationFailedException
{
if (callPeer == null || tone == null)
{
throw new NullPointerException("Argument is null");
}
if (! (callPeer instanceof CallPeerJabberImpl))
{
throw new IllegalArgumentException();
}
CallPeerJabberImpl cp = (CallPeerJabberImpl)callPeer;
DTMFMethod cpDTMFMethod = dtmfMethod;
// If "auto" DTMF mode selected, automatically selects RTP DTMF is
// telephon-event is available. Otherwise selects INBAND DMTF.
if(this.dtmfMethod == DTMFMethod.AUTO_DTMF)
{
if(isRFC4733Active(cp))
{
cpDTMFMethod = DTMFMethod.RTP_DTMF;
}
else
{
cpDTMFMethod = DTMFMethod.INBAND_DTMF;
}
}
// If the account is configured to use RTP DTMF method and the call
// does not manage telephone events. Then, we log it for future
// debugging.
if(this.dtmfMethod == DTMFMethod.RTP_DTMF && !isRFC4733Active(cp))
{
logger.debug("RTP DTMF used without telephone-event capacities");
}
((AudioMediaStream)cp.getMediaHandler().getStream(MediaType.AUDIO))
.startSendingDTMF(tone, cpDTMFMethod);
}
/**
* Stops sending DTMF.
*
* @param callPeer the call peer that we'd like to stop sending DTMF to.
*/
public synchronized void stopSendingDTMF(CallPeer callPeer)
{
if (callPeer == null)
{
throw new NullPointerException("Argument is null");
}
if (! (callPeer instanceof CallPeerJabberImpl))
{
throw new IllegalArgumentException();
}
CallPeerJabberImpl cp = (CallPeerJabberImpl) callPeer;
DTMFMethod cpDTMFMethod = dtmfMethod;
// If "auto" DTMF mode selected, automatically selects RTP DTMF is
// telephon-event is available. Otherwise selects INBAND DMTF.
if(this.dtmfMethod == DTMFMethod.AUTO_DTMF)
{
if(isRFC4733Active(cp))
{
cpDTMFMethod = DTMFMethod.RTP_DTMF;
}
else
{
cpDTMFMethod = DTMFMethod.INBAND_DTMF;
}
}
// If the account is configured to use RTP DTMF method and the call
// does not manage telephone events. Then, we log it for future
// debugging.
if(this.dtmfMethod == DTMFMethod.RTP_DTMF && !isRFC4733Active(cp))
{
logger.debug("RTP DTMF used without telephone-event capacities");
}
((AudioMediaStream)cp.getMediaHandler().getStream(MediaType.AUDIO))
.stopSendingDTMF(cpDTMFMethod);
}
/**
* Checks whether rfc4733 is negotiated for this call.
* @param peer the call peer.
* @return whether we can use rfc4733 in this call.
*/
private boolean isRFC4733Active(CallPeerJabberImpl peer)
{
Iterator<MediaFormat> iter =
peer.getMediaHandler().getStream(MediaType.AUDIO)
.getDynamicRTPPayloadTypes().values().iterator();
while (iter.hasNext())
{
MediaFormat mediaFormat = iter.next();
if(mediaFormat.getEncoding().equals(Constants.TELEPHONE_EVENT))
return true;
}
return false;
}
/**
* Returns the corresponding DTMF method used for this account.
*
* @param pps the Jabber Protocol provider service
*
* @return the DTMFEnum corresponding to the DTMF method set for this
* account.
*/
private DTMFMethod getDTMFMethod(ProtocolProviderServiceJabberImpl pps)
{
AccountID accountID = pps.getAccountID();
String dtmfString = accountID.getAccountPropertyString("DTMF_METHOD");
// Verifies that the DTMF_METHOD property string is correctly set.
// If not, sets this account to the "auto" DTMF method and corrects the
// property string.
if(dtmfString == null
|| (!dtmfString.equals("AUTO_DTMF")
&& !dtmfString.equals("RTP_DTMF")
&& !dtmfString.equals("INBAND_DTMF")))
{
dtmfString = "AUTO_DTMF";
accountID.putAccountProperty("DTMF_METHOD", dtmfString);
}
if(dtmfString.equals("AUTO_DTMF"))
{
return DTMFMethod.AUTO_DTMF;
}
else if(dtmfString.equals("RTP_DTMF"))
{
return DTMFMethod.RTP_DTMF;
}
else // if(dtmfString.equals(INBAND_DTMF"))
{
return DTMFMethod.INBAND_DTMF;
}
}
}

@ -1645,6 +1645,12 @@ protected void initialize(String screenname,
OperationSetBasicAutoAnswer.class,
new OperationSetAutoAnswerJabberImpl(basicTelephony));
// init DTMF
OperationSetDTMFJabberImpl operationSetDTMFSip
= new OperationSetDTMFJabberImpl(this);
addSupportedOperationSet(
OperationSetDTMF.class, operationSetDTMFSip);
addJingleFeatures();
// Check if desktop streaming is enabled.

@ -80,6 +80,16 @@ public class ConnectionPanel
Resources.getString("plugin.jabberaccregwizz.ALLOW_NON_SECURE"),
false);
private JComboBox dtmfMethodBox = new JComboBox(new Object []
{
Resources.getString(
"plugin.jabberaccregwizz.DTMF_AUTO"),
Resources.getString(
"plugin.sipaccregwizz.DTMF_RTP"),
Resources.getString(
"plugin.sipaccregwizz.DTMF_INBAND")
});
private final JabberAccountRegistrationForm parentForm;
/**
@ -180,6 +190,8 @@ public void actionPerformed(ActionEvent e)
mainPanel.add(advancedOpPanel);
mainPanel.add(createDTMFPanel());
String serverAddress = parentForm.getServerAddress();
if (serverAddress != null)
serverField.setText(serverAddress);
@ -187,6 +199,24 @@ public void actionPerformed(ActionEvent e)
add(mainPanel, BorderLayout.NORTH);
}
/**
* Creates the DTMF panel.
* @return the created DTMF panel
*/
private Component createDTMFPanel()
{
JPanel dtmfPanel = new TransparentPanel(new BorderLayout(10, 10));
JLabel dtmfMethodLabel = new JLabel(
Resources.getString("plugin.sipaccregwizz.DTMF_METHOD"));
dtmfPanel.add(dtmfMethodLabel, BorderLayout.WEST);
dtmfMethodBox.setSelectedItem(
parentForm.getRegistration().getDefaultDTMFMethod());
dtmfPanel.add(dtmfMethodBox, BorderLayout.CENTER);
return dtmfPanel;
}
/**
* Returns the server address.
* @return the server address
@ -392,4 +422,67 @@ boolean isAllowNonSecure()
{
return allowNonSecureBox.isSelected();
}
/**
* Returns the DTMF method.
* @return the DTMF method
*/
String getDTMFMethod()
{
Object selItem = dtmfMethodBox.getSelectedItem();
// By default sets DTMF mezthod to auto.
if(selItem == null)
{
return null;
}
String selString = selItem.toString();
if(selString.equals(
Resources.getString("plugin.sipaccregwizz.DTMF_RTP")))
{
return "RTP_DTMF";
}
else if(selString.equals(
Resources.getString("plugin.sipaccregwizz.DTMF_INBAND")))
{
return "INBAND_DTMF";
}
else
{
return "AUTO_DTMF";
}
}
/**
* Sets the DTMF method.
* @param dtmfMethod the DTMF method
*/
void setDTMFMethod(String dtmfMethod)
{
if(dtmfMethod == null)
{
dtmfMethodBox.setSelectedItem(0);
}
else
{
String selString;
if(dtmfMethod.equals("RTP_DTMF"))
{
selString =
Resources.getString("plugin.sipaccregwizz.DTMF_RTP");
}
else if(dtmfMethod.equals("INBAND_DTMF"))
{
selString =
Resources.getString("plugin.sipaccregwizz.DTMF_INBAND");
}
else
{
selString =
Resources.getString("plugin.jabberaccregwizz.DTMF_AUTO");
}
dtmfMethodBox.setSelectedItem(selString);
}
}
}

@ -43,6 +43,8 @@ public class JabberAccountRegistration
*/
public static final boolean DEFAULT_RESOURCE_AUTOGEN = true;
private String defaultDTMFMethod = "AUTO_DTMF";
/**
* The user identifier.
*/
@ -192,6 +194,11 @@ public class JabberAccountRegistration
*/
private String smsServerAddress;
/**
* DTMF method.
*/
private String dtmfMethod = null;
/**
* Returns the password of the jabber registration account.
* @return the password of the jabber registration account.
@ -773,4 +780,40 @@ public void setSmsServerAddress(String serverAddress)
{
this.smsServerAddress = serverAddress;
}
/**
* Returns the DTMF method.
*
* @return the DTMF method.
*/
public String getDTMFMethod()
{
return dtmfMethod;
}
/**
* Sets the DTMF method.
*
* @param dtmfMethod the DTMF method to set
*/
public void setDTMFMethod(String dtmfMethod)
{
this.dtmfMethod = dtmfMethod;
}
/**
* @return the defaultDTMFMethod
*/
public String getDefaultDTMFMethod()
{
return defaultDTMFMethod;
}
/**
* @param defaultDTMFMethod the defaultDTMFMethod to set
*/
public void setDefaultDTMFMethod(String defaultDTMFMethod)
{
this.defaultDTMFMethod = defaultDTMFMethod;
}
}

@ -284,6 +284,8 @@ public boolean commitPage(JabberAccountRegistration registration)
if (priority != null)
registration.setPriority(Integer.parseInt(priority));
registration.setDTMFMethod(connectionPanel.getDTMFMethod());
registration.setUseIce(iceConfigPanel.isUseIce());
registration.setUseGoogleIce(iceConfigPanel.isUseGoogleIce());
registration.setAutoDiscoverStun(iceConfigPanel.isAutoDiscoverStun());
@ -397,6 +399,9 @@ public void loadAccount(AccountID accountID)
connectionPanel.setPriority(priority);
connectionPanel.setDTMFMethod(
accountID.getAccountPropertyString("DTMF_METHOD"));
String useIce =
accountProperties.get(ProtocolProviderFactory.IS_USE_ICE);
boolean isUseIce = Boolean.parseBoolean(

@ -192,6 +192,10 @@ public Iterator<Map.Entry<String,String>> getSummary()
Resources.getString("plugin.jabberaccregwizz.PRIORITY"),
String.valueOf(registration.getPriority()));
summaryTable.put(
Resources.getString("plugin.sipaccregwizz.DTMF_METHOD"),
registration.getDTMFMethod());
return summaryTable.entrySet().iterator();
}
@ -421,6 +425,14 @@ protected ProtocolProviderService installAccount(
accountProperties.put(ProtocolProviderFactory.IS_ALLOW_NON_SECURE,
String.valueOf(registration.isAllowNonSecure()));
if(registration.getDTMFMethod() != null)
accountProperties.put("DTMF_METHOD",
registration.getDTMFMethod());
else
accountProperties.put("DTMF_METHOD",
registration.getDefaultDTMFMethod());
if (isModification())
{
providerFactory.modifyAccount( protocolProvider,

Loading…
Cancel
Save