First broadcast of filename being playing

This commit is contained in:
Tomasz Fluxid Kowalczyk 2012-02-04 17:43:37 +01:00
parent 8b11382e98
commit eaaa661099
2 changed files with 18 additions and 1 deletions

View File

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

View File

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