@@ -458,6 +458,74 @@ with all the popular application servers -- Unicorn, Puma and Passenger.
458
458
Action Cable does not work with WEBrick, because WEBrick does not support the
459
459
Rack socket hijacking API.
460
460
461
+ ## Frontend assets
462
+
463
+ Action Cable's frontend assets are distributed through two channels: the
464
+ official gem and npm package, both titled ` actioncable ` .
465
+
466
+ ### Gem usage
467
+
468
+ Through the ` actioncable ` gem, Action Cable's frontend assets are
469
+ available through the Rails Asset Pipeline. Create a ` cable.js ` or
470
+ ` cable.coffee ` file (this is automatically done for you with Rails
471
+ generators), and then simply require the assets:
472
+
473
+ In JavaScript...
474
+
475
+ ``` javascript
476
+ // = require action_cable
477
+ ```
478
+
479
+ ... and in CoffeeScript:
480
+
481
+ ``` coffeescript
482
+ # = require action_cable
483
+ ```
484
+
485
+ ### npm usage
486
+
487
+ In addition to being available through the ` actioncable ` gem, Action Cable's
488
+ frontend JS assets are also bundled in an officially supported npm module,
489
+ intended for usage in standalone frontend applications that communicate with a
490
+ Rails application. A common use case for this could be if you have a decoupled
491
+ frontend application written in React, Ember.js, etc. and want to add real-time
492
+ WebSocket functionality.
493
+
494
+ ### Installation
495
+
496
+ ```
497
+ npm install actioncable --save
498
+ ```
499
+
500
+ ### Usage
501
+
502
+ The ` ActionCable ` constant is available as a ` require ` -able module, so
503
+ you only have to require the package to gain access to the API that is
504
+ provided.
505
+
506
+ In JavaScript...
507
+
508
+ ``` javascript
509
+ ActionCable = require (' actioncable' )
510
+
511
+ var cable = ActionCable .createConsumer (' wss://RAILS-API-PATH.com/cable' )
512
+
513
+ cable .subscriptions .create (' AppearanceChannel' , {
514
+ // normal channel code goes here...
515
+ });
516
+ ```
517
+
518
+ and in CoffeeScript...
519
+
520
+ ``` coffeescript
521
+ ActionCable = require (' actioncable' )
522
+
523
+ cable = ActionCable .createConsumer (' wss://RAILS-API-PATH.com/cable' )
524
+
525
+ cable .subscriptions .create ' AppearanceChannel' ,
526
+ # normal channel code goes here...
527
+ ```
528
+
461
529
## License
462
530
463
531
Action Cable is released under the MIT license:
0 commit comments