w3c / webrtc-rtptransport

Repository for the RTPTransport specification of the WebRTC Working Group
Other
18 stars 6 forks source link

Update examples to use standard APIs #14

Open jan-ivar opened 9 months ago

jan-ivar commented 9 months ago

Thanks for the examples! I found them a helpful part of the explainer.

But they refer to the "Encoded Transform API", presumably webrtc-encoded-transform without using any of its APIs, (instead using nonstandard createEncodedStreams). This should be fixed to avoid confusion.

This should help solve #13 and address feedback from at least @jesup and myself that this API should be worker-first.

E.g. a minimum update of the existing examples to spec might yield:

Example: Send with custom packetization

// main.js

const pc = new RTCPeerConnection();
const rtpTransport = pc.createRtpTransport();
const transform = new RTCRtpScriptTransform(worker, {rtpTransport}, [rtpTransport]);
for (const sender of pc.getSenders()) {
  sender.transform = transform;
}

...except why expose rtpTransport on main thread at all? E.g. why not:

// worker.js

onrtctransform = async ({transformer}) => {
  const {readable, options} = transformer;
  const {writable} = transformer.createRtpTransport();
  await readable.pipeThrough(new TransformStream({transform})).pipeTo(writable);

  function transform(encodedFrame, controller) {
    for (const packet of myPacketizer.packetize(frame)) {
      controller.enqueue(packet);
    }
  };
}

I'm not necessarily condoning this as a final shape — it begs other questions like what is the type of a packet and why not reuse the transformer's existing writable? — but developing off of standard APIs I think is the right step forward.

dontcallmedom-bot commented 9 months ago

This issue was mentioned in WEBRTCWG-2023-12-05 (Page 62)