Skip to content
Browse files

Improve the documents.

  • Loading branch information...
1 parent a412475 commit 8be828743bf825c024c27ebf28bb2cdaf18cf4af @Ruiyun committed Jul 31, 2012
Showing with 29 additions and 57 deletions.
  1. +24 −7 src/cljain/dum.clj
  2. +0 −4 test/cljain/test/core.clj
  3. +3 −43 test/cljain/test/dum.clj
  4. +2 −3 test/cljain/test/register.clj
View
31 src/cljain/dum.clj
@@ -9,15 +9,27 @@
(println \"Received: \" (.getContent request))
(send-response! 200 :in transaction :pack \"I receive the message from myself.\"))
- (global-alter-account :user \"bob\" :domain \"localhost\" :display-name \"Bob\")
+ (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.\")))"
+ :on-timeout (fn [_] (println \"Timeout, try it later.\")))
+
+ Remember, if you want send REGISTER to sip registry, please use the 'register-to' function, that will
+ help you to deal the automatic rigister refresh:
+
+ (register-to (addr/address \"sip:the-registry\") 3600
+ :on-success #(prn \"Register success.\")
+ :on-failure #(prn \"Register failed.\")
+ :on-refreshed #(prn \"Refreshed fine.\")
+ :on-refresh-failed #(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."
:author "ruiyun"
:added "0.2.0"}
cljain.dum
@@ -42,7 +54,12 @@
:dynamic true}
*current-account*)
-(defn global-alter-account [& {:keys [user domain password display-name] :as account}]
+(defn global-set-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."
+ {:added "0.4.0"}
+ [& {:keys [user domain password display-name] :as account}]
(alter-var-root #'*current-account* (fn [_] account)))
(defmulti handle-request (fn [request & [transaction dialog]] (keyword (.getMethod request))))
@@ -206,9 +223,8 @@
"Send REGISTER sip message to target registry server, and auto refresh register before
expired.
- Notice: No matter the first register whether sent successfully, the register auto refresh
- timer will be started. Application can choose to stop it use 'stop-refresh-register', or
- let it auto retry after expires secondes."
+ 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."
{:added "0.3.0"}
[registry-address expires-seconds & {:keys [on-success on-failure on-refreshed on-refresh-failed]}]
{:pre [(addr/address? registry-address)
@@ -246,7 +262,8 @@
:on-timeout (fn [& _] (and on-failure (on-failure)))))))
(defn unregister-to
- "Send REGISTER sip message with expires 0 for unregister."
+ "Send REGISTER sip message with expires 0 for unregister.
+ And the auto-refresh timer will be canceled."
{:added "0.3.0"}
[registry-address]
(let [refresh-timer (get-in @register-ctx-map [registry-address :timer])]
View
4 test/cljain/test/core.clj
@@ -1,4 +0,0 @@
-(ns cljain.test.core
- (:use cljain.core)
- (:use clojure.test))
-
View
46 test/cljain/test/dum.clj
@@ -1,47 +1,7 @@
-(ns ^{:doc "place doc string here"
- :author "ruiyun"}
- cljain.test.dum
- (:require [cljain.sip.core :as core]
- [cljain.sip.header :as header]
- [cljain.sip.address :as addr]
- [cljain.sip.dialog :as dlg]
- [cljain.sip.message :as msg]
- [cljain.sip.transaction :as trans]
- [cljain.dum :as dum]))
+(ns ^{:author "ruiyun"}
+ cljain.test.dum)
(org.apache.log4j.PropertyConfigurator/configure "log4j.properties")
-;(core/global-bind-sip-provider! (core/sip-provider! "test" "127.0.0.1" 5060 "udp"))
-;(dum/initialize! :user "reuiyun" :domain "notbook" :display-name "Ruiyun Wen")
-;(core/start!)
-
-;(def bob (cljain.sip.address/address (cljain.sip.address/sip-uri "127.0.0.1" :port 5070 :user "bob") "Bob henry"))
-;(cljain.dum/send-request! :INVITE :to bob :pack {:type :application :sub-type :sdp :content "Welcome message"}
-; :on-success (fn [a b c] (prn "success!" (dlg/send-ack! b (dlg/ack b 1))))
-; :on-failure (fn [a b c] (prn "faliure!" a))
-; :on-timeout (fn [a] (prn "tiemout" a)))
-
-;(dum/register-to (addr/address (addr/sip-uri "127.0.0.1" :port 5070)) 40
-; :on-success #(prn "register-to has success!")
-; :on-failure #(prn "register-to has failed!")
-; :on-refreshed #(prn "register refresh has success!")
-; :on-refresh-failed #(prn "register refresh has failed!"))
-
-;(use 'cljain.dum)
-;(require '[cljain.sip.core :as sip]
-; '[cljain.sip.address :as addr])
-;
-;(def-request-handler :MESSAGE [request transaction dialog]
-; (println "Received: " (.getContent request))
-; (send-response! 200 :in transaction :pack "I receive your message."))
-;
-;(sip/global-bind-sip-provider! (sip/sip-provider! "my-app" "localhost" 5060 "udp"))
-;(initialize! :user "bob" :domain "home" :display-name "Bob")
-;(sip/start!)
-;
-;(send-request! :MESSAGE :to (addr/address "sip:alice@localhost") :pack "Hello, Alice."
-; :on-success (fn [_ _ response] (println "Fine! response: " (.getContent response)))
-; :on-failure (fn [_ _ response] (println "Oops!" (.getStatusCode response)))
-; :on-timeout (fn [_] (println "Timeout, try it later.")))
(use 'cljain.dum)
(require '[cljain.sip.core :as sip]
@@ -51,7 +11,7 @@
(println "Received: " (.getContent request))
(send-response! 200 :in transaction :pack "I receive the message from myself."))
-(global-alter-account :user "bob" :domain "localhost" :display-name "Bob")
+(global-set-account :user "bob" :domain "localhost" :display-name "Bob")
(sip/global-bind-sip-provider! (sip/sip-provider! "my-app" "localhost" 5060 "udp"))
(sip/set-listener! (dum-listener))
(sip/start!)
View
5 test/cljain/test/register.clj
@@ -1,5 +1,4 @@
-(ns ^{:doc "place doc string here"
- :author "ruiyun"}
+(ns ^{:author "ruiyun"}
cljain.test.register)
(org.apache.log4j.PropertyConfigurator/configure "log4j.properties")
@@ -8,7 +7,7 @@
(require '[cljain.sip.core :as sip]
'[cljain.sip.address :as addr])
-(global-alter-account :user "bob" :domain "test" :display-name "Bob" :password "123456")
+(global-set-account :user "bob" :domain "test" :display-name "Bob" :password "123456")
(sip/global-bind-sip-provider! (sip/sip-provider! "my-app" "localhost" 6060 "udp" :outbound-proxy "127.0.0.1:5060"))
(sip/set-listener! (dum-listener))
(sip/start!)

0 comments on commit 8be8287

Please sign in to comment.
Something went wrong with that request. Please try again.