Class Jabber::Session
In: lib/jabber4r/session.rb
Parent: Object

The Jabber Session is the main class for dealing with a Jabber service.

Methods

Attributes

connection  [R]  The Jabber::Protocol::Connection instance
host  [R]  The host this session is connected to
iqHandlers  [RW]  The iq handlers for this session
jid  [R]  The Jabber::JID of the current session
password  [RW]  The password to use for authenticating this session
port  [R]  The port (defaults to 5222) that this session is connected to
resource  [RW]  The resource id for this session
roster  [R]  The Jabber::Roster instance
session_id  [R]  The session id sent from the Jabber service upon connection
username  [RW]  The username to use for authenticating this session

Public Class methods

Session creation factory that creates a session, logs in, requests the roster, registers message and presence filters and announces initial presence. Login is done via plaintext password authentication.

jid:[String | JID] The account information ("account@host/resouce")
password:[String] The account password
port:[Integer = 5222] The host port
digest:[Boolean = false] Use digest authentication?
return:[Jabber::Session] The new session

Session creation factory that creates a session, logs in, requests the roster, registers message and presence filters and announces initial presence. Login is done via digest (SHA) password authentication.

jid:[String | JID] The account information ("account@host/resouce")
password:[String] The account password
port:[Integer = 5222] The host port
return:[Jabber::Session] The new session

Creates a new session connected to the supplied host and port. The method attempts to build a Jabber::Protocol::Connection object and send the open_stream XML message. It then blocks to recieve the coorisponding reply open_stream and sets the session_id from that xml element.

host:[String] The hostname of the Jabber service
port:[Integer=5222] The port of the Jabber service
raise:[RuntimeException] If connection fails

Public Instance methods

Add a listener for new messages

Usage:id = session.add_message_listener do |message|
  puts message

end

&block [Block] The block to process a message

return:[String] The listener ID…used to remove the listener

Registers a listener for roster events

&block:[Block] The listener block to process roster changes
return:[String] A roster ID to use when removing this listener

Sends an away from computer presence message

status:[String] The status message

Sends a do not disturb presence message

status:[String] The status message

Sends an extended away presence message

status:[String] The status message

Sends a free for chat presence message

status:[String] The status message

Sends the initial presence message to the Jabber service

Sends a ‘normal’ presence message

status:[String] The status message

Authenticate (logs into) this session with the supplied credentials. The method blocks waiting for a reply to the login message. Sets the authenticated attribute based on result.

username:[String] The username to use for authentication
password:[String] The password to use for authentication
resource:[String] The resource ID for this session
digest:[Boolean=false] True to use digest authentication (not sending password in the clear)
return:[Boolean] Whether the authentication succeeded or failed

Same as _release

Deletes a message listener

id:[String] A messanger ID returned from add_message_listener

Deletes the roster listener

id:[String] A roster ID received from the add_roster_listener method

Counter for message IDs

return:[String] A unique message id for this session

Is this an authenticated session?

return:[Boolean] True if the session is authenticated

Creates a new message addressed to the supplied JID of type CHAT

to:[JID] Who to send the message to
return:[Jabber::Protocol::Message] The new (chat) message

Creates a new message addressed to the supplied JID of type GROUPCHAT

to:[JID] Who to send the message to
return:[Jabber::Protocol::Message] The new (group chat) message

Creates a new message to the supplied JID of type NORMAL

to:[Jabber::JID] Who to send the message to
type:[String = Jabber::Protocol::Message::NORMAL] The type of message to send (see Jabber::Protocol::Message)
return:[Jabber::Protocol::Message] The new message

Notifies message listeners of the received message

message:[Jabber::Protocol::Message] The received message

Set a handler for session exceptions that get caught in communicating with the Jabber server.

Registers the roster filter with the Connection to forward IQ requests to the IQ listeners(they register by namespace)

Adds a filter to the Connection to manage tracking messages to forward to registered message listeners.

Adds a filter to the Connection to manage tracking resources that come online/offline

Registers the roster filter with the Connection to forward roster changes to the roster listeners.

Releases the connection and resets the session. The Session instance is no longer usable after this method is called

Requests the Roster for the (authenticated) account. This method blocks until a reply to the roster request is received.

Sets the handler for subscription requests, notifications, etc.

[Validate]