Show joins, lefts, and present people after join
This commit is contained in:
parent
eaaa661099
commit
3c0b8154ac
@ -29,6 +29,21 @@ class SyncClientProtocol(CommandProtocol):
|
|||||||
self.manager.stop()
|
self.manager.stop()
|
||||||
CommandProtocol.handle_error(self, args)
|
CommandProtocol.handle_error(self, args)
|
||||||
|
|
||||||
|
@arg_count(0)
|
||||||
|
def handle_init_hello(self, args):
|
||||||
|
self.change_state('connected')
|
||||||
|
|
||||||
|
@arg_count(1, 2)
|
||||||
|
def handle_init_present(self, args):
|
||||||
|
if len(args) == 2:
|
||||||
|
who, what = args
|
||||||
|
else:
|
||||||
|
who, what = args[0], None
|
||||||
|
if what:
|
||||||
|
print '%s is present and is playing %s' % (who, what)
|
||||||
|
else:
|
||||||
|
print '%s is present' % who
|
||||||
|
|
||||||
@arg_count(3, 4)
|
@arg_count(3, 4)
|
||||||
def handle_connected_state(self, args):
|
def handle_connected_state(self, args):
|
||||||
args = parse_state(args)
|
args = parse_state(args)
|
||||||
@ -47,7 +62,16 @@ class SyncClientProtocol(CommandProtocol):
|
|||||||
@arg_count(2)
|
@arg_count(2)
|
||||||
def handle_connected_playing(self, args):
|
def handle_connected_playing(self, args):
|
||||||
who, what = args
|
who, what = args
|
||||||
print '%s plays %s' % (who, what)
|
print '%s is playing %s' % (who, what)
|
||||||
|
|
||||||
|
@arg_count(1)
|
||||||
|
def handle_connected_joined(self, args):
|
||||||
|
print '%s joined' % args[0]
|
||||||
|
|
||||||
|
@arg_count(1)
|
||||||
|
def handle_connected_left(self, args):
|
||||||
|
print '%s left' % args[0]
|
||||||
|
|
||||||
|
|
||||||
def send_state(self, counter, paused, position):
|
def send_state(self, counter, paused, position):
|
||||||
self.send_message('state', counter, ('paused' if paused else 'playing'), int(position*1000))
|
self.send_message('state', counter, ('paused' if paused else 'playing'), int(position*1000))
|
||||||
@ -57,14 +81,20 @@ class SyncClientProtocol(CommandProtocol):
|
|||||||
|
|
||||||
|
|
||||||
states = dict(
|
states = dict(
|
||||||
|
init = dict(
|
||||||
|
present = 'handle_init_present',
|
||||||
|
hello = 'handle_init_hello',
|
||||||
|
),
|
||||||
connected = dict(
|
connected = dict(
|
||||||
state = 'handle_connected_state',
|
state = 'handle_connected_state',
|
||||||
seek = 'handle_connected_seek',
|
seek = 'handle_connected_seek',
|
||||||
ping = 'handle_connected_ping',
|
ping = 'handle_connected_ping',
|
||||||
playing = 'handle_connected_playing',
|
playing = 'handle_connected_playing',
|
||||||
|
joined = 'handle_connected_joined',
|
||||||
|
left = 'handle_connected_left',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
initial_state = 'connected'
|
initial_state = 'init'
|
||||||
|
|
||||||
class SyncClientFactory(ClientFactory):
|
class SyncClientFactory(ClientFactory):
|
||||||
def __init__(self, manager):
|
def __init__(self, manager):
|
||||||
|
|||||||
@ -89,6 +89,21 @@ class SyncServerProtocol(CommandProtocol):
|
|||||||
def send_playing(self, who, what):
|
def send_playing(self, who, what):
|
||||||
self.send_message('playing', who, what)
|
self.send_message('playing', who, what)
|
||||||
|
|
||||||
|
def send_present(self, who, what):
|
||||||
|
if what:
|
||||||
|
self.send_message('present', who, what)
|
||||||
|
else:
|
||||||
|
self.send_message('present', who)
|
||||||
|
|
||||||
|
def send_joined(self, who):
|
||||||
|
self.send_message('joined', who)
|
||||||
|
|
||||||
|
def send_left(self, who):
|
||||||
|
self.send_message('left', who)
|
||||||
|
|
||||||
|
def send_hello(self):
|
||||||
|
self.send_message('hello')
|
||||||
|
|
||||||
|
|
||||||
states = dict(
|
states = dict(
|
||||||
init = dict(
|
init = dict(
|
||||||
@ -110,6 +125,7 @@ class WatcherInfo(object):
|
|||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
self.position = 0
|
self.position = 0
|
||||||
|
self.filename = None
|
||||||
self.max_position = 0
|
self.max_position = 0
|
||||||
self.last_update = None
|
self.last_update = None
|
||||||
self.last_update_sent = None
|
self.last_update_sent = None
|
||||||
@ -139,12 +155,20 @@ class SyncFactory(Factory):
|
|||||||
def add_watcher(self, watcher_proto, name):
|
def add_watcher(self, watcher_proto, name):
|
||||||
watcher = WatcherInfo(watcher_proto, name)
|
watcher = WatcherInfo(watcher_proto, name)
|
||||||
self.watchers[watcher_proto] = watcher
|
self.watchers[watcher_proto] = watcher
|
||||||
|
for receiver in self.watchers.itervalues():
|
||||||
|
if receiver == watcher:
|
||||||
|
continue
|
||||||
|
receiver.watcher_proto.send_joined(name)
|
||||||
|
watcher_proto.send_present(receiver.name, receiver.filename)
|
||||||
|
watcher_proto.send_hello()
|
||||||
self.send_state_to(watcher)
|
self.send_state_to(watcher)
|
||||||
self.schedule_send_ping(watcher_proto)
|
self.schedule_send_ping(watcher_proto)
|
||||||
# send info someone joined
|
|
||||||
|
|
||||||
def remove_watcher(self, watcher_proto):
|
def remove_watcher(self, watcher_proto):
|
||||||
watcher = self.watchers.pop(watcher_proto, None)
|
watcher = self.watchers.pop(watcher_proto, None)
|
||||||
|
for receiver in self.watchers.itervalues():
|
||||||
|
if receiver != watcher:
|
||||||
|
receiver.watcher_proto.send_left(watcher.name)
|
||||||
if self.pause_change_by == watcher:
|
if self.pause_change_by == watcher:
|
||||||
self.pause_change_time = None
|
self.pause_change_time = None
|
||||||
self.pause_change_by = None
|
self.pause_change_by = None
|
||||||
@ -251,6 +275,8 @@ class SyncFactory(Factory):
|
|||||||
if not watcher:
|
if not watcher:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
watcher.filename = filename
|
||||||
|
|
||||||
for receiver in self.watchers.itervalues():
|
for receiver in self.watchers.itervalues():
|
||||||
if receiver != watcher:
|
if receiver != watcher:
|
||||||
receiver.watcher_proto.send_playing(watcher.name, filename)
|
receiver.watcher_proto.send_playing(watcher.name, filename)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user