You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@rails/actioncable

Package Overview
Dependencies
Maintainers
0
Versions
133
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rails/actioncable

WebSocket framework for Ruby on Rails.

8.0.200
latest
Source
npm
Version published
Weekly downloads
842K
4.79%
Maintainers
0
Weekly downloads
 
Created

What is @rails/actioncable?

@rails/actioncable is a JavaScript client for Action Cable, which is a framework for handling WebSockets in Ruby on Rails applications. It allows you to create real-time features in your Rails applications by providing a way to communicate between the server and the client using WebSockets.

What are @rails/actioncable's main functionalities?

Establishing a WebSocket Connection

This code establishes a WebSocket connection to the specified URL. The `createConsumer` method is used to create a new consumer instance that will manage the WebSocket connection.

const cable = ActionCable.createConsumer('ws://cable.example.com');

Subscribing to a Channel

This code subscribes to a channel named 'ChatChannel'. The `received` function is called whenever data is broadcasted to the channel. In this example, it simply logs the received data to the console.

const subscription = cable.subscriptions.create('ChatChannel', {
  received(data) {
    console.log('Received:', data);
  }
});

Sending Data to the Server

This code sends data to the server through the WebSocket connection. The `send` method is used to transmit a message to the server, which can then be processed and broadcasted to other clients.

subscription.send({ message: 'Hello, World!' });

Unsubscribing from a Channel

This code unsubscribes from the 'ChatChannel'. The `unsubscribe` method is used to terminate the subscription and stop receiving data from the channel.

subscription.unsubscribe();

Other packages similar to @rails/actioncable

Keywords

websockets

FAQs

Package last updated on 12 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts