actioncable 0.0.0 → 5.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +439 -21
  5. data/lib/action_cable.rb +47 -2
  6. data/lib/action_cable/channel.rb +14 -0
  7. data/lib/action_cable/channel/base.rb +277 -0
  8. data/lib/action_cable/channel/broadcasting.rb +29 -0
  9. data/lib/action_cable/channel/callbacks.rb +35 -0
  10. data/lib/action_cable/channel/naming.rb +22 -0
  11. data/lib/action_cable/channel/periodic_timers.rb +41 -0
  12. data/lib/action_cable/channel/streams.rb +114 -0
  13. data/lib/action_cable/connection.rb +16 -0
  14. data/lib/action_cable/connection/authorization.rb +13 -0
  15. data/lib/action_cable/connection/base.rb +221 -0
  16. data/lib/action_cable/connection/identification.rb +46 -0
  17. data/lib/action_cable/connection/internal_channel.rb +45 -0
  18. data/lib/action_cable/connection/message_buffer.rb +54 -0
  19. data/lib/action_cable/connection/subscriptions.rb +76 -0
  20. data/lib/action_cable/connection/tagged_logger_proxy.rb +40 -0
  21. data/lib/action_cable/connection/web_socket.rb +29 -0
  22. data/lib/action_cable/engine.rb +38 -0
  23. data/lib/action_cable/gem_version.rb +15 -0
  24. data/lib/action_cable/helpers/action_cable_helper.rb +29 -0
  25. data/lib/action_cable/process/logging.rb +10 -0
  26. data/lib/action_cable/remote_connections.rb +64 -0
  27. data/lib/action_cable/server.rb +19 -0
  28. data/lib/action_cable/server/base.rb +77 -0
  29. data/lib/action_cable/server/broadcasting.rb +54 -0
  30. data/lib/action_cable/server/configuration.rb +35 -0
  31. data/lib/action_cable/server/connections.rb +37 -0
  32. data/lib/action_cable/server/worker.rb +42 -0
  33. data/lib/action_cable/server/worker/active_record_connection_management.rb +22 -0
  34. data/lib/action_cable/version.rb +6 -1
  35. data/lib/assets/javascripts/action_cable.coffee.erb +23 -0
  36. data/lib/assets/javascripts/action_cable/connection.coffee +84 -0
  37. data/lib/assets/javascripts/action_cable/connection_monitor.coffee +84 -0
  38. data/lib/assets/javascripts/action_cable/consumer.coffee +31 -0
  39. data/lib/assets/javascripts/action_cable/subscription.coffee +68 -0
  40. data/lib/assets/javascripts/action_cable/subscriptions.coffee +78 -0
  41. data/lib/rails/generators/channel/USAGE +14 -0
  42. data/lib/rails/generators/channel/channel_generator.rb +21 -0
  43. data/lib/rails/generators/channel/templates/assets/channel.coffee +14 -0
  44. data/lib/rails/generators/channel/templates/channel.rb +17 -0
  45. metadata +161 -26
  46. data/.gitignore +0 -9
  47. data/Gemfile +0 -4
  48. data/LICENSE.txt +0 -21
  49. data/Rakefile +0 -2
  50. data/actioncable.gemspec +0 -22
  51. data/bin/console +0 -14
  52. data/bin/setup +0 -7
@@ -0,0 +1,78 @@
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)
@@ -0,0 +1,14 @@
1
+ Description:
2
+ ============
3
+ Stubs out a new cable channel for the server (in Ruby) and client (in CoffeeScript).
4
+ Pass the channel name, either CamelCased or under_scored, and an optional list of channel actions as arguments.
5
+
6
+ Note: Turn on the cable connection in app/assets/javascript/cable.coffee after generating any channels.
7
+
8
+ Example:
9
+ ========
10
+ rails generate channel Chat speak
11
+
12
+ creates a Chat channel class and CoffeeScript asset:
13
+ Channel: app/channels/chat_channel.rb
14
+ Assets: app/assets/javascript/channels/chat.coffee
@@ -0,0 +1,21 @@
1
+ module Rails
2
+ module Generators
3
+ class ChannelGenerator < NamedBase
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ argument :actions, type: :array, default: [], banner: "method method"
7
+
8
+ check_class_collision suffix: "Channel"
9
+
10
+ def create_channel_file
11
+ template "channel.rb", File.join('app/channels', class_path, "#{file_name}_channel.rb")
12
+ template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee")
13
+ end
14
+
15
+ protected
16
+ def file_name
17
+ @_file_name ||= super.gsub(/\_channel/i, '')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ App.<%= class_name.underscore %> = App.cable.subscriptions.create "<%= class_name %>Channel",
2
+ connected: ->
3
+ # Called when the subscription is ready for use on the server
4
+
5
+ disconnected: ->
6
+ # Called when the subscription has been terminated by the server
7
+
8
+ received: (data) ->
9
+ # Called when there's incoming data on the websocket for this channel
10
+ <% actions.each do |action| -%>
11
+
12
+ <%= action %>: ->
13
+ @perform '<%= action %>'
14
+ <% end -%>
@@ -0,0 +1,17 @@
1
+ # Be sure to restart your server when you modify this file. Action Cable runs in an EventMachine loop that does not support auto reloading.
2
+ <% module_namespacing do -%>
3
+ class <%= class_name %>Channel < ApplicationCable::Channel
4
+ def subscribed
5
+ # stream_from "some_channel"
6
+ end
7
+
8
+ def unsubscribed
9
+ # Any cleanup needed when channel is unsubscribed
10
+ end
11
+ <% actions.each do |action| -%>
12
+
13
+ def <%= action %>
14
+ end
15
+ <% end -%>
16
+ end
17
+ <% end -%>
metadata CHANGED
@@ -1,61 +1,195 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actioncable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 5.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
- - claudiob
7
+ - Pratik Naik
8
+ - David Heinemeier Hansson
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-04-21 00:00:00.000000000 Z
12
+ date: 2015-12-18 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
+ name: actionpack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 5.0.0.beta1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 5.0.0.beta1
28
+ - !ruby/object:Gem::Dependency
29
+ name: coffee-rails
15
30
  requirement: !ruby/object:Gem::Requirement
16
31
  requirements:
17
32
  - - "~>"
18
33
  - !ruby/object:Gem::Version
19
- version: '1.8'
20
- type: :development
34
+ version: 4.1.0
35
+ type: :runtime
21
36
  prerelease: false
22
37
  version_requirements: !ruby/object:Gem::Requirement
23
38
  requirements:
24
39
  - - "~>"
25
40
  - !ruby/object:Gem::Version
26
- version: '1.8'
41
+ version: 4.1.0
27
42
  - !ruby/object:Gem::Dependency
28
- name: rake
43
+ name: faye-websocket
29
44
  requirement: !ruby/object:Gem::Requirement
30
45
  requirements:
31
46
  - - "~>"
32
47
  - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
48
+ version: 0.10.0
49
+ type: :runtime
35
50
  prerelease: false
36
51
  version_requirements: !ruby/object:Gem::Requirement
37
52
  requirements:
38
53
  - - "~>"
39
54
  - !ruby/object:Gem::Version
40
- version: '10.0'
41
- description: This is Action Cable.
55
+ version: 0.10.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: websocket-driver
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 0.6.1
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.6.1
70
+ - !ruby/object:Gem::Dependency
71
+ name: celluloid
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 0.17.2
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 0.17.2
84
+ - !ruby/object:Gem::Dependency
85
+ name: em-hiredis
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 0.3.0
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 0.3.0
98
+ - !ruby/object:Gem::Dependency
99
+ name: redis
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '3.0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '3.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: puma
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: mocha
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ description: Structure many real-time application concerns into channels over a single
141
+ WebSocket connection.
42
142
  email:
43
- - claudiob@gmail.com
143
+ - pratiknaik@gmail.com
144
+ - david@loudthinking.com
44
145
  executables: []
45
146
  extensions: []
46
147
  extra_rdoc_files: []
47
148
  files:
48
- - ".gitignore"
49
- - Gemfile
50
- - LICENSE.txt
149
+ - CHANGELOG.md
150
+ - MIT-LICENSE
51
151
  - README.md
52
- - Rakefile
53
- - actioncable.gemspec
54
- - bin/console
55
- - bin/setup
56
152
  - lib/action_cable.rb
153
+ - lib/action_cable/channel.rb
154
+ - lib/action_cable/channel/base.rb
155
+ - lib/action_cable/channel/broadcasting.rb
156
+ - lib/action_cable/channel/callbacks.rb
157
+ - lib/action_cable/channel/naming.rb
158
+ - lib/action_cable/channel/periodic_timers.rb
159
+ - lib/action_cable/channel/streams.rb
160
+ - lib/action_cable/connection.rb
161
+ - lib/action_cable/connection/authorization.rb
162
+ - lib/action_cable/connection/base.rb
163
+ - lib/action_cable/connection/identification.rb
164
+ - lib/action_cable/connection/internal_channel.rb
165
+ - lib/action_cable/connection/message_buffer.rb
166
+ - lib/action_cable/connection/subscriptions.rb
167
+ - lib/action_cable/connection/tagged_logger_proxy.rb
168
+ - lib/action_cable/connection/web_socket.rb
169
+ - lib/action_cable/engine.rb
170
+ - lib/action_cable/gem_version.rb
171
+ - lib/action_cable/helpers/action_cable_helper.rb
172
+ - lib/action_cable/process/logging.rb
173
+ - lib/action_cable/remote_connections.rb
174
+ - lib/action_cable/server.rb
175
+ - lib/action_cable/server/base.rb
176
+ - lib/action_cable/server/broadcasting.rb
177
+ - lib/action_cable/server/configuration.rb
178
+ - lib/action_cable/server/connections.rb
179
+ - lib/action_cable/server/worker.rb
180
+ - lib/action_cable/server/worker/active_record_connection_management.rb
57
181
  - lib/action_cable/version.rb
58
- homepage: https://github.com/rails/actioncable
182
+ - lib/assets/javascripts/action_cable.coffee.erb
183
+ - lib/assets/javascripts/action_cable/connection.coffee
184
+ - lib/assets/javascripts/action_cable/connection_monitor.coffee
185
+ - lib/assets/javascripts/action_cable/consumer.coffee
186
+ - lib/assets/javascripts/action_cable/subscription.coffee
187
+ - lib/assets/javascripts/action_cable/subscriptions.coffee
188
+ - lib/rails/generators/channel/USAGE
189
+ - lib/rails/generators/channel/channel_generator.rb
190
+ - lib/rails/generators/channel/templates/assets/channel.coffee
191
+ - lib/rails/generators/channel/templates/channel.rb
192
+ homepage: http://rubyonrails.org
59
193
  licenses:
60
194
  - MIT
61
195
  metadata: {}
@@ -67,16 +201,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
201
  requirements:
68
202
  - - ">="
69
203
  - !ruby/object:Gem::Version
70
- version: '0'
204
+ version: 2.2.2
71
205
  required_rubygems_version: !ruby/object:Gem::Requirement
72
206
  requirements:
73
- - - ">="
207
+ - - ">"
74
208
  - !ruby/object:Gem::Version
75
- version: '0'
209
+ version: 1.3.1
76
210
  requirements: []
77
211
  rubyforge_project:
78
- rubygems_version: 2.4.5
212
+ rubygems_version: 2.5.1
79
213
  signing_key:
80
214
  specification_version: 4
81
- summary: Action Cable.
215
+ summary: WebSocket framework for Rails.
82
216
  test_files: []
217
+ has_rdoc:
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in actioncable.gemspec
4
- gemspec
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 claudiob
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
@@ -1,22 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'action_cable/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "actioncable"
8
- spec.version = ActionCable::VERSION
9
- spec.authors = ["claudiob"]
10
- spec.email = ["claudiob@gmail.com"]
11
- spec.summary = %q{Action Cable.}
12
- spec.description = %q{This is Action Cable.}
13
- spec.homepage = "https://github.com/rails/actioncable"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
19
-
20
- spec.add_development_dependency "bundler", "~> 1.8"
21
- spec.add_development_dependency "rake", "~> 10.0"
22
- end