Skip to content
GitLab
Menu
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
ca40b058
Commit
ca40b058
authored
Jan 25, 2017
by
okhin
Browse files
We do not need the playback, only the MOH
parent
938ea23f
Pipeline
#813
passed with stage
in 3 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
piphone.py
View file @
ca40b058
...
...
@@ -284,6 +284,9 @@ class Call(object):
We might also be in a case where no channel has been created … or we're still on moh.
'''
bridge_id
=
'-'
.
join
(
event
[
'channel'
][
'id'
].
split
(
'-'
)[:
-
1
])
self
.
update
((
':'
.
join
([
event
[
'channel'
][
'state'
]
,
event
[
'channel'
][
'id'
].
split
(
'-'
)[
-
1
]])
,
event
[
'timestamp'
]))
try
:
bridge
=
ari
.
Bridge
(
config
[
'asterisk'
],
bridge_id
,
'mixed'
)
results
=
json
.
loads
(
bridge
.
status
())
...
...
@@ -291,9 +294,6 @@ class Call(object):
# Not in a bridge yet. Our channel has been destroyed.
# That or we're in moh.
phone_logger
.
info
(
'Channel destroyed {}'
.
format
(
event
[
'channel'
][
'id'
]))
self
.
update
((
':'
.
join
([
event
[
'channel'
][
'state'
]
,
event
[
'channel'
][
'id'
].
split
(
'-'
)[
-
1
]])
,
event
[
'timestamp'
]))
return
if
len
(
results
[
'channels'
])
==
0
:
...
...
@@ -306,9 +306,6 @@ class Call(object):
chan
=
ari
.
Channel
(
config
[
'asterisk'
],
channel
)
phone_logger
.
info
(
'Hanging up channel {}'
.
format
(
channel
))
chan
.
delete
()
self
.
update
((
':'
.
join
([
'Down'
,
event
[
'channel'
][
'id'
].
split
(
'-'
)[
-
1
]])
,
event
[
'timestamp'
]))
def
dtmf
(
self
,
event
):
'''
...
...
@@ -320,16 +317,7 @@ class Call(object):
if
event
[
'digit'
]
!=
'1'
:
return
# Now, we're connectig the other side
# But first we should stop the playback
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
(
config
[
'asterisk'
],
event
[
'channel'
][
'id'
],
'sound:mario'
)
playback
.
stop
()
# Now we're moving the channel to the MOH Bridge
phone_logger
.
debug
(
'Moving call {} to the garage'
.
format
(
event
[
'channel'
][
'id'
]))
moh_bridge
=
ari
.
Bridge
(
config
[
'asterisk'
],
config
[
'moh'
][
'name'
])
moh_bridge
.
addChannel
(
event
[
'channel'
][
'id'
])
# Next we need to originate a call to the other side
# We need to originate a call to the other side
phone_logger
.
info
(
'Will now connect {} to {}'
.
format
(
self
.
caller
,
self
.
callee
,))
endpoint
=
'SIP/'
+
sanitize_phonenumber
(
self
.
callee
)
+
'@'
+
config
[
'asterisk'
][
'sip-context'
]
channel
=
ari
.
Channel
(
config
[
'asterisk'
],
self
.
id
+
'-'
+
sanitize_phonenumber
(
self
.
callee
))
...
...
@@ -358,7 +346,10 @@ class Call(object):
except
Exception
as
e
:
raise
e
# Step 2, moving channels
channels
=
","
.
join
([
self
.
id
+
'-'
+
sanitize_phonenumber
(
self
.
caller
),
self
.
id
+
'-'
+
sanitize_phonenumber
(
self
.
callee
)])
channels
=
","
.
join
([
self
.
id
+
'-'
+
sanitize_phonenumber
(
self
.
caller
),
self
.
id
+
'-'
+
sanitize_phonenumber
(
self
.
callee
)])
phone_logger
.
debug
(
"Moving channels to the created bridge: {}"
.
format
(
bridge
.
name
,))
bridge
.
addChannel
(
channels
)
phone_logger
.
info
(
"Call now fully connected: {} <-> {}"
.
format
(
self
.
caller
,
self
.
callee
))
...
...
@@ -366,9 +357,10 @@ class Call(object):
# Call is being picked up, we want to play a song
try
:
channel
=
ari
.
Channel
(
config
[
'asterisk'
],
event
[
'channel'
][
'id'
])
phone_logger
.
debug
(
'Preparing to create a playback'
)
# We're starting a playback, with the same ID as the channel, to keep track of it
channel
.
playback
(
channel
.
name
,
config
[
'asterisk'
][
'playback'
])
# Moving the channel to the MOH Bridge
phone_logger
.
debug
(
'Moving call {} to the garage'
.
format
(
event
[
'channel'
][
'id'
]))
moh_bridge
=
ari
.
Bridge
(
config
[
'asterisk'
],
config
[
'moh'
][
'name'
])
moh_bridge
.
addChannel
(
event
[
'channel'
][
'id'
])
except
Exception
as
e
:
phone_logger
.
exception
(
e
)
raise
e
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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