A Clojure library to communicate with freeswitch event socket.
- Freeswitch ESL protocol implemented in Clojure.
- Support for both inbound and outbound mode.
- Callback based event handling.
- Automated event handler management for things like
bgapi
andCUSTOM
events. - Uses high-performance
aleph
async framework under the hood.
Add the following dependency to your project file:
Full API documentation is available at cljdoc.org.
freeswitch-clj
can be used in both inbound mode and outbound mode.
(require '[freeswitch-clj :as f])
;; Connect to a local freeswitch server.
(def conn (f/connect :host "localhost"
:port 8021
:password "ClueCon"))
;; Send an 'api' request.
(f/req-api conn "status")
;; => {:ok true, :result "...", :Reply-Text "..."}
;; Define a handler to process result of a 'bgapi' request.
(def rslt-handler
(fn [conn rslt]
(println "Result is:" rslt)))
;; Make the 'bgapi' request.
(f/req-bgapi conn rslt-handler "status")
;; => {:ok true, :Reply-Text "...", :Job-UUID "<uuid>"}
;; Result is: {:ok true, :result "...", :event {...}}
;; Diconnect.
(f/disconnect conn)
(require '[freeswitch-clj :as f])
;; Define an incoming connection handler.
(defn conn-handler
[conn chan-data]
(println "Channel data is:" chan-data)
;; Channel data is: {...}
(println (f/req-api conn "status"))
;; {:ok true, :result "...", :Reply-Text "..."}
;; Send an 'exit' command.
(f/disconnect conn)
;; Wait for connection to close, by waiting for
;; a promise to be delivered.
@(conn :closed?))
;; Listen for connections from freeswitch.
(f/listen :port 10000 :handler conn-handler)
;; Sleep for 10 minutes.
(Thread/sleep 600000)
Check out tutorial for more usage examples.
You can run the tests with run_tests.sh
shell script.
This will spin up two docker containers containing freeswitch
and check freeswitch-clj under different scenarios.
Copyright © 2021 Titon Barua
Distributed under the MIT Public License.