Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
piphone
piphone-sip
Commits
c957c90d
Commit
c957c90d
authored
May 09, 2016
by
okhin
Browse files
Cleaning a bit more the code
parent
464fa383
Changes
1
Hide whitespace changes
Inline
Side-by-side
app.py
View file @
c957c90d
...
...
@@ -170,7 +170,8 @@ async def listen():
'''
global
running
global
ws
ws
=
await
websockets
.
connect
(
'ws://185.34.33.12:8088/ari/events?app=piphone&api_key=piphone:passpiphone'
)
ws
=
await
websockets
.
connect
(
config
[
'webservice'
][
'base_url'
]
+
'?app={}&api_key{}:{}'
.
format
(
config
[
'asterisk'
][
'app'
],
config
[
'asterisk'
][
'key'
],
config
[
'asterisk'
][
'password'
]))
ws_logger
.
debug
(
'Websocket connected: {}'
.
format
(
type
(
ws
)))
await
hold_bridges
()
while
running
==
True
:
...
...
@@ -275,18 +276,16 @@ class Call(object):
return
# Now, we're connectig the other side
# But first we should stop the playback
phone_logger
.
debug
(
'Stopping the playback currently running'
.
format
(
payload
,)
)
phone_logger
.
debug
(
'Stopping the playback currently running'
)
# We're stoping the playback, with the same ID as the channel, to keep track of it
playback
=
ari
.
Playback
(
self
.
config
[
'asterisk'
],
event
[
'channel'
][
'id'
],
'sound:mario'
)
playback
.
stop
()
# Now we're moving the channel to the MOH Bridge
payload
[
'channel'
]
=
event
[
'channel'
][
'id'
]
phone_logger
.
debug
(
'Moving call {} to the garage'
.
format
(
payload
[
'channel'
]))
phone_logger
.
debug
(
'Moving call {} to the garage'
.
format
(
event
[
'channel'
][
'id'
]))
moh_bridge
=
ari
.
Bridge
(
self
.
config
[
'asterisk'
],
self
.
config
[
'moh'
][
'name'
])
moh_bridge
.
addChannel
(
event
[
'channel'
][
'id'
])
# Next we need to originate a call to the other side
phone_logger
.
info
(
'Will now connect {} to {}'
.
format
(
self
.
caller
,
self
.
callee
,))
phone_logger
.
debug
(
'Preparing to send a request to the ARI with payload {}'
.
format
(
payload
,))
endpoint
=
'SIP/'
+
sanitize_phonenumber
(
self
.
callee
)
+
'@'
+
config
[
'asterisk'
][
'sip-context'
]
channel
=
ari
.
Channel
(
self
.
config
[
'asterisk'
],
self
.
id
+
'-'
+
sanitize_phonenumber
(
self
.
callee
))
channel
.
originate
(
endpoint
)
...
...
@@ -309,16 +308,14 @@ class Call(object):
bridge
.
create
()
# Step 2, moving channels
channels
=
","
.
join
([
self
.
id
+
'-'
+
self
.
caller
,
self
.
id
+
'-'
+
self
.
callee
])
phone_logger
.
debug
(
"Moving channels to the created bridge: {}"
.
format
(
payload
[
'channel'
]
))
phone_logger
.
debug
(
"Moving channels to the created bridge: {}"
.
format
(
brodge
.
name
,
))
bridge
.
addChannel
(
channels
)
phone_logger
.
info
(
"Call now fully connected: {} <-> {}"
.
format
(
self
.
caller
,
self
.
callee
))
return
# Call is being picked up, we want to play a song
try
:
payload
[
'media'
]
=
'sound:mario'
payload
[
'lang'
]
=
'en_US'
channel
=
ari
.
Channel
(
self
.
config
[
'asterisk'
],
event
[
'channel'
][
'id'
])
logging
.
debug
(
'Preparing to
send a request to the ARI with
pay
load {}'
.
format
(
payload
,)
)
logging
.
debug
(
'Preparing to
create a
p
l
ay
back'
)
# We're starting a playback, with the same ID as the channel, to keep track of it
channel
.
playback
(
channel
.
name
,
self
.
config
[
'asterisk'
][
'playback'
])
except
Exception
as
e
:
...
...
@@ -345,7 +342,6 @@ class Call(object):
# Now, let's create the channel
try
:
endpoint
=
'SIP/'
+
sanitize_phonenumber
(
self
.
caller
)
+
'@'
+
self
.
config
[
'asterisk'
][
'sip-context'
]
logging
.
debug
(
'Preparing to send a request to the ARI with payload {}'
.
format
(
payload
,))
channel
=
ari
.
Channel
(
self
.
config
[
'asterisk'
],
self
.
id
+
'-'
+
sanitize_phonenumber
(
self
.
caller
))
channel
.
originate
()
except
Exception
as
e
:
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment