{"id":15064600,"url":"https://github.com/eacaps/es6-actioncable","last_synced_at":"2025-04-10T12:22:45.222Z","repository":{"id":57239511,"uuid":"44386391","full_name":"eacaps/es6-actioncable","owner":"eacaps","description":"Port of actioncable code to ES6 and nodized it","archived":false,"fork":false,"pushed_at":"2018-04-26T00:03:44.000Z","size":82,"stargazers_count":28,"open_issues_count":2,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-24T11:11:17.747Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eacaps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-16T13:20:11.000Z","updated_at":"2020-04-16T15:17:54.000Z","dependencies_parsed_at":"2022-08-29T22:22:27.554Z","dependency_job_id":null,"html_url":"https://github.com/eacaps/es6-actioncable","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eacaps%2Fes6-actioncable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eacaps%2Fes6-actioncable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eacaps%2Fes6-actioncable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eacaps%2Fes6-actioncable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eacaps","download_url":"https://codeload.github.com/eacaps/es6-actioncable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217112,"owners_count":21066633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-25T00:22:17.119Z","updated_at":"2025-04-10T12:22:45.199Z","avatar_url":"https://github.com/eacaps.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# es6-actioncable\nThis module is a port of the rails/actioncable coffeescript code to ES6 and nodized it. For more info on actioncable, check out their github page - https://github.com/rails/actioncable.\n\n## Usage\nHere is a sample of what I have in my application.\n\nWebsocket.js\n\n    import Cable from 'es6-actioncable';\n\n    class Websocket {\n      constructor() {\n      }\n\n      connect() {\n        console.log('connecting websocket');\n        this.consumer = Cable.createConsumer(WEBSOCKET_URL);\n      }\n\n      getConsumer() {\n        if(!this.consumer) {\n          this.connect();\n        }\n        return this.consumer;\n      }\n\n      closeConnection() {\n        if(this.consumer) {\n          Cable.endConsumer(this.consumer);\n        }\n        delete this.consumer;\n      }\n    }\n\nMyChannel.js\n\n    import WebSocket from './websocket';\n\n    class MyChannel {\n      constructor() {\n      }\n      subscribe() {\n        this.subscription = WebSocket.getConsumer().subscriptions.create(\"MyChannel\", {\n          connected: function () {\n            console.log('connected to mychannel');\n          },\n          received: function (data) {\n            //do stuff with data\n          }\n        });\n      }\n      unsubscribe() {\n        if(this.subscription)\n          this.subscription.unsubscribe();\n      }\n    }\n\nActioncable is good stuff, even if it is in Ruby.\n\n## Connecting from Node.js\n\n`es6-actioncable` will work under Node.js, however you will need to bear the following in mind:\n\n* You will need to supply your own websocket library, 2 out of 2 developers recommend: https://www.npmjs.com/package/websocket.\n* Your ActionCable Rails server must be bound to a specific IP or `0.0.0.0`, but not localhost. This can be done as follows `rails server -b 0.0.0.0`. See https://twitter.com/mattheworiordan/status/713350750483693568 for an explanation of the issue.\n* You will need to pass the origin to the WebSocket library as Rails will by default reject requests with an invalid origin.  See example below:\n\n```javascript\nconst consumer = Cable.createConsumer('ws://0.0.0.0:3000/cable', { createWebsocket: (options) =\u003e {\n  var w3cwebsocket = require('websocket').w3cwebsocket;\n  let webSocket = new w3cwebsocket(\n     'ws://0.0.0.0:3000/cable',\n     options.protocols,\n     'http://0.0.0.0:3000',\n     options.headers,\n     options.extraRequestOptions\n   );\n   return webSocket;\n} });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feacaps%2Fes6-actioncable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feacaps%2Fes6-actioncable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feacaps%2Fes6-actioncable/lists"}