faye_tracking 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/faye_tracking.rb +11 -3
- data/lib/faye_tracking/{store/abstract_key_list.rb → abstract_key_list.rb} +0 -0
- data/lib/faye_tracking/faye_extension.rb +10 -8
- data/lib/faye_tracking/{store/adapter/namespaced_key_list.rb → namespaced_key_list.rb} +0 -0
- data/lib/faye_tracking/{store/adapter/redis_key_list.rb → redis_key_list.rb} +0 -0
- data/lib/faye_tracking/tracker.rb +4 -0
- data/lib/faye_tracking/version.rb +1 -1
- data/spec/faye_tracking/tracker_spec.rb +30 -0
- data/spec/faye_tracking_spec.rb +14 -47
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d632c5493a22f757f2b0303fb47f84d12066440
|
4
|
+
data.tar.gz: 54cc0a7362c2276f0c99e94f4514275583cae9df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0cd9f00bf48fa591079ea9e68ed6bff1e2a0b5c97207e1cf56288e7542b34da86788300f60bbe5e0f7ae6e3f1296c52f553adcc15691ebf2587ec5f3d2a142f
|
7
|
+
data.tar.gz: 194aea886aae0dd094017530891aad132676342e4b03978506bf35b57273032506868480e33e6b1a8ee7a7d9f6ae26ac9d7a6e37b54e94ace15a8d2f20800bd0
|
data/lib/faye_tracking.rb
CHANGED
@@ -24,6 +24,14 @@ module FayeTracking
|
|
24
24
|
tracker.users_in_channel(channel)
|
25
25
|
end
|
26
26
|
|
27
|
+
def user_with_client_id(client_id)
|
28
|
+
tracker.user_with_client_id(client_id)
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove_from_channel(channel, client)
|
32
|
+
tracker.remove(channel, client)
|
33
|
+
end
|
34
|
+
|
27
35
|
def reset_store
|
28
36
|
redis.keys('*').each {|k| redis.del k}
|
29
37
|
end
|
@@ -64,6 +72,6 @@ end
|
|
64
72
|
|
65
73
|
require "faye_tracking/faye_extension"
|
66
74
|
require "faye_tracking/tracker"
|
67
|
-
require "faye_tracking/
|
68
|
-
require "faye_tracking/
|
69
|
-
require "faye_tracking/
|
75
|
+
require "faye_tracking/abstract_key_list"
|
76
|
+
require "faye_tracking/redis_key_list"
|
77
|
+
require "faye_tracking/namespaced_key_list"
|
File without changes
|
@@ -17,17 +17,16 @@ module FayeTracking
|
|
17
17
|
FayeTracking.logger.debug "received incoming message: #{message}"
|
18
18
|
|
19
19
|
unless message['error']
|
20
|
-
subs_channel
|
21
|
-
client_id
|
20
|
+
subs_channel = message['subscription']
|
21
|
+
client_id = message['clientId']
|
22
|
+
run_subscribe_callbacks = false
|
22
23
|
|
23
24
|
case message['channel']
|
24
25
|
when '/meta/subscribe'
|
25
26
|
ext = message['ext']
|
26
27
|
if app_client_id = ext['faye_tracking_client_id']
|
27
28
|
@tracker.add(subs_channel, client_id, app_client_id)
|
28
|
-
|
29
|
-
client_id, app_client_id, subs_channel
|
30
|
-
)
|
29
|
+
run_subscribe_callbacks = true
|
31
30
|
else
|
32
31
|
error_message = "missing ext['faye_tracking_client_id']"
|
33
32
|
FayeTracking.logger.error "error with message: #{error_message}"
|
@@ -36,13 +35,16 @@ module FayeTracking
|
|
36
35
|
when '/meta/unsubscribe'
|
37
36
|
# This is not reliable, more robust way to detect unsubscribe event.
|
38
37
|
# see: http://faye.jcoglan.com/ruby/monitoring.html
|
39
|
-
@tracker.remove(subs_channel, client_id)
|
40
|
-
when '/meta/disconnect'
|
41
|
-
@tracker.remove_all(client_id)
|
42
38
|
end
|
43
39
|
end
|
44
40
|
|
45
41
|
callback.call(message)
|
42
|
+
|
43
|
+
if run_subscribe_callbacks
|
44
|
+
FayeTracking.run_on_subscribe_callbacks(
|
45
|
+
client_id, app_client_id, subs_channel
|
46
|
+
)
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
File without changes
|
File without changes
|
@@ -14,6 +14,10 @@ module FayeTracking
|
|
14
14
|
@client_id_to_users.add(client_id, user)
|
15
15
|
end
|
16
16
|
|
17
|
+
def user_with_client_id(client_id)
|
18
|
+
@client_id_to_users.members(client_id).first
|
19
|
+
end
|
20
|
+
|
17
21
|
def remove(channel, client_id)
|
18
22
|
@channel_to_client_ids.remove(channel, client_id)
|
19
23
|
@client_id_to_channels.remove(client_id, channel)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FayeTracking::Tracker do
|
4
|
+
let(:tracker) { described_class.new(FayeTracking.redis) }
|
5
|
+
let(:channel) { 'room' }
|
6
|
+
let(:client_id) { 'abcdefg123456' }
|
7
|
+
let(:user_id) { 'user_1' }
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
FayeTracking.reset_store
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#remove' do
|
14
|
+
before do
|
15
|
+
tracker.add(channel, client_id, user_id)
|
16
|
+
expect(tracker.users_in_channel(channel)).to_not be_empty
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'removes a user from a channel' do
|
20
|
+
tracker.remove channel, client_id
|
21
|
+
expect(tracker.users_in_channel(channel)).to be_empty
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'does not raise error when removing a non-existing user' do
|
25
|
+
expect {
|
26
|
+
tracker.remove channel, 'invalid_user'
|
27
|
+
}.to_not raise_error
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/faye_tracking_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe FayeTracking do
|
4
|
+
let(:client_id) { 'abcdefg123456' }
|
5
|
+
let(:another_client_id) { 'anotherclient' }
|
6
|
+
|
4
7
|
before(:each) do
|
5
8
|
FayeTracking.reset_store
|
6
9
|
end
|
7
10
|
|
8
|
-
let(:client_id) { 'rpy799jnfeq' }
|
9
|
-
let(:another_client_id) { '651w533ncba' }
|
10
|
-
|
11
11
|
def faye_run(meta_action, subscription, client_id, user)
|
12
12
|
message = { "channel" => meta_action, "clientId" => client_id }
|
13
13
|
message["subscription"] = subscription if subscription
|
@@ -45,70 +45,37 @@ describe FayeTracking do
|
|
45
45
|
expect(described_class.users_in_channel('room')).to \
|
46
46
|
match_array(['user_1', 'user_2'])
|
47
47
|
end
|
48
|
+
|
49
|
+
it 'associate client_id with user' do
|
50
|
+
faye_subscribe 'room', client_id, 'user_2'
|
51
|
+
expect(described_class.user_with_client_id(client_id)).to eq('user_2')
|
52
|
+
end
|
48
53
|
end
|
49
54
|
|
50
55
|
describe 'customize subscribe block' do
|
51
56
|
it 'can set a customize subscribe block' do
|
52
57
|
result = nil
|
53
|
-
|
58
|
+
described_class.on_subscribe do |client_id, user_id, channel|
|
54
59
|
result = [client_id, user_id, channel]
|
55
60
|
end
|
56
61
|
faye_subscribe 'room', client_id, 'user_1'
|
57
62
|
expect(result).to eq([client_id, 'user_1', 'room'])
|
58
|
-
|
63
|
+
described_class.reset_on_subscribe_callbacks
|
59
64
|
end
|
60
65
|
end
|
61
66
|
end
|
62
67
|
|
63
|
-
|
64
|
-
|
65
|
-
faye_subscribe 'room', client_id, 'user_1'
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'removes a user from a subscription channel' do
|
69
|
-
faye_unsubscribe 'room', client_id
|
70
|
-
expect(described_class.user_in_any_channel?('user_1')).to be_falsey
|
71
|
-
expect(described_class.users_in_channel('rooom')).to eq([])
|
72
|
-
|
73
|
-
faye_subscribe 'room', client_id, 'user_2'
|
74
|
-
expect(described_class.user_in_any_channel?('user_2')).to be_truthy
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'does not raise error when removing a non-existing user' do
|
78
|
-
expect {
|
79
|
-
faye_unsubscribe 'room', 'user_2'
|
80
|
-
}.to_not raise_error
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe 'subscribing/unsubscribing same users with different clientIds' do
|
85
|
-
before do
|
68
|
+
describe 'subscribing same user with different clientIds' do
|
69
|
+
it 'user able to have multiple client ids' do
|
86
70
|
faye_subscribe 'room', client_id, 'user_1'
|
87
71
|
faye_subscribe 'room', another_client_id, 'user_1'
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'user able to have multiple client ids' do
|
91
72
|
expect(described_class.user_in_channel?('user_1', 'room')).to be_truthy
|
92
73
|
|
93
|
-
|
74
|
+
described_class.remove_from_channel 'room', client_id
|
94
75
|
expect(described_class.user_in_channel?('user_1', 'room')).to be_truthy
|
95
76
|
|
96
|
-
|
77
|
+
described_class.remove_from_channel 'room', another_client_id
|
97
78
|
expect(described_class.user_in_channel?('user_1', 'room')).to be_falsey
|
98
79
|
end
|
99
80
|
end
|
100
|
-
|
101
|
-
context 'disconnecting' do
|
102
|
-
before do
|
103
|
-
faye_subscribe 'room1', client_id, 'user_1'
|
104
|
-
faye_subscribe 'room2', client_id, 'user_1'
|
105
|
-
faye_subscribe 'room1', another_client_id, 'user_2'
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'removes the user from all channels' do
|
109
|
-
faye_disconnect(client_id)
|
110
|
-
expect(described_class.user_in_any_channel?('user_1')).to be_falsey
|
111
|
-
expect(described_class.users_in_channel('room1')).to eq(['user_2'])
|
112
|
-
end
|
113
|
-
end
|
114
81
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin He
|
@@ -95,12 +95,13 @@ files:
|
|
95
95
|
- Rakefile
|
96
96
|
- faye_tracking.gemspec
|
97
97
|
- lib/faye_tracking.rb
|
98
|
+
- lib/faye_tracking/abstract_key_list.rb
|
98
99
|
- lib/faye_tracking/faye_extension.rb
|
99
|
-
- lib/faye_tracking/
|
100
|
-
- lib/faye_tracking/
|
101
|
-
- lib/faye_tracking/store/adapter/redis_key_list.rb
|
100
|
+
- lib/faye_tracking/namespaced_key_list.rb
|
101
|
+
- lib/faye_tracking/redis_key_list.rb
|
102
102
|
- lib/faye_tracking/tracker.rb
|
103
103
|
- lib/faye_tracking/version.rb
|
104
|
+
- spec/faye_tracking/tracker_spec.rb
|
104
105
|
- spec/faye_tracking_spec.rb
|
105
106
|
- spec/spec_helper.rb
|
106
107
|
homepage: https://github.com/he9lin/faye_tracking
|
@@ -128,6 +129,7 @@ signing_key:
|
|
128
129
|
specification_version: 4
|
129
130
|
summary: Faye extension for tracking user subscriptions
|
130
131
|
test_files:
|
132
|
+
- spec/faye_tracking/tracker_spec.rb
|
131
133
|
- spec/faye_tracking_spec.rb
|
132
134
|
- spec/spec_helper.rb
|
133
135
|
has_rdoc:
|