🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

ably

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ably

Realtime client library for Ably, the realtime messaging service

2.8.0
latest
Version published
Weekly downloads
148K
12.51%
Maintainers
8
Weekly downloads
 
Created

What is ably?

Ably is a real-time messaging service that allows you to build powerful real-time applications. It provides features such as pub/sub messaging, presence, message history, and more, making it suitable for chat applications, live updates, and collaborative tools.

What are ably's main functionalities?

Pub/Sub Messaging

This feature allows you to publish and subscribe to messages on a channel. The code sample demonstrates how to publish a message to a channel and subscribe to receive messages from that channel.

const Ably = require('ably');
const realtime = new Ably.Realtime('YOUR_API_KEY');
const channel = realtime.channels.get('test-channel');

// Publishing a message
channel.publish('greeting', 'Hello, world!', (err) => {
  if (err) {
    console.error('Unable to publish message; err = ' + err.message);
  } else {
    console.log('Message successfully sent');
  }
});

// Subscribing to a channel
channel.subscribe('greeting', (message) => {
  console.log('Received message: ' + message.data);
});

Presence

This feature allows you to track the presence of users in a channel. The code sample demonstrates how to enter presence and subscribe to presence events to track when users join the channel.

const Ably = require('ably');
const realtime = new Ably.Realtime('YOUR_API_KEY');
const channel = realtime.channels.get('presence-channel');

// Entering presence
channel.presence.enter('user1', (err) => {
  if (err) {
    console.error('Unable to enter presence; err = ' + err.message);
  } else {
    console.log('Entered presence');
  }
});

// Subscribing to presence events
channel.presence.subscribe('enter', (member) => {
  console.log('Member entered: ' + member.clientId);
});

Message History

This feature allows you to retrieve the history of messages sent on a channel. The code sample demonstrates how to fetch and display past messages from a channel.

const Ably = require('ably');
const realtime = new Ably.Realtime('YOUR_API_KEY');
const channel = realtime.channels.get('history-channel');

// Retrieving message history
channel.history((err, resultPage) => {
  if (err) {
    console.error('Unable to retrieve message history; err = ' + err.message);
  } else {
    resultPage.items.forEach((message) => {
      console.log('Message: ' + message.data);
    });
  }
});

Other packages similar to ably

FAQs

Package last updated on 01 May 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