@blockcast/multicast-browser

中文文档
1.0.0发布于 2026/10/13MITTypeScriptES Module构建来源已验证近 30 天下载 2107

Browser/extension/IWA adapter for the frozen v1 window.multicast contract: structural provider resolution plus readiness observation collection. Its only dependency is @blockcast/multicast-contract, which is itself dependency-free and consumed type-only.

原始使用文档
文档目录5 节
  1. One dependency, consumed type-only
  2. Usage
  3. Three places this is easy to get wrong
  4. What this package cannot see, and says so
  5. Build and test

@blockcast/multicast-browser

The browser / extension / IWA adapter for the frozen v1 window.multicast contract (@blockcast/multicast-contract).

The contract package is a deliberately pure leaf: evaluateReadiness is a pure function of a caller-supplied observation, and the gateway surface is types only. Something has to bind that to a real browser realm, and until this package nothing did — the contract shipped with zero consumers. This is that binding, and nothing more:

jobentry point
Resolve the installed provider against MulticastGatewaygetGateway, hasGateway
Collect the facts evaluateReadiness consumesobserveReadiness and its parts
Run the contract's conformance suite in a browser realmcreateBrowserConformanceDriver

One dependency, consumed type-only

@blockcast/multicast-contract is the only entry in dependencies, and it is itself dependency-free. It is declared so that npm install @blockcast/multicast-browser resolves the types this package's emitted .d.ts name — without it a consumer gets TS2307.

Nothing is imported at runtime: the contract is consumed type-only, so the emitted JS imports no bare specifier at all. That is what keeps a private transport implementation from ever becoming reachable through this public surface. A test pins that shipped sources use import type; the CI lane pins it again on the built output.

Usage

import { evaluateReadiness } from '@blockcast/multicast-contract';
import { getGateway, observeReadiness } from '@blockcast/multicast-browser';

const gateway = getGateway();
if (gateway === null) {
  // Not an exception — an absent provider is the expected state on most pages.
  const readiness = evaluateReadiness(
    await observeReadiness({ extensionDeadlineElapsed: true }),
  );
  console.warn(readiness.code, readiness.detail); // e.g. 'provider-absent'
} else {
  const subscription = await gateway.subscribe(config);
}

Nothing here prompts, grants, or opens a window. Setup UX stays with the host (ratified in the contract freeze), and that is not only a layering preference: on the deployed system every gateway call routes through sendToIWA, which auto-opens an IWA window as a side effect — so a readiness API that probed for itself would pop a window as a consequence of asking "are you ready?".

Three places this is easy to get wrong

Each of these has a live failure mode behind it, and each is pinned by a test.

udpBind is tri-state and must stay tri-state. A real ephemeral UDP bind is the only proof Direct Sockets works, but the provider only attempts it once both fine-grained permissions are granted. So null means NOT ATTEMPTED, and collapsing it to false reports "we never tried" as "the bind failed" — different cause, different fix, different message, and the contract has separate codes (udp-bind-unverified vs udp-bind-failed). The deployed IWA currently collapses it; readSocketWorker does not.

The legacy local-network-access alias must never gate readiness. Current Chromium reports it denied while both fine-grained names are granted, so gating on it reports a working bridge as blocked. It is carried on legacyAlias as informational only.

extensionResponded stays null until the caller's deadline elapses. Extension detection is a fire-and-forget probe with no built-in timeout, so silence is indistinguishable from absence until then — and the contract reads null as not-yet-observed rather than as a verdict. The deadline is the caller's parameter because only the caller knows when it started probing.

What this package cannot see, and says so

observeReadiness takes socket-worker diagnostics as a parameter rather than probing for them, because they are not observable from a page realm: the socket worker lives in the IWA's isolated-app: realm, and the extension exposes no page-facing diagnostic channel. Omitting them yields socket-worker-unavailable, which is the honest reading for a caller that genuinely cannot see the worker. Inventing a healthy default would certify a provider nobody checked.

Build and test

The contract's declarations are the type source, so build it first. Run these from the repository root:

npm --prefix packages/multicast-contract install
npm --prefix packages/multicast-contract run build

# This package's lane is install-free: its `tsconfig.json` path mapping resolves
# the contract from the sibling package's emitted declarations above, and its
# tests run on node's own type stripping. That mapping stays — it is what lets
# the lane build without the contract having to exist on the registry first.
packages/multicast-contract/node_modules/.bin/tsc -b packages/multicast-browser
npm --prefix packages/multicast-browser test   # unit + browser conformance

CI runs exactly this in .github/workflows/publish-npm.yml, after the contract's own steps.

版本与发布记录

@blockcast/multicast-browser 共发布 2 个版本,首次发布于 2026/09/20;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.0latest2026/10/1326 天前
0.0.02026/09/201 个月前

关于 @blockcast/multicast-browser 的常见问题

@blockcast/multicast-browser 是什么?

Browser/extension/IWA adapter for the frozen v1 window.multicast contract: structural provider resolution plus readiness observation collection. Its only dependency is @blockcast/multicast-contract, which is itself dependency-free and consumed type-only.

如何安装 @blockcast/multicast-browser?

在项目目录运行 npm install @blockcast/multicast-browser,或使用 pnpm add / yarn add / bun add。

@blockcast/multicast-browser 支持 TypeScript 吗?

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

@blockcast/multicast-browser 支持 ESM 还是 CommonJS?

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

@blockcast/multicast-browser 可以商用吗?

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

@blockcast/multicast-browser 的下载量有多少?

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

@blockcast/multicast-browser 还在维护吗?

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