celluloid_pubsub 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 269b50c5760b451657e2203852797199925b3d98
|
4
|
+
data.tar.gz: aa6318fa2134008fa6750690223d3fa9f7ff07e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71114ae804ba8d00224a9fe1a831775c85ab9c6ac9a1af050f0dbb360c1e652cabcf6252f0c4eb32481d802b0c39efae22a8adfda43ee1ce7aa24b40efa7b38b
|
7
|
+
data.tar.gz: 4eacd46bd37575138ab7a8dff3272c8ebe25728aa9f48ed4bb379c9e0914f48c6b4fe2cbf53b1dbf1b5a9ed287db0e7c876b79593d7d2cdd85f2e3ade6184a26
|
@@ -114,9 +114,7 @@ module CelluloidPubsub
|
|
114
114
|
#
|
115
115
|
# @api public
|
116
116
|
def publish(channel, data)
|
117
|
-
|
118
|
-
debug(" #{self.class} publishl to #{channel} message: #{publishing_data}") if debug_enabled?
|
119
|
-
async.chat(publishing_data)
|
117
|
+
send_action('publish', channel, data)
|
120
118
|
end
|
121
119
|
|
122
120
|
# unsubscribes current client from a channel
|
@@ -127,9 +125,7 @@ module CelluloidPubsub
|
|
127
125
|
#
|
128
126
|
# @api public
|
129
127
|
def unsubscribe(channel)
|
130
|
-
|
131
|
-
debug(" #{self.class} sends: #{publishing_data}") if debug_enabled?
|
132
|
-
async.chat(publishing_data)
|
128
|
+
send_action('unsubscribe', channel)
|
133
129
|
end
|
134
130
|
|
135
131
|
# unsubscribes all clients subscribed to a channel
|
@@ -140,9 +136,7 @@ module CelluloidPubsub
|
|
140
136
|
#
|
141
137
|
# @api public
|
142
138
|
def unsubscribe_clients(channel)
|
143
|
-
|
144
|
-
debug(" #{self.class} sends: #{publishing_data}") if debug_enabled?
|
145
|
-
async.chat(publishing_data)
|
139
|
+
send_action('unsubscribe_clients', channel)
|
146
140
|
end
|
147
141
|
|
148
142
|
# unsubscribes all clients from all channels
|
@@ -151,9 +145,7 @@ module CelluloidPubsub
|
|
151
145
|
#
|
152
146
|
# @api public
|
153
147
|
def unsubscribe_all
|
154
|
-
|
155
|
-
debug(" #{self.class} sends: #{publishing_data}") if debug_enabled?
|
156
|
-
async.chat(publishing_data)
|
148
|
+
send_action('unsubscribe_all')
|
157
149
|
end
|
158
150
|
# callback executes after connection is opened and delegates action to actor
|
159
151
|
#
|
@@ -199,6 +191,23 @@ module CelluloidPubsub
|
|
199
191
|
|
200
192
|
private
|
201
193
|
|
194
|
+
# method used to send an action to the webserver reactor , to a chanel and with data
|
195
|
+
#
|
196
|
+
# @param [String] action
|
197
|
+
# @param [String] channel
|
198
|
+
# @param [Hash] data
|
199
|
+
#
|
200
|
+
# @return [void]
|
201
|
+
#
|
202
|
+
# @api private
|
203
|
+
def send_action(action, channel = nil, data = {})
|
204
|
+
publishing_data = { 'client_action' => action }
|
205
|
+
publishing_data = publishing_data.merge('channel' => channel) if channel.present?
|
206
|
+
publishing_data = publishing_data.merge('data' => data) if data.present?
|
207
|
+
debug(" #{self.class} sends: #{publishing_data}") if debug_enabled?
|
208
|
+
async.chat(publishing_data)
|
209
|
+
end
|
210
|
+
|
202
211
|
# method used to send messages to the webserver
|
203
212
|
# checks too see if the message is a hash and if it is it will transform it to JSON and send it to the webser
|
204
213
|
# otherwise will construct a JSON object that will have the key action with the value 'message" and the key message witth the parameter's value
|
@@ -62,8 +62,8 @@ module CelluloidPubsub
|
|
62
62
|
message = nil
|
63
63
|
begin
|
64
64
|
message = @websocket.read
|
65
|
-
|
66
|
-
|
65
|
+
rescue => e
|
66
|
+
debug(e) if @server.debug_enabled?
|
67
67
|
end
|
68
68
|
message
|
69
69
|
end
|
@@ -208,10 +208,7 @@ module CelluloidPubsub
|
|
208
208
|
# @api public
|
209
209
|
def unsubscribe_clients(channel)
|
210
210
|
return if channel.blank? || @server.subscribers[channel].blank?
|
211
|
-
|
212
|
-
hash[:reactor].websocket.close
|
213
|
-
Celluloid::Actor.kill(hash[:reactor])
|
214
|
-
end
|
211
|
+
unsubscribe_from_channel(channel)
|
215
212
|
@server.subscribers[channel] = []
|
216
213
|
end
|
217
214
|
|
@@ -266,15 +263,25 @@ module CelluloidPubsub
|
|
266
263
|
# @api public
|
267
264
|
def unsubscribe_all
|
268
265
|
CelluloidPubsub::Registry.channels.map do |channel|
|
269
|
-
|
270
|
-
hash[:reactor].websocket.close
|
271
|
-
Celluloid::Actor.kill(hash[:reactor])
|
272
|
-
end
|
266
|
+
unsubscribe_from_channel(channel)
|
273
267
|
@server.subscribers[channel] = []
|
274
268
|
end
|
275
269
|
|
276
270
|
info 'clearing connections' if @server.debug_enabled?
|
277
271
|
shutdown
|
278
272
|
end
|
273
|
+
|
274
|
+
# unsubscribes all actors from the specified chanel
|
275
|
+
#
|
276
|
+
# @param [String] channel
|
277
|
+
# @return [void]
|
278
|
+
#
|
279
|
+
# @api public
|
280
|
+
def unsubscribe_from_channel(channel)
|
281
|
+
@server.subscribers[channel].each do |hash|
|
282
|
+
hash[:reactor].websocket.close
|
283
|
+
Celluloid::Actor.kill(hash[:reactor])
|
284
|
+
end
|
285
|
+
end
|
279
286
|
end
|
280
287
|
end
|
@@ -16,6 +16,8 @@
|
|
16
16
|
subject.stubs(:inspect).returns(subject)
|
17
17
|
subject.stubs(:run)
|
18
18
|
subject.work(websocket, server)
|
19
|
+
subject.stubs(:unsubscribe_from_channel).returns(true)
|
20
|
+
Celluloid::Actor.stubs(:kill).returns(true)
|
19
21
|
end
|
20
22
|
|
21
23
|
describe '#work' do
|
@@ -204,11 +206,8 @@
|
|
204
206
|
let(:message) { { a: 'b' } }
|
205
207
|
|
206
208
|
it 'adds subscribed' do
|
207
|
-
Celluloid::Actor.stubs(:kill).returns(true)
|
208
209
|
CelluloidPubsub::Registry.stubs(:channels).returns([channel])
|
209
|
-
|
210
|
-
subject.websocket.expects(:close)
|
211
|
-
subject.expects(:shutdown)
|
210
|
+
subject.expects(:unsubscribe_from_channel).with(channel)
|
212
211
|
subject.unsubscribe_all
|
213
212
|
end
|
214
213
|
end
|