Class Client
java.lang.Object
com.bytedesk.call.esl.client.inbound.Client
- All Implemented Interfaces:
IModEslApi
Entry point to connect to a running FreeSWITCH Event Socket Library module, as a client.
This class provides what the FreeSWITCH documentation refers to as an 'Inbound' connection
to the Event Socket module. That is, with reference to the socket listening on the FreeSWITCH
server, this client occurs as an inbound connection to the server.
See http://wiki.freeswitch.org/wiki/Mod_event_socket
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.bytedesk.call.esl.client.internal.IModEslApi
IModEslApi.EventFormat, IModEslApi.LoggingLevel -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate CommandResponseprivate final AtomicBooleanprivate final ConcurrentHashMap<String,CompletableFuture<EslEvent>> private ExecutorServiceprivate final List<IEslEventListener>private final IEslProtocolListener -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddEventFilter(String eventHeader, String valueToFilter) Add an event filter to the current set of event filters on this connection.voidaddEventListener(IEslEventListener listener) Cancel any existing event subscription.Disable any logging previously enabled with setLogLevel().booleancanSend()private voidclose()Close the socket connectionvoidconnect(SocketAddress clientAddress, String password, int timeoutSeconds) Attempt to establish an authenticated connection to the nominated FreeSWITCH ESL server socket.deleteEventFilter(String eventHeader, String valueToFilter) Delete an event filter from the current set of event filters on this connection.sendApiCommand(String command, String arg) Sends a FreeSWITCH API command to the server and blocks, waiting for an immediate response from the server.sendBackgroundApiCommand(String command, String arg) Submit a FreeSWITCH API command to the server to be executed in background mode.sendMessage(SendMsg sendMsg) Send aSendMsgcommand to FreeSWITCH.voidsetCallbackExecutor(ExecutorService callbackExecutor) setEventSubscriptions(IModEslApi.EventFormat format, String events) Set the current event subscription for this connection to the server.Enable log output.
-
Field Details
-
eventListeners
-
authenticatorResponded
-
backgroundJobs
-
authenticated
private boolean authenticated -
authenticationResponse
-
clientContext
-
callbackExecutor
-
protocolListener
-
-
Constructor Details
-
Client
public Client()
-
-
Method Details
-
addEventListener
-
canSend
public boolean canSend()- Specified by:
canSendin interfaceIModEslApi
-
checkConnected
private void checkConnected() -
setCallbackExecutor
-
connect
public void connect(SocketAddress clientAddress, String password, int timeoutSeconds) throws InboundConnectionFailure Attempt to establish an authenticated connection to the nominated FreeSWITCH ESL server socket. This call will block, waiting for an authentication handshake to occur, or timeout after the supplied number of seconds.- Parameters:
clientAddress- a SocketAddress representing the endpoint to connect topassword- server event socket is expecting (set in event_socket_conf.xml)timeoutSeconds- number of seconds to wait for the server socket before aborting- Throws:
InboundConnectionFailure
-
sendApiCommand
Sends a FreeSWITCH API command to the server and blocks, waiting for an immediate response from the server. The outcome of the command from the server is retured in anEslMessageobject.- Specified by:
sendApiCommandin interfaceIModEslApi- Parameters:
command- API command to sendarg- command arguments- Returns:
- an
EslMessagecontaining command results
-
sendBackgroundApiCommand
Submit a FreeSWITCH API command to the server to be executed in background mode. A synchronous response from the server provides a UUID to identify the job execution results. When the server has completed the job execution it fires a BACKGROUND_JOB Event with the execution results. Note that this Client must be subscribed in the normal way to BACKGOUND_JOB Events, in order to receive this event.- Specified by:
sendBackgroundApiCommandin interfaceIModEslApi- Parameters:
command- API command to sendarg- command arguments- Returns:
- String Job-UUID that the server will tag result event with.
-
setEventSubscriptions
Set the current event subscription for this connection to the server. Examples of the events argument are:ALL CHANNEL_CREATE CHANNEL_DESTROY HEARTBEAT CUSTOM conference::maintenance CHANNEL_CREATE CHANNEL_DESTROY CUSTOM conference::maintenance sofia::register sofia::expire
Subsequent calls to this method replaces any previous subscriptions that were set. Note: current implementation can only process 'plain' events.- Specified by:
setEventSubscriptionsin interfaceIModEslApi- Parameters:
format- can be { plain | xml }events- { all | space separated list of events }- Returns:
- a
CommandResponsewith the server's response.
-
cancelEventSubscriptions
Cancel any existing event subscription.- Specified by:
cancelEventSubscriptionsin interfaceIModEslApi- Returns:
- a
CommandResponsewith the server's response.
-
addEventFilter
Add an event filter to the current set of event filters on this connection. Any of the event headers can be used as a filter. Note that event filters follow 'filter-in' semantics. That is, when a filter is applied only the filtered values will be received. Multiple filters can be added to the current connection. Example filters:eventHeader valueToFilter ---------------------------------- Event-Name CHANNEL_EXECUTE Channel-State CS_NEW- Specified by:
addEventFilterin interfaceIModEslApi- Parameters:
eventHeader- to filter onvalueToFilter- the value to match- Returns:
- a
CommandResponsewith the server's response.
-
deleteEventFilter
Delete an event filter from the current set of event filters on this connection. See- Specified by:
deleteEventFilterin interfaceIModEslApi- Parameters:
eventHeader- to removevalueToFilter- to remove- Returns:
- a
CommandResponsewith the server's response.
-
sendMessage
Send aSendMsgcommand to FreeSWITCH. This client requires that theSendMsghas a call UUID parameter.- Specified by:
sendMessagein interfaceIModEslApi- Parameters:
sendMsg- aSendMsgwith call UUID- Returns:
- a
CommandResponsewith the server's response.
-
setLoggingLevel
Enable log output.- Specified by:
setLoggingLevelin interfaceIModEslApi- Parameters:
level- using the same values as in console.conf- Returns:
- a
CommandResponsewith the server's response.
-
cancelLogging
Disable any logging previously enabled with setLogLevel().- Specified by:
cancelLoggingin interfaceIModEslApi- Returns:
- a
CommandResponsewith the server's response.
-
close
Close the socket connection- Returns:
- a
CommandResponsewith the server's response.
-