adhearsion-xmpp 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,5 @@
1
+ # v1.0.1
2
+ * Bugfix: Get everything working in standalone connection mode (not sharing with Punchblock)
3
+
1
4
  # v1.0.0
2
5
  * First release
data/README.md CHANGED
@@ -27,7 +27,7 @@ In your Adhearsion app configuration file, add the following values:
27
27
  Adhearsion.config do |config|
28
28
  config.xmpp.jid = "valid-jid"
29
29
  config.xmpp.password = "valid-password"
30
- config.xmpp.host = "valid-host"
30
+ config.xmpp.server = "valid-server"
31
31
  config.xmpp.port = "valid-port"
32
32
  end
33
33
  ```
@@ -1,63 +1,33 @@
1
- require 'blather/client'
1
+ require 'blather/client/client'
2
+ require 'blather/client/dsl'
2
3
 
3
4
  module Adhearsion
4
5
  class XMPP
5
- module Connection
6
+ class Connection
6
7
 
7
- class << self
8
+ include Blather::DSL
8
9
 
9
- attr_accessor :client
10
-
11
- ##
12
- # Open the XMPP connection
13
- #
14
- # @param [String] jid the client/component JID to connect to
15
- # @param [String] password
16
- # @param [String] server
17
- # @param [Integer] port
18
- def start(jid, password, server, port)
19
- Blather.logger = logger
20
- setup_client_object jid, password, server, port
21
- register_event_namespaces
22
- register_default_client_handlers
23
- Adhearsion::Events.register_callback(:after_initialized) do
24
- connect
25
- end
26
- end
27
-
28
- # Close the XMPP connection
29
- def stop
30
- shutdown
31
- end
32
-
33
- private
34
-
35
- def setup_client_object(jid, password, server, port)
36
- self.client = Blather::Client.setup(jid, password, server, port)
37
- end
10
+ def initialize
11
+ Blather.logger = logger
12
+ Blather.default_log_level = :trace if Blather.respond_to? :default_log_level
13
+ register_default_client_handlers
14
+ Adhearsion::Events.after_initialized { connect }
15
+ Adhearsion::Events.shutdown { shutdown }
16
+ end
38
17
 
39
- def connect
40
- EventMachine.run {client.connect}
41
- end
18
+ private
42
19
 
43
- def register_event_namespaces
44
- Adhearsion::Events.register_namespace_name "/xmpp"
20
+ def connect
21
+ logger.info "Connecting to XMPP"
22
+ Adhearsion::Process.important_threads << Thread.new do
23
+ EventMachine.run { client.connect }
45
24
  end
25
+ end
46
26
 
47
- def register_default_client_handlers
48
- client.register_handler(:ready) do
49
- logger.info "Connected to XMPP server! Send messages to #{client.jid.stripped}."
50
- end
51
-
52
- client.register_handler(:disconnected) do
53
- if Adhearsion.status == :running
54
- logger.warn "XMPP Disconnected. Reconnecting."
55
- connect
56
- end
57
- # TODO: fix this to reconnect XMPP cleanly
58
- end
27
+ def register_default_client_handlers
28
+ client.register_handler(:ready) do
29
+ logger.info "Connected to XMPP server! Send messages to #{client.jid.stripped}."
59
30
  end
60
-
61
31
  end
62
32
 
63
33
  end
@@ -4,11 +4,11 @@ module Adhearsion
4
4
 
5
5
  # Default configuration for XMPP connection.
6
6
  config :xmpp do
7
- use_punchblock true , :desc => "Re-use Punchblock's XMPP connection. Boolean."
8
- jid nil , :desc => "Client/component JID to connect to. String."
9
- password nil , :desc => "Password identifier. String."
10
- server nil , :desc => "XMPP server hostname. May be omitted if server can be determined from JID. String."
11
- port nil , :desc => "XMPP server port. May be omitted if server can be determined from JID. Integer."
7
+ use_punchblock true, :desc => "Re-use Punchblock's XMPP connection. Boolean."
8
+ jid nil, :desc => "Client/component JID to connect to. String."
9
+ password nil, :desc => "Password identifier. String."
10
+ server nil, :desc => "XMPP server hostname. May be omitted if server can be determined from JID. String."
11
+ port nil, :desc => "XMPP server port. May be omitted if server can be determined from JID. Integer."
12
12
  end
13
13
 
14
14
  # Include the XMPP service in plugins initialization process
@@ -19,50 +19,26 @@ module Adhearsion
19
19
  end unless Adhearsion::XMPP.handlers.nil?
20
20
  end
21
21
 
22
- run :xmpp do
23
- Adhearsion::XMPP.plugin.run_plugin
24
- end
22
+ delegate :config, :to => self
23
+ delegate :use_punchblock, :to => :config
25
24
 
26
25
  def initialize
27
- @config ||= Adhearsion.config[:xmpp]
28
- init_blather unless @config.use_punchblock
29
- end
30
-
31
- def run_plugin
32
- run_blather unless @config.use_punchblock
26
+ init_blather config.jid, config.password, config.server, config.port unless use_punchblock
33
27
  end
34
28
 
35
- def start_punchblock
36
- # Nothing needed here; everything is delegated
37
- nil
38
- end
39
-
40
- def init_blather
41
- raise "Must supply a jid argument to the XMPP configuration" if (@config.jid.nil? || @config.jid.empty?)
42
- raise "Must supply a password argument to the XMPP configuration" if (@config.password.nil? || @config.password.empty?)
29
+ def init_blather(jid, password, server, port)
30
+ raise "Must supply a jid to the XMPP configuration" unless jid.present?
31
+ raise "Must supply a password to the XMPP configuration" unless password.present?
43
32
 
44
- Connection.extend Blather::DSL
45
- Connection.start @config.jid, @config.password, @config.server, @config.port
46
- end
47
-
48
- ##
49
- # Stop the XMPP connection
50
- def stop
51
- stop_blather unless @config.use_punchblock
52
- end
53
-
54
- def stop_blather
55
- Connection.stop
33
+ connection.setup jid, password, server, port
56
34
  end
57
35
 
58
36
  def connection
59
- @config.use_punchblock ?
60
- PunchblockPlugin.connection :
61
- Connection
62
- end
63
-
64
- def client
65
- @config.use_punchblock ? PunchblockPlugin.client : Connection.client
37
+ if use_punchblock
38
+ PunchblockPlugin.connection
39
+ else
40
+ @connection ||= Connection.new
41
+ end
66
42
  end
67
43
  end
68
44
  end
@@ -1,5 +1,5 @@
1
1
  module Adhearsion
2
2
  class XMPP
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adhearsion-xmpp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-04-11 00:00:00.000000000 Z
15
+ date: 2012-10-11 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: adhearsion
@@ -152,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  segments:
154
154
  - 0
155
- hash: 2528149548247411603
155
+ hash: 844702008144568214
156
156
  required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  none: false
158
158
  requirements:
@@ -161,10 +161,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  version: '0'
162
162
  segments:
163
163
  - 0
164
- hash: 2528149548247411603
164
+ hash: 844702008144568214
165
165
  requirements: []
166
166
  rubyforge_project: adhearsion-xmpp
167
- rubygems_version: 1.8.21
167
+ rubygems_version: 1.8.23
168
168
  signing_key:
169
169
  specification_version: 3
170
170
  summary: Send and receive XMPP messages in your Adhearsion application