Class: Jabber::UserTune::Helper

Inherits:
PubSub::ServiceHelper show all
Defined in:
lib/xmpp4r/tune/helper/helper.rb

Overview

A Helper for XEP-0118 User Tune

Use this helper to send user tunes, or receive them from a specified jid. Described at www.xmpp.org/extensions/xep-0118.html

For example: <pre> h = UserTune::Helper( @client, ‘[email protected]’ ) h.add_usertune_callback do |tune|

puts "Now playing: #{tune.title} by #{tune.artist}"

end </pre>

Also see the examples provided.

Instance Method Summary collapse

Methods inherited from PubSub::ServiceHelper

#add_event_callback, #create_collection_node, #create_node, #delete_item_from, #delete_node, #get_affiliations, #get_config_from, #get_items_from, #get_options_from, #get_subids_for, #get_subscribers_from, #get_subscriptions_from, #get_subscriptions_from_all_nodes, #initialize, #publish_item_to, #publish_item_with_id_to, #purge_items_from, #set_affiliations, #set_config_for, #set_options_for, #subscribe_to, #to_s, #unsubscribe_from

Constructor Details

This class inherits a constructor from Jabber::PubSub::ServiceHelper

Instance Method Details

#add_usertune_callback(prio = 200, ref = nil, &block) ⇒ Object

Add a callback that will be invoked when a tune is received from the jid specified when you constructed the Helper.



48
49
50
51
52
53
54
55
# File 'lib/xmpp4r/tune/helper/helper.rb', line 48

def add_usertune_callback(prio = 200, ref = nil, &block)
  add_event_callback(prio, ref) do |event|
    tune = event.first_element('items/item/tune')
    if tune
      block.call(tune)
    end
  end
end

#now_playing(track) ⇒ Object

Send out the tune currently playing.

track
Jabber::UserTune::Tune

the tune currently playing



31
32
33
34
35
36
# File 'lib/xmpp4r/tune/helper/helper.rb', line 31

def now_playing(track)
  item = Jabber::PubSub::Item.new()
  item.add(track)

  publish_item_to(NS_USERTUNE, item)
end

#stop_playingObject

Use this method to indicate that you have stopped playing a tune.



41
42
43
# File 'lib/xmpp4r/tune/helper/helper.rb', line 41

def stop_playing
  now_playing(Jabber::UserTune::Tune.new())
end