Class Jabber::MUC::SimpleMUCClient
In: lib/xmpp4r/muc/helper/simplemucclient.rb
Parent: MUCClient
Message Presence XMPPStanza Iq XMPPElement ErrorResponse X IqQuery JabberError ComponentAuthenticationFailure ArgumentError InvalidChatState SOCKS5Error ServerError NoNameXmlnsRegistered ServerDisconnected ClientAuthenticationFailure Connection Client Component Connection Client Singleton IdGenerator Comparable JID Enumerable CallbackList Items Publish StandardError REXML::Element Stream XMPPElement Location IqFeature StreamHost IqSiFile IqSiFileRange IqSi StreamHostUsed XRosterItem RosterItem C Body HTML UserItem XMUCUserInvite Configuration Retract IqPubSub Item IqPubSubOwner Event Subscription Unsubscribe Tune XDataField XDataReported XDataTitle XDataInstructions Feature Item Identity IqVcard PubSub::ServiceHelper Helper Helper SOCKS5Bytestreams SOCKS5BytestreamsTarget SOCKS5BytestreamsInitiator SOCKS5BytestreamsServerStreamHost TCPSocket SOCKS5Socket IqQuery IqQueryBytestreams IqQueryRoster IqQueryVersion IqQueryRPC IqQueryMUCOwner IqQueryMUCAdmin IqQueryDiscoItems IqQueryDiscoInfo IqQueryLastActivity IBB IBBTarget IBBInitiator RosterXItem XRoster RosterX X XDelay XMUC XMUCUser XData Responder SimpleResponder Iq IqCommand XMLRPC::ParserWriterChooseMixin Client Server XMLRPC::ParseContentType XMLRPC::BasicServer MUCClient SimpleMUCClient MUC::UserItem XMUCUserItem IqQueryMUCAdminItem XParent SubscriptionConfig NodeConfig OwnerNodeConfig EventItems ServiceHelper OAuthServiceHelper NodeHelper EventItem Base Anonymous DigestMD5 Plain FileSource Base Bot Callback StreamParser Semaphore SOCKS5BytestreamsPeer SOCKS5BytestreamsServer IBBQueueItem Helper Responder Helper Listener MUCBrowser NodeBrowser ListenerMocker Helper Responder Helper Helper Helper lib/xmpp4r/message.rb lib/xmpp4r/connection.rb lib/xmpp4r/xmppstanza.rb lib/xmpp4r/iq.rb lib/xmpp4r/callbacks.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/stream.rb lib/xmpp4r/client.rb lib/xmpp4r/jid.rb lib/xmpp4r/x.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/semaphore.rb lib/xmpp4r/errors.rb lib/xmpp4r/component.rb lib/xmpp4r/presence.rb lib/xmpp4r/xmppelement.rb lib/xmpp4r/query.rb XParent lib/xmpp4r/location/helper/helper.rb lib/xmpp4r/location/location.rb UserLocation lib/xmpp4r/feature_negotiation/iq/feature.rb FeatureNegotiation lib/xmpp4r/bytestreams/iq/si.rb lib/xmpp4r/bytestreams/helper/ibb/initiator.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb lib/xmpp4r/bytestreams/iq/bytestreams.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb lib/xmpp4r/bytestreams/helper/ibb/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb lib/xmpp4r/bytestreams/helper/ibb/base.rb Bytestreams lib/xmpp4r/roster/x/roster.rb lib/xmpp4r/roster/helper/roster.rb lib/xmpp4r/roster/iq/roster.rb Roster lib/xmpp4r/version/helper/responder.rb lib/xmpp4r/version/helper/simpleresponder.rb lib/xmpp4r/version/iq/version.rb Version lib/xmpp4r/command/iq/command.rb lib/xmpp4r/command/helper/responder.rb Command lib/xmpp4r/caps/helper/helper.rb lib/xmpp4r/caps/c.rb Caps lib/xmpp4r/reliable.rb Reliable lib/xmpp4r/delay/x/delay.rb Delay lib/xmpp4r/xhtml/html.rb XHTML lib/xmpp4r/rpc/helper/server.rb lib/xmpp4r/rpc/helper/client.rb lib/xmpp4r/rpc/iq/rpc.rb RPC lib/xmpp4r/muc/iq/mucadminitem.rb lib/xmpp4r/muc/x/muc.rb lib/xmpp4r/muc/item.rb lib/xmpp4r/muc/helper/simplemucclient.rb lib/xmpp4r/muc/iq/mucadmin.rb lib/xmpp4r/muc/helper/mucbrowser.rb lib/xmpp4r/muc/x/mucuseritem.rb lib/xmpp4r/muc/x/mucuserinvite.rb lib/xmpp4r/muc/iq/mucowner.rb lib/xmpp4r/muc/helper/mucclient.rb MUC lib/xmpp4r/pubsub/children/item.rb lib/xmpp4r/pubsub/children/configuration.rb lib/xmpp4r/pubsub/children/subscription.rb lib/xmpp4r/pubsub/helper/servicehelper.rb lib/xmpp4r/pubsub/children/unsubscribe.rb lib/xmpp4r/pubsub/children/publish.rb lib/xmpp4r/pubsub/helper/oauth_service_helper.rb lib/xmpp4r/pubsub/children/event.rb lib/xmpp4r/pubsub/iq/pubsub.rb lib/xmpp4r/pubsub/children/retract.rb lib/xmpp4r/pubsub/helper/nodebrowser.rb lib/xmpp4r/pubsub/helper/nodehelper.rb lib/xmpp4r/pubsub/children/items.rb lib/xmpp4r/pubsub/children/subscription_config.rb lib/xmpp4r/pubsub/children/node_config.rb OAuthPubSubStreamHelper PubSub lib/xmpp4r/httpbinding/client.rb HTTPBinding lib/xmpp4r/tune/helper/helper.rb lib/xmpp4r/tune/tune.rb UserTune lib/xmpp4r/sasl.rb SASL lib/xmpp4r/test/listener_mocker.rb Test lib/xmpp4r/dataforms/x/data.rb Dataforms lib/xmpp4r/discovery/helper/helper.rb lib/xmpp4r/discovery/iq/discoinfo.rb lib/xmpp4r/discovery/helper/responder.rb lib/xmpp4r/discovery/iq/discoitems.rb Discovery lib/xmpp4r/bytestreams/helper/filetransfer.rb TransferSource FileTransfer lib/xmpp4r/last/helper/helper.rb lib/xmpp4r/last/iq/last.rb LastActivity lib/xmpp4r/framework/base.rb lib/xmpp4r/framework/bot.rb Framework lib/xmpp4r/vcard/helper/vcard.rb lib/xmpp4r/vcard/iq/vcard.rb Vcard Jabber dot/m_110_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 40
40:       def initialize(stream)
41:         super
42: 
43:         @room_message_block = nil
44:         @message_block = nil
45:         @private_message_block = nil
46:         @subject_block = nil
47: 
48:         @subject = nil
49: 
50:         @join_block = nil
51:         add_join_callback(999) { |pres|
52:           # Presence time
53:           time = nil
54:           pres.each_element('x') { |x|
55:             if x.kind_of?(Delay::XDelay)
56:               time = x.stamp
57:             end
58:           }
59: 
60:           # Invoke...
61:           @join_block.call(time, pres.from.resource) if @join_block
62:           false
63:         }
64: 
65:         @leave_block = nil
66:         @self_leave_block = nil
67:         add_leave_callback(999) { |pres|
68:           # Presence time
69:           time = nil
70:           pres.each_element('x') { |x|
71:             if x.kind_of?(Delay::XDelay)
72:               time = x.stamp
73:             end
74:           }
75: 
76:           # Invoke...
77:           if pres.from == jid
78:             @self_leave_block.call(time) if @self_leave_block
79:           else
80:             @leave_block.call(time, pres.from.resource) if @leave_block
81:           end
82:           false
83:         }
84:       end

Public Instance methods

Administratively ban one or more user jids from the room.

Will wait for response, possibly raising ServerError

Sample usage:

  my_muc.ban 'pistol@foobar.com', 'Avaunt, you cullion!'
recipients:[Array] of, or single [String]: JIDs
reason:[String] Ban reason

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 199
199:       def ban(recipients, reason)
200:         recipients = [recipients] unless recipients.kind_of? Array
201:         items = recipients.collect { |recipient|
202:           item = IqQueryMUCAdminItem.new
203:           item.jid = recipient
204:           item.affiliation = :outcast
205:           item.reason = reason
206:           item
207:         }
208:         send_affiliations(items)
209:       end

Demote one or more users in the room to participant.

Will wait for response, possibly raising ServerError

Sample usage:

  my_muc.demote 'pistol'
recipients:[Array] of, or single [String]: Nicks

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 260
260:       def demote(recipients)
261:         recipients = [recipients] unless recipients.kind_of? Array
262:         items = recipients.collect { |recipient|
263:           item = IqQueryMUCAdminItem.new
264:           item.nick = recipient
265:           item.role = :participant
266:           item
267:         }
268:         send_affiliations(items)
269:       end

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 157
157:       def invite(recipients)
158:         msg = Message.new
159:         x = msg.add(XMUCUser.new)
160:         recipients.each { |jid,reason|
161:           x.add(XMUCUserInvite.new(jid, reason))
162:         }
163:         send(msg)
164:       end

Administratively remove one or more users from the room.

Will wait for response, possibly raising ServerError

Sample usage:

  my_muc.kick 'pistol', 'Avaunt, you cullion!'
  my_muc.kick(['Bill', 'Linus'], 'Stop flaming')
recipients:[Array] of, or single [String]: Nicks
reason:[String] Kick reason

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 177
177:       def kick(recipients, reason)
178:         recipients = [recipients] unless recipients.kind_of? Array
179:         items = recipients.collect { |recipient|
180:           item = IqQueryMUCAdminItem.new
181:           item.nick = recipient
182:           item.role = :none
183:           item.reason = reason
184:           item
185:         }
186:         send_affiliations(items)
187:       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 311
311:       def on_join(&block)
312:         @join_block = block
313:       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 318
318:       def on_leave(&block)
319:         @leave_block = block
320:       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 285
285:       def on_message(&block)
286:         @message_block = block
287:       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 293
293:       def on_private_message(&block)
294:         @private_message_block = block
295:       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 277
277:       def on_room_message(&block)
278:         @room_message_block = block
279:       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 327
327:       def on_self_leave(&block)
328:         @self_leave_block = block
329:       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 300
300:       def on_subject(&block)
301:         @subject_block = block
302:       end

Promote one or more users in the room to moderator.

Will wait for response, possibly raising ServerError

Sample usage:

  my_muc.promote 'pistol'
recipients:[Array] of, or single [String]: Nicks

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 240
240:       def promote(recipients)
241:         recipients = [recipients] unless recipients.kind_of? Array
242:         items = recipients.collect { |recipient|
243:           item = IqQueryMUCAdminItem.new
244:           item.nick = recipient
245:           item.role = :moderator
246:           item
247:         }
248:         send_affiliations(items)
249:       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 146
146:       def say(text, to=nil)
147:         send(Message.new(nil, text), to)
148:       end

Room subject/topic

result:[String] The subject

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 126
126:       def subject
127:         @subject
128:       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 136
136:       def subject=(s)
137:         msg = Message.new
138:         msg.subject = s
139:         send(msg)
140:       end

Unban one or more user jids for the room.

Will wait for response, possibly raising ServerError

Sample usage:

  my_muc.unban 'pistol@foobar.com'
recipients:[Array] of, or single [String]: JIDs

[Source]

     # File lib/xmpp4r/muc/helper/simplemucclient.rb, line 220
220:       def unban(recipients)
221:         recipients = [recipients] unless recipients.kind_of? Array
222:         items = recipients.collect { |recipient|
223:           item = IqQueryMUCAdminItem.new
224:           item.jid = recipient
225:           item.affiliation = :none
226:           item
227:         }
228:         send_affiliations(items)
229:       end

Private Instance methods

[Source]

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

[Validate]