plugin radiocol: sync data includes a "jump to time" info
This commit is contained in:
parent
8b700a6d48
commit
4818da04fc
1 changed files with 20 additions and 8 deletions
|
|
@ -63,7 +63,7 @@ class Radiocol(object):
|
|||
info(_("Radio collective initialization"))
|
||||
self.inheritFromRoomGame(host)
|
||||
RoomGame._init_(self, host, PLUGIN_INFO, (NC_RADIOCOL, RADIOC_TAG),
|
||||
game_init={'queue': [], 'upload': True, 'playing': False, 'to_delete': {}})
|
||||
game_init={'queue': [], 'upload': True, 'playing': None, 'playing_time': 0, 'to_delete': {}})
|
||||
self.host = host
|
||||
host.bridge.addMethod("radiocolLaunch", ".plugin", in_sign='asss', out_sign='', method=self.prepareRoom)
|
||||
host.bridge.addMethod("radiocolCreate", ".plugin", in_sign='sass', out_sign='', method=self.createGame)
|
||||
|
|
@ -135,11 +135,13 @@ class Radiocol(object):
|
|||
queue = radio_data['queue']
|
||||
if not queue:
|
||||
#nothing left to play, we need to wait for uploads
|
||||
radio_data['playing'] = False
|
||||
radio_data['playing'] = None
|
||||
return
|
||||
song = queue.pop(0)
|
||||
filename, length = song['filename'], float(song['length'])
|
||||
self.send(room_jid, ('', 'play'), {'filename': filename}, profile=profile)
|
||||
radio_data['playing'] = song
|
||||
radio_data['playing_time'] = time.time()
|
||||
|
||||
if not radio_data['upload'] and len(queue) < QUEUE_LIMIT:
|
||||
#upload is blocked and we now have resources to get more, we reactivate it
|
||||
|
|
@ -229,21 +231,31 @@ class Radiocol(object):
|
|||
if not radio_data['playing'] and len(queue) == QUEUE_TO_START:
|
||||
# We have not started playing yet, and we have QUEUE_TO_START
|
||||
# songs in queue. We can now start the party :)
|
||||
radio_data['playing'] = True
|
||||
self.playNext(room_jid, profile)
|
||||
else:
|
||||
error(_('Unmanaged game element: %s') % elt.name)
|
||||
|
||||
def getSyncData(self, room_jid_s, force_nicks=[]):
|
||||
data = {}
|
||||
status = self.games[room_jid_s]['status']
|
||||
game_data = self.games[room_jid_s]
|
||||
status = game_data['status']
|
||||
nicks = [nick for nick in status if status[nick] == 'desync']
|
||||
for nick in force_nicks:
|
||||
if nick not in nicks:
|
||||
nicks.append(nick)
|
||||
for nick in nicks:
|
||||
if len(self.games[room_jid_s]['queue']) > 0:
|
||||
data[nick] = copy.deepcopy(self.games[room_jid_s]['queue'])
|
||||
if len(self.games[room_jid_s]['queue']) == QUEUE_LIMIT:
|
||||
data[nick].append(domish.Element(('', 'no_upload')))
|
||||
elements = []
|
||||
if game_data['playing']:
|
||||
preload = copy.deepcopy(game_data['playing'])
|
||||
preload['filename'] += '#t=%.2f' % (time.time() - game_data['playing_time'])
|
||||
elements.append(preload)
|
||||
play = domish.Element(('', 'play'))
|
||||
play['filename'] = preload['filename']
|
||||
elements.append(play)
|
||||
if len(game_data['queue']) > 0:
|
||||
elements.extend(copy.deepcopy(game_data['queue']))
|
||||
if len(game_data['queue']) == QUEUE_LIMIT:
|
||||
elements.append(domish.Element(('', 'no_upload')))
|
||||
if data:
|
||||
data[nick] = elements
|
||||
return data
|
||||
|
|
|
|||
Loading…
Reference in a new issue