changeset 128:2849ec993d89

basic radio collective
author Goffi <goffi@goffi.org>
date Mon, 23 Jan 2012 00:15:19 +0100
parents e19a8de8b3de
children dd0d39ae7d24
files browser_side/panels.py browser_side/radiocol.py libervia.py libervia.tac
diffstat 4 files changed, 40 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/panels.py	Sun Jan 22 19:38:05 2012 +0100
+++ b/browser_side/panels.py	Mon Jan 23 00:15:19 2012 +0100
@@ -743,6 +743,8 @@
         #TODO: check that the game is launched, and manage errors
         if game_type=="Tarot":
             return self.tarot_panel 
+        elif game_type=="RadioCol":
+            return self.radiocol_panel 
 
 class WidgetsPanel(ScrollPanelWrapper):
     
--- a/browser_side/radiocol.py	Sun Jan 22 19:38:05 2012 +0100
+++ b/browser_side/radiocol.py	Mon Jan 23 00:15:19 2012 +0100
@@ -24,13 +24,14 @@
 from pyjamas.ui.HorizontalPanel import HorizontalPanel
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.FormPanel import FormPanel
-from pyjamas.ui.DockPanel import DockPanel
 from pyjamas.ui.NamedFrame import NamedFrame
 from pyjamas.ui.FileUpload import FileUpload
 from pyjamas.ui.Label import Label
 from pyjamas.ui.Button import Button
 from pyjamas.ui.ClickListener import ClickHandler
 from pyjamas.ui.MouseListener import MouseHandler
+from pyjamas.ui.Hidden import Hidden
+from pyjamas.ui.HTML import HTML
 from pyjamas import Window
 
 from jid import JID
@@ -41,22 +42,21 @@
 
     def __init__(self):
         VerticalPanel.__init__(self)
+        self.title = Label("title:")
         self.artist = Label("artist:")
         self.album = Label("album:")
-        self.title = Label("title:")
+        self.add(self.title)
         self.add(self.artist)
         self.add(self.album)
-        self.add(self.title)
 
 class ControlPanel(FormPanel):
     """Panel used to show controls to add a song, or vote for the current one"""
 
-    def __init__(self):
+    def __init__(self, referee):
         FormPanel.__init__(self)
         self.setEncoding(FormPanel.ENCODING_MULTIPART)
         self.setMethod(FormPanel.METHOD_POST)
         self.setAction("upload") # set this as appropriate
-        #self.setTarget("results")
         vPanel = VerticalPanel()
 
         hPanel = HorizontalPanel()
@@ -68,9 +68,10 @@
         hPanel.add(Button("Upload song", getattr(self, "onBtnClick")))
 
         vPanel.add(hPanel)
-
-        results = NamedFrame("results")
-        vPanel.add(results)
+        
+        #We need to know the referee
+        referee_field = Hidden('referee', referee)
+        vPanel.add(referee_field)
 
         self.add(vPanel)
         self.addFormHandler(self)
@@ -102,19 +103,21 @@
         # Now we set up the layout
         self.left_panel = VerticalPanel()
         self.add(self.left_panel)
-        self.right_panel = DockPanel()
+        self.right_panel = VerticalPanel()
         self.metadata_panel = MetadataPanel()
-        self.right_panel.add(self.metadata_panel, DockPanel.CENTER)
-        self.control_panel = ControlPanel()
-        self.right_panel.add(self.control_panel, DockPanel.SOUTH)
+        self.right_panel.add(self.metadata_panel)
+        self.control_panel = ControlPanel(self.referee)
+        self.right_panel.add(self.control_panel)
         self.add(self.right_panel)
-        self.right_panel.setBorderWidth(1)
+        #self.right_panel.setBorderWidth(1)
         self.left_panel.add(Label("Musique 1"))
         self.left_panel.add(Label("Musique 2"))
-        self.left_panel.add(Label("Musique 3"))
-        self.left_panel.add(Label("Musique 4"))
-        self.left_panel.add(Label("Musique 5"))
+        self.audio = HTML("")
+        self.right_panel.add(self.audio)
 
         
         self.addClickListener(self)
+    
+    def radiocolPreload(self, filename, title, artist, album):
+        self.audio.setHTML('<audio preload="auto" controls="controls" src="radiocol/%s" />' % html_sanitize(filename))
 
--- a/libervia.py	Sun Jan 22 19:38:05 2012 +0100
+++ b/libervia.py	Mon Jan 23 00:15:19 2012 +0100
@@ -243,6 +243,8 @@
             self._tarotGameGenericCb(name, args[0], args[1:])
         elif name == 'radiocolStarted':
             self._radioColStartedCb(*args)
+        elif name == 'radiocolPreload':
+            self._radioColGenericCb(name, args[0], args[1:])
         elif name == 'subscribe':
             self._subscribeCb(*args)
         elif name == 'contactDeleted':
@@ -360,6 +362,12 @@
             if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid:
                 lib_wid.startGame("RadioCol", referee)
     
+    def _radioColGenericCb(self, event_name, room_jid, args):
+        for lib_wid in self.libervia_widgets:
+            if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid:
+                getattr(lib_wid.getGame("RadioCol"), event_name)(*args) 
+
+    
     def _getPresenceStatusCb(self, presence_data):
         for entity in presence_data:
             for resource in presence_data[entity]:
--- 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