rrweb canvas webrtc 插件
通过 WebRTC 实时流式传输 canvas 元素内容的插件
通过 yarn live-stream 进行实时直播的示例
https://user-images.githubusercontent.com/4106/186701616-fd71a107-5d53-423c-ba09-0395a3a0252f.mov
使用说明
录制端
// Record side
import { record } from '@rrweb/record';
import { RRWebPluginCanvasWebRTCRecord } from '@rrweb/rrweb-plugin-canvas-webrtc-record';
const webRTCRecordPlugin = new RRWebPluginCanvasWebRTCRecord({
signalSendCallback: (msg) => {
// provides webrtc sdp offer signal & connect message
// make sure you send this to the replayer's `webRTCReplayPlugin.signalReceive(signal)`
sendSignalToReplayer(msg); // example of function that sends the signal to the replayer
},
});
record({
emit: (event) => {
// send these events to the `replayer.addEvent(event)`, how you do that is up to you
// you can send them to a server for example which can then send them to the replayer
sendEventToReplayer(event); // example of function that sends the event to the replayer
},
plugins: [
// add the plugin to the list of plugins, and initialize it via `.initPlugin()`
webRTCRecordPlugin.initPlugin(),
],
recordCanvas: false, // we don't want canvas recording turned on, we're going to do that via the plugin
});回放端
// Replay side
import { Replayer } from '@rrweb/replay';
import { RRWebPluginCanvasWebRTCReplay } from '@rrweb/rrweb-plugin-canvas-webrtc-replay';
const webRTCReplayPlugin = new RRWebPluginCanvasWebRTCReplay({
canvasFoundCallback(canvas, context) {
console.log('canvas', canvas);
// send the canvas id to `webRTCRecordPlugin.setupStream(id)`, how you do that is up to you
// you can send them to a server for example which can then send them to the replayer
sendCanvasIdToRecordScript(context.id); // example of function that sends the id to the record script
},
signalSendCallback(signal) {
// provides webrtc sdp offer signal & connect message
// make sure you send this to the record script's `webRTCRecordPlugin.signalReceive(signal)`
sendSignalToRecordScript(signal); // example of function that sends the signal to the record script
},
});
const replayer = new Replayer([], {
UNSAFE_replayCanvas: true, // turn canvas replay on!
liveMode: true, // live mode is needed to stream events to the replayer
plugins: [webRTCReplayPlugin.initPlugin()],
});
replayer.startLive(); // start the replayer in live mode
replayer.addEvent(event); // call this whenever an event is received from the record script启用 canvas 回放会向回放 iframe 添加 allow-scripts,并脱离 rrweb 的沙箱脚本执行保护。请仅对你能接受其风险的回放数据使用 UNSAFE_replayCanvas。
更多信息
https://github.com/rrweb-io/rrweb/pull/976
rrweb canvas webrtc 插件发布说明
2.1.0—2.1.1
这些版本中本包没有变更,仅递增版本号以与其他包保持同步
2.0.1
补丁变更
- 更新依赖 [
5f52d63]:- rrweb@2.0.1
2.0.0
重大变更
#1497
2606a2a感谢 @Juice10! - 将插件从 rrweb 中拆分出来,移入各自独立的包:@rrweb/packer、@rrweb/rrweb-plugin-canvas-webrtc-record、@rrweb/rrweb-plugin-canvas-webrtc-replay、@rrweb/rrweb-plugin-sequential-id-record、@rrweb/rrweb-plugin-sequential-id-replay、@rrweb/rrweb-plugin-console-record、@rrweb/rrweb-plugin-console-replay。更多信息请查看各包的 README,或访问 https://github.com/rrweb-io/rrweb/pull/1033 查看具体变更。#1497
2606a2a感谢 @Juice10! - 分发文件有了新的文件名、路径和扩展名。重要:如果你直接引用分发文件或类型,可能需要更新你的路径/文件名。例如你从rrweb/typings/...或rrdom/es导入。但如果你使用import rrweb from 'rrweb',则不会察觉到这一变更带来的差异。 如果你直接在 script 标签中引入 rrweb 文件,可能需要将该路径更新为.umd.cjs文件。现在所有.js文件都使用 ES 模块,可用于现代浏览器、node.js 以及支持 ES 模块的打包工具。所有 npm 包现在还会同时提供.cjs和.umd.cjs文件。.umd.cjs文件是将所有文件打包在一起的 CommonJS 模块,便于向浏览器环境交付单个文件(类似于之前的.js文件)。.cjs文件是可用于旧版 Node.js 环境的 CommonJS 模块。类型在package.json中应有更完善的定义;如果你需要特定类型,它们可能从新的包中导出(例如PlayerMachineState和SpeedMachineState现在从@rrweb/replay导出)。可用文件请查看package.json的main和exports字段。
补丁变更
#1593
5a78938感谢 @daibhin! -NodeType枚举已从 rrweb-snapshot 移至 @rrweb/types 以下类型已从 rrweb-snapshot 移至 @rrweb/types:documentNode、documentTypeNode、legacyAttributes、textNode、cdataNode、commentNode、elementNode、serializedNode、serializedNodeWithId、serializedElementNodeWithId、serializedTextNodeWithId、IMirror、INode、mediaAttributes、attributes和DataURLOptions#1704
33e01f5感谢 @eoghanmurray! - 在 /dist/ 之外新增 /umd/ 输出目录,以便提供带 .js 扩展名的 UMD(Universal Module Definition)文件,同时不违背 package.json 所设定的预期(即 /dist/ 中的所有 .js 文件都是模块)更新依赖 [
7103625,a2c8a1a,3d1877c,af0962c,57a940a,e65465e,d872d28,36da39d,b5e30cf,40bbc25,22bc4c3,11f6567,490b3e2,dc20cd4,3e9e42f,f27e545,7261c43,03b5216,ae6908d,46f1b25,e0f862b,cbbd1e5,a6893f7,8aea5b0,267e990,68076b7,9c6edfe,a1ec9a2,8059d96,bfe14c5,4014305,efdc167,88ea2d0,609b7fa,f6f07e9,1e0b273,1fe39ab,490b3e2,979d2b1,1385f7a,d7c72bf,ebcbe8b,123a81e,05478c3,fc390a9,bbbfa22,e96f668,58c9104,227d43a,bc84246,d2582e9,aa79db7,82f6fec,2606a2a,980a38c,2606a2a,a225d8e,a82a3b4,5c27b76,b149cf3,a2be77b,227d43a,527d9d3,79837ac,a7c33f2,43e4f5b,3cc4323,d38893f,6f4e691,d7cf8dd,335639a,04ee6ed,5fbb904,1e6f71b,d08624c,2606a2a,123a81e,314a8dd,5a78938,3416c3a,7c0dc9d,8e47ca1,53b83bb,9cd28b7,07ac5c9,33e01f5,02f50d2,502d15d,d0fbe23,a3de582,e08706a,8d209a6,be6bf52,aaabdbd,1e6f71b,6388fb5,4cb4d0e,5e6c132]:- rrweb@2.0.0
2.0.0-alpha.20
补丁变更
- 更新依赖 [
6388fb5]:- rrweb@2.0.0-alpha.20
2.0.0-alpha.19
补丁变更
2.0.0-alpha.18
补丁变更
- #1593
5a78938感谢 @daibhin! -NodeType枚举已从 rrweb-snapshot 移至 @rrweb/types 以下类型已从 rrweb-snapshot 移至 @rrweb/types:documentNode、documentTypeNode、legacyAttributes、textNode、cdataNode、commentNode、elementNode、serializedNode、serializedNodeWithId、serializedElementNodeWithId、serializedTextNodeWithId、IMirror、INode、mediaAttributes、attributes和DataURLOptions - 更新依赖 [
04ee6ed,5fbb904,5a78938,53b83bb]:- rrweb@2.0.0-alpha.18
2.0.0-alpha.17
补丁变更
2.0.0-alpha.15
重大变更
#1497
2606a2a感谢 @Juice10! - 将插件从 rrweb 中拆分出来,移入各自独立的包:@rrweb/packer、@rrweb/rrweb-plugin-canvas-webrtc-record、@rrweb/rrweb-plugin-canvas-webrtc-replay、@rrweb/rrweb-plugin-sequential-id-record、@rrweb/rrweb-plugin-sequential-id-replay、@rrweb/rrweb-plugin-console-record、@rrweb/rrweb-plugin-console-replay。更多信息请查看各包的 README,或访问 https://github.com/rrweb-io/rrweb/pull/1033 查看具体变更。#1497
2606a2a感谢 @Juice10! - 分发文件有了新的文件名、路径和扩展名。重要:如果你直接引用分发文件或类型,可能需要更新你的路径/文件名。例如你从rrweb/typings/...或rrdom/es导入。但如果你使用import rrweb from 'rrweb',则不会察觉到这一变更带来的差异。 如果你直接在 script 标签中引入 rrweb 文件,可能需要将该路径更新为.umd.cjs文件。现在所有.js文件都使用 ES 模块,可用于现代浏览器、node.js 以及支持 ES 模块的打包工具。所有 npm 包现在还会同时提供.cjs和.umd.cjs文件。.umd.cjs文件是将所有文件打包在一起的 CommonJS 模块,便于向浏览器环境交付单个文件(类似于之前的.js文件)。.cjs文件是可用于旧版 Node.js 环境的 CommonJS 模块。类型在package.json中应有更完善的定义;如果你需要特定类型,它们可能从新的包中导出(例如PlayerMachineState和SpeedMachineState现在从@rrweb/replay导出)。可用文件请查看package.json的main和exports字段。