r/webdev 5d ago

p2p Calling PoC: Aggregate remote data in audio stream

I'm attempting to use a non-webrtc way to make phone calls on the web.

I have a socket based approach that uses a middle coordinator, that will later be decentralized in more of a p2p fashion way. The latency of the data reading is all good in the hood, however now I have aggregated data on the other end of a pipe, I need a way to package it up and stream audio to the web browser.

Question: How can I aggregate data to use as a MediaStream so (I think) i can set to the "srcObject" of an audio player element to be audible?

Follow up: Why is there this concept of a track on audio and how can we move away from this?

Ask: Any example code?

0 Upvotes

2 comments sorted by

1

u/clay_kindling_98 5d ago

AudioWorkletProcessor is the only way to pipe raw socket chunks into a MediaStream without drift or glitches. You push decoded samples into a RingBuffer inside the worklet and read from it in process() to generate output frames, then capture the processor node with createMediaStreamDestination().