comparison xmpp.js @ 0:363600705376 default tip

Initial commit.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 23 Aug 2011 18:43:15 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:363600705376
1 #!/usr/bin/env node
2
3 var MPD = require('./lib');
4 var xmpp = require('node-xmpp');
5 var config = require('./config');
6
7 var mpd = new MPD();
8 var conn = new xmpp.Client(config);
9 var id = 0;
10 var NS = 'http://jabber.org/protocol/tune';
11
12 var publish = function() {
13 mpd.send('status', function(s) {
14 mpd.send('currentsong', function(cs) {
15 var tune = new xmpp.Element('tune', {xmlns: NS});
16
17 if (cs.file && s.state === 'play') {
18 // Don't publish "rating" and "uri".
19 if (cs.Artist)
20 tune.c('artist').t(cs.Artist);
21 if (cs.Time)
22 tune.c('length').t(cs.Time);
23 if (cs.Album)
24 tune.c('source').t(cs.Album);
25 if (cs.Title)
26 tune.c('title').t(cs.Title);
27 if (cs.Track)
28 tune.c('track').t(cs.Track);
29 }
30
31 conn.send(new xmpp.Element('iq', {type: 'set', id: 'mpd-'+(++id)})
32 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
33 .c('publish', {node: NS})
34 .c('item')
35 .cnode(tune).up()
36 .up()
37 .up()
38 .up());
39
40 mpd.send('idle player', publish);
41 });
42 });
43 };
44
45 // We suppose that the XMPP connection will be open after the MPD one.
46 conn.on('online', publish);
47
48 // vim: sts=2 et sw=2