Skip to content
Snippets Groups Projects
Commit 448b4e1e authored by Olivier Dion's avatar Olivier Dion Committed by Adrien Béraud
Browse files

agent/examples: Update examples with new bindings

Change-Id: Ib5194ef6ca475df5be621c923d7660266cf7256e
parent dd132c86
No related branches found
No related tags found
No related merge requests found
;;; This is an example of an active agent. ;;; This is an example of an active agent.
;;; Here we define a simple variable named `peer` that references a string.
;;;
;;; You should change this to the Jami ID of an other agent or one of your
;;; account.
(define my-peer "358d385fc78edde27981caac4ec40fb963c8a066")
;;; Here we define a variable named `details-matrix` that references a list of
;;; association lists.
;;; ;;;
;;; An association list is a list that has pairs of (key . value). ;;; The active agent ensure that an account is created and then call its peer
(define details-matrix ;;; every minute.
'((("Account.upnpEnabled" . "true")
("TURN.enable" . "true")) (use-modules
(ice-9 threads)
(("Account.upnpEnabled" . "false") ((agent) #:prefix agent:)
("TURN.enable" . "true")) ((jami account) #:prefix account:)
((jami signal) #:prefix jami:)
(("Account.upnpEnabled" . "false") ((jami call) #:prefix call:))
("TURN.enable" . "false"))))
(define (make-a-call from to)
(define (scenario/call:details someone) (let ((mtx (make-mutex))
" (cnd (make-condition-variable))
pre-conditions: SOMEONE is a string that references a valid contact in the agent account. (this-call-id "")
(success #f)
Here we define a variable named `scenario/call` that references a procedure (over #f))
that takes a single argument called `someone`.
(jami:on-signal 'call-state-changed
This procedure iterates over the details matrix defined above and changes the (lambda (call-id state code)
details of the account, using `agent:set-details` for every association list in (with-mutex mtx
the matrix. If it fails to place a call, then the `bad-call` exception is (let ((ret (cond
thrown. Finally, the agent sleeps for 10 seconds using `agent:wait`. ((not (string= call-id this-call-id)) #t)
" ((string= state "CURRENT") (begin
(for-each (lambda (details) (set! success #t)
(agent:set-details details) #t))
(or (agent:place-call someone) ((string= state "OVER") (begin
(throw 'bad-call))) (set! over #t)
(agent:wait 10) #f))
details-matrix)) (else #t))))
(signal-condition-variable cnd)
(define (scenario/call:periodic someone) ret))))
"
pre-conditions: SOMEONE is a string that references a valid contact in the agent account. (set! this-call-id (call:place-call from to))
Place a call to SOMEONE periodically until it fails. (with-mutex mtx
(while (not (or success over))
NOTE! This is an example of a recursive procedure. In Scheme, tail (wait-condition-variable cnd mtx (+ (current-time) 30))))
recursions are free."
(when (agent:place-call someone) (when success
(scenario/call:periodic someone))) (call:hang-up this-call-id))
(define (scenario/call:nth someone cnt) (unless over
" (with-mutex mtx
pre-conditions: SOMEONE is a string that references a valid contact in the agent account. (while (not over)
LEFT is a positive number. (wait-condition-variable cnd mtx (+ (current-time) 30)))))
Place a call to SOMEONE CNT time. success))
"
(let ((fail 0))
(do ((i 0 (1+ i)))
((> i cnt))
(unless (agent:place-call someone)
(set! fail (1+ fail))))
fail)
)
(define (scenario/ping conversation)
"
pre-conditions: CONVERSATION is a string that references a valid conversation in the agent account.
Here we define a variable named `scenario/ping` that references a procedure
that takes a single argument called `conversation`.
This procedure work just like `scenario/call`, but will send a random
message to CONVERSATION and expect to receive a pong of it, instead of
placing a call.
"
(for-each (lambda (details)
(agent:set-details details)
(or (agent:ping conversation) (throw 'bad-ping))
(agent:wait 5))
details-matrix))
;;; Set default account's details.
;(agent:set-details '(("Account.upnpEnabled" . "true") ("TURN.enable" . "true")))
;;; Search for our peer.
;(agent:search-for-peers my-peer)
;;; Let's call our peer 50 times.
;(scenario/call:nth my-peer 50)
;;; Wait for 100000 seconds.
(agent:ensure-account) (agent:ensure-account)
(agent:search-for-peers my-peer)
(format #t "Failed ~a calls out of 1000" (scenario/call:nth my-peer 100)) (while #t
(begin
(make-a-call agent:account-id "bcebc2f134fc15eb06c64366c1882de2e0f1e54f")
(account:send-register agent:account-id #f)
(sleep 30)
(account:send-register agent:account-id #t)
(sleep 30)))
;;; This is an example of a passive agent ;;; This is an example of a passive agent.
;;; ;;;
;;; It will accept all trust request and answer every call ;;; The passive agent ensure that an account is created and then wait for
;;; incomming call of any peer.
(define details-matrix (use-modules ((agent) #:prefix agent:)
'((("Account.upnpEnabled" . "true") ((jami signal) #:prefix jami:)
("TURN.enable" . "true")) ((jami call) #:prefix call:))
(("Account.upnpEnabled" . "false")
("TURN.enable" . "true"))
(("Account.upnpEnabled" . "false")
("TURN.enable" . "false"))))
(define (scenario/passive)
"Agent does nothing"
(agent:wait))
(define (scenario/passive:change-details)
"Agent changes its account details once in a while"
(for-each (lambda (details)
(agent:disable)
(agent:set-details details)
(agent:enable)
(agent:wait 15))
details-matrix))
(agent:ensure-account) (agent:ensure-account)
(scenario/passive)
(jami:on-signal 'incomming-call
(lambda (account-id call-id peer-display-name media-list)
(when (string= account-id agent:account-id)
(format #t
"Incoming [call:~a] from peer ~a~%"
call-id peer-display-name)
(call:accept call-id media-list))
#t))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment