lib/onim/engine.rb
# Connnect to the jabber server and
# * add hooks
# * get roster
# * set initial presence
Connnect to the jabber server and
add hooks
get roster
set initial presence
Connnect to the jabber server and add hooks get roster set initial presence
def connect
      debug "setting up.. jid #{base.config[:account_jid]}"    
      cl = Jabber::Client.new(Jabber::JID::new(base.config[:account_jid]))
      @client = cl
      begin
        debug "connect"
        cl.connect 
        debug "auth"
        cl.auth base.config[:account_password]
      rescue Exception => ex        
        debug "EX: #{ex.class} "
        debug ex.backtrace
        @base.auth_failure        
      end
      @roster = Jabber::Roster::Helper.new cl              
      @roster.add_presence_callback do |item,oldpres,pres|
        pres = Jabber::Presence.new unless pres
        oldpres = Jabber::Presence.new unless oldpres            
        status = pres.status.to_s
        presence = pres.show || :available
        jid = item.jid
        presence = :unavailable if pres.status.to_s == 'unavailable'
        debug "item #{jid} chaged presence to #{presence} status #{status}"
        base.item_presence_change(jid.to_s,presence,status)
      end
      @base.roster_items = get_roster_items
      @client.send Jabber::Presence.new
      set_presence
      cl.add_message_callback do |m|
        if m.type != :error
          debug "message received from #{m.from} type #{m.type}"
          @base.message_received(m.from.to_s,m.body)
        end
      end
    end
def connect debug "setting up.. jid #{base.config[:account_jid]}" cl = Jabber :: Client . new ( Jabber :: JID :: new ( base . config [ :account_jid ] ) ) @client = cl begin debug "connect" cl . connect debug "auth" cl . auth base . config [ :account_password ] rescue Exception => ex debug "EX: #{ex.class} " debug ex . backtrace @base . auth_failure end @roster = Jabber :: Roster :: Helper . new cl @roster . add_presence_callback do | item , oldpres , pres | pres = Jabber :: Presence . new unless pres oldpres = Jabber :: Presence . new unless oldpres status = pres . status . to_s presence = pres . show || :available jid = item . jid presence = :unavailable if pres . status . to_s == 'unavailable' debug "item #{jid} chaged presence to #{presence} status #{status}" base . item_presence_change ( jid . to_s , presence , status ) end @base . roster_items = get_roster_items @client . send Jabber :: Presence . new set_presence cl . add_message_callback do | m | if m . type != :error debug "message received from #{m.from} type #{m.type}" @base . message_received ( m . from . to_s , m . body ) end end end
Connnect to the jabber server and
 add hooks
 get roster
 set initial presence
Connnect to the jabber server and add hooks get roster set initial presence
# XXX should catch only proper exception types (including Jabber::ClientAuthenticationFailure) # XXX unavaliable