actioncable 5.0.0.beta1.1 → 5.0.0.beta2
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 +4 -4
- data/CHANGELOG.md +23 -3
- data/MIT-LICENSE +1 -1
- data/README.md +60 -44
- data/lib/action_cable.rb +2 -1
- data/lib/action_cable/channel/base.rb +2 -2
- data/lib/action_cable/channel/periodic_timers.rb +3 -3
- data/lib/action_cable/channel/streams.rb +4 -4
- data/lib/action_cable/connection.rb +4 -1
- data/lib/action_cable/connection/base.rb +22 -21
- data/lib/action_cable/connection/client_socket.rb +150 -0
- data/lib/action_cable/connection/identification.rb +1 -1
- data/lib/action_cable/connection/internal_channel.rb +6 -6
- data/lib/action_cable/connection/stream.rb +59 -0
- data/lib/action_cable/connection/stream_event_loop.rb +94 -0
- data/lib/action_cable/connection/subscriptions.rb +0 -1
- data/lib/action_cable/connection/web_socket.rb +14 -8
- data/lib/action_cable/engine.rb +3 -3
- data/lib/action_cable/gem_version.rb +1 -1
- data/lib/action_cable/remote_connections.rb +1 -1
- data/lib/action_cable/server.rb +0 -4
- data/lib/action_cable/server/base.rb +19 -22
- data/lib/action_cable/server/broadcasting.rb +1 -8
- data/lib/action_cable/server/configuration.rb +25 -5
- data/lib/action_cable/server/connections.rb +3 -5
- data/lib/action_cable/server/worker.rb +42 -13
- data/lib/action_cable/subscription_adapter.rb +8 -0
- data/lib/action_cable/subscription_adapter/async.rb +22 -0
- data/lib/action_cable/subscription_adapter/base.rb +28 -0
- data/lib/action_cable/subscription_adapter/evented_redis.rb +67 -0
- data/lib/action_cable/subscription_adapter/inline.rb +35 -0
- data/lib/action_cable/subscription_adapter/postgresql.rb +106 -0
- data/lib/action_cable/subscription_adapter/redis.rb +163 -0
- data/lib/action_cable/subscription_adapter/subscriber_map.rb +53 -0
- data/lib/assets/compiled/action_cable.js +473 -0
- data/lib/rails/generators/channel/channel_generator.rb +6 -1
- metadata +21 -99
- data/lib/action_cable/process/logging.rb +0 -10
- data/lib/assets/javascripts/action_cable.coffee.erb +0 -23
- data/lib/assets/javascripts/action_cable/connection.coffee +0 -84
- data/lib/assets/javascripts/action_cable/connection_monitor.coffee +0 -84
- data/lib/assets/javascripts/action_cable/consumer.coffee +0 -31
- data/lib/assets/javascripts/action_cable/subscription.coffee +0 -68
- data/lib/assets/javascripts/action_cable/subscriptions.coffee +0 -78
@@ -1,68 +0,0 @@
|
|
1
|
-
# A new subscription is created through the ActionCable.Subscriptions instance available on the consumer.
|
2
|
-
# It provides a number of callbacks and a method for calling remote procedure calls on the corresponding
|
3
|
-
# Channel instance on the server side.
|
4
|
-
#
|
5
|
-
# An example demonstrates the basic functionality:
|
6
|
-
#
|
7
|
-
# App.appearance = App.cable.subscriptions.create "AppearanceChannel",
|
8
|
-
# connected: ->
|
9
|
-
# # Called once the subscription has been successfully completed
|
10
|
-
#
|
11
|
-
# appear: ->
|
12
|
-
# @perform 'appear', appearing_on: @appearingOn()
|
13
|
-
#
|
14
|
-
# away: ->
|
15
|
-
# @perform 'away'
|
16
|
-
#
|
17
|
-
# appearingOn: ->
|
18
|
-
# $('main').data 'appearing-on'
|
19
|
-
#
|
20
|
-
# The methods #appear and #away forward their intent to the remote AppearanceChannel instance on the server
|
21
|
-
# by calling the `@perform` method with the first parameter being the action (which maps to AppearanceChannel#appear/away).
|
22
|
-
# The second parameter is a hash that'll get JSON encoded and made available on the server in the data parameter.
|
23
|
-
#
|
24
|
-
# This is how the server component would look:
|
25
|
-
#
|
26
|
-
# class AppearanceChannel < ApplicationActionCable::Channel
|
27
|
-
# def subscribed
|
28
|
-
# current_user.appear
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
# def unsubscribed
|
32
|
-
# current_user.disappear
|
33
|
-
# end
|
34
|
-
#
|
35
|
-
# def appear(data)
|
36
|
-
# current_user.appear on: data['appearing_on']
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# def away
|
40
|
-
# current_user.away
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# The "AppearanceChannel" name is automatically mapped between the client-side subscription creation and the server-side Ruby class name.
|
45
|
-
# The AppearanceChannel#appear/away public methods are exposed automatically to client-side invocation through the @perform method.
|
46
|
-
class ActionCable.Subscription
|
47
|
-
constructor: (@subscriptions, params = {}, mixin) ->
|
48
|
-
@identifier = JSON.stringify(params)
|
49
|
-
extend(this, mixin)
|
50
|
-
@subscriptions.add(this)
|
51
|
-
@consumer = @subscriptions.consumer
|
52
|
-
|
53
|
-
# Perform a channel action with the optional data passed as an attribute
|
54
|
-
perform: (action, data = {}) ->
|
55
|
-
data.action = action
|
56
|
-
@send(data)
|
57
|
-
|
58
|
-
send: (data) ->
|
59
|
-
@consumer.send(command: "message", identifier: @identifier, data: JSON.stringify(data))
|
60
|
-
|
61
|
-
unsubscribe: ->
|
62
|
-
@subscriptions.remove(this)
|
63
|
-
|
64
|
-
extend = (object, properties) ->
|
65
|
-
if properties?
|
66
|
-
for key, value of properties
|
67
|
-
object[key] = value
|
68
|
-
object
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# Collection class for creating (and internally managing) channel subscriptions. The only method intended to be triggered by the user
|
2
|
-
# us ActionCable.Subscriptions#create, and it should be called through the consumer like so:
|
3
|
-
#
|
4
|
-
# @App = {}
|
5
|
-
# App.cable = ActionCable.createConsumer "ws://example.com/accounts/1"
|
6
|
-
# App.appearance = App.cable.subscriptions.create "AppearanceChannel"
|
7
|
-
#
|
8
|
-
# For more details on how you'd configure an actual channel subscription, see ActionCable.Subscription.
|
9
|
-
class ActionCable.Subscriptions
|
10
|
-
constructor: (@consumer) ->
|
11
|
-
@subscriptions = []
|
12
|
-
@history = []
|
13
|
-
|
14
|
-
create: (channelName, mixin) ->
|
15
|
-
channel = channelName
|
16
|
-
params = if typeof channel is "object" then channel else {channel}
|
17
|
-
new ActionCable.Subscription this, params, mixin
|
18
|
-
|
19
|
-
# Private
|
20
|
-
|
21
|
-
add: (subscription) ->
|
22
|
-
@subscriptions.push(subscription)
|
23
|
-
@notify(subscription, "initialized")
|
24
|
-
@sendCommand(subscription, "subscribe")
|
25
|
-
|
26
|
-
remove: (subscription) ->
|
27
|
-
@forget(subscription)
|
28
|
-
|
29
|
-
unless @findAll(subscription.identifier).length
|
30
|
-
@sendCommand(subscription, "unsubscribe")
|
31
|
-
|
32
|
-
reject: (identifier) ->
|
33
|
-
for subscription in @findAll(identifier)
|
34
|
-
@forget(subscription)
|
35
|
-
@notify(subscription, "rejected")
|
36
|
-
|
37
|
-
forget: (subscription) ->
|
38
|
-
@subscriptions = (s for s in @subscriptions when s isnt subscription)
|
39
|
-
|
40
|
-
findAll: (identifier) ->
|
41
|
-
s for s in @subscriptions when s.identifier is identifier
|
42
|
-
|
43
|
-
reload: ->
|
44
|
-
for subscription in @subscriptions
|
45
|
-
@sendCommand(subscription, "subscribe")
|
46
|
-
|
47
|
-
notifyAll: (callbackName, args...) ->
|
48
|
-
for subscription in @subscriptions
|
49
|
-
@notify(subscription, callbackName, args...)
|
50
|
-
|
51
|
-
notify: (subscription, callbackName, args...) ->
|
52
|
-
if typeof subscription is "string"
|
53
|
-
subscriptions = @findAll(subscription)
|
54
|
-
else
|
55
|
-
subscriptions = [subscription]
|
56
|
-
|
57
|
-
for subscription in subscriptions
|
58
|
-
subscription[callbackName]?(args...)
|
59
|
-
|
60
|
-
if callbackName in ["initialized", "connected", "disconnected", "rejected"]
|
61
|
-
{identifier} = subscription
|
62
|
-
@record(notification: {identifier, callbackName, args})
|
63
|
-
|
64
|
-
sendCommand: (subscription, command) ->
|
65
|
-
{identifier} = subscription
|
66
|
-
if identifier is ActionCable.INTERNAL.identifiers.ping
|
67
|
-
@consumer.connection.isOpen()
|
68
|
-
else
|
69
|
-
@consumer.send({command, identifier})
|
70
|
-
|
71
|
-
record: (data) ->
|
72
|
-
data.time = new Date()
|
73
|
-
@history = @history.slice(-19)
|
74
|
-
@history.push(data)
|
75
|
-
|
76
|
-
toJSON: ->
|
77
|
-
history: @history
|
78
|
-
identifiers: (subscription.identifier for subscription in @subscriptions)
|