actioncable-nodejs

1.0.4 • Public • Published

actioncable-nodejs

ActionCable NodeJS client Implementation.

Getting Started

npm install actioncable-nodejs --save

const ActionCable = require('./actioncable/actioncable.js');

let cable_url = 'ws://localhost:3000/cable';

let cable = new ActionCable(cable_url, {
  // If you validate the origin on the server, you can set that here
  origin: 'http://localhost:3000',

  // Using headers with an API key for auth is recommended
  // because we dont have the normal browser session to authenticate with
  headers: {
    'X-Api-Key': 'someexampleheader'
  }
});

let subscription = cable.subscribe('RouterTestAgentChannel', {
  connected() {
    console.log("connected");
  },

  disconnected() {
    console.log("disconnected");
  },

  rejected() {
    console.log("rejected");
  },

  received(data) {
    console.log("received");
    console.log(data);
  }
});

// Send a message to the server
subscription.perform("command_processed", {foo: 'bar'});

Package Sidebar

Install

npm i actioncable-nodejs

Weekly Downloads

9

Version

1.0.4

License

MIT

Unpacked Size

5.94 kB

Total Files

4

Last publish

Collaborators

  • zackmattor