Asterisk-Java

org.asteriskjava.manager.event
Class DtmfEvent

java.lang.Object
  extended by java.util.EventObject
      extended by org.asteriskjava.manager.event.ManagerEvent
          extended by org.asteriskjava.manager.event.DtmfEvent
All Implemented Interfaces:
java.io.Serializable

public class DtmfEvent
extends ManagerEvent

A DtmfEvent is triggered each time a DTMF digit is sent or received on a channel.

To support variable-length DTMF Asterisk (since 1.4.0) interally uses two different frames for DTMF releated events (AST_FRAME_DTMF_BEGIN and AST_FRAME_DTMF_END). Before 1.4.0 Asterisk only used one frame (AST_FRAME_DTMF) which is now an alias for AST_FRAME_DTMF_END.
Many other systems and devices (like mobile phone providers) do not support variable-length DTMF. In these cases you will only see AST_FRAME_DTMF_END frames in Asterisk.
When building DTMF aware applications you should not rely on AST_FRAME_DTMF_BEGIN. Generally it is safe to just ignore them and only react on AST_FRAME_DTMF_END frames.
To check whether an DtmfEvent represents an AST_FRAME_DTMF_BEGIN or AST_FRAME_DTMF_END frame use the isBegin() and isEnd() methods.

You can find more information on how Asterisk handles DTMF in the DTMF article at voip-info.org

It is implemented in main/channel.c.

Available since Asterisk 1.6

Since:
1.0.0
Version:
$Id: DtmfEvent.java 961 2008-02-03 02:53:56Z srt $
Author:
srt
See Also:
Serialized Form

Field Summary
static java.lang.String DIRECTION_RECEIVED
           
static java.lang.String DIRECTION_SENT
           
 
Fields inherited from class java.util.EventObject
source
 
Constructor Summary
DtmfEvent(java.lang.Object source)
          Creates a new DtmfEvent.
 
Method Summary
 java.lang.String getChannel()
          Returns the name of the channel the DTMF digit was sent or received on.
 java.lang.String getDigit()
          Returns the DTMF digit that was sent or received.
 java.lang.String getDirection()
          Returns whether the DTMF digit was sent or received.
 java.lang.String getUniqueId()
          Returns the unique id of the the channel the DTMF digit was sent or received on.
 java.lang.Boolean isBegin()
          Returns whether this event represents an AST_FRAME_DTMF_BEGIN frame.
 boolean isEnd()
          Returns whether this event represents an AST_FRAME_DTMF_END frame.
 boolean isReceived()
          Returns whether the DTMF digit was received by Asterisk (sent from the device to Asterisk).
 boolean isSent()
          Returns whether the DTMF digit was sent from Asterisk to the device.
 void setBegin(java.lang.Boolean begin)
          Sets whether this event represents an AST_FRAME_DTMF_BEGIN frame.
 void setChannel(java.lang.String channel)
          Sets the name of the channel.
 void setDigit(java.lang.String digit)
          Sets the DTMF digit that was sent or received.
 void setDirection(java.lang.String direction)
          Sets whether the DTMF digit was sent or received.
 void setEnd(java.lang.Boolean end)
          Sets whether this event represents an AST_FRAME_DTMF_END frame.
 void setUniqueId(java.lang.String uniqueId)
          Sets the unique id of the the channel.
 
Methods inherited from class org.asteriskjava.manager.event.ManagerEvent
appendPropertyIfNotNull, getDateReceived, getFile, getFunc, getLine, getPrivilege, getSequenceNumber, getServer, getTimestamp, setDateReceived, setFile, setFunc, setLine, setPrivilege, setSequenceNumber, setServer, setTimestamp, toString
 
Methods inherited from class java.util.EventObject
getSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DIRECTION_RECEIVED

public static final java.lang.String DIRECTION_RECEIVED
See Also:
Constant Field Values

DIRECTION_SENT

public static final java.lang.String DIRECTION_SENT
See Also:
Constant Field Values
Constructor Detail

DtmfEvent

public DtmfEvent(java.lang.Object source)
Creates a new DtmfEvent.

Parameters:
source -
Method Detail

getChannel

public java.lang.String getChannel()
Returns the name of the channel the DTMF digit was sent or received on. The channel name is of the form "Zap/<channel number>".

Returns:
the channel name.

setChannel

public void setChannel(java.lang.String channel)
Sets the name of the channel.

Parameters:
channel - the channel name.

getUniqueId

public java.lang.String getUniqueId()
Returns the unique id of the the channel the DTMF digit was sent or received on.

Returns:
the unique id of the channel.

setUniqueId

public void setUniqueId(java.lang.String uniqueId)
Sets the unique id of the the channel.

Parameters:
uniqueId - the unique id of the the channel.

getDigit

public java.lang.String getDigit()
Returns the DTMF digit that was sent or received.

Returns:
the DTMF digit that was sent or received.

setDigit

public void setDigit(java.lang.String digit)
Sets the DTMF digit that was sent or received.

Parameters:
digit - the DTMF digit that was sent or received.

getDirection

public java.lang.String getDirection()
Returns whether the DTMF digit was sent or received.

Possible values are:

Returns:
"Reveived" if the DTMF was received (sent from the device to Asterisk) or "Sent" if the DTMF digit was sent (sent from Asterisk to the device).
See Also:
DIRECTION_RECEIVED, DIRECTION_SENT

setDirection

public void setDirection(java.lang.String direction)
Sets whether the DTMF digit was sent or received.

Parameters:
direction - "Received" or "Sent".

isBegin

public java.lang.Boolean isBegin()
Returns whether this event represents an AST_FRAME_DTMF_BEGIN frame.

Gerally your application will want to ignore begin events. You will only need them if you want to make use of the duration a DTMF key was pressed.

Note that there will be DTMF end events without a corresponding begin event as not all systems (including Asterisk prior to 1.4.0) support variable-length DTMF.

Returns:
true if this is a DTMF begin event (key pressed), false otherwise.

setBegin

public void setBegin(java.lang.Boolean begin)
Sets whether this event represents an AST_FRAME_DTMF_BEGIN frame.

Parameters:
begin - true if this is a DTMF begin event (key pressed), false otherwise.

isEnd

public boolean isEnd()
Returns whether this event represents an AST_FRAME_DTMF_END frame.

DTMF information received from systems that do not support variable-length DTMF you will only see DTMF end events.

Returns:
true if this is a DTMF end event (key released), false otherwise.

setEnd

public void setEnd(java.lang.Boolean end)
Sets whether this event represents an AST_FRAME_DTMF_END frame.

Parameters:
end - true if this is a DTMF end event (key released), false otherwise.

isReceived

public boolean isReceived()
Returns whether the DTMF digit was received by Asterisk (sent from the device to Asterisk).

Returns:
true if the DTMF digit was received by Asterisk, false otherwise.
See Also:
getDirection()

isSent

public boolean isSent()
Returns whether the DTMF digit was sent from Asterisk to the device.

Returns:
true if the DTMF digit was sent from Asterisk to the device, false otherwise.
See Also:
getDirection()

Asterisk-Java

Copyright © 2004-2009 Stefan Reuter. All Rights Reserved.