BBC Radio Labs and XMPP

God bless BBC Radio Labs. They get to build some cool little things including a fun little XMPP server. Its pushing out messages that usually only get seen on the front of DAB radios. I whipped this ruby script together pretty quick (you can tell), but shows how easy you can connect to it.

require 'rubygems'
require 'ruby-growl'
require 'xmpp4r-simple'

username = 'myusername'
password = 'password'
domain = 'hug.hellomatty.com'
im = Jabber::Simple.new("#{username}@#{domain}", password)
im.status(:chat, 'Hello world')

#  This bit just adds a few radio stations.  Should only be run once for your user
#
#  %w(radio1 radio2 radio3 radio4 5live 6music radio7 1xtra).each do |r|
#    im.add("#{r}@#{domain}")
#  end

g = Growl.new "localhost", "ruby-growl", ["ruby-growl Notification"], nil, "growl"
i = 0
while true
  i+=1
  if im.connected? == true
    im.presence_updates.each do |friend, old_presence, new_presence|
      if new_presence != nil
        puts "#{friend.gsub("@#{domain}", '')} #{new_presence}"
        g.notify("ruby-growl Notification", friend.gsub("@#{domain}", ''), new_presence)
      end
    end
  else
    puts '**************************** disconnected *************************'
    im = Jabber::Simple.new("#{username}@#{domain}", password)
    im.status(:chat, 'Hello world')
  end
  sleep(2)
  if i == 10
    # reconnect every now and then as we seem to be having odd issues.  a bug really
    im.reconnect
    i = 0
  end
end

Here is some sample output.

radio3: Details from bbc.co.uk/radio3 or call 08700 100 300.
1xtra: 1Xtra Dancehall Show - Robbo Ranx. Txt 88111 [network rates apply].
radio4: The World Tonight. Web - bbc.co.uk/news
radio2: Mark Lamarr. Mark presents the Shake, Rattle and Roll Show.
5live: Richard Bacon: Lively and provocative discussion regarding the day's key stories

Now I have no idea what I can do with this (twitter posting is already done to death), so I might have a think about this sort of thing. Be fun if it makes it into production.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>