Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
02c5cecd
Commit
02c5cecd
authored
3 years ago
by
Olivier Dion
Committed by
Sébastien Blin
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
agent/active-agent: Fix calling problems
Change-Id: I3f7b3fd9e5bea986f5b600273ae4ddb07bdd787a
parent
ea6a019d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/agent/examples/active-agent.scm
+49
-46
49 additions, 46 deletions
test/agent/examples/active-agent.scm
with
49 additions
and
46 deletions
test/agent/examples/active-agent.scm
+
49
−
46
View file @
02c5cecd
...
...
@@ -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
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment