• Stars
    star
    251
  • Rank 161,820 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A ruby client for interacting with Rails' ActionCable. -- Maintainers Wanted.

Action Cable Client

Gem Version Build Status Code Climate Test Coverage

This gem is a wrapper around websocket-eventmachine-client, and supports the Rails Action Cable protocol.

Usage

require 'action_cable_client'

EventMachine.run do

  uri = "ws://localhost:3000/cable/"
  client = ActionCableClient.new(uri, 'RoomChannel')
  # called whenever a welcome message is received from the server
  client.connected { puts 'successfully connected.' }

  # called whenever a message is received from the server
  client.received do | message |
    puts message
  end

  # Sends a message to the sever, with the 'action', 'speak'
  client.perform('speak', { message: 'hello from amc' })
end

This example is compatible with this version of a small Rails app with Action Cable

The available hooks to tie in to are:

  • disconnected {}
  • connected {}
  • subscribed {}
  • rejected {}
  • errored { |msg| }
  • received { |msg }
  • pinged { |msg| }

Connecting on initialization is also configurable.

client = ActionCableClient.new(uri, 'RoomChannel', false)
client.connect!(headers = {})
client.pinged do |_data|
  # you could track the time since you last received a ping, if you haven't
  # received one in a while, it could be that your client is disconnected.
end

To reconnect,

client.reconnect!

Sending additional params

params = { channel: 'RoomChannel', favorite_color: 'blue' }
client = ActionCableClient.new(uri, params)

then on the server end, in your Channel, params will give you:

{
       "channel" => "RoomChannel",
"favorite_color" => "blue"
}

Using Headers

params = { channel: 'RoomChannel', favorite_color: 'blue' }
client = ActionCableClient.new(uri, params, true, {
  'Authorization' => 'Bearer token'
})

Using TLS

Example given for client certificate authentication. See EventMachine::Connection#start_tls documentation for other options.

params = { channel: 'RoomChannel', favorite_color: 'blue' }
tls = {cert_chain_file: 'user.crt', private_key_file: 'user.key'}
client = ActionCableClient.new(uri, params, true, nil, tls)

Demo

Live Demo

Action Cable Client Demo on YouTube (1:41)

Here is a set of files in a gist that demonstrate how different action_cable_clients can communicate with eachother.

The Action Cable Protocol

There really isn't that much to this gem. :-)

  1. Connect to the Action Cable URL
  2. After the connection succeeds, send a subscribe message
  • The subscribe message JSON should look like this
    • {"command":"subscribe","identifier":"{\"channel\":\"MeshRelayChannel\"}"}
  • You should receive a message like this:
    • {"identifier"=>"{\"channel\":\"MeshRelayChannel\"}", "type"=>"confirm_subscription"}
  1. Once subscribed, you can send messages.
  • Make sure that the action string matches the data-handling method name on your ActionCable server.
  • Your message JSON should look like this:
    • {"command":"message","identifier":"{\"channel\":\"MeshRelayChannel\"}","data":"{\"to\":\"user1\",\"message\":\"hello from user2\",\"action\":\"chat\"}"}
    • Received messages should look about the same
  1. Notes:
  • Every message sent to the server has a command and identifier key.
  • The channel value must match the name of the channel class on the ActionCable server.
  • identifier and data are redundantly jsonified. So, for example (in ruby):
payload = {
  command: 'command text',
  identifier: { channel: 'MeshRelayChannel' }.to_json,
  data: { to: 'user', message: 'hi', action: 'chat' }.to_json
}.to_json

Contributing

  1. Fork it ( https://github.com/NullVoxPopuli/action_cable_client/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

More Repositories

1

emberclear

Encrypted Chat. No History. No Logs.
TypeScript
198
star
2

drawers

Group related classes together. No more silos. A solution to rails dystopia.
Ruby
147
star
3

skinny_controllers

A pattern for allowing for easier testing of large projects' business logic
Ruby
89
star
4

ember-resources

An implementation of Resources with some helpful utilities
TypeScript
81
star
5

ember-query-params-service

Do you have controllers that _only_ parse query params? now you can get rid of them :)
TypeScript
57
star
6

eslint-plugin-decorator-position

ESLint plugin for enforcing decorator position
JavaScript
42
star
7

react-vs-ember

A subjective comparison of problem solving in react (and it's ecosystem) vs. ember. (Supporting code for blog series)
TypeScript
42
star
8

ember-data-resources

Resources for use with ember-data for reactive data (re)fetching
TypeScript
32
star
9

coc-ember

ember-language-server integration with coc, an intellisense / language server engine for (neo)vim
TypeScript
32
star
10

limber

Glimdown playground for documentation, demos, etc
TypeScript
31
star
11

ember-apply

Automatic integration and configuration from the EmberJS community
JavaScript
31
star
12

dotfiles

CSS
28
star
13

ember-statechart-component

Statecharts as components. No classes. Pure declarative state transitions.
TypeScript
28
star
14

ember-deep-tracked

Deep auto-tracking for when you just don't care, and want things to work (at the cost of performance in some situtations)
TypeScript
26
star
15

react-state-helpers

component state helpers for react to help reduce boilerplate and to not rely on redux for everything
JavaScript
25
star
16

ember-popperjs

Renderless Component for Popper.JS for you to easily make popovers in Ember.JS
JavaScript
23
star
17

static-route-paths

Depedency-free static route builder that can be used alongside any dynamic routing library to bring sanity to intellisense
TypeScript
23
star
18

ember-autostash-modifier

A modifier for syncing data to another location based on changing arguments.
JavaScript
22
star
19

ember-contextual-services

Services in Ember are scoped to the app as a whole and are singletons. Sometimes you don't want that. :) This addon provides ephemeral route-based services.
JavaScript
20
star
20

ember-addon-migrator

ember addon v1 to v2 migrator
JavaScript
19
star
21

optional-chaining-codemod

there should be more codemods for mundane stuff like this
JavaScript
16
star
22

qunit-assertions-extra

Collection of helpful assertions for use with qunit
TypeScript
16
star
23

aeonvera

A generic registration system aimed towards swing dance events (mirrored from gitlab)
Ruby
15
star
24

ember-three-boxes-demo

pretty graphics!
JavaScript
14
star
25

lazy_crud

Lazy way to implement common actions in controllers in Rails
Ruby
12
star
26

ember-repl

Tools for building playgrounds and repls with and for ember. Useful for interactive styleguides, too
TypeScript
12
star
27

highlightjs-glimmer

glimmer syntax highlighting with highlight.js
JavaScript
12
star
28

CryptoExchangeClient

Clients for multiple cryptocurrency exchanges. All clients have a shared interface for common actions.
F#
12
star
29

ember-tailwind-cli-demo

Demo of settingup tailwind 3 (cli) with emberjs
JavaScript
11
star
30

latency-tester

For debugging audio latency in headphones, VR, etc.
HTML
11
star
31

ember-computed-promise-monitor

Enable computed properties to be async-aware.
TypeScript
11
star
32

ember-jsqr

ember integration with jsQR - a very fast QR Code scanner
TypeScript
11
star
33

action-setup-pnpm

Correctly sets up node, pnpm, and cache for fastest possible pnpm installations
10
star
34

whats-new-in-ember-since-octane

Aggregate of features, patterns, etc across the ecosystem (not just ember)
10
star
35

ember-wordle

Ember implementation of the game: wordle, https://www.powerlanguage.co.uk/wordle/
JavaScript
9
star
36

ember-todomvc-tutorial

step-by-step guide to todomvc with ember
JavaScript
9
star
37

ember-lifecycle-component

A component with additional lifecycles for times when you may not need need a template.
JavaScript
9
star
38

case_transform-rust-extensions

Rust Extensions for the Ruby gem case_transform
Ruby
9
star
39

tanqueReact

p2p encrypted React-based Chat
JavaScript
8
star
40

ember-noop

helpers for conditional actions.
JavaScript
8
star
41

ember-component-stats

TypeScript
8
star
42

Iris-Recognition

iris recognition for imagerec
Objective-C
8
star
43

ember-msw-development

Do you want to test your API before the API is implemented? Is your API team slower than your frontend team? Do you need to mock data for devlepment and testing? Try MSW!
JavaScript
8
star
44

vite-demo

Ember + Vite
JavaScript
8
star
45

DynamicFluentBuilder.Net

The Fluent Builder Pattern without all the manual work!
C#
7
star
46

mesh-relay

relay server for mesh-chat
Ruby
7
star
47

ember-functions-as-modifiers-polyfill

Polyfill for https://github.com/emberjs/rfcs/pull/757
TypeScript
7
star
48

eslint-configs

My Preferred ESLint configs for all my projects. Uses only overrides so that they're easy to maintain and update
JavaScript
7
star
49

ember-ci-update

Tool to drastically reduce config and mental burden when managing CI
JavaScript
6
star
50

ember-addon-automated-ci

ember-cli-update blueprint to quickly bootstrap automated ci and maintenance
JavaScript
6
star
51

testing-library-ember

maybe one day @testing-library/ember. Based off of https://testing-library.com/docs/dom-testing-library/intro and https://github.com/emberjs/ember-test-helpers
JavaScript
6
star
52

project-linter

Create conventions for file placement for any kind of JS/TS project. React, Angular, Vue, Svelte, Ember, etc.
TypeScript
5
star
53

ember-spicy-forms

Form library that lets you handle the presentation
JavaScript
5
star
54

ember-lifecycle-utils

Utils for lifecycle-related things in Ember
JavaScript
5
star
55

Genre-Map

Genre Map of Electronic Music Genres
Ruby
5
star
56

ember-test-helpers-extra

Additional test helpers that build upon the primitives in @ember/test-helpers
TypeScript
4
star
57

emberconf-2019

HTML
4
star
58

crypto-exchange-client

A common typed interface for cryptocurrency REST and websocket clients
TypeScript
4
star
59

coc-glint

coc.nvim plugin for Glint, https://typed-ember.gitbook.io/glint/
TypeScript
4
star
60

spiced_rumby

A ruby gem that acts as a mesh-chat client.
Ruby
4
star
61

HH_Headset_Switchboard

Java
4
star
62

Pokemon-Information-Scraper

I java tool for scraping the pokemon info off of bulbapedia
4
star
63

ember-array-map-resource

Array.prototype.map, but as a Resource that prevents unneeded memory thrashing
TypeScript
4
star
64

glimdown

Plugin for the Unified ecosystem to use glimmer/ember in markdown
TypeScript
4
star
65

mesh-relay-phoenix

Relay for the mesh-chat network, written in Elixir, using Phoenix
Elixir
4
star
66

comsat

I replay selector and launcher for StarCraft 2
JavaScript
4
star
67

ubuntu-post-install-script

I've had to set up a lot of Ubuntu systems, and I'm tired of it! AUTOMATE!
Shell
4
star
68

active-inflector

TypeScript
3
star
69

rollup-plugin-glimmer-template-tag

Rollup plugin for providing support for both gjs and gts file formats
JavaScript
3
star
70

react-action-decorators

Because making event handling for everything is tiresome.
JavaScript
3
star
71

glimmer

Collection of resources for Glimmer, the language
HTML
3
star
72

baobab-ram

RAM visualizer, inspired by baobab, the Gnome Disk Usage Analyzer
JavaScript
3
star
73

meshchat-core

core functionality of meshchat implemented in ruby.
Ruby
3
star
74

demo-ember-dynamic-component-import

JavaScript
3
star
75

csharp-extensions

because csharp needs some help
C#
3
star
76

polaris-toucan-starter

Starter App using the Polaris edition of Ember along with the Toucan tailwind preset
JavaScript
3
star
77

polaris-starter

Get started with the Polaris Edition of Ember before it's released!
JavaScript
3
star
78

ember-function-component

Hooks and Function components in Ember, but without the "rules of hooks" from React
TypeScript
3
star
79

ultimate-accordion-ember-version

In collaboration with Isaac for a talk at the Framework Summit.
HTML
3
star
80

Sunset-Detector

Sunset Detector for CSSE 463 - Image Rec
Objective-C
3
star
81

signals-tutorial

HTML
2
star
82

git-workflow

Git workflows for projects
2
star
83

glimmer-tutorial

Interactive Tutorial
2
star
84

CSSE413-CTF-AI

A.I. project for CSSE413 at Rose-Hulman . We called it the "Overmind", cause we are all obsessed with Starcraft
Java
2
star
85

ember-shared-memory

share memory between instances of the same class/component or across any kind of class
JavaScript
2
star
86

ember-cli-swc-minifier

Addon to replace Terser with SWC for performant minification
JavaScript
2
star
87

gmusic-sync-service

A lightweight service for DJing google music
Ruby
2
star
88

changeset-recover

recover utility to generate changeset (https://github.com/changesets/changesets) entries when they'd previously been forgetten. Gives library maintainers a chance to double check merged work without fear of missing attribution in the CHANGELOG.
JavaScript
2
star
89

vitest-blueprint

ember-cli blueprint for boot-strapping vitest projects
JavaScript
2
star
90

rails-NPlusOneTests

Benchmarking various scenarios for handling n+1 in rails.
Ruby
2
star
91

library-provides-web-worker-in-ember-project

JavaScript
2
star
92

prismjs-glimmer

glimmer syntax highlighting with prism.js
JavaScript
2
star
93

MetaHash

Provides a subclass of Hash and a wrapper around Rails' serialize attribute for object-like access to hashes without validating existence of nested hashes
Ruby
2
star
94

ember-jSquirrels

Codemod that iterates through ember-addons on EmberObserver.com distracts jQuery, and submits PRs with the jSquirrels removed
JavaScript
2
star
95

gitlab-runner

Kubernetes + GCE configured gitlab-runner for docker-compose-powered C.I. workflows.
Shell
2
star
96

test-ember-vite-app

JavaScript
1
star
97

cjs-transform-in-ember

ember-auto-import would be easier, but here is how you import a cjs module
1
star
98

octane-ember-concurrency-repro

JavaScript
1
star
99

ember-cjs-transform-example

1
star
100

Hash-Pre-image-A.I.

Independent Study
C++
1
star