rrweb canvas webrtc plugin
Plugin that live streams contents of canvas elements via webrtc
Example of live streaming via yarn live-stream
https://user-images.githubusercontent.com/4106/186701616-fd71a107-5d53-423c-ba09-0395a3a0252f.mov
Instructions
Record side
// 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
// 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 scriptEnabling canvas replay adds allow-scripts to the replay iframe and opts out of rrweb's sandbox script-execution protection. Only use UNSAFE_replayCanvas for replay data whose risk you accept.
More info
https://github.com/rrweb-io/rrweb/pull/976
Release Notes for rrweb canvas webrtc plugin
2.1.0—2.1.1
No changes to this package through these releases, version incremented to keep in sync with other packages
2.0.1
Patch Changes
- Updated dependencies [
5f52d63]:- rrweb@2.0.1
2.0.0
Major Changes
#1497
2606a2aThanks @Juice10! - Split plugins out of rrweb and move them into their own packages: @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. Check out the README of each package for more information or check out https://github.com/rrweb-io/rrweb/pull/1033 to see the changes.#1497
2606a2aThanks @Juice10! - Distributed files have new filenames, paths and extensions. Important: If you reference distributed files or types directly, you might have to update your paths/filenames. E.g. you import fromrrweb/typings/...orrrdom/es. However you runimport rrweb from 'rrweb'you won't notice a difference with this change. If you include rrweb files directly in a script tag, you might have to update that path to include a the.umd.cjsfiles instead. All.jsfiles now use ES modules which can be used in modern browsers, node.js and bundlers that support ES modules. All npm packages now also ship.cjsand.umd.cjsfiles. The.umd.cjsfiles are CommonJS modules that bundle all files together to make it easy to ship one file to browser environments (similar to the previous.jsfiles). The.cjsfiles are CommonJS modules that can be used in older Node.js environments. Types should be better defined inpackage.jsonand if you need specific types they might be exported from new packages (for examplePlayerMachineStateandSpeedMachineStateare now exported from@rrweb/replay). Check thepackage.json'smainandexportsfield for the available files.
Patch Changes
db20184Thanks @Juice10! - Keep package version in sync with other packages#1593
5a78938Thanks @daibhin! -NodeTypeenum was moved from rrweb-snapshot to @rrweb/types The following types where moved from rrweb-snapshot to @rrweb/types:documentNode,documentTypeNode,legacyAttributes,textNode,cdataNode,commentNode,elementNode,serializedNode,serializedNodeWithId,serializedElementNodeWithId,serializedTextNodeWithId,IMirror,INode,mediaAttributes,attributesandDataURLOptions#1704
33e01f5Thanks @eoghanmurray! - Provide a /umd/ output folder alongside the /dist/ one so that we can serve UMD (Universal Module Definition) files with a .js extension, without upsetting expectations set by package.json that all .js files in /dist/ are modulesUpdated dependencies [
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
Patch Changes
- Updated dependencies [
6388fb5]:- rrweb@2.0.0-alpha.20
2.0.0-alpha.19
Patch Changes
- Updated dependencies [
dc20cd4,3e9e42f,a6893f7,88ea2d0,fc390a9,79837ac,6f4e691,9cd28b7]:- rrweb@2.0.0-alpha.19
2.0.0-alpha.18
Patch Changes
- #1593
5a78938Thanks @daibhin! -NodeTypeenum was moved from rrweb-snapshot to @rrweb/types The following types where moved from rrweb-snapshot to @rrweb/types:documentNode,documentTypeNode,legacyAttributes,textNode,cdataNode,commentNode,elementNode,serializedNode,serializedNodeWithId,serializedElementNodeWithId,serializedTextNodeWithId,IMirror,INode,mediaAttributes,attributesandDataURLOptions - Updated dependencies [
04ee6ed,5fbb904,5a78938,53b83bb]:- rrweb@2.0.0-alpha.18
2.0.0-alpha.17
Patch Changes
db20184Thanks @Juice10! - Keep package version in sync with other packagesUpdated dependencies [
40bbc25,68076b7,8059d96,335639a,be6bf52]:- rrweb@2.0.0-alpha.17
2.0.0-alpha.15
Major Changes
#1497
2606a2aThanks @Juice10! - Split plugins out of rrweb and move them into their own packages: @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. Check out the README of each package for more information or check out https://github.com/rrweb-io/rrweb/pull/1033 to see the changes.#1497
2606a2aThanks @Juice10! - Distributed files have new filenames, paths and extensions. Important: If you reference distributed files or types directly, you might have to update your paths/filenames. E.g. you import fromrrweb/typings/...orrrdom/es. However you runimport rrweb from 'rrweb'you won't notice a difference with this change. If you include rrweb files directly in a script tag, you might have to update that path to include a the.umd.cjsfiles instead. All.jsfiles now use ES modules which can be used in modern browsers, node.js and bundlers that support ES modules. All npm packages now also ship.cjsand.umd.cjsfiles. The.umd.cjsfiles are CommonJS modules that bundle all files together to make it easy to ship one file to browser environments (similar to the previous.jsfiles). The.cjsfiles are CommonJS modules that can be used in older Node.js environments. Types should be better defined inpackage.jsonand if you need specific types they might be exported from new packages (for examplePlayerMachineStateandSpeedMachineStateare now exported from@rrweb/replay). Check thepackage.json'smainandexportsfield for the available files.