Sha256: f544240ef62924ecd155f0121fd6f572245d535067415bd7462f11ce1bbfc077

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

#!/usr/bin/env ruby

require 'xmpp4r'
require 'xmpp4r/roster'
require 'xmpp4r/tune'
require 'rbosa'

#
# Send XEP-0118 User Tune events...
#
# See Jabber::UserTune::Helper for the gory details...
#
# NB needs rbosa library to access iTunes - only on MacOSX
#

if ARGV.length != 2:
  puts "Usage: ruby tune_server.rb <jid> <pw>"
  exit 1
end

jid=ARGV[0]
pw=ARGV[1]

Jabber::debug=true

cl = Jabber::Client.new(jid)
cl.connect
cl.auth(pw)

# Following XEP-0163 PEP we need to
# ensure we have a 'both' subscription to the Tune client
roster = Jabber::Roster::Helper.new(cl)
roster.add_subscription_request_callback do |item,pres|
  roster.accept_subscription(pres.from)

  reply = pres.answer
  reply.type = :subscribe
  cl.send(reply)
end

cl.send(Jabber::Presence.new.set_show(:chat))

t=Jabber::UserTune::Helper.new(cl, nil)

itunes=OSA.app('iTunes')

loop do
  track = itunes.current_track

  if track
    puts "Now playing: #{track.name} by #{track.artist}"
    t.now_playing(Jabber::UserTune::Tune.new(track.artist, track.name))
  end

  sleep 5
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
bryanl-xmpp4r-0.3.2 data/doc/xmpp4r/examples/basic/tune_server.rb
heipei-xmpp4r-0.3.2 data/doc/xmpp4r/examples/basic/tune_server.rb