diff options
Diffstat (limited to 'actioncable')
-rw-r--r-- | actioncable/CHANGELOG.md | 5 | ||||
-rw-r--r-- | actioncable/README.md | 28 | ||||
-rw-r--r-- | actioncable/lib/action_cable/connection/base.rb | 9 | ||||
-rw-r--r-- | actioncable/lib/action_cable/connection/subscriptions.rb | 1 | ||||
-rw-r--r-- | actioncable/lib/rails/generators/channel/channel_generator.rb | 7 |
5 files changed, 26 insertions, 24 deletions
diff --git a/actioncable/CHANGELOG.md b/actioncable/CHANGELOG.md index 64aea88588..22126d82b7 100644 --- a/actioncable/CHANGELOG.md +++ b/actioncable/CHANGELOG.md @@ -1,8 +1,5 @@ ## Rails 5.0.0.beta1 (December 18, 2015) ## -* No changes. - - * Added to Rails! - *DHH*
\ No newline at end of file + *DHH* diff --git a/actioncable/README.md b/actioncable/README.md index 823964343a..c7420d48bc 100644 --- a/actioncable/README.md +++ b/actioncable/README.md @@ -1,4 +1,4 @@ -# Action Cable –- Integrated WebSockets for Rails +# Action Cable – Integrated WebSockets for Rails Action Cable seamlessly integrates WebSockets with the rest of your Rails application. It allows for real-time features to be written in Ruby in the same style @@ -16,7 +16,7 @@ WebSockets open to your application if they use multiple browser tabs or devices The client of a WebSocket connection is called the consumer. Each consumer can in turn subscribe to multiple cable channels. Each channel encapsulates -a logical unit of work, similar to what a controller does in a regular MVC setup. For example, +a logical unit of work, similar to what a controller does in a regular MVC setup. For example, you could have a `ChatChannel` and a `AppearancesChannel`, and a consumer could be subscribed to either or to both of these channels. At the very least, a consumer should be subscribed to one channel. @@ -91,7 +91,7 @@ The client-side needs to setup a consumer instance of this connection. That's do #= require action_cable @App = {} -App.cable = Cable.createConsumer("ws://cable.example.com") +App.cable = ActionCable.createConsumer("ws://cable.example.com") ``` The ws://cable.example.com address must point to your set of Action Cable servers, and it @@ -364,7 +364,7 @@ Then add the following line to your layout before your JavaScript tag: And finally, create your consumer like so: ```coffeescript -App.cable = Cable.createConsumer() +App.cable = ActionCable.createConsumer() ``` For a full list of all configuration options, see the `ActionCable::Server::Configuration` class. @@ -395,20 +395,20 @@ bundle exec puma -p 28080 cable/config.ru ``` The above will start a cable server on port 28080. Remember to point your client-side setup against that using something like: -`App.cable = Cable.createConsumer("ws://basecamp.dev:28080")`. +`App.cable = ActionCable.createConsumer("ws://basecamp.dev:28080")`. ### In app -If you are using a threaded server like Puma or Thin, the current implementation of ActionCable can run side-along with your Rails application. For example, to listen for WebSocket requests on `/websocket`, match requests on that path: +If you are using a threaded server like Puma or Thin, the current implementation of ActionCable can run side-along with your Rails application. For example, to listen for WebSocket requests on `/cable`, mount the server at that path: ```ruby # config/routes.rb Example::Application.routes.draw do - match "/websocket", :to => ActionCable.server, via: [:get, :post] + mount ActionCable.server => '/cable' end ``` -You can use `App.cable = Cable.createConsumer("/websocket")` to connect to the cable server. +You can use `App.cable = ActionCable.createConsumer()` to connect to the cable server if `action_cable_meta_tag` is included in the layout. A custom path is specified as first argument to `createConsumer` (e.g. `App.cable = ActionCable.createConsumer("/websocket")`). For every instance of your server you create and for every worker your server spawns, you will also have a new instance of ActionCable, but the use of Redis keeps messages synced across connections. @@ -452,6 +452,14 @@ Action Cable is released under the MIT license: ## Support -Bug reports can be filed for the alpha development project here: +API documentation is at: -* https://github.com/rails/actioncable/issues +* http://api.rubyonrails.org + +Bug reports can be filed for the Ruby on Rails project here: + +* https://github.com/rails/rails/issues + +Feature requests should be discussed on the rails-core mailing list here: + +* https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core diff --git a/actioncable/lib/action_cable/connection/base.rb b/actioncable/lib/action_cable/connection/base.rb index f7b18a85ae..977856d656 100644 --- a/actioncable/lib/action_cable/connection/base.rb +++ b/actioncable/lib/action_cable/connection/base.rb @@ -48,11 +48,9 @@ module ActionCable include InternalChannel include Authorization - attr_reader :server, :env, :subscriptions + attr_reader :server, :env, :subscriptions, :logger delegate :worker_pool, :pubsub, to: :server - attr_reader :logger - def initialize(server, env) @server, @env = server, env @@ -123,7 +121,6 @@ module ActionCable transmit ActiveSupport::JSON.encode(identifier: ActionCable::INTERNAL[:identifiers][:ping], message: Time.now.to_i) end - protected # The request that initiated the WebSocket connection is available here. This gives access to the environment, cookies, etc. def request @@ -138,8 +135,6 @@ module ActionCable request.cookie_jar end - - protected attr_reader :websocket attr_reader :message_buffer @@ -170,7 +165,6 @@ module ActionCable disconnect if respond_to?(:disconnect) end - def allow_request_origin? return true if server.config.disable_request_forgery_protection @@ -193,7 +187,6 @@ module ActionCable [ 404, { 'Content-Type' => 'text/plain' }, [ 'Page not found' ] ] end - # Tags are declared in the server but computed in the connection. This allows us per-connection tailored tags. def new_tagged_logger TaggedLoggerProxy.new server.logger, diff --git a/actioncable/lib/action_cable/connection/subscriptions.rb b/actioncable/lib/action_cable/connection/subscriptions.rb index 65d6634bb0..d7f95e6a62 100644 --- a/actioncable/lib/action_cable/connection/subscriptions.rb +++ b/actioncable/lib/action_cable/connection/subscriptions.rb @@ -49,7 +49,6 @@ module ActionCable find(data).perform_action ActiveSupport::JSON.decode(data['data']) end - def identifiers subscriptions.keys end diff --git a/actioncable/lib/rails/generators/channel/channel_generator.rb b/actioncable/lib/rails/generators/channel/channel_generator.rb index 2f37d8055b..c5d398810a 100644 --- a/actioncable/lib/rails/generators/channel/channel_generator.rb +++ b/actioncable/lib/rails/generators/channel/channel_generator.rb @@ -5,11 +5,16 @@ module Rails argument :actions, type: :array, default: [], banner: "method method" + class_option :assets, type: :boolean + check_class_collision suffix: "Channel" def create_channel_file template "channel.rb", File.join('app/channels', class_path, "#{file_name}_channel.rb") - template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee") + + if options[:assets] + template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee") + end end protected |