[webrtc-rtptransport] Update examples with standard APIs (#14)

jan-ivar has just created a new issue for https://github.com/w3c/webrtc-rtptransport:

== Update examples with standard APIs ==
I found the examples the most helpful part of the [explainer](https://github.com/w3c/webrtc-rtptransport/blob/main/explainer.md).

But they refer to the _"Encoded Transform API"_, presumably [webrtc-encoded-transform](https://w3c.github.io/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
```js
// 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:

```js
// 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.

Please view or discuss this issue at https://github.com/w3c/webrtc-rtptransport/issues/14 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 30 November 2023 21:23:21 UTC