skyfallsin-ruby_bosh 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/ruby_bosh.rb +18 -27
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/ruby_bosh.rb
CHANGED
@@ -5,9 +5,7 @@ require 'base64'
|
|
5
5
|
require 'hpricot'
|
6
6
|
require 'system_timer'
|
7
7
|
|
8
|
-
|
9
|
-
# http://code.stanziq.com/svn/strophe/trunk/strophejs/examples/attach/boshclient.py
|
10
|
-
class RubyBOSHClient
|
8
|
+
class RubyBOSH
|
11
9
|
BOSH_XMLNS = 'http://jabber.org/protocol/httpbind'
|
12
10
|
TLS_XMLNS = 'urn:ietf:params:xml:ns:xmpp-tls'
|
13
11
|
SASL_XMLNS = 'urn:ietf:params:xml:ns:xmpp-sasl'
|
@@ -15,6 +13,7 @@ class RubyBOSHClient
|
|
15
13
|
SESSION_XMLNS = 'urn:ietf:params:xml:ns:xmpp-session'
|
16
14
|
|
17
15
|
class Timeout < StandardError; end
|
16
|
+
class AuthFailed < StandardError; end
|
18
17
|
|
19
18
|
attr_accessor :jid, :rid, :sid, :success
|
20
19
|
def initialize(jid, pw, service_url, opts={})
|
@@ -25,21 +24,15 @@ class RubyBOSHClient
|
|
25
24
|
@timeout = opts[:timeout] || 3 #seconds
|
26
25
|
@headers = {"Content-Type" => "text/xml; charset=utf-8",
|
27
26
|
"Accept" => "text/xml"}
|
28
|
-
connect
|
29
|
-
end
|
30
|
-
|
31
|
-
def initialize_bosh_session
|
32
|
-
response = deliver(construct_body(:wait => 5, :to => @host,
|
33
|
-
:hold => 3, :window => 5,
|
34
|
-
"xmpp:version" => '1.0'))
|
35
|
-
parse(response)
|
36
27
|
end
|
37
28
|
|
38
29
|
def success?
|
39
|
-
success == true
|
30
|
+
@success == true
|
40
31
|
end
|
41
32
|
|
42
|
-
|
33
|
+
def self.initialize_session(*args)
|
34
|
+
new(*args).connect
|
35
|
+
end
|
43
36
|
|
44
37
|
def connect
|
45
38
|
initialize_bosh_session
|
@@ -49,9 +42,18 @@ class RubyBOSHClient
|
|
49
42
|
@success = send_session_request
|
50
43
|
end
|
51
44
|
|
52
|
-
|
53
|
-
|
54
|
-
|
45
|
+
raise RubyBOSH::AuthFailed, "could not authenticate #{@jid}" unless success?
|
46
|
+
@rid += 1 #updates the rid for the next call from the browser
|
47
|
+
|
48
|
+
[@jid, @sid, @rid]
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def initialize_bosh_session
|
53
|
+
response = deliver(construct_body(:wait => 5, :to => @host,
|
54
|
+
:hold => 3, :window => 5,
|
55
|
+
"xmpp:version" => '1.0'))
|
56
|
+
parse(response)
|
55
57
|
end
|
56
58
|
|
57
59
|
def construct_body(params={}, &block)
|
@@ -136,17 +138,6 @@ class RubyBOSHClient
|
|
136
138
|
end
|
137
139
|
|
138
140
|
|
139
|
-
class RubyBOSH
|
140
|
-
def self.initialize_session(jid, pw, service_url, opts={})
|
141
|
-
conn = RubyBOSHClient.new(jid, pw, service_url, opts)
|
142
|
-
if conn.success?
|
143
|
-
[conn.jid, conn.sid, conn.rid]
|
144
|
-
else
|
145
|
-
[nil, nil, nil]
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
141
|
if __FILE__ == $0
|
151
142
|
p RubyBOSH.initialize_session(ARGV[0], ARGV[1],
|
152
143
|
"http://localhost:5280/http-bind")
|