Makes it possible to use WebRTC in Workers.
yarn add git+https://github.com/johanholmerin/worker-webrtc#semver:^0.1.1
// in window
import workerRTC from 'worker-webrtc/window.js';
const worker = new Worker('worker.js');
workerRTC(worker);
// worker.js
// NOTE: EventTarget polyfill needed here
import {
RTCPeerConnection,
RTCSessionDescription,
RTCIceCandidate
} from 'worker-webrtc/worker.js';
const connection = new RTCPeerConnection();
const datachannel = connection.createDataChannel('label');
...
The polyfill extends EventTarget, which is not yet supported in all browsers. You are going to need a EventTarget polyfill, such as event-target.
This is only needed in the Worker.
If using Babel < 7, babel-plugin-transform-builtin-classes is required.
Media streams, accessible through getUserMedia()
and captureStream()
, are
not supported by the polyfill.