# ember-cable

> Power your ember.js application with actioncable

Latest version **0.8.1** (published 2018-05-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install ember-cable
pnpm add ember-cable
yarn add ember-cable
bun add ember-cable
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.8.1 |
| Published | 2018-05-23 |
| First published | 2015-12-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ^4.5 \|\| 6.* \|\| >= 7.* |
| Dependencies | 1 |
| Unpacked size | 479.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 93 |
| Author | Salvatore Ferrucci |
| Maintainers | safeforge |
| Keywords | ember-addon, ember-cli, ember, node, realtime, websocket, actioncable, rails |

## Links

- npm: https://www.npmjs.com/package/ember-cable
- Repository: https://github.com/algonauti/ember-cable
- Homepage: https://github.com/algonauti/ember-cable#readme
- Issues: https://github.com/algonauti/ember-cable/issues
- npm.io page: https://npm.io/package/ember-cable

## Dependencies (1)

- [ember-cli-babel](https://npm.io/package/ember-cli-babel.md) ^6.6.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.8.1 (latest) — 2018-05-23
- 0.8.0 — 2018-05-22
- 0.7.0 — 2018-03-29
- 0.6.3 — 2018-03-17
- 0.6.2 — 2017-11-04
- 0.6.1 — 2017-03-14
- 0.6.0 — 2017-02-25
- 0.5.0 — 2016-06-26
- 0.4.3 — 2016-06-05
- 0.4.2 — 2016-06-05
- 0.4.1 — 2016-05-31
- 0.4.0 — 2016-05-09
- 0.3.0 — 2016-04-20
- 0.2.2 — 2016-03-07
- 0.2.1 — 2016-03-07
- … 5 more at https://npm.io/package/ember-cable/versions

## README

# ember-cable

This add-on enables simple integration of Rails Action Cable into Ember apps.

[![Build Status](https://travis-ci.org/algonauti/ember-cable.svg?branch=master)](https://travis-ci.org/algonauti/ember-cable)
[![Ember Observer Score](https://emberobserver.com/badges/ember-cable.svg)](https://emberobserver.com/addons/ember-cable)

### Installation
run the following command from inside your ember-cli project:

    ember install ember-cable

## Basic Usage

Once the addon is installed, the cable service can be injected wherever
needed in the application.

```js
// app/controllers/application.js
import Ember from 'ember';

export default Ember.Controller.extend({
  cableService: Ember.inject.service('cable'),
  consumer: null,

  setupConsumer: Ember.on('init', function() {
    var consumer = this.get('cableService').createConsumer('ws://localhost:4200/cable');

    consumer.subscriptions.create("NotificationChannel", {
      connected() {
        this.perform('hello', { foo: 'bar' });
        this.perform('hello');
      },
      received(data) {
        Ember.debug( "received(data) -> " + Ember.inspect(data) );
      },
      disconnected() {
        Ember.debug("NotificationChannel#disconnected");
      }
    });

    // Passing Parameters to Channel
    const subscription = consumer.subscriptions.create({ channel: 'NotificationChannel', room: 'Best Room' }, {
      received: (data) => {
        this.updateRecord(data);
      }
    });

    // Using mixin and inject your services
    var channelMixin = Ember.Mixin.create({
      store: Ember.inject.service(),

      received(data) {
        this.get("store").pushPayload(data);
      }
    });

    consumer.subscriptions.create({ channel: 'NotificationChannel' }, channelMixin);

    // Send actions to your Action Cable channel class
    subscription.perform("your_channel_action", { hey: "hello" });

    // Save consumer to controller to link up computed props
    this.set('consumer', consumer);
  }),

  updateRecord(data) {
    Ember.debug( "updateRecord(data) -> " + Ember.inspect(data) );
  },

  // Flag indicating a connection is being attempted
  isConnecting: Ember.computed.readOnly('consumer.isConnecting'),

  // Milliseconds until the next connection attempt
  nextConnectionAt: Ember.computed.readOnly('consumer.nextConnectionAt'),
});

```

## License

ember-cable is released under the [MIT License](http://www.opensource.org/licenses/MIT).

---
_Source: https://npm.io/package/ember-cable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
