@equinor/fusion-framework-module-signalr

中文文档
14.1.0发布于 2026/11/12ISCTypeScriptES Module近 30 天下载 2740
原始使用文档
文档目录14 节
  1. When to use
  2. Installation
  3. Peer dependencies
  4. Quick start
  5. Service-discovery shorthand
  6. Custom configuration callback
  7. Subscribing to hub messages
  8. Sending messages
  9. Key concepts
  10. Hub configuration ( SignalRHubConfig )
  11. Connection lifecycle
  12. Operational telemetry
  13. Topic<T>
  14. Exports

@equinor/fusion-framework-module-signalr

Fusion Framework module for real-time communication via SignalR.

Provides an RxJS-based API for connecting to SignalR hubs, subscribing to server-side methods, and sending messages back to the server. Hub connections are reference-counted and automatically stopped when all subscribers unsubscribe.

When to use

Use this module when your Fusion application needs to:

  • Receive real-time push notifications from a backend service
  • Subscribe to server-sent events through a SignalR hub
  • Send messages to a SignalR hub method

Installation

pnpm add @equinor/fusion-framework-module-signalr

Peer dependencies

PackageRequired
@equinor/fusion-framework-moduleYes
@equinor/fusion-framework-module-msalNo (needed for automatic token acquisition)
@equinor/fusion-framework-module-service-discoveryNo (needed for service-discovery shorthand)

Quick start

Service-discovery shorthand

The simplest path uses enableSignalR with service-discovery and MSAL. The hub URL and access token are resolved automatically:

import { enableSignalR } from '@equinor/fusion-framework-module-signalr';

export const configure = (configurator) => {
  enableSignalR(configurator, 'portal', {
    service: 'portal',
    path: '/signalr/hubs/service-message',
  });
};

Custom configuration callback

For full control, pass a builder callback:

import { enableSignalR } from '@equinor/fusion-framework-module-signalr';

export const configure = (configurator) => {
  enableSignalR(configurator, 'custom', (builder) => {
    builder.addHub('custom', {
      url: 'https://my-service.example.com/hub',
      options: {
        accessTokenFactory: () => getAccessToken(),
      },
      automaticReconnect: true,
    });
  });
};

Subscribing to hub messages

Once the module is initialized, use ISignalRProvider.connect() to obtain a Topic — an RxJS Observable bound to a specific hub method:

const signalR = modules.signalR;
const topic = signalR.connect<MyMessage>('portal', 'OnServiceMessage');

const subscription = topic.subscribe((message) => {
  console.log('Received:', message);
});

// Unsubscribe when done — the hub connection is stopped automatically
// when the last subscriber unsubscribes.
subscription.unsubscribe();

Sending messages

A Topic also exposes send() (fire-and-forget) and invoke() (request-response) for communicating with the server:

// Fire-and-forget
topic.send('Hello from client');

// Request-response
const result = await topic.invoke<ServerResponse>('some argument');

Key concepts

Hub configuration (SignalRHubConfig)

Each hub connection is described by a SignalRHubConfig:

PropertyTypeDescription
urlstringAbsolute URL of the SignalR hub endpoint
optionsIHttpConnectionOptionsTransport and auth options (minus httpClient)
automaticReconnectbooleanEnable automatic reconnection on disconnect
logLevelLogLevelSignalR logging level (defaults to Critical)

Connection lifecycle

  • Lazy creation — hub connections are created on first subscription.
  • Shared connections — multiple Topic instances for the same hub share one underlying HubConnection via shareReplay.
  • Automatic teardown — when the last subscriber unsubscribes, the connection is stopped and removed from the internal cache.

Operational telemetry

When the telemetry module is available, the provider records each shared connection's lifecycle: fusion.signalr.connect.duration, fusion.signalr.reconnect.duration and fusion.signalr.disconnect.duration, with a sanitized .failure exception for failures, and a fusion.signalr.connection-lost notification when an established connection closes unexpectedly. Unsubscribing while a connection is still starting is a cancelled connect, not a failure. Hub names, URLs, tokens and messages are never recorded, and connection and reconnection behavior is unchanged.

Topic<T>

Topic extends RxJS Observable<T> and wraps a HubConnection method listener. It handles registering and unregistering the callback on the connection automatically.

Exports

ExportKindDescription
enableSignalRfunctionRegister the module and configure hubs in one call
module / defaultSignalRModuleModule instance for manual registration
moduleKey'signalR'Module registration key
SignalRModuleProviderclassDefault ISignalRProvider implementation
SignalRConfiguratorclassDefault ISignalRConfigurator implementation
SignalRModuleConfigBuilderclassBuilder for dynamic hub configuration
TopicclassRxJS Observable wrapper for a hub method
ISignalRProviderinterfaceProvider interface
ISignalRConfiguratorinterfaceConfigurator interface
SignalRConfigtypeResolved configuration
SignalRHubConfigtypeSingle hub configuration
SignalRModuleConfigBuilderCallbacktypeBuilder callback signature

版本与发布记录

@equinor/fusion-framework-module-signalr 共发布 122 个版本,首次发布于 2023/01/26;过去 12 个月发布了 22 个版本。

版本发布日期距今
14.1.0latest2026/11/121 天前
14.1.0-next.1next2026/11/112 天前
14.1.0-next.02026/10/2816 天前
14.0.42026/10/1727 天前
14.0.4-trusted-publishing-20261015-9dfe7602cd2a49a8a9df00d62c26e7304a82a85atrusted-publishing-202610152026/10/1629 天前
14.0.32026/10/121 个月前

其他发布通道:apploader → 6.0.3-apploader-be21a6b60eb13eee8bf869e75002d8634e9c50a9,cli-search-index → 9.0.1-cli-search-index.0,msal-v5 → 10.0.0-msal-v5.1,trusted-publishing-20261015 → 14.0.4-trusted-publishing-20261015-9dfe7602cd2a49a8a9df00d62c26e7304a82a85a,next → 14.1.0-next.1。

关于 @equinor/fusion-framework-module-signalr 的常见问题

如何安装 @equinor/fusion-framework-module-signalr?

在项目目录运行 npm install @equinor/fusion-framework-module-signalr,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@equinor/fusion-framework-module(^6.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@equinor/fusion-framework-module-signalr 支持 TypeScript 吗?

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

@equinor/fusion-framework-module-signalr 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@equinor/fusion-framework-module-signalr 可以商用吗?

@equinor/fusion-framework-module-signalr 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@equinor/fusion-framework-module-signalr 的下载量有多少?

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

@equinor/fusion-framework-module-signalr 还在维护吗?

最新版本 14.1.0 发布于 2026/11/12(1 天前);至今共发布 122 个版本,其中过去 12 个月发布了 22 个;首次发布于 2023/01/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。