faye_tracking 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/faye_tracking.rb +16 -0
- data/lib/faye_tracking/faye_extension.rb +13 -3
- data/lib/faye_tracking/store/adapter/namespaced_key_list.rb +3 -2
- data/lib/faye_tracking/version.rb +1 -1
- data/spec/faye_tracking_spec.rb +13 -1
- 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: 4d25e8f9595db01848dda129c76e4aa15f0ad8e0
|
4
|
+
data.tar.gz: e353842553b1d51dcd1e8b1e0dd49e55b8ebd232
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa8fba78c26b0301ab57ce157cfec9deb9aacb049a70a328dcd9324bef9b9e652b340fb11b76065bb1c935f32ea5a18a32323a57b0670e1f89e3721d256a86c7
|
7
|
+
data.tar.gz: 9ce51c9b99728bcf4d2126a2bf4d0ece75a9af0d8731cd7afa6cf38a4213d170f50f90f2ea65491419718ce959e1d1136c20bdaa7950b2397393584a13f46ad8
|
data/.gitignore
CHANGED
data/lib/faye_tracking.rb
CHANGED
@@ -43,6 +43,22 @@ module FayeTracking
|
|
43
43
|
def tracker
|
44
44
|
@_tracker = Tracker.new(redis)
|
45
45
|
end
|
46
|
+
|
47
|
+
def on_subscribe_callbacks
|
48
|
+
@_on_subscribe_callbacks || reset_on_subscribe_callbacks
|
49
|
+
end
|
50
|
+
|
51
|
+
def on_subscribe(&block)
|
52
|
+
on_subscribe_callbacks << block
|
53
|
+
end
|
54
|
+
|
55
|
+
def run_on_subscribe_callbacks(*args)
|
56
|
+
on_subscribe_callbacks.each { |blk| blk.call(*args) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def reset_on_subscribe_callbacks
|
60
|
+
@_on_subscribe_callbacks = []
|
61
|
+
end
|
46
62
|
end
|
47
63
|
end
|
48
64
|
|
@@ -1,13 +1,18 @@
|
|
1
1
|
module FayeTracking
|
2
2
|
class FayeExtension
|
3
|
-
MONITORED_CHANNELS = [
|
3
|
+
MONITORED_CHANNELS = [
|
4
|
+
'/meta/subscribe',
|
5
|
+
'/meta/unsubscribe',
|
6
|
+
'/meta/disconnect'
|
7
|
+
]
|
4
8
|
|
5
9
|
def initialize(tracker)
|
6
10
|
@tracker = tracker
|
7
11
|
end
|
8
12
|
|
9
13
|
def incoming(message, callback)
|
10
|
-
return callback.call(message)
|
14
|
+
return callback.call(message) \
|
15
|
+
unless MONITORED_CHANNELS.include? message['channel']
|
11
16
|
|
12
17
|
FayeTracking.logger.debug "received incoming message: #{message}"
|
13
18
|
|
@@ -20,12 +25,17 @@ module FayeTracking
|
|
20
25
|
ext = message['ext']
|
21
26
|
if app_client_id = ext['faye_tracking_client_id']
|
22
27
|
@tracker.add(subs_channel, client_id, app_client_id)
|
28
|
+
FayeTracking.run_on_subscribe_callbacks(
|
29
|
+
client_id, app_client_id, subs_channel
|
30
|
+
)
|
23
31
|
else
|
24
32
|
error_message = "missing ext['faye_tracking_client_id']"
|
25
|
-
FayeTracking.logger.
|
33
|
+
FayeTracking.logger.error "error with message: #{error_message}"
|
26
34
|
message['error'] = error_message
|
27
35
|
end
|
28
36
|
when '/meta/unsubscribe'
|
37
|
+
# This is not reliable, more robust way to detect unsubscribe event.
|
38
|
+
# see: http://faye.jcoglan.com/ruby/monitoring.html
|
29
39
|
@tracker.remove(subs_channel, client_id)
|
30
40
|
when '/meta/disconnect'
|
31
41
|
@tracker.remove_all(client_id)
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module FayeTracking
|
2
2
|
class NamespacedKeyList < AbstractKeyList
|
3
3
|
def initialize(ns, key_list)
|
4
|
-
raise ArgumentError, 'namespace param cannot be blank'
|
5
|
-
|
4
|
+
raise ArgumentError, 'namespace param cannot be blank' \
|
5
|
+
if ns.nil? || ns.empty?
|
6
|
+
|
6
7
|
@ns = ns
|
7
8
|
@key_list = key_list
|
8
9
|
end
|
data/spec/faye_tracking_spec.rb
CHANGED
@@ -42,7 +42,19 @@ describe FayeTracking do
|
|
42
42
|
|
43
43
|
it 'returns all users in a channel' do
|
44
44
|
faye_subscribe 'room', client_id, 'user_2'
|
45
|
-
expect(described_class.users_in_channel('room')).to
|
45
|
+
expect(described_class.users_in_channel('room')).to \
|
46
|
+
match_array(['user_1', 'user_2'])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'customize subscribe block' do
|
51
|
+
it 'can set a customize subscribe block' do
|
52
|
+
result = nil
|
53
|
+
FayeTracking.on_subscribe do |client_id, user_id, channel|
|
54
|
+
result = [client_id, user_id, channel]
|
55
|
+
end
|
56
|
+
faye_subscribe 'room', client_id, 'user_1'
|
57
|
+
expect(result).to eq([client_id, 'user_1', 'room'])
|
46
58
|
end
|
47
59
|
end
|
48
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faye_tracking
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin He
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|