Class Jabber::MUC::SimpleMUCClient
In: lib/xmpp4r/muc/helper/simplemucclient.rb
Parent: MUCClient
Message Presence XMPPStanza Iq Singleton IdGenerator XMPPElement X IqQuery Error Connection Client Component Client Comparable JID RuntimeError AuthenticationFailure ErrorException NoNameXmlnsRegistered SOCKS5Error REXML::Element Stream SOCKS5Bytestreams SOCKS5BytestreamsTarget SOCKS5BytestreamsInitiator XMPPElement StreamHost IqSiFileRange IqSiFile StreamHostUsed IqSi XRosterItem RosterItem IqFeature XMUCUserItem XMUCUserInvite IqPubSub Items Subscription IqPubSubOwner Item Event Feature Item Identity XDataField XDataReported XDataTitle XDataInstructions IqVcard SOCKS5BytestreamsServerStreamHost TCPSocket SOCKS5Socket IqQuery IqQueryBytestreams IqQueryVersion IqQueryRoster IqQueryMUCOwner IqQueryRPC IqQueryDiscoItems IqQueryDiscoInfo IBB IBBTarget IBBInitiator Responder SimpleResponder Iq IqCommand RosterXItem XRoster RosterX X XMUCUser XMUC XDelay XData XParent MUCClient SimpleMUCClient XMLRPC::ParserWriterChooseMixin Client Server XMLRPC::ParseContentType XMLRPC::BasicServer Base DigestMD5 Plain ServiceHelper NodeHelper FileSource CallbackList Callback Semaphore StreamParser SOCKS5BytestreamsPeer SOCKS5BytestreamsServer IBBQueueItem Responder Helper MUCBrowser NodeBrowser Helper Helper lib/xmpp4r/authenticationfailure.rb lib/xmpp4r/xmppstanza.rb lib/xmpp4r/callbacks.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/connection.rb lib/xmpp4r/iq.rb lib/xmpp4r/jid.rb lib/xmpp4r/errorexception.rb lib/xmpp4r/client.rb lib/xmpp4r/stream.rb lib/xmpp4r/semaphore.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/x.rb lib/xmpp4r/error.rb lib/xmpp4r/component.rb lib/xmpp4r/query.rb lib/xmpp4r/xmppelement.rb lib/xmpp4r/message.rb lib/xmpp4r/presence.rb lib/xmpp4r/bytestreams/helper/ibb/initiator.rb lib/xmpp4r/bytestreams/iq/si.rb lib/xmpp4r/bytestreams/iq/bytestreams.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb lib/xmpp4r/bytestreams/helper/ibb/base.rb lib/xmpp4r/bytestreams/helper/ibb/target.rb Bytestreams XParent lib/xmpp4r/version/iq/version.rb lib/xmpp4r/version/helper/responder.rb lib/xmpp4r/version/helper/simpleresponder.rb Version lib/xmpp4r/command/iq/command.rb lib/xmpp4r/command/helper/responder.rb Command lib/xmpp4r/roster/helper/roster.rb lib/xmpp4r/roster/iq/roster.rb lib/xmpp4r/roster/x/roster.rb Roster lib/xmpp4r/feature_negotiation/iq/feature.rb FeatureNegotiation lib/xmpp4r/muc/x/muc.rb lib/xmpp4r/muc/helper/mucclient.rb lib/xmpp4r/muc/x/mucuseritem.rb lib/xmpp4r/muc/helper/mucbrowser.rb lib/xmpp4r/muc/x/mucuserinvite.rb lib/xmpp4r/muc/iq/mucowner.rb lib/xmpp4r/muc/helper/simplemucclient.rb MUC lib/xmpp4r/rpc/helper/server.rb lib/xmpp4r/rpc/helper/client.rb lib/xmpp4r/rpc/iq/rpc.rb RPC lib/xmpp4r/sasl.rb SASL lib/xmpp4r/delay/x/delay.rb Delay lib/xmpp4r/pubsub/stanzas/subscription.rb lib/xmpp4r/pubsub/helper/servicehelper.rb lib/xmpp4r/pubsub/stanzas/item.rb lib/xmpp4r/pubsub/helper/nodehelper.rb lib/xmpp4r/pubsub/iq/pubsub.rb lib/xmpp4r/pubsub/stanzas/event.rb lib/xmpp4r/pubsub/helper/nodebrowser.rb lib/xmpp4r/pubsub/stanzas/items.rb PubSub lib/xmpp4r/httpbinding/client.rb HTTPBinding lib/xmpp4r/bytestreams/helper/filetransfer.rb TransferSource FileTransfer lib/xmpp4r/discovery/iq/discoinfo.rb lib/xmpp4r/discovery/iq/discoitems.rb Discovery lib/xmpp4r/dataforms/x/data.rb Dataforms lib/xmpp4r/vcard/helper/vcard.rb lib/xmpp4r/vcard/iq/vcard.rb Vcard Jabber dot/m_80_0.png

This class attempts to implement a lot of complexity of the Multi-User Chat protocol. If you want to implement JEP0045 yourself, use Jabber::MUC::MUCClient for some minor abstraction.

Minor flexibility penalty: the on_* callbacks are no CallbackLists and may therefore only used once. A second invocation will overwrite the previous set up block.

*Hint:* the parameter time may be nil if the server didn‘t send it.

Example usage:

  my_muc = Jabber::MUC::SimpleMUCClient.new(my_client)
  my_muc.on_message { |time,nick,text|
    puts (time || Time.new).strftime('%I:%M') + " <#{nick}> #{text}"
  }
  my_muc.join(Jabber::JID.new('jdev@conference.jabber.org/XMPP4R-Bot'))

Please take a look at Jabber::MUC::MUCClient for derived methods, such as MUCClient#join, MUCClient#exit, …

Methods

Public Class methods

Initialize a SimpleMUCClient

stream:[Stream] to operate on
jid:[JID] room@component/nick
password:[String] Optional password

[Source]

    # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 39
39:       def initialize(stream)
40:         super
41: 
42:         @room_message_block = nil
43:         @message_block = nil
44:         @private_message_block = nil
45:         @subject_block = nil
46: 
47:         @subject = nil
48: 
49:         @join_block = nil
50:         add_join_callback(999) { |pres|
51:           # Presence time
52:           time = nil
53:           pres.each_element('x') { |x|
54:             if x.kind_of?(Delay::XDelay)
55:               time = x.stamp
56:             end
57:           }
58: 
59:           # Invoke...
60:           @join_block.call(time, pres.from.resource) if @join_block
61:           false
62:         }
63: 
64:         @leave_block = nil
65:         @self_leave_block = nil
66:         add_leave_callback(999) { |pres|
67:           # Presence time
68:           time = nil
69:           pres.each_element('x') { |x|
70:             if x.kind_of?(Delay::XDelay)
71:               time = x.stamp
72:             end
73:           }
74: 
75:           # Invoke...
76:           if pres.from == jid
77:             @self_leave_block.call(time) if @self_leave_block
78:           else
79:             @leave_block.call(time, pres.from.resource) if @leave_block
80:           end
81:           false
82:         }
83:       end

Public Instance methods

Request the MUC to invite users to this room

Sample usage:

  my_muc.invite( {'wiccarocks@shakespeare.lit/laptop' => 'This coven needs both wiccarocks and hag66.',
                  'hag66@shakespeare.lit' => 'This coven needs both hag66 and wiccarocks.'} )
recipients:[Hash] of [JID] => [String] Reason

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 156
156:       def invite(recipients)
157:         msg = Message.new
158:         x = msg.add(XMUCUser.new)
159:         recipients.each { |jid,reason|
160:           x.add(XMUCUserInvite.new(jid, reason))
161:         }
162:         send(msg)
163:       end

Block to be called when somebody enters the room

If there is a non-nil time passed to the block, chances are great that this is initial presence from a participant after you have joined the room.

block:Takes two arguments: time, nickname

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 205
205:       def on_join(&block)
206:         @join_block = block
207:       end

Block to be called when somebody leaves the room

block:Takes two arguments: time, nickname

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 212
212:       def on_leave(&block)
213:         @leave_block = block
214:       end

Block to be invoked when a message from a participant to the whole room arrives

block:Takes three arguments: time, sender nickname, text

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 179
179:       def on_message(&block)
180:         @message_block = block
181:       end

Block to be invoked when a private message from a participant to you arrives.

block:Takes three arguments: time, sender nickname, text

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 187
187:       def on_private_message(&block)
188:         @private_message_block = block
189:       end

Block to be invoked when a message from the room arrives

Example:

  Astro has joined this session
block:Takes two arguments: time, text

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 171
171:       def on_room_message(&block)
172:         @room_message_block = block
173:       end

Block to be called when you leave the room

Deactivation occurs afterwards.

block:Takes one argument: time

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 221
221:       def on_self_leave(&block)
222:         @self_leave_block = block
223:       end

Block to be invoked when somebody sets a new room subject

block:Takes three arguments: time, nickname, new subject

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 194
194:       def on_subject(&block)
195:         @subject_block = block
196:       end

Send a simple text message

text:[String] Message body
to:[String] Optional nick if directed to specific user

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 145
145:       def say(text, to=nil)
146:         send(Message.new(nil, text), to)
147:       end

Room subject/topic

result:[String] The subject

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 125
125:       def subject
126:         @subject
127:       end

Change the room‘s subject/topic

This will not be reflected by SimpleMUCClient#subject immediately, wait for SimpleMUCClient#on_subject

s:[String] New subject

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 135
135:       def subject=(s)
136:         msg = Message.new
137:         msg.subject = s
138:         send(msg)
139:       end

Private Instance methods

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 87
 87:       def handle_message(msg)
 88:         super
 89: 
 90:         # Message time (e.g. history)
 91:         time = nil
 92:         msg.each_element('x') { |x|
 93:           if x.kind_of?(Delay::XDelay)
 94:             time = x.stamp
 95:           end
 96:         }
 97:         sender_nick = msg.from.resource
 98: 
 99: 
100:         if msg.subject
101:           @subject = msg.subject
102:           @subject_block.call(time, sender_nick, @subject) if @subject_block
103:         end
104:         
105:         if msg.body
106:           if sender_nick.nil?
107:             @room_message_block.call(time, msg.body) if @room_message_block
108:           else
109:             if msg.type == :chat
110:               @private_message_block.call(time, msg.from.resource, msg.body) if @private_message_block
111:             elsif msg.type == :groupchat
112:               @message_block.call(time, msg.from.resource, msg.body) if @message_block
113:             else
114:               # ...?
115:             end
116:           end
117:         end
118:       end

[Validate]