@aspnet/signalr

中文文档
1.0.27发布于 2021/04/09Apache-2.0TypeScriptESM + CJS零依赖近 30 天下载 11.2万

ASP.NET Core SignalR Client

此软件包已被标记为弃用

This package is no longer supported. Consider using @microsoft/signalr.

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. Browser
  4. Node.js
  5. Example (Browser)
  6. Example (NodeJS)

JavaScript and TypeScript clients for SignalR for ASP.NET Core

:warning: This package will no longer be supported starting August 21, 2021. This package follows the .NET Core 2.1 support lifecycle which is ending soon. Please transition to using @microsoft/signalr as described below.

Note: The JavaScript and TypeScript clients for SignalR for ASP.NET Core have been moved to @microsoft/signalr. If you are already using @aspnet/signalr and are unsure when to move to @microsoft/signalr, check the Feature Distribution chart in the ASP.NET Core SignalR documentation. Newer client releases are compatible with older version of ASP.NET Core SignalR which means it is safe to upgrade the client before upgrading the server.

Installation

npm install @aspnet/signalr

Usage

See the SignalR Documentation at docs.microsoft.com for documentation on the latest release.

Browser

To use the client in a browser, copy *.js files from the dist/browser folder to your script folder include on your page using the <script> tag.

Node.js

The following polyfills are required to use the client in Node.js applications:

  • XmlHttpRequest - always
  • WebSockets - to use the WebSockets transport
  • EventSource - to use the ServerSentEvents transport
  • btoa/atob - to use binary protocols (e.g. MessagePack) over text transports (ServerSentEvents)

Example (Browser)

let connection = new signalR.HubConnectionBuilder()
    .withUrl("/chat")
    .build();

connection.on("send", data => {
    console.log(data);
});

connection.start()
    .then(() => connection.invoke("send", "Hello"));

Example (NodeJS)

const signalR = require("@aspnet/signalr");

let connection = new signalR.HubConnectionBuilder()
    .withUrl("/chat")
    .build();

connection.on("send", data => {
    console.log(data);
});

connection.start()
    .then(() => connection.invoke("send", "Hello"));

版本与发布记录

@aspnet/signalr 共发布 23 个版本,首次发布于 2018/02/28;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.27latest2021/04/095 年前
1.0.262021/03/105 年前
3.0.0-preview6.19307.2next2019/06/127 年前
3.0.0-preview5-19227-012019/05/067 年前
3.0.0-preview4-19216-032019/04/197 年前
1.1.42019/04/097 年前

关于 @aspnet/signalr 的常见问题

@aspnet/signalr 是什么?

ASP.NET Core SignalR Client注意:该包已被作者标记为弃用——This package is no longer supported. Consider using @microsoft/signalr.

如何安装 @aspnet/signalr?

在项目目录运行 npm install @aspnet/signalr,或使用 pnpm add / yarn add / bun add。

@aspnet/signalr 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aspnet/signalr 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aspnet/signalr 可以商用吗?

@aspnet/signalr 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aspnet/signalr 的下载量有多少?

根据 npm 官方下载统计,@aspnet/signalr 在 2026/10/07 – 2026/11/05 这 30 天内被下载 112,050 次,日均约 3,735 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aspnet/signalr 还在维护吗?

最新版本 1.0.27 发布于 2021/04/09(5 年前);至今共发布 23 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/02/28。作者已将其标记为弃用,新项目建议寻找替代方案。