addEventListener("rtctransform", (event) => {
const transform = new TransformStream({
async transform(encodedFrame, controller) {
// Reconstruct the original frame.
const view = new DataView(encodedFrame.data);
// Construct a new buffer
const newData = new ArrayBuffer(encodedFrame.data.byteLength);
const newView = new DataView(newData);
// Encrypt frame bytes using the encryptFunction() method (not shown)
for (let i = 0; i < encodedFrame.data.byteLength; ++i) {
const encryptedByte = encryptFunction(~view.getInt8(i));
newView.setInt8(i, encryptedByte);
}
encodedFrame.data = newData;
controller.enqueue(encodedFrame);
},
});
event.transformer.readable
.pipeThrough(transform)
.pipeTo(event.transformer.writable);
});RTCEncodedAudioFrame / notebook
RTCEncodedAudioFrame
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.