百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

ably-js

> 前端框架
开源

JavaScript、Node、TypeScript、React、用于 Ably 实时消息服务的 React Native 客户端库 SDK

363 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

JavaScript、Node、TypeScript、React、用于 Ably 实时消息服务的 React Native 客户端库 SDK


Ably Pub/Sub JavaScript SDK

Build any realtime experience using Ably’s Pub/Sub JavaScript SDK. Supported on all popular platforms and frameworks, including Node, React, and Web Workers.

Ably Pub/Sub provides flexible APIs that deliver features such as pub-sub messaging, message history, presence, and push notifications. Utilizing Ably’s realtime messaging platform, applications benefit from its highly performant, reliable, and scalable infrastructure.

Ably LiveObjects is also available as a Pub/Sub JavaScript SDK plugin. You can use LiveObjects to synchronize application state across your clients at scale.

Find out more:

  • Ably Pub/Sub docs
  • Ably Pub/Sub Examples

Getting started

Everything you need to get started with Ably:

  • Getting started with Pub/Sub in JavaScript
  • Getting started with Pub/Sub in React
  • Getting started with LiveObjects in JavaScript

Supported platforms

Ably aims to support a wide range of platforms and all current browser versions, including Chrome, Firefox, Safari, Microsoft Edge, and other modern browsers. If you experience any compatibility issues, open an issue in the repository or contact Ably support.

The following platforms are supported:

Platform Support
JavaScript ES2017
Node.js See engines in package.json.
React >=16.8.x
TypeScript Type definitions are included in the package.
Web Workers Browser bundle and modular support.

[!NOTE] Versions 1.2.x of the SDK support Internet Explorer >=9 and other older browsers, as well as Node.js >=8.17.

[!IMPORTANT] SDK versions { console.log(Received message: ${message.data}); });

// Publish a test message to the channel await channel.publish('test-event', 'hello world');

…

javascript import { BaseRealtime, WebSocketTransport, FetchRequest, RealtimePresence } from 'ably/modular';

const client = new BaseRealtime({ key: 'YOUR_ABLY_API_KEY', // Replace with a real key from the Ably dashboard plugins: { WebSocketTransport, FetchRequest, RealtimePresence, }, });

…

json { // ... "minimum_chrome_version": "116" // ... }

…

tsx 'use client';

import { useEffect, useState } from 'react'; import * as Ably from 'ably'; import { AblyProvider } from 'ably/react';

export default function AblyClientProvider({ children }) { const [client, setClient] = useState(null);

useEffect(() => { const ably = new Ably.Realtime({ authUrl: '/token', authMethod: 'POST', clientId: 'demo' }); setClient(ably); return () => { ably.close(); }; }, []);

if (!client) return ;

return {children}; }

…

javascript const nextConfig = { // ... experimental: { serverComponentsExternalPackages: ['ably'], }, };

…

tsx 'use client';

import { useEffect, useState } from 'react'; import * as Ably from 'ably';

export default function MyComponent() { const [client, setClient] = useState(null);

useEffect(() => { const ably = new Ably.Realtime({ authUrl: '/token', authMethod: 'POST', clientId: 'demo' }); setClient(ably); return () => { ably.close(); }; }, []);

if (!client) return ;

// Use client here }


#### Component re-renders

Avoid creating the client inside React component bodies, as this creates a new connection on every render. Use the `useEffect` + `useState` pattern shown above to ensure the client is created once.

#### Hot module replacement (HMR)

To avoid duplicate client instances caused by hot reloads, move the new `Ably.Realtime()` call into a separate file, for example, `ably.js` and export the client from there. This ensures a single shared instance is reused during development.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptclient-libraryjavascriptjsreact-native

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架