Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
piphone-sip
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
4
Issues
4
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
piphone
piphone-sip
Commits
8acb208f
Commit
8acb208f
authored
May 09, 2016
by
okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing some stupid syntaxes
parent
191b11fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
16 deletions
+15
-16
ari.py
ari.py
+1
-2
config.ini
config.ini
+1
-1
piphone.py
piphone.py
+13
-13
No files found.
ari.py
View file @
8acb208f
...
...
@@ -15,7 +15,7 @@ def ari_call(config, verbs, method, payload):
if
method
.
lower
()
==
'del'
:
call
=
requests
.
delete
else
:
call
=
getattr
s
(
requests
,
method
.
lower
())
call
=
getattr
(
requests
,
method
.
lower
())
payload
[
'app'
]
=
config
[
'app'
]
payload
[
'api_key'
]
=
config
[
'key'
]
+
':'
+
config
[
'password'
]
result
=
call
(
full_url
,
data
=
payload
)
...
...
@@ -68,7 +68,6 @@ class Bridge(object):
return
ari_call
(
self
.
config
,
[
'bridges'
,
self
.
name
,
'addChannel'
],
'POST'
,
{
'channel'
:
channel
})
except
:
raise
class
Channel
(
object
):
'''
This class is used to regroup all the method to manage a Channel
...
...
config.ini
View file @
8acb208f
[webservice]
base_url
=
ws://
185.34.33.12
:8088/ari/events
base_url
=
ws://
pi3.lqdn.fr
:8088/ari/events
[asterisk]
protocol
=
http
...
...
piphone.py
View file @
8acb208f
...
...
@@ -151,14 +151,14 @@ async def hold_bridge():
It will play a song in a loop.
'''
try
:
bridge
=
ari
.
Bridge
(
self
.
config
[
'asterisk'
],
self
.
config
[
'moh'
][
'name'
],
'holding'
)
bridge
=
ari
.
Bridge
(
config
[
'asterisk'
],
config
[
'moh'
][
'name'
],
'holding'
)
except
Exception
as
e
:
phone_logger
.
critical
(
"No Music On Hold (moh) section in config file. Exiting"
)
phone_logger
.
E
xception
(
e
)
phone_logger
.
e
xception
(
e
)
raise
e
try
:
result
=
bridge
.
create
()
result
=
bridge
.
startMoh
(
self
.
config
[
'moh'
][
'class'
])
result
=
bridge
.
startMoh
(
config
[
'moh'
][
'class'
])
except
Exception
as
e
:
phone_logger
.
error
(
"Cannot start 'on hold' bridge"
)
phone_logger
.
exception
(
e
)
...
...
@@ -174,7 +174,7 @@ async def listen():
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_bridge
s
()
await
hold_bridge
()
while
running
==
True
:
try
:
event
=
await
ws
.
recv
()
...
...
@@ -279,16 +279,16 @@ class Call(object):
# 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
(
self
.
config
[
'asterisk'
],
event
[
'channel'
][
'id'
],
'sound:mario'
)
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
(
self
.
config
[
'asterisk'
],
self
.
config
[
'moh'
][
'name'
])
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
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
(
self
.
config
[
'asterisk'
],
self
.
id
+
'-'
+
sanitize_phonenumber
(
self
.
callee
))
channel
=
ari
.
Channel
(
config
[
'asterisk'
],
self
.
id
+
'-'
+
sanitize_phonenumber
(
self
.
callee
))
channel
.
originate
(
endpoint
)
except
AssertionError
as
e
:
logging
.
error
(
"Received a DTMF sequence out le being in a '{}' state, ignoring: {}"
.
format
(
self
.
state
(),
event
[
'digit'
]))
...
...
@@ -304,7 +304,7 @@ class Call(object):
# Are we the caller orthe callee?
if
event
[
'channel'
][
'id'
].
endswith
(
self
.
callee
):
# Step 1 create a bridge
bridge
=
ari
.
Bridge
(
self
.
config
[
'asterisk'
],
self
.
id
,
'mixing'
)
bridge
=
ari
.
Bridge
(
config
[
'asterisk'
],
self
.
id
,
'mixing'
)
phone_logger
.
debug
(
"Creating a bridges to connect {} to {}"
.
format
(
self
.
caller
,
self
.
callee
,))
bridge
.
create
()
# Step 2, moving channels
...
...
@@ -315,10 +315,10 @@ class Call(object):
return
# Call is being picked up, we want to play a song
try
:
channel
=
ari
.
Channel
(
self
.
config
[
'asterisk'
],
event
[
'channel'
][
'id'
])
channel
=
ari
.
Channel
(
config
[
'asterisk'
],
event
[
'channel'
][
'id'
])
logging
.
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
,
self
.
config
[
'asterisk'
][
'playback'
])
channel
.
playback
(
channel
.
name
,
config
[
'asterisk'
][
'playback'
])
except
Exception
as
e
:
logging
.
exception
(
e
)
raise
e
...
...
@@ -332,7 +332,7 @@ class Call(object):
'''
self
.
update
((
':'
.
join
([
event
[
'type'
],
event
[
'channel'
][
'id'
].
split
(
'-'
)[
-
1
]]),
event
[
'timestamp'
],))
# We want to check if the moh bridge is opened
moh_bridge
=
ari
.
Bridge
(
self
.
config
[
'asterisk'
],
self
.
config
[
'moh'
][
'name'
],
'holding'
)
moh_bridge
=
ari
.
Bridge
(
config
[
'asterisk'
],
config
[
'moh'
][
'name'
],
'holding'
)
try
:
moh_bridge
.
status
()
except
HTTPError
as
e
:
...
...
@@ -342,8 +342,8 @@ class Call(object):
# Now, let's create the channel
try
:
endpoint
=
'SIP/'
+
sanitize_phonenumber
(
self
.
caller
)
+
'@'
+
self
.
config
[
'asterisk'
][
'sip-context'
]
channel
=
ari
.
Channel
(
self
.
config
[
'asterisk'
],
self
.
id
+
'-'
+
sanitize_phonenumber
(
self
.
caller
))
endpoint
=
'SIP/'
+
sanitize_phonenumber
(
self
.
caller
)
+
'@'
+
config
[
'asterisk'
][
'sip-context'
]
channel
=
ari
.
Channel
(
config
[
'asterisk'
],
self
.
id
+
'-'
+
sanitize_phonenumber
(
self
.
caller
))
channel
.
originate
()
except
Exception
as
e
:
logging
.
exception
(
e
)
...
...
Write
Preview
Markdown
is supported
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