cljain.dum documentation
Here is a simplest example show how to use it:
(use 'cljain.dum)
(require '[cljain.sip.core :as sip]
'[cljain.sip.address :as addr])
(defmethod handle-request :MESSAGE [request transaction _]
(println "Received: " (.getContent request))
(send-response! 200 :in transaction :pack "I receive the message from myself."))
(global-set-account {:user "bob" :domain "localhost" :display-name "Bob" :password "thepwd"})
(sip/global-bind-sip-provider! (sip/sip-provider! "my-app" "localhost" 5060 "udp"))
(sip/set-listener! (dum-listener))
(sip/start!)
(send-request! :MESSAGE :to (addr/address "sip:bob@localhost") :pack "Hello, Bob."
:on-success (fn [& {:keys [response]}]
(println "Fine! response: " (.getContent response)))
:on-failure (fn [& {:keys [response]}]
(println "Oops!" (.getStatusCode response)))
:on-timeout (fn [& _]
(println "Timeout, try it later.")))
Remember, if you want to send REGISTER request, prefer to use the 'register-to!' function, it will
help you to deal the automatic rigister refresh:
(register-to! (addr/address "sip:the-registry") 3600
:on-success (fn [response]
(prn "Register success."))
:on-failure (fn [response]
(prn "Register failed."))
:on-refreshed (fn [response]
(prn "Refreshed fine."))
:on-refresh-failed (fn [response]
(prn "Refresh failed.")))
This version cljain.dum has some limitation that if you want auto-refresh work correctly, you must use
'global-set-account' to give a root binding with *current-account* like previous.
*current-account*
A map contain these four fields: :user, :domain, :password and :display-name.
->AccountManagerImpl
(->AccountManagerImpl)
Positional factory function for class cljain.dum.AccountManagerImpl.
dum-listener
(dum-listener)
Create a dum default event listener.
You can use it for 'cljain.sip.core/set-listener!' function.
global-set-account
(global-set-account account)
Give the *current-account* a root binding.
Although you can use the clojure dynamic binding form, but use this function in this version
cljian.dum is more recommended.
account has follow keys:
:user
:domain
:password
:display-name
legal-content?
(legal-content? content)
Check the content is a string or a map with :type, :sub-type, :length and :content keys.
map->AccountManagerImpl
(map->AccountManagerImpl m__5818__auto__)
Factory function for class cljain.dum.AccountManagerImpl, taking a map of keywords to field values.
register-to!
(register-to! registry-address expires-seconds & {:keys [on-success on-failure on-refreshed on-refresh-failed]})
Send REGISTER sip message to target registry server, and auto refresh register before
expired.
Notice: please call 'global-set-account' before you call 'register-to!'. in this version,
use dynamic binding form to bind *current-account* can not work for auto-refresh.
send-request!
(send-request! message & {content :pack, to-address :to, transport :use, dialog :in, more-headers :more-headers, on-success :on-success, on-failure :on-failure, on-timeout :on-timeout})
Fluent style sip message send function.
The simplest example just send a trivial MESSAGE:
(send-request! :MESSAGE :to (sip-address "192.168.1.128"))
(send-request! :INFO :in dialog-with-bob)
More complicate example:
(send-request! "MESSAGE" :pack "Welcome" :to (sip-address "192.168.1.128" :user "bob") :use "UDP"
:on-success #(prn %) :on-failure #(prn %) :on-timeout #(prn %))
If the pack content is not just a trivial string, provide a well named funciont
to return a content map like this is recommended:
{:type "application"
:sub-type "pidf-diff+xml"
:content content-object}
send-response!
(send-response! status-code & {transaction :in, content :pack, transport :use, more-headers :more-headers})
Send response with a server transactions.
unregister-to!
(unregister-to! registry-address)
Send REGISTER sip message with expires 0 for unregister.
And the auto-refresh timer will be canceled.