Class: Xrc::Client
- Inherits:
-
Object
- Object
- Xrc::Client
- Defined in:
- lib/xrc/client.rb
Constant Summary collapse
- DEFAULT_PORT =
5222
- PING_INTERVAL =
30
Instance Attribute Summary collapse
-
#users ⇒ Xrc::Roster
readonly
Users information existing in the server.
Instance Method Summary collapse
-
#connect ⇒ nil
Connects to the JID’s server and waits for message.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #join(jids) ⇒ Object
-
#mention_name ⇒ String
Mention name of this account.
-
#on_connection_established { ... } ⇒ Proc
Registers a callback called when a client connected to server.
-
#on_event {|element| ... } ⇒ Proc
Registers a callback called when client received a new XML element from server.
-
#on_invite(&block) ⇒ Proc
Registers a callback for invitation message.
-
#on_private_message {|element| ... } ⇒ Proc
Registers a callback called when client received a new private message (a.k.a. 1vs1 message).
-
#on_room_message {|element| ... } ⇒ Proc
Registers a callback called when client received a new room message.
-
#on_subject {|element| ... } ⇒ Proc
Registers a callback called when client received a new message with subject.
-
#reply(options) ⇒ REXML::Element
Replies to given message.
-
#say(options) ⇒ REXML::Element
Send a message.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
17 18 19 |
# File 'lib/xrc/client.rb', line 17 def initialize( = {}) @options = end |
Instance Attribute Details
#users ⇒ Xrc::Roster (readonly)
Returns Users information existing in the server.
8 9 10 |
# File 'lib/xrc/client.rb', line 8 def users @users end |
Instance Method Details
#connect ⇒ nil
Connects to the JID’s server and waits for message
23 24 25 26 |
# File 'lib/xrc/client.rb', line 23 def connect connection.connect nil end |
#join(jids) ⇒ Object
137 138 139 140 141 |
# File 'lib/xrc/client.rb', line 137 def join(jids) Array(jids).each do |room_jid| post(Elements::Join.new(from: jid.strip, to: "#{room_jid}/#{nickname}")) end end |
#mention_name ⇒ String
Returns Mention name of this account.
133 134 135 |
# File 'lib/xrc/client.rb', line 133 def mention_name users[jid].try(:mention_name) end |
#on_connection_established { ... } ⇒ Proc
Registers a callback called when a client connected to server
36 37 38 |
# File 'lib/xrc/client.rb', line 36 def on_connection_established(&block) @on_connection_established_block = block end |
#on_event {|element| ... } ⇒ Proc
Registers a callback called when client received a new XML element from server
88 89 90 |
# File 'lib/xrc/client.rb', line 88 def on_event(&block) @on_event_block = block end |
#on_invite(&block) ⇒ Proc
Registers a callback for invitation message
94 95 96 |
# File 'lib/xrc/client.rb', line 94 def on_invite(&block) @on_invite_block = block end |
#on_private_message {|element| ... } ⇒ Proc
Registers a callback called when client received a new private message (a.k.a. 1vs1 message)
49 50 51 |
# File 'lib/xrc/client.rb', line 49 def (&block) @on_private_message_block = block end |
#on_room_message {|element| ... } ⇒ Proc
Registers a callback called when client received a new room message
62 63 64 |
# File 'lib/xrc/client.rb', line 62 def (&block) @on_room_message_block = block end |
#on_subject {|element| ... } ⇒ Proc
Registers a callback called when client received a new message with subject
75 76 77 |
# File 'lib/xrc/client.rb', line 75 def on_subject(&block) @on_subject_block = block end |
#reply(options) ⇒ REXML::Element
Replies to given message
104 105 106 107 108 109 110 111 |
# File 'lib/xrc/client.rb', line 104 def reply() say( body: [:body], from: [:to].to, to: [:to].from, type: [:to].type, ) end |