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
30295f08
Commit
30295f08
authored
Jan 23, 2017
by
okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Managing destrcution of channels a bit better
parent
4841ab42
Pipeline
#778
passed with stage
in 2 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
ari.py
ari.py
+1
-0
piphone.py
piphone.py
+23
-4
No files found.
ari.py
View file @
30295f08
...
...
@@ -79,6 +79,7 @@ class Bridge(object):
return
ari_call
(
self
.
config
,
[
'bridges'
,
self
.
name
,
'addChannel'
],
'POST'
,
{
'channel'
:
channel
})
except
:
raise
def
delete
(
self
):
'''
Let's delete the bridge
...
...
piphone.py
View file @
30295f08
...
...
@@ -216,6 +216,7 @@ class Call(object):
actions
=
{
'Created'
:
'call_caller'
,
'ChannelStateChange'
:
'change'
,
'ChannelDtmfReceived'
:
'dtmf'
,
'ChannelDestroyed'
:
'hangup'
,
'ChannelHangupRequest'
:
'hangup'
}
def
__init__
(
self
,
caller
,
callee
,
owner
,
callid
=
None
,
db
=
None
):
...
...
@@ -279,9 +280,21 @@ class Call(object):
more than one channel.
If there's more than one, then we need to send a hangup to the other side and then delete
our channel, if not we need to delete ourselves and then delete the bridge.
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
])
bridge
=
ari
.
Bridge
(
config
[
'asterisk'
],
bridge_id
,
'mixed'
)
try
:
bridge
=
ari
.
Bridge
(
config
[
'asterisk'
],
bridge_id
,
'mixed'
)
except
:
# 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
[
'cause_txt'
])
,
event
[
'timestamp'
]))
return
results
=
json
.
loads
(
bridge
.
status
())
if
len
(
results
[
'channels'
])
==
0
:
# We were the last channel standing
...
...
@@ -326,11 +339,14 @@ class Call(object):
Let's change the state of the call
'''
# First we need to check if it's really a change ie, if the new state is not the previous one
self
.
update
((
':'
.
join
([
event
[
'channel'
][
'state'
],
event
[
'channel'
][
'id'
].
split
(
'-'
)[
-
1
]]),
event
[
'timestamp'
],))
self
.
update
((
':'
.
join
([
event
[
'channel'
][
'state'
]
,
event
[
'channel'
][
'id'
].
split
(
'-'
)[
-
1
]]
,
event
[
'cause_txt'
])
,
event
[
'timestamp'
],))
phone_logger
.
info
(
"New state for call {}: {}"
.
format
(
event
[
'channel'
][
'id'
],
event
[
'channel'
][
'state'
]))
# We now need to take action according to our new state
if
event
[
'channel'
][
'state'
]
==
'Up'
:
# Are we the caller orthe callee?
# Are we the caller or
the callee?
if
event
[
'channel'
][
'id'
].
endswith
(
self
.
callee
):
# Step 1 create a bridge
bridge
=
ari
.
Bridge
(
config
[
'asterisk'
],
self
.
id
,
'mixing'
)
...
...
@@ -359,7 +375,10 @@ class Call(object):
The bridge needed to connect the calls together will be created later.
'''
self
.
update
((
':'
.
join
([
event
[
'type'
],
event
[
'channel'
][
'id'
].
split
(
'-'
)[
-
1
]]),
event
[
'timestamp'
],))
self
.
update
((
':'
.
join
([
event
[
'type'
]
,
event
[
'channel'
][
'id'
].
split
(
'-'
)[
-
1
]]
,
event
[
'cause_txt'
])
,
event
[
'timestamp'
],))
# We want to check if the moh bridge is opened
moh_bridge
=
ari
.
Bridge
(
config
[
'asterisk'
],
config
[
'moh'
][
'name'
],
'holding'
)
try
:
...
...
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