pubnub 3.7.0 → 3.7.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pubnub might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +7 -3
- data/README.md +3 -3
- data/lib/pubnub.rb +2 -0
- data/lib/pubnub/client.rb +32 -32
- data/lib/pubnub/crypto.rb +5 -5
- data/lib/pubnub/event.rb +70 -60
- data/lib/pubnub/events/here_now.rb +1 -1
- data/lib/pubnub/events/leave.rb +4 -4
- data/lib/pubnub/events/publish.rb +2 -2
- data/lib/pubnub/exceptions.rb +2 -2
- data/lib/pubnub/version.rb +1 -1
- data/spec/lib/channel_presence_concat_pam_spec.rb +2 -2
- data/spec/lib/eof_error_spec.rb +2 -2
- data/spec/lib/integration/audit_dpc_spec.rb +2 -2
- data/spec/lib/integration/audit_spec.rb +2 -2
- data/spec/lib/integration/global_here_now_dpc_spec.rb +2 -2
- data/spec/lib/integration/global_here_now_spec.rb +2 -2
- data/spec/lib/integration/grant_dpc_spec.rb +2 -2
- data/spec/lib/integration/grant_spec.rb +2 -2
- data/spec/lib/integration/here_now_dpc_spec.rb +2 -2
- data/spec/lib/integration/here_now_spec.rb +2 -2
- data/spec/lib/integration/history_dpc_spec.rb +2 -2
- data/spec/lib/integration/history_spec.rb +2 -2
- data/spec/lib/integration/leave_dpc_spec.rb +2 -2
- data/spec/lib/integration/leave_spec.rb +2 -2
- data/spec/lib/integration/presence_dpc_spec.rb +2 -2
- data/spec/lib/integration/presence_spec.rb +2 -2
- data/spec/lib/integration/publish_spec_old.rb +2 -2
- data/spec/lib/integration/revoke_dpc_spec.rb +2 -2
- data/spec/lib/integration/revoke_spec.rb +2 -2
- data/spec/lib/integration/state_spec.rb +2 -2
- data/spec/lib/integration/subscribe_dpc_spec.rb +2 -2
- data/spec/lib/integration/subscribe_spec.rb +2 -2
- data/spec/lib/integration/time_dpc_spec.rb +2 -2
- data/spec/lib/integration/time_spec.rb +2 -2
- data/spec/lib/integration/v3_presence_dpc_spec.rb +2 -2
- data/spec/lib/integration/v3_presence_spec.rb +2 -2
- data/spec/lib/integration/where_now_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4b1a3482014d1b1506b37bc8740aca689461aa4
|
4
|
+
data.tar.gz: c8b546230f0cb24477739c34b9e9cdd168ceff1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c6dd571ce7820226c2888749c699f40ad0c5370668f8a1486e0b53ea9d7dd46c2260f927e81e694ec51c8b075b565d6c5dc97aee29bf5482922b029429c52bb
|
7
|
+
data.tar.gz: 6ae74d44a8a982668c73c4193875f95b6c504dd9acd77067c24b1627b6a43e857c550f8369dde6a45e7c3525959353c25e4d76be444226478f3f1abd1f61f81f
|
data/CHANGELOG.txt
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pubnub (3.7.
|
4
|
+
pubnub (3.7.0)
|
5
5
|
eventmachine (~> 1.0)
|
6
6
|
json (~> 1.8)
|
7
7
|
net-http-persistent (~> 2.9)
|
@@ -15,8 +15,9 @@ GEM
|
|
15
15
|
crack (0.4.2)
|
16
16
|
safe_yaml (~> 1.0.0)
|
17
17
|
diff-lcs (1.2.5)
|
18
|
-
eventmachine (1.0.
|
19
|
-
json (1.8.
|
18
|
+
eventmachine (1.0.7)
|
19
|
+
json (1.8.2)
|
20
|
+
memory_profiler (0.0.4)
|
20
21
|
method_source (0.8.2)
|
21
22
|
net-http-persistent (2.9.4)
|
22
23
|
pry (0.10.0)
|
@@ -32,6 +33,7 @@ GEM
|
|
32
33
|
rspec-expectations (2.14.5)
|
33
34
|
diff-lcs (>= 1.1.3, < 2.0)
|
34
35
|
rspec-mocks (2.14.6)
|
36
|
+
ruby-prof (0.15.3)
|
35
37
|
safe_yaml (1.0.3)
|
36
38
|
slop (3.5.0)
|
37
39
|
vcr (2.9.2)
|
@@ -45,9 +47,11 @@ PLATFORMS
|
|
45
47
|
DEPENDENCIES
|
46
48
|
awesome_print
|
47
49
|
bundler (~> 1.6)
|
50
|
+
memory_profiler
|
48
51
|
pry
|
49
52
|
pubnub!
|
50
53
|
rr
|
51
54
|
rspec (= 2.14)
|
55
|
+
ruby-prof
|
52
56
|
vcr
|
53
57
|
webmock
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Please direct all Support Questions and Concerns to Support@PubNub.com
|
2
2
|
|
3
|
-
## PubNub Gem version 3.7.
|
3
|
+
## PubNub Gem version 3.7.1
|
4
4
|
|
5
5
|
##### YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
|
6
6
|
##### http://www.pubnub.com/account
|
@@ -17,10 +17,10 @@ We've made the response format compatible across all operations. This may break
|
|
17
17
|
Examples of affected operations can be found [here](3.5_to_3.6_upgrade_notes.md).
|
18
18
|
|
19
19
|
### Upgrading from PubNub 3.3.x and Earlier
|
20
|
-
PubNub 3.7.
|
20
|
+
PubNub 3.7.1 is NOT compatible with earlier than 3.4 versions of Pubnub Ruby Client.
|
21
21
|
|
22
22
|
### Upgrading from PubNub 3.4 and higher versions
|
23
|
-
PubNub 3.7.
|
23
|
+
PubNub 3.7.1 is compatible with 3.4 version.
|
24
24
|
|
25
25
|
## Important Notice about Blocking vs Non-Blocking Calls
|
26
26
|
|
data/lib/pubnub.rb
CHANGED
data/lib/pubnub/client.rb
CHANGED
@@ -27,7 +27,7 @@ module Pubnub
|
|
27
27
|
define_method event_name do |params = {}, &block|
|
28
28
|
params[:callback] = block if params[:callback].nil?
|
29
29
|
event = Pubnub.const_get(classify_method(event_name)).new(params, self)
|
30
|
-
|
30
|
+
Pubnub.logger.debug(:pubnub){'Created event ' + event.class.to_s}
|
31
31
|
event.fire(self)
|
32
32
|
end
|
33
33
|
end
|
@@ -105,11 +105,11 @@ module Pubnub
|
|
105
105
|
|
106
106
|
EM.stop if stop_em
|
107
107
|
|
108
|
-
|
108
|
+
Pubnub.logger.info(:pubnub){'Bye!'}
|
109
109
|
end
|
110
110
|
|
111
111
|
def stop_async
|
112
|
-
|
112
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#stop_async | fired'}
|
113
113
|
@env[:subscribe_railgun].cancel unless @env[:subscribe_railgun].blank?
|
114
114
|
@env[:respirator].cancel unless @env[:respirator].blank?
|
115
115
|
@env[:subscribe_railgun].cancel unless @env[:subscribe_railgun].blank?
|
@@ -120,7 +120,7 @@ module Pubnub
|
|
120
120
|
|
121
121
|
EM.stop
|
122
122
|
|
123
|
-
|
123
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#stop_async | timers killed'}
|
124
124
|
end
|
125
125
|
|
126
126
|
def restore_async
|
@@ -130,24 +130,24 @@ module Pubnub
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def start_respirator
|
133
|
-
|
133
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_respirator | fired'}
|
134
134
|
if @env[:heartbeat]
|
135
|
-
|
135
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_respirator | starting'}
|
136
136
|
|
137
137
|
if @env[:heartbeat] != @env[:respirator].interval
|
138
|
-
|
138
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_respirator | destroy old respirator'}
|
139
139
|
@env[:respirator].cancel
|
140
140
|
@env[:respirator] = nil
|
141
141
|
end if @env[:respirator]
|
142
142
|
|
143
143
|
@env[:respirator] = EM.add_periodic_timer((@env[:heartbeat].to_i/2) - 1) do
|
144
144
|
@env[:subscriptions].each do |origin, subscribe|
|
145
|
-
|
146
|
-
EM.defer { heartbeat(:channel => subscribe.get_channels, :group => subscribe.get_channel_groups ){ |e|
|
145
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_respirator | BUM'}
|
146
|
+
EM.defer { heartbeat(:channel => subscribe.get_channels, :group => subscribe.get_channel_groups ){ |e| Pubnub.logger.debug('Pubnub::Client#start_respirator | bum') } }
|
147
147
|
end
|
148
148
|
end unless @env[:respirator]
|
149
149
|
|
150
|
-
|
150
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_respirator | started'}
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
@@ -157,7 +157,7 @@ module Pubnub
|
|
157
157
|
start_respirator if @env[:heartbeat]
|
158
158
|
|
159
159
|
if override
|
160
|
-
|
160
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_subscribe | Override'}
|
161
161
|
@env[:subscribe_railgun].cancel
|
162
162
|
@env[:subscribe_railgun] = nil
|
163
163
|
@env[:wait_for_response].each do |k,v|
|
@@ -166,7 +166,7 @@ module Pubnub
|
|
166
166
|
end
|
167
167
|
|
168
168
|
if @env[:subscribe_railgun] && @subscribe_deffered_thread
|
169
|
-
|
169
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_subscribe | Aborting previous request'}
|
170
170
|
@subscribe_deffered_thread.kill
|
171
171
|
Thread.pass until @subscribe_deffered_thread.status == false
|
172
172
|
end
|
@@ -179,9 +179,9 @@ module Pubnub
|
|
179
179
|
unless @env[:wait_for_response][origin]
|
180
180
|
@env[:wait_for_response][origin] = true
|
181
181
|
|
182
|
-
|
183
|
-
|
184
|
-
|
182
|
+
Pubnub.logger.debug(:pubnub){'Async subscription running'}
|
183
|
+
Pubnub.logger.debug(:pubnub){"origin: #{origin}"}
|
184
|
+
Pubnub.logger.debug(:pubnub){"timetoken: #{@env[:timetoken]}"}
|
185
185
|
|
186
186
|
EM.defer do
|
187
187
|
@subscribe_deffered_thread = Thread.current
|
@@ -192,8 +192,8 @@ module Pubnub
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
rescue => e
|
195
|
-
|
196
|
-
|
195
|
+
Pubnub.logger.error(:pubnub){e}
|
196
|
+
Pubnub.logger.error(:pubnub){e.backtrace}
|
197
197
|
end
|
198
198
|
end
|
199
199
|
end
|
@@ -211,7 +211,7 @@ module Pubnub
|
|
211
211
|
|
212
212
|
def update_timetoken(timetoken)
|
213
213
|
@env[:timetoken] = timetoken.to_i
|
214
|
-
|
214
|
+
Pubnub.logger.debug(:pubnub){"Pubnub::Client#update_timetoken | Current timetoken is eq #{@env[:timetoken]}"}
|
215
215
|
end
|
216
216
|
|
217
217
|
def set_uuid(uuid)
|
@@ -253,16 +253,16 @@ module Pubnub
|
|
253
253
|
def start_railgun
|
254
254
|
start_event_machine(@env)
|
255
255
|
if @env[:railgun]
|
256
|
-
|
256
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_railgun | Railgun already initialized'}
|
257
257
|
else
|
258
|
-
|
258
|
+
Pubnub.logger.debug('Pubnub'){'Pubnub::Client#start_railgun | Initializing railgun'}
|
259
259
|
@env[:railgun] = EM.add_periodic_timer(0.01) do
|
260
260
|
@async_events.each do |event|
|
261
261
|
EM.defer do
|
262
|
-
event.fire(self) unless event.fired
|
262
|
+
event.fire(self) unless event.fired?
|
263
263
|
end
|
264
264
|
end
|
265
|
-
@async_events.delete_if {|event| event.finished }
|
265
|
+
@async_events.delete_if {|event| event.finished? }
|
266
266
|
end
|
267
267
|
end
|
268
268
|
end
|
@@ -287,28 +287,28 @@ module Pubnub
|
|
287
287
|
end
|
288
288
|
|
289
289
|
def start_event_machine(options = nil)
|
290
|
-
|
290
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_event_machine | starting EM in new thread'}
|
291
291
|
if defined?(Thin)
|
292
|
-
|
292
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_event_machine | We\'re running on thin'}
|
293
293
|
else
|
294
|
-
|
294
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_event_machine | We aren\'t running on thin'}
|
295
295
|
end
|
296
296
|
if EM.reactor_running?
|
297
|
-
|
297
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_event_machine | EM already running'}
|
298
298
|
else
|
299
299
|
Thread.new { EM.run {} }
|
300
300
|
Thread.pass until EM.reactor_running?
|
301
|
-
|
301
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Client#start_event_machine | EM started in new thread'}
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
305
305
|
def setup_app(options)
|
306
|
-
|
306
|
+
Pubnub.logger = options[:logger] || Logger.new('pubnub.log')
|
307
307
|
@env = symbolize_options_keys(options)
|
308
308
|
@env = set_default_values(@env)
|
309
|
-
@env.delete_if { |
|
309
|
+
@env.delete_if { |_,v| v.blank? } # nillify if blank
|
310
310
|
@async_events = Array.new
|
311
|
-
|
311
|
+
Pubnub.logger.debug(:pubnub){"\n\nCreated new Pubnub::Client instance"}
|
312
312
|
end
|
313
313
|
|
314
314
|
def create_connections_pools(options)
|
@@ -337,7 +337,7 @@ module Pubnub
|
|
337
337
|
}
|
338
338
|
|
339
339
|
# Let's fill missing keys with default values
|
340
|
-
|
340
|
+
Pubnub.logger.debug(:pubnub){'Setting default values'}
|
341
341
|
defaults.each do |key,default_value|
|
342
342
|
env[key] = default_value if @env[key].nil?
|
343
343
|
end
|
@@ -346,7 +346,7 @@ module Pubnub
|
|
346
346
|
end
|
347
347
|
|
348
348
|
def symbolize_options_keys(options)
|
349
|
-
|
349
|
+
Pubnub.logger.debug(:pubnub){'Symbolizing options keys'}
|
350
350
|
symbolized_options = {}
|
351
351
|
options.each_key { |k| symbolized_options.merge!({ k.to_sym => options[k] }) }
|
352
352
|
symbolized_options
|
data/lib/pubnub/crypto.rb
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
module Pubnub
|
3
3
|
class Crypto
|
4
4
|
def initialize(cipher_key)
|
5
|
-
|
5
|
+
Pubnub.logger.debug(:pubnub){'Initializing Crypto'}
|
6
6
|
@alg = 'AES-256-CBC'
|
7
7
|
sha256_key = Digest::SHA256.hexdigest(cipher_key)
|
8
8
|
@key = sha256_key.slice(0,32)
|
9
9
|
|
10
10
|
@iv = '0123456789012345'
|
11
|
-
|
11
|
+
Pubnub.logger.debug(:pubnub){'Initialized Crypto'}
|
12
12
|
end
|
13
13
|
|
14
14
|
|
@@ -28,7 +28,7 @@ module Pubnub
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def decrypt(cipher_text)
|
31
|
-
|
31
|
+
Pubnub.logger.debug(:pubnub){"Decrypting: #{cipher_text}"}
|
32
32
|
decode_cipher = OpenSSL::Cipher::Cipher.new(@alg)
|
33
33
|
decode_cipher.decrypt
|
34
34
|
decode_cipher.key = @key
|
@@ -41,7 +41,7 @@ module Pubnub
|
|
41
41
|
plain_text = decode_cipher.update(undecoded_text)
|
42
42
|
plain_text << decode_cipher.final
|
43
43
|
rescue => e
|
44
|
-
|
44
|
+
Pubnub.logger.error(:pubnub){'DECRYPTION ERROR'}
|
45
45
|
plain_text = '"DECRYPTION ERROR"'
|
46
46
|
end
|
47
47
|
|
@@ -51,7 +51,7 @@ module Pubnub
|
|
51
51
|
JSON.load("[#{plain_text}]")[0] # srsly ruby? srsly?
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
Pubnub.logger.debug(:pubnub){'Finished decrypting'}
|
55
55
|
|
56
56
|
plain_text
|
57
57
|
|
data/lib/pubnub/event.rb
CHANGED
@@ -31,13 +31,13 @@ module Pubnub
|
|
31
31
|
@channel = format_channels(@channel)
|
32
32
|
@channel_group = format_channel_group(options[:group], false)
|
33
33
|
@original_channel = format_channels(@channel, false)
|
34
|
-
|
34
|
+
Pubnub.logger.debug(:pubnub){"Event#initialize | Initialized #{self.class.to_s}"}
|
35
35
|
end
|
36
36
|
|
37
37
|
def fire(app)
|
38
|
-
|
38
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::Event#fire'}
|
39
39
|
@fired = true
|
40
|
-
|
40
|
+
Pubnub.logger.debug(:pubnub){'Event#fire'}
|
41
41
|
setup_connection(app) unless connection_exist?(app)
|
42
42
|
envelopes = start_event(app)
|
43
43
|
end
|
@@ -53,8 +53,8 @@ module Pubnub
|
|
53
53
|
def start_event(app, count = 0)
|
54
54
|
begin
|
55
55
|
if count <= app.env[:max_retries]
|
56
|
-
|
57
|
-
|
56
|
+
Pubnub.logger.debug(:pubnub){'Event#start_event | sending request'}
|
57
|
+
Pubnub.logger.debug(:pubnub){"Event#start_event | tt: #{@timetoken}; ctt #{app.env[:timetoken]}"}
|
58
58
|
@response = send_request(app)
|
59
59
|
end
|
60
60
|
|
@@ -66,11 +66,11 @@ module Pubnub
|
|
66
66
|
start_event(app, count + 1)
|
67
67
|
end
|
68
68
|
rescue => e
|
69
|
-
|
69
|
+
Pubnub.logger.error(:pubnub){e.inspect}
|
70
70
|
if count <= app.env[:max_retries]
|
71
71
|
start_event(app, count + 1)
|
72
72
|
else
|
73
|
-
|
73
|
+
Pubnub.logger.error(:pubnub){"Aborting #{self.class} event due to network errors and reaching max retries"}
|
74
74
|
end
|
75
75
|
false
|
76
76
|
end
|
@@ -89,6 +89,14 @@ module Pubnub
|
|
89
89
|
|
90
90
|
end
|
91
91
|
|
92
|
+
def finished?
|
93
|
+
@finished ? true : false
|
94
|
+
end
|
95
|
+
|
96
|
+
def fired?
|
97
|
+
@fired ? true : false
|
98
|
+
end
|
99
|
+
|
92
100
|
private
|
93
101
|
|
94
102
|
def response_error(response, app)
|
@@ -107,12 +115,12 @@ module Pubnub
|
|
107
115
|
|
108
116
|
def handle_response(response, app, error)
|
109
117
|
|
110
|
-
|
118
|
+
Pubnub.logger.debug(:pubnub){'Event#handle_response'}
|
111
119
|
envelopes = format_envelopes(response, app, error)
|
112
|
-
|
120
|
+
Pubnub.logger.debug(:pubnub){"Response: #{response.body}"} if (response && response.body)
|
113
121
|
update_app_timetoken(envelopes, app)
|
114
|
-
fire_callbacks(envelopes,app)
|
115
122
|
@finished = true
|
123
|
+
fire_callbacks(envelopes,app)
|
116
124
|
envelopes
|
117
125
|
|
118
126
|
end
|
@@ -123,27 +131,29 @@ module Pubnub
|
|
123
131
|
|
124
132
|
def fire_callbacks(envelopes, app)
|
125
133
|
unless envelopes.blank?
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
+
Pubnub.logger.debug(:pubnub){'Firing callbacks'}
|
135
|
+
# EM.defer do
|
136
|
+
envelopes.each do |envelope|
|
137
|
+
@callback.call(envelope) if envelope && !envelope.error && @callback && !envelope.timetoken_update
|
138
|
+
#if envelope.timetoken_update || envelope.timetoken.to_i > app.env[:timetoken].to_i
|
139
|
+
# update_timetoken(app, envelope.timetoken)
|
140
|
+
#end
|
141
|
+
end
|
142
|
+
@error_callback.call(envelopes.first) if envelopes.first.error
|
143
|
+
# end
|
134
144
|
else
|
135
|
-
|
145
|
+
Pubnub.logger.debug(:pubnub){'No envelopes for callback'}
|
136
146
|
end
|
137
147
|
end
|
138
148
|
|
139
149
|
def update_timetoken(app, timetoken)
|
140
150
|
@timetoken = timetoken.to_i
|
141
151
|
app.update_timetoken(timetoken.to_i)
|
142
|
-
|
152
|
+
Pubnub.logger.debug(:pubnub){"Updated timetoken to #{timetoken}"}
|
143
153
|
end
|
144
154
|
|
145
155
|
def add_common_data_to_envelopes(envelopes, response, app, error)
|
146
|
-
|
156
|
+
Pubnub.logger.debug(:pubnub){'Event#add_common_data_to_envelopes'}
|
147
157
|
|
148
158
|
envelopes.each do |envelope|
|
149
159
|
envelope.response = response.body
|
@@ -207,7 +217,7 @@ module Pubnub
|
|
207
217
|
end
|
208
218
|
|
209
219
|
def uri(app)
|
210
|
-
|
220
|
+
Pubnub.logger.debug(:pubnub){"#{self.class}#uri #{[origin(app), path(app), '?', params_hash_to_url_params(parameters(app))].join}"}
|
211
221
|
URI [origin(app), path(app), '?', params_hash_to_url_params(parameters(app))].join
|
212
222
|
end
|
213
223
|
|
@@ -236,17 +246,17 @@ module Pubnub
|
|
236
246
|
module SingleEvent
|
237
247
|
|
238
248
|
def fire(app)
|
239
|
-
|
249
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::SingleEvent#fire'}
|
240
250
|
if @http_sync
|
241
|
-
|
251
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::SingleEvent#fire | Sync event!'}
|
242
252
|
super(app)
|
243
253
|
elsif app.async_events.include? self
|
244
|
-
|
254
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::SingleEvent#fire | Event already on list!'}
|
245
255
|
super(app)
|
246
256
|
else
|
247
|
-
|
257
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::SingleEvent#fire | Adding event to async_events'}
|
248
258
|
app.async_events << self
|
249
|
-
|
259
|
+
Pubnub.logger.debug(:pubnub){'Pubnub::SingleEvent#fire | Starting railgun'}
|
250
260
|
app.start_railgun
|
251
261
|
end
|
252
262
|
end
|
@@ -283,9 +293,9 @@ module Pubnub
|
|
283
293
|
|
284
294
|
def fire(app)
|
285
295
|
begin
|
286
|
-
|
296
|
+
Pubnub.logger.debug(:pubnub){'SubscribeEvent#fire'}
|
287
297
|
if @http_sync
|
288
|
-
|
298
|
+
Pubnub.logger.debug(:pubnub){'SubscribeEvent#fire sync'}
|
289
299
|
if self.class == Pubnub::Subscribe && app.env[:heartbeat]
|
290
300
|
app.heartbeat(:channel => @channel, :http_sync => true)
|
291
301
|
envelopes = super
|
@@ -297,26 +307,26 @@ module Pubnub
|
|
297
307
|
end
|
298
308
|
envelopes
|
299
309
|
else
|
300
|
-
|
301
|
-
|
310
|
+
Pubnub.logger.debug(:pubnub){'SubscribeEvent#fire async'}
|
311
|
+
Pubnub.logger.debug(:pubnub){"Channel: #{@channel}"}
|
302
312
|
setup_connection(app) unless connection_exist?(app)
|
303
313
|
unless app.env[:subscriptions][@origin].blank?
|
304
314
|
@channel.each do |channel|
|
305
315
|
if app.env[:subscriptions][@origin].get_channels.include?(channel)
|
306
316
|
@channel.delete(channel)
|
307
|
-
|
317
|
+
Pubnub.logger.error(:pubnub){"Already subscribed to channel #{channel}, you have to leave that channel first"}
|
308
318
|
end
|
309
319
|
end
|
310
320
|
|
311
321
|
@channel.each do |channel|
|
312
|
-
|
322
|
+
Pubnub.logger.debug(:pubnub){'SubscribeEvent#add_channel | Adding channel'}
|
313
323
|
app.env[:subscriptions][@origin].add_channel(channel, app)
|
314
324
|
end
|
315
325
|
|
316
326
|
@channel_group.each do |cg|
|
317
327
|
if app.env[:subscriptions][@origin].get_channel_groups.include?(cg)
|
318
328
|
@channel_group.delete(cg)
|
319
|
-
|
329
|
+
Pubnub.logger.error(:pubnub){"Already subscribed to channel group #{cg}, you have to leave that channel first"}
|
320
330
|
else
|
321
331
|
app.env[:subscriptions][@origin].add_channel_group(cg, app)
|
322
332
|
end
|
@@ -375,7 +385,7 @@ module Pubnub
|
|
375
385
|
|
376
386
|
end
|
377
387
|
rescue => error
|
378
|
-
|
388
|
+
Pubnub.logger.error(:pubnub){error}
|
379
389
|
end
|
380
390
|
end
|
381
391
|
|
@@ -385,33 +395,33 @@ module Pubnub
|
|
385
395
|
|
386
396
|
def add_channel_group(cg, app)
|
387
397
|
@channel_group << cg
|
388
|
-
|
398
|
+
Pubnub.logger.debug(:pubnub){'SubscribeEvent#add_channel | Added channel'}
|
389
399
|
end
|
390
400
|
|
391
401
|
def add_channel(channel, app)
|
392
402
|
@channel = @channel + format_channels(channel)
|
393
|
-
|
403
|
+
Pubnub.logger.debug(:pubnub){'SubscribeEvent#add_channel | Added channel'}
|
394
404
|
end
|
395
405
|
|
396
406
|
def remove_channel(channel, app)
|
397
407
|
@channel = @channel - format_channels(channel)
|
398
|
-
|
408
|
+
Pubnub.logger.debug(:pubnub){'SubscribeEvent#remove_channel | Removed channel'}
|
399
409
|
begin
|
400
410
|
shutdown_subscribe(app) if @channel.empty? && @channel_group.empty?
|
401
411
|
rescue => e
|
402
|
-
|
403
|
-
|
412
|
+
Pubnub.logger.error(:pubnub){e.message}
|
413
|
+
Pubnub.logger.error(:pubnub){e.backtrace}
|
404
414
|
end
|
405
415
|
end
|
406
416
|
|
407
417
|
def remove_channel_group(channel_group, app)
|
408
418
|
@channel_group = @channel_group - format_channel_group(channel_group, false)
|
409
|
-
|
419
|
+
Pubnub.logger.debug(:pubnub){'SubscribeEvent#remove_channel | Removed channel'}
|
410
420
|
begin
|
411
421
|
shutdown_subscribe(app) if @channel.empty? && @channel_group.empty?
|
412
422
|
rescue => e
|
413
|
-
|
414
|
-
|
423
|
+
Pubnub.logger.error(:pubnub){e.message}
|
424
|
+
Pubnub.logger.error(:pubnub){e.backtrace}
|
415
425
|
end
|
416
426
|
end
|
417
427
|
|
@@ -438,7 +448,7 @@ module Pubnub
|
|
438
448
|
end
|
439
449
|
|
440
450
|
def update_app_timetoken(envelopes, app)
|
441
|
-
|
451
|
+
Pubnub.logger.debug(:pubnub){'Event#update_app_timetoken'}
|
442
452
|
envelopes.each do |envelope|
|
443
453
|
if envelope.timetoken_update || envelope.timetoken.to_i > app.env[:timetoken].to_i
|
444
454
|
update_timetoken(app, envelope.timetoken)
|
@@ -462,7 +472,7 @@ module Pubnub
|
|
462
472
|
super
|
463
473
|
else
|
464
474
|
begin
|
465
|
-
|
475
|
+
Pubnub.logger.debug(:pubnub){'Event#fire_callbacks async'}
|
466
476
|
envelopes.each do |envelope|
|
467
477
|
if envelope.channel_group && app.env[:callbacks_pool][:channel_group][@origin][envelope.channel_group]
|
468
478
|
app.env[:callbacks_pool][:channel_group][@origin][envelope.channel_group][:callback].call(envelope) if !envelope.error && !envelope.timetoken_update
|
@@ -470,13 +480,13 @@ module Pubnub
|
|
470
480
|
app.env[:callbacks_pool][:channel][@origin][envelope.channel][:callback].call(envelope) if !envelope.error && !envelope.timetoken_update
|
471
481
|
end
|
472
482
|
end
|
473
|
-
|
483
|
+
Pubnub.logger.debug(:pubnub){'We can send next request now'}
|
474
484
|
app.env[:error_callbacks_pool][:channel][@origin].call(envelopes.first) if envelopes.first.error && !envelopes.first.channel_group
|
475
485
|
app.env[:error_callbacks_pool][:channel_group][@origin].call(envelopes.first) if envelopes.first.error && envelopes.first.channel_group
|
476
486
|
|
477
487
|
rescue => error
|
478
|
-
|
479
|
-
|
488
|
+
Pubnub.logger.error(:pubnub){error}
|
489
|
+
Pubnub.logger.error(:pubnub){error.backtrace}
|
480
490
|
end
|
481
491
|
end unless envelopes.nil?
|
482
492
|
|
@@ -513,15 +523,15 @@ module Pubnub
|
|
513
523
|
|
514
524
|
def format_envelopes(response, app, error)
|
515
525
|
|
516
|
-
|
526
|
+
Pubnub.logger.debug(:pubnub){'Subscribe#format_envelopes'}
|
517
527
|
|
518
528
|
parsed_response = Parser.parse_json(response.body) if Parser.valid_json?(response.body)
|
519
529
|
|
520
|
-
|
530
|
+
Pubnub.logger.debug(:pubnub){'Subscribe#format_envelopes | Response parsed'}
|
521
531
|
|
522
532
|
envelopes = Array.new
|
523
533
|
if error
|
524
|
-
|
534
|
+
Pubnub.logger.debug(:pubnub){'Subscribe#format_envelopes | Error'}
|
525
535
|
envelopes << Envelope.new(
|
526
536
|
{
|
527
537
|
:channel => @channel,
|
@@ -530,7 +540,7 @@ module Pubnub
|
|
530
540
|
app
|
531
541
|
)
|
532
542
|
elsif parsed_response[0].empty?
|
533
|
-
|
543
|
+
Pubnub.logger.debug(:pubnub){'Subscribe#format_envelopes | Timetoken'}
|
534
544
|
envelopes << Envelope.new(
|
535
545
|
{
|
536
546
|
:channel => @channel.first,
|
@@ -541,7 +551,7 @@ module Pubnub
|
|
541
551
|
app
|
542
552
|
)
|
543
553
|
elsif parsed_response.length < 4
|
544
|
-
|
554
|
+
Pubnub.logger.debug(:pubnub){'Subscribe#format_envelopes | Not timetoken update'}
|
545
555
|
|
546
556
|
if parsed_response[2]
|
547
557
|
channels = parsed_response[2].split(',')
|
@@ -555,9 +565,9 @@ module Pubnub
|
|
555
565
|
else
|
556
566
|
channel = channels[i]
|
557
567
|
end
|
558
|
-
|
568
|
+
Pubnub.logger.debug(:pubnub){"Subscribe#format_envelopes | Channel #{channel} created"}
|
559
569
|
|
560
|
-
|
570
|
+
Pubnub.logger.debug(:pubnub){"#{parsed_response}"}
|
561
571
|
|
562
572
|
envelopes << Envelope.new(
|
563
573
|
{
|
@@ -569,17 +579,17 @@ module Pubnub
|
|
569
579
|
app
|
570
580
|
)
|
571
581
|
|
572
|
-
|
582
|
+
Pubnub.logger.debug(:pubnub){'Subscribe#format_envelopes | Envelopes created'}
|
573
583
|
|
574
584
|
end
|
575
585
|
else
|
576
|
-
|
586
|
+
Pubnub.logger.debug(:pubnub){'Subscribe#format_envelopes | Not timetoken update'}
|
577
587
|
|
578
588
|
parsed_response[0].size.times do |i|
|
579
589
|
channel = parsed_response[3].split(',')[i]
|
580
590
|
channel_group = parsed_response[2].split(',')[i]
|
581
591
|
|
582
|
-
|
592
|
+
Pubnub.logger.debug(:pubnub){"#{parsed_response}"}
|
583
593
|
|
584
594
|
envelopes << Envelope.new(
|
585
595
|
{
|
@@ -592,12 +602,12 @@ module Pubnub
|
|
592
602
|
app
|
593
603
|
)
|
594
604
|
|
595
|
-
|
605
|
+
Pubnub.logger.debug(:pubnub){'Subscribe#format_envelopes | Envelopes created'}
|
596
606
|
|
597
607
|
end
|
598
608
|
end
|
599
609
|
|
600
|
-
|
610
|
+
Pubnub.logger.debug(:pubnub){'Subscribe#format_envelopes | envelopes created'}
|
601
611
|
|
602
612
|
envelopes = add_common_data_to_envelopes(envelopes, response, app, error)
|
603
613
|
|