Calculate media time correction from connections

This commit is contained in:
shortcutme 2018-08-29 19:53:44 +02:00
parent 16f7dafcdf
commit ee97eb6d27
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -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