-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e5f35f2
Showing
11 changed files
with
1,461 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/target | ||
/classes | ||
/checkouts | ||
pom.xml | ||
pom.xml.asc | ||
*.jar | ||
*.class | ||
/.lein-* | ||
/.nrepl-port | ||
.hgignore | ||
.hg/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Change Log | ||
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). | ||
|
||
## [Unreleased] | ||
### Changed | ||
- Add a new arity to `make-widget-async` to provide a different widget shape. | ||
|
||
## [0.1.1] - 2017-10-29 | ||
### Changed | ||
- Documentation on how to make the widgets. | ||
|
||
### Removed | ||
- `make-widget-sync` - we're all async, all the time. | ||
|
||
### Fixed | ||
- Fixed widget maker to keep working when daylight savings switches over. | ||
|
||
## 0.1.0 - 2017-10-29 | ||
### Added | ||
- Files from the new template. | ||
- Widget maker public API - `make-widget-sync`. | ||
|
||
[Unreleased]: https://github.com/your-name/freeswitch-clj/compare/0.1.1...HEAD | ||
[0.1.1]: https://github.com/your-name/freeswitch-clj/compare/0.1.0...0.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Copyright 2017 Messrs Concitus, Bangladesh. <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# freeswitch-clj | ||
|
||
A Clojure library to communicate with freeswitch event socket. | ||
|
||
## Features | ||
|
||
- 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` and `CUSTOM` events. | ||
- Uses high-performance `aleph` async framework under the hood. | ||
|
||
## Usage | ||
|
||
`freeswitch-clj` can be used in both inbound mode and outbound mode. | ||
|
||
### Inbound example | ||
|
||
```clojure | ||
(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 "status" rslt-handler) | ||
;; => {:ok true, :Reply-Text "...", :Job-UUID "<uuid>"} | ||
;; Result is: {:ok true, :result "...", :event {...}} | ||
|
||
;; Diconnect. | ||
(f/disconnect conn) | ||
``` | ||
|
||
### Outbound example | ||
|
||
```clojure | ||
(require '[freeswitch-clj :as f]) | ||
|
||
;; Define an incoming connection handler. | ||
(defn conn-handler | ||
[conn] | ||
(println "Channel data is:" (conn :channel-data)) | ||
;; Channel data is: {...} | ||
|
||
(println (f/req-api conn "status")) | ||
;; {:ok true, :result "...", :Reply-Text "..."} | ||
|
||
(f/disconnect conn)) | ||
|
||
;; Listen for connections from freeswitch. | ||
(f/listen :port 10000 :handler conn-handler) | ||
``` | ||
|
||
Check out [more usage examples.](http://) | ||
|
||
## License | ||
|
||
Copyright © 2017 [Messrs Concitus, Dhaka, Bangladesh](mailto:[email protected]) | ||
|
||
Distributed under the MIT Public License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Usage examples | ||
|
||
## Basic inbound setup | ||
|
||
Here's a basic setup to send some commands to freeswitch in inbound mode: | ||
|
||
```clojure | ||
(require '[freeswitch-clj.core :as f]) | ||
|
||
;; Make a connection. | ||
(def conn (f/connect :host "127.0.0.1")) | ||
|
||
;; Print result of an api request. | ||
(println (req-api conn "status")) | ||
|
||
(f/disconnect conn) | ||
``` | ||
|
||
## Basic outbound setup | ||
|
||
A basic outbound setup where freeswitch is configured to knock on port | ||
`10000` for decision about call routing: | ||
|
||
```clojure | ||
(require '[freeswitch-clj.core :as f]) | ||
|
||
;; Create a connection handler. | ||
(defn conn-handler | ||
[conn] | ||
(println "Channel data:" (:channel-data conn)) | ||
(println (f/req-api conn "status")) | ||
(f/disconnect conn)) | ||
|
||
;; Listen for outbound connections from freeswitch on port 10000. | ||
(f/listen :port 10000 | ||
:handler conn-handler) | ||
``` | ||
|
||
## Handling result of background jobs | ||
|
||
The function `req-bgapi` can be used to effortlessly handle result of background jobs. | ||
|
||
```clojure | ||
;; Define a result handler function. | ||
(defn bgjob-handler | ||
[conn rslt] | ||
(println "bgjob result:" rslt)) | ||
|
||
;; Make a bgapi request. | ||
(f/req-bgapi conn "status" bgjob-handler) | ||
``` | ||
|
||
## Handling events, the high-level way | ||
|
||
Function `req-event` can be used to both subscribe and setup handler | ||
for an event. | ||
|
||
```clojure | ||
;; Define an event handler. | ||
(defn event-handler | ||
[conn event-map] | ||
(println "Received event:" event-map)) | ||
|
||
;; Watch for a heartbeat event. | ||
(f/req-event conn "HEARTBEAT" event-handler) | ||
``` | ||
|
||
## Handling events, the low-level approach | ||
|
||
For more control, event handler binding and event subscription can be | ||
separated. | ||
|
||
```clojure | ||
;; Bind event handler. | ||
(f/bind-event | ||
conn | ||
"HEARTBEAT" | ||
(fn [conn event-map] | ||
(println "Received heartbeat:" event-map)))) | ||
|
||
;; Subscribe to the event. | ||
(f/req-cmd conn "event HEARTBEAT") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(defproject freeswitch-clj "0.1.0-SNAPSHOT" | ||
:description "A Clojure interface to freeswitch event socket." | ||
:url "http://example.com/FIXME" | ||
:license {:name "MIT Public License" | ||
:url "https://opensource.org/licenses/MIT"} | ||
:dependencies [[org.clojure/clojure "1.8.0"] | ||
[com.taoensso/timbre "4.10.0"] | ||
[danlentz/clj-uuid "0.1.7"] | ||
[cheshire "5.8.0"] | ||
[aleph "0.4.3"] | ||
[com.cemerick/url "0.1.1"] | ||
|
||
;; dependencies for testing and documentation. | ||
[proto-repl "0.3.1"] | ||
[codox-theme-rdash "0.1.2"] | ||
[digest "1.4.6"]] | ||
:plugins [[lein-codox "0.10.3"]] | ||
:codox {:metadata {:doc/format :plaintext} | ||
:themes [:rdash]}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
Content-Type: auth/request | ||
|
||
Content-Type: command/reply | ||
Reply-Text: +OK accepted | ||
|
||
Content-Type: api/response | ||
Content-Length: 330 | ||
|
||
UP 0 years, 0 days, 17 hours, 41 minutes, 5 seconds, 409 milliseconds, 299 microseconds | ||
FreeSWITCH (Version 1.6.19 64bit) is ready | ||
0 session(s) since startup | ||
0 session(s) - peak 0, last 5min 0 | ||
0 session(s) per Sec out of max 30, peak 0, last 5min 0 | ||
1000 session(s) max | ||
min idle cpu 0.00/98.13 | ||
Current Stack Size/Max 240K/8192K | ||
Content-Type: command/reply | ||
Reply-Text: +OK event listener enabled plain | ||
|
||
Content-Type: command/reply | ||
Reply-Text: +OK Job-UUID: 5caf00ab-e476-4e5a-8bea-2749d428dea2 | ||
Job-UUID: 5caf00ab-e476-4e5a-8bea-2749d428dea2 | ||
|
||
Content-Length: 885 | ||
Content-Type: text/event-plain | ||
|
||
Event-Name: BACKGROUND_JOB | ||
Core-UUID: 35a647e7-c4e9-42f5-97cc-73606bbaa258 | ||
FreeSWITCH-Hostname: oscar-delu | ||
FreeSWITCH-Switchname: oscar-delu | ||
FreeSWITCH-IPv4: 192.168.250.70 | ||
FreeSWITCH-IPv6: %3A%3A1 | ||
Event-Date-Local: 2017-11-10%2013%3A54%3A48 | ||
Event-Date-GMT: Fri,%2010%20Nov%202017%2007%3A54%3A48%20GMT | ||
Event-Date-Timestamp: 1510300488443268 | ||
Event-Calling-File: mod_event_socket.c | ||
Event-Calling-Function: api_exec | ||
Event-Calling-Line-Number: 1557 | ||
Event-Sequence: 8061 | ||
Job-UUID: 5caf00ab-e476-4e5a-8bea-2749d428dea2 | ||
Job-Command: status | ||
Content-Length: 331 | ||
|
||
UP 0 years, 0 days, 17 hours, 41 minutes, 22 seconds, 817 milliseconds, 606 microseconds | ||
FreeSWITCH (Version 1.6.19 64bit) is ready | ||
0 session(s) since startup | ||
0 session(s) - peak 0, last 5min 0 | ||
0 session(s) per Sec out of max 30, peak 0, last 5min 0 | ||
1000 session(s) max | ||
min idle cpu 0.00/98.43 | ||
Current Stack Size/Max 240K/8192K | ||
Content-Type: command/reply | ||
Reply-Text: +OK event listener enabled xml | ||
|
||
Content-Type: command/reply | ||
Reply-Text: +OK Job-UUID: ed3dd1a8-3301-4ed4-be1a-4045ac3dd247 | ||
Job-UUID: ed3dd1a8-3301-4ed4-be1a-4045ac3dd247 | ||
|
||
Content-Length: 1305 | ||
Content-Type: text/event-xml | ||
|
||
<event> | ||
<headers> | ||
<Event-Name>BACKGROUND_JOB</Event-Name> | ||
<Core-UUID>35a647e7-c4e9-42f5-97cc-73606bbaa258</Core-UUID> | ||
<FreeSWITCH-Hostname>oscar-delu</FreeSWITCH-Hostname> | ||
<FreeSWITCH-Switchname>oscar-delu</FreeSWITCH-Switchname> | ||
<FreeSWITCH-IPv4>192.168.250.70</FreeSWITCH-IPv4> | ||
<FreeSWITCH-IPv6>%3A%3A1</FreeSWITCH-IPv6> | ||
<Event-Date-Local>2017-11-10%2013%3A55%3A02</Event-Date-Local> | ||
<Event-Date-GMT>Fri,%2010%20Nov%202017%2007%3A55%3A02%20GMT</Event-Date-GMT> | ||
<Event-Date-Timestamp>1510300502603269</Event-Date-Timestamp> | ||
<Event-Calling-File>mod_event_socket.c</Event-Calling-File> | ||
<Event-Calling-Function>api_exec</Event-Calling-Function> | ||
<Event-Calling-Line-Number>1557</Event-Calling-Line-Number> | ||
<Event-Sequence>8065</Event-Sequence> | ||
<Job-UUID>ed3dd1a8-3301-4ed4-be1a-4045ac3dd247</Job-UUID> | ||
<Job-Command>status</Job-Command> | ||
</headers> | ||
<Content-Length>331</Content-Length> | ||
<body>UP 0 years, 0 days, 17 hours, 41 minutes, 36 seconds, 962 milliseconds, 323 microseconds | ||
FreeSWITCH (Version 1.6.19 64bit) is ready | ||
0 session(s) since startup | ||
0 session(s) - peak 0, last 5min 0 | ||
0 session(s) per Sec out of max 30, peak 0, last 5min 0 | ||
1000 session(s) max | ||
min idle cpu 0.00/97.93 | ||
Current Stack Size/Max 240K/8192K | ||
</body> | ||
</event> | ||
Content-Type: command/reply | ||
Reply-Text: +OK event listener enabled json | ||
|
||
Content-Type: command/reply | ||
Reply-Text: +OK Job-UUID: fac71fdb-86f1-4b44-84c1-ae383321388d | ||
Job-UUID: fac71fdb-86f1-4b44-84c1-ae383321388d | ||
|
||
Content-Length: 928 | ||
Content-Type: text/event-json | ||
|
||
{"Event-Name":"BACKGROUND_JOB","Core-UUID":"35a647e7-c4e9-42f5-97cc-73606bbaa258","FreeSWITCH-Hostname":"oscar-delu","FreeSWITCH-Switchname":"oscar-delu","FreeSWITCH-IPv4":"192.168.250.70","FreeSWITCH-IPv6":"::1","Event-Date-Local":"2017-11-10 13:55:13","Event-Date-GMT":"Fri, 10 Nov 2017 07:55:13 GMT","Event-Date-Timestamp":"1510300513943270","Event-Calling-File":"mod_event_socket.c","Event-Calling-Function":"api_exec","Event-Calling-Line-Number":"1557","Event-Sequence":"8069","Job-UUID":"fac71fdb-86f1-4b44-84c1-ae383321388d","Job-Command":"status","Content-Length":"331","_body":"UP 0 years, 0 days, 17 hours, 41 minutes, 48 seconds, 306 milliseconds, 778 microseconds\nFreeSWITCH (Version 1.6.19 64bit) is ready\n0 session(s) since startup\n0 session(s) - peak 0, last 5min 0 \n0 session(s) per Sec out of max 30, peak 0, last 5min 0 \n1000 session(s) max\nmin idle cpu 0.00/97.77\nCurrent Stack Size/Max 240K/8192K\n"}Content-Type: command/reply | ||
Reply-Text: +OK event listener enabled json | ||
|
||
Content-Length: 912 | ||
Content-Type: text/event-json | ||
|
||
{"Event-Name":"HEARTBEAT","Core-UUID":"35a647e7-c4e9-42f5-97cc-73606bbaa258","FreeSWITCH-Hostname":"oscar-delu","FreeSWITCH-Switchname":"oscar-delu","FreeSWITCH-IPv4":"192.168.250.70","FreeSWITCH-IPv6":"::1","Event-Date-Local":"2017-11-10 13:57:52","Event-Date-GMT":"Fri, 10 Nov 2017 07:57:52 GMT","Event-Date-Timestamp":"1510300672183268","Event-Calling-File":"switch_core.c","Event-Calling-Function":"send_heartbeat","Event-Calling-Line-Number":"74","Event-Sequence":"8087","Event-Info":"System Ready","Up-Time":"0 years, 0 days, 17 hours, 44 minutes, 26 seconds, 550 milliseconds, 931 microseconds","FreeSWITCH-Version":"1.6.19~64bit","Uptime-msec":"63866550","Session-Count":"0","Max-Sessions":"1000","Session-Per-Sec":"30","Session-Per-Sec-Last":"0","Session-Per-Sec-Max":"0","Session-Per-Sec-FiveMin":"0","Session-Since-Startup":"0","Session-Peak-Max":"0","Session-Peak-FiveMin":"0","Idle-CPU":"98.033333"}Content-Type: command/reply | ||
Reply-Text: +OK bye | ||
|
||
Content-Type: text/disconnect-notice | ||
Content-Length: 67 | ||
|
||
Disconnected, goodbye. | ||
See you at ClueCon! http://www.cluecon.com/ |
Oops, something went wrong.