Add call stat functionality

This commit is contained in:
sqozz 2020-09-02 20:45:23 +02:00
parent 15c57bf4cc
commit 016fef57a2
2 changed files with 37 additions and 0 deletions

View file

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

View file

@ -109,6 +109,42 @@ class LinphoneCommunicationSocket():
else: else:
raise RuntimeError(answer["error"]) 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): def call_resume(self, call_id):
self.socket.send("call-resume {call_id}".format(call_id=call_id).encode("ascii")) self.socket.send("call-resume {call_id}".format(call_id=call_id).encode("ascii"))
answer = self._await_answer() answer = self._await_answer()