aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable
Commit message (Collapse)AuthorAgeFilesLines
* Add ActionCable channel/connection load hooksVladimir Dementyev2019-01-293-0/+17
|
* Add CHANGELOG entries for npm package renames [ci skip]Javan Makhmali2019-01-281-0/+6
|
* Merge pull request #35021 from palkan/refactor/broadcasting-for-testingKasper Timm Hansen2019-01-246-19/+55
|\ | | | | Action Cable: move channel_name to Channel.broadcasting_for
| * fix fixture syntax in cable docs and guidesVladimir Dementyev2019-01-221-3/+3
| |
| * Add note about broadcast_to/broadcasting_for to change logVladimir Dementyev2019-01-222-1/+25
| |
| * Add Channel#broadcast_toVladimir Dementyev2019-01-222-2/+2
| |
| * Move `channel_name` to Channel.broadcasting_forVladimir Dementyev2019-01-224-14/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | That would allow us to test broadcasting made with channel, e.g.: ```ruby class ChatRelayJob < ApplicationJob def perform_later(room, msg) ChatChannel.broadcast_to room, message: msg end end ``` To test this functionality we need to know the underlying stream name (to use `assert_broadcasts`), which relies on `channel_name`. We had to use the following code: ```ruby assert_broadcasts(ChatChannel.broadcasting_for([ChatChannel.channel_name, room]), 1) do ChatRelayJob.perform_now end ``` The problem with this approach is that we use _internal_ API (we shouldn't care about `channel_name` prefix in our code). With this commit we could re-write the test as following: ```ruby assert_broadcasts(ChatChannel.broadcasting_for(room), 1) do ChatRelayJob.perform_now end ```
* | Fix attribute typo in ActionCable connection test requestSergey Ponomarev2019-01-231-2/+0
|/
* Preparing for 6.0.0.beta1 releaseRafael Mendonça França2019-01-183-2/+4
|
* Merge pull request #34959 from alkesh26/action-cable-typo-fixesRafael França2019-01-183-3/+3
|\ | | | | Typo fixes in action cable.
| * typo fixes in action cablealkesh262019-01-173-3/+3
| |
* | Merge pull request #34941 from rmacklin/allow-actioncable-to-run-in-web-workersJavan Makhmali2019-01-164-12/+12
|\ \ | | | | | | Avoid ReferenceError exceptions if ActionCable is used in a web worker
| * | Remove explicit `document` receiver from add/removeEventListener callsRichard Macklin2019-01-152-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows ActionCable to be used in a web worker, where the `document` global is undefined. Previously, attempting to use ActionCable inside a web worker would result in this exception after you try to open a connection: ``` ReferenceError: document is not defined ``` The visibilitychange event won't ever get triggered in a worker, so adding the listener is effectively a no-op there. But the listener is mainly a convenience, rather than a critical piece of the javascript interface, so using ActionCable in a worker will still work. (And you could listen for visibilitychange yourself in a window script, then tell the worker to reconnect if you still want that behavior.)
| * | Replace `window` references in ActionCable with `self`Richard Macklin2019-01-143-8/+8
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change, attempting to use ActionCable inside a web worker would result in an exception being thrown: ``` ReferenceError: window is not defined ``` By replacing the `window` reference with `self`, which is available in both a window context and a worker context, we can avoid this error. Ref: https://developer.mozilla.org/en-US/docs/Web/API/Window/self
* / Remove `frozen_string_literal` from Action Cable's template filesbogdanvlviv2019-01-161-2/+0
|/ | | | | | Related to 837f602fa1b3281113dac965a8ef96de3cac8b02 Fix the testing guide.
* Merge pull request #34934 from ↵Rafael França2019-01-143-16/+19
|\ | | | | | | | | rmacklin/simplify-actioncable-methods-after-decaffeination Clean up ActionCable JS a bit more after the CoffeeScript conversion
| * Simplify `this.isActive() && this.webSocket` into `this.isActive()`Richard Macklin2019-01-142-2/+2
| | | | | | | | | | | | | | | | | | in Connection#close. We can do this because `isActive()` can only return `true` if `this.webSocket` is truthy. (We can't have an active connection without having instantiated a WebSocket. This is confirmed in the code: Connection#isActive calls Connection#isState which calls Connection#getState, which checks if `this.webSocket` is truthy and returns `null` otherwise.)
| * Simplify ActionCable.getConfig, Connection#getProtocol, and Connection#closeRichard Macklin2019-01-143-7/+17
| | | | | | | | by relying on the implicit undefined return value
| * Simplify ActionCable.createConsumer by using default argumentRichard Macklin2019-01-142-10/+3
| |
* | Add Action Cable Testing guidesVladimir Dementyev2019-01-142-1/+5
| |
* | Add channel test generatorVladimir Dementyev2019-01-134-1/+34
|/
* Update Action Cable connection testing.Kasper Timm Hansen2019-01-142-57/+57
| | | | | | | | | | | | | | | * Don't reimplement assert_raises Also test what happens in case there's no explicit rejection. * Avoid OpenStruct. Remove space beneath private. * Simplify verification methods for code under test. * Match documentation with other Rails docs. Also remove mention of the custom path argument for now. Unsure how useful that really is.
* Merge pull request #34930 from ↵Ryuta Kamizono2019-01-141-544/+1
|\ | | | | | | | | bogdanvlviv/merge-actioncable-README.md-to-the-guide Merge `actioncable/README.md` to the Action Cable Overview guide [ci skip]
| * Merge `actioncable/README.md` to the Action Cable Overview guide [ci skip]bogdanvlviv2019-01-131-544/+1
| | | | | | | | | | | | | | | | | | | | | | | | In #34709 we updated the guide, but `actioncable/README.md` is still outdated. Instead of fixing content in the file. I suggest not duplicate the info that is already in the guide and instead remove the info from the file and just add a message: "You can read more about Action Cable in the [Action Cable Overview](https://edgeguides.rubyonrails.org/action_cable_overview.html) guide." The same approach is being used for Action Mailbox and Action Text, see #34812 and #34878.
* | Merge pull request #34845 from palkan/feature/action-cable-connection-testingKasper Timm Hansen2019-01-133-0/+434
|\ \ | |/ |/| Add ActionCable::Connection::TestCase
| * feature: add ActionCable::Connection::TestCaseVladimir Dementyev2019-01-023-0/+434
| |
* | Move all npm packages to @rails scopeJavan Makhmali2019-01-103-5/+5
| | | | | | | | Fixes #33083
* | Revert "Revert "Merge pull request #34387 from ↵Kasper Timm Hansen2019-01-081-0/+3
| | | | | | | | | | | | | | | | yhirano55/rails_info_properties_json"" I reverted the wrong commit. Damn it. This reverts commit f66a977fc7ae30d2a07124ad91924c4ee638a703.
* | Revert "Merge pull request #34387 from yhirano55/rails_info_properties_json"Kasper Timm Hansen2019-01-081-3/+0
|/ | | | | | | | | | | We had a discussion on the Core team and we don't want to expose this information as a JSON endpoint and not by default. It doesn't make sense to expose this JSON locally and this controller is only accessible in dev, so the proposed access from a production app seems off. This reverts commit 8eaffe7e89719ac62ff29c2e4208cfbeb1cd1c38, reversing changes made to b6e4305c3bca4c673996d0af9db0f4cfbf50215e.
* Merge pull request #34831 from arunagw/bump-year-to-2019Arun Agrawal2018-12-312-2/+2
|\ | | | | Bump license years for 2019
| * Bump license years for 2019Arun Agrawal2018-12-312-2/+2
| |
* | Merge pull request #34740 from sponomarev/feature/assert_has_streamGeorge Claghorn2018-12-312-6/+73
|\ \ | |/ |/| Add streams assert methods to ActionCable channel test case
| * Add streams assert methods to ActionCable channel test caseSergey Ponomarev2018-12-182-6/+73
| |
* | Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-213-104/+90
| | | | | | | | | | | | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* | Require Ruby 2.5 for Rails 6.Kasper Timm Hansen2018-12-192-3/+3
|/ | | | | | | | | | Generally followed the pattern for https://github.com/rails/rails/pull/32034 * Removes needless CI configs for 2.4 * Targets 2.5 in rubocop * Updates existing CHANGELOG entries for fewer merge conflicts * Removes Hash#slice extension as that's inlined on Ruby 2.5. * Removes the need for send on define_method in MethodCallAssertions.
* Add Missing ActiveSupport::Rescuable to ActionCable::ChannelIlia Kasianenko2018-12-122-1/+21
| | | | [timthez, Ilia Kasianenko]
* Stop trying to reconnect on unauthorized cable connectionsMick Staugaard2018-12-059-10/+46
|
* Add missing authorship to ActionCable changelog entryRichard Macklin2018-12-021-0/+2
| | | | | I accidentally forgot to add the author line to my changelog entry from 2bb4fdef5efc70327c018e982ff809a29ac6708b
* Merge pull request #34590 from rmacklin/use-websocket-adapter-in-getStateJavan Makhmali2018-12-025-4/+37
|\ | | | | Replace reference to WebSocket global with ActionCable.adapters.WebSocket
| * Replace reference to WebSocket global with ActionCable.adapters.WebSocketRichard Macklin2018-12-015-4/+37
| | | | | | | | | | | | | | | | | | | | The WebSocket dependency of ActionCable.Connection was made configurable in 66901c1849efae74c8a58fe0cb36afd487c067cc However, the reference here in Connection#getState was not updated to use the configurable property. This change remedies that and adds a test to verify it. Additionally, it backfills a test to ensure that Connection#open uses the configurable property.
* | Remove obsolete yarn.lock files and check in root yarn.lock fileRichard Macklin2018-12-021-4053/+0
|/
* Remove circular dependency warnings in ActionCable javascript and publish ↵rmacklin2018-12-0115-289/+324
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | source modules with fine-grained exports (#34370) * Replace several ActionCable.* references with finer-grained imports This reduces the number of circular dependencies among the module imports from 4: ``` (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/connection.js -> app/javascript/action_cable/index.js (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/connection_monitor.js -> app/javascript/action_cable/index.js (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/consumer.js -> app/javascript/action_cable/index.js (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/subscriptions.js -> app/javascript/action_cable/index.js ``` to 2: ``` (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/connection.js -> app/javascript/action_cable/index.js (!) Circular dependency: app/javascript/action_cable/index.js -> app/javascript/action_cable/connection.js -> app/javascript/action_cable/connection_monitor.js -> app/javascript/action_cable/index.js ``` * Remove tests that only test javascript object property assignment These tests really only assert that you can assign a property to the ActionCable global object. That's true for pretty much any object in javascript (it would only be false if the object has been frozen, or has explicitly set some properties to be nonconfigurable). * Refactor ActionCable to provide individual named exports By providing individual named exports rather than a default export which is an object with all of those properties, we enable applications to only import the functions they need: any unused functions will be removed via tree shaking. Additionally, this restructuring removes the remaining circular dependencies by extracting the separate adapters and logger modules, so there are now no warnings when compiling the ActionCable bundle. Note: This produces two small breaking API changes: - The `ActionCable.WebSocket` getter and setter would be moved to `ActionCable.adapters.WebSocket`. If a user is currently configuring this, when upgrading they'd need to either add a delegated getter/setter themselves, or change it like this: ```diff - ActionCable.WebSocket = MyWebSocket + ActionCable.adapters.WebSocket = MyWebSocket ``` Applications which don't change the WebSocket adapter would not need any changes for this when upgrading. - Similarly, the `ActionCable.logger` getter and setter would be moved to `ActionCable.adapters.logger`. If a user is currently configuring this, when upgrading they'd need to either add a delegated getter/setter themselves, or change it like this: ```diff - ActionCable.logger = myLogger + ActionCable.adapters.logger = myLogger ``` Applications which don't change the logger would not need any changes for this when upgrading. These two aspects of the public API have to change because there's no way to export a property setter for `WebSocket` (or `logger`) such that this: ```js import ActionCable from "actioncable" ActionCable.WebSocket = MyWebSocket ``` would actually update `adapters.WebSocket`. (We can only offer that if we have two separate source files like if `index.js` uses `import * as ActionCable from "./action_cable" and then exports a wrapper which has delegated getters and setters for those properties.) This API change is very minor - it should be easy for applications to add the `adapters.` prefix in their assignments or to patch in delegated setters. And especially because most applications in the wild are not ever changing the default value of `ActionCable.WebSocket` or `ActionCable.logger` (because the default values are perfect), this API breakage is worth the tree-shaking benefits we gain. * Include source code in published actioncable npm package This allows actioncable users to ship smaller javascript bundles to visitors using modern browsers, as demonstrated in this repository: https://github.com/rmacklin/actioncable-es2015-build-example In that example, the bundle shrinks by 2.8K (25.2%) when you simply change the actioncable import to point to the untranspiled src. If you go a step further, like this: ``` diff --git a/app/scripts/main.js b/app/scripts/main.js index 17bc031..1a2b2e0 100644 --- a/app/scripts/main.js +++ b/app/scripts/main.js @@ -1,6 +1,6 @@ -import ActionCable from 'actioncable'; +import * as ActionCable from 'actioncable'; let cable = ActionCable.createConsumer('wss://cable.example.com'); cable.subscriptions.create('AppearanceChannel', { ``` then the bundle shrinks by 3.6K (31.7%)! In addition to allowing smaller bundles for those who ship untranspiled code to modern browsers, including the source code in the published package can be useful in other ways: 1. Users can import individual modules rather than the whole library 2. As a result of (1), users can also monkey patch parts of actioncable by importing the relevant module, modifying the exported object, and then importing the rest of actioncable (which would then use the patched object). Note: This is the same enhancement that we made to activestorage in c0368ad090b79c19300a4aa133bb188b2d9ab611 * Remove unused commonjs & resolve plugins from ActionCable rollup config These were added when we copied the rollup config from ActiveStorage, but ActionCable does not have any commonjs dependencies (it doesn't have any external dependencies at all), so these plugins are unnecessary here * Change ActionCable.startDebugging() -> ActionCable.logger.enabled=true and ActionCable.stopDebugging() -> ActionCable.logger.enabled=false This API is simpler and more clearly describes what it does * Change Travis configuration to run yarn install at the root for ActionCable builds This is necessary now that the repository is using Yarn Workspaces
* Convert ActionCable tests from CoffeeScript to ES2015 and replace Blade with ↵rmacklin2018-11-2622-4778/+2479
| | | | | | | | | | | | | | | | | | | | | | | | Karma and Rollup (#34440) * Rename .coffee files in ActionCable test suite in prep for decaffeination * Decaffeinate ActionCable tests * Replace Blade with Karma and Rollup to run ActionCable JS tests - Add karma and qunit devDependencies - Add test script to ActionCable package - Use rollup to bundle ActionCable tests - Use karma as the ActionCable JS test runner * Replace vendored mock-socket with package devDependency in ActionCable * Move ActionCable yarn install to TravisCI before_install config * Clean up decaffeinated ActionCable tests to use consistent formatting
* Synchronize ActionCable JS source code with compiled bundleRichard Macklin2018-11-161-3/+4
| | | | | | | | 30a0c7e04093add0b14be6da17c7496e7dd40e10 commited changes to the compiled bundle but not to the corresponding source files. This meant that running `yarn build` was producing untracked changes to the compiled bundle. The fix is to commit the changes to the source files so that they are in sync.
* Allow patching polling interval logarithmic multiplierHusam Bilal2018-11-141-3/+4
|
* Amend CVE note and security guide section wordingsGannon McGibbon2018-11-061-3/+3
| | | | | | | Reword first sentence of dep management and CVE section of security guide. Also, reword and move gemspec notes above deps. [ci skip]
* Add CVE note to security guide and gemspecsGannon McGibbon2018-11-061-0/+3
| | | | [ci skip]
* Convert ActionCable javascript to ES2015 modules with modern build environmentRichard Macklin2018-11-0216-302/+2748
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We've replaced the sprockets `//= require` directives with ES2015 imports. As a result, the ActionCable javascript can now be compiled with rollup (like ActiveStorage already is). - Rename action_cable/index.js.erb -> action_cable/index.js - Add rake task to generate a javascript module of the ActionCable::INTERNAL ruby hash This will allow us to get rid of ERB from the actioncable javascript, since it is only used to interpolate ActionCable::INTERNAL.to_json. - Import INTERNAL directly in ActionCable Connection module This is necessary to remove a load-order dependency conflict in the rollup-compiled build. Using ActionCable.INTERNAL would result in a runtime error: ``` TypeError: Cannot read property 'INTERNAL' of undefined ``` because ActionCable.INTERNAL is not set before the Connection module is executed. All other ActionCable.* references are executed inside of the body of a function, so there is no load-order dependency there. - Add eslint and eslint-plugin-import devDependencies to actioncable These will be used to add a linting setup to actioncable like the one in activestorage. - Add .eslintrc to actioncable This lint configuration was copied from activestorage - Add lint script to actioncable This is the same as the lint script in activestorage - Add babel-core, babel-plugin-external-helpers, and babel-preset-env devDependencies to actioncable These will be used to add ES2015 transpilation support to actioncable like we have in activestorage. - Add .babelrc to actioncable This configuration was copied from activestorage - Enable loose mode in ActionCable's babel config This generates a smaller bundle when compiled - Add rollup devDependencies to actioncable These will be used to add a modern build pipeline to actioncable like the one in activestorage. - Add rollup config to actioncable This is essentially the same as the rollup config from activestorage - Add prebuild and build scripts to actioncable package These scripts were copied from activestorage - Invoke code generation task as part of actioncable's prebuild script This will guarantee that the action_cable/internal.js module is available at build time (which is important, because two other modules now depend on it). - Update actioncable package to reference the rollup-compiled files Now that we have a fully functional rollup pipeline in actioncable, we can use the compiled output in our npm package. - Remove build section from ActionCable blade config Now that rollup is responsible for building ActionCable, we can remove that responsibility from Blade. - Remove assets:compile and assets:verify tasks from ActionCable Now that we've added a compiled ActionCable bundle to version control, we don't need to compile and verify it at publish-time. (We're following the pattern set in ActiveStorage.) - Include compiled ActionCable javascript bundle in published gem This is necessary to maintain support for depending on the ActionCable javascript through the Sprockets asset pipeline. - Add compiled ActionCable bundle to version control This mirrors what we do in ActiveStorage, and allows ActionCable to continue to be consumed via the sprockets-based asset pipeline when using a git source instead of a published version of the gem.
* Refactor decaffeinate output to more natural/idiomatic javascriptRichard Macklin2018-11-026-279/+228
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Remove unnecessary Array.from usages from subscriptions.js These were all Arrays before, so Array.from is a no-op - Remove unnecessary IIFEs from subscriptions.js - Manually decaffeinate sample ActionCable code in comments Here the coffeescript -> ES2015 conversion was done by hand rather than using decaffeinate, because these code samples were simple enough. - Refactor ActionCable.Subscription to avoid initClass - Refactor ActionCable.Subscription to use ES2015 default parameters - Refactor ActionCable.ConnectionMonitor to avoid initClass - Refactor ActionCable.ConnectionMonitor to use shorter variations of null checks - Remove unnecessary code created because of implicit returns in ConnectionMonitor This removes the `return` statements that were returning the value of console.log and those from private methods whose return value was not being used. - Refactor ActionCable.Connection to avoid initClass - Refactor Connection#isProtocolSupported and #isState This addresses these three decaffeinate cleanup suggestions: - DS101: Remove unnecessary use of Array.from - DS104: Avoid inline assignments - DS204: Change includes calls to have a more natural evaluation order It also removes the use of Array.prototype.includes, which means we don't have to worry about providing a polyfill or requiring that end users provide one. - Refactor ActionCable.Connection to use ES2015 default parameters - Refactor ActionCable.Connection to use shorter variations of null checks - Remove return statements that return the value of console.log() in ActionCable.Connection - Simplify complex destructure assignment in connection.js decaffeinate had inserted ``` adjustedLength = Math.max(protocols.length, 1) ``` to be safe, but we know that there has to always be at least one protocol, so we don't have to worry about protocols.length being 0 here. - Refactor Connection#getState The decaffeinate translation of this method was not very clear, so we've rewritten it to be more natural. - Simplify destructure assignment in connection.js - Remove unnecessary use of Array.from from action_cable.js.erb - Refactor ActionCable#createConsumer and #getConfig This addresses these two decaffeinate cleanup suggestions: - DS104: Avoid inline assignments - DS207: Consider shorter variations of null checks - Remove unnecessary code created because of implicit returns in action_cable.js.erb This removes the `return` statements that were returning the value of console.log and those from methods that just set and unset the `debugging` flag. - Remove decaffeinate suggestion about avoiding top-level this In this case, the top-level `this` is intentional, so it's okay to ignore this suggestion. - Remove decaffeinate suggestions about removing unnecessary returns I did remove some of the return statements in previous commits, where it seemed appropriate. However, the rest of these should probably remain because the return values have been exposed through the public API. If we want to break that contract, we can do so, but I think it should be done deliberately as part of a breaking-API change (separate from this coffeescript -> ES2015 conversion) - Remove unused `unsupportedProtocol` variable from connection.js Leaving this would cause eslint to fail - Refactor Subscriptions methods to avoid `for` ... `of` syntax Babel transpiles `for` ... `of` syntax to use `Symbol.iterator`, which would require a polyfill in applications that support older browsers. The `for` ... `of` syntax was produced by running `decaffeinate`, but in these instances a simpler `map` should be sufficient and avoid any `Symbol` issues.
* Run decaffeinate on action_cable/*.jsRichard Macklin2018-11-026-401/+581
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using [decaffeinate], we have converted these files from coffeescript syntax to ES2015 syntax. Decaffeinate is very conservative in the conversion process to ensure exact coffeescript semantics are preserved. Most of the time, it's safe to clean up the code, and decaffeinate has left suggestions regarding potential cleanups we can take. I'll tackle those cleanups separately. After running decaffeinate, I ran: ``` eslint --fix app/javascript ``` using the eslint configuration from ActiveStorage to automatically correct lint violations in the decaffeinated output. This removed 189 extra semicolons and changed one instance of single quotes to double quotes. Note: decaffeinate and eslint can't parse ERB syntax. So I worked around that by temporarily quoting the ERB: ```diff @ActionCable = - INTERNAL: <%= ActionCable::INTERNAL.to_json %> + INTERNAL: "<%= ActionCable::INTERNAL.to_json %>" WebSocket: window.WebSocket logger: window.console ``` and then removing those quotes after running decaffeinate and eslint. [decaffeinate]: https://github.com/decaffeinate/decaffeinate