Browse Source

Add call stat functionality

master
sqozz 4 years ago
parent
commit
016fef57a2
  1. 1
      README.md
  2. 36
      pylinphone.py

1
README.md

@ -12,6 +12,7 @@ Currently implemented Features: @@ -12,6 +12,7 @@ Currently implemented Features:
* resume the call (`call-resume`)
* play dtmf tones (`dtmf`)
* get call status (`call-status`)
* get call stats (`call-stats`)
Features supported by the unix socket (linphone deamon):

36
pylinphone.py

@ -109,6 +109,42 @@ class LinphoneCommunicationSocket(): @@ -109,6 +109,42 @@ class LinphoneCommunicationSocket():
else:
raise RuntimeError(answer["error"])
def call_stats(self, call_id):
self.socket.send("call-stats {call_id}".format(call_id=call_id).encode("ascii"))
answer = self._await_answer()
if answer["status"]:
stats_offsets = [i for i, x in enumerate(answer["data"]) if "Id:" in x]
stats = {
"audio": {},
"video": {}
}
stat_type = answer["data"][stats_offsets[0]+1].split(":", 1)[1].strip().lower()
for stat in answer["data"][:stats_offsets[1]]:
k, v = stat.split(":", 1)
key = k.strip().lower().replace(" ", "_")
value = v.strip().lower().replace(" ", "_")
try:
value = int(value)
except Exception:
pass
stats[stat_type].update({key: value})
stat_type = answer["data"][stats_offsets[1]+1].split(":", 1)[1].strip().lower()
for stat in answer["data"][stats_offsets[1]:]:
k, v = stat.split(":", 1)
key = k.strip().lower().replace(" ", "_")
value = v.strip().lower().replace(" ", "_")
try:
value = int(value)
except Exception:
pass
stats[stat_type].update({key: value})
return status
else:
raise RuntimeError(answer["error"])
def call_resume(self, call_id):
self.socket.send("call-resume {call_id}".format(call_id=call_id).encode("ascii"))
answer = self._await_answer()

Loading…
Cancel
Save