From 15c57bf4cca547fb6566411245e3af6ca6199744 Mon Sep 17 00:00:00 2001 From: sqozz Date: Tue, 1 Sep 2020 22:30:15 +0200 Subject: [PATCH] Add call status functionality --- README.md | 1 + pylinphone.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index d2c385c..c33b077 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Currently implemented Features: * pause the call (`call-pause`) * resume the call (`call-resume`) * play dtmf tones (`dtmf`) +* get call status (`call-status`) Features supported by the unix socket (linphone deamon): diff --git a/pylinphone.py b/pylinphone.py index c463a96..45d883d 100644 --- a/pylinphone.py +++ b/pylinphone.py @@ -93,6 +93,22 @@ class LinphoneCommunicationSocket(): else: raise RuntimeError(answer["error"]) + def call_status(self, call_id): + self.socket.send("call-status {call_id}".format(call_id=call_id).encode("ascii")) + answer = self._await_answer() + + if answer["status"]: + data = answer["data"] + status = { + "state": data[0].split(":", 1)[1].strip(), + "from": data[1].split(":", 1)[1].strip(), + "direction": data[2].split(":", 1)[1].strip(), + "duration": int(data[3].split(":", 1)[1].strip()) + } + 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()