Add one more argument to state message, pausing with lagged connection should now work better (at all)
This commit is contained in:
parent
5b529bf36f
commit
c9bb239506
@ -28,15 +28,15 @@ class SyncClientProtocol(CommandProtocol):
|
||||
self.drop_with_error('Malformed state attributes')
|
||||
return
|
||||
|
||||
paused, position, name = arg
|
||||
counter, paused, position, name = arg
|
||||
|
||||
self.manager.update_global_state(paused, position, name)
|
||||
self.manager.update_global_state(counter, paused, position, name)
|
||||
|
||||
def handle_connected_ping(self, arg):
|
||||
self.send_message('pong', arg)
|
||||
|
||||
def send_state(self, paused, position):
|
||||
self.send_message('state', ('paused' if paused else 'playing'), int(position*100))
|
||||
def send_state(self, counter, paused, position):
|
||||
self.send_message('state', counter, ('paused' if paused else 'playing'), int(position*100))
|
||||
|
||||
|
||||
states = dict(
|
||||
@ -75,6 +75,8 @@ class Manager(object):
|
||||
self.player_paused = True
|
||||
self.player_position = 0.0
|
||||
|
||||
self.counter = 0
|
||||
|
||||
def get_current_global_position(self):
|
||||
return self.global_position + (time.time() - self.last_global_update)
|
||||
|
||||
@ -115,8 +117,10 @@ class Manager(object):
|
||||
def send_status(self):
|
||||
if not self.running:
|
||||
return
|
||||
self.counter += 1
|
||||
if self.protocol:
|
||||
self.protocol.send_state(self.player_paused, self.player_position)
|
||||
print 'sent', self.counter
|
||||
self.protocol.send_state(self.counter, self.player_paused, self.player_position)
|
||||
self.schedule_send_status()
|
||||
|
||||
|
||||
@ -140,11 +144,12 @@ class Manager(object):
|
||||
if old != value and self.global_paused != value:
|
||||
self.send_status()
|
||||
|
||||
def update_global_state(self, paused, position, name):
|
||||
def update_global_state(self, counter, paused, position, name):
|
||||
self.global_paused = paused
|
||||
self.global_position = position
|
||||
self.last_global_update = time.time()
|
||||
if self.player:
|
||||
print 'received', counter
|
||||
if self.player and not (self.counter and counter < self.counter):
|
||||
changed = False
|
||||
if abs(self.player_position - position) > 4:
|
||||
self.player.send_set_position(position)
|
||||
|
||||
@ -35,9 +35,9 @@ class SyncServerProtocol(CommandProtocol):
|
||||
self.drop_with_error('Malformed state attributes')
|
||||
return
|
||||
|
||||
paused, position, _ = arg
|
||||
counter, paused, position, _ = arg
|
||||
|
||||
self.factory.update_state(self, paused, position)
|
||||
self.factory.update_state(self, counter, paused, position)
|
||||
|
||||
def handle_connected_seek(self, arg):
|
||||
try:
|
||||
@ -59,8 +59,8 @@ class SyncServerProtocol(CommandProtocol):
|
||||
)))
|
||||
|
||||
|
||||
def send_state(self, paused, position, who_last_changed):
|
||||
self.send_message('state', ('paused' if paused else 'playing'), int(position*100), who_last_changed)
|
||||
def send_state(self, counter, paused, position, who_last_changed):
|
||||
self.send_message('state', counter, ('paused' if paused else 'playing'), int(position*100), who_last_changed)
|
||||
|
||||
def send_seek(self, position, who_seeked):
|
||||
self.send_message('seek', int(position*100), who_seeked)
|
||||
@ -96,6 +96,8 @@ class WatcherInfo(object):
|
||||
self.last_ping_time = None
|
||||
self.last_ping_value = None
|
||||
|
||||
self.counter = 0
|
||||
|
||||
def update_position(self, position):
|
||||
if self.ping is not None:
|
||||
position += self.ping
|
||||
@ -132,12 +134,13 @@ class SyncFactory(Factory):
|
||||
self.pause_change_by = None
|
||||
# send info someone quit
|
||||
|
||||
def update_state(self, watcher_proto, paused, position):
|
||||
def update_state(self, watcher_proto, counter, paused, position):
|
||||
watcher = self.watchers.get(watcher_proto)
|
||||
if not watcher:
|
||||
return
|
||||
|
||||
watcher.update_position(position)
|
||||
watcher.counter = counter
|
||||
pause_changed = paused != self.paused
|
||||
|
||||
curtime = time.time()
|
||||
@ -176,9 +179,9 @@ class SyncFactory(Factory):
|
||||
position += watcher.ping
|
||||
|
||||
if self.pause_change_by:
|
||||
watcher.watcher_proto.send_state(self.paused, position, self.pause_change_by.name)
|
||||
watcher.watcher_proto.send_state(watcher.counter, self.paused, position, self.pause_change_by.name)
|
||||
else:
|
||||
watcher.watcher_proto.send_state(self.paused, position, None)
|
||||
watcher.watcher_proto.send_state(watcher.counter, self.paused, position, None)
|
||||
|
||||
watcher.last_update_sent = curtime
|
||||
|
||||
|
||||
@ -8,16 +8,21 @@ def split_args(args, number):
|
||||
return args.split(None, number-1)
|
||||
|
||||
def parse_state(args):
|
||||
args = split_args(args, 3)
|
||||
args = split_args(args, 4)
|
||||
l = len(args)
|
||||
if l == 2:
|
||||
state, position = args
|
||||
if l == 3:
|
||||
counter, state, position = args
|
||||
who_changed_state = None
|
||||
elif l == 3:
|
||||
state, position, who_changed_state = args
|
||||
elif l == 4:
|
||||
counter, state, position, who_changed_state = args
|
||||
else:
|
||||
return
|
||||
|
||||
try:
|
||||
counter = int(counter)
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
if not state in ('paused', 'playing'):
|
||||
return
|
||||
|
||||
@ -30,7 +35,7 @@ def parse_state(args):
|
||||
|
||||
position /= 100.0
|
||||
|
||||
return paused, position, who_changed_state
|
||||
return counter, paused, position, who_changed_state
|
||||
|
||||
def find_exec_path(name):
|
||||
if os.access(name, os.X_OK):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user