@mattebox/cast-receiver

中文文档
0.3.1发布于 2026/11/02MITTypeScriptES Module零依赖构建来源已验证

The bridge between Google's Cast receiver framework and , with hooks. No DOM of its own.

原始使用文档

@mattebox/cast-receiver

This library connects Google's Cast receiver framework (CAF, version 3) to <mattebox-player>. You can turn a web page into a Chromecast receiver with a few lines of code. The library creates no DOM, and importing it has no side effects.

Install the library and its peer dependencies:

npm install @mattebox/cast-receiver @mattebox/player @mattebox/player-core mattebox

Add Google's framework to your page:

<script src="https://www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js"></script>

Create the receiver, create the player with the receiver's handlers, and start the receiver:

import { createReceiver } from '@mattebox/cast-receiver';
import { MatteboxPlayerElement } from '@mattebox/player';
import full from 'mattebox/presets/full';

const receiver = createReceiver({ preset: full });
const player = new MatteboxPlayerElement({ handlers: receiver.handlers() });
document.body.append(player);
receiver.start(player);
The library does thisThe library does not do this
It passes the sender's LOAD through your resolve and loads the playerIt does not create or append any element
It reports the media status from the video and the engineIt does not know what a token is, or where a license comes from
It selects audio and text tracks under stable Cast idsIt does not bundle an engine preset. Your page imports one
It sends the player's errors to every senderIt does not load Google's framework. Your page loads it
It passes custom namespaces throughIt does not ship a fake framework. The library's tests have their own

The framework's script is never a dependency of the library. The engine, the core and the player are peer dependencies.

You can read the guide in the repository: docs/guide.

License

MIT

版本与发布记录

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

版本发布日期距今
0.3.1latest2026/11/021 天前
0.3.02026/10/2311 天前
0.2.02026/10/1419 天前
0.1.12026/09/301 个月前
0.1.02026/09/211 个月前

关于 @mattebox/cast-receiver 的常见问题

@mattebox/cast-receiver 是什么?

谷歌的Cast接收器框架与钩子之间的桥梁。没有自己的DOM。

如何安装 @mattebox/cast-receiver?

在项目目录运行 npm install @mattebox/cast-receiver,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:mattebox(^0.17.0)、@mattebox/player(>=0.5.0)、@mattebox/player-core(^0.9.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@mattebox/cast-receiver 支持 TypeScript 吗?

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

@mattebox/cast-receiver 支持 ESM 还是 CommonJS?

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

@mattebox/cast-receiver 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.19。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@mattebox/cast-receiver 可以商用吗?

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

@mattebox/cast-receiver 还在维护吗?

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