Docs / Web / WebRTC
WebRTC on the Web
Send a beautified camera over a plain RTCPeerConnection, either from the start or by replacing the camera track without renegotiation.
Demo app: facevity-web-demo on GitHub
With plain WebRTC, Facevity’s processed track is just another MediaStreamTrack. Add it to the peer connection instead of the camera, or swap it in on a running call.
1. Requirements
@facevity/webset up as in the quick start- Any
RTCPeerConnectionsetup with your own signalling - A licence that lists the page’s domain
2. Add the processed track
import { Facevity, BeautyParams } from '@facevity/web';
const fv = await Facevity.initialize({ licenseToken, assetsBaseUrl: '/facevity/' });
fv.setParams(BeautyParams.NATURAL);
const media = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
const camera = media.getVideoTracks()[0];
const processed = fv.createProcessedTrack(camera);
const out = new MediaStream([processed, ...media.getAudioTracks()]);
out.getTracks().forEach((t) => pc.addTrack(t, out));
localVideo.srcObject = new MediaStream([processed]);
3. Or swap it into a running call
replaceWithProcessedTrack finds the sender of the camera track and calls sender.replaceTrack with the processed track. No renegotiation is needed.
import { replaceWithProcessedTrack } from '@facevity/web';
await replaceWithProcessedTrack(fv, pc, camera); // = sender.replaceTrack(fv.createProcessedTrack(camera))
4. Tear down
processed.stop(); // stops the processing; the camera track stays yours
camera.stop();
fv.release();
Notes
- Mirror only the local
<video>(CSStransform: scaleX(-1)); never mirror what is sent. - The web demo includes a loopback call and a call between two browser tabs.
Next: all platforms · API reference
Need help with an integration? Contact the Facevity team. We answer integration questions during trials.