Class: Adhearsion::Rayo::Connection::XMPP
- Inherits:
-
GenericConnection
- Object
- GenericConnection
- Adhearsion::Rayo::Connection::XMPP
- Includes:
- Blather::DSL
- Defined in:
- lib/adhearsion/rayo/connection/xmpp.rb
Instance Attribute Summary collapse
-
#event_handler ⇒ Object
Returns the value of attribute event_handler.
-
#root_domain ⇒ Object
Returns the value of attribute root_domain.
Instance Method Summary collapse
- #connect ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(options = {}) ⇒ XMPP
constructor
Initialize the required connection attributes.
- #new_call_uri ⇒ Object
- #not_ready! ⇒ Object
- #prep_command_for_execution(command, options = {}) ⇒ Object
- #ready! ⇒ Object
-
#run ⇒ Object
Fire up the connection.
- #send_message(call_id, domain, body, options = {}) ⇒ Object
- #stop ⇒ Object
- #write(command, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ XMPP
Initialize the required connection attributes
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 29 def initialize( = {}) raise ArgumentError unless (@username = [:username]) && [:password] setup(*[:username, :password, :host, :port, :certs, :connection_timeout].map { |key| .delete key }) @root_domain = Blather::JID.new([:root_domain] || [:rayo_domain] || @username).domain @joined_mixers = [] @ping_period = .has_key?(:ping_period) ? [:ping_period] : 60 Blather.logger = logger Blather.default_log_level = :trace if Blather.respond_to? :default_log_level register_handlers super() end |
Instance Attribute Details
#event_handler ⇒ Object
Returns the value of attribute event_handler.
16 17 18 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 16 def event_handler @event_handler end |
#root_domain ⇒ Object
Returns the value of attribute root_domain.
16 17 18 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 16 def root_domain @root_domain end |
Instance Method Details
#connect ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 88 def connect begin EM.run { client.run } rescue Blather::Stream::ConnectionFailed, Blather::Stream::ConnectionTimeout, Blather::StreamError => e raise DisconnectedError.new(e.class.to_s, e.) end end |
#connected? ⇒ Boolean
100 101 102 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 100 def connected? client.connected? end |
#new_call_uri ⇒ Object
114 115 116 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 114 def new_call_uri "xmpp:#{Adhearsion.new_uuid}@#{root_domain}" end |
#not_ready! ⇒ Object
109 110 111 112 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 109 def not_ready! send_presence :dnd super end |
#prep_command_for_execution(command, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 60 def prep_command_for_execution(command, = {}) command.connection = self command.target_call_id ||= [:call_id] command.target_mixer_name ||= [:mixer_name] command.domain ||= [:domain] command.component_id ||= [:component_id] if command.is_a?(Command::Join) && command.mixer_name @joined_mixers << command.mixer_name end create_iq(jid_for_command(command), command.request_id).tap do |iq| command.to_rayo(iq) end end |
#ready! ⇒ Object
104 105 106 107 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 104 def ready! send_presence :chat super end |
#run ⇒ Object
Fire up the connection
84 85 86 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 84 def run connect end |
#send_message(call_id, domain, body, options = {}) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 74 def (call_id, domain, body, = {}) jid = Blather::JID.new(call_id, domain || root_domain).to_s = Blather::Stanza::Message.new(jid, body, :normal) .subject = [:subject] client.write end |
#stop ⇒ Object
96 97 98 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 96 def stop client.close if client.connected? end |
#write(command, options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/adhearsion/rayo/connection/xmpp.rb', line 48 def write(command, = {}) iq = prep_command_for_execution command, command.request! client.write_with_handler iq do |response| if response.result? handle_iq_result response, command elsif response.error? handle_error response, command end end end |