comparison libervia.tac @ 128:2849ec993d89

basic radio collective
author Goffi <goffi@goffi.org>
date Mon, 23 Jan 2012 00:15:19 +0100
parents e19a8de8b3de
children dd0d39ae7d24
comparison
equal deleted inserted replaced
127:e19a8de8b3de 128:2849ec993d89
266 """Tell to the server that we are ready to start the game""" 266 """Tell to the server that we are ready to start the game"""
267 profile = ISATSession(self.session).profile 267 profile = ISATSession(self.session).profile
268 self.sat_host.bridge.tarotGameContratChoosed(player_nick, referee, contrat, profile) 268 self.sat_host.bridge.tarotGameContratChoosed(player_nick, referee, contrat, profile)
269 269
270 def jsonrpc_tarotGamePlayCards(self, player_nick, referee, cards): 270 def jsonrpc_tarotGamePlayCards(self, player_nick, referee, cards):
271 """Tell to the server that we are ready to start the game""" 271 """Tell to the server the cards we want to put on the table"""
272 profile = ISATSession(self.session).profile 272 profile = ISATSession(self.session).profile
273 self.sat_host.bridge.tarotGamePlayCards(player_nick, referee, cards, profile) 273 self.sat_host.bridge.tarotGamePlayCards(player_nick, referee, cards, profile)
274 274
275 def jsonrpc_launchRadioCollective(self, invited): 275 def jsonrpc_launchRadioCollective(self, invited):
276 """Create a room, invite people, and start a radio collective""" 276 """Create a room, invite people, and start a radio collective"""
620 return jsonrpc.JSONRPC.render(self, request) 620 return jsonrpc.JSONRPC.render(self, request)
621 621
622 class UploadManager(Resource): 622 class UploadManager(Resource):
623 """This class manage the upload of a file 623 """This class manage the upload of a file
624 It redirect the stream to SàT core backend""" 624 It redirect the stream to SàT core backend"""
625 #XXX: only used for RadioCol so far
625 isLeaf = True 626 isLeaf = True
626 627
627 def __init__(self, sat_host): 628 def __init__(self, sat_host):
628 self.sat_host=sat_host 629 self.sat_host=sat_host
629 self.upload_dir = tempfile.mkdtemp() 630 self.upload_dir = tempfile.mkdtemp()
630 self.sat_host.addCleanup(shutil.rmtree, self.upload_dir) 631 self.sat_host.addCleanup(shutil.rmtree, self.upload_dir)
632
633 def getTmpDir(self):
634 return self.upload_dir
631 635
632 def render(self, request): 636 def render(self, request):
633 """ 637 """
634 Render method with some hacks: 638 Render method with some hacks:
635 - if login is requested, try to login with form data 639 - if login is requested, try to login with form data
636 - except login, every method is jsonrpc 640 - except login, every method is jsonrpc
637 - user doesn't need to be authentified for isRegistered, but must be for all other methods 641 - user doesn't need to be authentified for isRegistered, but must be for all other methods
638 """ 642 """
639 filename = str(uuid.uuid4()) 643 filename = str(uuid.uuid4())
640 with open(os.path.join(self.upload_dir, filename),'w') as f: 644 filepath = os.path.join(self.upload_dir, filename)
645 with open(filepath,'w') as f:
641 f.write(request.args['song'][0]) 646 f.write(request.args['song'][0])
647 profile = ISATSession(request.getSession()).profile
648 self.sat_host.bridge.radiocolSongAdded(request.args['referee'][0], filepath, profile)
642 return "OK" 649 return "OK"
643 650
644 class Libervia(service.Service): 651 class Libervia(service.Service):
645 652
646 def __init__(self): 653 def __init__(self):
666 for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'updatedValue']: 673 for signal_name in ['presenceUpdate', 'newMessage', 'subscribe', 'contactDeleted', 'newContact', 'updatedValue']:
667 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name)) 674 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name))
668 #plugins 675 #plugins
669 for signal_name in ['personalEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat', 676 for signal_name in ['personalEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',
670 'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn', 'tarotGameScore', 677 'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn', 'tarotGameScore',
671 'radiocolStarted']: 678 'radiocolStarted', 'radiocolPreload']:
672 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin") 679 self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin")
673 self.media_dir = self.bridge.getConfig('','media_dir') 680 self.media_dir = self.bridge.getConfig('','media_dir')
674 self.local_dir = self.bridge.getConfig('','local_dir') 681 self.local_dir = self.bridge.getConfig('','local_dir')
675 root.putChild('json_signal_api', self.signal_handler) 682 root.putChild('json_signal_api', self.signal_handler)
676 root.putChild('json_api', MethodHandler(self)) 683 root.putChild('json_api', MethodHandler(self))
678 root.putChild('upload', _upload) 685 root.putChild('upload', _upload)
679 root.putChild('blog', MicroBlog(self)) 686 root.putChild('blog', MicroBlog(self))
680 root.putChild('css', ProtectedFile("server_css/")) 687 root.putChild('css', ProtectedFile("server_css/"))
681 root.putChild(os.path.dirname(MEDIA_DIR), ProtectedFile(self.media_dir)) 688 root.putChild(os.path.dirname(MEDIA_DIR), ProtectedFile(self.media_dir))
682 root.putChild(os.path.dirname(AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, AVATARS_DIR))) 689 root.putChild(os.path.dirname(AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, AVATARS_DIR)))
690 root.putChild('radiocol', ProtectedFile(_upload.getTmpDir(), defaultType="audio/ogg")) #We cheat for PoC because we know we are on the same host, so we use directly upload dir
683 self.site = server.Site(root) 691 self.site = server.Site(root)
684 self.site.sessionFactory = LiberviaSession 692 self.site.sessionFactory = LiberviaSession
685 693
686 def addCleanup(self, callback, *args, **kwargs): 694 def addCleanup(self, callback, *args, **kwargs):
687 """Add cleaning method to call when service is stopped 695 """Add cleaning method to call when service is stopped