diff --git a/syncplay/client.py b/syncplay/client.py index 834e52c..e427bda 100644 --- a/syncplay/client.py +++ b/syncplay/client.py @@ -44,6 +44,11 @@ class SyncClientProtocol(CommandProtocol): def handle_connected_ping(self, args): self.send_message('pong', args[0]) + @arg_count(2) + def handle_connected_playing(self, args): + who, what = args + print '%s plays %s' % (who, what) + def send_state(self, counter, paused, position): self.send_message('state', counter, ('paused' if paused else 'playing'), int(position*1000)) diff --git a/syncplay/server.py b/syncplay/server.py index c12667b..c67b7dd 100644 --- a/syncplay/server.py +++ b/syncplay/server.py @@ -63,7 +63,7 @@ class SyncServerProtocol(CommandProtocol): @arg_count(1) def handle_connected_playing(self, args): - pass + self.factory.playing_received(self, args[0]) def __hash__(self): return hash('|'.join(( @@ -86,6 +86,9 @@ class SyncServerProtocol(CommandProtocol): def send_ping(self, value): self.send_message('ping', value) + def send_playing(self, who, what): + self.send_message('playing', who, what) + states = dict( init = dict( @@ -243,3 +246,12 @@ class SyncFactory(Factory): def schedule_send_ping(self, watcher_proto, when=1): reactor.callLater(when, self.send_ping_to, watcher_proto) + def playing_received(self, watcher_proto, filename): + watcher = self.watchers.get(watcher_proto) + if not watcher: + return + + for receiver in self.watchers.itervalues(): + if receiver != watcher: + receiver.watcher_proto.send_playing(watcher.name, filename) +