diff 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
line wrap: on
line diff
--- a/libervia.tac	Sun Jan 22 19:38:05 2012 +0100
+++ b/libervia.tac	Mon Jan 23 00:15:19 2012 +0100
@@ -268,7 +268,7 @@
         self.sat_host.bridge.tarotGameContratChoosed(player_nick, referee, contrat, profile)
     
     def jsonrpc_tarotGamePlayCards(self, player_nick, referee, cards):
-        """Tell to the server that we are ready to start the game"""
+        """Tell to the server the cards we want to put on the table"""
         profile = ISATSession(self.session).profile
         self.sat_host.bridge.tarotGamePlayCards(player_nick, referee, cards, profile)
 
@@ -622,6 +622,7 @@
 class UploadManager(Resource):
     """This class manage the upload of a file
     It redirect the stream to SàT core backend"""
+    #XXX: only used for RadioCol so far
     isLeaf = True
 
     def __init__(self, sat_host):
@@ -629,6 +630,9 @@
         self.upload_dir = tempfile.mkdtemp()
         self.sat_host.addCleanup(shutil.rmtree, self.upload_dir)
 
+    def getTmpDir(self):
+        return self.upload_dir
+
     def render(self, request):
         """
         Render method with some hacks:
@@ -637,8 +641,11 @@
            - user doesn't need to be authentified for isRegistered, but must be for all other methods
         """
         filename = str(uuid.uuid4())
-        with open(os.path.join(self.upload_dir, filename),'w') as f:
+        filepath = os.path.join(self.upload_dir, filename)
+        with open(filepath,'w') as f:
             f.write(request.args['song'][0])
+        profile = ISATSession(request.getSession()).profile
+        self.sat_host.bridge.radiocolSongAdded(request.args['referee'][0], filepath, profile)
         return "OK"
 
 class Libervia(service.Service):
@@ -668,7 +675,7 @@
         #plugins
         for signal_name in ['personalEvent', 'roomJoined', 'roomUserJoined', 'roomUserLeft', 'tarotGameStarted', 'tarotGameNew', 'tarotGameChooseContrat',
                             'tarotGameShowCards', 'tarotGameInvalidCards', 'tarotGameCardsPlayed', 'tarotGameYourTurn', 'tarotGameScore', 
-                            'radiocolStarted']:
+                            'radiocolStarted', 'radiocolPreload']:
             self.bridge.register(signal_name, self.signal_handler.getGenericCb(signal_name), "plugin")
         self.media_dir = self.bridge.getConfig('','media_dir')
         self.local_dir = self.bridge.getConfig('','local_dir')
@@ -680,6 +687,7 @@
         root.putChild('css', ProtectedFile("server_css/"))
         root.putChild(os.path.dirname(MEDIA_DIR), ProtectedFile(self.media_dir))
         root.putChild(os.path.dirname(AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, AVATARS_DIR)))
+        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
         self.site = server.Site(root)
         self.site.sessionFactory = LiberviaSession