70 likes | 196 Views
Talking JSON over Comet to deliver content for a network music player. Ben Klaas Logitech Squeezebox Developer. The Squeezebox. Networked Music Player Local Music Internet Radio Podcasts Online Services (Rhapsody, Pandora, Classical.com, Last.FM, etc.). Shameless plug:
E N D
Talking JSON over Comet to deliver content for a network music player Ben Klaas Logitech Squeezebox Developer
The Squeezebox • Networked Music Player • Local Music • Internet Radio • Podcasts • Online Services (Rhapsody, Pandora, Classical.com, Last.FM, etc.) Shameless plug: http://logitechsqueezebox.com
The Client-Server Environment • Server is in Perl: Woot! • Server talks to N thin(nish) clients • New Squeezeboxes use a menu-driven GUI that is written in Lua • Need a communication layer to drive that marriage
All you do to me is Talk Talk • XML is for suckers • JSON! • Polling is for suckers • Subscribe! Comet!
The Basics • Perl-side sends initial top levels of client menu items (with callbacks) • Lua-side renders the menu items, registers callbacks • Item called (My Music->Albums->) • Perl does query, returns total count and first set of items • Lua continues sending requests until menu filled
Subscriptions • That’s fine for Request-Response code • What about information from the server that the client needs to know about? • Server status • Player status • New home menu items • UI Feedback *
A basic example • Lua: subscribe to displaystatus -- subscribe to displaystatus cmd = { 'displaystatus', 'subscribe:showbriefly' } self.slimServer.comet:subscribe( '/slim/displaystatus/' .. self.id, _getSink(self, cmd), self.id, cmd ) • Perl: registers client’s displaystatus subscription • Perl: create menu item with callback to push message through Comet displaystatus subscription • Go!