From ee97eb6d276cd9cd2d16eadf6060152bb0bebbfd Mon Sep 17 00:00:00 2001 From: shortcutme Date: Wed, 29 Aug 2018 19:53:44 +0200 Subject: [PATCH] Calculate media time correction from connections --- src/Connection/ConnectionServer.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Connection/ConnectionServer.py b/src/Connection/ConnectionServer.py index 7abd76d7..9959abff 100644 --- a/src/Connection/ConnectionServer.py +++ b/src/Connection/ConnectionServer.py @@ -306,3 +306,15 @@ class ConnectionServer(object): def onInternetOffline(self): self.log.info("Internet offline") + + def getTimeCorrection(self): + corrections = sorted([ + connection.handshake.get("time") - connection.handshake_time + connection.last_ping_delay + for connection in self.connections + if connection.handshake.get("time") and connection.last_ping_delay + ]) + if len(corrections) < 6: + return 0.0 + mid = len(corrections) / 2 - 1 + median = (corrections[mid - 1] + corrections[mid] + corrections[mid + 1]) / 3 + return median