|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.orderlysoftware.orderlycalls.asterisk.agi.AGIConnection
public class AGIConnection
AGIConnection objects represent individual calls coming from the FastAGI source (Asterisk).
Asterisk sends a variety of information with the call to the AGIServer. These properties are stored in the agiProperties property. The various other methods are wrappers for FastAGI calls, which execute on the Asterisk server.
All FastAGI calls block until completion.
Constructor Summary | |
---|---|
AGIConnection()
Creates an uninitialised AGIConnection object. |
|
AGIConnection(java.net.Socket connection,
AGIServer server,
AGIProcessor processor)
Initialises the object in preparation for read from Asterisk. |
Method Summary | |
---|---|
int |
answer()
Answers channel if not already in answer state. |
static char |
asciiToChar(int i)
Converts an ASCII value to a java char. |
int |
channelStatus()
Gets the status of the current channel. |
int |
channelStatus(java.lang.String channelName)
Returns the status of the specified channel. |
static int |
charToInt(char c)
Convert a DTMF character to a number. |
void |
clean()
Closes any connections without throwing an exception. |
int |
databaseDel(java.lang.String family,
java.lang.String key)
Deletes an entry in the Asterisk database for a given family and key. |
int |
databaseDelTree(java.lang.String family)
Deletes a family in the Asterisk database. |
int |
databaseDelTree(java.lang.String family,
java.lang.String keyTree)
Deletes a keytree within a specific family in the Asterisk database. |
java.lang.String |
databaseGet(java.lang.String family,
java.lang.String key)
Retrieves an entry in the Asterisk database for a given family and key. |
int |
databasePut(java.lang.String family,
java.lang.String key,
java.lang.String value)
Adds or updates an entry in the Asterisk database. |
java.lang.String |
exec(java.lang.String application,
java.lang.String options)
Executes application with given options. |
static AGIConnection |
getAGIConnection(java.net.Socket connection,
AGIServer server,
AGIProcessor processor)
Gets an AGIConnection object from the pool, and initialises it. |
java.util.HashMap |
getAGIProperties()
Retrieves the properties for this call as received from Asterisk. |
java.lang.String |
getAGIProperty(java.lang.String name)
Gets a particular property for this call. |
java.lang.String |
getData(java.lang.String filename)
|
java.lang.String |
getData(java.lang.String filename,
long timeout)
|
java.lang.String |
getData(java.lang.String filename,
long timeout,
int digits)
Stream the given file, and recieve DTMF data. |
AGIServer |
getServer()
Gets the AGIServer that received this connection. |
java.net.Socket |
getSocket()
|
java.lang.String |
getVariable(java.lang.String variableName)
Gets an Asterisk variable. |
int |
hangUp()
Hangs up the call. |
int |
hangUp(java.lang.String channelName)
Hangs up a particular channel. |
void |
init(java.net.Socket connection,
AGIServer server,
AGIProcessor processor)
Initialises a pre-existing AGIConnection object. |
boolean |
isTimedOut()
Determines whether the last FastAGI call timed out. |
void |
noop()
Does nothing. |
char |
receiveChar(long timeout)
Receives a character of text on a channel. |
int |
recordFile(java.lang.String filename,
java.lang.String format,
java.lang.String escapeDigits,
long timeout,
boolean beep)
|
int |
recordFile(java.lang.String filename,
java.lang.String format,
java.lang.String escapeDigits,
long timeout,
boolean beep,
int silence)
|
int |
recordFile(java.lang.String filename,
java.lang.String format,
java.lang.String escapeDigits,
long timeout,
long offsetSamples,
boolean beep)
|
int |
recordFile(java.lang.String filename,
java.lang.String format,
java.lang.String escapeDigits,
long timeout,
long offsetSamples,
boolean beep,
int silence)
Record to a file until a given dtmf digit in the sequence is received. |
void |
run()
Reads the properties and runs the processor. |
int |
sayDigits(java.lang.String digits,
java.lang.String escapeDigits)
Say a given digit string, returning early if any of the given DTMF digits are received on the channel. |
int |
sayNumber(java.lang.String number,
java.lang.String escapeDigits)
Say a given number, returning early if any of the given DTMF digits are received on the channel. |
int |
sayPhonetic(java.lang.String text,
java.lang.String escapeDigits)
Say a given character string with phonetics, returning early if any of the given DTMF digits are received on the channel. |
int |
sayTime(long time,
java.lang.String escapeDigits)
Say a given time, returning early if any of the given DTMF digits are received on the channel. |
int |
sendImage(java.lang.String image)
Sends the given image on a channel. |
int |
sendText(java.lang.String text)
Sends the given text on a channel. |
int |
setAutoHangup(int seconds)
Cause the channel to automatically hangup in the future. |
int |
setCallerID(java.lang.String idSpecification)
Changes the callerId of the current channel. |
int |
setContext(java.lang.String newContext)
Sets the context for continuation upon exiting the application. |
int |
setExtension(java.lang.String newExtension)
Changes the extension for continuation upon exiting the application |
int |
setMusic(boolean enable)
Enables/Disables the music on hold generator with the default music class. |
int |
setMusic(boolean enable,
java.lang.String music)
Enables/Disables the music on hold generator. |
int |
setPriority(java.lang.String newPriority)
Changes the priority (the number attached to the extension in extensions.conf) for continuation upon exiting the application. |
void |
setServer(AGIServer server)
|
void |
setSocket(java.net.Socket socket)
|
int |
setVariable(java.lang.String name,
java.lang.String value)
Sets an Asterisk variable |
int |
streamFile(java.lang.String filename)
Send the given file, without interrupt. |
int |
streamFile(java.lang.String filename,
java.lang.String escapeDigits)
Send the given file, allowing playback to be interrupted by the given digits, if any. |
int |
streamFile(java.lang.String filename,
java.lang.String escapeDigits,
long sampleOffset)
Send the given file, allowing playback to be interrupted by the given digits, if any. |
int |
tddMode(boolean enable)
Enable/Disable TDD transmission/reception on a channel. |
int |
verbose(java.lang.String message,
java.lang.String level)
Sends text to the console via verbose message system. |
int |
waitForDigit(long timeout)
Waits up to 'timeout' milliseconds for channel to receive a DTMF digit. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AGIConnection()
Required for use with ObjectPool.
public AGIConnection(java.net.Socket connection, AGIServer server, AGIProcessor processor)
Called automatically by AGIServer for you.
connection
- The socket representing this call.server
- The AGIServer that is managing this connection.processor
- The processor to run.Method Detail |
---|
public java.util.HashMap getAGIProperties()
for a list of available properties.
public void init(java.net.Socket connection, AGIServer server, AGIProcessor processor)
connection
- The socket connected to Asterisk.server
- The AGIServer that received the connection.processor
- The AGIProcessor that will be used to process the call.public static AGIConnection getAGIConnection(java.net.Socket connection, AGIServer server, AGIProcessor processor)
connection
- The socket connected to Asterisk.server
- The AGIServer that received the connection.processor
- The AGIProcessor that will be used to process the call.
public java.lang.String getAGIProperty(java.lang.String name)
The "agi_channel" and "agi_uniqueid" properties are useful for producing integrated AGI and Manager applications.
Complete keys list (with examples):
name
- the name of the property to get.
public boolean isTimedOut()
Method calls may time out while waiting for digits from the caller, for instance.
Use this method to check for timeouts.
true
if the last call timed out,
false
otherwise.public void run()
Called automatically by AGIServer for you.
run
in interface java.lang.Runnable
public int answer() throws java.io.IOException
java.io.IOException
- if the caller hangs up before answer.public int hangUp() throws java.io.IOException
Does NOT automatically close socket.
java.io.IOException
public int hangUp(java.lang.String channelName) throws java.io.IOException
channelName
- The name of the channel to hang up.
java.io.IOException
public int setAutoHangup(int seconds) throws java.io.IOException
Of course it can be hungup before then as well (by the caller).
Setting seconds
to zero will cause the autohangup feature
to be disabled on this channel.
seconds
- the amount of time to wait before hanging up.
java.io.IOException
public void noop() throws java.io.IOException
Why do we even bother? :-)
java.io.IOException
public int channelStatus() throws java.io.IOException
java.io.IOException
public int channelStatus(java.lang.String channelName) throws java.io.IOException
channelName
- the channel to query (null for current channel)
java.io.IOException
public java.lang.String exec(java.lang.String application, java.lang.String options) throws java.io.IOException
application
- The application to execute.options
- The options to send it.
java.io.IOException
public int waitForDigit(long timeout) throws java.io.IOException
timeout
- Use -1 for the timeout value if you desire the call to block
indefinitely.
java.io.IOException
- if the caller hangs up.asciiToChar(int)
public static char asciiToChar(int i)
Just in case anyone's not sure how to do this.
i
- the ASCII value, e.g. 53
public static int charToInt(char c)
c
- the char to convert, '0','1','2','#' etc.
public int databasePut(java.lang.String family, java.lang.String key, java.lang.String value) throws java.io.IOException
family
- The family of keys containing the key.key
- The key to update.value
- The value to set it to.
java.io.IOException
public java.lang.String databaseGet(java.lang.String family, java.lang.String key) throws java.io.IOException
family
- The family of keys containing the key.key
- The key to get the value for.
java.io.IOException
public int databaseDel(java.lang.String family, java.lang.String key) throws java.io.IOException
family
- The family of keys containing the key.key
- The key to delete.
java.io.IOException
public int databaseDelTree(java.lang.String family) throws java.io.IOException
family
- The family of keys to delete.
java.io.IOException
public int databaseDelTree(java.lang.String family, java.lang.String keyTree) throws java.io.IOException
family
- The family of keys containing the key tree.keyTree
- The tree of keys to delete.
java.io.IOException
public void clean()
Will cause Asterisk to proceed to next priority line in extensions.conf,
unless this has been overriden by calls to setContext(java.lang.String)
,
setExtension(java.lang.String)
and/or setPriority(java.lang.String)
Also frees this object for reuse by the system, so don't use it after calling clean()
java.io.IOException
public java.lang.String getVariable(java.lang.String variableName) throws java.io.IOException
variableName
- the name of the variable to get.
java.io.IOException
public java.lang.String getData(java.lang.String filename) throws java.io.IOException
java.io.IOException
public java.lang.String getData(java.lang.String filename, long timeout) throws java.io.IOException
java.io.IOException
public java.lang.String getData(java.lang.String filename, long timeout, int digits) throws java.io.IOException
filename
- the file to streamtimeout
- how long to wait for digits.digits
- the maximum number of digits to receive
java.io.IOException
- if the connection is lost.public char receiveChar(long timeout) throws java.io.IOException
Specify timeout to be the maximum time to wait for input in milliseconds.
Most channels do not support the reception of text.
timeout
- set to 0 or -1 to wait indefinitely.
PostCondition: Check for timeout by calling isTimedOut()
java.io.IOException
- if the connection is lost.public int recordFile(java.lang.String filename, java.lang.String format, java.lang.String escapeDigits, long timeout, boolean beep, int silence) throws java.io.IOException
java.io.IOException
public int recordFile(java.lang.String filename, java.lang.String format, java.lang.String escapeDigits, long timeout, long offsetSamples, boolean beep) throws java.io.IOException
java.io.IOException
public int recordFile(java.lang.String filename, java.lang.String format, java.lang.String escapeDigits, long timeout, boolean beep) throws java.io.IOException
java.io.IOException
public int recordFile(java.lang.String filename, java.lang.String format, java.lang.String escapeDigits, long timeout, long offsetSamples, boolean beep, int silence) throws java.io.IOException
filename
- The name of the file to record (without extension).format
- The format will specify what kind of file will be recorded.escapeDigits
- DTMF digits that will cause the recording to stop.timeout
- is the maximum record time in milliseconds, or -1 for no
timeout.offsetSamples
- is optional, and if provided will seek to the offset without
exceeding the end of the file.beep
- Play a beep before recording.silence
- The number of seconds of silence allowed before the function
returns despite the lack of dtmf digits or reaching timeout.
java.io.IOException
public int sayDigits(java.lang.String digits, java.lang.String escapeDigits) throws java.io.IOException
"101" is said as one-zero-one.
digits
- The digits to say.escapeDigits
- DTMF digits that when pressed will abort playback.
java.io.IOException
- if the connection is lost.public int sayNumber(java.lang.String number, java.lang.String escapeDigits) throws java.io.IOException
"101" is said as one-hundred-and-one
number
- the number to say.escapeDigits
- DTMF digits that when pressed will abort playback.
java.io.IOException
- if the connection is lost.public int sayPhonetic(java.lang.String text, java.lang.String escapeDigits) throws java.io.IOException
text
- The words to sayescapeDigits
- DTMF digits that will abort playback.
java.io.IOException
- if the connection is lost.public int sayTime(long time, java.lang.String escapeDigits) throws java.io.IOException
Java Date and Timestamp times are stored in milliseconds, and so can be
said by calling sayTime(date.getTime()/1000, null)
time
- is number of seconds elapsed since 00:00:00 on January 1,
1970, Coordinated Universal Time (UTC).escapeDigits
- DTMF digits that abort playback.
java.io.IOException
- if the connection is closed.public int sendImage(java.lang.String image) throws java.io.IOException
image
- the image to send
java.io.IOException
public int sendText(java.lang.String text) throws java.io.IOException
text
- to send
java.io.IOException
- if the connection is lost.public int setCallerID(java.lang.String idSpecification) throws java.io.IOException
Do not enclose idSpecification in quotes - this is done for you.
newCallerId
-
java.io.IOException
public int setContext(java.lang.String newContext) throws java.io.IOException
newContext
- The Context in which to continue when the socket is closed.
java.io.IOException
public int setExtension(java.lang.String newExtension) throws java.io.IOException
newExtension
- The extension at which to continue when the socket closes.
java.io.IOException
public int setPriority(java.lang.String newPriority) throws java.io.IOException
newPriority
- The extension priority at which to continue when the socket
closes.
java.io.IOException
public int setMusic(boolean enable) throws java.io.IOException
enable
- true
to start playing music.
java.io.IOException
public int setMusic(boolean enable, java.lang.String music) throws java.io.IOException
enable
- true
to start playing music.music
- The name of the music to play (must be defined in asterisk's
conf).
java.io.IOException
public int setVariable(java.lang.String name, java.lang.String value) throws java.io.IOException
name
- The name of the variable.value
- The value to set it to.
java.io.IOException
public int streamFile(java.lang.String filename) throws java.io.IOException
The file must exist in the Asterisk sounds directory (usually /var/lib/asterisk/sounds). Remember, the file extension must not be included in the filename.
filename
- the file to play
java.io.IOException
- if the connection is lost.public int streamFile(java.lang.String filename, java.lang.String escapeDigits) throws java.io.IOException
Remember, the file extension must not be included in the filename.
filename
- the file to playescapeDigits
- the permitted interrupt digits
java.io.IOException
- if the connection is lost.public int streamFile(java.lang.String filename, java.lang.String escapeDigits, long sampleOffset) throws java.io.IOException
filename
- the file to playescapeDigits
- the permitted interrupt digitssampleOffset
- the audio will seek to sample offset before play starts
java.io.IOException
- if the connection is lost.public int tddMode(boolean enable) throws java.io.IOException
enable
- true to enable.
java.io.IOException
- if the connection is lost.public int verbose(java.lang.String message, java.lang.String level) throws java.io.IOException
message
- to sendlevel
- is the the verbose level (1-4)
java.io.IOException
- if the connection is lost.public AGIServer getServer()
public void setServer(AGIServer server)
server
- The server to set.public java.net.Socket getSocket()
public void setSocket(java.net.Socket socket)
socket
- The socket to set.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |