Skip to content
Snippets Groups Projects
Commit 02c5cecd authored by Olivier Dion's avatar Olivier Dion Committed by Sébastien Blin
Browse files

agent/active-agent: Fix calling problems

Change-Id: I3f7b3fd9e5bea986f5b600273ae4ddb07bdd787a
parent ea6a019d
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
;;; The active agent ensure that an account is created and then call its peer
;;; every minute.
;;; We import here Jami's primitives.
(use-modules
(ice-9 threads)
((agent) #:prefix agent:)
......@@ -11,59 +12,61 @@
((jami call) #:prefix call:)
((jami logger) #:prefix jami:))
(define (make-a-call from to)
(define* (make-a-call from to #:key (timeout 30) (media-flow 10))
"Make a call from account id FROM to peer id TO.
If call is not in state CURRENT before TIMEOUT, returns #f, otherwise the call is
hang up after MEDIA-FLOW seconds and #t is returned.
"
(jami:info "Placing call from:~a to:~a" from to)
(let ((mtx (make-mutex))
(cnd (make-condition-variable))
(this-call-id "")
(success #f)
(over #f))
(jami:on-signal 'state-changed
(lambda (call-id state code)
(with-mutex mtx
(let ((ret (cond
((not (string= call-id this-call-id)) #t)
((string= state "CURRENT") (begin
(set! success #t)
#t))
((string= state "OVER") (begin
(set! over #t)
#f))
(else #t))))
(signal-condition-variable cnd)
ret))))
(set! this-call-id (call:place-call from to))
(let ([mtx (make-recursive-mutex)]
[cnd (make-condition-variable)]
[this-call-id ""]
[continue #t])
(with-mutex mtx
(while (not (or success over))
(wait-condition-variable cnd mtx (+ (current-time) 30))))
(when success
(call:hang-up this-call-id))
(jami:on-signal 'state-changed
(lambda (account-id call-id state code)
(with-mutex mtx
(when (and continue
(string= account-id from)
(string= call-id this-call-id)
(string= "CURRENT" state))
(signal-condition-variable cnd))
continue)))
(unless over
(with-mutex mtx
(while (not over)
(wait-condition-variable cnd mtx (+ (current-time) 30)))))
(set! this-call-id (call:place-call/media from to))
success))
(let ([success (wait-condition-variable cnd mtx
(+ (current-time) timeout))])
(when success
(sleep media-flow) ; Wait for media to flow between peers.
(call:hang-up from this-call-id))
(set! continue #f)
success))))
;;; This ensure you have an account created for the agent.
(agent:ensure-account)
(let ((account (agent:account-id))
(peer "FIXME"))
;;; Change FIXME for the peer id you want to contact. You can also change the
;;; value of media-flow and grace-period.
(let loop ([account (agent:account-id)]
[peer "FIXME"]
[media-flow 7]
[grace-period 30])
;; Calling our PEER.
(make-a-call account peer #:media-flow media-flow)
;; Disabling our account for GRACE-PERIOD.
(jami:info "Disabling account")
(account:send-register account #f)
(sleep grace-period)
;; Renabling our account and wait GRACE-PERIOD.
(jami:info "Enabling account")
(account:send-register account #t)
(sleep grace-period)
(when (string= peer "FIXME")
(throw 'bad-peer
"Peer was not set! Please set variable `peer` to a valid Jami's ID"))
(while #t
(begin
(make-a-call account peer)
(jami:info "Disabling account")
(account:send-register account #f)
(sleep 30)
(jami:info "Enabling account")
(account:send-register account #t)
(sleep 30))))
;; Loop again.
(loop account peer media-flow grace-period))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment